• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 "lite_win_requestor.h"
17 #include "gfx_utils/graphic_log.h"
18 #include "lite_wm_type.h"
19 #include "lite_wms_client.h"
20 #include "surface_impl.h"
21 
22 namespace OHOS {
LiteWinRequestor(int32_t id)23 LiteWinRequestor::LiteWinRequestor(int32_t id) : proxy_(nullptr), id_(id), surface_(nullptr)
24 {
25     proxy_ = LiteWMSClient::GetInstance()->GetClientProxy();
26 }
27 
~LiteWinRequestor()28 LiteWinRequestor::~LiteWinRequestor()
29 {
30     if (surface_ != nullptr) {
31         delete surface_;
32         surface_ = nullptr;
33     }
34 }
35 
Callback(void * owner,int code,IpcIo * reply)36 int LiteWinRequestor::Callback(void* owner, int code, IpcIo* reply)
37 {
38     if (code != 0) {
39         GRAPHIC_LOGE("callback error, code = %d", code);
40         return -1;
41     }
42 
43     if (owner == nullptr) {
44         return -1;
45     }
46 
47     CallBackPara* para = static_cast<CallBackPara*>(owner);
48     GRAPHIC_LOGD("Callback, funcId = %d", para->funcId);
49     switch (para->funcId) {
50         case LiteWMS_GetSurface: {
51             LiteWinRequestor* requestor = static_cast<LiteWinRequestor*>(para->data);
52             int32_t ret;
53             ReadInt32(reply, &ret);
54             if ((ret == LiteWMS_EOK) && (requestor != nullptr)) {
55                 requestor->GenericSurface(reply);
56             }
57             break;
58         }
59         default:
60             break;
61     }
62     return 0;
63 }
64 
GenericSurface(IpcIo * reply)65 void LiteWinRequestor::GenericSurface(IpcIo* reply)
66 {
67     surface_ = SurfaceImpl::GenericSurfaceByIpcIo(*reply);
68 }
69 
GetSurface()70 Surface* LiteWinRequestor::GetSurface()
71 {
72     if (surface_ == nullptr) {
73         IpcIo io;
74         uint8_t tmpData[DEFAULT_IPC_SIZE];
75         IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
76         WriteInt32(&io, id_);
77 
78         CallBackPara para = {};
79         para.funcId = LiteWMS_GetSurface;
80         para.data = this;
81         int32_t ret = proxy_->Invoke(proxy_, LiteWMS_GetSurface, &io, &para, Callback);
82         if (ret != 0) {
83             GRAPHIC_LOGE("GetSurface failed, ret=%d", ret);
84         }
85     }
86     return surface_;
87 }
88 
Show()89 void LiteWinRequestor::Show()
90 {
91     IpcIo io;
92     uint8_t tmpData[DEFAULT_IPC_SIZE];
93     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
94     WriteInt32(&io, id_);
95 
96     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Show, &io, NULL, NULL);
97     if (ret != 0) {
98         GRAPHIC_LOGE("Show failed, ret=%d", ret);
99     }
100 }
101 
Hide()102 void LiteWinRequestor::Hide()
103 {
104     IpcIo io;
105     uint8_t tmpData[DEFAULT_IPC_SIZE];
106     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
107     WriteInt32(&io, id_);
108 
109     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Hide, &io, NULL, NULL);
110     if (ret != 0) {
111         GRAPHIC_LOGE("Hide failed, ret=%d", ret);
112     }
113 }
114 
RaiseToTop()115 void LiteWinRequestor::RaiseToTop()
116 {
117     IpcIo io;
118     uint8_t tmpData[DEFAULT_IPC_SIZE];
119     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
120     WriteInt32(&io, id_);
121 
122     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_RaiseToTop, &io, NULL, NULL);
123     if (ret != 0) {
124         GRAPHIC_LOGE("RaiseToTop failed, ret=%d", ret);
125     }
126 }
127 
LowerToBottom()128 void LiteWinRequestor::LowerToBottom()
129 {
130     IpcIo io;
131     uint8_t tmpData[DEFAULT_IPC_SIZE];
132     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
133     WriteInt32(&io, id_);
134 
135     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_LowerToBottom, &io, NULL, NULL);
136     if (ret != 0) {
137         GRAPHIC_LOGE("LowerToBottom failed, ret=%d", ret);
138     }
139 }
140 
MoveTo(int16_t x,int16_t y)141 void LiteWinRequestor::MoveTo(int16_t x, int16_t y)
142 {
143     IpcIo io;
144     uint8_t tmpData[DEFAULT_IPC_SIZE];
145     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
146     WriteInt32(&io, id_);
147     WriteUint32(&io, x);
148     WriteUint32(&io, y);
149 
150     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_MoveTo, &io, NULL, NULL);
151     if (ret != 0) {
152         GRAPHIC_LOGE("MoveTo failed, ret=%d", ret);
153     }
154 }
155 
Resize(int16_t width,int16_t height)156 void LiteWinRequestor::Resize(int16_t width, int16_t height)
157 {
158     IpcIo io;
159     uint8_t tmpData[DEFAULT_IPC_SIZE];
160     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
161     WriteInt32(&io, id_);
162     WriteUint32(&io, width);
163     WriteUint32(&io, height);
164 
165     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Resize, &io, NULL, Callback);
166     if (ret != 0) {
167         GRAPHIC_LOGE("Resize failed, ret=%d", ret);
168     }
169 }
170 
Update()171 void LiteWinRequestor::Update()
172 {
173     IpcIo io;
174     uint8_t tmpData[DEFAULT_IPC_SIZE];
175     IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
176     WriteInt32(&io, id_);
177 
178     int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Update, &io, NULL, NULL);
179     if (ret != 0) {
180         GRAPHIC_LOGE("Update failed, ret=%d", ret);
181     }
182 }
183 } // namespace OHOS
184