Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: src/gpu/GrDrawState.h

Issue 25023003: Implement color filter as GrGLEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 GrDrawState_DEFINED 8 #ifndef GrDrawState_DEFINED
9 #define GrDrawState_DEFINED 9 #define GrDrawState_DEFINED
10 10
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 * Sets the color to be used for the next draw to be 259 * Sets the color to be used for the next draw to be
260 * (r,g,b,a) = (alpha, alpha, alpha, alpha). 260 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
261 * 261 *
262 * @param alpha The alpha value to set as the color. 262 * @param alpha The alpha value to set as the color.
263 */ 263 */
264 void setAlpha(uint8_t a) { 264 void setAlpha(uint8_t a) {
265 this->setColor((a << 24) | (a << 16) | (a << 8) | a); 265 this->setColor((a << 24) | (a << 16) | (a << 8) | a);
266 } 266 }
267 267
268 /** 268 /**
269 * Add a color filter that can be represented by a color and a mode. Applied
270 * after color-computing effect stages.
271 */
272 void setColorFilter(GrColor c, SkXfermode::Mode mode) {
273 fCommon.fColorFilterColor = c;
274 fCommon.fColorFilterMode = mode;
275 }
276
277 GrColor getColorFilterColor() const { return fCommon.fColorFilterColor; }
278 SkXfermode::Mode getColorFilterMode() const { return fCommon.fColorFilterMod e; }
279
280 /**
281 * Constructor sets the color to be 'color' which is undone by the destructo r. 269 * Constructor sets the color to be 'color' which is undone by the destructo r.
282 */ 270 */
283 class AutoColorRestore : public ::SkNoncopyable { 271 class AutoColorRestore : public ::SkNoncopyable {
284 public: 272 public:
285 AutoColorRestore() : fDrawState(NULL), fOldColor(0) {} 273 AutoColorRestore() : fDrawState(NULL), fOldColor(0) {}
286 274
287 AutoColorRestore(GrDrawState* drawState, GrColor color) { 275 AutoColorRestore(GrDrawState* drawState, GrColor color) {
288 fDrawState = NULL; 276 fDrawState = NULL;
289 this->set(drawState, color); 277 this->set(drawState, color);
290 } 278 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 /// The input color to the first color-stage is either the constant color or interpolated 341 /// The input color to the first color-stage is either the constant color or interpolated
354 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage 342 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage
355 /// (usually full-coverage) or interpolated per-vertex coverage. 343 /// (usually full-coverage) or interpolated per-vertex coverage.
356 /// 344 ///
357 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the 345 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
358 /// the color / coverage distinction. 346 /// the color / coverage distinction.
359 //// 347 ////
360 348
361 const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { 349 const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
362 SkASSERT(NULL != effect); 350 SkASSERT(NULL != effect);
351 if (!(*effect)->willUseInputColor()) {
bsalomon 2013/10/02 16:37:59 I don't think this is safe because of AutoRestoreE
Kimmo Kinnunen 2013/10/04 06:21:18 Done. Not sure the new naming is the best possible
352 fColorStages.reset();
353 }
363 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); 354 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1));
364 return effect; 355 return effect;
365 } 356 }
366 357
367 const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { 358 const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
368 SkASSERT(NULL != effect); 359 SkASSERT(NULL != effect);
369 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); 360 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
370 return effect; 361 return effect;
371 } 362 }
372 363
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 fCommon.fViewMatrix.reset(); 899 fCommon.fViewMatrix.reset();
909 } else { 900 } else {
910 fCommon.fViewMatrix = *initialViewMatrix; 901 fCommon.fViewMatrix = *initialViewMatrix;
911 } 902 }
912 fCommon.fSrcBlend = kOne_GrBlendCoeff; 903 fCommon.fSrcBlend = kOne_GrBlendCoeff;
913 fCommon.fDstBlend = kZero_GrBlendCoeff; 904 fCommon.fDstBlend = kZero_GrBlendCoeff;
914 fCommon.fBlendConstant = 0x0; 905 fCommon.fBlendConstant = 0x0;
915 fCommon.fFlagBits = 0x0; 906 fCommon.fFlagBits = 0x0;
916 fCommon.fStencilSettings.setDisabled(); 907 fCommon.fStencilSettings.setDisabled();
917 fCommon.fCoverage = 0xffffffff; 908 fCommon.fCoverage = 0xffffffff;
918 fCommon.fColorFilterMode = SkXfermode::kDst_Mode;
919 fCommon.fColorFilterColor = 0x0;
920 fCommon.fDrawFace = kBoth_DrawFace; 909 fCommon.fDrawFace = kBoth_DrawFace;
921 } 910 }
922 911
923 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState. */ 912 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState. */
924 struct CommonState { 913 struct CommonState {
925 // These fields are roughly sorted by decreasing likelihood of being dif ferent in op== 914 // These fields are roughly sorted by decreasing likelihood of being dif ferent in op==
926 GrColor fColor; 915 GrColor fColor;
927 SkMatrix fViewMatrix; 916 SkMatrix fViewMatrix;
928 GrBlendCoeff fSrcBlend; 917 GrBlendCoeff fSrcBlend;
929 GrBlendCoeff fDstBlend; 918 GrBlendCoeff fDstBlend;
930 GrColor fBlendConstant; 919 GrColor fBlendConstant;
931 uint32_t fFlagBits; 920 uint32_t fFlagBits;
932 const GrVertexAttrib* fVAPtr; 921 const GrVertexAttrib* fVAPtr;
933 int fVACount; 922 int fVACount;
934 GrStencilSettings fStencilSettings; 923 GrStencilSettings fStencilSettings;
935 GrColor fCoverage; 924 GrColor fCoverage;
936 SkXfermode::Mode fColorFilterMode;
937 GrColor fColorFilterColor;
938 DrawFace fDrawFace; 925 DrawFace fDrawFace;
939 926
940 // This is simply a different representation of info in fVertexAttribs a nd thus does 927 // This is simply a different representation of info in fVertexAttribs a nd thus does
941 // not need to be compared in op==. 928 // not need to be compared in op==.
942 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin gCnt]; 929 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin gCnt];
943 930
944 bool operator== (const CommonState& other) const { 931 bool operator== (const CommonState& other) const {
945 bool result = fColor == other.fColor && 932 bool result = fColor == other.fColor &&
946 fViewMatrix.cheapEqualTo(other.fViewMatrix) && 933 fViewMatrix.cheapEqualTo(other.fViewMatrix) &&
947 fSrcBlend == other.fSrcBlend && 934 fSrcBlend == other.fSrcBlend &&
948 fDstBlend == other.fDstBlend && 935 fDstBlend == other.fDstBlend &&
949 fBlendConstant == other.fBlendConstant && 936 fBlendConstant == other.fBlendConstant &&
950 fFlagBits == other.fFlagBits && 937 fFlagBits == other.fFlagBits &&
951 fVACount == other.fVACount && 938 fVACount == other.fVACount &&
952 !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVert exAttrib)) && 939 !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVert exAttrib)) &&
953 fStencilSettings == other.fStencilSettings && 940 fStencilSettings == other.fStencilSettings &&
954 fCoverage == other.fCoverage && 941 fCoverage == other.fCoverage &&
955 fColorFilterMode == other.fColorFilterMode &&
956 fColorFilterColor == other.fColorFilterColor &&
957 fDrawFace == other.fDrawFace; 942 fDrawFace == other.fDrawFace;
958 SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, 943 SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices,
959 other.fFixedFunctionVertexAttribIndi ces, 944 other.fFixedFunctionVertexAttribIndi ces,
960 sizeof(fFixedFunctionVertexAttribInd ices))); 945 sizeof(fFixedFunctionVertexAttribInd ices)));
961 return result; 946 return result;
962 } 947 }
963 bool operator!= (const CommonState& other) const { return !(*this == oth er); } 948 bool operator!= (const CommonState& other) const { return !(*this == oth er); }
964 }; 949 };
965 950
966 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on GrEffectRef. 951 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on GrEffectRef.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. 1061 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt.
1077 */ 1062 */
1078 void setVertexAttribs(const GrVertexAttrib attribs[], int count); 1063 void setVertexAttribs(const GrVertexAttrib attribs[], int count);
1079 1064
1080 typedef SkRefCnt INHERITED; 1065 typedef SkRefCnt INHERITED;
1081 }; 1066 };
1082 1067
1083 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); 1068 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
1084 1069
1085 #endif 1070 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698