OLD | NEW |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 bool matrix_needs_clamping(SkScalar matrix[20]) { | 51 bool matrix_needs_clamping(SkScalar matrix[20]) { |
52 return component_needs_clamping(matrix) | 52 return component_needs_clamping(matrix) |
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) { | 61 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) { |
62 SkASSERT(cf); | 62 SkASSERT(cf); |
63 SkScalar colorMatrix[20], inputMatrix[20]; | 63 SkScalar colorMatrix[20], inputMatrix[20]; |
64 SkColorFilter* inputColorFilter; | 64 SkColorFilter* inputColorFilter; |
65 if (input && cf->asColorMatrix(colorMatrix) | 65 if (input && cf->asColorMatrix(colorMatrix) |
66 && input->asColorFilter(&inputColorFilter) | 66 && input->asColorFilter(&inputColorFilter) |
67 && (NULL != inputColorFilter)) { | 67 && (NULL != inputColorFilter)) { |
68 SkAutoUnref autoUnref(inputColorFilter); | 68 SkAutoUnref autoUnref(inputColorFilter); |
69 if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clampi
ng(inputMatrix)) { | 69 if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clampi
ng(inputMatrix)) { |
70 SkScalar combinedMatrix[20]; | 70 SkScalar combinedMatrix[20]; |
71 mult_color_matrix(colorMatrix, inputMatrix, combinedMatrix); | 71 mult_color_matrix(colorMatrix, inputMatrix, combinedMatrix); |
72 SkAutoTUnref<SkColorFilter> newCF(SkColorMatrixFilter::Create(combin
edMatrix)); | 72 SkAutoTUnref<SkColorFilter> newCF(SkColorMatrixFilter::Create(combin
edMatrix)); |
73 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(
0), cropRect)); | 73 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(
0), cropRect, 0)); |
74 } | 74 } |
75 } | 75 } |
76 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect)); | 76 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID))
; |
77 } | 77 } |
78 | 78 |
79 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, | 79 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, |
80 SkImageFilter* input, const CropRect* cropRect) | 80 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) |
81 : INHERITED(1, &input, cropRect), fColorFilter(cf) { | 81 : INHERITED(1, &input, cropRect, uniqueID), fColorFilter(cf) { |
82 SkASSERT(cf); | 82 SkASSERT(cf); |
83 SkSafeRef(cf); | 83 SkSafeRef(cf); |
84 } | 84 } |
85 | 85 |
86 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | 86 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
87 SkColorFilterImageFilter::SkColorFilterImageFilter(SkReadBuffer& buffer) | 87 SkColorFilterImageFilter::SkColorFilterImageFilter(SkReadBuffer& buffer) |
88 : INHERITED(1, buffer) { | 88 : INHERITED(1, buffer) { |
89 fColorFilter = buffer.readColorFilter(); | 89 fColorFilter = buffer.readColorFilter(); |
90 } | 90 } |
91 #endif | 91 #endif |
92 | 92 |
93 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { | 93 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { |
94 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 94 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
95 SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter()); | 95 SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter()); |
96 return Create(cf, common.getInput(0), &common.cropRect()); | 96 return Create(cf, common.getInput(0), &common.cropRect(), common.uniqueID())
; |
97 } | 97 } |
98 | 98 |
99 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { | 99 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { |
100 this->INHERITED::flatten(buffer); | 100 this->INHERITED::flatten(buffer); |
101 buffer.writeFlattenable(fColorFilter); | 101 buffer.writeFlattenable(fColorFilter); |
102 } | 102 } |
103 | 103 |
104 SkColorFilterImageFilter::~SkColorFilterImageFilter() { | 104 SkColorFilterImageFilter::~SkColorFilterImageFilter() { |
105 SkSafeUnref(fColorFilter); | 105 SkSafeUnref(fColorFilter); |
106 } | 106 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { | 140 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { |
141 if (!cropRectIsSet()) { | 141 if (!cropRectIsSet()) { |
142 if (filter) { | 142 if (filter) { |
143 *filter = fColorFilter; | 143 *filter = fColorFilter; |
144 fColorFilter->ref(); | 144 fColorFilter->ref(); |
145 } | 145 } |
146 return true; | 146 return true; |
147 } | 147 } |
148 return false; | 148 return false; |
149 } | 149 } |
OLD | NEW |