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 24 matching lines...) Expand all Loading... |
35 memcpy(dst, tableG, 256); | 35 memcpy(dst, tableG, 256); |
36 dst += 256; | 36 dst += 256; |
37 fFlags |= kG_Flag; | 37 fFlags |= kG_Flag; |
38 } | 38 } |
39 if (tableB) { | 39 if (tableB) { |
40 memcpy(dst, tableB, 256); | 40 memcpy(dst, tableB, 256); |
41 fFlags |= kB_Flag; | 41 fFlags |= kB_Flag; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 virtual ~SkTable_ColorFilter() { | 45 virtual ~SkTable_ColorFilter() { delete fBitmap; } |
46 SkDELETE(fBitmap); | |
47 } | |
48 | 46 |
49 bool asComponentTable(SkBitmap* table) const override; | 47 bool asComponentTable(SkBitmap* table) const override; |
50 SkColorFilter* newComposed(const SkColorFilter* inner) const override; | 48 SkColorFilter* newComposed(const SkColorFilter* inner) const override; |
51 | 49 |
52 #if SK_SUPPORT_GPU | 50 #if SK_SUPPORT_GPU |
53 bool asFragmentProcessors(GrContext*, GrProcessorDataManager*, | 51 bool asFragmentProcessors(GrContext*, GrProcessorDataManager*, |
54 SkTDArray<GrFragmentProcessor*>*) const override; | 52 SkTDArray<GrFragmentProcessor*>*) const override; |
55 #endif | 53 #endif |
56 | 54 |
57 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; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (flags & kB_Flag) { | 250 if (flags & kB_Flag) { |
253 b = ptr; | 251 b = ptr; |
254 ptr += 256; | 252 ptr += 256; |
255 } | 253 } |
256 return SkTableColorFilter::CreateARGB(a, r, g, b); | 254 return SkTableColorFilter::CreateARGB(a, r, g, b); |
257 } | 255 } |
258 | 256 |
259 bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const { | 257 bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const { |
260 if (table) { | 258 if (table) { |
261 if (NULL == fBitmap) { | 259 if (NULL == fBitmap) { |
262 SkBitmap* bmp = SkNEW(SkBitmap); | 260 SkBitmap* bmp = new SkBitmap; |
263 bmp->allocPixels(SkImageInfo::MakeA8(256, 4)); | 261 bmp->allocPixels(SkImageInfo::MakeA8(256, 4)); |
264 uint8_t* bitmapPixels = bmp->getAddr8(0, 0); | 262 uint8_t* bitmapPixels = bmp->getAddr8(0, 0); |
265 int offset = 0; | 263 int offset = 0; |
266 static const unsigned kFlags[] = { kA_Flag, kR_Flag, kG_Flag, kB_Fla
g }; | 264 static const unsigned kFlags[] = { kA_Flag, kR_Flag, kG_Flag, kB_Fla
g }; |
267 | 265 |
268 for (int x = 0; x < 4; ++x) { | 266 for (int x = 0; x < 4; ++x) { |
269 if (!(fFlags & kFlags[x])) { | 267 if (!(fFlags & kFlags[x])) { |
270 memcpy(bitmapPixels, gIdentityTable, sizeof(gIdentityTable))
; | 268 memcpy(bitmapPixels, gIdentityTable, sizeof(gIdentityTable))
; |
271 } else { | 269 } else { |
272 memcpy(bitmapPixels, fStorage + offset, 256); | 270 memcpy(bitmapPixels, fStorage + offset, 256); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 int row = atlas->lockRow(bitmap); | 473 int row = atlas->lockRow(bitmap); |
476 SkAutoTUnref<GrTexture> texture; | 474 SkAutoTUnref<GrTexture> texture; |
477 if (-1 == row) { | 475 if (-1 == row) { |
478 atlas = NULL; | 476 atlas = NULL; |
479 // Passing params=NULL because this effect does no tiling or filtering. | 477 // Passing params=NULL because this effect does no tiling or filtering. |
480 texture.reset(GrRefCachedBitmapTexture(context, bitmap, NULL)); | 478 texture.reset(GrRefCachedBitmapTexture(context, bitmap, NULL)); |
481 } else { | 479 } else { |
482 texture.reset(SkRef(atlas->getTexture())); | 480 texture.reset(SkRef(atlas->getTexture())); |
483 } | 481 } |
484 | 482 |
485 return SkNEW_ARGS(ColorTableEffect, (texture, atlas, row, flags)); | 483 return new ColorTableEffect(texture, atlas, row, flags); |
486 } | 484 } |
487 | 485 |
488 ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atla
s, int row, | 486 ColorTableEffect::ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atla
s, int row, |
489 unsigned flags) | 487 unsigned flags) |
490 : fTextureAccess(texture, "a") | 488 : fTextureAccess(texture, "a") |
491 , fFlags(flags) | 489 , fFlags(flags) |
492 , fAtlas(atlas) | 490 , fAtlas(atlas) |
493 , fRow(row) { | 491 , fRow(row) { |
494 this->initClassID<ColorTableEffect>(); | 492 this->initClassID<ColorTableEffect>(); |
495 this->addTextureAccess(&fTextureAccess); | 493 this->addTextureAccess(&fTextureAccess); |
496 } | 494 } |
497 | 495 |
498 ColorTableEffect::~ColorTableEffect() { | 496 ColorTableEffect::~ColorTableEffect() { |
499 if (fAtlas) { | 497 if (fAtlas) { |
500 fAtlas->unlockRow(fRow); | 498 fAtlas->unlockRow(fRow); |
501 } | 499 } |
502 } | 500 } |
503 | 501 |
504 void ColorTableEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 502 void ColorTableEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
505 GrProcessorKeyBuilder* b) const { | 503 GrProcessorKeyBuilder* b) const { |
506 GLColorTableEffect::GenKey(*this, caps, b); | 504 GLColorTableEffect::GenKey(*this, caps, b); |
507 } | 505 } |
508 | 506 |
509 GrGLFragmentProcessor* ColorTableEffect::onCreateGLInstance() const { | 507 GrGLFragmentProcessor* ColorTableEffect::onCreateGLInstance() const { |
510 return SkNEW_ARGS(GLColorTableEffect, (*this)); | 508 return new GLColorTableEffect(*this); |
511 } | 509 } |
512 | 510 |
513 bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const { | 511 bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const { |
514 // For non-atlased instances, the texture (compared by base class) is suffic
ient to | 512 // For non-atlased instances, the texture (compared by base class) is suffic
ient to |
515 // differentiate different tables. For atlased instances we ensure they are
using the | 513 // differentiate different tables. For atlased instances we ensure they are
using the |
516 // same row. | 514 // same row. |
517 const ColorTableEffect& that = other.cast<ColorTableEffect>(); | 515 const ColorTableEffect& that = other.cast<ColorTableEffect>(); |
518 SkASSERT(SkToBool(fAtlas) == SkToBool(that.fAtlas)); | 516 SkASSERT(SkToBool(fAtlas) == SkToBool(that.fAtlas)); |
519 // Ok to always do this comparison since both would be -1 if non-atlased. | 517 // Ok to always do this comparison since both would be -1 if non-atlased. |
520 return fRow == that.fRow; | 518 return fRow == that.fRow; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 #else | 598 #else |
601 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) | 599 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) |
602 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) | 600 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) |
603 #define SK_G32_INDEX (3 - (SK_G32_SHIFT >> 3)) | 601 #define SK_G32_INDEX (3 - (SK_G32_SHIFT >> 3)) |
604 #define SK_B32_INDEX (3 - (SK_B32_SHIFT >> 3)) | 602 #define SK_B32_INDEX (3 - (SK_B32_SHIFT >> 3)) |
605 #endif | 603 #endif |
606 | 604 |
607 /////////////////////////////////////////////////////////////////////////////// | 605 /////////////////////////////////////////////////////////////////////////////// |
608 | 606 |
609 SkColorFilter* SkTableColorFilter::Create(const uint8_t table[256]) { | 607 SkColorFilter* SkTableColorFilter::Create(const uint8_t table[256]) { |
610 return SkNEW_ARGS(SkTable_ColorFilter, (table, table, table, table)); | 608 return new SkTable_ColorFilter(table, table, table, table); |
611 } | 609 } |
612 | 610 |
613 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 611 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
614 const uint8_t tableR[256], | 612 const uint8_t tableR[256], |
615 const uint8_t tableG[256], | 613 const uint8_t tableG[256], |
616 const uint8_t tableB[256]) { | 614 const uint8_t tableB[256]) { |
617 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); | 615 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); |
618 } | 616 } |
619 | 617 |
620 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 618 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
621 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 619 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
622 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 620 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |