Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / effects / SkColorCubeFilter.h
1 /*
2  * Copyright 2014 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 #ifndef SkColorCubeFilter_DEFINED
9 #define SkColorCubeFilter_DEFINED
10
11 #include "SkColorFilter.h"
12 #include "SkData.h"
13
14 class SK_API SkColorCubeFilter : public SkColorFilter {
15 public:
16     /** cubeData must containt a 3D data in the form of cube of the size:
17      *  cubeDimension * cubeDimension * cubeDimension * sizeof(SkColor)
18      *  This cube contains a transform where (x,y,z) maps to the (r,g,b).
19      *  The alpha components of the colors are ignored (treated as 0xFF).
20      */
21     static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
22
23     virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const SK_OVERRIDE;
24     virtual uint32_t getFlags() const SK_OVERRIDE;
25
26 #if SK_SUPPORT_GPU
27    virtual GrFragmentProcessor* asFragmentProcessor(GrContext*) const SK_OVERRIDE;
28 #endif
29
30     SK_TO_STRING_OVERRIDE()
31     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
32
33 protected:
34     SkColorCubeFilter(SkData* cubeData, int cubeDimension);
35 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
36     SkColorCubeFilter(SkReadBuffer& buffer);
37 #endif
38     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
39
40 private:
41     /** The cache is initialized on-demand when getProcessingLuts is called.
42      */
43     class ColorCubeProcesingCache {
44     public:
45         ColorCubeProcesingCache(int cubeDimension);
46
47         void getProcessingLuts(const int* (*colorToIndex)[2],
48                                const SkScalar* (*colorToFactors)[2],
49                                const SkScalar** colorToScalar);
50
51         int cubeDimension() const { return fCubeDimension; }
52
53     private:
54         // Working pointers. If any of these is NULL,
55         // we need to recompute the corresponding cache values.
56         int* fColorToIndex[2];
57         SkScalar* fColorToFactors[2];
58         SkScalar* fColorToScalar;
59
60         SkAutoMalloc fLutStorage;
61
62         const int fCubeDimension;
63
64         // Make sure we only initialize the caches once.
65         SkMutex fLutsMutex;
66         bool fLutsInited;
67
68         static void initProcessingLuts(ColorCubeProcesingCache* cache);
69     };
70
71     SkAutoDataUnref fCubeData;
72     int32_t fUniqueID;
73
74     mutable ColorCubeProcesingCache fCache;
75
76     typedef SkColorFilter INHERITED;
77 };
78
79 #endif