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

Side by Side Diff: src/gpu/gl/GrGLXferProcessor.cpp

Issue 1440073002: Move XferProcessors to glsl (Closed) Base URL: https://skia.googlesource.com/skia.git@fragProcs
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « src/gpu/gl/GrGLXferProcessor.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gl/GrGLXferProcessor.h"
9
10 #include "GrXferProcessor.h"
11 #include "glsl/GrGLSLFragmentShaderBuilder.h"
12 #include "glsl/GrGLSLProgramBuilder.h"
13 #include "glsl/GrGLSLProgramDataManager.h"
14
15 void GrGLXferProcessor::emitCode(const EmitArgs& args) {
16 if (!args.fXP.willReadDstColor()) {
17 this->emitOutputsForBlendState(args);
18 return;
19 }
20
21 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
22 const char* dstColor = fsBuilder->dstColor();
23
24 if (args.fXP.getDstTexture()) {
25 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori gin();
26
27 if (args.fXP.readsCoverage()) {
28 // We don't think any shaders actually output negative coverage, but just as a safety
29 // check for floating point precision errors we compare with <= here
30 fsBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {"
31 " discard;"
32 "}", args.fInputCoverage);
33 }
34
35 const char* dstTopLeftName;
36 const char* dstCoordScaleName;
37
38 fDstTopLeftUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Vi sibility,
39 kVec2f_GrSLType,
40 kDefault_GrSLPrecision,
41 "DstTextureUpperLeft",
42 &dstTopLeftName);
43 fDstScaleUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Visi bility,
44 kVec2f_GrSLType,
45 kDefault_GrSLPrecision,
46 "DstTextureCoordScale",
47 &dstCoordScaleName);
48 const char* fragPos = fsBuilder->fragmentPosition();
49
50 fsBuilder->codeAppend("// Read color from copy of the destination.\n");
51 fsBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;",
52 fragPos, dstTopLeftName, dstCoordScaleName);
53
54 if (!topDown) {
55 fsBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;");
56 }
57
58 fsBuilder->codeAppendf("vec4 %s = ", dstColor);
59 fsBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec2f _GrSLType);
60 fsBuilder->codeAppend(";");
61 }
62
63 this->emitBlendCodeForDstRead(args.fPB, args.fInputColor, dstColor, args.fOu tputPrimary,
64 args.fXP);
65
66 // Apply coverage.
67 if (args.fXP.dstReadUsesMixedSamples()) {
68 if (args.fXP.readsCoverage()) {
69 fsBuilder->codeAppendf("%s *= %s;", args.fOutputPrimary, args.fInput Coverage);
70 fsBuilder->codeAppendf("%s = %s;", args.fOutputSecondary, args.fInpu tCoverage);
71 } else {
72 fsBuilder->codeAppendf("%s = vec4(1.0);", args.fOutputSecondary);
73 }
74 } else if (args.fXP.readsCoverage()) {
75 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;",
76 args.fOutputPrimary, args.fInputCoverage,
77 args.fOutputPrimary, args.fInputCoverage, dstColo r);
78 }
79 }
80
81 void GrGLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrXfe rProcessor& xp) {
82 if (xp.getDstTexture()) {
83 if (fDstTopLeftUni.isValid()) {
84 pdm.set2f(fDstTopLeftUni, static_cast<float>(xp.dstTextureOffset().f X),
85 static_cast<float>(xp.dstTextureOffset().fY));
86 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(),
87 1.f / xp.getDstTexture()->height());
88 } else {
89 SkASSERT(!fDstScaleUni.isValid());
90 }
91 } else {
92 SkASSERT(!fDstTopLeftUni.isValid());
93 SkASSERT(!fDstScaleUni.isValid());
94 }
95 this->onSetData(pdm, xp);
96 }
97
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLXferProcessor.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698