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" | 8 #include "base/compiler_specific.h" |
9 #include "cc/paint/paint_export.h" | 9 #include "cc/paint/paint_export.h" |
10 #include "cc/paint/paint_shader.h" | |
11 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "third_party/skia/include/core/SkColorFilter.h" | 11 #include "third_party/skia/include/core/SkColorFilter.h" |
13 #include "third_party/skia/include/core/SkDrawLooper.h" | 12 #include "third_party/skia/include/core/SkDrawLooper.h" |
14 #include "third_party/skia/include/core/SkImageFilter.h" | 13 #include "third_party/skia/include/core/SkImageFilter.h" |
15 #include "third_party/skia/include/core/SkMaskFilter.h" | 14 #include "third_party/skia/include/core/SkMaskFilter.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
17 #include "third_party/skia/include/core/SkPathEffect.h" | 16 #include "third_party/skia/include/core/SkPathEffect.h" |
18 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
19 #include "third_party/skia/include/core/SkTypeface.h" | 18 #include "third_party/skia/include/core/SkTypeface.h" |
20 | 19 |
21 namespace cc { | 20 namespace cc { |
22 | 21 |
| 22 using PaintShader = SkShader; |
| 23 |
23 class CC_PAINT_EXPORT PaintFlags { | 24 class CC_PAINT_EXPORT PaintFlags { |
24 public: | 25 public: |
25 enum Style { | 26 enum Style { |
26 kFill_Style = SkPaint::kFill_Style, | 27 kFill_Style = SkPaint::kFill_Style, |
27 kStroke_Style = SkPaint::kStroke_Style, | 28 kStroke_Style = SkPaint::kStroke_Style, |
28 kStrokeAndFill_Style = SkPaint::kStrokeAndFill_Style, | 29 kStrokeAndFill_Style = SkPaint::kStrokeAndFill_Style, |
29 }; | 30 }; |
30 ALWAYS_INLINE Style getStyle() const { | 31 ALWAYS_INLINE Style getStyle() const { |
31 return static_cast<Style>(paint_.getStyle()); | 32 return static_cast<Style>(paint_.getStyle()); |
32 } | 33 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 153 } |
153 ALWAYS_INLINE void setColorFilter(sk_sp<SkColorFilter> filter) { | 154 ALWAYS_INLINE void setColorFilter(sk_sp<SkColorFilter> filter) { |
154 paint_.setColorFilter(std::move(filter)); | 155 paint_.setColorFilter(std::move(filter)); |
155 } | 156 } |
156 ALWAYS_INLINE SkMaskFilter* getMaskFilter() const { | 157 ALWAYS_INLINE SkMaskFilter* getMaskFilter() const { |
157 return paint_.getMaskFilter(); | 158 return paint_.getMaskFilter(); |
158 } | 159 } |
159 ALWAYS_INLINE void setMaskFilter(sk_sp<SkMaskFilter> mask) { | 160 ALWAYS_INLINE void setMaskFilter(sk_sp<SkMaskFilter> mask) { |
160 paint_.setMaskFilter(std::move(mask)); | 161 paint_.setMaskFilter(std::move(mask)); |
161 } | 162 } |
162 // TODO(vmpstr): Remove this from recording calls, since we want to avoid | 163 ALWAYS_INLINE PaintShader* getShader() const { return paint_.getShader(); } |
163 // constructing the shader until rasterization. | 164 ALWAYS_INLINE void setShader(sk_sp<PaintShader> shader) { |
164 ALWAYS_INLINE SkShader* getSkShader() const { return paint_.getShader(); } | 165 paint_.setShader(std::move(shader)); |
165 | |
166 // Returns true if the shader has been set on the flags. | |
167 ALWAYS_INLINE bool HasShader() const { return !!paint_.getShader(); } | |
168 | |
169 // Returns whether the shader is opaque. Note that it is only valid to call | |
170 // this function if HasShader() returns true. | |
171 ALWAYS_INLINE bool ShaderIsOpaque() const { | |
172 return paint_.getShader()->isOpaque(); | |
173 } | |
174 | |
175 ALWAYS_INLINE void setShader(std::unique_ptr<PaintShader> shader) { | |
176 paint_.setShader(shader ? shader->sk_shader() : nullptr); | |
177 } | 166 } |
178 ALWAYS_INLINE SkPathEffect* getPathEffect() const { | 167 ALWAYS_INLINE SkPathEffect* getPathEffect() const { |
179 return paint_.getPathEffect(); | 168 return paint_.getPathEffect(); |
180 } | 169 } |
181 ALWAYS_INLINE void setPathEffect(sk_sp<SkPathEffect> effect) { | 170 ALWAYS_INLINE void setPathEffect(sk_sp<SkPathEffect> effect) { |
182 paint_.setPathEffect(std::move(effect)); | 171 paint_.setPathEffect(std::move(effect)); |
183 } | 172 } |
184 ALWAYS_INLINE bool getFillPath(const SkPath& src, | 173 ALWAYS_INLINE bool getFillPath(const SkPath& src, |
185 SkPath* dst, | 174 SkPath* dst, |
186 const SkRect* cullRect = nullptr, | 175 const SkRect* cullRect = nullptr, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 return flags.paint_; | 219 return flags.paint_; |
231 } | 220 } |
232 | 221 |
233 ALWAYS_INLINE const SkPaint* ToSkPaint(const PaintFlags* flags) { | 222 ALWAYS_INLINE const SkPaint* ToSkPaint(const PaintFlags* flags) { |
234 return &flags->paint_; | 223 return &flags->paint_; |
235 } | 224 } |
236 | 225 |
237 } // namespace cc | 226 } // namespace cc |
238 | 227 |
239 #endif // CC_PAINT_PAINT_FLAGS_H_ | 228 #endif // CC_PAINT_PAINT_FLAGS_H_ |
OLD | NEW |