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