OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #ifndef SkLayerDrawLooper_DEFINED | 8 #ifndef SkLayerDrawLooper_DEFINED |
9 #define SkLayerDrawLooper_DEFINED | 9 #define SkLayerDrawLooper_DEFINED |
10 | 10 |
11 #include "SkDrawLooper.h" | 11 #include "SkDrawLooper.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkPoint.h" | 13 #include "SkPoint.h" |
14 #include "SkXfermode.h" | 14 #include "SkXfermode.h" |
15 | 15 |
16 class SK_API SkLayerDrawLooper : public SkDrawLooper { | 16 class SK_API SkLayerDrawLooper : public SkDrawLooper { |
17 public: | 17 public: |
18 SK_DECLARE_INST_COUNT(SkLayerDrawLooper) | 18 SK_DECLARE_INST_COUNT(SkLayerDrawLooper) |
19 | 19 |
20 SkLayerDrawLooper(); | |
21 virtual ~SkLayerDrawLooper(); | 20 virtual ~SkLayerDrawLooper(); |
22 | 21 |
23 /** | 22 /** |
24 * Bits specifies which aspects of the layer's paint should replace the | 23 * Bits specifies which aspects of the layer's paint should replace the |
25 * corresponding aspects on the draw's paint. | 24 * corresponding aspects on the draw's paint. |
26 * kEntirePaint_Bits means use the layer's paint completely. | 25 * kEntirePaint_Bits means use the layer's paint completely. |
27 * 0 means ignore the layer's paint... except for fColorMode, which is | 26 * 0 means ignore the layer's paint... except for fColorMode, which is |
28 * always applied. | 27 * always applied. |
29 */ | 28 */ |
30 enum Bits { | 29 enum Bits { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 /** | 66 /** |
68 * Initial the LayerInfo. Defaults to settings that will draw the | 67 * Initial the LayerInfo. Defaults to settings that will draw the |
69 * layer with no changes: e.g. | 68 * layer with no changes: e.g. |
70 * fPaintBits == 0 | 69 * fPaintBits == 0 |
71 * fColorMode == kDst_Mode | 70 * fColorMode == kDst_Mode |
72 * fOffset == (0, 0) | 71 * fOffset == (0, 0) |
73 */ | 72 */ |
74 LayerInfo(); | 73 LayerInfo(); |
75 }; | 74 }; |
76 | 75 |
77 /** | |
78 * Call for each layer you want to add (from top to bottom). | |
79 * This returns a paint you can modify, but that ptr is only valid until | |
80 * the next call made to addLayer(). | |
81 */ | |
82 SkPaint* addLayer(const LayerInfo&); | |
83 | |
84 /** | |
85 * This layer will draw with the original paint, at the specified offset | |
86 */ | |
87 void addLayer(SkScalar dx, SkScalar dy); | |
88 | |
89 /** | |
90 * This layer will with the original paint and no offset. | |
91 */ | |
92 void addLayer() { this->addLayer(0, 0); } | |
93 | |
94 /// Similar to addLayer, but adds a layer to the top. | |
95 SkPaint* addLayerOnTop(const LayerInfo&); | |
96 | |
97 virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const
SK_OVERRIDE; | 76 virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const
SK_OVERRIDE; |
98 | 77 |
99 virtual size_t contextSize() const SK_OVERRIDE { return sizeof(LayerDrawLoop
erContext); } | 78 virtual size_t contextSize() const SK_OVERRIDE { return sizeof(LayerDrawLoop
erContext); } |
100 | 79 |
101 SK_TO_STRING_OVERRIDE() | 80 SK_TO_STRING_OVERRIDE() |
102 | 81 |
103 /// Implements Flattenable. | 82 /// Implements Flattenable. |
104 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } | 83 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } |
105 static SkFlattenable* CreateProc(SkReadBuffer& buffer); | 84 static SkFlattenable* CreateProc(SkReadBuffer& buffer); |
106 | 85 |
107 protected: | 86 protected: |
| 87 SkLayerDrawLooper(); |
| 88 |
108 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 89 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
109 | 90 |
110 private: | 91 private: |
111 struct Rec { | 92 struct Rec { |
112 Rec* fNext; | 93 Rec* fNext; |
113 SkPaint fPaint; | 94 SkPaint fPaint; |
114 LayerInfo fInfo; | 95 LayerInfo fInfo; |
115 }; | 96 }; |
116 Rec* fRecs; | 97 Rec* fRecs; |
117 Rec* fTopRec; | 98 Rec* fTopRec; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 SkLayerDrawLooper* detachLooper(); | 152 SkLayerDrawLooper* detachLooper(); |
172 | 153 |
173 private: | 154 private: |
174 Rec* fRecs; | 155 Rec* fRecs; |
175 Rec* fTopRec; | 156 Rec* fTopRec; |
176 int fCount; | 157 int fCount; |
177 }; | 158 }; |
178 }; | 159 }; |
179 | 160 |
180 #endif | 161 #endif |
OLD | NEW |