Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: src/effects/SkColorFilterImageFilter.cpp

Issue 967833003: check for inputs before reporting asColorFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: check if the composecolorfilter succeeded Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/ImageFilterTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkColorFilterImageFilter.h" 8 #include "SkColorFilterImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorMatrixFilter.h" 11 #include "SkColorMatrixFilter.h"
12 #include "SkDevice.h" 12 #include "SkDevice.h"
13 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
14 #include "SkReadBuffer.h" 14 #include "SkReadBuffer.h"
15 #include "SkTableColorFilter.h" 15 #include "SkTableColorFilter.h"
16 #include "SkWriteBuffer.h" 16 #include "SkWriteBuffer.h"
17 17
18 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, 18 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf,
19 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) { 19 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) {
20 if (NULL == cf) { 20 if (NULL == cf) {
21 return NULL; 21 return NULL;
22 } 22 }
23 23
24 SkColorFilter* inputColorFilter; 24 SkColorFilter* inputCF;
25 if (input && input->asColorFilter(&inputColorFilter)) { 25 if (input && input->asColorFilter(&inputCF)) {
26 SkAutoUnref autoUnref(inputColorFilter); 26 // This is an optimization, as it collapses the hierarchy by just combin ing the two
27 SkAutoTUnref<SkColorFilter> newCF(cf->newComposed(inputColorFilter)); 27 // colorfilters into a single one, which the new imagefilter will wrap.
28 SkAutoUnref autoUnref(inputCF);
29 SkAutoTUnref<SkColorFilter> newCF(SkColorFilter::CreateComposeFilter(cf, inputCF));
28 if (newCF) { 30 if (newCF) {
29 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput( 0), cropRect, 0)); 31 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput( 0), cropRect, 0));
30 } 32 }
31 } 33 }
32 34
33 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID)) ; 35 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID)) ;
34 } 36 }
35 37
36 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, 38 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
37 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) 39 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 paint.setColorFilter(fColorFilter); 81 paint.setColorFilter(fColorFilter);
80 canvas.drawSprite(src, srcOffset.fX - bounds.fLeft, srcOffset.fY - bounds.fT op, &paint); 82 canvas.drawSprite(src, srcOffset.fX - bounds.fLeft, srcOffset.fY - bounds.fT op, &paint);
81 83
82 *result = device.get()->accessBitmap(false); 84 *result = device.get()->accessBitmap(false);
83 offset->fX = bounds.fLeft; 85 offset->fX = bounds.fLeft;
84 offset->fY = bounds.fTop; 86 offset->fY = bounds.fTop;
85 return true; 87 return true;
86 } 88 }
87 89
88 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { 90 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const {
89 if (!cropRectIsSet()) { 91 if (!this->cropRectIsSet()) {
92 SkASSERT(1 == this->countInputs());
93 // Since our factory has already performed the collapse optimization, we can assert that
94 // if we have an input, it is *not* also a colorfilter.
Stephen White 2015/03/05 18:52:18 Since we're now limiting the amount of collapsing
95 SkASSERT(!this->getInput(0) || !this->getInput(0)->asColorFilter(NULL));
90 if (filter) { 96 if (filter) {
91 *filter = fColorFilter; 97 *filter = SkRef(fColorFilter);
92 fColorFilter->ref();
93 } 98 }
94 return true; 99 return true;
95 } 100 }
96 return false; 101 return false;
97 } 102 }
98 103
99 #ifndef SK_IGNORE_TO_STRING 104 #ifndef SK_IGNORE_TO_STRING
100 void SkColorFilterImageFilter::toString(SkString* str) const { 105 void SkColorFilterImageFilter::toString(SkString* str) const {
101 str->appendf("SkColorFilterImageFilter: ("); 106 str->appendf("SkColorFilterImageFilter: (");
102 107
103 str->appendf("input: ("); 108 str->appendf("input: (");
104 109
105 if (this->getInput(0)) { 110 if (this->getInput(0)) {
106 this->getInput(0)->toString(str); 111 this->getInput(0)->toString(str);
107 } 112 }
108 113
109 str->appendf(") color filter: "); 114 str->appendf(") color filter: ");
110 fColorFilter->toString(str); 115 fColorFilter->toString(str);
111 116
112 str->append(")"); 117 str->append(")");
113 } 118 }
114 #endif 119 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698