From 4e1a279c4679794f57af98243230d1ccc963725f Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Thu, 6 Jul 2023 18:44:26 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/gn/BUILD.gn | 1 + etc/icon/Default.png | Bin 0 -> 522 bytes window_manager/ft_pointer_draw/BUILD.gn | 50 +++ .../ft_pointer_draw_manager_adapter.cpp | 102 ++++++ .../i_pointer_drawing_manager.h | 70 ++++ .../ft_pointer_draw/pointer_draw_manager.cpp | 317 ++++++++++++++++++ .../ft_pointer_draw/pointer_draw_manager.h | 115 +++++++ 7 files changed, 655 insertions(+) create mode 100644 etc/icon/Default.png create mode 100644 window_manager/ft_pointer_draw/BUILD.gn create mode 100644 window_manager/ft_pointer_draw/ft_pointer_draw_manager_adapter.cpp create mode 100644 window_manager/ft_pointer_draw/i_pointer_drawing_manager.h create mode 100644 window_manager/ft_pointer_draw/pointer_draw_manager.cpp create mode 100644 window_manager/ft_pointer_draw/pointer_draw_manager.h diff --git a/build/gn/BUILD.gn b/build/gn/BUILD.gn index 0da0214..22e2e28 100644 --- a/build/gn/BUILD.gn +++ b/build/gn/BUILD.gn @@ -22,6 +22,7 @@ group("ft_display_server") { group("ft_window_manager") { deps = [ "//window_manager/wmserver/ft_build:libwms", + "//window_manager/ft_pointer_draw:libpointerdraw", ] } diff --git a/etc/icon/Default.png b/etc/icon/Default.png new file mode 100644 index 0000000000000000000000000000000000000000..6308171fe9d612050376f6a5dfdc870e51bc92db GIT binary patch literal 522 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(&7aK09DS?;h@)n>(w zU77zQXSuG~_Vy8v33K!P7bm_yUcX@Svdm|xk@w1C%MBhDGF)SI{17H`RCu}vlS{!L zCCv%ZDe@;&i#VR}{gj=c{lwoPZ^G?{7=?OfBlmYqDP4C&Pw@N{f1qB}ng3n(RpBwS z1-ZAMe3~8@dbLJIcGrY=PaKx7dp$d9(h@!2%S_RI?##T>UmN=#ueoO!5_(r*V$$sA zKd*k+ck!CYi(Prm<=TgT>F^w8Wyn_fEW&x=`(M?6?DGTV65l;mFI%YLPBzD z8Qv=8{5Pi9nO#{PC}JC=;A!Y7^hs~t1zVqfm808ojeRc{b(#21UQ%&Z#m1>zOkKJ?!T{$GzTFckq`?ald5N4T%|&a;7<7S+i;@V%NAb rDKSoL@NiI35E9_*U~yskZ`a75v-6BzVow+-o)|n`{an^LB{Ts5(G +#include +#include "i_pointer_drawing_manager.h" +#include "display_info.h" + +namespace OHOS { +namespace MMI { + +#if defined(__cplusplus) +extern "C" { +#endif // __cplusplus + +using PointerDrawPtr = std::shared_ptr; +std::map g_pointerDrawMap; +constexpr uint32_t MAX_PTRDRAW_NUMS = 64; + +static PointerDrawPtr FindPointerDraw(const uintptr_t instanceHdl) +{ + auto it = g_pointerDrawMap.find(instanceHdl); + if (it == g_pointerDrawMap.end()) { + return nullptr; + } + return it->second; +} + +uintptr_t FTPtrDrawMgrGetInstance() +{ + if (g_pointerDrawMap.size() > MAX_PTRDRAW_NUMS) { + return 0; + } + + PointerDrawPtr instance = IPointerDrawingManager::GetInstance(); + if (instance == nullptr) { + return 0; + } + + uintptr_t instanceHdl = reinterpret_cast(instance.get()); + g_pointerDrawMap[instanceHdl] = instance; + return instanceHdl; +} + +void FTPtrDrawMgrFreeInstance(const uintptr_t instanceHdl) +{ + if (g_pointerDrawMap.size() == 0) { + return; + } + g_pointerDrawMap.erase(instanceHdl); +} + +bool FTPtrDrawMgrInit(const uintptr_t instanceHdl) +{ + PointerDrawPtr instance = FindPointerDraw(instanceHdl); + if (instance == nullptr) { + return false; + } + + instance->Init(); + return true; +} + +bool FTPtrDrawMgrUpdataDispInfo(const uintptr_t instanceHdl, const DisplayInfo& displayInfo) +{ + PointerDrawPtr instance = FindPointerDraw(instanceHdl); + if (instance == nullptr) { + return false; + } + + instance->UpdateDisplayInfo(displayInfo); + return true; +} + +bool FTPtrDrawMgrDrawPointer(const uintptr_t instanceHdl, int32_t displayId, int32_t physicalX, int32_t physicalY) +{ + PointerDrawPtr instance = FindPointerDraw(instanceHdl); + if (instance == nullptr) { + return false; + } + + instance->DrawPointer(displayId, physicalX, physicalY); + return true; +} + +#if defined(__cplusplus) +} +#endif // __cplusplus + +} // MMI +} // OHOS \ No newline at end of file diff --git a/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h b/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h new file mode 100644 index 0000000..385d003 --- /dev/null +++ b/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef I_POINTER_DRAWING_MANAGER_H +#define I_POINTER_DRAWING_MANAGER_H + +#include + +#include "display_info.h" +#include "struct_multimodal.h" + +namespace OHOS { +namespace MMI { +class IPointerDrawingManager { +public: + IPointerDrawingManager() = default; + virtual ~IPointerDrawingManager() = default; + + static std::shared_ptr GetInstance(); + virtual void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, + const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) {} + virtual void UpdateDisplayInfo(const DisplayInfo& displayInfo) {} + virtual void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) {} + virtual void OnWindowInfo(const WinInfo &info) {} + virtual bool Init() + { + return true; + } + virtual void DeletePointerVisible(int32_t pid) {} + virtual int32_t SetPointerVisible(int32_t pid, bool visible) + { + return 0; + } + virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) + { + return 0; + } + virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) + { + return 0; + } + virtual void DrawPointerStyle() {} + virtual bool IsPointerVisible() + { + return false; + } + virtual void SetMouseDisplayState(bool state) {} + virtual bool GetMouseDisplayState() const + { + return true; + } + virtual void SetPointerLocation(int32_t pid, int32_t x, int32_t y) {} +public: + static inline std::shared_ptr iPointDrawMgr_ { nullptr }; +}; +} // namespace MMI +} // namespace OHOS +#endif // I_POINTER_DRAWING_MANAGER_H \ No newline at end of file diff --git a/window_manager/ft_pointer_draw/pointer_draw_manager.cpp b/window_manager/ft_pointer_draw/pointer_draw_manager.cpp new file mode 100644 index 0000000..a3ac259 --- /dev/null +++ b/window_manager/ft_pointer_draw/pointer_draw_manager.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pointer_draw_manager.h" + +#include "unistd.h" +#include + +#include "ui/rs_surface_extractor.h" +#include "transaction/rs_transaction.h" +#include "image_source.h" + +namespace OHOS { +namespace MMI { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "PointerDrawingManager"}; + constexpr int32_t PATH_MAX = 200; + const std::string POINTER_PIXEL_PATH = "/usr/local/share/ft/icon/"; + constexpr int32_t FILE_SIZE_MAX = 0X5000; + constexpr int32_t ICON_WIDTH = 40; + constexpr int32_t ICON_HEIGHT = 40; +} + +std::shared_ptr IPointerDrawingManager::GetInstance() +{ + if (iPointDrawMgr_ == nullptr) { + iPointDrawMgr_ = std::make_shared(); + } + return iPointDrawMgr_; +} + +bool PointerDrawingManager::Init() +{ +#ifndef USE_IMITATE_POINTER + if (InitIconPixel() != WMError::WM_OK) { + WLOGFE("InitIconPixel fail"); + return false; + } +#endif + + runner_ = AppExecFwk::EventRunner::Create("PointerDrawingManager"); + handler_ = std::make_shared(runner_); + + return true; +} + +void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, + const MOUSE_ICON mouseStyle) +{ + if (!isDrawing_) { + if (InitLayerNode(physicalX, physicalY) != WMError::WM_OK) { + WLOGFE("InitLayerNode fail"); + return; + } + + if (InitDisplayNode() != WMError::WM_OK) { + WLOGFE("InitDisplayNode fail"); + return; + } + isDrawing_ = true; + return; + } + + if (handler_ == nullptr) { + WLOGFE("EventHandler is nullptr"); + return; + } + + std::function task = [this, physicalX, physicalY]() -> void { + MoveTo(physicalX, physicalY); + }; + + bool ret = handler_->PostTask(task); + if (ret == false) { + WLOGFE("EventHandler PostTask Failed"); + } +} + +void PointerDrawingManager::SetPointerLocation(int32_t pid, int32_t x, int32_t y) +{ + if (!isDrawing_) { + WLOGFE("need to invoke DrawPointer before SetPointerLocation"); + return; + } + + if (handler_ == nullptr) { + WLOGFE("EventHandler is nullptr"); + return; + } + + std::function task = [this, x, y]() -> void { + MoveTo(x, y); + }; + + bool ret = handler_->PostTask(task); + if (ret == false) { + WLOGFE("EventHandler PostTask Failed"); + } +} + +void PointerDrawingManager::UpdateDisplayInfo(const DisplayInfo& displayInfo) +{ + displayWidth_ = displayInfo.width; + displayHeight_ = displayInfo.height; + displayId_ = displayInfo.id; + + if (displayWidth_ <= 0 || displayHeight_ <= 0) { + WLOGFE("Invalid DisplayInfo"); + } +} + +WMError PointerDrawingManager::MoveTo(int32_t x, int32_t y) +{ + if (surfaceNode_ == nullptr) { + WLOGFE("surfaceNode_ is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + + surfaceNode_->SetBounds(x, y, ICON_WIDTH, ICON_HEIGHT); + Rosen::RSTransaction::FlushImplicitTransaction(); + + return WMError::WM_OK; +} + +WMError PointerDrawingManager::InitLayerNode(int32_t x, int32_t y) +{ + Rosen::RSSurfaceNodeConfig config; + surfaceNode_ = Rosen::RSSurfaceNode::Create(config); + if (surfaceNode_ == nullptr) { + WLOGFE("RSSurfaceNode::Create fail"); + return WMError::WM_ERROR_NULLPTR; + } + + surfaceNode_->SetBounds(x, y, ICON_WIDTH, ICON_HEIGHT); + rsSurface_ = Rosen::RSSurfaceExtractor::ExtractRSSurface(surfaceNode_); + if (rsSurface_ == nullptr) { + WLOGFE("ExtractRSSurface fail"); + return WMError::WM_ERROR_NULLPTR; + } + + auto framePtr = rsSurface_->RequestFrame(ICON_WIDTH, ICON_HEIGHT); + if (framePtr == nullptr) { + WLOGFE("RequestFrame fail"); + return WMError::WM_ERROR_NULLPTR; + } + + auto canvas = framePtr->GetCanvas(); + canvas->clear(SK_ColorTRANSPARENT); + +#ifdef USE_IMITATE_POINTER + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kFill_Style); + paint.setStrokeJoin(SkPaint::kRound_Join); + paint.setColor(SK_ColorBLUE); + canvas->drawRect(SkRect::MakeXYWH(0, 0, ICON_WIDTH, ICON_HEIGHT), paint); +#else + if (mouseIcons_.size() == 0) { + WLOGFE("can not find icon pixel file"); + return WMError::WM_ERROR_NULLPTR; + } + auto pixelmap = DecodeImageToPixelMap(mouseIcons_[DEFAULT].iconPath); + if (pixelmap == nullptr) { + WLOGFE("DecodeImageToPixelMap fail"); + return WMError::WM_ERROR_NULLPTR; + } + + SkImageInfo imageInfo = SkImageInfo::Make(pixelmap->GetWidth(), pixelmap->GetHeight(), + PixelFormatConvert(pixelmap->GetPixelFormat()), + static_cast(pixelmap->GetAlphaType())); + SkPixmap srcPixmap(imageInfo, pixelmap->GetPixels(), pixelmap->GetRowBytes()); + SkBitmap srcBitmap; + srcBitmap.installPixels(srcPixmap); + canvas->drawBitmap(srcBitmap, 0, 0); +#endif + framePtr->SetDamageRegion(0, 0, ICON_WIDTH, ICON_HEIGHT); + rsSurface_->FlushFrame(framePtr); + + return WMError::WM_OK; +} + +WMError PointerDrawingManager::InitDisplayNode() +{ + Rosen::RSDisplayNodeConfig config; + displayNode_ = Rosen::RSDisplayNode::Create(config); + if (displayNode_ == nullptr) { + WLOGFE("RSDisplayNode::Create fail"); + return WMError::WM_ERROR_NULLPTR; + } + + displayNode_->SetScreenId(displayId_); + displayNode_->SetBounds(0, 0, displayWidth_, displayHeight_); + displayNode_->AddChild(surfaceNode_, -1); + Rosen::RSTransaction::FlushImplicitTransaction(); + + return WMError::WM_OK; +} + +WMError PointerDrawingManager::InitIconPixel() +{ + mouseIcons_ = { + {DEFAULT, {ANGLE_NW, POINTER_PIXEL_PATH + "Default.png"}}, + }; + for (auto iter = mouseIcons_.begin(); iter != mouseIcons_.end();) { + if (CheckPixelFile(iter->second.iconPath) != WMError::WM_OK) { + iter = mouseIcons_.erase(iter); + continue; + } + ++iter; + } + + if (mouseIcons_.size() == 0) { + WLOGFE("InitStyle fail"); + return WMError::WM_ERROR_NULLPTR; + } + + return WMError::WM_OK; +} + +WMError PointerDrawingManager::CheckPixelFile(const std::string &filePath) +{ + if (filePath.empty()) { + WLOGFE("Empty path"); + return WMError::WM_ERROR_NULLPTR; + } + + if (access(filePath.c_str(), F_OK) != 0) { + WLOGFE("Unreachable path"); + return WMError::WM_ERROR_NULLPTR; + } + + char realPath[PATH_MAX] = {}; + if (realpath(filePath.c_str(), realPath) == nullptr) { + WLOGFE("Invalid path"); + return WMError::WM_ERROR_NULLPTR; + } + + struct stat statbuf = {0}; + if (stat(filePath.c_str(), &statbuf) != 0) { + WLOGFE("Failed to get size"); + return WMError::WM_ERROR_NULLPTR; + } + if (statbuf.st_size <= 0 || statbuf.st_size > FILE_SIZE_MAX) { + WLOGFE("Invalid size"); + return WMError::WM_ERROR_NULLPTR; + } + + return WMError::WM_OK; +} + +std::unique_ptr PointerDrawingManager::DecodeImageToPixelMap(const std::string &imagePath) +{ + OHOS::Media::SourceOptions opts; + opts.formatHint = "image/png"; + uint32_t ret = 0; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret); + if (ret != 0) { + WLOGFE("CreateImageSource fail"); + return nullptr; + } + + std::set formats; + ret = imageSource->GetSupportedFormats(formats); + if (ret != 0) { + WLOGFE("GetSupportedFormats fail"); + return nullptr; + } + + OHOS::Media::DecodeOptions decodeOpts; + decodeOpts.desiredSize = { + .width = ICON_WIDTH, + .height = ICON_HEIGHT + }; + std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); + if (pixelMap == nullptr) { + WLOGFE("CreatePixelMap fail"); + return nullptr; + } + return pixelMap; +} + +SkColorType PointerDrawingManager::PixelFormatConvert(const Media::PixelFormat& pixelFormat) +{ + SkColorType colorType; + switch (pixelFormat) { + case Media::PixelFormat::BGRA_8888: + colorType = SkColorType::kBGRA_8888_SkColorType; + break; + case Media::PixelFormat::RGBA_8888: + colorType = SkColorType::kRGBA_8888_SkColorType; + break; + case Media::PixelFormat::RGB_565: + colorType = SkColorType::kRGB_565_SkColorType; + break; + case Media::PixelFormat::ALPHA_8: + colorType = SkColorType::kAlpha_8_SkColorType; + break; + default: + colorType = SkColorType::kUnknown_SkColorType; + break; + } + return colorType; +} +} // namespace MMI +} // namespace OHOS diff --git a/window_manager/ft_pointer_draw/pointer_draw_manager.h b/window_manager/ft_pointer_draw/pointer_draw_manager.h new file mode 100644 index 0000000..f2a9933 --- /dev/null +++ b/window_manager/ft_pointer_draw/pointer_draw_manager.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POINTER_DRAW_H +#define POINTER_DRAW_H + +#include "i_pointer_drawing_manager.h" +#include "hilog/log.h" +#include "nocopyable.h" +#include "ui/rs_display_node.h" +#include "ui/rs_surface_node.h" +#include "pixel_map.h" +#include "event_handler.h" + +namespace OHOS { +namespace MMI { +static constexpr unsigned int HILOG_DOMAIN_WINDOW = 0xD004200; + +#define _W_DFUNC HiviewDFX::HiLog::Debug +#define _W_IFUNC HiviewDFX::HiLog::Info +#define _W_WFUNC HiviewDFX::HiLog::Warn +#define _W_EFUNC HiviewDFX::HiLog::Error + +#define _W_CPRINTF(func, fmt, ...) func(LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__) + +#define WLOGD(fmt, ...) _W_CPRINTF(_W_DFUNC, fmt, ##__VA_ARGS__) +#define WLOGI(fmt, ...) _W_CPRINTF(_W_IFUNC, fmt, ##__VA_ARGS__) +#define WLOGW(fmt, ...) _W_CPRINTF(_W_WFUNC, fmt, ##__VA_ARGS__) +#define WLOGE(fmt, ...) _W_CPRINTF(_W_EFUNC, fmt, ##__VA_ARGS__) + +#define _W_FUNC __func__ + +#define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) + +class PointerDrawingManager : public IPointerDrawingManager { +public: + DISALLOW_COPY_AND_MOVE(PointerDrawingManager); + PointerDrawingManager() = default; + ~PointerDrawingManager() = default; + + bool Init() override; + void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, + const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) override; + void UpdateDisplayInfo(const DisplayInfo& displayInfo) override; + void SetPointerLocation(int32_t pid, int32_t x, int32_t y) override; + void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) override {} + void OnWindowInfo(const WinInfo &info) override {} + void DeletePointerVisible(int32_t pid) override {} + void SetMouseDisplayState(bool state) override {} + void DrawPointerStyle() override {} + int32_t SetPointerVisible(int32_t pid, bool visible) override + { + return WMError::WM_OK; + } + int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) override + { + return WMError::WM_OK; + } + int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) override + { + return WMError::WM_OK; + } + bool IsPointerVisible() override + { + return true; + } + bool GetMouseDisplayState() const override + { + return true; + } + +private: + using Task = std::function; + struct IconStyle { + ICON_TYPE type; + std::string iconPath; + }; + + OHOS::WMError InitLayerNode(int32_t x, int32_t y); + OHOS::WMError InitDisplayNode(); + OHOS::WMError InitIconPixel(); + OHOS::WMError CheckPixelFile(const std::string &filePath); + OHOS::WMError MoveTo(int32_t x, int32_t y); + std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); + SkColorType PixelFormatConvert(const OHOS::Media::PixelFormat& pixelFormat); + + bool isDrawing_ = false; + int32_t displayWidth_ = 0; + int32_t displayHeight_ = 0; + int32_t displayId_ = 0; + std::map mouseIcons_; + OHOS::Rosen::RSDisplayNode::SharedPtr displayNode_ = nullptr; + OHOS::Rosen::RSSurfaceNode::SharedPtr surfaceNode_ = nullptr; + std::shared_ptr rsSurface_ = nullptr; + std::shared_ptr runner_ = nullptr; + std::shared_ptr handler_ = nullptr; +}; +} // namespace MMI +} // namespace OHOS +#endif // POINTER_DRAW_H -- Gitee From 7235804e1f046673a643fcad8a3ee1bccbb3fa5f Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Fri, 7 Jul 2023 10:01:51 +0800 Subject: [PATCH 2/6] Revert "fix comments" This reverts commit 1f6749f680e1a51dc595e4181ae1f2c4950c4089. --- .../pointer_draw/pointer_draw.cpp | 14 +++++----- .../ft_build => }/pointer_draw/pointer_draw.h | 26 ++++++++++--------- window_manager/wmserver/ft_build/BUILD.gn | 4 +-- .../wmserver/src/window_inner_manager.cpp | 4 +-- 4 files changed, 25 insertions(+), 23 deletions(-) rename window_manager/{wmserver/ft_build => }/pointer_draw/pointer_draw.cpp (95%) rename window_manager/{wmserver/ft_build => }/pointer_draw/pointer_draw.h (68%) diff --git a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.cpp b/window_manager/pointer_draw/pointer_draw.cpp similarity index 95% rename from window_manager/wmserver/ft_build/pointer_draw/pointer_draw.cpp rename to window_manager/pointer_draw/pointer_draw.cpp index 79eea75..509eae4 100644 --- a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.cpp +++ b/window_manager/pointer_draw/pointer_draw.cpp @@ -20,10 +20,8 @@ #include "ui/rs_surface_extractor.h" #include "transaction/rs_transaction.h" -using namespace OHOS; -using namespace OHOS::Rosen; - -namespace FangTian { +namespace OHOS { +namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "PointerDraw"}; constexpr int32_t ICON_WIDTH = 30; @@ -78,7 +76,7 @@ WMError PointerDraw::InitDisplayInfo() displayHeight_ = displayInfo->GetHeight(); displayId_ = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); - if (displayWidth_ <= 0 || displayHeight_ <= 0) { + if (displayWidth_ <=0 || displayHeight_ <= 0) { WLOGFE("Invalid display info"); return WMError::WM_ERROR_INVALID_PARAM; } @@ -95,7 +93,7 @@ WMError PointerDraw::InitLayerNode() return WMError::WM_ERROR_NULLPTR; } - surfaceNode_->SetBounds(0, 0, ICON_WIDTH, ICON_HEIGHT); + surfaceNode_->SetBounds(displayWidth_ / 2, displayHeight_ / 2, ICON_WIDTH, ICON_HEIGHT); rsSurface_ = RSSurfaceExtractor::ExtractRSSurface(surfaceNode_); if (rsSurface_ == nullptr) { WLOGFE("ExtractRSSurface fail"); @@ -113,6 +111,7 @@ WMError PointerDraw::InitLayerNode() SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kFill_Style); + paint.setStrokeWidth(20); paint.setStrokeJoin(SkPaint::kRound_Join); paint.setColor(SK_ColorBLUE); canvas->drawRect(SkRect::MakeXYWH(0, 0, ICON_WIDTH, ICON_HEIGHT), paint); @@ -161,4 +160,5 @@ void PointerDraw::PostAsyncTask(Task task) } } } -} // FangTian +} // Rosen +} // OHOS diff --git a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.h b/window_manager/pointer_draw/pointer_draw.h similarity index 68% rename from window_manager/wmserver/ft_build/pointer_draw/pointer_draw.h rename to window_manager/pointer_draw/pointer_draw.h index 5ded3dc..5dbf302 100644 --- a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.h +++ b/window_manager/pointer_draw/pointer_draw.h @@ -22,11 +22,12 @@ #include "ui/rs_surface_node.h" #include "event_handler.h" -namespace FangTian { +namespace OHOS { +namespace Rosen { class PointerDraw { WM_DECLARE_SINGLE_INSTANCE_BASE(PointerDraw); public: - OHOS::WMError Init(); + WMError Init(); void AsyncMove(int32_t x, int32_t y); private: @@ -34,20 +35,21 @@ private: virtual ~PointerDraw() = default; using Task = std::function; - OHOS::WMError InitDisplayInfo(); - OHOS::WMError InitLayerNode(); - OHOS::WMError InitDisplayNode(); - OHOS::WMError MoveTo(int32_t x, int32_t y); + WMError InitDisplayInfo(); + WMError InitLayerNode(); + WMError InitDisplayNode(); + WMError MoveTo(int32_t x, int32_t y); void PostAsyncTask(Task task); int32_t displayWidth_ = 0; int32_t displayHeight_ = 0; uint64_t displayId_ = 0; - OHOS::Rosen::RSDisplayNode::SharedPtr displayNode_ = nullptr; - OHOS::Rosen::RSSurfaceNode::SharedPtr surfaceNode_ = nullptr; - std::shared_ptr rsSurface_ = nullptr; - std::shared_ptr runner_ = nullptr; - std::shared_ptr handler_ = nullptr; + RSDisplayNode::SharedPtr displayNode_ = nullptr; + RSSurfaceNode::SharedPtr surfaceNode_ = nullptr; + std::shared_ptr rsSurface_ = nullptr; + std::shared_ptr runner_ = nullptr; + std::shared_ptr handler_ = nullptr; }; -} // namespace FangTian +} // namespace Rosen +} // namespace OHOS #endif // POINTER_DRAW_H diff --git a/window_manager/wmserver/ft_build/BUILD.gn b/window_manager/wmserver/ft_build/BUILD.gn index cb94cc5..6f1cf2f 100644 --- a/window_manager/wmserver/ft_build/BUILD.gn +++ b/window_manager/wmserver/ft_build/BUILD.gn @@ -25,7 +25,7 @@ config("libwms_config") { "$window_manager_path/interfaces/innerkits/wm", "$window_manager_path/interfaces/innerkits/dm", "$window_manager_path/ft_adapter", - "pointer_draw", + "$window_manager_path/pointer_draw", "$window_manager_path/wm/include", "$window_manager_path/utils/include", "$window_manager_path/dm/include", @@ -41,6 +41,7 @@ ft_shared_library("libwms") { defines = ft_defines sources = [ + "$window_manager_path/pointer_draw/pointer_draw.cpp", "$window_manager_path/wm/src/zidl/window_manager_agent_proxy.cpp", "$window_manager_path/wm/src/zidl/window_proxy.cpp", "$window_manager_path/wmserver/src/accessibility_connection.cpp", @@ -77,7 +78,6 @@ ft_shared_library("libwms") { "$window_manager_path/wmserver/src/window_zorder_policy.cpp", "$window_manager_path/wmserver/src/zidl/ressched_report.cpp", "$window_manager_path/wmserver/src/zidl/window_manager_stub.cpp", - "pointer_draw/pointer_draw.cpp", ] configs = [ diff --git a/window_manager/wmserver/src/window_inner_manager.cpp b/window_manager/wmserver/src/window_inner_manager.cpp index 46dc0b9..f54b7c8 100644 --- a/window_manager/wmserver/src/window_inner_manager.cpp +++ b/window_manager/wmserver/src/window_inner_manager.cpp @@ -57,7 +57,7 @@ bool WindowInnerManager::Init() return false; } - FangTian::PointerDraw::GetInstance().Init(); + PointerDraw::GetInstance().Init(); WLOGFI("init window inner manager service success."); return true; @@ -312,7 +312,7 @@ void WindowInnerManager::ConsumePointerEvent(const std::shared_ptrGetPointerId(); if (pointerEvent->GetPointerItem(pointId, pointerItem)) { - FangTian::PointerDraw::GetInstance().AsyncMove(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); + PointerDraw::GetInstance().AsyncMove(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); } } -- Gitee From 27759d5b46cb0fcd5cdf1bfe41132d63fda33a66 Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Fri, 7 Jul 2023 10:02:01 +0800 Subject: [PATCH 3/6] Revert "use lambda" This reverts commit 416b0d22e7c55bbd6c86583a4e2268370fbb794d. --- window_manager/pointer_draw/pointer_draw.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/window_manager/pointer_draw/pointer_draw.cpp b/window_manager/pointer_draw/pointer_draw.cpp index 509eae4..342e479 100644 --- a/window_manager/pointer_draw/pointer_draw.cpp +++ b/window_manager/pointer_draw/pointer_draw.cpp @@ -54,11 +54,21 @@ WMError PointerDraw::Init() void PointerDraw::AsyncMove(int32_t x, int32_t y) { - int32_t posx = (x >= 0) ? x : 0; - posx = (posx <= displayWidth_) ? posx : displayWidth_; + int32_t posx = x; + if (posx < 0) { + posx = 0; + } + if (posx > displayWidth_) { + posx = displayWidth_; + } - int32_t posy = (y >= 0) ? y : 0; - posy = (posy <= displayHeight_) ? posy : displayHeight_; + int32_t posy = y; + if (posy < 0) { + posy = 0; + } + if (posy > displayHeight_) { + posy = displayHeight_; + } PostAsyncTask([this, posx, posy]() { MoveTo(posx, posy); -- Gitee From 30cabfca1a71f91642b537956a1d036b57ace3c0 Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Fri, 7 Jul 2023 10:02:07 +0800 Subject: [PATCH 4/6] Revert "remove useless code" This reverts commit 93f711154baad0b810d73c61965378b276bf880d. --- window_manager/pointer_draw/pointer_draw.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/window_manager/pointer_draw/pointer_draw.cpp b/window_manager/pointer_draw/pointer_draw.cpp index 342e479..f31f877 100644 --- a/window_manager/pointer_draw/pointer_draw.cpp +++ b/window_manager/pointer_draw/pointer_draw.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Technologies Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,9 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "pointer_draw.h" +#include "unistd.h" +#include + #include "window_manager_hilog.h" #include "display_manager_service_inner.h" #include "ui/rs_surface_extractor.h" -- Gitee From 26bd1050aa17901703af3ae8368a422e07475d87 Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Fri, 7 Jul 2023 10:02:13 +0800 Subject: [PATCH 5/6] Revert "enable pointer draw" This reverts commit 3528b5e8cad879c1ad247879673d1935ad416a22. --- window_manager/pointer_draw/pointer_draw.cpp | 176 ------------------ window_manager/pointer_draw/pointer_draw.h | 55 ------ window_manager/wmserver/ft_build/BUILD.gn | 7 +- .../wmserver/src/window_inner_manager.cpp | 12 -- 4 files changed, 3 insertions(+), 247 deletions(-) delete mode 100644 window_manager/pointer_draw/pointer_draw.cpp delete mode 100644 window_manager/pointer_draw/pointer_draw.h diff --git a/window_manager/pointer_draw/pointer_draw.cpp b/window_manager/pointer_draw/pointer_draw.cpp deleted file mode 100644 index f31f877..0000000 --- a/window_manager/pointer_draw/pointer_draw.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "pointer_draw.h" - -#include "unistd.h" -#include - -#include "window_manager_hilog.h" -#include "display_manager_service_inner.h" -#include "ui/rs_surface_extractor.h" -#include "transaction/rs_transaction.h" - -namespace OHOS { -namespace Rosen { -namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "PointerDraw"}; - constexpr int32_t ICON_WIDTH = 30; - constexpr int32_t ICON_HEIGHT = 30; -} -WM_IMPLEMENT_SINGLE_INSTANCE(PointerDraw) - -WMError PointerDraw::Init() -{ - if (InitDisplayInfo() != WMError::WM_OK) { - WLOGFE("InitDisplayInfo fail"); - return WMError::WM_ERROR_INNER; - } - - if (InitLayerNode() != WMError::WM_OK) { - WLOGFE("InitLayerNode fail"); - return WMError::WM_ERROR_INNER; - } - - if (InitDisplayNode() != WMError::WM_OK) { - WLOGFE("InitDisplayNode fail"); - return WMError::WM_ERROR_INNER; - } - - runner_ = AppExecFwk::EventRunner::Create("PointerDraw"); - handler_ = std::make_shared(runner_); - - return WMError::WM_OK; -} - -void PointerDraw::AsyncMove(int32_t x, int32_t y) -{ - int32_t posx = x; - if (posx < 0) { - posx = 0; - } - if (posx > displayWidth_) { - posx = displayWidth_; - } - - int32_t posy = y; - if (posy < 0) { - posy = 0; - } - if (posy > displayHeight_) { - posy = displayHeight_; - } - - PostAsyncTask([this, posx, posy]() { - MoveTo(posx, posy); - }); -} - -WMError PointerDraw::InitDisplayInfo() -{ - auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDefaultDisplay(); - if (displayInfo == nullptr) { - WLOGFE("GetDefaultDisplay fail"); - return WMError::WM_ERROR_NULLPTR; - } - displayWidth_ = displayInfo->GetWidth(); - displayHeight_ = displayInfo->GetHeight(); - displayId_ = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); - - if (displayWidth_ <=0 || displayHeight_ <= 0) { - WLOGFE("Invalid display info"); - return WMError::WM_ERROR_INVALID_PARAM; - } - - return WMError::WM_OK; -} - -WMError PointerDraw::InitLayerNode() -{ - RSSurfaceNodeConfig config; - surfaceNode_ = RSSurfaceNode::Create(config); - if (surfaceNode_ == nullptr) { - WLOGFE("RSSurfaceNode::Create fail"); - return WMError::WM_ERROR_NULLPTR; - } - - surfaceNode_->SetBounds(displayWidth_ / 2, displayHeight_ / 2, ICON_WIDTH, ICON_HEIGHT); - rsSurface_ = RSSurfaceExtractor::ExtractRSSurface(surfaceNode_); - if (rsSurface_ == nullptr) { - WLOGFE("ExtractRSSurface fail"); - return WMError::WM_ERROR_NULLPTR; - } - - auto framePtr = rsSurface_->RequestFrame(ICON_WIDTH, ICON_HEIGHT); - if (framePtr == nullptr) { - WLOGFE("RequestFrame fail"); - return WMError::WM_ERROR_NULLPTR; - } - - auto canvas = framePtr->GetCanvas(); - canvas->clear(SK_ColorTRANSPARENT); - SkPaint paint; - paint.setAntiAlias(true); - paint.setStyle(SkPaint::kFill_Style); - paint.setStrokeWidth(20); - paint.setStrokeJoin(SkPaint::kRound_Join); - paint.setColor(SK_ColorBLUE); - canvas->drawRect(SkRect::MakeXYWH(0, 0, ICON_WIDTH, ICON_HEIGHT), paint); - framePtr->SetDamageRegion(0, 0, ICON_WIDTH, ICON_HEIGHT); - rsSurface_->FlushFrame(framePtr); - - return WMError::WM_OK; -} - -WMError PointerDraw::InitDisplayNode() -{ - RSDisplayNodeConfig config; - displayNode_ = RSDisplayNode::Create(config); - if (displayNode_ == nullptr) { - WLOGFE("RSDisplayNode::Create fail"); - return WMError::WM_ERROR_NULLPTR; - } - - displayNode_->SetScreenId(displayId_); - displayNode_->SetBounds(0, 0, displayWidth_, displayHeight_); - displayNode_->AddChild(surfaceNode_, -1); - RSTransaction::FlushImplicitTransaction(); - - return WMError::WM_OK; -} - -WMError PointerDraw::MoveTo(int32_t x, int32_t y) -{ - if (surfaceNode_ == nullptr) { - WLOGFE("surfaceNode_ is nullptr"); - return WMError::WM_ERROR_NULLPTR; - } - - surfaceNode_->SetBounds(x, y, ICON_WIDTH, ICON_HEIGHT); - RSTransaction::FlushImplicitTransaction(); - - return WMError::WM_OK; -} - -void PointerDraw::PostAsyncTask(Task task) -{ - if (handler_ != nullptr) { - bool ret = handler_->PostTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE); - if (!ret) { - WLOGFE("EventHandler PostTask Failed"); - } - } -} -} // Rosen -} // OHOS diff --git a/window_manager/pointer_draw/pointer_draw.h b/window_manager/pointer_draw/pointer_draw.h deleted file mode 100644 index 5dbf302..0000000 --- a/window_manager/pointer_draw/pointer_draw.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Technologies Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POINTER_DRAW_H -#define POINTER_DRAW_H - -#include "graphic_common.h" -#include "wm_single_instance.h" -#include "ui/rs_display_node.h" -#include "ui/rs_surface_node.h" -#include "event_handler.h" - -namespace OHOS { -namespace Rosen { -class PointerDraw { -WM_DECLARE_SINGLE_INSTANCE_BASE(PointerDraw); -public: - WMError Init(); - void AsyncMove(int32_t x, int32_t y); - -private: - PointerDraw() = default; - virtual ~PointerDraw() = default; - using Task = std::function; - - WMError InitDisplayInfo(); - WMError InitLayerNode(); - WMError InitDisplayNode(); - WMError MoveTo(int32_t x, int32_t y); - void PostAsyncTask(Task task); - - int32_t displayWidth_ = 0; - int32_t displayHeight_ = 0; - uint64_t displayId_ = 0; - RSDisplayNode::SharedPtr displayNode_ = nullptr; - RSSurfaceNode::SharedPtr surfaceNode_ = nullptr; - std::shared_ptr rsSurface_ = nullptr; - std::shared_ptr runner_ = nullptr; - std::shared_ptr handler_ = nullptr; -}; -} // namespace Rosen -} // namespace OHOS -#endif // POINTER_DRAW_H diff --git a/window_manager/wmserver/ft_build/BUILD.gn b/window_manager/wmserver/ft_build/BUILD.gn index 6f1cf2f..5eed6d5 100644 --- a/window_manager/wmserver/ft_build/BUILD.gn +++ b/window_manager/wmserver/ft_build/BUILD.gn @@ -25,7 +25,6 @@ config("libwms_config") { "$window_manager_path/interfaces/innerkits/wm", "$window_manager_path/interfaces/innerkits/dm", "$window_manager_path/ft_adapter", - "$window_manager_path/pointer_draw", "$window_manager_path/wm/include", "$window_manager_path/utils/include", "$window_manager_path/dm/include", @@ -41,7 +40,6 @@ ft_shared_library("libwms") { defines = ft_defines sources = [ - "$window_manager_path/pointer_draw/pointer_draw.cpp", "$window_manager_path/wm/src/zidl/window_manager_agent_proxy.cpp", "$window_manager_path/wm/src/zidl/window_proxy.cpp", "$window_manager_path/wmserver/src/accessibility_connection.cpp", @@ -94,10 +92,11 @@ ft_shared_library("libwms") { "$window_manager_path/dmserver/ft_build:libdms", "$window_manager_path/utils/ft_build:libwmutil", "$window_manager_path/wm/ft_build:libwm", + + "//build/gn/configs/system_libs:safwk", "//build/gn/configs/system_libs:eventhandler", + "//build/gn/configs/system_libs:skia", "//build/gn/configs/system_libs:image", "//build/gn/configs/system_libs:mmi", - "//build/gn/configs/system_libs:safwk", - "//build/gn/configs/system_libs:skia", ] } diff --git a/window_manager/wmserver/src/window_inner_manager.cpp b/window_manager/wmserver/src/window_inner_manager.cpp index f54b7c8..7471358 100644 --- a/window_manager/wmserver/src/window_inner_manager.cpp +++ b/window_manager/wmserver/src/window_inner_manager.cpp @@ -17,7 +17,6 @@ #include "ability_manager_client.h" #include "memory_guard.h" -#include "pointer_draw.h" #include "window.h" #include "window_manager_hilog.h" @@ -57,8 +56,6 @@ bool WindowInnerManager::Init() return false; } - PointerDraw::GetInstance().Init(); - WLOGFI("init window inner manager service success."); return true; } @@ -307,15 +304,6 @@ void WindowInnerManager::NotifyWindowRemovedOrDestroyed(uint32_t windowId) void WindowInnerManager::ConsumePointerEvent(const std::shared_ptr& pointerEvent) { - if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE && - pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { - MMI::PointerEvent::PointerItem pointerItem; - int32_t pointId = pointerEvent->GetPointerId(); - if (pointerEvent->GetPointerItem(pointId, pointerItem)) { - PointerDraw::GetInstance().AsyncMove(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); - } - } - uint32_t windowId = static_cast(pointerEvent->GetAgentWindowId()); if (moveDragController_->GetActiveWindowId() != windowId || moveDragController_->GetActiveWindowId() == INVALID_WINDOW_ID) { -- Gitee From c5f78389b6fa8243ac1cae5654ec52e32643f9d0 Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Fri, 7 Jul 2023 17:08:06 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E5=A4=B4=E6=96=87=E4=BB=B6=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_manager/ft_pointer_draw/BUILD.gn | 2 +- .../ft_pointer_draw_manager_adapter.cpp | 16 +-- .../i_pointer_drawing_manager.h | 135 +++++++++++++----- .../ft_pointer_draw/pointer_draw_manager.cpp | 21 +-- .../ft_pointer_draw/pointer_draw_manager.h | 71 +++++++-- 5 files changed, 180 insertions(+), 65 deletions(-) diff --git a/window_manager/ft_pointer_draw/BUILD.gn b/window_manager/ft_pointer_draw/BUILD.gn index 7f3aa55..75bdb27 100644 --- a/window_manager/ft_pointer_draw/BUILD.gn +++ b/window_manager/ft_pointer_draw/BUILD.gn @@ -24,7 +24,7 @@ config("pointer_draw_config") { include_dirs = [ "$window_manager_path/interfaces/innerkits/dm", - "/usr/local/include/mmi", + #"/usr/local/include/mmi", ] } diff --git a/window_manager/ft_pointer_draw/ft_pointer_draw_manager_adapter.cpp b/window_manager/ft_pointer_draw/ft_pointer_draw_manager_adapter.cpp index 9962963..6a9dd55 100644 --- a/window_manager/ft_pointer_draw/ft_pointer_draw_manager_adapter.cpp +++ b/window_manager/ft_pointer_draw/ft_pointer_draw_manager_adapter.cpp @@ -15,10 +15,6 @@ #include #include #include "i_pointer_drawing_manager.h" -#include "display_info.h" - -namespace OHOS { -namespace MMI { #if defined(__cplusplus) extern "C" { @@ -72,13 +68,18 @@ bool FTPtrDrawMgrInit(const uintptr_t instanceHdl) return true; } -bool FTPtrDrawMgrUpdataDispInfo(const uintptr_t instanceHdl, const DisplayInfo& displayInfo) +bool FTPtrDrawMgrUpdataDispInfo(const uintptr_t instanceHdl, int32_t displayId, int32_t width, int32_t height) { PointerDrawPtr instance = FindPointerDraw(instanceHdl); if (instance == nullptr) { return false; } + ScreenDisplayInfo displayInfo; + displayInfo.width = width; + displayInfo.height = height; + displayInfo.id = displayId; + instance->UpdateDisplayInfo(displayInfo); return true; } @@ -90,13 +91,10 @@ bool FTPtrDrawMgrDrawPointer(const uintptr_t instanceHdl, int32_t displayId, int return false; } - instance->DrawPointer(displayId, physicalX, physicalY); + instance->DrawPointer(displayId, physicalX, physicalY, 0); return true; } #if defined(__cplusplus) } #endif // __cplusplus - -} // MMI -} // OHOS \ No newline at end of file diff --git a/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h b/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h index 385d003..a24b860 100644 --- a/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h +++ b/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h @@ -17,54 +17,119 @@ #define I_POINTER_DRAWING_MANAGER_H #include +#include +#include -#include "display_info.h" -#include "struct_multimodal.h" +enum Direction { + Direction0, // Rotating the display clockwise by 0 degree + Direction90, // Rotating the display clockwise by 90 degrees + Direction180, // Rotating the display clockwise by 180 degrees + Direction270, // Rotating the display clockwise by 270 degrees +}; + +struct Rect { + int32_t x; // X coordinate of the upper left corner + int32_t y; // Y coordinate of the upper left corner + int32_t width; + int32_t height; +}; + +struct WindowInfo { + static constexpr int32_t MAX_HOTAREA_COUNT = 10; // Maximum number of hot areas + static constexpr uint32_t FLAG_BIT_UNTOUCHABLE = 1; // Untouchable window + int32_t id; // Globally unique identifier of the window + int32_t pid; // PID of the process where the window is located + int32_t uid; // UID of the process where the window is located + Rect area; // Window display area + + /** + * Number of touch response areas (excluding the mouse response areas) in the window. + * The value cannot exceed the value of MAX_HOTAREA_COUNT. + */ + std::vector defaultHotAreas; + + /** + * Number of mouse response areas in the window. The value cannot exceed the value of MAX_HOTAREA_COUNT. + */ + std::vector pointerHotAreas; + + /** + * Agent window ID + */ + int32_t agentWindowId; + + /** + * A 32-bit flag that represents the window status. If the 0th bit is 1, + * the window is untouchable; if the 0th bit is 0, the window is touchable. + */ + uint32_t flags; +}; + +/** + * Physical screen information + */ +struct ScreenDisplayInfo { + int32_t id; // Unique ID of the physical display + int32_t x; // X coordinate of the upper left corner on the logical screen + int32_t y; // Y coordinate of the upper left corner on the logical screen + + /** + * Display width, which is the logical width of the original screen when the rotation angle is 0. + * The value remains unchanged even if the display screen is rotated. + */ + int32_t width; + + /** + * Display height, which is the logical height of the original screen when the rotation angle is 0. + * The value remains unchanged even if the display screen is rotated. + */ + int32_t height; + + std::string name; // Name of the physical display, which is used for debugging + Direction direction; // Orientation of the physical display + + /** + * Unique screen ID, which is used to associate the corresponding touchscreen. The default value is default0. + */ + std::string uniq; +}; + +/** + * Logical screen information + * + * @since 9 + */ +struct DisplayGroupInfo { + int32_t width; // Width of the logical display + int32_t height; // Height of the logical display + int32_t focusWindowId; // ID of the focus window + /** + * List of window information of the logical display arranged in Z order, with the top window at the top + */ + std::vector windowsInfo; + std::vector displaysInfo; // Physical screen information list +}; -namespace OHOS { -namespace MMI { class IPointerDrawingManager { public: IPointerDrawingManager() = default; virtual ~IPointerDrawingManager() = default; - static std::shared_ptr GetInstance(); - virtual void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, - const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) {} - virtual void UpdateDisplayInfo(const DisplayInfo& displayInfo) {} + virtual void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, int32_t mouseStyle) {} + virtual void UpdateDisplayInfo(const ScreenDisplayInfo& displayInfo) {} virtual void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) {} - virtual void OnWindowInfo(const WinInfo &info) {} - virtual bool Init() - { - return true; - } + virtual void OnWindowInfo(int32_t windowPid, int32_t windowId) {} + virtual bool Init() { return true;} virtual void DeletePointerVisible(int32_t pid) {} - virtual int32_t SetPointerVisible(int32_t pid, bool visible) - { - return 0; - } - virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) - { - return 0; - } - virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) - { - return 0; - } + virtual int32_t SetPointerVisible(int32_t pid, bool visible) { return 0;} + virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) { return 0; } + virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) { return 0;} virtual void DrawPointerStyle() {} - virtual bool IsPointerVisible() - { - return false; - } + virtual bool IsPointerVisible() { return false; } virtual void SetMouseDisplayState(bool state) {} - virtual bool GetMouseDisplayState() const - { - return true; - } + virtual bool GetMouseDisplayState() const { return true; } virtual void SetPointerLocation(int32_t pid, int32_t x, int32_t y) {} public: static inline std::shared_ptr iPointDrawMgr_ { nullptr }; }; -} // namespace MMI -} // namespace OHOS #endif // I_POINTER_DRAWING_MANAGER_H \ No newline at end of file diff --git a/window_manager/ft_pointer_draw/pointer_draw_manager.cpp b/window_manager/ft_pointer_draw/pointer_draw_manager.cpp index a3ac259..c4be243 100644 --- a/window_manager/ft_pointer_draw/pointer_draw_manager.cpp +++ b/window_manager/ft_pointer_draw/pointer_draw_manager.cpp @@ -22,8 +22,8 @@ #include "transaction/rs_transaction.h" #include "image_source.h" -namespace OHOS { -namespace MMI { +using namespace OHOS; + namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "PointerDrawingManager"}; constexpr int32_t PATH_MAX = 200; @@ -57,8 +57,10 @@ bool PointerDrawingManager::Init() } void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, - const MOUSE_ICON mouseStyle) + int32_t mouseStyle) { + (void)mouseStyle; + if (!isDrawing_) { if (InitLayerNode(physicalX, physicalY) != WMError::WM_OK) { WLOGFE("InitLayerNode fail"); @@ -110,14 +112,14 @@ void PointerDrawingManager::SetPointerLocation(int32_t pid, int32_t x, int32_t y } } -void PointerDrawingManager::UpdateDisplayInfo(const DisplayInfo& displayInfo) +void PointerDrawingManager::UpdateDisplayInfo(const ScreenDisplayInfo& displayInfo) { displayWidth_ = displayInfo.width; displayHeight_ = displayInfo.height; displayId_ = displayInfo.id; if (displayWidth_ <= 0 || displayHeight_ <= 0) { - WLOGFE("Invalid DisplayInfo"); + WLOGFE("Invalid ScreenDisplayInfo"); } } @@ -210,6 +212,7 @@ WMError PointerDrawingManager::InitDisplayNode() WMError PointerDrawingManager::InitIconPixel() { +#ifndef USE_IMITATE_POINTER mouseIcons_ = { {DEFAULT, {ANGLE_NW, POINTER_PIXEL_PATH + "Default.png"}}, }; @@ -225,8 +228,10 @@ WMError PointerDrawingManager::InitIconPixel() WLOGFE("InitStyle fail"); return WMError::WM_ERROR_NULLPTR; } - return WMError::WM_OK; +#else + return WMError::WM_OK; +#endif } WMError PointerDrawingManager::CheckPixelFile(const std::string &filePath) @@ -312,6 +317,4 @@ SkColorType PointerDrawingManager::PixelFormatConvert(const Media::PixelFormat& break; } return colorType; -} -} // namespace MMI -} // namespace OHOS +} \ No newline at end of file diff --git a/window_manager/ft_pointer_draw/pointer_draw_manager.h b/window_manager/ft_pointer_draw/pointer_draw_manager.h index f2a9933..8bda51d 100644 --- a/window_manager/ft_pointer_draw/pointer_draw_manager.h +++ b/window_manager/ft_pointer_draw/pointer_draw_manager.h @@ -24,8 +24,6 @@ #include "pixel_map.h" #include "event_handler.h" -namespace OHOS { -namespace MMI { static constexpr unsigned int HILOG_DOMAIN_WINDOW = 0xD004200; #define _W_DFUNC HiviewDFX::HiLog::Debug @@ -47,6 +45,60 @@ static constexpr unsigned int HILOG_DOMAIN_WINDOW = 0xD004200; #define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) #define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +enum MOUSE_ICON { + DEFAULT = 0, + EAST = 1, + WEST = 2, + SOUTH = 3, + NORTH = 4, + WEST_EAST = 5, + NORTH_SOUTH = 6, + NORTH_EAST = 7, + NORTH_WEST = 8, + SOUTH_EAST = 9, + SOUTH_WEST = 10, + NORTH_EAST_SOUTH_WEST = 11, + NORTH_WEST_SOUTH_EAST = 12, + CROSS = 13, + CURSOR_COPY = 14, + CURSOR_FORBID = 15, + COLOR_SUCKER = 16, + HAND_GRABBING = 17, + HAND_OPEN = 18, + HAND_POINTING = 19, + HELP = 20, + CURSOR_MOVE = 21, + RESIZE_LEFT_RIGHT = 22, + RESIZE_UP_DOWN = 23, + SCREENSHOT_CHOOSE = 24, + SCREENSHOT_CURSOR = 25, + TEXT_CURSOR = 26, + ZOOM_IN = 27, + ZOOM_OUT = 28, + MIDDLE_BTN_EAST = 29, + MIDDLE_BTN_WEST = 30, + MIDDLE_BTN_SOUTH = 31, + MIDDLE_BTN_NORTH = 32, + MIDDLE_BTN_NORTH_SOUTH = 33, + MIDDLE_BTN_NORTH_EAST = 34, + MIDDLE_BTN_NORTH_WEST = 35, + MIDDLE_BTN_SOUTH_EAST = 36, + MIDDLE_BTN_SOUTH_WEST = 37, + MIDDLE_BTN_NORTH_SOUTH_WEST_EAST = 38, +}; + +enum ICON_TYPE { + ANGLE_E = 0, + ANGLE_S = 1, + ANGLE_W = 2, + ANGLE_N = 3, + ANGLE_SE = 4, + ANGLE_NE = 5, + ANGLE_SW = 6, + ANGLE_NW = 7, + ANGLE_CENTER = 8, +}; + class PointerDrawingManager : public IPointerDrawingManager { public: DISALLOW_COPY_AND_MOVE(PointerDrawingManager); @@ -54,26 +106,25 @@ public: ~PointerDrawingManager() = default; bool Init() override; - void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, - const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) override; - void UpdateDisplayInfo(const DisplayInfo& displayInfo) override; + void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, int32_t mouseStyle) override; + void UpdateDisplayInfo(const ScreenDisplayInfo& displayInfo) override; void SetPointerLocation(int32_t pid, int32_t x, int32_t y) override; void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) override {} - void OnWindowInfo(const WinInfo &info) override {} + void OnWindowInfo(int32_t windowPid, int32_t windowId) override {} void DeletePointerVisible(int32_t pid) override {} void SetMouseDisplayState(bool state) override {} void DrawPointerStyle() override {} int32_t SetPointerVisible(int32_t pid, bool visible) override { - return WMError::WM_OK; + return OHOS::WMError::WM_OK; } int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) override { - return WMError::WM_OK; + return OHOS::WMError::WM_OK; } int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) override { - return WMError::WM_OK; + return OHOS::WMError::WM_OK; } bool IsPointerVisible() override { @@ -110,6 +161,4 @@ private: std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; }; -} // namespace MMI -} // namespace OHOS #endif // POINTER_DRAW_H -- Gitee