1 /* 2 * Copyright (c) 2022-2023 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 RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_OVERDRAW_CONTROLLER_H 17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_OVERDRAW_CONTROLLER_H 18 19 #include <array> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include <vector> 24 25 #include "common/rs_macros.h" 26 #include "delegate/rs_delegate.h" 27 #include "platform/common/rs_log.h" 28 #include "rs_listened_canvas.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 constexpr auto OverdrawColorArrayLength = 6; 33 using OverdrawColorArray = std::array<Drawing::ColorQuad, OverdrawColorArrayLength>; 34 class RSB_EXPORT RSOverdrawController { 35 public: 36 static RSB_EXPORT RSOverdrawController &GetInstance(); 37 38 ~RSOverdrawController() = default; 39 40 void SetDelegate(const std::shared_ptr<RSDelegate> &delegate); 41 bool IsEnabled() const; 42 void SetEnable(bool enable); 43 OverdrawColorArray GetColorArray() const; 44 std::map<int, Drawing::ColorQuad> GetColorMap() const; 45 46 template<class RSCanvasListenerImpl> CreateListener(RSPaintFilterCanvas * canvas)47 std::shared_ptr<RSCanvasListenerImpl> CreateListener(RSPaintFilterCanvas *canvas) 48 { 49 if (enabled_ == true && canvas != nullptr) { 50 auto listener = std::make_shared<RSCanvasListenerImpl>(*canvas); 51 if (listener->IsValid() == false) { 52 ROSEN_LOGD("CreateListener %{public}s failed", listener->Name()); 53 return nullptr; 54 } 55 return listener; 56 } 57 return nullptr; 58 } 59 60 private: 61 RSOverdrawController(); 62 RSOverdrawController(RSOverdrawController &&) = delete; 63 RSOverdrawController(const RSOverdrawController &) = delete; 64 RSOverdrawController &operator =(RSOverdrawController &&) = delete; 65 RSOverdrawController &operator =(const RSOverdrawController &) = delete; 66 67 static void SwitchFunction(const char *key, const char *value, void *context); 68 static void OnColorChange(const char *key, const char *value, void *context); 69 70 std::shared_ptr<RSDelegate> delegate_ = nullptr; 71 bool enabled_ = false; 72 73 // colors 74 mutable std::mutex colorMutex_; 75 std::vector<uint32_t> colors_; 76 OverdrawColorArray colorArray_ = { 77 0x00000000, 78 0x00000000, 79 0x220000ff, 80 0x2200ff00, 81 0x22ff0000, 82 0x44ff0000, 83 }; 84 std::map<int, Drawing::ColorQuad> colorMap_ = { 85 {0, 0x22ff0000}, 86 {1, 0x00000000}, 87 {2, 0x220000ff}, 88 {3, 0x2200ff00}, 89 {4, 0x22ff0000}, 90 }; 91 }; 92 } // namespace Rosen 93 } // namespace OHOS 94 95 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_OVERDRAW_CONTROLLER_H 96