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