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

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

Issue 1254833003: Added GrGLBlend.h|cpp with helper function AppendPorterDuffBlend() in preparation for SkComposeShad… (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Fixed nits suggested by Greg Created 5 years, 5 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/GrGLBlend.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLBlend.cpp
diff --git a/src/gpu/gl/GrGLBlend.cpp b/src/gpu/gl/GrGLBlend.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0189fd446f26573ab2cd4c8270d2e0b7afe08d7a
--- /dev/null
+++ b/src/gpu/gl/GrGLBlend.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "GrGLBlend.h"
+#include "gl/builders/GrGLFragmentShaderBuilder.h"
+
+static bool append_porterduff_term(GrGLFragmentBuilder* fsBuilder, SkXfermode::Coeff coeff,
+ const char* colorName, const char* srcColorName,
+ const char* dstColorName, bool hasPrevious) {
+ if (SkXfermode::kZero_Coeff == coeff) {
+ return hasPrevious;
+ } else {
+ if (hasPrevious) {
+ fsBuilder->codeAppend(" + ");
+ }
+ fsBuilder->codeAppendf("%s", colorName);
+ switch (coeff) {
+ case SkXfermode::kOne_Coeff:
+ break;
+ case SkXfermode::kSC_Coeff:
+ fsBuilder->codeAppendf(" * %s", srcColorName);
+ break;
+ case SkXfermode::kISC_Coeff:
+ fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", srcColorName);
+ break;
+ case SkXfermode::kDC_Coeff:
+ fsBuilder->codeAppendf(" * %s", dstColorName);
+ break;
+ case SkXfermode::kIDC_Coeff:
+ fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", dstColorName);
+ break;
+ case SkXfermode::kSA_Coeff:
+ fsBuilder->codeAppendf(" * %s.a", srcColorName);
+ break;
+ case SkXfermode::kISA_Coeff:
+ fsBuilder->codeAppendf(" * (1.0 - %s.a)", srcColorName);
+ break;
+ case SkXfermode::kDA_Coeff:
+ fsBuilder->codeAppendf(" * %s.a", dstColorName);
+ break;
+ case SkXfermode::kIDA_Coeff:
+ fsBuilder->codeAppendf(" * (1.0 - %s.a)", dstColorName);
+ break;
+ default:
+ SkFAIL("Unsupported Blend Coeff");
+ }
+ return true;
+ }
+}
+
+void GrGLBlend::AppendPorterDuffBlend(GrGLFragmentBuilder* fsBuilder, const char* srcColor,
+ const char* dstColor, const char* outColor, SkXfermode::Mode mode) {
egdaniel 2015/07/24 20:21:42 I josh want you to align the parameters here. The
wangyix 2015/07/24 20:37:16 Done.
+
+ SkXfermode::Coeff srcCoeff, dstCoeff;
+ SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff);
+
+ fsBuilder->codeAppendf("%s =", outColor);
+ // append src blend
+ bool didAppend = append_porterduff_term(fsBuilder, srcCoeff,
+ srcColor, srcColor,
egdaniel 2015/07/24 20:21:42 These actually looked nicer your original way imo.
wangyix 2015/07/24 20:37:16 Done.
+ dstColor, false);
+ // append dst blend
+ SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff,
+ dstColor, srcColor,
+ dstColor, didAppend));
+ fsBuilder->codeAppend(";");
+}
« no previous file with comments | « src/gpu/gl/GrGLBlend.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698