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