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

Unified Diff: src/gpu/gl/GrGLSL.cpp

Issue 13895006: Expand modulate, add, subtract, extract component glsl helpers. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLSL.cpp
===================================================================
--- src/gpu/gl/GrGLSL.cpp (revision 8735)
+++ src/gpu/gl/GrGLSL.cpp (working copy)
@@ -87,76 +87,28 @@
return GrGLSLVectorNonhomogCoords(GrSLTypeToVecLength(type));
}
-GrSLConstantVec GrGLSLModulate4f(SkString* outAppend,
- const char* in0,
- const char* in1,
- GrSLConstantVec default0,
- GrSLConstantVec default1) {
- GrAssert(NULL != outAppend);
-
- bool has0 = NULL != in0 && '\0' != *in0;
- bool has1 = NULL != in1 && '\0' != *in1;
-
- GrAssert(has0 || kNone_GrSLConstantVec != default0);
- GrAssert(has1 || kNone_GrSLConstantVec != default1);
-
- if (!has0 && !has1) {
- GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
- GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
- if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == default1) {
- outAppend->append(GrGLSLZerosVecf(4));
- return kZeros_GrSLConstantVec;
- } else {
- // both inputs are ones vectors
- outAppend->append(GrGLSLOnesVecf(4));
- return kOnes_GrSLConstantVec;
+namespace {
+ void append_tabs(SkString* outAppend, int tabCnt) {
+ static const char kTabs[] = "\t\t\t\t\t\t\t\t";
+ while (tabCnt) {
+ int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
+ outAppend->append(kTabs, cnt);
+ tabCnt -= cnt;
}
- } else if (!has0) {
- GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
- if (kZeros_GrSLConstantVec == default0) {
- outAppend->append(GrGLSLZerosVecf(4));
- return kZeros_GrSLConstantVec;
- } else {
- outAppend->appendf("vec4(%s)", in1);
- return kNone_GrSLConstantVec;
- }
- } else if (!has1) {
- GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
- if (kZeros_GrSLConstantVec == default1) {
- outAppend->append(GrGLSLZerosVecf(4));
- return kZeros_GrSLConstantVec;
- } else {
- outAppend->appendf("vec4(%s)", in0);
- return kNone_GrSLConstantVec;
- }
- } else {
- outAppend->appendf("vec4(%s * %s)", in0, in1);
- return kNone_GrSLConstantVec;
}
}
-namespace {
-void append_tabs(SkString* outAppend, int tabCnt) {
- static const char kTabs[] = "\t\t\t\t\t\t\t\t";
- while (tabCnt) {
- int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
- outAppend->append(kTabs, cnt);
- tabCnt -= cnt;
- }
-}
-}
-
GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend,
int tabCnt,
const char* vec4VarName,
const char* mulFactor,
GrSLConstantVec mulFactorDefault) {
bool haveFactor = NULL != mulFactor && '\0' != *mulFactor;
-
+
GrAssert(NULL != outAppend);
GrAssert(NULL != vec4VarName);
GrAssert(kNone_GrSLConstantVec != mulFactorDefault || haveFactor);
-
+
if (!haveFactor) {
if (kOnes_GrSLConstantVec == mulFactorDefault) {
return kNone_GrSLConstantVec;
@@ -172,31 +124,24 @@
return kNone_GrSLConstantVec;
}
-GrSLConstantVec GrGLSLAdd4f(SkString* outAppend,
- const char* in0,
- const char* in1,
- GrSLConstantVec default0,
- GrSLConstantVec default1) {
- GrAssert(NULL != outAppend);
-
- bool has0 = NULL != in0 && '\0' != *in0;
- bool has1 = NULL != in1 && '\0' != *in1;
-
- if (!has0 && !has1) {
- GrAssert(kZeros_GrSLConstantVec == default0);
- GrAssert(kZeros_GrSLConstantVec == default1);
- outAppend->append(GrGLSLZerosVecf(4));
- return kZeros_GrSLConstantVec;
- } else if (!has0) {
- GrAssert(kZeros_GrSLConstantVec == default0);
- outAppend->appendf("vec4(%s)", in1);
- return kNone_GrSLConstantVec;
- } else if (!has1) {
- GrAssert(kZeros_GrSLConstantVec == default1);
- outAppend->appendf("vec4(%s)", in0);
- return kNone_GrSLConstantVec;
+GrSLConstantVec GrGLSLGetComponent4f(SkString* outAppend,
+ const char* expr,
+ GrColorComponentFlags component,
+ GrSLConstantVec defaultExpr,
+ bool omitIfConst) {
+ if (NULL == expr || '\0' == *expr) {
+ GrAssert(defaultExpr != kNone_GrSLConstantVec);
+ if (!omitIfConst) {
+ if (kOnes_GrSLConstantVec == defaultExpr) {
+ outAppend->append("1.0");
+ } else {
+ GrAssert(kZeros_GrSLConstantVec == defaultExpr);
+ outAppend->append("0.0");
+ }
+ }
+ return defaultExpr;
} else {
- outAppend->appendf("(vec4(%s) + vec4(%s))", in0, in1);
+ outAppend->appendf("(%s).%c", expr, GrColorComponentFlagToChar(component));
return kNone_GrSLConstantVec;
}
}
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698