| 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 #ifndef SkShader_DEFINED | 8 #ifndef SkShader_DEFINED |
| 9 #define SkShader_DEFINED | 9 #define SkShader_DEFINED |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 enum { | 67 enum { |
| 68 kTileModeCount = kMirror_TileMode + 1 | 68 kTileModeCount = kMirror_TileMode + 1 |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // override these in your subclass | 71 // override these in your subclass |
| 72 | 72 |
| 73 enum Flags { | 73 enum Flags { |
| 74 //!< set if all of the colors will be opaque | 74 //!< set if all of the colors will be opaque |
| 75 kOpaqueAlpha_Flag = 0x01, | 75 kOpaqueAlpha_Flag = 1 << 0, |
| 76 | |
| 77 //! set if this shader's shadeSpan16() method can be called | |
| 78 kHasSpan16_Flag = 0x02, | |
| 79 | |
| 80 /** Set this bit if the shader's native data type is instrinsically 16 | |
| 81 bit, meaning that calling the 32bit shadeSpan() entry point will | |
| 82 mean the the impl has to up-sample 16bit data into 32bit. Used as a | |
| 83 a means of clearing a dither request if the it will have no effect | |
| 84 */ | |
| 85 kIntrinsicly16_Flag = 0x04, | |
| 86 | 76 |
| 87 /** set if the spans only vary in X (const in Y). | 77 /** set if the spans only vary in X (const in Y). |
| 88 e.g. an Nx1 bitmap that is being tiled in Y, or a linear-gradient | 78 e.g. an Nx1 bitmap that is being tiled in Y, or a linear-gradient |
| 89 that varies from left-to-right. This flag specifies this for | 79 that varies from left-to-right. This flag specifies this for |
| 90 shadeSpan(). | 80 shadeSpan(). |
| 91 */ | 81 */ |
| 92 kConstInY32_Flag = 0x08, | 82 kConstInY32_Flag = 1 << 1, |
| 93 | |
| 94 /** same as kConstInY32_Flag, but is set if this is true for shadeSpan16 | |
| 95 which may not always be the case, since shadeSpan16 may be | |
| 96 predithered, which would mean it was not const in Y, even though | |
| 97 the 32bit shadeSpan() would be const. | |
| 98 */ | |
| 99 kConstInY16_Flag = 0x10 | |
| 100 }; | 83 }; |
| 101 | 84 |
| 102 /** | 85 /** |
| 103 * Returns true if the shader is guaranteed to produce only opaque | 86 * Returns true if the shader is guaranteed to produce only opaque |
| 104 * colors, subject to the SkPaint using the shader to apply an opaque | 87 * colors, subject to the SkPaint using the shader to apply an opaque |
| 105 * alpha value. Subclasses should override this to allow some | 88 * alpha value. Subclasses should override this to allow some |
| 106 * optimizations. | 89 * optimizations. |
| 107 */ | 90 */ |
| 108 virtual bool isOpaque() const { return false; } | 91 virtual bool isOpaque() const { return false; } |
| 109 | 92 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 130 /** | 113 /** |
| 131 * Called sometimes before drawing with this shader. Return the type of | 114 * Called sometimes before drawing with this shader. Return the type of |
| 132 * alpha your shader will return. The default implementation returns 0. | 115 * alpha your shader will return. The default implementation returns 0. |
| 133 * Your subclass should override if it can (even sometimes) report a | 116 * Your subclass should override if it can (even sometimes) report a |
| 134 * non-zero value, since that will enable various blitters to perform | 117 * non-zero value, since that will enable various blitters to perform |
| 135 * faster. | 118 * faster. |
| 136 */ | 119 */ |
| 137 virtual uint32_t getFlags() const { return 0; } | 120 virtual uint32_t getFlags() const { return 0; } |
| 138 | 121 |
| 139 /** | 122 /** |
| 140 * Return the alpha associated with the data returned by shadeSpan16().
If | |
| 141 * kHasSpan16_Flag is not set, this value is meaningless. | |
| 142 */ | |
| 143 virtual uint8_t getSpan16Alpha() const { return fPaintAlpha; } | |
| 144 | |
| 145 /** | |
| 146 * Called for each span of the object being drawn. Your subclass should | 123 * Called for each span of the object being drawn. Your subclass should |
| 147 * set the appropriate colors (with premultiplied alpha) that correspon
d | 124 * set the appropriate colors (with premultiplied alpha) that correspon
d |
| 148 * to the specified device coordinates. | 125 * to the specified device coordinates. |
| 149 */ | 126 */ |
| 150 virtual void shadeSpan(int x, int y, SkPMColor[], int count) = 0; | 127 virtual void shadeSpan(int x, int y, SkPMColor[], int count) = 0; |
| 151 | 128 |
| 152 /** | 129 /** |
| 153 * The const void* ctx is only const because all the implementations are
const. | 130 * The const void* ctx is only const because all the implementations are
const. |
| 154 * This can be changed to non-const if a new shade proc needs to change
the ctx. | 131 * This can be changed to non-const if a new shade proc needs to change
the ctx. |
| 155 */ | 132 */ |
| 156 typedef void (*ShadeProc)(const void* ctx, int x, int y, SkPMColor[], in
t count); | 133 typedef void (*ShadeProc)(const void* ctx, int x, int y, SkPMColor[], in
t count); |
| 157 virtual ShadeProc asAShadeProc(void** ctx); | 134 virtual ShadeProc asAShadeProc(void** ctx); |
| 158 | 135 |
| 159 /** | 136 /** |
| 160 * Called only for 16bit devices when getFlags() returns | |
| 161 * kOpaqueAlphaFlag | kHasSpan16_Flag | |
| 162 */ | |
| 163 virtual void shadeSpan16(int x, int y, uint16_t[], int count); | |
| 164 | |
| 165 /** | |
| 166 * Similar to shadeSpan, but only returns the alpha-channel for a span. | 137 * Similar to shadeSpan, but only returns the alpha-channel for a span. |
| 167 * The default implementation calls shadeSpan() and then extracts the a
lpha | 138 * The default implementation calls shadeSpan() and then extracts the a
lpha |
| 168 * values from the returned colors. | 139 * values from the returned colors. |
| 169 */ | 140 */ |
| 170 virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count); | 141 virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count); |
| 171 | 142 |
| 172 /** | |
| 173 * Helper function that returns true if this shader's shadeSpan16() met
hod | |
| 174 * can be called. | |
| 175 */ | |
| 176 bool canCallShadeSpan16() { | |
| 177 return SkShader::CanCallShadeSpan16(this->getFlags()); | |
| 178 } | |
| 179 | |
| 180 // Notification from blitter::blitMask in case we need to see the non-al
pha channels | 143 // Notification from blitter::blitMask in case we need to see the non-al
pha channels |
| 181 virtual void set3DMask(const SkMask*) {} | 144 virtual void set3DMask(const SkMask*) {} |
| 182 | 145 |
| 183 protected: | 146 protected: |
| 184 // Reference to shader, so we don't have to dupe information. | 147 // Reference to shader, so we don't have to dupe information. |
| 185 const SkShader& fShader; | 148 const SkShader& fShader; |
| 186 | 149 |
| 187 enum MatrixClass { | 150 enum MatrixClass { |
| 188 kLinear_MatrixClass, // no perspective | 151 kLinear_MatrixClass, // no perspective |
| 189 kFixedStepInX_MatrixClass, // fast perspective, need to call fi
xedStepInX() each | 152 kFixedStepInX_MatrixClass, // fast perspective, need to call fi
xedStepInX() each |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 | 176 |
| 214 /** | 177 /** |
| 215 * Return the size of a Context returned by createContext. | 178 * Return the size of a Context returned by createContext. |
| 216 * | 179 * |
| 217 * Override this if your subclass overrides createContext, to return the co
rrect size of | 180 * Override this if your subclass overrides createContext, to return the co
rrect size of |
| 218 * your subclass' context. | 181 * your subclass' context. |
| 219 */ | 182 */ |
| 220 virtual size_t contextSize() const; | 183 virtual size_t contextSize() const; |
| 221 | 184 |
| 222 /** | 185 /** |
| 223 * Helper to check the flags to know if it is legal to call shadeSpan16() | |
| 224 */ | |
| 225 static bool CanCallShadeSpan16(uint32_t flags) { | |
| 226 return (flags & kHasSpan16_Flag) != 0; | |
| 227 } | |
| 228 | |
| 229 /** | |
| 230 * Returns true if this shader is just a bitmap, and if not null, returns t
he bitmap, | 186 * Returns true if this shader is just a bitmap, and if not null, returns t
he bitmap, |
| 231 * localMatrix, and tilemodes. If this is not a bitmap, returns false and i
gnores the | 187 * localMatrix, and tilemodes. If this is not a bitmap, returns false and i
gnores the |
| 232 * out-parameters. | 188 * out-parameters. |
| 233 */ | 189 */ |
| 234 bool isABitmap(SkBitmap* outTexture, SkMatrix* outMatrix, TileMode xy[2]) co
nst { | 190 bool isABitmap(SkBitmap* outTexture, SkMatrix* outMatrix, TileMode xy[2]) co
nst { |
| 235 return this->onIsABitmap(outTexture, outMatrix, xy); | 191 return this->onIsABitmap(outTexture, outMatrix, xy); |
| 236 } | 192 } |
| 237 | 193 |
| 238 bool isABitmap() const { | 194 bool isABitmap() const { |
| 239 return this->isABitmap(nullptr, nullptr, nullptr); | 195 return this->isABitmap(nullptr, nullptr, nullptr); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 SkMatrix fLocalMatrix; | 400 SkMatrix fLocalMatrix; |
| 445 | 401 |
| 446 // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer con
structor. | 402 // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer con
structor. |
| 447 friend class SkLocalMatrixShader; | 403 friend class SkLocalMatrixShader; |
| 448 friend class SkBitmapProcShader; // for computeTotalInverse() | 404 friend class SkBitmapProcShader; // for computeTotalInverse() |
| 449 | 405 |
| 450 typedef SkFlattenable INHERITED; | 406 typedef SkFlattenable INHERITED; |
| 451 }; | 407 }; |
| 452 | 408 |
| 453 #endif | 409 #endif |
| OLD | NEW |