| 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) | 21 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const SkIRe
ct* cropRect) |
| 22 : fInputCount(inputCount), fInputs(new SkImageFilter*[inputCount]) { | 22 : fInputCount(inputCount), |
| 23 fInputs(new SkImageFilter*[inputCount]), |
| 24 fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { |
| 23 for (int i = 0; i < inputCount; ++i) { | 25 for (int i = 0; i < inputCount; ++i) { |
| 24 fInputs[i] = inputs[i]; | 26 fInputs[i] = inputs[i]; |
| 25 SkSafeRef(fInputs[i]); | 27 SkSafeRef(fInputs[i]); |
| 26 } | 28 } |
| 27 } | 29 } |
| 28 | 30 |
| 29 SkImageFilter::SkImageFilter(SkImageFilter* input) | 31 SkImageFilter::SkImageFilter(SkImageFilter* input, const SkIRect* cropRect) |
| 30 : fInputCount(1), fInputs(new SkImageFilter*[1]) { | 32 : fInputCount(1), |
| 33 fInputs(new SkImageFilter*[1]), |
| 34 fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { |
| 31 fInputs[0] = input; | 35 fInputs[0] = input; |
| 32 SkSafeRef(fInputs[0]); | 36 SkSafeRef(fInputs[0]); |
| 33 } | 37 } |
| 34 | 38 |
| 35 SkImageFilter::SkImageFilter(SkImageFilter* input1, SkImageFilter* input2) | 39 SkImageFilter::SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const
SkIRect* cropRect) |
| 36 : fInputCount(2), fInputs(new SkImageFilter*[2]) { | 40 : fInputCount(2), fInputs(new SkImageFilter*[2]), |
| 41 fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { |
| 37 fInputs[0] = input1; | 42 fInputs[0] = input1; |
| 38 fInputs[1] = input2; | 43 fInputs[1] = input2; |
| 39 SkSafeRef(fInputs[0]); | 44 SkSafeRef(fInputs[0]); |
| 40 SkSafeRef(fInputs[1]); | 45 SkSafeRef(fInputs[1]); |
| 41 } | 46 } |
| 42 | 47 |
| 43 SkImageFilter::~SkImageFilter() { | 48 SkImageFilter::~SkImageFilter() { |
| 44 for (int i = 0; i < fInputCount; i++) { | 49 for (int i = 0; i < fInputCount; i++) { |
| 45 SkSafeUnref(fInputs[i]); | 50 SkSafeUnref(fInputs[i]); |
| 46 } | 51 } |
| 47 delete[] fInputs; | 52 delete[] fInputs; |
| 48 } | 53 } |
| 49 | 54 |
| 50 SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer) | 55 SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer) |
| 51 : fInputCount(buffer.readInt()), fInputs(new SkImageFilter*[fInputCount]) { | 56 : fInputCount(buffer.readInt()), fInputs(new SkImageFilter*[fInputCount]) { |
| 52 for (int i = 0; i < fInputCount; i++) { | 57 for (int i = 0; i < fInputCount; i++) { |
| 53 if (buffer.readBool()) { | 58 if (buffer.readBool()) { |
| 54 fInputs[i] = static_cast<SkImageFilter*>(buffer.readFlattenable()); | 59 fInputs[i] = static_cast<SkImageFilter*>(buffer.readFlattenable()); |
| 55 } else { | 60 } else { |
| 56 fInputs[i] = NULL; | 61 fInputs[i] = NULL; |
| 57 } | 62 } |
| 58 } | 63 } |
| 64 buffer.readIRect(&fCropRect); |
| 59 } | 65 } |
| 60 | 66 |
| 61 void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 67 void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 62 buffer.writeInt(fInputCount); | 68 buffer.writeInt(fInputCount); |
| 63 for (int i = 0; i < fInputCount; i++) { | 69 for (int i = 0; i < fInputCount; i++) { |
| 64 SkImageFilter* input = getInput(i); | 70 SkImageFilter* input = getInput(i); |
| 65 buffer.writeBool(input != NULL); | 71 buffer.writeBool(input != NULL); |
| 66 if (input != NULL) { | 72 if (input != NULL) { |
| 67 buffer.writeFlattenable(input); | 73 buffer.writeFlattenable(input); |
| 68 } | 74 } |
| 69 } | 75 } |
| 76 buffer.writeIRect(fCropRect); |
| 70 } | 77 } |
| 71 | 78 |
| 72 bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, | 79 bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, |
| 73 const SkMatrix& ctm, | 80 const SkMatrix& ctm, |
| 74 SkBitmap* result, SkIPoint* loc) { | 81 SkBitmap* result, SkIPoint* loc) { |
| 75 SkASSERT(result); | 82 SkASSERT(result); |
| 76 SkASSERT(loc); | 83 SkASSERT(loc); |
| 77 /* | 84 /* |
| 78 * Give the proxy first shot at the filter. If it returns false, ask | 85 * Give the proxy first shot at the filter. If it returns false, ask |
| 79 * the filter to do it. | 86 * the filter to do it. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 paint.addColorEffect(effect); | 137 paint.addColorEffect(effect); |
| 131 context->drawRect(paint, rect); | 138 context->drawRect(paint, rect); |
| 132 SkAutoTUnref<GrTexture> resultTex(dst.detach()); | 139 SkAutoTUnref<GrTexture> resultTex(dst.detach()); |
| 133 SkImageFilterUtils::WrapTexture(resultTex, input.width(), input.height(), re
sult); | 140 SkImageFilterUtils::WrapTexture(resultTex, input.width(), input.height(), re
sult); |
| 134 return true; | 141 return true; |
| 135 #else | 142 #else |
| 136 return false; | 143 return false; |
| 137 #endif | 144 #endif |
| 138 } | 145 } |
| 139 | 146 |
| 147 bool SkImageFilter::applyCropRect(SkIRect* rect) const { |
| 148 return rect->intersect(fCropRect); |
| 149 } |
| 150 |
| 140 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 151 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 141 SkIRect* dst) { | 152 SkIRect* dst) { |
| 142 *dst = src; | 153 *dst = src; |
| 143 return true; | 154 return true; |
| 144 } | 155 } |
| 145 | 156 |
| 146 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const { | 157 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const { |
| 147 return false; | 158 return false; |
| 148 } | 159 } |
| 149 | 160 |
| 150 bool SkImageFilter::asColorFilter(SkColorFilter**) const { | 161 bool SkImageFilter::asColorFilter(SkColorFilter**) const { |
| 151 return false; | 162 return false; |
| 152 } | 163 } |
| OLD | NEW |