| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 this->getInput(1)->toString(str); | 116 this->getInput(1)->toString(str); |
| 117 str->appendf(")"); | 117 str->appendf(")"); |
| 118 } | 118 } |
| 119 str->append(")"); | 119 str->append(")"); |
| 120 } | 120 } |
| 121 #endif | 121 #endif |
| 122 | 122 |
| 123 #if SK_SUPPORT_GPU | 123 #if SK_SUPPORT_GPU |
| 124 | 124 |
| 125 bool SkXfermodeImageFilter::canFilterImageGPU() const { | 125 bool SkXfermodeImageFilter::canFilterImageGPU() const { |
| 126 return fMode && fMode->asFragmentProcessor(NULL, NULL) && !cropRectIsSet(); | 126 return fMode && fMode->asFragmentProcessor(NULL, NULL, NULL) && !cropRectIsS
et(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, | 129 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, |
| 130 const SkBitmap& src, | 130 const SkBitmap& src, |
| 131 const Context& ctx, | 131 const Context& ctx, |
| 132 SkBitmap* result, | 132 SkBitmap* result, |
| 133 SkIPoint* offset) const { | 133 SkIPoint* offset) const { |
| 134 SkBitmap background = src; | 134 SkBitmap background = src; |
| 135 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 135 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
| 136 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &backgro
und, | 136 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &backgro
und, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 159 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 159 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 160 desc.fWidth = src.width(); | 160 desc.fWidth = src.width(); |
| 161 desc.fHeight = src.height(); | 161 desc.fHeight = src.height(); |
| 162 desc.fConfig = kSkia8888_GrPixelConfig; | 162 desc.fConfig = kSkia8888_GrPixelConfig; |
| 163 SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture( | 163 SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture( |
| 164 desc, GrTextureProvider::kApprox_ScratchTexMatch)); | 164 desc, GrTextureProvider::kApprox_ScratchTexMatch)); |
| 165 if (!dst) { | 165 if (!dst) { |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, backgroundTex)) { | 169 GrPaint paint; |
| 170 if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, paint.getShaderDat
aManager(), |
| 171 backgroundTex)) { |
| 170 // canFilterImageGPU() should've taken care of this | 172 // canFilterImageGPU() should've taken care of this |
| 171 SkASSERT(false); | 173 SkASSERT(false); |
| 172 return false; | 174 return false; |
| 173 } | 175 } |
| 174 | 176 |
| 175 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); | 177 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); |
| 176 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), | 178 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), |
| 177 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); | 179 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); |
| 178 | 180 |
| 179 | 181 |
| 180 SkRect srcRect; | 182 SkRect srcRect; |
| 181 src.getBounds(&srcRect); | 183 src.getBounds(&srcRect); |
| 182 | 184 |
| 183 GrPaint paint; | |
| 184 SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Cr
eate( | 185 SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Cr
eate( |
| 185 foregroundTex, foregroundMatrix, | 186 foregroundTex, foregroundMatrix, |
| 186 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), | 187 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), |
| 187 GrTextureDomain::kDecal_Mode, | 188 GrTextureDomain::kDecal_Mode, |
| 188 GrTextureParams::kNone_FilterMode) | 189 GrTextureParams::kNone_FilterMode) |
| 189 ); | 190 ); |
| 190 | 191 |
| 191 paint.addColorProcessor(foregroundDomain.get()); | 192 paint.addColorProcessor(foregroundDomain.get()); |
| 192 paint.addColorProcessor(xferProcessor)->unref(); | 193 paint.addColorProcessor(xferProcessor)->unref(); |
| 193 | 194 |
| 194 GrDrawContext* drawContext = context->drawContext(); | 195 GrDrawContext* drawContext = context->drawContext(); |
| 195 if (!drawContext) { | 196 if (!drawContext) { |
| 196 return false; | 197 return false; |
| 197 } | 198 } |
| 198 | 199 |
| 199 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, | 200 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, |
| 200 SkMatrix::I(), srcRect); | 201 SkMatrix::I(), srcRect); |
| 201 | 202 |
| 202 offset->fX = backgroundOffset.fX; | 203 offset->fX = backgroundOffset.fX; |
| 203 offset->fY = backgroundOffset.fY; | 204 offset->fY = backgroundOffset.fY; |
| 204 WrapTexture(dst, src.width(), src.height(), result); | 205 WrapTexture(dst, src.width(), src.height(), result); |
| 205 return true; | 206 return true; |
| 206 } | 207 } |
| 207 | 208 |
| 208 #endif | 209 #endif |
| 209 | 210 |
| OLD | NEW |