Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef GrPaint_DEFINED | 10 #ifndef GrPaint_DEFINED |
| 11 #define GrPaint_DEFINED | 11 #define GrPaint_DEFINED |
| 12 | 12 |
| 13 #include "GrColor.h" | 13 #include "GrColor.h" |
| 14 #include "GrFragmentStage.h" | 14 #include "GrFragmentStage.h" |
| 15 #include "GrXferProcessor.h" | |
| 15 | 16 |
| 16 #include "SkXfermode.h" | 17 #include "SkXfermode.h" |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * The paint describes how color and coverage are computed at each pixel by GrCo ntext draw | 20 * The paint describes how color and coverage are computed at each pixel by GrCo ntext draw |
| 20 * functions and the how color is blended with the destination pixel. | 21 * functions and the how color is blended with the destination pixel. |
| 21 * | 22 * |
| 22 * The paint allows installation of custom color and coverage stages. New types of stages are | 23 * The paint allows installation of custom color and coverage stages. New types of stages are |
| 23 * created by subclassing GrProcessor. | 24 * created by subclassing GrProcessor. |
| 24 * | 25 * |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 */ | 72 */ |
| 72 void setAntiAlias(bool aa) { fAntiAlias = aa; } | 73 void setAntiAlias(bool aa) { fAntiAlias = aa; } |
| 73 bool isAntiAlias() const { return fAntiAlias; } | 74 bool isAntiAlias() const { return fAntiAlias; } |
| 74 | 75 |
| 75 /** | 76 /** |
| 76 * Should dithering be applied. Defaults to false. | 77 * Should dithering be applied. Defaults to false. |
| 77 */ | 78 */ |
| 78 void setDither(bool dither) { fDither = dither; } | 79 void setDither(bool dither) { fDither = dither; } |
| 79 bool isDither() const { return fDither; } | 80 bool isDither() const { return fDither; } |
| 80 | 81 |
| 82 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { | |
| 83 SkASSERT(xpFactory); | |
|
bsalomon
2014/11/26 21:02:44
This assert is done in SkRef().
egdaniel
2014/12/01 18:18:24
removed
| |
| 84 fXPFactory.reset(SkRef(xpFactory)); | |
| 85 return xpFactory; | |
| 86 } | |
| 87 | |
| 81 /** | 88 /** |
| 82 * Appends an additional color processor to the color computation. | 89 * Appends an additional color processor to the color computation. |
| 83 */ | 90 */ |
| 84 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp) { | 91 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp) { |
| 85 SkASSERT(fp); | 92 SkASSERT(fp); |
| 86 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp)); | 93 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp)); |
| 87 return fp; | 94 return fp; |
| 88 } | 95 } |
| 89 | 96 |
| 90 /** | 97 /** |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 102 */ | 109 */ |
| 103 void addColorTextureProcessor(GrTexture*, const SkMatrix&); | 110 void addColorTextureProcessor(GrTexture*, const SkMatrix&); |
| 104 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&); | 111 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&); |
| 105 void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTexturePa rams&); | 112 void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTexturePa rams&); |
| 106 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextur eParams&); | 113 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextur eParams&); |
| 107 | 114 |
| 108 int numColorStages() const { return fColorStages.count(); } | 115 int numColorStages() const { return fColorStages.count(); } |
| 109 int numCoverageStages() const { return fCoverageStages.count(); } | 116 int numCoverageStages() const { return fCoverageStages.count(); } |
| 110 int numTotalStages() const { return this->numColorStages() + this->numCovera geStages(); } | 117 int numTotalStages() const { return this->numColorStages() + this->numCovera geStages(); } |
| 111 | 118 |
| 119 bool hasXPFactory() const { return SkToBool(fXPFactory.get()); } | |
| 120 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | |
| 121 | |
| 112 const GrFragmentStage& getColorStage(int s) const { return fColorStages[s]; } | 122 const GrFragmentStage& getColorStage(int s) const { return fColorStages[s]; } |
| 113 const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStage s[s]; } | 123 const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStage s[s]; } |
| 114 | 124 |
| 115 GrPaint& operator=(const GrPaint& paint) { | 125 GrPaint& operator=(const GrPaint& paint) { |
| 116 fSrcBlendCoeff = paint.fSrcBlendCoeff; | 126 fSrcBlendCoeff = paint.fSrcBlendCoeff; |
| 117 fDstBlendCoeff = paint.fDstBlendCoeff; | 127 fDstBlendCoeff = paint.fDstBlendCoeff; |
| 118 fAntiAlias = paint.fAntiAlias; | 128 fAntiAlias = paint.fAntiAlias; |
| 119 fDither = paint.fDither; | 129 fDither = paint.fDither; |
| 120 | 130 |
| 121 fColor = paint.fColor; | 131 fColor = paint.fColor; |
| 122 | 132 |
| 123 fColorStages = paint.fColorStages; | 133 fColorStages = paint.fColorStages; |
| 124 fCoverageStages = paint.fCoverageStages; | 134 fCoverageStages = paint.fCoverageStages; |
| 125 | 135 |
| 136 SkASSERT(paint.hasXPFactory()); | |
|
bsalomon
2014/11/26 21:02:44
Why this assert?
egdaniel
2014/12/01 18:18:24
gone
| |
| 137 fXPFactory.reset(SkRef(paint.getXPFactory())); | |
| 138 | |
| 126 return *this; | 139 return *this; |
| 127 } | 140 } |
| 128 | 141 |
| 129 /** | 142 /** |
| 130 * Resets the paint to the defaults. | 143 * Resets the paint to the defaults. |
| 131 */ | 144 */ |
| 132 void reset() { | 145 void reset() { |
| 133 this->resetBlend(); | 146 this->resetBlend(); |
| 134 this->resetOptions(); | 147 this->resetOptions(); |
| 135 this->resetColor(); | 148 this->resetColor(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 computed = true; | 203 computed = true; |
| 191 } | 204 } |
| 192 fCoverageStages[i].localCoordChange(oldToNew); | 205 fCoverageStages[i].localCoordChange(oldToNew); |
| 193 } | 206 } |
| 194 return true; | 207 return true; |
| 195 } | 208 } |
| 196 | 209 |
| 197 friend class GrContext; // To access above two functions | 210 friend class GrContext; // To access above two functions |
| 198 friend class GrStencilAndCoverTextContext; // To access above two functions | 211 friend class GrStencilAndCoverTextContext; // To access above two functions |
| 199 | 212 |
| 200 SkSTArray<4, GrFragmentStage> fColorStages; | 213 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 201 SkSTArray<2, GrFragmentStage> fCoverageStages; | 214 SkSTArray<4, GrFragmentStage> fColorStages; |
| 215 SkSTArray<2, GrFragmentStage> fCoverageStages; | |
| 202 | 216 |
| 203 GrBlendCoeff fSrcBlendCoeff; | 217 GrBlendCoeff fSrcBlendCoeff; |
| 204 GrBlendCoeff fDstBlendCoeff; | 218 GrBlendCoeff fDstBlendCoeff; |
| 205 bool fAntiAlias; | 219 bool fAntiAlias; |
| 206 bool fDither; | 220 bool fDither; |
| 207 | 221 |
| 208 GrColor fColor; | 222 GrColor fColor; |
| 209 | 223 |
| 210 void resetBlend() { | 224 void resetBlend() { |
| 211 fSrcBlendCoeff = kOne_GrBlendCoeff; | 225 fSrcBlendCoeff = kOne_GrBlendCoeff; |
| 212 fDstBlendCoeff = kZero_GrBlendCoeff; | 226 fDstBlendCoeff = kZero_GrBlendCoeff; |
| 213 } | 227 } |
| 214 | 228 |
| 215 void resetOptions() { | 229 void resetOptions() { |
| 216 fAntiAlias = false; | 230 fAntiAlias = false; |
| 217 fDither = false; | 231 fDither = false; |
| 218 } | 232 } |
| 219 | 233 |
| 220 void resetColor() { | 234 void resetColor() { |
| 221 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); | 235 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); |
| 222 } | 236 } |
| 223 | 237 |
| 224 void resetStages() { | 238 void resetStages(); |
| 225 fColorStages.reset(); | |
| 226 fCoverageStages.reset(); | |
| 227 } | |
| 228 }; | 239 }; |
| 229 | 240 |
| 230 #endif | 241 #endif |
| OLD | NEW |