• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "wmclient_native_test_5.h"
17 
18 #include <cstdio>
19 #include <fstream>
20 #include <securec.h>
21 
22 #include <display_type.h>
23 #include <window_manager.h>
24 
25 #include "native_test_class.h"
26 #include "util.h"
27 #include "wmclient_native_test_1.h"
28 
29 using namespace OHOS;
30 
31 namespace {
32 class WMClientNativeTest5 : public WMClientNativeTest1, public IWindowShotCallback {
33 public:
GetDescription() const34     std::string GetDescription() const override
35     {
36         constexpr const char *desc = "shot window";
37         return desc;
38     }
39 
GetID() const40     int32_t GetID() const override
41     {
42         constexpr int32_t id = 5;
43         return id;
44     }
45 
GetLastTime() const46     uint32_t GetLastTime() const override
47     {
48         constexpr uint32_t lastTime = 2000;
49         return lastTime;
50     }
51 
Run(int32_t argc,const char ** argv)52     void Run(int32_t argc, const char **argv) override
53     {
54         auto initRet = WindowManager::GetInstance()->Init();
55         if (initRet) {
56             printf("init failed with %s\n", GSErrorStr(initRet).c_str());
57             ExitTest();
58             return;
59         }
60 
61         WMClientNativeTest1::Run(argc, argv);
62 
63         constexpr uint32_t delayTime = 1000;
64         PostTask(std::bind(&WMClientNativeTest5::AfterRun, this), delayTime);
65     }
66 
AfterRun()67     void AfterRun()
68     {
69         auto wm = WindowManager::GetInstance();
70         wm->ListenNextWindowShot(window, this);
71     }
72 
OnWindowShot(const struct WMImageInfo & info)73     void OnWindowShot(const struct WMImageInfo &info) override
74     {
75         printf("width: %u, height: %u\n", info.width, info.height);
76         printf("format: %u, size: %u, data: %p\n", info.format, info.size, info.data);
77 
78         printf("writing to /data/wmtest5.raw\n");
79         std::ofstream rawDataFile("/data/wmtest5.raw", std::ofstream::binary);
80         rawDataFile.write(static_cast<const char *>(info.data), info.size);
81         rawDataFile.close();
82         printf("write completed\n");
83 
84         ExitTest();
85     }
86 } g_autoload;
87 } // namespace
88