| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 | 8 |
| 9 #ifndef SkShader_DEFINED | 9 #ifndef SkShader_DEFINED |
| 10 #define SkShader_DEFINED | 10 #define SkShader_DEFINED |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * Returns true if the shader is guaranteed to produce only opaque | 115 * Returns true if the shader is guaranteed to produce only opaque |
| 116 * colors, subject to the SkPaint using the shader to apply an opaque | 116 * colors, subject to the SkPaint using the shader to apply an opaque |
| 117 * alpha value. Subclasses should override this to allow some | 117 * alpha value. Subclasses should override this to allow some |
| 118 * optimizations. | 118 * optimizations. |
| 119 */ | 119 */ |
| 120 virtual bool isOpaque() const { return false; } | 120 virtual bool isOpaque() const { return false; } |
| 121 | 121 |
| 122 /** |
| 123 * ContextRec acts as a parameter bundle for creating Contexts. |
| 124 */ |
| 125 struct ContextRec { |
| 126 ContextRec() : fDevice(NULL), fPaint(NULL), fMatrix(NULL) {} |
| 127 ContextRec(const ContextRec& other) |
| 128 : fDevice(other.fDevice), fPaint(other.fPaint), fMatrix(other.fMatri
x) {} |
| 129 ContextRec(const SkBitmap& device, const SkPaint& paint, const SkMatrix&
matrix) |
| 130 : fDevice(&device) |
| 131 , fPaint(&paint) |
| 132 , fMatrix(&matrix) {} |
| 133 |
| 134 const SkBitmap* fDevice; // the bitmap we are drawing into |
| 135 const SkPaint* fPaint; // the current paint associated with the dra
w |
| 136 const SkMatrix* fMatrix; // the current matrix in the canvas |
| 137 }; |
| 138 |
| 122 class Context : public ::SkNoncopyable { | 139 class Context : public ::SkNoncopyable { |
| 123 public: | 140 public: |
| 124 Context(const SkShader& shader, const SkBitmap& device, | 141 Context(const SkShader& shader, const ContextRec&); |
| 125 const SkPaint& paint, const SkMatrix& matrix); | |
| 126 | 142 |
| 127 virtual ~Context(); | 143 virtual ~Context(); |
| 128 | 144 |
| 129 /** | 145 /** |
| 130 * Called sometimes before drawing with this shader. Return the type of | 146 * Called sometimes before drawing with this shader. Return the type of |
| 131 * alpha your shader will return. The default implementation returns 0. | 147 * alpha your shader will return. The default implementation returns 0. |
| 132 * Your subclass should override if it can (even sometimes) report a | 148 * Your subclass should override if it can (even sometimes) report a |
| 133 * non-zero value, since that will enable various blitters to perform | 149 * non-zero value, since that will enable various blitters to perform |
| 134 * faster. | 150 * faster. |
| 135 */ | 151 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 uint8_t fPaintAlpha; | 209 uint8_t fPaintAlpha; |
| 194 uint8_t fTotalInverseClass; | 210 uint8_t fTotalInverseClass; |
| 195 | 211 |
| 196 typedef SkNoncopyable INHERITED; | 212 typedef SkNoncopyable INHERITED; |
| 197 }; | 213 }; |
| 198 | 214 |
| 199 /** | 215 /** |
| 200 * Subclasses should be sure to call their INHERITED::validContext() if | 216 * Subclasses should be sure to call their INHERITED::validContext() if |
| 201 * they override this method. | 217 * they override this method. |
| 202 */ | 218 */ |
| 203 virtual bool validContext(const SkBitmap& device, const SkPaint& paint, | 219 virtual bool validContext(const ContextRec&, SkMatrix* totalInverse = NULL)
const; |
| 204 const SkMatrix& matrix, SkMatrix* totalInverse = N
ULL) const; | |
| 205 | 220 |
| 206 /** | 221 /** |
| 207 * Create the actual object that does the shading. | 222 * Create the actual object that does the shading. |
| 208 * Returns NULL if validContext() returns false. | 223 * Returns NULL if validContext() returns false. |
| 209 * Size of storage must be >= contextSize. | 224 * Size of storage must be >= contextSize. |
| 210 * Your subclass must also override contextSize() if it overrides createCon
text(). | 225 * Your subclass must also override contextSize() if it overrides createCon
text(). |
| 211 * | 226 * |
| 212 * Base class implementation returns NULL. | 227 * Base class implementation returns NULL. |
| 213 */ | 228 */ |
| 214 virtual Context* createContext(const SkBitmap& device, | 229 virtual Context* createContext(const ContextRec&, void* storage) const; |
| 215 const SkPaint& paint, | |
| 216 const SkMatrix& matrix, | |
| 217 void* storage) const; | |
| 218 | 230 |
| 219 /** | 231 /** |
| 220 * Return the size of a Context returned by createContext. | 232 * Return the size of a Context returned by createContext. |
| 221 * | 233 * |
| 222 * Override this if your subclass overrides createContext, to return the co
rrect size of | 234 * Override this if your subclass overrides createContext, to return the co
rrect size of |
| 223 * your subclass' context. | 235 * your subclass' context. |
| 224 */ | 236 */ |
| 225 virtual size_t contextSize() const; | 237 virtual size_t contextSize() const; |
| 226 | 238 |
| 227 /** | 239 /** |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 414 |
| 403 private: | 415 private: |
| 404 SkMatrix fLocalMatrix; | 416 SkMatrix fLocalMatrix; |
| 405 | 417 |
| 406 bool computeTotalInverse(const SkMatrix& matrix, SkMatrix* totalInverse) con
st; | 418 bool computeTotalInverse(const SkMatrix& matrix, SkMatrix* totalInverse) con
st; |
| 407 | 419 |
| 408 typedef SkFlattenable INHERITED; | 420 typedef SkFlattenable INHERITED; |
| 409 }; | 421 }; |
| 410 | 422 |
| 411 #endif | 423 #endif |
| OLD | NEW |