Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2015 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "SkTableColorFilter.h"
      9 #include "SkPM4f.h"
     10 #include "SkArenaAlloc.h"
     11 #include "SkBitmap.h"
     12 #include "SkColorPriv.h"
     13 #include "SkRasterPipeline.h"
     14 #include "SkReadBuffer.h"
     15 #include "SkString.h"
     16 #include "SkUnPreMultiply.h"
     17 #include "SkWriteBuffer.h"
     18 
     19 static const uint8_t gIdentityTable[] = {
     20     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
     21     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
     22     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
     23     0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
     24     0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
     25     0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
     26     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
     27     0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
     28     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
     29     0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
     30     0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
     31     0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
     32     0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
     33     0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
     34     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
     35     0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
     36     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
     37     0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
     38     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
     39     0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
     40     0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
     41     0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
     42     0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
     43     0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
     44     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
     45     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
     46     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
     47     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
     48     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     49     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
     50     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
     51     0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
     52 };
     53 
     54 class SkTable_ColorFilter : public SkColorFilter {
     55 public:
     56     SkTable_ColorFilter(const uint8_t tableA[], const uint8_t tableR[],
     57                         const uint8_t tableG[], const uint8_t tableB[]) {
     58         fBitmap = nullptr;
     59         fFlags = 0;
     60 
     61         uint8_t* dst = fStorage;
     62         if (tableA) {
     63             memcpy(dst, tableA, 256);
     64             dst += 256;
     65             fFlags |= kA_Flag;
     66         }
     67         if (tableR) {
     68             memcpy(dst, tableR, 256);
     69             dst += 256;
     70             fFlags |= kR_Flag;
     71         }
     72         if (tableG) {
     73             memcpy(dst, tableG, 256);
     74             dst += 256;
     75             fFlags |= kG_Flag;
     76         }
     77         if (tableB) {
     78             memcpy(dst, tableB, 256);
     79             fFlags |= kB_Flag;
     80         }
     81     }
     82 
     83     ~SkTable_ColorFilter() override { delete fBitmap; }
     84 
     85     bool asComponentTable(SkBitmap* table) const override;
     86     sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override;
     87 
     88 #if SK_SUPPORT_GPU
     89     sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, SkColorSpace*) const override;
     90 #endif
     91 
     92     SK_TO_STRING_OVERRIDE()
     93 
     94     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter)
     95 
     96     enum {
     97         kA_Flag = 1 << 0,
     98         kR_Flag = 1 << 1,
     99         kG_Flag = 1 << 2,
    100         kB_Flag = 1 << 3,
    101     };
    102 
    103     void onAppendStages(SkRasterPipeline* p, SkColorSpace*, SkArenaAlloc* alloc,
    104                         bool shaderIsOpaque) const override {
    105         const uint8_t *r = gIdentityTable,
    106                       *g = gIdentityTable,
    107                       *b = gIdentityTable,
    108                       *a = gIdentityTable;
    109         const uint8_t* ptr = fStorage;
    110         if (fFlags & kA_Flag) { a = ptr; ptr += 256; }
    111         if (fFlags & kR_Flag) { r = ptr; ptr += 256; }
    112         if (fFlags & kG_Flag) { g = ptr; ptr += 256; }
    113         if (fFlags & kB_Flag) { b = ptr;             }
    114 
    115         if (!shaderIsOpaque) {
    116             p->append(SkRasterPipeline::unpremul);
    117         }
    118 
    119         struct Tables { const uint8_t *r, *g, *b, *a; };
    120         p->append(SkRasterPipeline::byte_tables, alloc->make<Tables>(Tables{r,g,b,a}));
    121 
    122         bool definitelyOpaque = shaderIsOpaque && a[0xff] == 0xff;
    123         if (!definitelyOpaque) {
    124             p->append(SkRasterPipeline::premul);
    125         }
    126     }
    127 
    128 protected:
    129     void flatten(SkWriteBuffer&) const override;
    130 
    131 private:
    132     mutable const SkBitmap* fBitmap; // lazily allocated
    133 
    134     uint8_t fStorage[256 * 4];
    135     unsigned fFlags;
    136 
    137     friend class SkTableColorFilter;
    138 
    139     typedef SkColorFilter INHERITED;
    140 };
    141 
    142 #ifndef SK_IGNORE_TO_STRING
    143 void SkTable_ColorFilter::toString(SkString* str) const {
    144     const uint8_t* table = fStorage;
    145     const uint8_t* tableA = gIdentityTable;
    146     const uint8_t* tableR = gIdentityTable;
    147     const uint8_t* tableG = gIdentityTable;
    148     const uint8_t* tableB = gIdentityTable;
    149     if (fFlags & kA_Flag) {
    150         tableA = table; table += 256;
    151     }
    152     if (fFlags & kR_Flag) {
    153         tableR = table; table += 256;
    154     }
    155     if (fFlags & kG_Flag) {
    156         tableG = table; table += 256;
    157     }
    158     if (fFlags & kB_Flag) {
    159         tableB = table;
    160     }
    161 
    162     str->append("SkTable_ColorFilter (");
    163 
    164     for (int i = 0; i < 256; ++i) {
    165         str->appendf("%d: %d,%d,%d,%d\n",
    166                      i, tableR[i], tableG[i], tableB[i], tableA[i]);
    167     }
    168 
    169     str->append(")");
    170 }
    171 #endif
    172 
    173 static const uint8_t gCountNibBits[] = {
    174     0, 1, 1, 2,
    175     1, 2, 2, 3,
    176     1, 2, 2, 3,
    177     2, 3, 3, 4
    178 };
    179 
    180 #include "SkPackBits.h"
    181 
    182 void SkTable_ColorFilter::flatten(SkWriteBuffer& buffer) const {
    183     uint8_t storage[5*256];
    184     int count = gCountNibBits[fFlags & 0xF];
    185     size_t size = SkPackBits::Pack8(fStorage, count * 256, storage,
    186                                     sizeof(storage));
    187 
    188     buffer.write32(fFlags);
    189     buffer.writeByteArray(storage, size);
    190 }
    191 
    192 sk_sp<SkFlattenable> SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) {
    193     const int flags = buffer.read32();
    194     const size_t count = gCountNibBits[flags & 0xF];
    195     SkASSERT(count <= 4);
    196 
    197     uint8_t packedStorage[5*256];
    198     size_t packedSize = buffer.getArrayCount();
    199     if (!buffer.validate(packedSize <= sizeof(packedStorage))) {
    200         return nullptr;
    201     }
    202     if (!buffer.readByteArray(packedStorage, packedSize)) {
    203         return nullptr;
    204     }
    205 
    206     uint8_t unpackedStorage[4*256];
    207     size_t unpackedSize = SkPackBits::Unpack8(packedStorage, packedSize,
    208                               unpackedStorage, sizeof(unpackedStorage));
    209     // now check that we got the size we expected
    210     if (!buffer.validate(unpackedSize == count*256)) {
    211         return nullptr;
    212     }
    213 
    214     const uint8_t* a = nullptr;
    215     const uint8_t* r = nullptr;
    216     const uint8_t* g = nullptr;
    217     const uint8_t* b = nullptr;
    218     const uint8_t* ptr = unpackedStorage;
    219 
    220     if (flags & kA_Flag) {
    221         a = ptr;
    222         ptr += 256;
    223     }
    224     if (flags & kR_Flag) {
    225         r = ptr;
    226         ptr += 256;
    227     }
    228     if (flags & kG_Flag) {
    229         g = ptr;
    230         ptr += 256;
    231     }
    232     if (flags & kB_Flag) {
    233         b = ptr;
    234         ptr += 256;
    235     }
    236     return SkTableColorFilter::MakeARGB(a, r, g, b);
    237 }
    238 
    239 bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const {
    240     if (table) {
    241         if (nullptr == fBitmap) {
    242             SkBitmap* bmp = new SkBitmap;
    243             bmp->allocPixels(SkImageInfo::MakeA8(256, 4));
    244             uint8_t* bitmapPixels = bmp->getAddr8(0, 0);
    245             int offset = 0;
    246             static const unsigned kFlags[] = { kA_Flag, kR_Flag, kG_Flag, kB_Flag };
    247 
    248             for (int x = 0; x < 4; ++x) {
    249                 if (!(fFlags & kFlags[x])) {
    250                     memcpy(bitmapPixels, gIdentityTable, sizeof(gIdentityTable));
    251                 } else {
    252                     memcpy(bitmapPixels, fStorage + offset, 256);
    253                     offset += 256;
    254                 }
    255                 bitmapPixels += 256;
    256             }
    257             fBitmap = bmp;
    258         }
    259         *table = *fBitmap;
    260     }
    261     return true;
    262 }
    263 
    264 // Combines the two lookup tables so that making a lookup using res[] has
    265 // the same effect as making a lookup through inner[] then outer[].
    266 static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uint8_t inner[256]) {
    267     for (int i = 0; i < 256; i++) {
    268         res[i] = outer[inner[i]];
    269     }
    270 }
    271 
    272 sk_sp<SkColorFilter> SkTable_ColorFilter::makeComposed(sk_sp<SkColorFilter> innerFilter) const {
    273     SkBitmap innerBM;
    274     if (!innerFilter->asComponentTable(&innerBM)) {
    275         return nullptr;
    276     }
    277 
    278     if (nullptr == innerBM.getPixels()) {
    279         return nullptr;
    280     }
    281 
    282     const uint8_t* table = fStorage;
    283     const uint8_t* tableA = gIdentityTable;
    284     const uint8_t* tableR = gIdentityTable;
    285     const uint8_t* tableG = gIdentityTable;
    286     const uint8_t* tableB = gIdentityTable;
    287     if (fFlags & kA_Flag) {
    288         tableA = table; table += 256;
    289     }
    290     if (fFlags & kR_Flag) {
    291         tableR = table; table += 256;
    292     }
    293     if (fFlags & kG_Flag) {
    294         tableG = table; table += 256;
    295     }
    296     if (fFlags & kB_Flag) {
    297         tableB = table;
    298     }
    299 
    300     uint8_t concatA[256];
    301     uint8_t concatR[256];
    302     uint8_t concatG[256];
    303     uint8_t concatB[256];
    304 
    305     combine_tables(concatA, tableA, innerBM.getAddr8(0, 0));
    306     combine_tables(concatR, tableR, innerBM.getAddr8(0, 1));
    307     combine_tables(concatG, tableG, innerBM.getAddr8(0, 2));
    308     combine_tables(concatB, tableB, innerBM.getAddr8(0, 3));
    309 
    310     return SkTableColorFilter::MakeARGB(concatA, concatR, concatG, concatB);
    311 }
    312 
    313 #if SK_SUPPORT_GPU
    314 
    315 #include "GrContext.h"
    316 #include "GrFragmentProcessor.h"
    317 #include "GrTextureStripAtlas.h"
    318 #include "SkGr.h"
    319 #include "glsl/GrGLSLFragmentProcessor.h"
    320 #include "glsl/GrGLSLFragmentShaderBuilder.h"
    321 #include "glsl/GrGLSLProgramDataManager.h"
    322 #include "glsl/GrGLSLUniformHandler.h"
    323 
    324 class ColorTableEffect : public GrFragmentProcessor {
    325 public:
    326     static sk_sp<GrFragmentProcessor> Make(GrContext* context,
    327                                            const SkBitmap& bitmap,
    328                                            unsigned flags);
    329 
    330     ~ColorTableEffect() override;
    331 
    332     const char* name() const override { return "ColorTable"; }
    333 
    334     const GrTextureStripAtlas* atlas() const { return fAtlas; }
    335     int atlasRow() const { return fRow; }
    336 
    337 private:
    338     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
    339 
    340     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
    341 
    342     bool onIsEqual(const GrFragmentProcessor&) const override;
    343 
    344     ColorTableEffect(sk_sp<GrTextureProxy> proxy,
    345                      GrTextureStripAtlas* atlas, int row, unsigned flags);
    346 
    347     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
    348 
    349     TextureSampler fTextureSampler;
    350     GrTextureStripAtlas* fAtlas;
    351     int fRow;
    352 
    353     typedef GrFragmentProcessor INHERITED;
    354 };
    355 
    356 class GLColorTableEffect : public GrGLSLFragmentProcessor {
    357 public:
    358     void emitCode(EmitArgs&) override;
    359 
    360     static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*) {}
    361 
    362 protected:
    363     void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
    364 
    365 private:
    366     UniformHandle fRGBAYValuesUni;
    367     typedef GrGLSLFragmentProcessor INHERITED;
    368 };
    369 
    370 void GLColorTableEffect::onSetData(const GrGLSLProgramDataManager& pdm,
    371                                    const GrFragmentProcessor& proc) {
    372     // The textures are organized in a strip where the rows are ordered a, r, g, b.
    373     float rgbaYValues[4];
    374     const ColorTableEffect& cte = proc.cast<ColorTableEffect>();
    375     if (cte.atlas()) {
    376         SkScalar yDelta = cte.atlas()->getNormalizedTexelHeight();
    377         rgbaYValues[3] = cte.atlas()->getYOffset(cte.atlasRow()) + SK_ScalarHalf * yDelta;
    378         rgbaYValues[0] = rgbaYValues[3] + yDelta;
    379         rgbaYValues[1] = rgbaYValues[0] + yDelta;
    380         rgbaYValues[2] = rgbaYValues[1] + yDelta;
    381     } else {
    382         rgbaYValues[3] = 0.125;
    383         rgbaYValues[0] = 0.375;
    384         rgbaYValues[1] = 0.625;
    385         rgbaYValues[2] = 0.875;
    386     }
    387     pdm.set4fv(fRGBAYValuesUni, 1, rgbaYValues);
    388 }
    389 
    390 void GLColorTableEffect::emitCode(EmitArgs& args) {
    391     const char* yoffsets;
    392     fRGBAYValuesUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
    393                                                        kVec4f_GrSLType, kDefault_GrSLPrecision,
    394                                                        "yoffsets", &yoffsets);
    395     static const float kColorScaleFactor = 255.0f / 256.0f;
    396     static const float kColorOffsetFactor = 1.0f / 512.0f;
    397     GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
    398     if (nullptr == args.fInputColor) {
    399         // the input color is solid white (all ones).
    400         static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor;
    401         fragBuilder->codeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n",
    402                                  kMaxValue, kMaxValue, kMaxValue, kMaxValue);
    403 
    404     } else {
    405         fragBuilder->codeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", args.fInputColor);
    406         fragBuilder->codeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha);\n",
    407                                  args.fInputColor);
    408         fragBuilder->codeAppendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n",
    409                                  kColorScaleFactor,
    410                                  kColorOffsetFactor, kColorOffsetFactor,
    411                                  kColorOffsetFactor, kColorOffsetFactor);
    412     }
    413 
    414     SkString coord;
    415 
    416     fragBuilder->codeAppendf("\t\t%s.a = ", args.fOutputColor);
    417     coord.printf("vec2(coord.a, %s.a)", yoffsets);
    418     fragBuilder->appendTextureLookup(args.fTexSamplers[0], coord.c_str());
    419     fragBuilder->codeAppend(".a;\n");
    420 
    421     fragBuilder->codeAppendf("\t\t%s.r = ", args.fOutputColor);
    422     coord.printf("vec2(coord.r, %s.r)", yoffsets);
    423     fragBuilder->appendTextureLookup(args.fTexSamplers[0], coord.c_str());
    424     fragBuilder->codeAppend(".a;\n");
    425 
    426     fragBuilder->codeAppendf("\t\t%s.g = ", args.fOutputColor);
    427     coord.printf("vec2(coord.g, %s.g)", yoffsets);
    428     fragBuilder->appendTextureLookup(args.fTexSamplers[0], coord.c_str());
    429     fragBuilder->codeAppend(".a;\n");
    430 
    431     fragBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor);
    432     coord.printf("vec2(coord.b, %s.b)", yoffsets);
    433     fragBuilder->appendTextureLookup(args.fTexSamplers[0], coord.c_str());
    434     fragBuilder->codeAppend(".a;\n");
    435 
    436     fragBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOutputColor);
    437 }
    438 
    439 ///////////////////////////////////////////////////////////////////////////////
    440 sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, const SkBitmap& bitmap,
    441                                                   unsigned flags) {
    442 
    443     GrTextureStripAtlas::Desc desc;
    444     desc.fWidth  = bitmap.width();
    445     desc.fHeight = 128;
    446     desc.fRowHeight = bitmap.height();
    447 
    448     // TODO: this seems a bit heavy handed (passing a GrContext as part of the desc)
    449     desc.fContext = context;
    450     desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *context->caps());
    451     GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc);
    452     int row = atlas->lockRow(bitmap);
    453     sk_sp<GrTextureProxy> proxy;
    454     if (-1 == row) {
    455         atlas = nullptr;
    456 
    457         proxy = GrMakeCachedBitmapProxy(context->resourceProvider(), bitmap);
    458     } else {
    459         proxy = atlas->asTextureProxyRef();
    460     }
    461 
    462     if (!proxy) {
    463         return nullptr;
    464     }
    465 
    466     return sk_sp<GrFragmentProcessor>(new ColorTableEffect(std::move(proxy), atlas, row, flags));
    467 }
    468 
    469 ColorTableEffect::ColorTableEffect(sk_sp<GrTextureProxy> proxy,
    470                                    GrTextureStripAtlas* atlas, int row, unsigned flags)
    471         : INHERITED(kNone_OptimizationFlags)  // Not bothering with table-specific optimizations.
    472         , fTextureSampler(std::move(proxy))
    473         , fAtlas(atlas)
    474         , fRow(row) {
    475     this->initClassID<ColorTableEffect>();
    476     this->addTextureSampler(&fTextureSampler);
    477 }
    478 
    479 ColorTableEffect::~ColorTableEffect() {
    480     if (fAtlas) {
    481         fAtlas->unlockRow(fRow);
    482     }
    483 }
    484 
    485 void ColorTableEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
    486                                              GrProcessorKeyBuilder* b) const {
    487     GLColorTableEffect::GenKey(*this, caps, b);
    488 }
    489 
    490 GrGLSLFragmentProcessor* ColorTableEffect::onCreateGLSLInstance() const {
    491     return new GLColorTableEffect;
    492 }
    493 
    494 bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const {
    495     // For non-atlased instances, the texture (compared by base class) is sufficient to
    496     // differentiate different tables. For atlased instances we ensure they are using the
    497     // same row.
    498     const ColorTableEffect& that = other.cast<ColorTableEffect>();
    499     SkASSERT(SkToBool(fAtlas) == SkToBool(that.fAtlas));
    500     // Ok to always do this comparison since both would be -1 if non-atlased.
    501     return fRow == that.fRow;
    502 }
    503 
    504 ///////////////////////////////////////////////////////////////////////////////
    505 
    506 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorTableEffect);
    507 
    508 #if GR_TEST_UTILS
    509 sk_sp<GrFragmentProcessor> ColorTableEffect::TestCreate(GrProcessorTestData* d) {
    510     int flags = 0;
    511     uint8_t luts[256][4];
    512     do {
    513         for (int i = 0; i < 4; ++i) {
    514             flags |= d->fRandom->nextBool() ? (1  << i): 0;
    515         }
    516     } while (!flags);
    517     for (int i = 0; i < 4; ++i) {
    518         if (flags & (1 << i)) {
    519             for (int j = 0; j < 256; ++j) {
    520                 luts[j][i] = SkToU8(d->fRandom->nextBits(8));
    521             }
    522         }
    523     }
    524     auto filter(SkTableColorFilter::MakeARGB(
    525         (flags & (1 << 0)) ? luts[0] : nullptr,
    526         (flags & (1 << 1)) ? luts[1] : nullptr,
    527         (flags & (1 << 2)) ? luts[2] : nullptr,
    528         (flags & (1 << 3)) ? luts[3] : nullptr
    529     ));
    530     sk_sp<SkColorSpace> colorSpace = GrTest::TestColorSpace(d->fRandom);
    531     sk_sp<GrFragmentProcessor> fp = filter->asFragmentProcessor(d->context(), colorSpace.get());
    532     SkASSERT(fp);
    533     return fp;
    534 }
    535 #endif
    536 
    537 sk_sp<GrFragmentProcessor> SkTable_ColorFilter::asFragmentProcessor(GrContext* context,
    538                                                                     SkColorSpace*) const {
    539     SkBitmap bitmap;
    540     this->asComponentTable(&bitmap);
    541 
    542     return ColorTableEffect::Make(context, bitmap, fFlags);
    543 }
    544 
    545 #endif // SK_SUPPORT_GPU
    546 
    547 ///////////////////////////////////////////////////////////////////////////////
    548 
    549 sk_sp<SkColorFilter> SkTableColorFilter::Make(const uint8_t table[256]) {
    550     return sk_make_sp<SkTable_ColorFilter>(table, table, table, table);
    551 }
    552 
    553 sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256],
    554                                                   const uint8_t tableR[256],
    555                                                   const uint8_t tableG[256],
    556                                                   const uint8_t tableB[256]) {
    557     return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB);
    558 }
    559 
    560 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter)
    561     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter)
    562 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
    563