• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef USE_ROSEN_DRAWING
34 using OverdrawColorArray = std::array<SkColor, OverdrawColorArrayLength>;
35 #else
36 using OverdrawColorArray = std::array<Drawing::ColorQuad, OverdrawColorArrayLength>;
37 #endif
38 class RSB_EXPORT RSOverdrawController {
39 public:
40     static RSB_EXPORT RSOverdrawController &GetInstance();
41 
42     ~RSOverdrawController() = default;
43 
44     void SetDelegate(const std::shared_ptr<RSDelegate> &delegate);
45     bool IsEnabled() const;
46     void SetEnable(bool enable);
47     OverdrawColorArray GetColorArray() const;
48 #ifndef USE_ROSEN_DRAWING
49     std::map<int, SkColor> GetColorMap() const;
50 #else
51     std::map<int, Drawing::ColorQuad> GetColorMap() const;
52 #endif
53 
54     template<class RSCanvasListenerImpl>
CreateListener(RSPaintFilterCanvas * canvas)55     std::shared_ptr<RSCanvasListenerImpl> CreateListener(RSPaintFilterCanvas *canvas)
56     {
57         if (enabled_ == true && canvas != nullptr) {
58             auto listener = std::make_shared<RSCanvasListenerImpl>(*canvas);
59             if (listener->IsValid() == false) {
60                 ROSEN_LOGD("CreateListener %s failed", listener->Name());
61                 return nullptr;
62             }
63             return listener;
64         }
65         return nullptr;
66     }
67 
68 private:
69     RSOverdrawController();
70     RSOverdrawController(RSOverdrawController &&) = delete;
71     RSOverdrawController(const RSOverdrawController &) = delete;
72     RSOverdrawController &operator =(RSOverdrawController &&) = delete;
73     RSOverdrawController &operator =(const RSOverdrawController &) = delete;
74 
75     static void SwitchFunction(const char *key, const char *value, void *context);
76     static void OnColorChange(const char *key, const char *value, void *context);
77 
78     std::shared_ptr<RSDelegate> delegate_ = nullptr;
79     bool enabled_ = false;
80 
81     // colors
82     mutable std::mutex colorMutex_;
83     std::vector<uint32_t> colors_;
84     OverdrawColorArray colorArray_ = {
85         0x00000000,
86         0x00000000,
87         0x220000ff,
88         0x2200ff00,
89         0x22ff0000,
90         0x44ff0000,
91     };
92 #ifndef USE_ROSEN_DRAWING
93     std::map<int, SkColor> colorMap_ = {
94         {0, 0x22ff0000},
95         {1, 0x00000000},
96         {2, 0x220000ff},
97         {3, 0x2200ff00},
98         {4, 0x22ff0000},
99 #else
100     std::map<int, Drawing::ColorQuad> colorMap_ = {
101         {0, 0x22ff0000},
102         {1, 0x00000000},
103         {2, 0x220000ff},
104         {3, 0x2200ff00},
105         {4, 0x22ff0000},
106 #endif
107     };
108 };
109 } // namespace Rosen
110 } // namespace OHOS
111 
112 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_OVERDRAW_CONTROLLER_H
113