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