• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 #ifndef RS_MAGIC_POINTER_RENDER_MANAGER_H
17 #define RS_MAGIC_POINTER_RENDER_MANAGER_H
18 
19 #include "feature/gpuComposition/rs_image_manager.h"
20 #include "ipc_callbacks/pointer_render/pointer_luminance_change_callback.h"
21 #include "pipeline/rs_processor.h"
22 #include "pipeline/rs_screen_render_node.h"
23 
24 #ifdef RS_ENABLE_VK
25 #include "feature/gpuComposition/rs_vk_image_manager.h"
26 #endif
27 
28 namespace OHOS::Rosen {
29 
30 class RSMagicPointerRenderManager {
31 public:
32     RSMagicPointerRenderManager() = default;
33     ~RSMagicPointerRenderManager() = default;
34 
35 #if (defined (RS_ENABLE_GL) && defined (RS_ENABLE_EGLIMAGE)) || defined (RS_ENABLE_VK)
36     static void InitInstance(const std::shared_ptr<RSImageManager>& imageManager);
37 #endif
38 
39     static RSMagicPointerRenderManager& GetInstance();
40     static int64_t GetCurrentTime();
41     void ProcessColorPicker(std::shared_ptr<RSProcessor> processor, std::shared_ptr<Drawing::GPUContext> gpuContext);
42     void SetPointerColorInversionConfig(float darkBuffer, float brightBuffer, int64_t interval, int32_t rangeSize);
43     void RegisterPointerLuminanceChangeCallback(pid_t pid, sptr<RSIPointerLuminanceChangeCallback> callback);
44     void UnRegisterPointerLuminanceChangeCallback(pid_t pid);
SetCacheImgForPointer(std::shared_ptr<Drawing::Image> cacheImgForPointer)45     void SetCacheImgForPointer(std::shared_ptr<Drawing::Image> cacheImgForPointer)
46     {
47         cacheImgForPointer_ = cacheImgForPointer;
48     }
49     void SetPointerColorInversionEnabled(bool enable);
50     bool GetPointerColorInversionEnabled();
51 
52 private:
53     void ExecutePointerLuminanceChangeCallback(int32_t brightness);
54     void CallPointerLuminanceChange(int32_t brightness);
55     bool CheckColorPickerEnabled();
56     void CalculateColorRange(RectI& pRect);
57     bool CalculateTargetLayer(std::shared_ptr<RSProcessor> processor);
58     void RunColorPickerTask();
59     std::shared_ptr<Drawing::Image> GetIntersectImageByLayer(BufferDrawParam& param);
60     bool GetIntersectImageBySubset(std::shared_ptr<Drawing::GPUContext> gpuContext);
61     std::shared_ptr<Drawing::Image> GetImageTexture(std::shared_ptr<Drawing::Image>& image);
62     void GetRectAndTargetLayer(std::vector<LayerInfoPtr>& layers, RectI& pRect, int displayNodeIndex);
63     void RunColorPickerTaskBackground(BufferDrawParam& param);
64     static int16_t CalcAverageLuminance(std::shared_ptr<Drawing::Image> image);
65 
66 private:
67     RectI rect_;
68     LayerInfoPtr target_;
69 #if (defined (RS_ENABLE_GL) && defined (RS_ENABLE_EGLIMAGE)) || defined (RS_ENABLE_VK)
70     std::shared_ptr<RSImageManager> imageManager_ = nullptr;
71 #endif
72     int16_t luminance_ = 0;
73     bool forceCPU_ = false;
74     std::shared_ptr<Drawing::Image> image_ = nullptr;
75     std::shared_ptr<Drawing::Image> imagePre_ = nullptr;
76     Drawing::BackendTexture backendTexture_;
77     Drawing::BackendTexture backendTexturePre_;
78     Drawing::BitmapFormat bitmapFormat_;
79     std::atomic<bool> taskDoing_ = false;
80     bool isEnableCursorInversion_ = false;
81     std::shared_ptr<Drawing::Image> cacheImgForPointer_ = nullptr;
82     std::mutex mtx_;
83     std::map<pid_t, sptr<RSIPointerLuminanceChangeCallback>> colorChangeListeners_;
84     enum class CursorBrightness {
85         NONE,
86         BRIGHT,
87         DARK
88     };
89     CursorBrightness brightnessMode_ = CursorBrightness::NONE;
90     int64_t lastColorPickerTime_ = 0;
91     int64_t colorSamplingInterval_ = 50;
92     int32_t rangeSize_ = 0;
93     float darkBuffer_ = 0.58f;
94     float brightBuffer_ = 0.40f;
95 };
96 }
97 #endif // RS_MAGIC_POINTER_RENDER_MANAGER_H