author Lee Salzman <>
Tue, 09 Feb 2016 13:38:06 -0500
changeset 283658 159e0a5a653f2789e0c9b94f41501a4a44f7cb34
parent 276800 aa380501527094672fd84092655f82e62c504482
child 295372 cf560124d28f3737353c105eec79677a7731d2e8
permissions -rw-r--r--
Bug 1246756 - part 3 - update Skia to m49 branch. r=jrmuizel

 * Copyright 2014 Google Inc.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.

#ifndef SkColorCubeFilter_DEFINED
#define SkColorCubeFilter_DEFINED

#include "SkColorFilter.h"
#include "SkData.h"
#include "../private/SkMutex.h"
#include "../private/SkTemplates.h"

class SK_API SkColorCubeFilter : public SkColorFilter {
    /** cubeData must containt a 3D data in the form of cube of the size:
     *  cubeDimension * cubeDimension * cubeDimension * sizeof(SkColor)
     *  This cube contains a transform where (x,y,z) maps to the (r,g,b).
     *  The alpha components of the colors must be 0xFF.
    static SkColorFilter* Create(SkData* cubeData, int cubeDimension);

    void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
    uint32_t getFlags() const override;

    const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override;


    SkColorCubeFilter(SkData* cubeData, int cubeDimension);
    void flatten(SkWriteBuffer&) const override;

    /** The cache is initialized on-demand when getProcessingLuts is called.
    class ColorCubeProcesingCache {
        ColorCubeProcesingCache(int cubeDimension);

        void getProcessingLuts(const int* (*colorToIndex)[2],
                               const SkScalar* (*colorToFactors)[2],
                               const SkScalar** colorToScalar);

        int cubeDimension() const { return fCubeDimension; }

        // Working pointers. If any of these is NULL,
        // we need to recompute the corresponding cache values.
        int* fColorToIndex[2];
        SkScalar* fColorToFactors[2];
        SkScalar* fColorToScalar;

        SkAutoTMalloc<uint8_t> fLutStorage;

        const int fCubeDimension;

        // Make sure we only initialize the caches once.
        SkMutex fLutsMutex;
        bool fLutsInited;

        static void initProcessingLuts(ColorCubeProcesingCache* cache);

    SkAutoDataUnref fCubeData;
    int32_t fUniqueID;

    mutable ColorCubeProcesingCache fCache;

    typedef SkColorFilter INHERITED;