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" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 SkASSERT(dst); | 95 SkASSERT(dst); |
96 return this->onFilterBounds(src, ctm, dst); | 96 return this->onFilterBounds(src, ctm, dst); |
97 } | 97 } |
98 | 98 |
99 bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, | 99 bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, |
100 SkBitmap*, SkIPoint*) { | 100 SkBitmap*, SkIPoint*) { |
101 return false; | 101 return false; |
102 } | 102 } |
103 | 103 |
104 bool SkImageFilter::canFilterImageGPU() const { | 104 bool SkImageFilter::canFilterImageGPU() const { |
105 return this->asNewEffect(NULL, NULL); | 105 return this->asNewEffect(NULL, NULL, SkIPoint::Make(0, 0)); |
106 } | 106 } |
107 | 107 |
108 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap*
result, | 108 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap*
result, |
109 SkIPoint* offset) { | 109 SkIPoint* offset) { |
110 #if SK_SUPPORT_GPU | 110 #if SK_SUPPORT_GPU |
111 SkBitmap input; | 111 SkBitmap input; |
112 SkASSERT(fInputCount == 1); | 112 SkASSERT(fInputCount == 1); |
113 if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, &i
nput, offset)) { | 113 if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, &i
nput, offset)) { |
114 return false; | 114 return false; |
115 } | 115 } |
116 GrTexture* srcTexture = input.getTexture(); | 116 GrTexture* srcTexture = input.getTexture(); |
117 SkRect rect; | 117 SkIRect bounds; |
118 src.getBounds(&rect); | 118 src.getBounds(&bounds); |
| 119 if (!this->applyCropRect(&bounds)) { |
| 120 return false; |
| 121 } |
| 122 SkRect srcRect = SkRect::Make(bounds); |
| 123 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
119 GrContext* context = srcTexture->getContext(); | 124 GrContext* context = srcTexture->getContext(); |
120 | 125 |
121 GrTextureDesc desc; | 126 GrTextureDesc desc; |
122 desc.fFlags = kRenderTarget_GrTextureFlagBit, | 127 desc.fFlags = kRenderTarget_GrTextureFlagBit, |
123 desc.fWidth = input.width(); | 128 desc.fWidth = bounds.width(); |
124 desc.fHeight = input.height(); | 129 desc.fHeight = bounds.height(); |
125 desc.fConfig = kRGBA_8888_GrPixelConfig; | 130 desc.fConfig = kRGBA_8888_GrPixelConfig; |
126 | 131 |
127 GrAutoScratchTexture dst(context, desc); | 132 GrAutoScratchTexture dst(context, desc); |
128 GrContext::AutoMatrix am; | 133 GrContext::AutoMatrix am; |
129 am.setIdentity(context); | 134 am.setIdentity(context); |
130 GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); | 135 GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); |
131 GrContext::AutoClip acs(context, rect); | 136 GrContext::AutoClip acs(context, dstRect); |
132 GrEffectRef* effect; | 137 GrEffectRef* effect; |
133 this->asNewEffect(&effect, srcTexture); | 138 this->asNewEffect(&effect, srcTexture, SkIPoint::Make(bounds.left(), bounds.
top())); |
134 SkASSERT(effect); | 139 SkASSERT(effect); |
135 SkAutoUnref effectRef(effect); | 140 SkAutoUnref effectRef(effect); |
136 GrPaint paint; | 141 GrPaint paint; |
137 paint.addColorEffect(effect); | 142 paint.addColorEffect(effect); |
138 context->drawRect(paint, rect); | 143 context->drawRectToRect(paint, dstRect, srcRect); |
| 144 |
139 SkAutoTUnref<GrTexture> resultTex(dst.detach()); | 145 SkAutoTUnref<GrTexture> resultTex(dst.detach()); |
140 SkImageFilterUtils::WrapTexture(resultTex, input.width(), input.height(), re
sult); | 146 SkImageFilterUtils::WrapTexture(resultTex, bounds.width(), bounds.height(),
result); |
| 147 offset->fX += bounds.left(); |
| 148 offset->fY += bounds.top(); |
141 return true; | 149 return true; |
142 #else | 150 #else |
143 return false; | 151 return false; |
144 #endif | 152 #endif |
145 } | 153 } |
146 | 154 |
147 bool SkImageFilter::applyCropRect(SkIRect* rect) const { | 155 bool SkImageFilter::applyCropRect(SkIRect* rect) const { |
148 return rect->intersect(fCropRect); | 156 return rect->intersect(fCropRect); |
149 } | 157 } |
150 | 158 |
151 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 159 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
152 SkIRect* dst) { | 160 SkIRect* dst) { |
153 *dst = src; | 161 *dst = src; |
154 return true; | 162 return true; |
155 } | 163 } |
156 | 164 |
157 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const { | 165 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkIPoint& offse
t) const { |
158 return false; | 166 return false; |
159 } | 167 } |
160 | 168 |
161 bool SkImageFilter::asColorFilter(SkColorFilter**) const { | 169 bool SkImageFilter::asColorFilter(SkColorFilter**) const { |
162 return false; | 170 return false; |
163 } | 171 } |
OLD | NEW |