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 "SkTableColorFilter.h" | 8 #include "SkTableColorFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 kColorScaleFactor, | 435 kColorScaleFactor, |
436 kColorOffsetFactor, kColorOffsetFactor, | 436 kColorOffsetFactor, kColorOffsetFactor, |
437 kColorOffsetFactor, kColorOffsetFactor); | 437 kColorOffsetFactor, kColorOffsetFactor); |
438 } | 438 } |
439 | 439 |
440 SkString coord; | 440 SkString coord; |
441 | 441 |
442 fragBuilder->codeAppendf("\t\t%s.a = ", args.fOutputColor); | 442 fragBuilder->codeAppendf("\t\t%s.a = ", args.fOutputColor); |
443 coord.printf("vec2(coord.a, %s.a)", yoffsets); | 443 coord.printf("vec2(coord.a, %s.a)", yoffsets); |
444 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); | 444 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); |
445 fragBuilder->codeAppend(";\n"); | 445 fragBuilder->codeAppend(".a;\n"); |
446 | 446 |
447 fragBuilder->codeAppendf("\t\t%s.r = ", args.fOutputColor); | 447 fragBuilder->codeAppendf("\t\t%s.r = ", args.fOutputColor); |
448 coord.printf("vec2(coord.r, %s.r)", yoffsets); | 448 coord.printf("vec2(coord.r, %s.r)", yoffsets); |
449 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); | 449 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); |
450 fragBuilder->codeAppend(";\n"); | 450 fragBuilder->codeAppend(".a;\n"); |
451 | 451 |
452 fragBuilder->codeAppendf("\t\t%s.g = ", args.fOutputColor); | 452 fragBuilder->codeAppendf("\t\t%s.g = ", args.fOutputColor); |
453 coord.printf("vec2(coord.g, %s.g)", yoffsets); | 453 coord.printf("vec2(coord.g, %s.g)", yoffsets); |
454 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); | 454 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); |
455 fragBuilder->codeAppend(";\n"); | 455 fragBuilder->codeAppend(".a;\n"); |
456 | 456 |
457 fragBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor); | 457 fragBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor); |
458 coord.printf("vec2(coord.b, %s.b)", yoffsets); | 458 coord.printf("vec2(coord.b, %s.b)", yoffsets); |
459 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); | 459 fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str()); |
460 fragBuilder->codeAppend(";\n"); | 460 fragBuilder->codeAppend(".a;\n"); |
461 | 461 |
462 fragBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fO
utputColor); | 462 fragBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fO
utputColor); |
463 } | 463 } |
464 | 464 |
465 /////////////////////////////////////////////////////////////////////////////// | 465 /////////////////////////////////////////////////////////////////////////////// |
466 const GrFragmentProcessor* ColorTableEffect::Create(GrContext* context, SkBitmap
bitmap, | 466 const GrFragmentProcessor* ColorTableEffect::Create(GrContext* context, SkBitmap
bitmap, |
467 unsigned flags) { | 467 unsigned flags) { |
468 | 468 |
469 GrTextureStripAtlas::Desc desc; | 469 GrTextureStripAtlas::Desc desc; |
470 desc.fWidth = bitmap.width(); | 470 desc.fWidth = bitmap.width(); |
471 desc.fHeight = 128; | 471 desc.fHeight = 128; |
472 desc.fRowHeight = bitmap.height(); | 472 desc.fRowHeight = bitmap.height(); |
473 desc.fContext = context; | 473 desc.fContext = context; |
474 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); | 474 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); |
475 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc); | 475 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc); |
476 int row = atlas->lockRow(bitmap); | 476 int row = atlas->lockRow(bitmap); |
477 SkAutoTUnref<GrTexture> texture; | 477 SkAutoTUnref<GrTexture> texture; |
478 if (-1 == row) { | 478 if (-1 == row) { |
479 atlas = nullptr; | 479 atlas = nullptr; |
480 texture.reset(GrRefCachedBitmapTexture(context, bitmap, GrTextureParams:
:ClampNoFilter())); | 480 texture.reset(GrRefCachedBitmapTexture(context, bitmap, GrTextureParams:
:ClampNoFilter())); |
481 } else { | 481 } else { |
482 texture.reset(SkRef(atlas->getTexture())); | 482 texture.reset(SkRef(atlas->getTexture())); |
483 } | 483 } |
484 | 484 |
485 return new ColorTableEffect(texture, atlas, row, flags); | 485 return new ColorTableEffect(texture, atlas, row, flags); |
486 } | 486 } |
487 | 487 |
488 ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atla
s, int row, | 488 ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atla
s, int row, |
489 unsigned flags) | 489 unsigned flags) |
490 : fTextureAccess(texture, "a") | 490 : fTextureAccess(texture) |
491 , fFlags(flags) | 491 , fFlags(flags) |
492 , fAtlas(atlas) | 492 , fAtlas(atlas) |
493 , fRow(row) { | 493 , fRow(row) { |
494 this->initClassID<ColorTableEffect>(); | 494 this->initClassID<ColorTableEffect>(); |
495 this->addTextureAccess(&fTextureAccess); | 495 this->addTextureAccess(&fTextureAccess); |
496 } | 496 } |
497 | 497 |
498 ColorTableEffect::~ColorTableEffect() { | 498 ColorTableEffect::~ColorTableEffect() { |
499 if (fAtlas) { | 499 if (fAtlas) { |
500 fAtlas->unlockRow(fRow); | 500 fAtlas->unlockRow(fRow); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 598 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
599 const uint8_t tableR[256], | 599 const uint8_t tableR[256], |
600 const uint8_t tableG[256], | 600 const uint8_t tableG[256], |
601 const uint8_t tableB[256]) { | 601 const uint8_t tableB[256]) { |
602 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); | 602 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); |
603 } | 603 } |
604 | 604 |
605 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 605 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
606 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 606 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
607 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 607 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |