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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 GrTexture* foregroundTex = foreground.getTexture(); | 132 GrTexture* foregroundTex = foreground.getTexture(); |
133 GrContext* context = foregroundTex->getContext(); | 133 GrContext* context = foregroundTex->getContext(); |
134 | 134 |
135 GrFragmentProcessor* xferProcessor = NULL; | 135 GrFragmentProcessor* xferProcessor = NULL; |
136 | 136 |
137 GrTextureDesc desc; | 137 GrTextureDesc desc; |
138 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 138 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
139 desc.fWidth = src.width(); | 139 desc.fWidth = src.width(); |
140 desc.fHeight = src.height(); | 140 desc.fHeight = src.height(); |
141 desc.fConfig = kSkia8888_GrPixelConfig; | 141 desc.fConfig = kSkia8888_GrPixelConfig; |
142 | 142 SkAutoTUnref<GrTexture> dst( |
143 GrAutoScratchTexture ast(context, desc); | 143 context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
144 if (NULL == ast.texture()) { | 144 if (!dst) { |
145 return false; | 145 return false; |
146 } | 146 } |
147 SkAutoTUnref<GrTexture> dst(ast.detach()); | |
148 | |
149 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); | 147 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); |
150 | 148 |
151 if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, backgroundTex)) { | 149 if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, backgroundTex)) { |
152 // canFilterImageGPU() should've taken care of this | 150 // canFilterImageGPU() should've taken care of this |
153 SkASSERT(false); | 151 SkASSERT(false); |
154 return false; | 152 return false; |
155 } | 153 } |
156 | 154 |
157 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); | 155 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); |
158 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), | 156 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), |
159 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); | 157 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); |
160 | 158 |
161 | 159 |
162 SkRect srcRect; | 160 SkRect srcRect; |
163 src.getBounds(&srcRect); | 161 src.getBounds(&srcRect); |
164 | 162 |
165 GrPaint paint; | 163 GrPaint paint; |
166 paint.addColorTextureProcessor(foregroundTex, foregroundMatrix); | 164 paint.addColorTextureProcessor(foregroundTex, foregroundMatrix); |
167 paint.addColorProcessor(xferProcessor)->unref(); | 165 paint.addColorProcessor(xferProcessor)->unref(); |
168 context->drawRect(paint, srcRect); | 166 context->drawRect(paint, srcRect); |
169 | 167 |
170 offset->fX = backgroundOffset.fX; | 168 offset->fX = backgroundOffset.fX; |
171 offset->fY = backgroundOffset.fY; | 169 offset->fY = backgroundOffset.fY; |
172 WrapTexture(dst, src.width(), src.height(), result); | 170 WrapTexture(dst, src.width(), src.height(), result); |
173 return true; | 171 return true; |
174 } | 172 } |
175 | 173 |
176 #endif | 174 #endif |
OLD | NEW |