• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_RS_PAINT_FILTER_CANVAS_H
17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_PAINT_FILTER_CANVAS_H
18 
19 #include <include/utils/SkPaintFilterCanvas.h>
20 #include <stack>
21 #include <vector>
22 
23 #include "include/core/SkSurface.h"
24 
25 #include "common/rs_macros.h"
26 
27 class SkDrawable;
28 namespace OHOS {
29 namespace Rosen {
30 
31 class RSB_EXPORT RSPaintFilterCanvas : public SkPaintFilterCanvas {
32 public:
33     RSPaintFilterCanvas(SkCanvas* canvas, float alpha = 1.0f);
34     RSPaintFilterCanvas(SkSurface* skSurface, float alpha = 1.0f);
~RSPaintFilterCanvas()35     ~RSPaintFilterCanvas() override {};
36 
37     void MultiplyAlpha(float alpha);
38     float GetAlpha() const;
39 
40     int SaveAlpha();
41     void RestoreAlpha();
42     void RestoreAlphaToCount(int count);
43 
44     std::pair<int, int> SaveCanvasAndAlpha();
45     void RestoreCanvasAndAlpha(std::pair<int, int>& count);
46 
47     SkSurface* GetSurface() const;
48 
SetHighContrast(bool enabled)49     void SetHighContrast(bool enabled)
50     {
51         isHighContrastEnabled_  = enabled;
52     }
isHighContrastEnabled()53     bool isHighContrastEnabled() const
54     {
55         return isHighContrastEnabled_;
56     }
57 
SetCacheEnabled(bool enabled)58     void SetCacheEnabled(bool enabled)
59     {
60         isCacheEnabled_ = enabled;
61     }
isCacheEnabled()62     bool isCacheEnabled() const
63     {
64         return isCacheEnabled_;
65     }
66 
SetVisibleRect(SkRect visibleRect)67     void SetVisibleRect(SkRect visibleRect)
68     {
69         visibleRect_ = visibleRect;
70     }
71 
GetVisibleRect()72     SkRect GetVisibleRect() const
73     {
74         return visibleRect_;
75     }
76 
77 protected:
78     bool onFilter(SkPaint& paint) const override;
79     void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) override;
80 
81 private:
82     SkSurface* skSurface_ = nullptr;
83     std::stack<float> alphaStack_;
84     std::atomic_bool isHighContrastEnabled_ { false };
85     bool isCacheEnabled_ { false };
86     SkRect visibleRect_ = SkRect::MakeEmpty();
87 };
88 
89 } // namespace Rosen
90 } // namespace OHOS
91 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_PAINT_FILTER_CANVAS_H
92