• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <iostream>
17 #include "securec.h"
18 #include "surface.h"
19 #include "window.h"
20 
21 #include "transaction/rs_transaction.h"
22 #include "ui/rs_surface_node.h"
23 
24 using namespace OHOS;
25 using namespace OHOS::Rosen;
26 
27 namespace Test {
GetWindowSurface(uint32_t w,uint32_t h)28 sptr<OHOS::Surface> GetWindowSurface(uint32_t w, uint32_t h)
29 {
30     sptr<WindowOption> option = new WindowOption();
31     option->SetWindowRect( {0, 0, w, h} );
32     option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_LAUNCHING);
33     option->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
34     sptr<OHOS::Rosen::Window> previewWindow = Rosen::Window::Create("xcomponent_window", option);
35     if (previewWindow == nullptr || previewWindow->GetSurfaceNode() == nullptr) {
36         std::cout << "previewWindow is nullptr" << std::endl;
37         return nullptr;
38     }
39     previewWindow->Show();
40     auto surfaceNode = previewWindow->GetSurfaceNode();
41     surfaceNode->SetFrameGravity(Rosen::Gravity::RESIZE);
42     Rosen::RSTransaction::FlushImplicitTransaction();
43     return surfaceNode->GetSurface();
44 }
45 
46 struct PriData {
47     GraphicExtDataHandle handle;
48     int data;
49 };
50 }
51 
main()52 int main()
53 {
54     std::cout << "Test Begin " << std::endl;
55     // 500 300 width and height
56     sptr<OHOS::Surface> surface = Test::GetWindowSurface(500, 300);
57     if (surface == nullptr) {
58         return 0;
59     }
60     std::cout << "GetWindowSurface Success" << std::endl;
61     Test::PriData priHandle;
62     priHandle.handle.fd = -1;
63     priHandle.handle.reserveInts = 1;
64     priHandle.data = 1;
65     GraphicExtDataHandle *graphicDataHandle = reinterpret_cast<GraphicExtDataHandle*>(&priHandle);
66     std::cout << "SetTunnelHandle Begin " << std::endl;
67     surface->SetTunnelHandle(graphicDataHandle);
68     std::cout << "SetTunnelHandle Finish " << std::endl;
69     sleep(1000); // wait 1000s
70 }