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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 return false; | 140 return false; |
141 } | 141 } |
142 | 142 |
143 SkBitmap foreground = src; | 143 SkBitmap foreground = src; |
144 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); | 144 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); |
145 if (!this->filterInputGPU(1, proxy, src, ctx, &foreground, &foregroundOffset
)) { | 145 if (!this->filterInputGPU(1, proxy, src, ctx, &foreground, &foregroundOffset
)) { |
146 return false; | 146 return false; |
147 } | 147 } |
148 GrTexture* foregroundTex = foreground.getTexture(); | 148 GrTexture* foregroundTex = foreground.getTexture(); |
149 GrContext* context = foregroundTex->getContext(); | 149 GrContext* context = foregroundTex->getContext(); |
| 150 SkIRect bounds = background.bounds().makeOffset(backgroundOffset.x(), backgr
oundOffset.y()); |
| 151 bounds.join(foreground.bounds().makeOffset(foregroundOffset.x(), foregroundO
ffset.y())); |
| 152 if (bounds.isEmpty()) { |
| 153 return false; |
| 154 } |
150 | 155 |
151 const GrFragmentProcessor* xferFP = nullptr; | 156 const GrFragmentProcessor* xferFP = nullptr; |
152 | 157 |
153 GrSurfaceDesc desc; | 158 GrSurfaceDesc desc; |
154 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 159 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
155 desc.fWidth = src.width(); | 160 desc.fWidth = bounds.width(); |
156 desc.fHeight = src.height(); | 161 desc.fHeight = bounds.height(); |
157 desc.fConfig = kSkia8888_GrPixelConfig; | 162 desc.fConfig = kSkia8888_GrPixelConfig; |
158 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); | 163 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); |
159 if (!dst) { | 164 if (!dst) { |
160 return false; | 165 return false; |
161 } | 166 } |
162 | 167 |
163 GrPaint paint; | 168 GrPaint paint; |
164 SkMatrix bgMatrix; | 169 SkMatrix backgroundMatrix; |
165 bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); | 170 backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); |
166 SkAutoTUnref<const GrFragmentProcessor> bgFP( | 171 backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX), |
167 GrSimpleTextureEffect::Create(backgroundTex, bgMatrix)); | 172 SkIntToScalar(-backgroundOffset.fY)); |
| 173 SkAutoTUnref<const GrFragmentProcessor> bgFP(GrTextureDomainEffect::Create( |
| 174 backgroundTex, backgroundMatrix, |
| 175 GrTextureDomain::MakeTexelDomain(backgroundTex, background.bounds()), |
| 176 GrTextureDomain::kDecal_Mode, |
| 177 GrTextureParams::kNone_FilterMode) |
| 178 ); |
168 if (!fMode || !fMode->asFragmentProcessor(&xferFP, bgFP)) { | 179 if (!fMode || !fMode->asFragmentProcessor(&xferFP, bgFP)) { |
169 // canFilterImageGPU() should've taken care of this | 180 // canFilterImageGPU() should've taken care of this |
170 SkASSERT(false); | 181 SkASSERT(false); |
171 return false; | 182 return false; |
172 } | 183 } |
173 | 184 |
174 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); | 185 SkMatrix foregroundMatrix; |
175 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), | 186 foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height()); |
176 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); | 187 foregroundMatrix.preTranslate(SkIntToScalar(-foregroundOffset.fX), |
| 188 SkIntToScalar(-foregroundOffset.fY)); |
177 | 189 |
178 | 190 |
179 SkRect srcRect; | 191 SkAutoTUnref<const GrFragmentProcessor> foregroundFP(GrTextureDomainEffect::
Create( |
180 src.getBounds(&srcRect); | |
181 | |
182 SkAutoTUnref<const GrFragmentProcessor> foregroundDomain(GrTextureDomainEffe
ct::Create( | |
183 foregroundTex, foregroundMatrix, | 192 foregroundTex, foregroundMatrix, |
184 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), | 193 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), |
185 GrTextureDomain::kDecal_Mode, | 194 GrTextureDomain::kDecal_Mode, |
186 GrTextureParams::kNone_FilterMode) | 195 GrTextureParams::kNone_FilterMode) |
187 ); | 196 ); |
188 | 197 |
189 paint.addColorFragmentProcessor(foregroundDomain.get()); | 198 paint.addColorFragmentProcessor(foregroundFP.get()); |
190 if (xferFP) { | 199 if (xferFP) { |
191 paint.addColorFragmentProcessor(xferFP)->unref(); | 200 paint.addColorFragmentProcessor(xferFP)->unref(); |
192 } | 201 } |
193 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 202 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
194 | 203 |
195 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); | 204 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); |
196 if (!drawContext) { | 205 if (!drawContext) { |
197 return false; | 206 return false; |
198 } | 207 } |
199 | 208 |
200 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), srcRect); | 209 SkMatrix matrix; |
| 210 matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top
())); |
| 211 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(bounds
)); |
201 | 212 |
202 offset->fX = backgroundOffset.fX; | 213 offset->fX = bounds.left(); |
203 offset->fY = backgroundOffset.fY; | 214 offset->fY = bounds.top(); |
204 WrapTexture(dst, src.width(), src.height(), result); | 215 WrapTexture(dst, bounds.width(), bounds.height(), result); |
205 return true; | 216 return true; |
206 } | 217 } |
207 | 218 |
208 #endif | 219 #endif |
209 | 220 |
OLD | NEW |