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