OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaint.h" | 8 #include "SkPaint.h" |
9 #include "SkAutoKern.h" | 9 #include "SkAutoKern.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // e.g. setTextSize(-1) | 45 // e.g. setTextSize(-1) |
46 //#define SK_REPORT_API_RANGE_CHECK | 46 //#define SK_REPORT_API_RANGE_CHECK |
47 | 47 |
48 SkPaint::SkPaint() { | 48 SkPaint::SkPaint() { |
49 fTextSize = SkPaintDefaults_TextSize; | 49 fTextSize = SkPaintDefaults_TextSize; |
50 fTextScaleX = SK_Scalar1; | 50 fTextScaleX = SK_Scalar1; |
51 fTextSkewX = 0; | 51 fTextSkewX = 0; |
52 fColor = SK_ColorBLACK; | 52 fColor = SK_ColorBLACK; |
53 fWidth = 0; | 53 fWidth = 0; |
54 fMiterLimit = SkPaintDefaults_MiterLimit; | 54 fMiterLimit = SkPaintDefaults_MiterLimit; |
| 55 fBlendMode = (unsigned)SkBlendMode::kSrcOver; |
55 | 56 |
56 // Zero all bitfields, then set some non-zero defaults. | 57 // Zero all bitfields, then set some non-zero defaults. |
57 fBitfieldsUInt = 0; | 58 fBitfieldsUInt = 0; |
58 fBitfields.fFlags = SkPaintDefaults_Flags; | 59 fBitfields.fFlags = SkPaintDefaults_Flags; |
59 fBitfields.fCapType = kDefault_Cap; | 60 fBitfields.fCapType = kDefault_Cap; |
60 fBitfields.fJoinType = kDefault_Join; | 61 fBitfields.fJoinType = kDefault_Join; |
61 fBitfields.fTextAlign = kLeft_Align; | 62 fBitfields.fTextAlign = kLeft_Align; |
62 fBitfields.fStyle = kFill_Style; | 63 fBitfields.fStyle = kFill_Style; |
63 fBitfields.fTextEncoding = kUTF8_TextEncoding; | 64 fBitfields.fTextEncoding = kUTF8_TextEncoding; |
64 fBitfields.fHinting = SkPaintDefaults_Hinting; | 65 fBitfields.fHinting = SkPaintDefaults_Hinting; |
65 } | 66 } |
66 | 67 |
67 SkPaint::SkPaint(const SkPaint& src) | 68 SkPaint::SkPaint(const SkPaint& src) |
68 #define COPY(field) field(src.field) | 69 #define COPY(field) field(src.field) |
69 : COPY(fTypeface) | 70 : COPY(fTypeface) |
70 , COPY(fPathEffect) | 71 , COPY(fPathEffect) |
71 , COPY(fShader) | 72 , COPY(fShader) |
72 , COPY(fXfermode) | |
73 , COPY(fMaskFilter) | 73 , COPY(fMaskFilter) |
74 , COPY(fColorFilter) | 74 , COPY(fColorFilter) |
75 , COPY(fRasterizer) | 75 , COPY(fRasterizer) |
76 , COPY(fDrawLooper) | 76 , COPY(fDrawLooper) |
77 , COPY(fImageFilter) | 77 , COPY(fImageFilter) |
78 , COPY(fTextSize) | 78 , COPY(fTextSize) |
79 , COPY(fTextScaleX) | 79 , COPY(fTextScaleX) |
80 , COPY(fTextSkewX) | 80 , COPY(fTextSkewX) |
81 , COPY(fColor) | 81 , COPY(fColor) |
82 , COPY(fWidth) | 82 , COPY(fWidth) |
83 , COPY(fMiterLimit) | 83 , COPY(fMiterLimit) |
| 84 , COPY(fBlendMode) |
84 , COPY(fBitfields) | 85 , COPY(fBitfields) |
85 #undef COPY | 86 #undef COPY |
86 {} | 87 {} |
87 | 88 |
88 SkPaint::SkPaint(SkPaint&& src) { | 89 SkPaint::SkPaint(SkPaint&& src) { |
89 #define MOVE(field) field = std::move(src.field) | 90 #define MOVE(field) field = std::move(src.field) |
90 MOVE(fTypeface); | 91 MOVE(fTypeface); |
91 MOVE(fPathEffect); | 92 MOVE(fPathEffect); |
92 MOVE(fShader); | 93 MOVE(fShader); |
93 MOVE(fXfermode); | |
94 MOVE(fMaskFilter); | 94 MOVE(fMaskFilter); |
95 MOVE(fColorFilter); | 95 MOVE(fColorFilter); |
96 MOVE(fRasterizer); | 96 MOVE(fRasterizer); |
97 MOVE(fDrawLooper); | 97 MOVE(fDrawLooper); |
98 MOVE(fImageFilter); | 98 MOVE(fImageFilter); |
99 MOVE(fTextSize); | 99 MOVE(fTextSize); |
100 MOVE(fTextScaleX); | 100 MOVE(fTextScaleX); |
101 MOVE(fTextSkewX); | 101 MOVE(fTextSkewX); |
102 MOVE(fColor); | 102 MOVE(fColor); |
103 MOVE(fWidth); | 103 MOVE(fWidth); |
104 MOVE(fMiterLimit); | 104 MOVE(fMiterLimit); |
| 105 MOVE(fBlendMode); |
105 MOVE(fBitfields); | 106 MOVE(fBitfields); |
106 #undef MOVE | 107 #undef MOVE |
107 } | 108 } |
108 | 109 |
109 SkPaint::~SkPaint() {} | 110 SkPaint::~SkPaint() {} |
110 | 111 |
111 SkPaint& SkPaint::operator=(const SkPaint& src) { | 112 SkPaint& SkPaint::operator=(const SkPaint& src) { |
112 if (this == &src) { | 113 if (this == &src) { |
113 return *this; | 114 return *this; |
114 } | 115 } |
115 | 116 |
116 #define ASSIGN(field) field = src.field | 117 #define ASSIGN(field) field = src.field |
117 ASSIGN(fTypeface); | 118 ASSIGN(fTypeface); |
118 ASSIGN(fPathEffect); | 119 ASSIGN(fPathEffect); |
119 ASSIGN(fShader); | 120 ASSIGN(fShader); |
120 ASSIGN(fXfermode); | |
121 ASSIGN(fMaskFilter); | 121 ASSIGN(fMaskFilter); |
122 ASSIGN(fColorFilter); | 122 ASSIGN(fColorFilter); |
123 ASSIGN(fRasterizer); | 123 ASSIGN(fRasterizer); |
124 ASSIGN(fDrawLooper); | 124 ASSIGN(fDrawLooper); |
125 ASSIGN(fImageFilter); | 125 ASSIGN(fImageFilter); |
126 ASSIGN(fTextSize); | 126 ASSIGN(fTextSize); |
127 ASSIGN(fTextScaleX); | 127 ASSIGN(fTextScaleX); |
128 ASSIGN(fTextSkewX); | 128 ASSIGN(fTextSkewX); |
129 ASSIGN(fColor); | 129 ASSIGN(fColor); |
130 ASSIGN(fWidth); | 130 ASSIGN(fWidth); |
131 ASSIGN(fMiterLimit); | 131 ASSIGN(fMiterLimit); |
| 132 ASSIGN(fBlendMode); |
132 ASSIGN(fBitfields); | 133 ASSIGN(fBitfields); |
133 #undef ASSIGN | 134 #undef ASSIGN |
134 | 135 |
135 return *this; | 136 return *this; |
136 } | 137 } |
137 | 138 |
138 SkPaint& SkPaint::operator=(SkPaint&& src) { | 139 SkPaint& SkPaint::operator=(SkPaint&& src) { |
139 if (this == &src) { | 140 if (this == &src) { |
140 return *this; | 141 return *this; |
141 } | 142 } |
142 | 143 |
143 #define MOVE(field) field = std::move(src.field) | 144 #define MOVE(field) field = std::move(src.field) |
144 MOVE(fTypeface); | 145 MOVE(fTypeface); |
145 MOVE(fPathEffect); | 146 MOVE(fPathEffect); |
146 MOVE(fShader); | 147 MOVE(fShader); |
147 MOVE(fXfermode); | |
148 MOVE(fMaskFilter); | 148 MOVE(fMaskFilter); |
149 MOVE(fColorFilter); | 149 MOVE(fColorFilter); |
150 MOVE(fRasterizer); | 150 MOVE(fRasterizer); |
151 MOVE(fDrawLooper); | 151 MOVE(fDrawLooper); |
152 MOVE(fImageFilter); | 152 MOVE(fImageFilter); |
153 MOVE(fTextSize); | 153 MOVE(fTextSize); |
154 MOVE(fTextScaleX); | 154 MOVE(fTextScaleX); |
155 MOVE(fTextSkewX); | 155 MOVE(fTextSkewX); |
156 MOVE(fColor); | 156 MOVE(fColor); |
157 MOVE(fWidth); | 157 MOVE(fWidth); |
158 MOVE(fMiterLimit); | 158 MOVE(fMiterLimit); |
| 159 MOVE(fBlendMode); |
159 MOVE(fBitfields); | 160 MOVE(fBitfields); |
160 #undef MOVE | 161 #undef MOVE |
161 | 162 |
162 return *this; | 163 return *this; |
163 } | 164 } |
164 | 165 |
165 bool operator==(const SkPaint& a, const SkPaint& b) { | 166 bool operator==(const SkPaint& a, const SkPaint& b) { |
166 #define EQUAL(field) (a.field == b.field) | 167 #define EQUAL(field) (a.field == b.field) |
167 return EQUAL(fTypeface) | 168 return EQUAL(fTypeface) |
168 && EQUAL(fPathEffect) | 169 && EQUAL(fPathEffect) |
169 && EQUAL(fShader) | 170 && EQUAL(fShader) |
170 && EQUAL(fXfermode) | |
171 && EQUAL(fMaskFilter) | 171 && EQUAL(fMaskFilter) |
172 && EQUAL(fColorFilter) | 172 && EQUAL(fColorFilter) |
173 && EQUAL(fRasterizer) | 173 && EQUAL(fRasterizer) |
174 && EQUAL(fDrawLooper) | 174 && EQUAL(fDrawLooper) |
175 && EQUAL(fImageFilter) | 175 && EQUAL(fImageFilter) |
176 && EQUAL(fTextSize) | 176 && EQUAL(fTextSize) |
177 && EQUAL(fTextScaleX) | 177 && EQUAL(fTextScaleX) |
178 && EQUAL(fTextSkewX) | 178 && EQUAL(fTextSkewX) |
179 && EQUAL(fColor) | 179 && EQUAL(fColor) |
180 && EQUAL(fWidth) | 180 && EQUAL(fWidth) |
181 && EQUAL(fMiterLimit) | 181 && EQUAL(fMiterLimit) |
| 182 && EQUAL(fBlendMode) |
182 && EQUAL(fBitfieldsUInt) | 183 && EQUAL(fBitfieldsUInt) |
183 ; | 184 ; |
184 #undef EQUAL | 185 #undef EQUAL |
185 } | 186 } |
186 | 187 |
187 void SkPaint::reset() { | 188 void SkPaint::reset() { |
188 SkPaint init; | 189 SkPaint init; |
189 *this = init; | 190 *this = init; |
190 } | 191 } |
191 | 192 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 354 } |
354 | 355 |
355 /////////////////////////////////////////////////////////////////////////////// | 356 /////////////////////////////////////////////////////////////////////////////// |
356 | 357 |
357 #define MOVE_FIELD(Field) void SkPaint::set##Field(sk_sp<Sk##Field> f) { f##Fiel
d = std::move(f); } | 358 #define MOVE_FIELD(Field) void SkPaint::set##Field(sk_sp<Sk##Field> f) { f##Fiel
d = std::move(f); } |
358 MOVE_FIELD(Typeface) | 359 MOVE_FIELD(Typeface) |
359 MOVE_FIELD(Rasterizer) | 360 MOVE_FIELD(Rasterizer) |
360 MOVE_FIELD(ImageFilter) | 361 MOVE_FIELD(ImageFilter) |
361 MOVE_FIELD(Shader) | 362 MOVE_FIELD(Shader) |
362 MOVE_FIELD(ColorFilter) | 363 MOVE_FIELD(ColorFilter) |
363 MOVE_FIELD(Xfermode) | |
364 MOVE_FIELD(PathEffect) | 364 MOVE_FIELD(PathEffect) |
365 MOVE_FIELD(MaskFilter) | 365 MOVE_FIELD(MaskFilter) |
366 MOVE_FIELD(DrawLooper) | 366 MOVE_FIELD(DrawLooper) |
367 #undef MOVE_FIELD | 367 #undef MOVE_FIELD |
368 void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fDrawLooper = std::move(lo
oper); } | 368 void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fDrawLooper = std::move(lo
oper); } |
369 | 369 |
370 #define SET_PTR(Field) \ | 370 #define SET_PTR(Field) \ |
371 Sk##Field* SkPaint::set##Field(Sk##Field* f) { \ | 371 Sk##Field* SkPaint::set##Field(Sk##Field* f) { \ |
372 this->f##Field.reset(SkSafeRef(f)); \ | 372 this->f##Field.reset(SkSafeRef(f)); \ |
373 return f; \ | 373 return f; \ |
374 } | 374 } |
375 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR | 375 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR |
376 SET_PTR(Typeface) | 376 SET_PTR(Typeface) |
377 #endif | 377 #endif |
378 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR | 378 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR |
379 SET_PTR(Rasterizer) | 379 SET_PTR(Rasterizer) |
380 #endif | 380 #endif |
381 SET_PTR(ImageFilter) | 381 SET_PTR(ImageFilter) |
382 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR | 382 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR |
383 SET_PTR(Shader) | 383 SET_PTR(Shader) |
384 #endif | 384 #endif |
385 #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR | 385 #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR |
386 SET_PTR(ColorFilter) | 386 SET_PTR(ColorFilter) |
387 #endif | 387 #endif |
388 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR | 388 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR |
389 SET_PTR(Xfermode) | 389 SkXfermode* SkPaint::setXfermode(SkXfermode* xfer) { |
| 390 this->setBlendMode(xfer ? xfer->blend() : SkBlendMode::kSrcOver); |
| 391 return this->getXfermode(); |
| 392 } |
390 #endif | 393 #endif |
391 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR | 394 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
392 SET_PTR(PathEffect) | 395 SET_PTR(PathEffect) |
393 #endif | 396 #endif |
394 #ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR | 397 #ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR |
395 SET_PTR(MaskFilter) | 398 SET_PTR(MaskFilter) |
396 #endif | 399 #endif |
397 #undef SET_PTR | 400 #undef SET_PTR |
398 | 401 |
399 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR | 402 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR |
400 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { | 403 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { |
401 fDrawLooper.reset(SkSafeRef(looper)); | 404 fDrawLooper.reset(SkSafeRef(looper)); |
402 return looper; | 405 return looper; |
403 } | 406 } |
404 #endif | 407 #endif |
405 | 408 |
| 409 #ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT |
| 410 void SkPaint::setXfermode(sk_sp<SkXfermode> mode) { |
| 411 this->setBlendMode(mode ? mode->blend() : SkBlendMode::kSrcOver); |
| 412 } |
| 413 SkXfermode* SkPaint::getXfermode() const { |
| 414 return SkXfermode::Peek((SkBlendMode)fBlendMode); |
| 415 } |
406 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { | 416 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { |
407 fXfermode = SkXfermode::Make(mode); | 417 this->setBlendMode((SkBlendMode)mode); |
408 return fXfermode.get(); // can/should we change this API to be void, like th
e other setters? | 418 return SkXfermode::Peek((SkBlendMode)mode); |
409 } | 419 } |
| 420 #endif |
410 | 421 |
411 /////////////////////////////////////////////////////////////////////////////// | 422 /////////////////////////////////////////////////////////////////////////////// |
412 | 423 |
413 static SkScalar mag2(SkScalar x, SkScalar y) { | 424 static SkScalar mag2(SkScalar x, SkScalar y) { |
414 return x * x + y * y; | 425 return x * x + y * y; |
415 } | 426 } |
416 | 427 |
417 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { | 428 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { |
418 return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max | 429 return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max |
419 || | 430 || |
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 /* To save space/time, we analyze the paint, and write a truncated version of | 1908 /* To save space/time, we analyze the paint, and write a truncated version of |
1898 it if there are not tricky elements like shaders, etc. | 1909 it if there are not tricky elements like shaders, etc. |
1899 */ | 1910 */ |
1900 void SkPaint::flatten(SkWriteBuffer& buffer) const { | 1911 void SkPaint::flatten(SkWriteBuffer& buffer) const { |
1901 uint8_t flatFlags = 0; | 1912 uint8_t flatFlags = 0; |
1902 if (this->getTypeface()) { | 1913 if (this->getTypeface()) { |
1903 flatFlags |= kHasTypeface_FlatFlag; | 1914 flatFlags |= kHasTypeface_FlatFlag; |
1904 } | 1915 } |
1905 if (asint(this->getPathEffect()) | | 1916 if (asint(this->getPathEffect()) | |
1906 asint(this->getShader()) | | 1917 asint(this->getShader()) | |
1907 asint(this->getXfermode()) | | |
1908 asint(this->getMaskFilter()) | | 1918 asint(this->getMaskFilter()) | |
1909 asint(this->getColorFilter()) | | 1919 asint(this->getColorFilter()) | |
1910 asint(this->getRasterizer()) | | 1920 asint(this->getRasterizer()) | |
1911 asint(this->getLooper()) | | 1921 asint(this->getLooper()) | |
1912 asint(this->getImageFilter())) { | 1922 asint(this->getImageFilter())) { |
1913 flatFlags |= kHasEffects_FlatFlag; | 1923 flatFlags |= kHasEffects_FlatFlag; |
1914 } | 1924 } |
1915 | 1925 |
1916 buffer.writeScalar(this->getTextSize()); | 1926 buffer.writeScalar(this->getTextSize()); |
1917 buffer.writeScalar(this->getTextScaleX()); | 1927 buffer.writeScalar(this->getTextScaleX()); |
1918 buffer.writeScalar(this->getTextSkewX()); | 1928 buffer.writeScalar(this->getTextSkewX()); |
1919 buffer.writeScalar(this->getStrokeWidth()); | 1929 buffer.writeScalar(this->getStrokeWidth()); |
1920 buffer.writeScalar(this->getStrokeMiter()); | 1930 buffer.writeScalar(this->getStrokeMiter()); |
1921 buffer.writeColor(this->getColor()); | 1931 buffer.writeColor(this->getColor()); |
1922 | 1932 |
1923 buffer.writeUInt(pack_paint_flags(this->getFlags(), this->getHinting(), this
->getTextAlign(), | 1933 buffer.writeUInt(pack_paint_flags(this->getFlags(), this->getHinting(), this
->getTextAlign(), |
1924 this->getFilterQuality(), flatFlags)); | 1934 this->getFilterQuality(), flatFlags)); |
1925 buffer.writeUInt(pack_4(this->getStrokeCap(), this->getStrokeJoin(), | 1935 buffer.writeUInt(pack_4(this->getStrokeCap(), this->getStrokeJoin(), |
1926 this->getStyle(), this->getTextEncoding())); | 1936 (this->getStyle() << 4) | this->getTextEncoding(), |
| 1937 fBlendMode)); |
1927 | 1938 |
1928 // now we're done with ptr and the (pre)reserved space. If we need to write | 1939 // now we're done with ptr and the (pre)reserved space. If we need to write |
1929 // additional fields, use the buffer directly | 1940 // additional fields, use the buffer directly |
1930 if (flatFlags & kHasTypeface_FlatFlag) { | 1941 if (flatFlags & kHasTypeface_FlatFlag) { |
1931 buffer.writeTypeface(this->getTypeface()); | 1942 buffer.writeTypeface(this->getTypeface()); |
1932 } | 1943 } |
1933 if (flatFlags & kHasEffects_FlatFlag) { | 1944 if (flatFlags & kHasEffects_FlatFlag) { |
1934 buffer.writeFlattenable(this->getPathEffect()); | 1945 buffer.writeFlattenable(this->getPathEffect()); |
1935 buffer.writeFlattenable(this->getShader()); | 1946 buffer.writeFlattenable(this->getShader()); |
1936 buffer.writeFlattenable(this->getXfermode()); | |
1937 buffer.writeFlattenable(this->getMaskFilter()); | 1947 buffer.writeFlattenable(this->getMaskFilter()); |
1938 buffer.writeFlattenable(this->getColorFilter()); | 1948 buffer.writeFlattenable(this->getColorFilter()); |
1939 buffer.writeFlattenable(this->getRasterizer()); | 1949 buffer.writeFlattenable(this->getRasterizer()); |
1940 buffer.writeFlattenable(this->getLooper()); | 1950 buffer.writeFlattenable(this->getLooper()); |
1941 buffer.writeFlattenable(this->getImageFilter()); | 1951 buffer.writeFlattenable(this->getImageFilter()); |
1942 } | 1952 } |
1943 } | 1953 } |
1944 | 1954 |
1945 void SkPaint::unflatten(SkReadBuffer& buffer) { | 1955 void SkPaint::unflatten(SkReadBuffer& buffer) { |
1946 this->setTextSize(buffer.readScalar()); | 1956 this->setTextSize(buffer.readScalar()); |
1947 this->setTextScaleX(buffer.readScalar()); | 1957 this->setTextScaleX(buffer.readScalar()); |
1948 this->setTextSkewX(buffer.readScalar()); | 1958 this->setTextSkewX(buffer.readScalar()); |
1949 this->setStrokeWidth(buffer.readScalar()); | 1959 this->setStrokeWidth(buffer.readScalar()); |
1950 this->setStrokeMiter(buffer.readScalar()); | 1960 this->setStrokeMiter(buffer.readScalar()); |
1951 this->setColor(buffer.readColor()); | 1961 this->setColor(buffer.readColor()); |
1952 | 1962 |
1953 unsigned flatFlags = unpack_paint_flags(this, buffer.readUInt()); | 1963 unsigned flatFlags = unpack_paint_flags(this, buffer.readUInt()); |
1954 | 1964 |
1955 uint32_t tmp = buffer.readUInt(); | 1965 uint32_t tmp = buffer.readUInt(); |
1956 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); | 1966 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); |
1957 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); | 1967 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); |
1958 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); | 1968 if (buffer.isVersionLT(SkReadBuffer::kXfermodeToBlendMode_Version)) { |
1959 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); | 1969 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); |
| 1970 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); |
| 1971 } else { |
| 1972 this->setStyle(static_cast<Style>((tmp >> 12) & 0xF)); |
| 1973 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 8) & 0xF)); |
| 1974 this->setBlendMode((SkBlendMode)(tmp & 0xFF)); |
| 1975 } |
1960 | 1976 |
1961 if (flatFlags & kHasTypeface_FlatFlag) { | 1977 if (flatFlags & kHasTypeface_FlatFlag) { |
1962 this->setTypeface(buffer.readTypeface()); | 1978 this->setTypeface(buffer.readTypeface()); |
1963 } else { | 1979 } else { |
1964 this->setTypeface(nullptr); | 1980 this->setTypeface(nullptr); |
1965 } | 1981 } |
1966 | 1982 |
1967 if (flatFlags & kHasEffects_FlatFlag) { | 1983 if (flatFlags & kHasEffects_FlatFlag) { |
1968 this->setPathEffect(buffer.readPathEffect()); | 1984 this->setPathEffect(buffer.readPathEffect()); |
1969 this->setShader(buffer.readShader()); | 1985 this->setShader(buffer.readShader()); |
1970 this->setXfermode(buffer.readXfermode()); | 1986 if (buffer.isVersionLT(SkReadBuffer::kXfermodeToBlendMode_Version)) { |
| 1987 sk_sp<SkXfermode> xfer = buffer.readXfermode(); |
| 1988 this->setBlendMode(xfer ? xfer->blend() : SkBlendMode::kSrcOver); |
| 1989 } |
1971 this->setMaskFilter(buffer.readMaskFilter()); | 1990 this->setMaskFilter(buffer.readMaskFilter()); |
1972 this->setColorFilter(buffer.readColorFilter()); | 1991 this->setColorFilter(buffer.readColorFilter()); |
1973 this->setRasterizer(buffer.readRasterizer()); | 1992 this->setRasterizer(buffer.readRasterizer()); |
1974 this->setLooper(buffer.readDrawLooper()); | 1993 this->setLooper(buffer.readDrawLooper()); |
1975 this->setImageFilter(buffer.readImageFilter()); | 1994 this->setImageFilter(buffer.readImageFilter()); |
1976 | 1995 |
1977 if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version))
{ | 1996 if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version))
{ |
1978 // We used to store annotations here (string+skdata) if this bool wa
s true | 1997 // We used to store annotations here (string+skdata) if this bool wa
s true |
1979 if (buffer.readBool()) { | 1998 if (buffer.readBool()) { |
1980 // Annotations have moved to drawAnnotation, so we just drop thi
s one on the floor. | 1999 // Annotations have moved to drawAnnotation, so we just drop thi
s one on the floor. |
1981 SkString key; | 2000 SkString key; |
1982 buffer.readString(&key); | 2001 buffer.readString(&key); |
1983 (void)buffer.readByteArrayAsData(); | 2002 (void)buffer.readByteArrayAsData(); |
1984 } | 2003 } |
1985 } | 2004 } |
1986 } else { | 2005 } else { |
1987 this->setPathEffect(nullptr); | 2006 this->setPathEffect(nullptr); |
1988 this->setShader(nullptr); | 2007 this->setShader(nullptr); |
1989 this->setXfermode(nullptr); | |
1990 this->setMaskFilter(nullptr); | 2008 this->setMaskFilter(nullptr); |
1991 this->setColorFilter(nullptr); | 2009 this->setColorFilter(nullptr); |
1992 this->setRasterizer(nullptr); | 2010 this->setRasterizer(nullptr); |
1993 this->setLooper(nullptr); | 2011 this->setLooper(nullptr); |
1994 this->setImageFilter(nullptr); | 2012 this->setImageFilter(nullptr); |
1995 } | 2013 } |
1996 } | 2014 } |
1997 | 2015 |
1998 /////////////////////////////////////////////////////////////////////////////// | 2016 /////////////////////////////////////////////////////////////////////////////// |
1999 | 2017 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 str->append("</dd>"); | 2127 str->append("</dd>"); |
2110 } | 2128 } |
2111 | 2129 |
2112 SkShader* shader = this->getShader(); | 2130 SkShader* shader = this->getShader(); |
2113 if (shader) { | 2131 if (shader) { |
2114 str->append("<dt>Shader:</dt><dd>"); | 2132 str->append("<dt>Shader:</dt><dd>"); |
2115 shader->toString(str); | 2133 shader->toString(str); |
2116 str->append("</dd>"); | 2134 str->append("</dd>"); |
2117 } | 2135 } |
2118 | 2136 |
2119 SkXfermode* xfer = this->getXfermode(); | 2137 if (!this->isSrcOver()) { |
2120 if (xfer) { | 2138 str->appendf("<dt>Xfermode:</dt><dd>%d</dd>", fBlendMode); |
2121 str->append("<dt>Xfermode:</dt><dd>"); | |
2122 xfer->toString(str); | |
2123 str->append("</dd>"); | |
2124 } | 2139 } |
2125 | 2140 |
2126 SkMaskFilter* maskFilter = this->getMaskFilter(); | 2141 SkMaskFilter* maskFilter = this->getMaskFilter(); |
2127 if (maskFilter) { | 2142 if (maskFilter) { |
2128 str->append("<dt>MaskFilter:</dt><dd>"); | 2143 str->append("<dt>MaskFilter:</dt><dd>"); |
2129 maskFilter->toString(str); | 2144 maskFilter->toString(str); |
2130 str->append("</dd>"); | 2145 str->append("</dd>"); |
2131 } | 2146 } |
2132 | 2147 |
2133 SkColorFilter* colorFilter = this->getColorFilter(); | 2148 SkColorFilter* colorFilter = this->getColorFilter(); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 static bool affects_alpha(const SkImageFilter* imf) { | 2371 static bool affects_alpha(const SkImageFilter* imf) { |
2357 // TODO: check if we should allow imagefilters to broadcast that they don't
affect alpha | 2372 // TODO: check if we should allow imagefilters to broadcast that they don't
affect alpha |
2358 // ala colorfilters | 2373 // ala colorfilters |
2359 return imf != nullptr; | 2374 return imf != nullptr; |
2360 } | 2375 } |
2361 | 2376 |
2362 bool SkPaint::nothingToDraw() const { | 2377 bool SkPaint::nothingToDraw() const { |
2363 if (fDrawLooper) { | 2378 if (fDrawLooper) { |
2364 return false; | 2379 return false; |
2365 } | 2380 } |
2366 SkXfermode::Mode mode; | 2381 switch ((SkBlendMode)fBlendMode) { |
2367 if (SkXfermode::AsMode(fXfermode.get(), &mode)) { | 2382 case SkBlendMode::kSrcOver: |
2368 switch (mode) { | 2383 case SkBlendMode::kSrcATop: |
2369 case SkXfermode::kSrcOver_Mode: | 2384 case SkBlendMode::kDstOut: |
2370 case SkXfermode::kSrcATop_Mode: | 2385 case SkBlendMode::kDstOver: |
2371 case SkXfermode::kDstOut_Mode: | 2386 case SkBlendMode::kPlus: |
2372 case SkXfermode::kDstOver_Mode: | 2387 if (0 == this->getAlpha()) { |
2373 case SkXfermode::kPlus_Mode: | 2388 return !affects_alpha(fColorFilter.get()) && !affects_alpha(fIma
geFilter.get()); |
2374 if (0 == this->getAlpha()) { | 2389 } |
2375 return !affects_alpha(fColorFilter.get()) && !affects_alpha(
fImageFilter.get()); | 2390 break; |
2376 } | 2391 case SkBlendMode::kDst: |
2377 break; | 2392 return true; |
2378 case SkXfermode::kDst_Mode: | 2393 default: |
2379 return true; | 2394 break; |
2380 default: | |
2381 break; | |
2382 } | |
2383 } | 2395 } |
2384 return false; | 2396 return false; |
2385 } | 2397 } |
2386 | 2398 |
2387 uint32_t SkPaint::getHash() const { | 2399 uint32_t SkPaint::getHash() const { |
2388 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, | 2400 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, |
2389 // so fBitfields should be 10 pointers and 6 32-bit values from the start. | 2401 // so fBitfields should be 10 pointers and 6 32-bit values from the start. |
2390 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo
f(uint32_t), | 2402 static_assert(offsetof(SkPaint, fBitfields) == 8 * sizeof(void*) + 7 * sizeo
f(uint32_t), |
2391 "SkPaint_notPackedTightly"); | 2403 "SkPaint_notPackedTightly"); |
2392 return SkOpts::hash(reinterpret_cast<const uint32_t*>(this), | 2404 return SkOpts::hash(reinterpret_cast<const uint32_t*>(this), |
2393 offsetof(SkPaint, fBitfields) + sizeof(fBitfields)); | 2405 offsetof(SkPaint, fBitfields) + sizeof(fBitfields)); |
2394 } | 2406 } |
OLD | NEW |