| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 ///////////////////////////////////////////////////////////////////////////// | 384 ///////////////////////////////////////////////////////////////////////////// |
| 385 | 385 |
| 386 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { | 386 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { |
| 387 return lazy->isValid() ? lazy->get() : lazy->set(orig); | 387 return lazy->isValid() ? lazy->get() : lazy->set(orig); |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * If the paint has an imagefilter, but it can be simplified to just a colorfil
ter, return that | 391 * If the paint has an imagefilter, but it can be simplified to just a colorfil
ter, return that |
| 392 * colorfilter, else return nullptr. | 392 * colorfilter, else return nullptr. |
| 393 */ | 393 */ |
| 394 static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) { | 394 static SkColorFilter* image_to_color_filter(const SkPaint& paint) { |
| 395 SkImageFilter* imgf = paint.getImageFilter(); | 395 SkImageFilter* imgf = paint.getImageFilter(); |
| 396 if (!imgf) { | 396 if (!imgf) { |
| 397 return nullptr; | 397 return nullptr; |
| 398 } | 398 } |
| 399 | 399 |
| 400 SkColorFilter* imgCFPtr; | 400 SkColorFilter* imgCF; |
| 401 if (!imgf->asAColorFilter(&imgCFPtr)) { | 401 if (!imgf->asAColorFilter(&imgCF)) { |
| 402 return nullptr; | 402 return nullptr; |
| 403 } | 403 } |
| 404 sk_sp<SkColorFilter> imgCF(imgCFPtr); | |
| 405 | 404 |
| 406 SkColorFilter* paintCF = paint.getColorFilter(); | 405 SkColorFilter* paintCF = paint.getColorFilter(); |
| 407 if (nullptr == paintCF) { | 406 if (nullptr == paintCF) { |
| 408 // there is no existing paint colorfilter, so we can just return the ima
gefilter's | 407 // there is no existing paint colorfilter, so we can just return the ima
gefilter's |
| 409 return imgCF; | 408 return imgCF; |
| 410 } | 409 } |
| 411 | 410 |
| 412 // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-c
olorfilter(imgCF) | 411 // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-c
olorfilter(imgCF) |
| 413 // and we need to combine them into a single colorfilter. | 412 // and we need to combine them into a single colorfilter. |
| 414 return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF)
); | 413 SkAutoTUnref<SkColorFilter> autoImgCF(imgCF); |
| 414 return SkColorFilter::CreateComposeFilter(imgCF, paintCF); |
| 415 } | 415 } |
| 416 | 416 |
| 417 /** | 417 /** |
| 418 * There are many bounds in skia. A circle's bounds is just its center extended
by its radius. | 418 * There are many bounds in skia. A circle's bounds is just its center extended
by its radius. |
| 419 * However, if we stroke a circle, then the "bounds" of that is larger, since it
will now draw | 419 * However, if we stroke a circle, then the "bounds" of that is larger, since it
will now draw |
| 420 * outside of its raw-bounds by 1/2 the stroke width. SkPaint has lots of optio
nal | 420 * outside of its raw-bounds by 1/2 the stroke width. SkPaint has lots of optio
nal |
| 421 * effects/attributes that can modify the effective bounds of a given primitive
-- maskfilters, | 421 * effects/attributes that can modify the effective bounds of a given primitive
-- maskfilters, |
| 422 * patheffects, stroking, etc. This function takes a raw bounds and a paint, an
d returns the | 422 * patheffects, stroking, etc. This function takes a raw bounds and a paint, an
d returns the |
| 423 * conservative "effective" bounds based on the settings in the paint... with on
e exception. This | 423 * conservative "effective" bounds based on the settings in the paint... with on
e exception. This |
| 424 * function does *not* look at the imagefilter, which can also modify the effect
ive bounds. It is | 424 * function does *not* look at the imagefilter, which can also modify the effect
ive bounds. It is |
| (...skipping 23 matching lines...) Expand all Loading... |
| 448 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER | 448 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 449 fFilter = canvas->getDrawFilter(); | 449 fFilter = canvas->getDrawFilter(); |
| 450 #else | 450 #else |
| 451 fFilter = nullptr; | 451 fFilter = nullptr; |
| 452 #endif | 452 #endif |
| 453 fPaint = &fOrigPaint; | 453 fPaint = &fOrigPaint; |
| 454 fSaveCount = canvas->getSaveCount(); | 454 fSaveCount = canvas->getSaveCount(); |
| 455 fTempLayerForImageFilter = false; | 455 fTempLayerForImageFilter = false; |
| 456 fDone = false; | 456 fDone = false; |
| 457 | 457 |
| 458 auto simplifiedCF = image_to_color_filter(fOrigPaint); | 458 SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint); |
| 459 if (simplifiedCF) { | 459 if (simplifiedCF) { |
| 460 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); | 460 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); |
| 461 paint->setColorFilter(std::move(simplifiedCF)); | 461 paint->setColorFilter(simplifiedCF)->unref(); |
| 462 paint->setImageFilter(nullptr); | 462 paint->setImageFilter(nullptr); |
| 463 fPaint = paint; | 463 fPaint = paint; |
| 464 } | 464 } |
| 465 | 465 |
| 466 if (!skipLayerForImageFilter && fPaint->getImageFilter()) { | 466 if (!skipLayerForImageFilter && fPaint->getImageFilter()) { |
| 467 /** | 467 /** |
| 468 * We implement ImageFilters for a given draw by creating a layer,
then applying the | 468 * We implement ImageFilters for a given draw by creating a layer,
then applying the |
| 469 * imagefilter to the pixels of that layer (its backing surface/ima
ge), and then | 469 * imagefilter to the pixels of that layer (its backing surface/ima
ge), and then |
| 470 * we call restore() to xfer that layer to the main canvas. | 470 * we call restore() to xfer that layer to the main canvas. |
| 471 * | 471 * |
| (...skipping 2564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 } | 3036 } |
| 3037 | 3037 |
| 3038 if (matrix) { | 3038 if (matrix) { |
| 3039 canvas->concat(*matrix); | 3039 canvas->concat(*matrix); |
| 3040 } | 3040 } |
| 3041 } | 3041 } |
| 3042 | 3042 |
| 3043 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3043 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 3044 fCanvas->restoreToCount(fSaveCount); | 3044 fCanvas->restoreToCount(fSaveCount); |
| 3045 } | 3045 } |
| OLD | NEW |