| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkTableColorFilter.h" | 9 #include "SkTableColorFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 fFlags |= kB_Flag; | 41 fFlags |= kB_Flag; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 virtual ~SkTable_ColorFilter() { delete fBitmap; } | 45 virtual ~SkTable_ColorFilter() { delete fBitmap; } |
| 46 | 46 |
| 47 bool asComponentTable(SkBitmap* table) const override; | 47 bool asComponentTable(SkBitmap* table) const override; |
| 48 SkColorFilter* newComposed(const SkColorFilter* inner) const override; | 48 SkColorFilter* newComposed(const SkColorFilter* inner) const override; |
| 49 | 49 |
| 50 #if SK_SUPPORT_GPU | 50 #if SK_SUPPORT_GPU |
| 51 bool asFragmentProcessors(GrContext*, GrProcessorDataManager*, | 51 const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
| 52 SkTDArray<const GrFragmentProcessor*>*) const over
ride; | 52 GrProcessorDataManager*) cons
t override; |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const ove
rride; | 55 void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const ove
rride; |
| 56 | 56 |
| 57 SK_TO_STRING_OVERRIDE() | 57 SK_TO_STRING_OVERRIDE() |
| 58 | 58 |
| 59 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) | 59 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) |
| 60 | 60 |
| 61 enum { | 61 enum { |
| 62 kA_Flag = 1 << 0, | 62 kA_Flag = 1 << 0, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 333 |
| 334 #include "GrFragmentProcessor.h" | 334 #include "GrFragmentProcessor.h" |
| 335 #include "GrInvariantOutput.h" | 335 #include "GrInvariantOutput.h" |
| 336 #include "SkGr.h" | 336 #include "SkGr.h" |
| 337 #include "effects/GrTextureStripAtlas.h" | 337 #include "effects/GrTextureStripAtlas.h" |
| 338 #include "gl/GrGLFragmentProcessor.h" | 338 #include "gl/GrGLFragmentProcessor.h" |
| 339 #include "gl/builders/GrGLProgramBuilder.h" | 339 #include "gl/builders/GrGLProgramBuilder.h" |
| 340 | 340 |
| 341 class ColorTableEffect : public GrFragmentProcessor { | 341 class ColorTableEffect : public GrFragmentProcessor { |
| 342 public: | 342 public: |
| 343 static GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap, unsi
gned flags); | 343 static const GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap
, unsigned flags); |
| 344 | 344 |
| 345 virtual ~ColorTableEffect(); | 345 virtual ~ColorTableEffect(); |
| 346 | 346 |
| 347 const char* name() const override { return "ColorTable"; } | 347 const char* name() const override { return "ColorTable"; } |
| 348 | 348 |
| 349 const GrTextureStripAtlas* atlas() const { return fAtlas; } | 349 const GrTextureStripAtlas* atlas() const { return fAtlas; } |
| 350 int atlasRow() const { return fRow; } | 350 int atlasRow() const { return fRow; } |
| 351 | 351 |
| 352 private: | 352 private: |
| 353 GrGLFragmentProcessor* onCreateGLInstance() const override; | 353 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 454 |
| 455 fsBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor); | 455 fsBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor); |
| 456 coord.printf("vec2(coord.b, %s.b)", yoffsets); | 456 coord.printf("vec2(coord.b, %s.b)", yoffsets); |
| 457 fsBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); | 457 fsBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); |
| 458 fsBuilder->codeAppend(";\n"); | 458 fsBuilder->codeAppend(";\n"); |
| 459 | 459 |
| 460 fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOut
putColor); | 460 fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOut
putColor); |
| 461 } | 461 } |
| 462 | 462 |
| 463 /////////////////////////////////////////////////////////////////////////////// | 463 /////////////////////////////////////////////////////////////////////////////// |
| 464 GrFragmentProcessor* ColorTableEffect::Create(GrContext* context, SkBitmap bitma
p, unsigned flags) { | 464 const GrFragmentProcessor* ColorTableEffect::Create(GrContext* context, SkBitmap
bitmap, |
| 465 unsigned flags) { |
| 465 | 466 |
| 466 GrTextureStripAtlas::Desc desc; | 467 GrTextureStripAtlas::Desc desc; |
| 467 desc.fWidth = bitmap.width(); | 468 desc.fWidth = bitmap.width(); |
| 468 desc.fHeight = 128; | 469 desc.fHeight = 128; |
| 469 desc.fRowHeight = bitmap.height(); | 470 desc.fRowHeight = bitmap.height(); |
| 470 desc.fContext = context; | 471 desc.fContext = context; |
| 471 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); | 472 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); |
| 472 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc); | 473 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc); |
| 473 int row = atlas->lockRow(bitmap); | 474 int row = atlas->lockRow(bitmap); |
| 474 SkAutoTUnref<GrTexture> texture; | 475 SkAutoTUnref<GrTexture> texture; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 557 } |
| 557 } | 558 } |
| 558 } | 559 } |
| 559 SkAutoTUnref<SkColorFilter> filter(SkTableColorFilter::CreateARGB( | 560 SkAutoTUnref<SkColorFilter> filter(SkTableColorFilter::CreateARGB( |
| 560 (flags & (1 << 0)) ? luts[0] : nullptr, | 561 (flags & (1 << 0)) ? luts[0] : nullptr, |
| 561 (flags & (1 << 1)) ? luts[1] : nullptr, | 562 (flags & (1 << 1)) ? luts[1] : nullptr, |
| 562 (flags & (1 << 2)) ? luts[2] : nullptr, | 563 (flags & (1 << 2)) ? luts[2] : nullptr, |
| 563 (flags & (1 << 3)) ? luts[3] : nullptr | 564 (flags & (1 << 3)) ? luts[3] : nullptr |
| 564 )); | 565 )); |
| 565 | 566 |
| 566 SkTDArray<const GrFragmentProcessor*> array; | 567 const GrFragmentProcessor* fp = filter->asFragmentProcessor(d->fContext, d->
fProcDataManager); |
| 567 if (filter->asFragmentProcessors(d->fContext, d->fProcDataManager, &array))
{ | 568 SkASSERT(fp); |
| 568 SkASSERT(1 == array.count()); // TableColorFilter only returns 1 | 569 return fp; |
| 569 return array[0]; | |
| 570 } | |
| 571 return nullptr; | |
| 572 } | 570 } |
| 573 | 571 |
| 574 bool SkTable_ColorFilter::asFragmentProcessors(GrContext* context, | 572 const GrFragmentProcessor* SkTable_ColorFilter::asFragmentProcessor(GrContext* c
ontext, |
| 575 GrProcessorDataManager*, | 573 GrProcessorD
ataManager*) const { |
| 576 SkTDArray<const GrFragmentProcess
or*>* array) const { | |
| 577 SkBitmap bitmap; | 574 SkBitmap bitmap; |
| 578 this->asComponentTable(&bitmap); | 575 this->asComponentTable(&bitmap); |
| 579 | 576 |
| 580 GrFragmentProcessor* frag = ColorTableEffect::Create(context, bitmap, fFlags
); | 577 return ColorTableEffect::Create(context, bitmap, fFlags); |
| 581 if (frag) { | |
| 582 if (array) { | |
| 583 *array->append() = frag; | |
| 584 } else { | |
| 585 frag->unref(); | |
| 586 SkDEBUGCODE(frag = nullptr;) | |
| 587 } | |
| 588 return true; | |
| 589 } | |
| 590 return false; | |
| 591 } | 578 } |
| 592 | 579 |
| 593 #endif // SK_SUPPORT_GPU | 580 #endif // SK_SUPPORT_GPU |
| 594 | 581 |
| 595 /////////////////////////////////////////////////////////////////////////////// | 582 /////////////////////////////////////////////////////////////////////////////// |
| 596 | 583 |
| 597 #ifdef SK_CPU_BENDIAN | 584 #ifdef SK_CPU_BENDIAN |
| 598 #else | 585 #else |
| 599 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) | 586 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) |
| 600 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) | 587 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 611 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 598 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
| 612 const uint8_t tableR[256], | 599 const uint8_t tableR[256], |
| 613 const uint8_t tableG[256], | 600 const uint8_t tableG[256], |
| 614 const uint8_t tableB[256]) { | 601 const uint8_t tableB[256]) { |
| 615 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); | 602 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); |
| 616 } | 603 } |
| 617 | 604 |
| 618 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 605 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
| 619 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 606 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
| 620 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 607 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |