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 | |
14 #include "GrContext.h" | |
15 #include "GrTexture.h" | |
16 #include "SkImageFilterUtils.h" | |
17 #endif | |
13 | 18 |
14 SK_DEFINE_INST_COUNT(SkImageFilter) | 19 SK_DEFINE_INST_COUNT(SkImageFilter) |
15 | 20 |
16 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs) | 21 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs) |
17 : fInputCount(inputCount), fInputs(new SkImageFilter*[inputCount]) { | 22 : fInputCount(inputCount), fInputs(new SkImageFilter*[inputCount]) { |
18 for (int i = 0; i < inputCount; ++i) { | 23 for (int i = 0; i < inputCount; ++i) { |
19 fInputs[i] = inputs[i]; | 24 fInputs[i] = inputs[i]; |
20 SkSafeRef(fInputs[i]); | 25 SkSafeRef(fInputs[i]); |
21 } | 26 } |
22 } | 27 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 SkASSERT(dst); | 102 SkASSERT(dst); |
98 return this->onFilterBounds(src, ctm, dst); | 103 return this->onFilterBounds(src, ctm, dst); |
99 } | 104 } |
100 | 105 |
101 bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, | 106 bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, |
102 SkBitmap*, SkIPoint*) { | 107 SkBitmap*, SkIPoint*) { |
103 return false; | 108 return false; |
104 } | 109 } |
105 | 110 |
106 bool SkImageFilter::canFilterImageGPU() const { | 111 bool SkImageFilter::canFilterImageGPU() const { |
107 return false; | 112 return asNewEffect(NULL, NULL); |
bsalomon
2013/04/08 19:38:30
this->
| |
108 } | 113 } |
109 | 114 |
110 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result) { | 115 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result) { |
111 SkASSERT(false); // Should never be called, since canFilterImageGPU() retur ned false. | 116 #if SK_SUPPORT_GPU |
117 SkBitmap input; | |
118 SkASSERT(fInputCount == 1); | |
119 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &input)) { | |
bsalomon
2013/04/08 19:38:30
this->
| |
120 return false; | |
121 } | |
122 GrTexture* srcTexture = (GrTexture*) input.getTexture(); | |
123 SkRect rect; | |
124 src.getBounds(&rect); | |
125 GrContext* context = srcTexture->getContext(); | |
126 | |
127 GrTextureDesc desc; | |
128 desc.fFlags = kRenderTarget_GrTextureFlagBit, | |
129 desc.fWidth = input.width(); | |
130 desc.fHeight = input.height(); | |
131 desc.fConfig = kRGBA_8888_GrPixelConfig; | |
132 | |
133 GrAutoScratchTexture dst(context, desc); | |
134 GrContext::AutoMatrix am; | |
135 am.setIdentity(context); | |
136 GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); | |
137 GrContext::AutoClip acs(context, rect); | |
138 GrEffectRef* effect; | |
139 asNewEffect(&effect, srcTexture); | |
bsalomon
2013/04/08 19:38:30
this->
| |
140 SkASSERT(effect); | |
141 SkAutoUnref effectRef(effect); | |
142 GrPaint paint; | |
143 paint.colorStage(0)->setEffect(effect); | |
144 context->drawRect(paint, rect); | |
145 SkAutoTUnref<GrTexture> resultTex(dst.detach()); | |
146 SkImageFilterUtils::WrapTexture(resultTex, input.width(), input.height(), re sult); | |
147 return true; | |
148 #else | |
112 return false; | 149 return false; |
150 #endif | |
113 } | 151 } |
114 | 152 |
115 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 153 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
116 SkIRect* dst) { | 154 SkIRect* dst) { |
117 *dst = src; | 155 *dst = src; |
118 return true; | 156 return true; |
119 } | 157 } |
120 | 158 |
121 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const { | 159 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const { |
122 return false; | 160 return false; |
123 } | 161 } |
124 | 162 |
125 bool SkImageFilter::asColorFilter(SkColorFilter**) const { | 163 bool SkImageFilter::asColorFilter(SkColorFilter**) const { |
126 return false; | 164 return false; |
127 } | 165 } |
OLD | NEW |