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, SkIPoint::Make(0, 0)); | 105 return this->asNewEffect(NULL, NULL, SkMatrix::I()); |
bsalomon
2013/08/27 20:00:02
hmm... is this fragile? should canFilterImageGPU t
Stephen White
2013/08/27 21:21:38
I say we cross that bridge when we get to it. None
| |
106 } | 106 } |
107 | 107 |
108 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMa trix& ctm, | 108 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMa trix& ctm, |
109 SkBitmap* result, SkIPoint* offset) { | 109 SkBitmap* result, 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, ct m, &input, offset)) { | 113 if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, ct m, &input, offset)) { |
114 return false; | 114 return false; |
115 } | 115 } |
116 GrTexture* srcTexture = input.getTexture(); | 116 GrTexture* srcTexture = input.getTexture(); |
117 SkIRect bounds; | 117 SkIRect bounds; |
118 src.getBounds(&bounds); | 118 src.getBounds(&bounds); |
119 if (!this->applyCropRect(&bounds)) { | 119 if (!this->applyCropRect(&bounds, ctm)) { |
120 return false; | 120 return false; |
121 } | 121 } |
122 SkRect srcRect = SkRect::Make(bounds); | 122 SkRect srcRect = SkRect::Make(bounds); |
123 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 123 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
124 GrContext* context = srcTexture->getContext(); | 124 GrContext* context = srcTexture->getContext(); |
125 | 125 |
126 GrTextureDesc desc; | 126 GrTextureDesc desc; |
127 desc.fFlags = kRenderTarget_GrTextureFlagBit, | 127 desc.fFlags = kRenderTarget_GrTextureFlagBit, |
128 desc.fWidth = bounds.width(); | 128 desc.fWidth = bounds.width(); |
129 desc.fHeight = bounds.height(); | 129 desc.fHeight = bounds.height(); |
130 desc.fConfig = kRGBA_8888_GrPixelConfig; | 130 desc.fConfig = kRGBA_8888_GrPixelConfig; |
131 | 131 |
132 GrAutoScratchTexture dst(context, desc); | 132 GrAutoScratchTexture dst(context, desc); |
133 GrContext::AutoMatrix am; | 133 GrContext::AutoMatrix am; |
134 am.setIdentity(context); | 134 am.setIdentity(context); |
135 GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); | 135 GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); |
136 GrContext::AutoClip acs(context, dstRect); | 136 GrContext::AutoClip acs(context, dstRect); |
137 GrEffectRef* effect; | 137 GrEffectRef* effect; |
138 this->asNewEffect(&effect, srcTexture, SkIPoint::Make(bounds.left(), bounds. top())); | 138 SkMatrix matrix(ctm); |
139 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to p())); | |
140 this->asNewEffect(&effect, srcTexture, matrix); | |
139 SkASSERT(effect); | 141 SkASSERT(effect); |
140 SkAutoUnref effectRef(effect); | 142 SkAutoUnref effectRef(effect); |
141 GrPaint paint; | 143 GrPaint paint; |
142 paint.addColorEffect(effect); | 144 paint.addColorEffect(effect); |
143 context->drawRectToRect(paint, dstRect, srcRect); | 145 context->drawRectToRect(paint, dstRect, srcRect); |
144 | 146 |
145 SkAutoTUnref<GrTexture> resultTex(dst.detach()); | 147 SkAutoTUnref<GrTexture> resultTex(dst.detach()); |
146 SkImageFilterUtils::WrapTexture(resultTex, bounds.width(), bounds.height(), result); | 148 SkImageFilterUtils::WrapTexture(resultTex, bounds.width(), bounds.height(), result); |
147 offset->fX += bounds.left(); | 149 offset->fX += bounds.left(); |
148 offset->fY += bounds.top(); | 150 offset->fY += bounds.top(); |
149 return true; | 151 return true; |
150 #else | 152 #else |
151 return false; | 153 return false; |
152 #endif | 154 #endif |
153 } | 155 } |
154 | 156 |
155 bool SkImageFilter::applyCropRect(SkIRect* rect) const { | 157 bool SkImageFilter::applyCropRect(SkIRect* rect, const SkMatrix& matrix) const { |
156 return rect->intersect(fCropRect); | 158 SkRect cropRect; |
159 matrix.mapRect(&cropRect, SkRect::Make(fCropRect)); | |
160 SkIRect cropRectI; | |
161 cropRect.roundOut(&cropRectI); | |
162 // If the original crop rect edges were unset, max out the new crop edges | |
163 if (fCropRect.fLeft == SK_MinS32) cropRectI.fLeft = SK_MinS32; | |
reed1
2013/08/27 19:54:44
nit: missing Skia's verbose { } for "ifs"
| |
164 if (fCropRect.fTop == SK_MinS32) cropRectI.fTop = SK_MinS32; | |
165 if (fCropRect.fRight == SK_MaxS32) cropRectI.fRight = SK_MaxS32; | |
166 if (fCropRect.fBottom == SK_MaxS32) cropRectI.fBottom = SK_MaxS32; | |
167 return rect->intersect(cropRectI); | |
157 } | 168 } |
158 | 169 |
159 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 170 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
160 SkIRect* dst) { | 171 SkIRect* dst) { |
161 *dst = src; | 172 *dst = src; |
162 return true; | 173 return true; |
163 } | 174 } |
164 | 175 |
165 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkIPoint& offse t) const { | 176 bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkMatrix&) cons t { |
166 return false; | 177 return false; |
167 } | 178 } |
168 | 179 |
169 bool SkImageFilter::asColorFilter(SkColorFilter**) const { | 180 bool SkImageFilter::asColorFilter(SkColorFilter**) const { |
170 return false; | 181 return false; |
171 } | 182 } |
OLD | NEW |