diff --git a/build/gn/BUILD.gn b/build/gn/BUILD.gn index 093ef43c0f8e0dca5c5be8e4c8c6b7b0133bd400..850cff34a71ed7aa25bec14bac6c15462b60f1f2 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 Binary files /dev/null and b/etc/icon/Default.png differ diff --git a/window_manager/ft_pointer_draw/BUILD.gn b/window_manager/ft_pointer_draw/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..864f784544a82fa0aa4f4837bc49e6a111d8461e --- /dev/null +++ b/window_manager/ft_pointer_draw/BUILD.gn @@ -0,0 +1,49 @@ +# 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. + +import("//build/gn/fangtian.gni") +import("//config.gni") + +config("pointer_draw_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wno-c++11-narrowing", + "-DUSE_IMITATE_POINTER", + ] + + include_dirs = [ + "$window_manager_path/interfaces/innerkits/dm", + ] +} + +ft_shared_library("libpointerdraw") { + sources = [ + "pointer_draw_manager.cpp", + "ft_pointer_draw_manager_adapter.cpp", + ] + + configs = [ + ":pointer_draw_config", + ] + + deps = [ + "$display_server_root/rosen/modules/render_service_base/ft_build:librender_service_base", + "$display_server_root/rosen/modules/render_service_client/ft_build:librender_service_client", + "$window_manager_path/dmserver/ft_build:libdms", + "//build/gn/configs/system_libs:eventhandler", + "//build/gn/configs/system_libs:image", + "//build/gn/configs/system_libs:safwk", + "//build/gn/configs/system_libs:skia", + ] +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..ad0617595934ea3212404a492fd50425254d34ba --- /dev/null +++ b/window_manager/ft_pointer_draw/ft_pointer_draw_manager_adapter.cpp @@ -0,0 +1,101 @@ +/* + * 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 +#include +#include "i_pointer_drawing_manager.h" + +#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, 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; +} + +bool FTPtrDrawMgrDrawPointer(const uintptr_t instanceHdl, int32_t displayId, int32_t physicalX, int32_t physicalY) +{ + int32_t defaultStyle = 0; + PointerDrawPtr instance = FindPointerDraw(instanceHdl); + if (instance == nullptr) { + return false; + } + + instance->DrawPointer(displayId, physicalX, physicalY, defaultStyle); + return true; +} + +#if defined(__cplusplus) +} +#endif // __cplusplus 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 0000000000000000000000000000000000000000..9385e75bb2dd927e08c1c913d52e4edb925ae452 --- /dev/null +++ b/window_manager/ft_pointer_draw/i_pointer_drawing_manager.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2023 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 +#include + +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 +}; + +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, int32_t mouseStyle) {} + virtual void UpdateDisplayInfo(const ScreenDisplayInfo& displayInfo) {} + virtual void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) {} + 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 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) {} +}; +#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 0000000000000000000000000000000000000000..64ad57062429f673558999d704d4814e453ae9f0 --- /dev/null +++ b/window_manager/ft_pointer_draw/pointer_draw_manager.cpp @@ -0,0 +1,318 @@ +/* + * 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" + +using namespace OHOS; + +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() +{ + static std::shared_ptr instance = std::make_shared(); + return instance; +} + +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, + int32_t mouseStyle) +{ + (void)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 ScreenDisplayInfo& displayInfo) +{ + displayWidth_ = displayInfo.width; + displayHeight_ = displayInfo.height; + displayId_ = displayInfo.id; + + if (displayWidth_ <= 0 || displayHeight_ <= 0) { + WLOGFE("Invalid ScreenDisplayInfo"); + } +} + +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() +{ +#ifndef USE_IMITATE_POINTER + 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; +#else + return WMError::WM_OK; +#endif +} + +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; +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..8bda51db3ecdc11d24889f87f0d6a1d1dabf67a2 --- /dev/null +++ b/window_manager/ft_pointer_draw/pointer_draw_manager.h @@ -0,0 +1,164 @@ +/* + * 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" + +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__) + +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); + PointerDrawingManager() = default; + ~PointerDrawingManager() = default; + + bool Init() 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(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 OHOS::WMError::WM_OK; + } + int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) override + { + return OHOS::WMError::WM_OK; + } + int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) override + { + return OHOS::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; +}; +#endif // POINTER_DRAW_H diff --git a/window_manager/wmserver/ft_build/BUILD.gn b/window_manager/wmserver/ft_build/BUILD.gn index cb94cc5756e019f2a808c4fae65c9e669cf2c390..5eed6d5d4e50d39086c481069140657a2c0d44f3 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", - "pointer_draw", "$window_manager_path/wm/include", "$window_manager_path/utils/include", "$window_manager_path/dm/include", @@ -77,7 +76,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 = [ @@ -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/ft_build/pointer_draw/pointer_draw.cpp b/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.cpp deleted file mode 100644 index 79eea750442d6d6ffe6c124e2fdc6005c9151584..0000000000000000000000000000000000000000 --- a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.cpp +++ /dev/null @@ -1,164 +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. - */ - -#include "pointer_draw.h" - -#include "window_manager_hilog.h" -#include "display_manager_service_inner.h" -#include "ui/rs_surface_extractor.h" -#include "transaction/rs_transaction.h" - -using namespace OHOS; -using namespace OHOS::Rosen; - -namespace FangTian { -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 >= 0) ? x : 0; - posx = (posx <= displayWidth_) ? posx : displayWidth_; - - int32_t posy = (y >= 0) ? y : 0; - posy = (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(0, 0, 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.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"); - } - } -} -} // FangTian diff --git a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.h b/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.h deleted file mode 100644 index 5ded3dc5fbcd13b38fc56fca1121cc61b3e751cf..0000000000000000000000000000000000000000 --- a/window_manager/wmserver/ft_build/pointer_draw/pointer_draw.h +++ /dev/null @@ -1,53 +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 FangTian { -class PointerDraw { -WM_DECLARE_SINGLE_INSTANCE_BASE(PointerDraw); -public: - OHOS::WMError Init(); - void AsyncMove(int32_t x, int32_t y); - -private: - PointerDraw() = default; - 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); - 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; -}; -} // namespace FangTian -#endif // POINTER_DRAW_H diff --git a/window_manager/wmserver/src/window_inner_manager.cpp b/window_manager/wmserver/src/window_inner_manager.cpp index 46dc0b91bc46cbe20f78eafd3ee66553b9cee98e..747135890ba2878ba71bcdc931277ad279608171 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; } - FangTian::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)) { - FangTian::PointerDraw::GetInstance().AsyncMove(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); - } - } - uint32_t windowId = static_cast(pointerEvent->GetAgentWindowId()); if (moveDragController_->GetActiveWindowId() != windowId || moveDragController_->GetActiveWindowId() == INVALID_WINDOW_ID) {