• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 BRUSH_H
17 #define BRUSH_H
18 
19 #include "draw/color.h"
20 #include "effect/color_space.h"
21 #include "effect/blender.h"
22 #include "effect/filter.h"
23 #include "effect/shader_effect.h"
24 #include "utils/drawing_macros.h"
25 #include "utils/rect.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class DRAWING_API Brush {
31 public:
32     Brush() noexcept;
33     Brush(const Brush& b) noexcept = default;
34     Brush(const Color& c) noexcept;
35     Brush(const std::shared_ptr<ShaderEffect> e) noexcept;
36     Brush(int rgba) noexcept;
37 
~Brush()38     ~Brush() {}
39     const Color& GetColor() const;
40     void SetColor(const Color& c);
41     void SetColor(uint32_t c);
42     void SetARGB(int a, int r, int g, int b);
43 
44     Color4f GetColor4f();
45     std::shared_ptr<ColorSpace> GetColorSpace() const;
46     void SetColor(const Color4f& cf, std::shared_ptr<ColorSpace> s);
47 
GetAlpha()48     inline uint32_t GetAlpha() const
49     {
50         return color_.GetAlpha();
51     }
52 
GetAlphaF()53     inline scalar GetAlphaF() const
54     {
55         return color_.GetAlphaF();
56     }
57 
58     void SetAlpha(uint32_t a);
59     void SetAlphaF(scalar a);
60 
GetBlendMode()61     const BlendMode& GetBlendMode() const { return blendMode_; }
62     void SetBlendMode(const BlendMode& mode);
63 
64     void SetFilter(const Filter& filter);
65     const Filter& GetFilter() const;
HasFilter()66     bool HasFilter() const { return hasFilter_; }
67 
68     void SetShaderEffect(std::shared_ptr<ShaderEffect> e);
69     std::shared_ptr<ShaderEffect> GetShaderEffect() const;
70 
71     void SetBlender(std::shared_ptr<Blender> blender);
GetBlender()72     std::shared_ptr<Blender> GetBlender() const { return blender_; }
73 
74     bool IsAntiAlias() const;
75     void SetAntiAlias(bool aa);
76 
77     bool CanComputeFastBounds();
78     const Rect& ComputeFastBounds(const Rect& orig, Rect* storage);
79 
80     bool AsBlendMode();
81     void Reset();
82 
83     friend DRAWING_API bool operator==(const Brush& b1, const Brush& b2);
84     friend DRAWING_API bool operator!=(const Brush& b1, const Brush& b2);
85 
86 private:
87     Color color_;
88     BlendMode blendMode_;
89     Filter filter_;
90     std::shared_ptr<ColorSpace> colorSpace_;
91     std::shared_ptr<ShaderEffect> shaderEffect_;
92     std::shared_ptr<Blender> blender_;
93 
94     bool antiAlias_;
95     bool hasFilter_ = false;
96 };
97 } // namespace Drawing
98 } // namespace Rosen
99 } // namespace OHOS
100 #endif