| 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 "SkImageFilter.h" | 8 #include "SkImageFilter.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkFlattenableBuffers.h" | 11 #include "SkFlattenableBuffers.h" |
| 12 #include "SkRect.h" | 12 #include "SkRect.h" |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 #include "GrContext.h" | 14 #include "GrContext.h" |
| 15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 #include "SkImageFilterUtils.h" | 16 #include "SkImageFilterUtils.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 SK_DEFINE_INST_COUNT(SkImageFilter) | 19 SK_DEFINE_INST_COUNT(SkImageFilter) |
| 20 | 20 |
| 21 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
ect* cropRect) | 21 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
ect* cropRect) |
| 22 : fInputCount(inputCount), | 22 : fInputCount(inputCount), |
| 23 fInputs(new SkImageFilter*[inputCount]), | 23 fInputs(new SkImageFilter*[inputCount]), |
| 24 #ifdef SK_CROP_RECT_IS_INT | |
| 25 fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { | |
| 26 #else | |
| 27 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)) { | 24 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)) { |
| 28 #endif | |
| 29 for (int i = 0; i < inputCount; ++i) { | 25 for (int i = 0; i < inputCount; ++i) { |
| 30 fInputs[i] = inputs[i]; | 26 fInputs[i] = inputs[i]; |
| 31 SkSafeRef(fInputs[i]); | 27 SkSafeRef(fInputs[i]); |
| 32 } | 28 } |
| 33 } | 29 } |
| 34 | 30 |
| 35 SkImageFilter::SkImageFilter(SkImageFilter* input, const CropRect* cropRect) | 31 SkImageFilter::SkImageFilter(SkImageFilter* input, const CropRect* cropRect) |
| 36 : fInputCount(1), | 32 : fInputCount(1), |
| 37 fInputs(new SkImageFilter*[1]), | 33 fInputs(new SkImageFilter*[1]), |
| 38 #ifdef SK_CROP_RECT_IS_INT | |
| 39 fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { | |
| 40 #else | |
| 41 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)) { | 34 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)) { |
| 42 #endif | |
| 43 fInputs[0] = input; | 35 fInputs[0] = input; |
| 44 SkSafeRef(fInputs[0]); | 36 SkSafeRef(fInputs[0]); |
| 45 } | 37 } |
| 46 | 38 |
| 47 SkImageFilter::SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const
CropRect* cropRect) | 39 SkImageFilter::SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const
CropRect* cropRect) |
| 48 : fInputCount(2), fInputs(new SkImageFilter*[2]), | 40 : fInputCount(2), fInputs(new SkImageFilter*[2]), |
| 49 #ifdef SK_CROP_RECT_IS_INT | |
| 50 fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { | |
| 51 #else | |
| 52 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)) { | 41 fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)) { |
| 53 #endif | |
| 54 fInputs[0] = input1; | 42 fInputs[0] = input1; |
| 55 fInputs[1] = input2; | 43 fInputs[1] = input2; |
| 56 SkSafeRef(fInputs[0]); | 44 SkSafeRef(fInputs[0]); |
| 57 SkSafeRef(fInputs[1]); | 45 SkSafeRef(fInputs[1]); |
| 58 } | 46 } |
| 59 | 47 |
| 60 SkImageFilter::~SkImageFilter() { | 48 SkImageFilter::~SkImageFilter() { |
| 61 for (int i = 0; i < fInputCount; i++) { | 49 for (int i = 0; i < fInputCount; i++) { |
| 62 SkSafeUnref(fInputs[i]); | 50 SkSafeUnref(fInputs[i]); |
| 63 } | 51 } |
| 64 delete[] fInputs; | 52 delete[] fInputs; |
| 65 } | 53 } |
| 66 | 54 |
| 67 SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer) | 55 SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer) |
| 68 : fInputCount(buffer.readInt()), fInputs(new SkImageFilter*[fInputCount]) { | 56 : fInputCount(buffer.readInt()), fInputs(new SkImageFilter*[fInputCount]) { |
| 69 for (int i = 0; i < fInputCount; i++) { | 57 for (int i = 0; i < fInputCount; i++) { |
| 70 if (buffer.readBool()) { | 58 if (buffer.readBool()) { |
| 71 fInputs[i] = buffer.readImageFilter(); | 59 fInputs[i] = buffer.readImageFilter(); |
| 72 } else { | 60 } else { |
| 73 fInputs[i] = NULL; | 61 fInputs[i] = NULL; |
| 74 } | 62 } |
| 75 } | 63 } |
| 76 #ifdef SK_CROP_RECT_IS_INT | |
| 77 buffer.readIRect(&fCropRect); | |
| 78 #else | |
| 79 buffer.readRect(&fCropRect.fRect); | 64 buffer.readRect(&fCropRect.fRect); |
| 80 fCropRect.fFlags = buffer.readUInt(); | 65 fCropRect.fFlags = buffer.readUInt(); |
| 81 #endif | |
| 82 } | 66 } |
| 83 | 67 |
| 84 void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 68 void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 85 buffer.writeInt(fInputCount); | 69 buffer.writeInt(fInputCount); |
| 86 for (int i = 0; i < fInputCount; i++) { | 70 for (int i = 0; i < fInputCount; i++) { |
| 87 SkImageFilter* input = getInput(i); | 71 SkImageFilter* input = getInput(i); |
| 88 buffer.writeBool(input != NULL); | 72 buffer.writeBool(input != NULL); |
| 89 if (input != NULL) { | 73 if (input != NULL) { |
| 90 buffer.writeFlattenable(input); | 74 buffer.writeFlattenable(input); |
| 91 } | 75 } |
| 92 } | 76 } |
| 93 #ifdef SK_CROP_RECT_IS_INT | |
| 94 buffer.writeIRect(fCropRect); | |
| 95 #else | |
| 96 buffer.writeRect(fCropRect.fRect); | 77 buffer.writeRect(fCropRect.fRect); |
| 97 buffer.writeUInt(fCropRect.fFlags); | 78 buffer.writeUInt(fCropRect.fFlags); |
| 98 #endif | |
| 99 } | 79 } |
| 100 | 80 |
| 101 bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, | 81 bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, |
| 102 const SkMatrix& ctm, | 82 const SkMatrix& ctm, |
| 103 SkBitmap* result, SkIPoint* loc) { | 83 SkBitmap* result, SkIPoint* loc) { |
| 104 SkASSERT(result); | 84 SkASSERT(result); |
| 105 SkASSERT(loc); | 85 SkASSERT(loc); |
| 106 /* | 86 /* |
| 107 * Give the proxy first shot at the filter. If it returns false, ask | 87 * Give the proxy first shot at the filter. If it returns false, ask |
| 108 * the filter to do it. | 88 * the filter to do it. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 offset->fX += bounds.left(); | 151 offset->fX += bounds.left(); |
| 172 offset->fY += bounds.top(); | 152 offset->fY += bounds.top(); |
| 173 return true; | 153 return true; |
| 174 #else | 154 #else |
| 175 return false; | 155 return false; |
| 176 #endif | 156 #endif |
| 177 } | 157 } |
| 178 | 158 |
| 179 bool SkImageFilter::applyCropRect(SkIRect* rect, const SkMatrix& matrix) const { | 159 bool SkImageFilter::applyCropRect(SkIRect* rect, const SkMatrix& matrix) const { |
| 180 SkRect cropRect; | 160 SkRect cropRect; |
| 181 #ifdef SK_CROP_RECT_IS_INT | |
| 182 matrix.mapRect(&cropRect, SkRect::Make(fCropRect)); | |
| 183 SkIRect cropRectI; | |
| 184 cropRect.roundOut(&cropRectI); | |
| 185 // If the original crop rect edges were unset, max out the new crop edges | |
| 186 if (fCropRect.fLeft == SK_MinS32) cropRectI.fLeft = SK_MinS32; | |
| 187 if (fCropRect.fTop == SK_MinS32) cropRectI.fTop = SK_MinS32; | |
| 188 if (fCropRect.fRight == SK_MaxS32) cropRectI.fRight = SK_MaxS32; | |
| 189 if (fCropRect.fBottom == SK_MaxS32) cropRectI.fBottom = SK_MaxS32; | |
| 190 #else | |
| 191 matrix.mapRect(&cropRect, fCropRect.fRect); | 161 matrix.mapRect(&cropRect, fCropRect.fRect); |
| 192 SkIRect cropRectI; | 162 SkIRect cropRectI; |
| 193 cropRect.roundOut(&cropRectI); | 163 cropRect.roundOut(&cropRectI); |
| 194 // If the original crop rect edges were unset, max out the new crop edges | 164 // If the original crop rect edges were unset, max out the new crop edges |
| 195 if (!(fCropRect.fFlags & CropRect::kHasLeft_CropEdge)) cropRectI.fLeft = SK_
MinS32; | 165 if (!(fCropRect.fFlags & CropRect::kHasLeft_CropEdge)) cropRectI.fLeft = SK_
MinS32; |
| 196 if (!(fCropRect.fFlags & CropRect::kHasTop_CropEdge)) cropRectI.fTop = SK_Mi
nS32; | 166 if (!(fCropRect.fFlags & CropRect::kHasTop_CropEdge)) cropRectI.fTop = SK_Mi
nS32; |
| 197 if (!(fCropRect.fFlags & CropRect::kHasRight_CropEdge)) cropRectI.fRight = S
K_MaxS32; | 167 if (!(fCropRect.fFlags & CropRect::kHasRight_CropEdge)) cropRectI.fRight = S
K_MaxS32; |
| 198 if (!(fCropRect.fFlags & CropRect::kHasBottom_CropEdge)) cropRectI.fBottom =
SK_MaxS32; | 168 if (!(fCropRect.fFlags & CropRect::kHasBottom_CropEdge)) cropRectI.fBottom =
SK_MaxS32; |
| 199 #endif | |
| 200 return rect->intersect(cropRectI); | 169 return rect->intersect(cropRectI); |
| 201 } | 170 } |
| 202 | 171 |
| 203 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 172 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 204 SkIRect* dst) { | 173 SkIRect* dst) { |
| 205 *dst = src; | 174 *dst = src; |
| 206 return true; | 175 return true; |
| 207 } | 176 } |
| 208 | 177 |
| 209 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkMatrix&) cons
t { | 178 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkMatrix&) cons
t { |
| 210 return false; | 179 return false; |
| 211 } | 180 } |
| 212 | 181 |
| 213 bool SkImageFilter::asColorFilter(SkColorFilter**) const { | 182 bool SkImageFilter::asColorFilter(SkColorFilter**) const { |
| 214 return false; | 183 return false; |
| 215 } | 184 } |
| OLD | NEW |