OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 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 "SkXfermodeImageFilter.h" | 8 #include "SkXfermodeImageFilter.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 this->getInput(1)->toString(str); | 117 this->getInput(1)->toString(str); |
118 str->appendf(")"); | 118 str->appendf(")"); |
119 } | 119 } |
120 str->append(")"); | 120 str->append(")"); |
121 } | 121 } |
122 #endif | 122 #endif |
123 | 123 |
124 #if SK_SUPPORT_GPU | 124 #if SK_SUPPORT_GPU |
125 | 125 |
126 bool SkXfermodeImageFilter::canFilterImageGPU() const { | 126 bool SkXfermodeImageFilter::canFilterImageGPU() const { |
127 return fMode && fMode->asFragmentProcessor(nullptr, nullptr, nullptr) && !cr
opRectIsSet(); | 127 return fMode && fMode->asFragmentProcessor(nullptr, nullptr) && !cropRectIsS
et(); |
128 } | 128 } |
129 | 129 |
130 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, | 130 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, |
131 const SkBitmap& src, | 131 const SkBitmap& src, |
132 const Context& ctx, | 132 const Context& ctx, |
133 SkBitmap* result, | 133 SkBitmap* result, |
134 SkIPoint* offset) const { | 134 SkIPoint* offset) const { |
135 SkBitmap background = src; | 135 SkBitmap background = src; |
136 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 136 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
137 if (this->getInput(0) && | 137 if (this->getInput(0) && |
(...skipping 25 matching lines...) Expand all Loading... |
163 desc.fConfig = kSkia8888_GrPixelConfig; | 163 desc.fConfig = kSkia8888_GrPixelConfig; |
164 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); | 164 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); |
165 if (!dst) { | 165 if (!dst) { |
166 return false; | 166 return false; |
167 } | 167 } |
168 | 168 |
169 GrPaint paint; | 169 GrPaint paint; |
170 SkMatrix bgMatrix; | 170 SkMatrix bgMatrix; |
171 bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); | 171 bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); |
172 SkAutoTUnref<const GrFragmentProcessor> bgFP( | 172 SkAutoTUnref<const GrFragmentProcessor> bgFP( |
173 GrSimpleTextureEffect::Create(paint.getProcessorDataManager(), backgroun
dTex, bgMatrix)); | 173 GrSimpleTextureEffect::Create(backgroundTex, bgMatrix)); |
174 if (!fMode || !fMode->asFragmentProcessor(&xferFP, paint.getProcessorDataMan
ager(), bgFP)) { | 174 if (!fMode || !fMode->asFragmentProcessor(&xferFP, bgFP)) { |
175 // canFilterImageGPU() should've taken care of this | 175 // canFilterImageGPU() should've taken care of this |
176 SkASSERT(false); | 176 SkASSERT(false); |
177 return false; | 177 return false; |
178 } | 178 } |
179 | 179 |
180 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); | 180 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); |
181 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), | 181 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), |
182 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); | 182 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); |
183 | 183 |
184 | 184 |
185 SkRect srcRect; | 185 SkRect srcRect; |
186 src.getBounds(&srcRect); | 186 src.getBounds(&srcRect); |
187 | 187 |
188 SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Cr
eate( | 188 SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Cr
eate( |
189 paint.getProcessorDataManager(), | |
190 foregroundTex, foregroundMatrix, | 189 foregroundTex, foregroundMatrix, |
191 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), | 190 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), |
192 GrTextureDomain::kDecal_Mode, | 191 GrTextureDomain::kDecal_Mode, |
193 GrTextureParams::kNone_FilterMode) | 192 GrTextureParams::kNone_FilterMode) |
194 ); | 193 ); |
195 | 194 |
196 paint.addColorFragmentProcessor(foregroundDomain.get()); | 195 paint.addColorFragmentProcessor(foregroundDomain.get()); |
197 if (xferFP) { | 196 if (xferFP) { |
198 paint.addColorFragmentProcessor(xferFP)->unref(); | 197 paint.addColorFragmentProcessor(xferFP)->unref(); |
199 } | 198 } |
200 | 199 |
201 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); | 200 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); |
202 if (!drawContext) { | 201 if (!drawContext) { |
203 return false; | 202 return false; |
204 } | 203 } |
205 | 204 |
206 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, | 205 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, |
207 SkMatrix::I(), srcRect); | 206 SkMatrix::I(), srcRect); |
208 | 207 |
209 offset->fX = backgroundOffset.fX; | 208 offset->fX = backgroundOffset.fX; |
210 offset->fY = backgroundOffset.fY; | 209 offset->fY = backgroundOffset.fY; |
211 WrapTexture(dst, src.width(), src.height(), result); | 210 WrapTexture(dst, src.width(), src.height(), result); |
212 return true; | 211 return true; |
213 } | 212 } |
214 | 213 |
215 #endif | 214 #endif |
216 | 215 |
OLD | NEW |