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 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 sk_sp<GrTexture> backgroundTex, foregroundTex; | 169 sk_sp<GrTexture> backgroundTex, foregroundTex; |
170 | 170 |
171 if (background) { | 171 if (background) { |
172 backgroundTex = background->asTextureRef(context); | 172 backgroundTex = background->asTextureRef(context); |
173 } | 173 } |
174 | 174 |
175 if (foreground) { | 175 if (foreground) { |
176 foregroundTex = foreground->asTextureRef(context); | 176 foregroundTex = foreground->asTextureRef(context); |
177 } | 177 } |
178 | 178 |
179 GrSurfaceDesc desc; | |
180 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
181 desc.fWidth = bounds.width(); | |
182 desc.fHeight = bounds.height(); | |
183 desc.fConfig = kSkia8888_GrPixelConfig; | |
184 sk_sp<GrTexture> dst(context->textureProvider()->createApproxTexture(desc)); | |
185 if (!dst) { | |
186 return nullptr; | |
187 } | |
188 | |
189 GrPaint paint; | 179 GrPaint paint; |
190 // SRGBTODO: AllowSRGBInputs? | 180 // SRGBTODO: AllowSRGBInputs? |
191 SkAutoTUnref<const GrFragmentProcessor> bgFP; | 181 SkAutoTUnref<const GrFragmentProcessor> bgFP; |
192 | 182 |
193 if (backgroundTex) { | 183 if (backgroundTex) { |
194 SkMatrix backgroundMatrix; | 184 SkMatrix backgroundMatrix; |
195 backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()
); | 185 backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()
); |
196 backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX), | 186 backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX), |
197 SkIntToScalar(-backgroundOffset.fY)); | 187 SkIntToScalar(-backgroundOffset.fY)); |
198 bgFP.reset(GrTextureDomainEffect::Create( | 188 bgFP.reset(GrTextureDomainEffect::Create( |
(...skipping 30 matching lines...) Expand all Loading... |
229 // It would be awesome to use SkXfermode::Create here but it knows b
etter | 219 // It would be awesome to use SkXfermode::Create here but it knows b
etter |
230 // than us and won't return a kSrcOver_Mode SkXfermode. That means w
e | 220 // than us and won't return a kSrcOver_Mode SkXfermode. That means w
e |
231 // have to get one the hard way. | 221 // have to get one the hard way. |
232 struct ProcCoeff rec; | 222 struct ProcCoeff rec; |
233 rec.fProc = SkXfermode::GetProc(SkXfermode::kSrcOver_Mode); | 223 rec.fProc = SkXfermode::GetProc(SkXfermode::kSrcOver_Mode); |
234 SkXfermode::ModeAsCoeff(SkXfermode::kSrcOver_Mode, &rec.fSC, &rec.fD
C); | 224 SkXfermode::ModeAsCoeff(SkXfermode::kSrcOver_Mode, &rec.fSC, &rec.fD
C); |
235 | 225 |
236 mode.reset(new SkProcCoeffXfermode(rec, SkXfermode::kSrcOver_Mode)); | 226 mode.reset(new SkProcCoeffXfermode(rec, SkXfermode::kSrcOver_Mode)); |
237 } | 227 } |
238 | 228 |
239 SkAutoTUnref<const GrFragmentProcessor> xferFP(mode->getFragmentProcesso
rForImageFilter(bgFP)); | 229 sk_sp<const GrFragmentProcessor> xferFP(mode->getFragmentProcessorForIma
geFilter(bgFP)); |
240 | 230 |
241 // A null 'xferFP' here means kSrc_Mode was used in which case we can ju
st proceed | 231 // A null 'xferFP' here means kSrc_Mode was used in which case we can ju
st proceed |
242 if (xferFP) { | 232 if (xferFP) { |
243 paint.addColorFragmentProcessor(xferFP); | 233 paint.addColorFragmentProcessor(xferFP.get()); |
244 } | 234 } |
245 } else { | 235 } else { |
246 paint.addColorFragmentProcessor(bgFP); | 236 paint.addColorFragmentProcessor(bgFP); |
247 } | 237 } |
248 | 238 |
249 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 239 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
250 | 240 |
251 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRende
rTarget()))); | 241 sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_B
ackingFit, |
| 242 bounds.width(), bou
nds.height(), |
| 243 kSkia8888_GrPixelCo
nfig)); |
252 if (!drawContext) { | 244 if (!drawContext) { |
253 return nullptr; | 245 return nullptr; |
254 } | 246 } |
255 | 247 |
256 SkMatrix matrix; | 248 SkMatrix matrix; |
257 matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top
())); | 249 matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top
())); |
258 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(bounds
)); | 250 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(bounds
)); |
259 | 251 |
260 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.he
ight()), | 252 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.he
ight()), |
261 kNeedNewImageUniqueID_SpecialImage, | 253 kNeedNewImageUniqueID_SpecialImage, |
262 std::move(dst)); | 254 drawContext->asTexture()); |
263 } | 255 } |
264 | 256 |
265 #endif | 257 #endif |
OLD | NEW |