OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_PAINT_PAINT_FLAGS_H_ | 5 #ifndef CC_PAINT_PAINT_FLAGS_H_ |
6 #define CC_PAINT_PAINT_FLAGS_H_ | 6 #define CC_PAINT_PAINT_FLAGS_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | |
9 #include "cc/paint/paint_shader.h" | |
10 #include "third_party/skia/include/core/SkCanvas.h" | |
11 #include "third_party/skia/include/core/SkColorFilter.h" | |
12 #include "third_party/skia/include/core/SkDrawLooper.h" | |
13 #include "third_party/skia/include/core/SkImageFilter.h" | |
14 #include "third_party/skia/include/core/SkMaskFilter.h" | |
8 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
16 #include "third_party/skia/include/core/SkPathEffect.h" | |
17 #include "third_party/skia/include/core/SkTypeface.h" | |
9 | 18 |
10 namespace cc { | 19 namespace cc { |
11 | 20 |
12 using PaintFlags = SkPaint; | 21 class CC_PAINT_EXPORT PaintFlags { |
13 | 22 public: |
14 inline const SkPaint& ToSkPaint(const PaintFlags& flags) { | 23 PaintFlags() = default; |
vmpstr
2017/03/03 07:12:08
I don't think you need to declare any ctors or ass
| |
15 return flags; | 24 ~PaintFlags() = default; |
25 | |
26 PaintFlags(const PaintFlags& flags) : paint_(flags.paint_) {} | |
27 PaintFlags& operator=(const PaintFlags& flags) { | |
28 paint_ = flags.paint_; | |
29 return *this; | |
30 } | |
31 | |
32 enum Style { | |
33 kFill_Style = SkPaint::kFill_Style, | |
34 kStroke_Style = SkPaint::kStroke_Style, | |
35 kStrokeAndFill_Style = SkPaint::kStrokeAndFill_Style, | |
36 }; | |
37 ALWAYS_INLINE Style getStyle() const { | |
38 return static_cast<Style>(paint_.getStyle()); | |
39 } | |
40 ALWAYS_INLINE void setStyle(Style style) { | |
41 paint_.setStyle(static_cast<SkPaint::Style>(style)); | |
42 } | |
43 ALWAYS_INLINE SkColor getColor() const { return paint_.getColor(); } | |
44 ALWAYS_INLINE void setColor(SkColor color) { paint_.setColor(color); } | |
45 ALWAYS_INLINE void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { | |
46 paint_.setARGB(a, r, g, b); | |
47 } | |
48 ALWAYS_INLINE uint8_t getAlpha() const { return paint_.getAlpha(); } | |
49 ALWAYS_INLINE void setAlpha(U8CPU a) { paint_.setAlpha(a); } | |
50 ALWAYS_INLINE void setBlendMode(SkBlendMode mode) { | |
51 paint_.setBlendMode(mode); | |
52 } | |
53 ALWAYS_INLINE SkBlendMode getBlendMode() const { | |
54 return paint_.getBlendMode(); | |
55 } | |
56 ALWAYS_INLINE bool isSrcOver() const { return paint_.isSrcOver(); } | |
57 ALWAYS_INLINE bool isAntiAlias() const { return paint_.isAntiAlias(); } | |
58 ALWAYS_INLINE void setAntiAlias(bool aa) { paint_.setAntiAlias(aa); } | |
59 ALWAYS_INLINE bool isVerticalText() const { return paint_.isVerticalText(); } | |
60 ALWAYS_INLINE void setVerticalText(bool vertical) { | |
61 paint_.setVerticalText(vertical); | |
62 } | |
63 ALWAYS_INLINE bool isSubpixelText() const { return paint_.isSubpixelText(); } | |
64 ALWAYS_INLINE void setSubpixelText(bool subpixelText) { | |
danakj
2017/03/03 18:33:19
sub_pixel_text
| |
65 paint_.setSubpixelText(subpixelText); | |
66 } | |
67 ALWAYS_INLINE bool isLCDRenderText() const { | |
68 return paint_.isLCDRenderText(); | |
69 } | |
70 ALWAYS_INLINE void setLCDRenderText(bool lcdText) { | |
danakj
2017/03/03 18:33:19
lcd_text
| |
71 paint_.setLCDRenderText(lcdText); | |
72 } | |
73 enum Hinting { | |
74 kNo_Hinting = SkPaint::kNo_Hinting, | |
75 kSlight_Hinting = SkPaint::kSlight_Hinting, | |
76 kNormal_Hinting = SkPaint::kNormal_Hinting, //!< this is the default | |
77 kFull_Hinting = SkPaint::kFull_Hinting | |
78 }; | |
79 ALWAYS_INLINE Hinting getHinting() const { | |
80 return static_cast<Hinting>(paint_.getHinting()); | |
81 } | |
82 ALWAYS_INLINE void setHinting(Hinting hinting_level) { | |
83 paint_.setHinting(static_cast<SkPaint::Hinting>(hinting_level)); | |
84 } | |
85 ALWAYS_INLINE bool isAutohinted() const { return paint_.isAutohinted(); } | |
86 ALWAYS_INLINE void setAutohinted(bool use_auto_hinter) { | |
87 paint_.setAutohinted(use_auto_hinter); | |
88 } | |
89 ALWAYS_INLINE bool isDither() const { return paint_.isDither(); } | |
90 ALWAYS_INLINE void setDither(bool dither) { paint_.setDither(dither); } | |
91 enum TextEncoding { | |
92 kUTF8_TextEncoding = SkPaint::kUTF8_TextEncoding, | |
93 kUTF16_TextEncoding = SkPaint::kUTF16_TextEncoding, | |
94 kUTF32_TextEncoding = SkPaint::kUTF32_TextEncoding, | |
95 kGlyphID_TextEncoding = SkPaint::kGlyphID_TextEncoding | |
96 }; | |
97 ALWAYS_INLINE TextEncoding getTextEncoding() const { | |
98 return static_cast<TextEncoding>(paint_.getTextEncoding()); | |
99 } | |
100 ALWAYS_INLINE void setTextEncoding(TextEncoding encoding) { | |
101 paint_.setTextEncoding(static_cast<SkPaint::TextEncoding>(encoding)); | |
102 } | |
103 ALWAYS_INLINE SkScalar getTextSize() const { return paint_.getTextSize(); } | |
104 ALWAYS_INLINE void setTextSize(SkScalar textSize) { | |
105 paint_.setTextSize(textSize); | |
106 } | |
107 ALWAYS_INLINE void setFilterQuality(SkFilterQuality quality) { | |
108 paint_.setFilterQuality(quality); | |
109 } | |
110 ALWAYS_INLINE SkFilterQuality getFilterQuality() const { | |
111 return paint_.getFilterQuality(); | |
112 } | |
113 ALWAYS_INLINE SkScalar getStrokeWidth() const { | |
114 return paint_.getStrokeWidth(); | |
115 } | |
116 ALWAYS_INLINE void setStrokeWidth(SkScalar width) { | |
117 paint_.setStrokeWidth(width); | |
118 } | |
119 ALWAYS_INLINE SkScalar getStrokeMiter() const { | |
120 return paint_.getStrokeMiter(); | |
121 } | |
122 ALWAYS_INLINE void setStrokeMiter(SkScalar miter) { | |
123 paint_.setStrokeMiter(miter); | |
124 } | |
125 enum Cap { | |
126 kButt_Cap = SkPaint::kButt_Cap, //!< begin/end contours with no extension | |
127 kRound_Cap = SkPaint::kRound_Cap, //!< begin/end contours with a | |
128 //! semi-circle extension | |
129 kSquare_Cap = SkPaint::kSquare_Cap, //!< begin/end contours with a half | |
130 //! square extension | |
131 kLast_Cap = kSquare_Cap, | |
132 kDefault_Cap = kButt_Cap | |
133 }; | |
134 ALWAYS_INLINE Cap getStrokeCap() const { | |
135 return static_cast<Cap>(paint_.getStrokeCap()); | |
136 } | |
137 ALWAYS_INLINE void setStrokeCap(Cap cap) { | |
138 paint_.setStrokeCap(static_cast<SkPaint::Cap>(cap)); | |
139 } | |
140 enum Join { | |
141 kMiter_Join = SkPaint::kMiter_Join, | |
142 kRound_Join = SkPaint::kRound_Join, | |
143 kBevel_Join = SkPaint::kBevel_Join, | |
144 kLast_Join = kBevel_Join, | |
145 kDefault_Join = kMiter_Join | |
146 }; | |
147 ALWAYS_INLINE Join getStrokeJoin() const { | |
148 return static_cast<Join>(paint_.getStrokeJoin()); | |
149 } | |
150 ALWAYS_INLINE void setStrokeJoin(Join join) { | |
151 paint_.setStrokeJoin(static_cast<SkPaint::Join>(join)); | |
152 } | |
153 ALWAYS_INLINE SkTypeface* getTypeface() const { return paint_.getTypeface(); } | |
154 ALWAYS_INLINE void setTypeface(sk_sp<SkTypeface> typeface) { | |
155 paint_.setTypeface(std::move(typeface)); | |
156 } | |
157 ALWAYS_INLINE SkColorFilter* getColorFilter() const { | |
158 return paint_.getColorFilter(); | |
159 } | |
160 ALWAYS_INLINE void setColorFilter(sk_sp<SkColorFilter> filter) { | |
161 paint_.setColorFilter(std::move(filter)); | |
162 } | |
163 ALWAYS_INLINE SkMaskFilter* getMaskFilter() const { | |
164 return paint_.getMaskFilter(); | |
165 } | |
166 ALWAYS_INLINE void setMaskFilter(sk_sp<SkMaskFilter> mask) { | |
167 paint_.setMaskFilter(std::move(mask)); | |
168 } | |
169 ALWAYS_INLINE PaintShader* getShader() const { return paint_.getShader(); } | |
170 ALWAYS_INLINE void setShader(sk_sp<PaintShader> shader) { | |
171 paint_.setShader(std::move(shader)); | |
172 } | |
173 ALWAYS_INLINE SkPathEffect* getPathEffect() const { | |
174 return paint_.getPathEffect(); | |
175 } | |
176 ALWAYS_INLINE void setPathEffect(sk_sp<SkPathEffect> effect) { | |
177 paint_.setPathEffect(std::move(effect)); | |
178 } | |
179 ALWAYS_INLINE bool getFillPath(const SkPath& src, | |
180 SkPath* dst, | |
181 const SkRect* cullRect = nullptr, | |
182 SkScalar resScale = 1) const { | |
183 return paint_.getFillPath(src, dst, cullRect, resScale); | |
184 } | |
185 ALWAYS_INLINE sk_sp<SkImageFilter> refImageFilter() const { | |
186 return paint_.refImageFilter(); | |
187 } | |
188 ALWAYS_INLINE SkImageFilter* getImageFilter() const { | |
189 return paint_.getImageFilter(); | |
190 } | |
191 void setImageFilter(sk_sp<SkImageFilter> filter) { | |
192 paint_.setImageFilter(std::move(filter)); | |
193 } | |
194 ALWAYS_INLINE SkDrawLooper* getDrawLooper() const { | |
195 return paint_.getDrawLooper(); | |
196 } | |
197 ALWAYS_INLINE SkDrawLooper* getLooper() const { return paint_.getLooper(); } | |
198 ALWAYS_INLINE void setLooper(sk_sp<SkDrawLooper> looper) { | |
199 paint_.setLooper(std::move(looper)); | |
200 } | |
201 ALWAYS_INLINE bool canComputeFastBounds() const { | |
202 return paint_.canComputeFastBounds(); | |
203 } | |
204 ALWAYS_INLINE const SkRect& computeFastBounds(const SkRect& orig, | |
205 SkRect* storage) const { | |
206 return paint_.computeFastBounds(orig, storage); | |
207 } | |
208 | |
209 private: | |
210 friend const SkPaint& ToSkPaint(const PaintFlags& flags); | |
211 friend const SkPaint* ToSkPaint(const PaintFlags* flags); | |
212 | |
213 SkPaint paint_; | |
214 }; | |
215 | |
216 ALWAYS_INLINE const SkPaint& ToSkPaint(const PaintFlags& flags) { | |
217 return flags.paint_; | |
16 } | 218 } |
17 | 219 |
220 ALWAYS_INLINE const SkPaint* ToSkPaint(const PaintFlags* flags) { | |
221 return &flags->paint_; | |
222 } | |
223 | |
18 } // namespace cc | 224 } // namespace cc |
19 | 225 |
20 #endif // CC_PAINT_PAINT_FLAGS_H_ | 226 #endif // CC_PAINT_PAINT_FLAGS_H_ |
OLD | NEW |