| 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 SkBitmap* result, SkIPoint* offset) const override; | 323 SkBitmap* result, SkIPoint* offset) const override; |
| 324 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 324 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, |
| 325 const SkMatrix&, | 325 const SkMatrix&, |
| 326 const SkIRect& bounds, | 326 const SkIRect& bounds, |
| 327 BoundaryMode boundaryMode)
const = 0; | 327 BoundaryMode boundaryMode)
const = 0; |
| 328 #endif | 328 #endif |
| 329 private: | 329 private: |
| 330 #if SK_SUPPORT_GPU | 330 #if SK_SUPPORT_GPU |
| 331 void drawRect(GrDrawContext* drawContext, | 331 void drawRect(GrDrawContext* drawContext, |
| 332 GrTexture* src, | 332 GrTexture* src, |
| 333 GrTexture* dst, | |
| 334 const SkMatrix& matrix, | 333 const SkMatrix& matrix, |
| 335 const GrClip& clip, | 334 const GrClip& clip, |
| 336 const SkRect& dstRect, | 335 const SkRect& dstRect, |
| 337 BoundaryMode boundaryMode, | 336 BoundaryMode boundaryMode, |
| 338 const SkIRect& bounds) const; | 337 const SkIRect& bounds) const; |
| 339 #endif | 338 #endif |
| 340 typedef SkLightingImageFilter INHERITED; | 339 typedef SkLightingImageFilter INHERITED; |
| 341 }; | 340 }; |
| 342 | 341 |
| 343 #if SK_SUPPORT_GPU | 342 #if SK_SUPPORT_GPU |
| 344 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, | 343 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, |
| 345 GrTexture* src, | 344 GrTexture* src, |
| 346 GrTexture* dst, | |
| 347 const SkMatrix& matrix, | 345 const SkMatrix& matrix, |
| 348 const GrClip& clip, | 346 const GrClip& clip, |
| 349 const SkRect& dstRect, | 347 const SkRect& dstRect, |
| 350 BoundaryMode boundaryMode, | 348 BoundaryMode boundaryMode, |
| 351 const SkIRect& bounds) const { | 349 const SkIRect& bounds) const { |
| 352 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 350 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
| 353 GrPaint paint; | 351 GrPaint paint; |
| 354 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo
undaryMode); | 352 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo
undaryMode); |
| 355 paint.addColorFragmentProcessor(fp)->unref(); | 353 paint.addColorFragmentProcessor(fp)->unref(); |
| 356 drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri
x::I(), | 354 drawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect, srcRec
t); |
| 357 dstRect, srcRect); | |
| 358 } | 355 } |
| 359 | 356 |
| 360 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, | 357 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, |
| 361 const SkBitmap& src, | 358 const SkBitmap& src, |
| 362 const Context& ctx, | 359 const Context& ctx, |
| 363 SkBitmap* result, | 360 SkBitmap* result, |
| 364 SkIPoint* offset) const { | 361 SkIPoint* offset) const { |
| 365 SkBitmap input = src; | 362 SkBitmap input = src; |
| 366 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 363 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 367 if (this->getInput(0) && | 364 if (this->getInput(0) && |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1); | 396 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1); |
| 400 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1); | 397 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1); |
| 401 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1); | 398 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1); |
| 402 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2); | 399 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2); |
| 403 SkRect interior = dstRect.makeInset(1, 1); | 400 SkRect interior = dstRect.makeInset(1, 1); |
| 404 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height()
- 2); | 401 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height()
- 2); |
| 405 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1); | 402 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1); |
| 406 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() -
2, 1); | 403 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() -
2, 1); |
| 407 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height()
- 1, 1, 1); | 404 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height()
- 1, 1, 1); |
| 408 | 405 |
| 409 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); | 406 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); |
| 410 if (!drawContext) { | 407 if (!drawContext) { |
| 411 return false; | 408 return false; |
| 412 } | 409 } |
| 413 | 410 |
| 414 this->drawRect(drawContext, srcTexture, dst, matrix, clip, topLeft, kTopLeft
_BoundaryMode, | 411 this->drawRect(drawContext, srcTexture, matrix, clip, topLeft, kTopLeft_Boun
daryMode, bounds); |
| 412 this->drawRect(drawContext, srcTexture, matrix, clip, top, kTop_BoundaryMode
, bounds); |
| 413 this->drawRect(drawContext, srcTexture, matrix, clip, topRight, kTopRight_Bo
undaryMode, |
| 415 bounds); | 414 bounds); |
| 416 this->drawRect(drawContext, srcTexture, dst, matrix, clip, top, kTop_Boundar
yMode, bounds); | 415 this->drawRect(drawContext, srcTexture, matrix, clip, left, kLeft_BoundaryMo
de, bounds); |
| 417 this->drawRect(drawContext, srcTexture, dst, matrix, clip, topRight, kTopRig
ht_BoundaryMode, | 416 this->drawRect(drawContext, srcTexture, matrix, clip, interior, kInterior_Bo
undaryMode, |
| 418 bounds); | 417 bounds); |
| 419 this->drawRect(drawContext, srcTexture, dst, matrix, clip, left, kLeft_Bound
aryMode, bounds); | 418 this->drawRect(drawContext, srcTexture, matrix, clip, right, kRight_Boundary
Mode, bounds); |
| 420 this->drawRect(drawContext, srcTexture, dst, matrix, clip, interior, kInteri
or_BoundaryMode, | 419 this->drawRect(drawContext, srcTexture, matrix, clip, bottomLeft, kBottomLef
t_BoundaryMode, |
| 421 bounds); | 420 bounds); |
| 422 this->drawRect(drawContext, srcTexture, dst, matrix, clip, right, kRight_Bou
ndaryMode, bounds); | 421 this->drawRect(drawContext, srcTexture, matrix, clip, bottom, kBottom_Bounda
ryMode, bounds); |
| 423 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottomLeft, kBott
omLeft_BoundaryMode, | 422 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight, |
| 424 bounds); | |
| 425 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottom, kBottom_B
oundaryMode, bounds); | |
| 426 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottomRight, | |
| 427 kBottomRight_BoundaryMode, bounds); | 423 kBottomRight_BoundaryMode, bounds); |
| 428 WrapTexture(dst, bounds.width(), bounds.height(), result); | 424 WrapTexture(dst, bounds.width(), bounds.height(), result); |
| 429 return true; | 425 return true; |
| 430 } | 426 } |
| 431 #endif | 427 #endif |
| 432 | 428 |
| 433 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { | 429 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { |
| 434 public: | 430 public: |
| 435 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, | 431 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, |
| 436 SkScalar kd, SkImageFilter*, | 432 SkScalar kd, SkImageFilter*, |
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2011 | 2007 |
| 2012 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2008 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 2013 } | 2009 } |
| 2014 | 2010 |
| 2015 #endif | 2011 #endif |
| 2016 | 2012 |
| 2017 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2013 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 2018 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2014 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 2019 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2015 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2016 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |