Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/effects/SkTableColorFilter.cpp

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkPerlinNoiseShader.cpp ('k') | src/effects/SkXfermodeImageFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkTableColorFilter.h" 8 #include "SkTableColorFilter.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 fFlags |= kB_Flag; 42 fFlags |= kB_Flag;
43 } 43 }
44 } 44 }
45 45
46 virtual ~SkTable_ColorFilter() { delete fBitmap; } 46 virtual ~SkTable_ColorFilter() { delete fBitmap; }
47 47
48 bool asComponentTable(SkBitmap* table) const override; 48 bool asComponentTable(SkBitmap* table) const override;
49 sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override ; 49 sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override ;
50 50
51 #if SK_SUPPORT_GPU 51 #if SK_SUPPORT_GPU
52 const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; 52 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 #include "GrInvariantOutput.h" 336 #include "GrInvariantOutput.h"
337 #include "SkGr.h" 337 #include "SkGr.h"
338 #include "effects/GrTextureStripAtlas.h" 338 #include "effects/GrTextureStripAtlas.h"
339 #include "glsl/GrGLSLFragmentProcessor.h" 339 #include "glsl/GrGLSLFragmentProcessor.h"
340 #include "glsl/GrGLSLFragmentShaderBuilder.h" 340 #include "glsl/GrGLSLFragmentShaderBuilder.h"
341 #include "glsl/GrGLSLProgramDataManager.h" 341 #include "glsl/GrGLSLProgramDataManager.h"
342 #include "glsl/GrGLSLUniformHandler.h" 342 #include "glsl/GrGLSLUniformHandler.h"
343 343
344 class ColorTableEffect : public GrFragmentProcessor { 344 class ColorTableEffect : public GrFragmentProcessor {
345 public: 345 public:
346 static const GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap , unsigned flags); 346 static sk_sp<GrFragmentProcessor> Make(GrContext* context, SkBitmap bitmap, unsigned flags);
347 347
348 virtual ~ColorTableEffect(); 348 virtual ~ColorTableEffect();
349 349
350 const char* name() const override { return "ColorTable"; } 350 const char* name() const override { return "ColorTable"; }
351 351
352 const GrTextureStripAtlas* atlas() const { return fAtlas; } 352 const GrTextureStripAtlas* atlas() const { return fAtlas; }
353 int atlasRow() const { return fRow; } 353 int atlasRow() const { return fRow; }
354 354
355 private: 355 private:
356 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 356 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 fragBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor); 453 fragBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor);
454 coord.printf("vec2(coord.b, %s.b)", yoffsets); 454 coord.printf("vec2(coord.b, %s.b)", yoffsets);
455 fragBuilder->appendTextureLookup(args.fTexSamplers[0], coord.c_str()); 455 fragBuilder->appendTextureLookup(args.fTexSamplers[0], coord.c_str());
456 fragBuilder->codeAppend(".a;\n"); 456 fragBuilder->codeAppend(".a;\n");
457 457
458 fragBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fO utputColor); 458 fragBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fO utputColor);
459 } 459 }
460 460
461 /////////////////////////////////////////////////////////////////////////////// 461 ///////////////////////////////////////////////////////////////////////////////
462 const GrFragmentProcessor* ColorTableEffect::Create(GrContext* context, SkBitmap bitmap, 462 sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, SkBitmap b itmap,
463 unsigned flags) { 463 unsigned flags) {
464 464
465 GrTextureStripAtlas::Desc desc; 465 GrTextureStripAtlas::Desc desc;
466 desc.fWidth = bitmap.width(); 466 desc.fWidth = bitmap.width();
467 desc.fHeight = 128; 467 desc.fHeight = 128;
468 desc.fRowHeight = bitmap.height(); 468 desc.fRowHeight = bitmap.height();
469 desc.fContext = context; 469 desc.fContext = context;
470 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *context->caps()); 470 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *context->caps());
471 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc); 471 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc);
472 int row = atlas->lockRow(bitmap); 472 int row = atlas->lockRow(bitmap);
473 SkAutoTUnref<GrTexture> texture; 473 SkAutoTUnref<GrTexture> texture;
474 if (-1 == row) { 474 if (-1 == row) {
475 atlas = nullptr; 475 atlas = nullptr;
476 texture.reset(GrRefCachedBitmapTexture(context, bitmap, GrTextureParams: :ClampNoFilter(), 476 texture.reset(GrRefCachedBitmapTexture(context, bitmap, GrTextureParams: :ClampNoFilter(),
477 SkSourceGammaTreatment::kRespect) ); 477 SkSourceGammaTreatment::kRespect) );
478 } else { 478 } else {
479 texture.reset(SkRef(atlas->getTexture())); 479 texture.reset(SkRef(atlas->getTexture()));
480 } 480 }
481 481
482 return new ColorTableEffect(texture, atlas, row, flags); 482 return sk_sp<GrFragmentProcessor>(new ColorTableEffect(texture, atlas, row, flags));
483 } 483 }
484 484
485 ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atla s, int row, 485 ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atla s, int row,
486 unsigned flags) 486 unsigned flags)
487 : fTextureAccess(texture) 487 : fTextureAccess(texture)
488 , fFlags(flags) 488 , fFlags(flags)
489 , fAtlas(atlas) 489 , fAtlas(atlas)
490 , fRow(row) { 490 , fRow(row) {
491 this->initClassID<ColorTableEffect>(); 491 this->initClassID<ColorTableEffect>();
492 this->addTextureAccess(&fTextureAccess); 492 this->addTextureAccess(&fTextureAccess);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if (fFlags & SkTable_ColorFilter::kA_Flag) { 533 if (fFlags & SkTable_ColorFilter::kA_Flag) {
534 invalidateFlags |= kA_GrColorComponentFlag; 534 invalidateFlags |= kA_GrColorComponentFlag;
535 } 535 }
536 inout->invalidateComponents(invalidateFlags, GrInvariantOutput::kWill_ReadIn put); 536 inout->invalidateComponents(invalidateFlags, GrInvariantOutput::kWill_ReadIn put);
537 } 537 }
538 538
539 /////////////////////////////////////////////////////////////////////////////// 539 ///////////////////////////////////////////////////////////////////////////////
540 540
541 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorTableEffect); 541 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorTableEffect);
542 542
543 const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d) { 543 sk_sp<GrFragmentProcessor> ColorTableEffect::TestCreate(GrProcessorTestData* d) {
544 int flags = 0; 544 int flags = 0;
545 uint8_t luts[256][4]; 545 uint8_t luts[256][4];
546 do { 546 do {
547 for (int i = 0; i < 4; ++i) { 547 for (int i = 0; i < 4; ++i) {
548 flags |= d->fRandom->nextBool() ? (1 << i): 0; 548 flags |= d->fRandom->nextBool() ? (1 << i): 0;
549 } 549 }
550 } while (!flags); 550 } while (!flags);
551 for (int i = 0; i < 4; ++i) { 551 for (int i = 0; i < 4; ++i) {
552 if (flags & (1 << i)) { 552 if (flags & (1 << i)) {
553 for (int j = 0; j < 256; ++j) { 553 for (int j = 0; j < 256; ++j) {
554 luts[j][i] = SkToU8(d->fRandom->nextBits(8)); 554 luts[j][i] = SkToU8(d->fRandom->nextBits(8));
555 } 555 }
556 } 556 }
557 } 557 }
558 auto filter(SkTableColorFilter::MakeARGB( 558 auto filter(SkTableColorFilter::MakeARGB(
559 (flags & (1 << 0)) ? luts[0] : nullptr, 559 (flags & (1 << 0)) ? luts[0] : nullptr,
560 (flags & (1 << 1)) ? luts[1] : nullptr, 560 (flags & (1 << 1)) ? luts[1] : nullptr,
561 (flags & (1 << 2)) ? luts[2] : nullptr, 561 (flags & (1 << 2)) ? luts[2] : nullptr,
562 (flags & (1 << 3)) ? luts[3] : nullptr 562 (flags & (1 << 3)) ? luts[3] : nullptr
563 )); 563 ));
564 564
565 const GrFragmentProcessor* fp = filter->asFragmentProcessor(d->fContext); 565 sk_sp<GrFragmentProcessor> fp = filter->asFragmentProcessor(d->fContext);
566 SkASSERT(fp); 566 SkASSERT(fp);
567 return fp; 567 return fp;
568 } 568 }
569 569
570 const GrFragmentProcessor* SkTable_ColorFilter::asFragmentProcessor(GrContext* c ontext) const { 570 sk_sp<GrFragmentProcessor> SkTable_ColorFilter::asFragmentProcessor(GrContext* c ontext) const {
571 SkBitmap bitmap; 571 SkBitmap bitmap;
572 this->asComponentTable(&bitmap); 572 this->asComponentTable(&bitmap);
573 573
574 return ColorTableEffect::Create(context, bitmap, fFlags); 574 return ColorTableEffect::Make(context, bitmap, fFlags);
575 } 575 }
576 576
577 #endif // SK_SUPPORT_GPU 577 #endif // SK_SUPPORT_GPU
578 578
579 /////////////////////////////////////////////////////////////////////////////// 579 ///////////////////////////////////////////////////////////////////////////////
580 580
581 #ifdef SK_CPU_BENDIAN 581 #ifdef SK_CPU_BENDIAN
582 #else 582 #else
583 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) 583 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3))
584 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) 584 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3))
(...skipping 10 matching lines...) Expand all
595 sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256], 595 sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256],
596 const uint8_t tableR[256], 596 const uint8_t tableR[256],
597 const uint8_t tableG[256], 597 const uint8_t tableG[256],
598 const uint8_t tableB[256]) { 598 const uint8_t tableB[256]) {
599 return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB); 599 return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB);
600 } 600 }
601 601
602 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) 602 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter)
603 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) 603 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter)
604 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 604 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkPerlinNoiseShader.cpp ('k') | src/effects/SkXfermodeImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698