Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #include "../private/SkOnce.h"
14 #include "../private/SkTemplates.h"
15 
16 class SK_API SkColorCubeFilter : public SkColorFilter {
17 public:
23  static sk_sp<SkColorFilter> Make(sk_sp<SkData> cubeData, int cubeDimension);
24 
25 #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
26  static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
27 #endif
28 
29  void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
30  uint32_t getFlags() const override;
31 
32 #if SK_SUPPORT_GPU
34 #endif
35 
36  SK_TO_STRING_OVERRIDE()
37  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
38 
39 protected:
40  SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension);
41  void flatten(SkWriteBuffer&) const override;
42 
43 private:
47  public:
48  ColorCubeProcesingCache(int cubeDimension);
49 
50  void getProcessingLuts(const int* (*colorToIndex)[2],
51  const SkScalar* (*colorToFactors)[2],
52  const SkScalar** colorToScalar);
53 
54  int cubeDimension() const { return fCubeDimension; }
55 
56  private:
57  // Working pointers. If any of these is NULL,
58  // we need to recompute the corresponding cache values.
59  int* fColorToIndex[2];
60  SkScalar* fColorToFactors[2];
61  SkScalar* fColorToScalar;
62 
63  SkAutoTMalloc<uint8_t> fLutStorage;
64 
65  const int fCubeDimension;
66 
67  // Make sure we only initialize the caches once.
68  SkOnce fLutsInitOnce;
69 
70  static void initProcessingLuts(ColorCubeProcesingCache* cache);
71  };
72 
73  sk_sp<SkData> fCubeData;
74  int32_t fUniqueID;
75 
76  mutable ColorCubeProcesingCache fCache;
77 
78  typedef SkColorFilter INHERITED;
79 };
80 
81 #endif
Definition: SkColorCubeFilter.h:16
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:29
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) const =0
Called with a scanline of colors, as if there was a shader installed.
The cache is initialized on-demand when getProcessingLuts is called.
Definition: SkColorCubeFilter.h:46
SkData holds an immutable data buffer.
Definition: SkData.h:22
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:70
virtual uint32_t getFlags() const
Returns the flags for this filter.
Definition: SkColorFilter.h:84
Definition: GrContext.h:48
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
Definition: SkWriteBuffer.h:26
virtual void flatten(SkWriteBuffer &) const
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
Definition: SkFlattenable.h:117
virtual sk_sp< GrFragmentProcessor > asFragmentProcessor(GrContext *) const
A subclass may implement this factory function to work with the GPU backend.