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

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

Issue 675013003: Trying to be consistent when members are allowed to be NULL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed nits Created 6 years, 1 month 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 | « src/core/SkLocalMatrixShader.cpp ('k') | src/effects/SkRectShaderImageFilter.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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 || component_needs_clamping(matrix+5) 53 || component_needs_clamping(matrix+5)
54 || component_needs_clamping(matrix+10) 54 || component_needs_clamping(matrix+10)
55 || component_needs_clamping(matrix+15); 55 || component_needs_clamping(matrix+15);
56 } 56 }
57 57
58 }; 58 };
59 59
60 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, 60 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf,
61 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) { 61 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) {
62 SkASSERT(cf); 62 SkASSERT(cf);
63 if (NULL == cf) {
64 return NULL;
65 }
63 SkScalar colorMatrix[20], inputMatrix[20]; 66 SkScalar colorMatrix[20], inputMatrix[20];
64 SkColorFilter* inputColorFilter; 67 SkColorFilter* inputColorFilter;
65 if (input && cf->asColorMatrix(colorMatrix) 68 if (input && cf->asColorMatrix(colorMatrix)
66 && input->asColorFilter(&inputColorFilter) 69 && input->asColorFilter(&inputColorFilter)
67 && (inputColorFilter)) { 70 && (inputColorFilter)) {
68 SkAutoUnref autoUnref(inputColorFilter); 71 SkAutoUnref autoUnref(inputColorFilter);
69 if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clampi ng(inputMatrix)) { 72 if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clampi ng(inputMatrix)) {
70 SkScalar combinedMatrix[20]; 73 SkScalar combinedMatrix[20];
71 mult_color_matrix(colorMatrix, inputMatrix, combinedMatrix); 74 mult_color_matrix(colorMatrix, inputMatrix, combinedMatrix);
72 SkAutoTUnref<SkColorFilter> newCF(SkColorMatrixFilter::Create(combin edMatrix)); 75 SkAutoTUnref<SkColorFilter> newCF(SkColorMatrixFilter::Create(combin edMatrix));
73 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput( 0), cropRect, 0)); 76 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput( 0), cropRect, 0));
74 } 77 }
75 } 78 }
76 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID)) ; 79 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID)) ;
77 } 80 }
78 81
79 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, 82 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
80 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) 83 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID)
81 : INHERITED(1, &input, cropRect, uniqueID), fColorFilter(cf) { 84 : INHERITED(1, &input, cropRect, uniqueID), fColorFilter(SkRef(cf)) {
82 SkASSERT(cf);
83 SkSafeRef(cf);
84 } 85 }
85 86
86 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 87 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
87 SkColorFilterImageFilter::SkColorFilterImageFilter(SkReadBuffer& buffer) 88 SkColorFilterImageFilter::SkColorFilterImageFilter(SkReadBuffer& buffer)
88 : INHERITED(1, buffer) { 89 : INHERITED(1, buffer) {
89 fColorFilter = buffer.readColorFilter(); 90 fColorFilter = buffer.readColorFilter();
90 } 91 }
91 #endif 92 #endif
92 93
93 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { 94 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) {
94 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 95 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
95 SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter()); 96 SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter());
96 return Create(cf, common.getInput(0), &common.cropRect(), common.uniqueID()) ; 97 return Create(cf, common.getInput(0), &common.cropRect(), common.uniqueID()) ;
97 } 98 }
98 99
99 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { 100 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
100 this->INHERITED::flatten(buffer); 101 this->INHERITED::flatten(buffer);
101 buffer.writeFlattenable(fColorFilter); 102 buffer.writeFlattenable(fColorFilter);
102 } 103 }
103 104
104 SkColorFilterImageFilter::~SkColorFilterImageFilter() { 105 SkColorFilterImageFilter::~SkColorFilterImageFilter() {
105 SkSafeUnref(fColorFilter); 106 fColorFilter->unref();
106 } 107 }
107 108
108 bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc e, 109 bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc e,
109 const Context& ctx, 110 const Context& ctx,
110 SkBitmap* result, 111 SkBitmap* result,
111 SkIPoint* offset) const { 112 SkIPoint* offset) const {
112 SkBitmap src = source; 113 SkBitmap src = source;
113 SkIPoint srcOffset = SkIPoint::Make(0, 0); 114 SkIPoint srcOffset = SkIPoint::Make(0, 0);
114 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO ffset)) { 115 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO ffset)) {
115 return false; 116 return false;
(...skipping 24 matching lines...) Expand all
140 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { 141 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const {
141 if (!cropRectIsSet()) { 142 if (!cropRectIsSet()) {
142 if (filter) { 143 if (filter) {
143 *filter = fColorFilter; 144 *filter = fColorFilter;
144 fColorFilter->ref(); 145 fColorFilter->ref();
145 } 146 }
146 return true; 147 return true;
147 } 148 }
148 return false; 149 return false;
149 } 150 }
OLDNEW
« no previous file with comments | « src/core/SkLocalMatrixShader.cpp ('k') | src/effects/SkRectShaderImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698