| 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 "SkChecksum.h" | 10 #include "SkChecksum.h" |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR | 373 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR |
| 374 SET_PTR(Rasterizer) | 374 SET_PTR(Rasterizer) |
| 375 #endif | 375 #endif |
| 376 SET_PTR(ImageFilter) | 376 SET_PTR(ImageFilter) |
| 377 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR | 377 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR |
| 378 SET_PTR(Shader) | 378 SET_PTR(Shader) |
| 379 #endif | 379 #endif |
| 380 #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR | 380 #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR |
| 381 SET_PTR(ColorFilter) | 381 SET_PTR(ColorFilter) |
| 382 #endif | 382 #endif |
| 383 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR |
| 383 SET_PTR(Xfermode) | 384 SET_PTR(Xfermode) |
| 385 #endif |
| 384 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR | 386 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
| 385 SET_PTR(PathEffect) | 387 SET_PTR(PathEffect) |
| 386 #endif | 388 #endif |
| 387 SET_PTR(MaskFilter) | 389 SET_PTR(MaskFilter) |
| 388 #undef SET_PTR | 390 #undef SET_PTR |
| 389 | 391 |
| 390 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR | 392 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR |
| 391 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { | 393 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { |
| 392 fLooper.reset(SkSafeRef(looper)); | 394 fLooper.reset(SkSafeRef(looper)); |
| 393 return looper; | 395 return looper; |
| 394 } | 396 } |
| 395 #endif | 397 #endif |
| 396 | 398 |
| 397 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { | 399 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { |
| 398 fXfermode.reset(SkXfermode::Create(mode)); | 400 fXfermode = SkXfermode::Make(mode); |
| 399 return fXfermode.get(); | 401 return fXfermode.get(); // can/should we change this API to be void, like th
e other setters? |
| 400 } | 402 } |
| 401 | 403 |
| 402 /////////////////////////////////////////////////////////////////////////////// | 404 /////////////////////////////////////////////////////////////////////////////// |
| 403 | 405 |
| 404 static SkScalar mag2(SkScalar x, SkScalar y) { | 406 static SkScalar mag2(SkScalar x, SkScalar y) { |
| 405 return x * x + y * y; | 407 return x * x + y * y; |
| 406 } | 408 } |
| 407 | 409 |
| 408 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { | 410 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { |
| 409 return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max | 411 return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max |
| (...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 | 1922 |
| 1921 if (flatFlags & kHasTypeface_FlatFlag) { | 1923 if (flatFlags & kHasTypeface_FlatFlag) { |
| 1922 this->setTypeface(buffer.readTypeface()); | 1924 this->setTypeface(buffer.readTypeface()); |
| 1923 } else { | 1925 } else { |
| 1924 this->setTypeface(nullptr); | 1926 this->setTypeface(nullptr); |
| 1925 } | 1927 } |
| 1926 | 1928 |
| 1927 if (flatFlags & kHasEffects_FlatFlag) { | 1929 if (flatFlags & kHasEffects_FlatFlag) { |
| 1928 this->setPathEffect(buffer.readPathEffect()); | 1930 this->setPathEffect(buffer.readPathEffect()); |
| 1929 this->setShader(buffer.readShader()); | 1931 this->setShader(buffer.readShader()); |
| 1930 SkSafeUnref(this->setXfermode(buffer.readXfermode())); | 1932 this->setXfermode(buffer.readXfermode()); |
| 1931 SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter())); | 1933 SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter())); |
| 1932 this->setColorFilter(buffer.readColorFilter()); | 1934 this->setColorFilter(buffer.readColorFilter()); |
| 1933 this->setRasterizer(buffer.readRasterizer()); | 1935 this->setRasterizer(buffer.readRasterizer()); |
| 1934 this->setLooper(buffer.readDrawLooper()); | 1936 this->setLooper(buffer.readDrawLooper()); |
| 1935 SkSafeUnref(this->setImageFilter(buffer.readImageFilter())); | 1937 SkSafeUnref(this->setImageFilter(buffer.readImageFilter())); |
| 1936 | 1938 |
| 1937 if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version))
{ | 1939 if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version))
{ |
| 1938 // We used to store annotations here (string+skdata) if this bool wa
s true | 1940 // We used to store annotations here (string+skdata) if this bool wa
s true |
| 1939 if (buffer.readBool()) { | 1941 if (buffer.readBool()) { |
| 1940 // Annotations have moved to drawAnnotation, so we just drop thi
s one on the floor. | 1942 // Annotations have moved to drawAnnotation, so we just drop thi
s one on the floor. |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2355 } | 2357 } |
| 2356 | 2358 |
| 2357 uint32_t SkPaint::getHash() const { | 2359 uint32_t SkPaint::getHash() const { |
| 2358 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, | 2360 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, |
| 2359 // so fBitfields should be 10 pointers and 6 32-bit values from the start. | 2361 // so fBitfields should be 10 pointers and 6 32-bit values from the start. |
| 2360 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo
f(uint32_t), | 2362 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo
f(uint32_t), |
| 2361 "SkPaint_notPackedTightly"); | 2363 "SkPaint_notPackedTightly"); |
| 2362 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), | 2364 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), |
| 2363 offsetof(SkPaint, fBitfields) + sizeof(fBitfields
)); | 2365 offsetof(SkPaint, fBitfields) + sizeof(fBitfields
)); |
| 2364 } | 2366 } |
| OLD | NEW |