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_POINTER_RENDER_MANAGER_H 17 #define RS_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 "pipeline/rs_vk_image_manager.h" 24 #endif 25 26 namespace OHOS::Rosen { 27 28 class RSPointerRenderManager { 29 public: 30 RSPointerRenderManager() = default; 31 ~RSPointerRenderManager() = 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 RSPointerRenderManager& 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 SetPointerColorInversionEnabled(bool enable); 46 void RegisterPointerLuminanceChangeCallback(pid_t pid, sptr<RSIPointerLuminanceChangeCallback> callback); 47 void UnRegisterPointerLuminanceChangeCallback(pid_t pid); SetCacheImgForPointer(std::shared_ptr<Drawing::Image> cacheImgForPointer)48 void SetCacheImgForPointer(std::shared_ptr<Drawing::Image> cacheImgForPointer) 49 { 50 cacheImgForPointer_ = cacheImgForPointer; 51 } 52 53 private: 54 void ExecutePointerLuminanceChangeCallback(int32_t brightness); 55 void CallPointerLuminanceChange(int32_t brightness); 56 bool CheckColorPickerEnabled(); 57 void CalculateColorRange(RectI& pRect); 58 bool CalculateTargetLayer(std::shared_ptr<RSProcessor> processor); 59 void RunColorPickerTask(); 60 std::shared_ptr<Drawing::Image> GetIntersectImageByLayer(const BufferDrawParam& param); 61 bool GetIntersectImageBySubset(std::shared_ptr<Drawing::GPUContext> gpuContext); 62 #if defined (RS_ENABLE_VK) 63 std::shared_ptr<Drawing::Image> GetIntersectImageFromVK(Drawing::RectI& imgCutRect, 64 std::shared_ptr<Drawing::GPUContext>& context, const BufferDrawParam& param); 65 #endif 66 #if defined (RS_ENABLE_GL) && defined (RS_ENABLE_EGLIMAGE) 67 std::shared_ptr<Drawing::Image> GetIntersectImageFromGL(Drawing::RectI& imgCutRect, 68 std::shared_ptr<Drawing::GPUContext>& context, const BufferDrawParam& param); 69 #endif 70 std::shared_ptr<Drawing::Image> GetImageTexture(std::shared_ptr<Drawing::Image>& image); 71 void GetRectAndTargetLayer(std::vector<LayerInfoPtr>& layers, RectI& pRect, int displayNodeIndex); 72 void RunColorPickerTaskBackground(const BufferDrawParam& param); 73 int16_t CalcAverageLuminance(std::shared_ptr<Drawing::Image> image); 74 75 private: 76 RectI rect_; 77 LayerInfoPtr target_; 78 #if defined (RS_ENABLE_VK) 79 std::shared_ptr<RSVkImageManager> vkImageManager_ = nullptr; 80 #endif 81 #if defined (RS_ENABLE_GL) && defined (RS_ENABLE_EGLIMAGE) 82 std::shared_ptr<RSEglImageManager> eglImageManager_ = nullptr; 83 #endif 84 int16_t luminance_ = 0; 85 bool forceCPU_ = false; 86 std::shared_ptr<Drawing::Image> image_ = nullptr; 87 Drawing::BackendTexture backendTexture_; 88 Drawing::BackendTexture backendTexturePre_; 89 Drawing::BitmapFormat bitmapFormat_; 90 std::atomic<bool> taskDoing_ = false; 91 bool isEnableCursorInversion_ = false; 92 std::shared_ptr<Drawing::Image> cacheImgForPointer_ = nullptr; 93 std::mutex mtx_; 94 std::mutex cursorInvertMutex_; 95 std::map<pid_t, sptr<RSIPointerLuminanceChangeCallback>> colorChangeListeners_; 96 enum class CursorBrightness { 97 NONE, 98 BRIGHT, 99 DARK 100 }; 101 CursorBrightness brightnessMode_ = CursorBrightness::NONE; 102 int64_t lastColorPickerTime_ = 0; 103 int64_t colorSamplingInterval_ = 50; 104 int32_t rangeSize_ = 0; 105 float darkBuffer_ = 0.58f; 106 float brightBuffer_ = 0.40f; 107 }; 108 } 109 #endif // RS_POINTER_RENDER_MANAGER_H