OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 SkScalar surfaceScale, | 353 SkScalar surfaceScale, |
354 sk_sp<SkImageFilter> input, | 354 sk_sp<SkImageFilter> input, |
355 const CropRect* cropRect) | 355 const CropRect* cropRect) |
356 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
{ | 356 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
{ |
357 } | 357 } |
358 | 358 |
359 #if SK_SUPPORT_GPU | 359 #if SK_SUPPORT_GPU |
360 sk_sp<SkSpecialImage> filterImageGPU(SkSpecialImage* source, | 360 sk_sp<SkSpecialImage> filterImageGPU(SkSpecialImage* source, |
361 SkSpecialImage* input, | 361 SkSpecialImage* input, |
362 const SkIRect& bounds, | 362 const SkIRect& bounds, |
363 const SkMatrix& matrix) const; | 363 const SkMatrix& matrix, |
| 364 const OutputProperties& outputPropertie
s) const; |
364 virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, | 365 virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, |
365 const SkMatrix&, | 366 const SkMatrix&, |
366 const SkIRect* srcB
ounds, | 367 const SkIRect* srcB
ounds, |
367 BoundaryMode bounda
ryMode) const = 0; | 368 BoundaryMode bounda
ryMode) const = 0; |
368 #endif | 369 #endif |
369 private: | 370 private: |
370 #if SK_SUPPORT_GPU | 371 #if SK_SUPPORT_GPU |
371 void drawRect(GrDrawContext* drawContext, | 372 void drawRect(GrDrawContext* drawContext, |
372 GrTexture* src, | 373 GrTexture* src, |
373 const SkMatrix& matrix, | 374 const SkMatrix& matrix, |
(...skipping 18 matching lines...) Expand all Loading... |
392 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 393 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
393 GrPaint paint; | 394 GrPaint paint; |
394 paint.setAllowSRGBInputs(drawContext->isGammaCorrect()); | 395 paint.setAllowSRGBInputs(drawContext->isGammaCorrect()); |
395 sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBo
unds, | 396 sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBo
unds, |
396 boundaryMode)); | 397 boundaryMode)); |
397 paint.addColorFragmentProcessor(std::move(fp)); | 398 paint.addColorFragmentProcessor(std::move(fp)); |
398 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 399 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
399 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); | 400 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); |
400 } | 401 } |
401 | 402 |
402 sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
ge* source, | 403 sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU( |
403 SkSpecialIma
ge* input, | 404 SkSpecialImage* source, |
404 const SkIRec
t& offsetBounds, | 405 SkSpecialImage* input, |
405 const SkMatr
ix& matrix) const { | 406 const SkIRect& offsetBounds, |
| 407 const SkMatrix& matrix, |
| 408 const OutputProperties& outpu
tProperties) const { |
406 SkASSERT(source->isTextureBacked()); | 409 SkASSERT(source->isTextureBacked()); |
407 | 410 |
408 GrContext* context = source->getContext(); | 411 GrContext* context = source->getContext(); |
409 | 412 |
410 sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); | 413 sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); |
411 SkASSERT(inputTexture); | 414 SkASSERT(inputTexture); |
412 | 415 |
413 sk_sp<GrDrawContext> drawContext( | 416 sk_sp<GrDrawContext> drawContext( |
414 context->makeDrawContext(SkBackingFit::kApprox,offsetBounds.width(), off
setBounds.height(), | 417 context->makeDrawContext(SkBackingFit::kApprox,offsetBounds.width(), off
setBounds.height(), |
415 GrRenderableConfigForColorSpace(source->getColo
rSpace()), | 418 GrRenderableConfigForColorSpace(outputPropertie
s.colorSpace()), |
416 sk_ref_sp(source->getColorSpace()))); | 419 sk_ref_sp(outputProperties.colorSpace()))); |
417 if (!drawContext) { | 420 if (!drawContext) { |
418 return nullptr; | 421 return nullptr; |
419 } | 422 } |
420 | 423 |
421 SkIRect dstIRect = SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height
()); | 424 SkIRect dstIRect = SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height
()); |
422 SkRect dstRect = SkRect::Make(dstIRect); | 425 SkRect dstRect = SkRect::Make(dstIRect); |
423 | 426 |
424 // setup new clip | 427 // setup new clip |
425 GrFixedClip clip(dstIRect); | 428 GrFixedClip clip(dstIRect); |
426 | 429 |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 | 1256 |
1254 offset->fX = bounds.left(); | 1257 offset->fX = bounds.left(); |
1255 offset->fY = bounds.top(); | 1258 offset->fY = bounds.top(); |
1256 bounds.offset(-inputOffset); | 1259 bounds.offset(-inputOffset); |
1257 | 1260 |
1258 #if SK_SUPPORT_GPU | 1261 #if SK_SUPPORT_GPU |
1259 if (source->isTextureBacked()) { | 1262 if (source->isTextureBacked()) { |
1260 SkMatrix matrix(ctx.ctm()); | 1263 SkMatrix matrix(ctx.ctm()); |
1261 matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->
fY)); | 1264 matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->
fY)); |
1262 | 1265 |
1263 return this->filterImageGPU(source, input.get(), bounds, matrix); | 1266 return this->filterImageGPU(source, input.get(), bounds, matrix, ctx.out
putProperties()); |
1264 } | 1267 } |
1265 #endif | 1268 #endif |
1266 | 1269 |
1267 if (bounds.width() < 2 || bounds.height() < 2) { | 1270 if (bounds.width() < 2 || bounds.height() < 2) { |
1268 return nullptr; | 1271 return nullptr; |
1269 } | 1272 } |
1270 | 1273 |
1271 SkBitmap inputBM; | 1274 SkBitmap inputBM; |
1272 | 1275 |
1273 if (!input->getROPixels(&inputBM)) { | 1276 if (!input->getROPixels(&inputBM)) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 | 1421 |
1419 offset->fX = bounds.left(); | 1422 offset->fX = bounds.left(); |
1420 offset->fY = bounds.top(); | 1423 offset->fY = bounds.top(); |
1421 bounds.offset(-inputOffset); | 1424 bounds.offset(-inputOffset); |
1422 | 1425 |
1423 #if SK_SUPPORT_GPU | 1426 #if SK_SUPPORT_GPU |
1424 if (source->isTextureBacked()) { | 1427 if (source->isTextureBacked()) { |
1425 SkMatrix matrix(ctx.ctm()); | 1428 SkMatrix matrix(ctx.ctm()); |
1426 matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->
fY)); | 1429 matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->
fY)); |
1427 | 1430 |
1428 return this->filterImageGPU(source, input.get(), bounds, matrix); | 1431 return this->filterImageGPU(source, input.get(), bounds, matrix, ctx.out
putProperties()); |
1429 } | 1432 } |
1430 #endif | 1433 #endif |
1431 | 1434 |
1432 if (bounds.width() < 2 || bounds.height() < 2) { | 1435 if (bounds.width() < 2 || bounds.height() < 2) { |
1433 return nullptr; | 1436 return nullptr; |
1434 } | 1437 } |
1435 | 1438 |
1436 SkBitmap inputBM; | 1439 SkBitmap inputBM; |
1437 | 1440 |
1438 if (!input->getROPixels(&inputBM)) { | 1441 if (!input->getROPixels(&inputBM)) { |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2171 | 2174 |
2172 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2175 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2173 } | 2176 } |
2174 | 2177 |
2175 #endif | 2178 #endif |
2176 | 2179 |
2177 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2180 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2178 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2181 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2179 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2182 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2180 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2183 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |