• 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 "pointer_drawing_manager.h"
17 
18 #include "image/bitmap.h"
19 #include "image_source.h"
20 #include "image_type.h"
21 #include "image_utils.h"
22 #include "pixel_map.h"
23 
24 #include "define_multimodal.h"
25 #include "input_device_manager.h"
26 #include "mmi_log.h"
27 #include "util.h"
28 
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "PointerDrawingManager" };
33 const std::string IMAGE_POINTER_DEFAULT_PATH = "/system/etc/multimodalinput/mouse_icon/";
34 constexpr int32_t PAD_SCREEN_WIDTH = 2560;
35 constexpr int32_t PHONE_SCREEN_WIDTH = 2160;
36 constexpr int32_t SMALL_ICON_WIDTH = 40;
37 constexpr int32_t SMALL_ICON_HEIGHT = 40;
38 constexpr int32_t MIDDLE_ICON_WIDTH = 60;
39 constexpr int32_t MIDDLE_ICON_HEIGHT = 60;
40 constexpr int32_t LARGE_ICON_WIDTH = 80;
41 constexpr int32_t LARGE_ICON_HEIGHT = 80;
42 } // namespace
43 } // namespace MMI
44 } // namespace OHOS
45 
46 namespace OHOS {
47 namespace MMI {
PointerDrawingManager()48 PointerDrawingManager::PointerDrawingManager()
49 {
50     InitStyle();
51 }
52 
DrawPointer(int32_t displayId,int32_t physicalX,int32_t physicalY,const MOUSE_ICON mouseStyle)53 void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY,
54     const MOUSE_ICON mouseStyle)
55 {
56     CALL_DEBUG_ENTER;
57     MMI_HILOGD("Display:%{public}d,physicalX:%{public}d,physicalY:%{public}d,mouseStyle:%{public}d",
58         displayId, physicalX, physicalY, mouseStyle);
59     FixCursorPosition(physicalX, physicalY);
60     lastPhysicalX_ = physicalX;
61     lastPhysicalY_ = physicalY;
62 
63     AdjustMouseFocus(ICON_TYPE(mouseIcons_[mouseStyle].alignmentWay), physicalX, physicalY);
64     if (pointerWindow_ != nullptr) {
65         pointerWindow_->MoveTo(physicalX + displayInfo_.x, physicalY + displayInfo_.y);
66         if (lastMouseStyle_ == mouseStyle) {
67             MMI_HILOGD("The lastMouseStyle is equal with mouseStyle");
68             return;
69         }
70         lastMouseStyle_ = mouseStyle;
71         int32_t ret = InitLayer(mouseStyle);
72         if (ret != RET_OK) {
73             MMI_HILOGE("Init layer failed");
74             return;
75         }
76         UpdatePointerVisible();
77         MMI_HILOGD("Leave, display:%{public}d,physicalX:%{public}d,physicalY:%{public}d",
78             displayId, physicalX, physicalY);
79         return;
80     }
81 
82     CreatePointerWindow(displayId, physicalX, physicalY);
83     CHKPV(pointerWindow_);
84     int32_t ret = InitLayer(mouseStyle);
85     if (ret != RET_OK) {
86         MMI_HILOGE("Init layer failed");
87         return;
88     }
89     UpdatePointerVisible();
90     MMI_HILOGD("Leave, display:%{public}d,physicalX:%{public}d,physicalY:%{public}d",
91         displayId, physicalX, physicalY);
92 }
93 
InitLayer(const MOUSE_ICON mouseStyle)94 int32_t PointerDrawingManager::InitLayer(const MOUSE_ICON mouseStyle)
95 {
96     CALL_DEBUG_ENTER;
97     CHKPR(pointerWindow_, RET_ERR);
98     sptr<OHOS::Surface> layer = GetLayer();
99     if (layer == nullptr) {
100         pointerWindow_->Destroy();
101         pointerWindow_ = nullptr;
102         MMI_HILOGE("Init layer is failed, Layer is nullptr");
103         return RET_ERR;
104     }
105 
106     sptr<OHOS::SurfaceBuffer> buffer = GetSurfaceBuffer(layer);
107     if (buffer == nullptr || buffer->GetVirAddr() == nullptr) {
108         pointerWindow_->Destroy();
109         pointerWindow_ = nullptr;
110         MMI_HILOGE("Init layer is failed, buffer or virAddr is nullptr");
111         return RET_ERR;
112     }
113 
114     auto addr = static_cast<uint8_t *>(buffer->GetVirAddr());
115     DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), mouseStyle);
116     OHOS::BufferFlushConfig flushConfig = {
117         .damage = {
118             .w = buffer->GetWidth(),
119             .h = buffer->GetHeight(),
120         },
121     };
122     OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig);
123     if (ret != OHOS::SURFACE_ERROR_OK) {
124         MMI_HILOGE("Init layer failed, FlushBuffer return ret:%{public}s", SurfaceErrorStr(ret).c_str());
125         return RET_ERR;
126     }
127     MMI_HILOGD("Init layer success");
128     return RET_OK;
129 }
130 
AdjustMouseFocus(ICON_TYPE iconType,int32_t & physicalX,int32_t & physicalY)131 void PointerDrawingManager::AdjustMouseFocus(ICON_TYPE iconType, int32_t &physicalX, int32_t &physicalY)
132 {
133     CALL_DEBUG_ENTER;
134     switch (iconType) {
135         case ANGLE_SW: {
136             physicalY -= imageHeight_;
137             break;
138         }
139         case ANGLE_CENTER: {
140             physicalX -= imageWidth_ / 2;
141             physicalY -= imageHeight_ / 2;
142             break;
143         }
144         case ANGLE_NW:
145         default: {
146             MMI_HILOGD("No need adjust mouse focus");
147             break;
148         }
149     }
150 }
151 
FixCursorPosition(int32_t & physicalX,int32_t & physicalY)152 void PointerDrawingManager::FixCursorPosition(int32_t &physicalX, int32_t &physicalY)
153 {
154     if (physicalX < 0) {
155         physicalX = 0;
156     }
157 
158     if (physicalY < 0) {
159         physicalY = 0;
160     }
161     const int32_t cursorUnit = 16;
162     if (displayInfo_.direction == Direction0 || displayInfo_.direction == Direction180) {
163         if (physicalX > (displayInfo_.width - imageWidth_ / cursorUnit)) {
164             physicalX = displayInfo_.width - imageWidth_ / cursorUnit;
165         }
166         if (physicalY > (displayInfo_.height - imageHeight_ / cursorUnit)) {
167             physicalY = displayInfo_.height - imageHeight_ / cursorUnit;
168         }
169     } else {
170         if (physicalX > (displayInfo_.height - imageHeight_ / cursorUnit)) {
171             physicalX = displayInfo_.height - imageHeight_ / cursorUnit;
172         }
173         if (physicalY > (displayInfo_.width - imageWidth_ / cursorUnit)) {
174             physicalY = displayInfo_.width - imageWidth_ / cursorUnit;
175         }
176     }
177 }
178 
CreatePointerWindow(int32_t displayId,int32_t physicalX,int32_t physicalY)179 void PointerDrawingManager::CreatePointerWindow(int32_t displayId, int32_t physicalX, int32_t physicalY)
180 {
181     sptr<OHOS::Rosen::WindowOption> option = new (std::nothrow) OHOS::Rosen::WindowOption();
182     CHKPV(option);
183     option->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_POINTER);
184     option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING);
185     option->SetDisplayId(displayId);
186     OHOS::Rosen::Rect rect = {
187         .posX_ = physicalX,
188         .posY_ = physicalY,
189         .width_ = IMAGE_WIDTH,
190         .height_ = IMAGE_HEIGHT,
191     };
192     option->SetWindowRect(rect);
193     option->SetFocusable(false);
194     option->SetTouchable(false);
195     std::string windowName = "pointer window";
196     pointerWindow_ = OHOS::Rosen::Window::Create(windowName, option, nullptr);
197 }
198 
GetLayer()199 sptr<OHOS::Surface> PointerDrawingManager::GetLayer()
200 {
201     std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode = pointerWindow_->GetSurfaceNode();
202     if (surfaceNode == nullptr) {
203         MMI_HILOGE("Draw pointer is failed, get node is nullptr");
204         pointerWindow_->Destroy();
205         pointerWindow_ = nullptr;
206         return nullptr;
207     }
208     return surfaceNode->GetSurface();
209 }
210 
SetMouseDisplayState(bool state)211 void PointerDrawingManager::SetMouseDisplayState(bool state)
212 {
213     CALL_DEBUG_ENTER;
214     if (mouseDisplayState_ != state) {
215         mouseDisplayState_ = state;
216         if (mouseDisplayState_) {
217             InitLayer(MOUSE_ICON(lastMouseStyle_));
218         }
219         UpdatePointerVisible();
220     }
221 }
222 
GetMouseDisplayState() const223 bool PointerDrawingManager::GetMouseDisplayState() const
224 {
225     return mouseDisplayState_;
226 }
227 
GetSurfaceBuffer(sptr<OHOS::Surface> layer) const228 sptr<OHOS::SurfaceBuffer> PointerDrawingManager::GetSurfaceBuffer(sptr<OHOS::Surface> layer) const
229 {
230     sptr<OHOS::SurfaceBuffer> buffer;
231     int32_t releaseFence = 0;
232     OHOS::BufferRequestConfig config = {
233         .width = IMAGE_WIDTH,
234         .height = IMAGE_HEIGHT,
235         .strideAlignment = 0x8,
236         .format = PIXEL_FMT_RGBA_8888,
237         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
238     };
239 
240     OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config);
241     if (ret != OHOS::SURFACE_ERROR_OK) {
242         MMI_HILOGE("Request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str());
243         return nullptr;
244     }
245     return buffer;
246 }
247 
DoDraw(uint8_t * addr,uint32_t width,uint32_t height,const MOUSE_ICON mouseStyle)248 void PointerDrawingManager::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const MOUSE_ICON mouseStyle)
249 {
250     CALL_DEBUG_ENTER;
251     OHOS::Rosen::Drawing::Bitmap bitmap;
252     OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888,
253         OHOS::Rosen::Drawing::ALPHATYPE_OPAQUE };
254     bitmap.Build(width, height, format);
255     OHOS::Rosen::Drawing::Canvas canvas;
256     canvas.Bind(bitmap);
257     canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT);
258     DrawPixelmap(canvas, mouseIcons_[mouseStyle].iconPath);
259     static constexpr uint32_t stride = 4;
260     uint32_t addrSize = width * height * stride;
261     errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);
262     if (ret != EOK) {
263         MMI_HILOGE("Memcpy data is error, ret:%{public}d", ret);
264         return;
265     }
266 }
267 
DrawPixelmap(OHOS::Rosen::Drawing::Canvas & canvas,const std::string & iconPath)268 void PointerDrawingManager::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& iconPath)
269 {
270     CALL_DEBUG_ENTER;
271     std::unique_ptr<OHOS::Media::PixelMap> pixelmap = DecodeImageToPixelMap(iconPath);
272     CHKPV(pixelmap);
273     OHOS::Rosen::Drawing::Pen pen;
274     pen.SetAntiAlias(true);
275     pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE);
276     OHOS::Rosen::Drawing::scalar penWidth = 1;
277     pen.SetWidth(penWidth);
278     canvas.AttachPen(pen);
279     canvas.DrawBitmap(*pixelmap, 0, 0);
280 }
281 
DecodeImageToPixelMap(const std::string & imagePath)282 std::unique_ptr<OHOS::Media::PixelMap> PointerDrawingManager::DecodeImageToPixelMap(const std::string &imagePath)
283 {
284     OHOS::Media::SourceOptions opts;
285     opts.formatHint = "image/png";
286     uint32_t ret = 0;
287     auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret);
288     CHKPP(imageSource);
289     std::set<std::string> formats;
290     ret = imageSource->GetSupportedFormats(formats);
291     MMI_HILOGD("Get supported format ret:%{public}u", ret);
292 
293     OHOS::Media::DecodeOptions decodeOpts;
294     decodeOpts.desiredSize = {
295         .width = imageWidth_,
296         .height = imageHeight_
297     };
298 
299     std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
300     if (pixelMap == nullptr) {
301         MMI_HILOGE("The pixelMap is nullptr");
302     }
303     return pixelMap;
304 }
305 
UpdateDisplayInfo(const DisplayInfo & displayInfo)306 void PointerDrawingManager::UpdateDisplayInfo(const DisplayInfo& displayInfo)
307 {
308     CALL_DEBUG_ENTER;
309     hasDisplay_ = true;
310     displayInfo_ = displayInfo;
311 
312     if ((displayInfo_.width >= PHONE_SCREEN_WIDTH) || (displayInfo_.height >= PHONE_SCREEN_WIDTH)) {
313         if ((displayInfo_.width == PAD_SCREEN_WIDTH) || (displayInfo_.height == PAD_SCREEN_WIDTH)) {
314             imageWidth_ = MIDDLE_ICON_WIDTH;
315             imageHeight_ = MIDDLE_ICON_HEIGHT;
316         } else {
317             imageWidth_ = LARGE_ICON_WIDTH;
318             imageHeight_ = LARGE_ICON_HEIGHT;
319         }
320     } else {
321         imageWidth_ = SMALL_ICON_WIDTH;
322         imageHeight_ = SMALL_ICON_HEIGHT;
323     }
324 }
325 
OnDisplayInfo(const DisplayGroupInfo & displayGroupInfo)326 void PointerDrawingManager::OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo)
327 {
328     CALL_DEBUG_ENTER;
329     for (const auto& item : displayGroupInfo.displaysInfo) {
330         if (item.id == displayInfo_.id) {
331             UpdateDisplayInfo(item);
332             DrawManager();
333             return;
334         }
335     }
336     UpdateDisplayInfo(displayGroupInfo.displaysInfo[0]);
337     lastPhysicalX_ = displayGroupInfo.displaysInfo[0].width / 2;
338     lastPhysicalY_ = displayGroupInfo.displaysInfo[0].height / 2;
339     MouseEventHdr->OnDisplayLost(displayInfo_.id);
340     if (pointerWindow_ != nullptr) {
341         pointerWindow_->Destroy();
342         pointerWindow_ = nullptr;
343     }
344     MMI_HILOGD("displayId_:%{public}d, displayWidth_:%{public}d, displayHeight_:%{public}d",
345         displayInfo_.id, displayInfo_.width, displayInfo_.height);
346 }
347 
OnWindowInfo(const WinInfo & info)348 void PointerDrawingManager::OnWindowInfo(const WinInfo &info)
349 {
350     CALL_DEBUG_ENTER;
351     windowId_ = info.windowId;
352     pid_ = info.windowPid;
353 }
354 
UpdatePointerDevice(bool hasPointerDevice,bool isPointerVisible)355 void PointerDrawingManager::UpdatePointerDevice(bool hasPointerDevice, bool isPointerVisible)
356 {
357     CALL_DEBUG_ENTER;
358     hasPointerDevice_ = hasPointerDevice;
359     if (hasPointerDevice_) {
360         SetPointerVisible(getpid(), isPointerVisible);
361     } else {
362         DeletePointerVisible(getpid());
363     }
364     DrawManager();
365 }
366 
DrawManager()367 void PointerDrawingManager::DrawManager()
368 {
369     if (hasDisplay_ && hasPointerDevice_ && pointerWindow_ == nullptr) {
370         MMI_HILOGD("Draw pointer begin");
371         int32_t mouseStyle = -1;
372         int32_t ret = WinMgr->GetPointerStyle(pid_, windowId_, mouseStyle);
373         if (ret != RET_OK) {
374             MMI_HILOGE("Get pointer style failed, pointerStyleInfo is nullptr");
375             return;
376         }
377         if (lastPhysicalX_ == -1 || lastPhysicalY_ == -1) {
378             DrawPointer(displayInfo_.id, displayInfo_.width / 2, displayInfo_.height / 2, MOUSE_ICON(mouseStyle));
379             MMI_HILOGD("Draw manager, mouseStyle:%{public}d, last physical is initial value", mouseStyle);
380             return;
381         }
382         DrawPointer(displayInfo_.id, lastPhysicalX_, lastPhysicalY_, MOUSE_ICON(mouseStyle));
383         MMI_HILOGD("Draw manager, mouseStyle:%{public}d", mouseStyle);
384         return;
385     }
386     if (!hasPointerDevice_ && pointerWindow_ != nullptr) {
387         MMI_HILOGD("Destroy draw pointer");
388         pointerWindow_->Destroy();
389         pointerWindow_ = nullptr;
390     }
391 }
392 
Init()393 bool PointerDrawingManager::Init()
394 {
395     CALL_DEBUG_ENTER;
396     InputDevMgr->Attach(shared_from_this());
397     pidInfos_.clear();
398     return true;
399 }
400 
GetInstance()401 std::shared_ptr<IPointerDrawingManager> IPointerDrawingManager::GetInstance()
402 {
403     if (iPointDrawMgr_ == nullptr) {
404         iPointDrawMgr_ = std::make_shared<PointerDrawingManager>();
405     }
406     return iPointDrawMgr_;
407 }
408 
UpdatePointerVisible()409 void PointerDrawingManager::UpdatePointerVisible()
410 {
411     CALL_DEBUG_ENTER;
412     CHKPV(pointerWindow_);
413     if (IsPointerVisible() && mouseDisplayState_) {
414         pointerWindow_->Show();
415     } else {
416         pointerWindow_->Hide();
417     }
418 }
419 
IsPointerVisible()420 bool PointerDrawingManager::IsPointerVisible()
421 {
422     CALL_DEBUG_ENTER;
423     if (pidInfos_.empty()) {
424         MMI_HILOGD("Visible property is true");
425         return true;
426     }
427     auto info = pidInfos_.back();
428     MMI_HILOGD("Visible property:%{public}zu.%{public}d-%{public}d", pidInfos_.size(), info.pid, info.visible);
429     return info.visible;
430 }
431 
DeletePointerVisible(int32_t pid)432 void PointerDrawingManager::DeletePointerVisible(int32_t pid)
433 {
434     CALL_DEBUG_ENTER;
435     auto it = pidInfos_.begin();
436     for (; it != pidInfos_.end(); ++it) {
437         if (it->pid == pid) {
438             pidInfos_.erase(it);
439             break;
440         }
441     }
442     if (it != pidInfos_.end()) {
443         if (IsPointerVisible()) {
444             InitLayer(MOUSE_ICON(lastMouseStyle_));
445         }
446         UpdatePointerVisible();
447     }
448 }
449 
SetPointerVisible(int32_t pid,bool visible)450 int32_t PointerDrawingManager::SetPointerVisible(int32_t pid, bool visible)
451 {
452     CALL_DEBUG_ENTER;
453     for (auto it = pidInfos_.begin(); it != pidInfos_.end(); ++it) {
454         if (it->pid == pid) {
455             pidInfos_.erase(it);
456             break;
457         }
458     }
459     PidInfo info = { .pid = pid, .visible = visible };
460     pidInfos_.push_back(info);
461     if (visible) {
462         InitLayer(MOUSE_ICON(lastMouseStyle_));
463     }
464     UpdatePointerVisible();
465     return RET_OK;
466 }
467 
SetPointerLocation(int32_t pid,int32_t x,int32_t y)468 void PointerDrawingManager::SetPointerLocation(int32_t pid, int32_t x, int32_t y)
469 {
470     CALL_DEBUG_ENTER;
471     FixCursorPosition(x, y);
472     lastPhysicalX_ = x;
473     lastPhysicalY_ = y;
474     if (pointerWindow_ != nullptr) {
475         pointerWindow_->MoveTo(x, y);
476         SetPointerVisible(pid, true);
477     }
478 }
479 
SetPointerStyle(int32_t pid,int32_t windowId,int32_t pointerStyle)480 int32_t PointerDrawingManager::SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle)
481 {
482     CALL_DEBUG_ENTER;
483     auto it = mouseIcons_.find(MOUSE_ICON(pointerStyle));
484     if (it == mouseIcons_.end()) {
485         MMI_HILOGE("The param pointerStyle is invalid");
486         return RET_ERR;
487     }
488 
489     int32_t ret = WinMgr->SetPointerStyle(pid, windowId, pointerStyle);
490     if (ret != RET_OK) {
491         MMI_HILOGE("Set pointer style failed");
492         return ret;
493     }
494 
495     if (!InputDevMgr->HasPointerDevice()) {
496         MMI_HILOGD("The pointer device is not exist");
497         return RET_OK;
498     }
499 
500     if (!WinMgr->IsNeedRefreshLayer(windowId)) {
501         MMI_HILOGD("Not need refresh layer, window type:%{public}d, pointer style:%{public}d", windowId, pointerStyle);
502         return RET_OK;
503     }
504 
505     if (pointerWindow_ != nullptr) {
506         int32_t physicalX = lastPhysicalX_;
507         int32_t physicalY = lastPhysicalY_;
508         AdjustMouseFocus(ICON_TYPE(mouseIcons_[MOUSE_ICON(pointerStyle)].alignmentWay), physicalX, physicalY);
509         pointerWindow_->MoveTo(physicalX + displayInfo_.x, physicalY + displayInfo_.y);
510 
511         lastMouseStyle_ = pointerStyle;
512         int32_t ret = InitLayer(MOUSE_ICON(pointerStyle));
513         if (ret != RET_OK) {
514             MMI_HILOGE("Init layer failed");
515             return RET_ERR;
516         }
517     }
518     UpdatePointerVisible();
519     MMI_HILOGD("Window id:%{public}d set pointer style:%{public}d success", windowId, pointerStyle);
520     return RET_OK;
521 }
522 
GetPointerStyle(int32_t pid,int32_t windowId,int32_t & pointerStyle)523 int32_t PointerDrawingManager::GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle)
524 {
525     CALL_DEBUG_ENTER;
526     int32_t ret = WinMgr->GetPointerStyle(pid, windowId, pointerStyle);
527     if (ret != RET_OK) {
528         MMI_HILOGE("Get pointer style failed, pointerStyleInfo is nullptr");
529         return ret;
530     }
531     MMI_HILOGD("Window id:%{public}d get pointer style:%{public}d success", windowId, pointerStyle);
532     return RET_OK;
533 }
534 
DrawPointerStyle()535 void PointerDrawingManager::DrawPointerStyle()
536 {
537     CALL_DEBUG_ENTER;
538     if (hasDisplay_ && hasPointerDevice_) {
539         int32_t mouseStyle = -1;
540         int32_t ret = WinMgr->GetPointerStyle(pid_, windowId_, mouseStyle);
541         if (ret != RET_OK) {
542             MMI_HILOGE("Draw pointer style failed, pointerStyleInfo is nullptr");
543             return;
544         }
545         if (lastPhysicalX_ == -1 || lastPhysicalY_ == -1) {
546             DrawPointer(displayInfo_.id, displayInfo_.width / 2, displayInfo_.height / 2, MOUSE_ICON(mouseStyle));
547             MMI_HILOGD("Draw pointer style, mouseStyle:%{public}d", mouseStyle);
548             return;
549         }
550 
551         DrawPointer(displayInfo_.id, lastPhysicalX_, lastPhysicalY_, MOUSE_ICON(mouseStyle));
552         MMI_HILOGD("Draw pointer style, mouseStyle:%{public}d", mouseStyle);
553     }
554 }
555 
InitStyle()556 void PointerDrawingManager::InitStyle()
557 {
558     CALL_DEBUG_ENTER;
559     mouseIcons_ = {
560         {DEFAULT, {ANGLE_NW, IMAGE_POINTER_DEFAULT_PATH + "Default.png"}},
561         {EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "East.png"}},
562         {WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "West.png"}},
563         {SOUTH, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "South.png"}},
564         {NORTH, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "North.png"}},
565         {WEST_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "West_East.png"}},
566         {NORTH_SOUTH, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "North_South.png"}},
567         {NORTH_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "North_East.png"}},
568         {NORTH_WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "North_West.png"}},
569         {SOUTH_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "South_East.png"}},
570         {SOUTH_WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "South_West.png"}},
571         {NORTH_EAST_SOUTH_WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "North_East_South_West.png"}},
572         {NORTH_WEST_SOUTH_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "North_West_South_East.png"}},
573         {CROSS, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Cross.png"}},
574         {CURSOR_COPY, {ANGLE_NW, IMAGE_POINTER_DEFAULT_PATH + "Copy.png"}},
575         {CURSOR_FORBID, {ANGLE_NW, IMAGE_POINTER_DEFAULT_PATH + "Forbid.png"}},
576         {COLOR_SUCKER, {ANGLE_SW, IMAGE_POINTER_DEFAULT_PATH + "Colorsucker.png"}},
577         {HAND_GRABBING, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Hand_Grabbing.png"}},
578         {HAND_OPEN, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Hand_Open.png"}},
579         {HAND_POINTING, {ANGLE_NW, IMAGE_POINTER_DEFAULT_PATH + "Hand_Pointing.png"}},
580         {HELP, {ANGLE_NW, IMAGE_POINTER_DEFAULT_PATH + "Help.png"}},
581         {CURSOR_MOVE, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Move.png"}},
582         {RESIZE_LEFT_RIGHT, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Resize_Left_Right.png"}},
583         {RESIZE_UP_DOWN, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Resize_Up_Down.png"}},
584         {SCREENSHOT_CHOOSE, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Screenshot_Cross.png"}},
585         {SCREENSHOT_CURSOR, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Screenshot_Cursor.png"}},
586         {TEXT_CURSOR, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Text_Cursor.png"}},
587         {ZOOM_IN, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Zoom_In.png"}},
588         {ZOOM_OUT, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "Zoom_Out.png"}},
589         {MIDDLE_BTN_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_East.png"}},
590         {MIDDLE_BTN_WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_West.png"}},
591         {MIDDLE_BTN_SOUTH, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_South.png"}},
592         {MIDDLE_BTN_NORTH, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_North.png"}},
593         {MIDDLE_BTN_NORTH_SOUTH, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_North_South.png"}},
594         {MIDDLE_BTN_NORTH_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_North_East.png"}},
595         {MIDDLE_BTN_NORTH_WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_North_West.png"}},
596         {MIDDLE_BTN_SOUTH_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_South_East.png"}},
597         {MIDDLE_BTN_SOUTH_WEST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH + "MID_Btn_South_West.png"}},
598         {MIDDLE_BTN_NORTH_SOUTH_WEST_EAST, {ANGLE_CENTER, IMAGE_POINTER_DEFAULT_PATH +
599             "MID_Btn_North_South_West_East.png"}},
600     };
601     for (auto iter = mouseIcons_.begin(); iter != mouseIcons_.end();) {
602         if ((ReadCursorStyleFile(iter->second.iconPath)) != RET_OK) {
603             iter = mouseIcons_.erase(iter);
604             continue;
605         }
606         ++iter;
607     }
608 }
609 } // namespace MMI
610 } // namespace OHOS
611