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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 class SkLightingImageFilterInternal : public SkLightingImageFilter { | 348 class SkLightingImageFilterInternal : public SkLightingImageFilter { |
349 protected: | 349 protected: |
350 SkLightingImageFilterInternal(SkImageFilterLight* light, | 350 SkLightingImageFilterInternal(SkImageFilterLight* light, |
351 SkScalar surfaceScale, | 351 SkScalar surfaceScale, |
352 SkImageFilter* input, | 352 SkImageFilter* input, |
353 const CropRect* cropRect) | 353 const CropRect* cropRect) |
354 : INHERITED(light, surfaceScale, input, cropRect) {} | 354 : INHERITED(light, surfaceScale, input, cropRect) {} |
355 | 355 |
356 #if SK_SUPPORT_GPU | 356 #if SK_SUPPORT_GPU |
357 bool canFilterImageGPU() const override { return true; } | 357 bool canFilterImageGPU() const override { return true; } |
358 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, | 358 bool filterImageGPUDeprecated(Proxy*, const SkBitmap& src, const Context&, |
359 SkBitmap* result, SkIPoint* offset) const override; | 359 SkBitmap* result, SkIPoint* offset) const over
ride; |
360 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 360 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, |
361 const SkMatrix&, | 361 const SkMatrix&, |
362 const SkIRect* srcBounds, | 362 const SkIRect* srcBounds, |
363 BoundaryMode boundaryMode)
const = 0; | 363 BoundaryMode boundaryMode)
const = 0; |
364 #endif | 364 #endif |
365 private: | 365 private: |
366 #if SK_SUPPORT_GPU | 366 #if SK_SUPPORT_GPU |
367 void drawRect(GrDrawContext* drawContext, | 367 void drawRect(GrDrawContext* drawContext, |
368 GrTexture* src, | 368 GrTexture* src, |
369 const SkMatrix& matrix, | 369 const SkMatrix& matrix, |
(...skipping 16 matching lines...) Expand all Loading... |
386 const SkIRect* srcBounds, | 386 const SkIRect* srcBounds, |
387 const SkIRect& bounds) const { | 387 const SkIRect& bounds) const { |
388 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 388 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
389 GrPaint paint; | 389 GrPaint paint; |
390 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, srcBounds,
boundaryMode); | 390 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, srcBounds,
boundaryMode); |
391 paint.addColorFragmentProcessor(fp)->unref(); | 391 paint.addColorFragmentProcessor(fp)->unref(); |
392 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 392 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
393 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); | 393 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); |
394 } | 394 } |
395 | 395 |
396 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, | 396 bool SkLightingImageFilterInternal::filterImageGPUDeprecated(Proxy* proxy, |
397 const SkBitmap& src, | 397 const SkBitmap& src
, |
398 const Context& ctx, | 398 const Context& ctx, |
399 SkBitmap* result, | 399 SkBitmap* result, |
400 SkIPoint* offset) const { | 400 SkIPoint* offset) c
onst { |
401 SkBitmap input = src; | 401 SkBitmap input = src; |
402 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 402 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
403 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { | 403 if (!this->filterInputGPUDeprecated(0, proxy, src, ctx, &input, &srcOffset))
{ |
404 return false; | 404 return false; |
405 } | 405 } |
406 SkIRect srcBounds = input.bounds(); | 406 SkIRect srcBounds = input.bounds(); |
407 srcBounds.offset(srcOffset); | 407 srcBounds.offset(srcOffset); |
408 SkIRect bounds; | 408 SkIRect bounds; |
409 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | 409 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
410 return false; | 410 return false; |
411 } | 411 } |
412 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()), | 412 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()), |
413 SkIntToScalar(bounds.height())); | 413 SkIntToScalar(bounds.height())); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const CropRect*); | 480 const CropRect*); |
481 | 481 |
482 SK_TO_STRING_OVERRIDE() | 482 SK_TO_STRING_OVERRIDE() |
483 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 483 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
484 SkScalar kd() const { return fKD; } | 484 SkScalar kd() const { return fKD; } |
485 | 485 |
486 protected: | 486 protected: |
487 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal
e, | 487 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal
e, |
488 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 488 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
489 void flatten(SkWriteBuffer& buffer) const override; | 489 void flatten(SkWriteBuffer& buffer) const override; |
490 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 490 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, |
491 SkBitmap* result, SkIPoint* offset) const override; | 491 SkBitmap* result, SkIPoint* offset) const overr
ide; |
492 #if SK_SUPPORT_GPU | 492 #if SK_SUPPORT_GPU |
493 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, | 493 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, |
494 BoundaryMode) const override; | 494 BoundaryMode) const override; |
495 #endif | 495 #endif |
496 | 496 |
497 private: | 497 private: |
498 friend class SkLightingImageFilter; | 498 friend class SkLightingImageFilter; |
499 typedef SkLightingImageFilterInternal INHERITED; | 499 typedef SkLightingImageFilterInternal INHERITED; |
500 SkScalar fKD; | 500 SkScalar fKD; |
501 }; | 501 }; |
502 | 502 |
503 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { | 503 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { |
504 public: | 504 public: |
505 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, | 505 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, |
506 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); | 506 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); |
507 | 507 |
508 SK_TO_STRING_OVERRIDE() | 508 SK_TO_STRING_OVERRIDE() |
509 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 509 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
510 | 510 |
511 SkScalar ks() const { return fKS; } | 511 SkScalar ks() const { return fKS; } |
512 SkScalar shininess() const { return fShininess; } | 512 SkScalar shininess() const { return fShininess; } |
513 | 513 |
514 protected: | 514 protected: |
515 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca
le, SkScalar ks, | 515 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca
le, SkScalar ks, |
516 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); | 516 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); |
517 void flatten(SkWriteBuffer& buffer) const override; | 517 void flatten(SkWriteBuffer& buffer) const override; |
518 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 518 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, |
519 SkBitmap* result, SkIPoint* offset) const override; | 519 SkBitmap* result, SkIPoint* offset) const overr
ide; |
520 #if SK_SUPPORT_GPU | 520 #if SK_SUPPORT_GPU |
521 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, | 521 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, |
522 BoundaryMode) const override; | 522 BoundaryMode) const override; |
523 #endif | 523 #endif |
524 | 524 |
525 private: | 525 private: |
526 SkScalar fKS; | 526 SkScalar fKS; |
527 SkScalar fShininess; | 527 SkScalar fShininess; |
528 friend class SkLightingImageFilter; | 528 friend class SkLightingImageFilter; |
529 typedef SkLightingImageFilterInternal INHERITED; | 529 typedef SkLightingImageFilterInternal INHERITED; |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 SkScalar surfaceScale = buffer.readScalar(); | 1216 SkScalar surfaceScale = buffer.readScalar(); |
1217 SkScalar kd = buffer.readScalar(); | 1217 SkScalar kd = buffer.readScalar(); |
1218 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect(
)); | 1218 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect(
)); |
1219 } | 1219 } |
1220 | 1220 |
1221 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1221 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1222 this->INHERITED::flatten(buffer); | 1222 this->INHERITED::flatten(buffer); |
1223 buffer.writeScalar(fKD); | 1223 buffer.writeScalar(fKD); |
1224 } | 1224 } |
1225 | 1225 |
1226 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, | 1226 bool SkDiffuseLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, |
1227 const SkBitmap& source, | 1227 const SkBitmap& sourc
e, |
1228 const Context& ctx, | 1228 const Context& ctx, |
1229 SkBitmap* dst, | 1229 SkBitmap* dst, |
1230 SkIPoint* offset) const { | 1230 SkIPoint* offset) con
st { |
1231 SkBitmap src = source; | 1231 SkBitmap src = source; |
1232 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 1232 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
1233 if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) { | 1233 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) { |
1234 return false; | 1234 return false; |
1235 } | 1235 } |
1236 | 1236 |
1237 if (src.colorType() != kN32_SkColorType) { | 1237 if (src.colorType() != kN32_SkColorType) { |
1238 return false; | 1238 return false; |
1239 } | 1239 } |
1240 SkIRect srcBounds = src.bounds(); | 1240 SkIRect srcBounds = src.bounds(); |
1241 srcBounds.offset(srcOffset); | 1241 srcBounds.offset(srcOffset); |
1242 SkIRect bounds; | 1242 SkIRect bounds; |
1243 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | 1243 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 SkScalar shine = buffer.readScalar(); | 1360 SkScalar shine = buffer.readScalar(); |
1361 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr
opRect()); | 1361 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr
opRect()); |
1362 } | 1362 } |
1363 | 1363 |
1364 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1364 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1365 this->INHERITED::flatten(buffer); | 1365 this->INHERITED::flatten(buffer); |
1366 buffer.writeScalar(fKS); | 1366 buffer.writeScalar(fKS); |
1367 buffer.writeScalar(fShininess); | 1367 buffer.writeScalar(fShininess); |
1368 } | 1368 } |
1369 | 1369 |
1370 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, | 1370 bool SkSpecularLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, |
1371 const SkBitmap& source, | 1371 const SkBitmap& sour
ce, |
1372 const Context& ctx, | 1372 const Context& ctx, |
1373 SkBitmap* dst, | 1373 SkBitmap* dst, |
1374 SkIPoint* offset) const { | 1374 SkIPoint* offset) co
nst { |
1375 SkBitmap src = source; | 1375 SkBitmap src = source; |
1376 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 1376 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
1377 if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) { | 1377 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) { |
1378 return false; | 1378 return false; |
1379 } | 1379 } |
1380 | 1380 |
1381 if (src.colorType() != kN32_SkColorType) { | 1381 if (src.colorType() != kN32_SkColorType) { |
1382 return false; | 1382 return false; |
1383 } | 1383 } |
1384 | 1384 |
1385 SkIRect srcBounds = src.bounds(); | 1385 SkIRect srcBounds = src.bounds(); |
1386 srcBounds.offset(srcOffset); | 1386 srcBounds.offset(srcOffset); |
1387 SkIRect bounds; | 1387 SkIRect bounds; |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 | 2118 |
2119 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2119 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2120 } | 2120 } |
2121 | 2121 |
2122 #endif | 2122 #endif |
2123 | 2123 |
2124 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2124 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2125 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2125 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2126 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2126 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |