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

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

Issue 1170553002: Apply coverage in XP base class when using dst reads (Closed) Base URL: https://skia.googlesource.com/skia.git@upload2_reenablebea
Patch Set: names Created 5 years, 6 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
« no previous file with comments | « src/gpu/gl/GrGLXferProcessor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 #include "gl/GrGLXferProcessor.h" 8 #include "gl/GrGLXferProcessor.h"
9 9
10 #include "GrXferProcessor.h" 10 #include "GrXferProcessor.h"
11 #include "gl/builders/GrGLFragmentShaderBuilder.h" 11 #include "gl/builders/GrGLFragmentShaderBuilder.h"
12 #include "gl/builders/GrGLProgramBuilder.h" 12 #include "gl/builders/GrGLProgramBuilder.h"
13 13
14 void GrGLXferProcessor::emitCode(const EmitArgs& args) { 14 void GrGLXferProcessor::emitCode(const EmitArgs& args) {
15 if (!args.fXP.willReadDstColor()) {
16 this->emitOutputsForBlendState(args);
17 return;
18 }
19
20 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
21 const char* dstColor = fsBuilder->dstColor();
22
15 if (args.fXP.getDstTexture()) { 23 if (args.fXP.getDstTexture()) {
16 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori gin(); 24 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori gin();
17 25
18 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
19
20 if (args.fXP.readsCoverage()) { 26 if (args.fXP.readsCoverage()) {
21 // We don't think any shaders actually output negative coverage, but just as a safety 27 // We don't think any shaders actually output negative coverage, but just as a safety
22 // check for floating point precision errors we compare with <= here 28 // check for floating point precision errors we compare with <= here
23 fsBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {" 29 fsBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {"
24 " discard;" 30 " discard;"
25 "}", args.fInputCoverage); 31 "}", args.fInputCoverage);
26 } 32 }
27 33
28 const char* dstColor = fsBuilder->dstColor();
29
30 const char* dstTopLeftName; 34 const char* dstTopLeftName;
31 const char* dstCoordScaleName; 35 const char* dstCoordScaleName;
32 36
33 fDstTopLeftUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visi bility, 37 fDstTopLeftUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visi bility,
34 kVec2f_GrSLType, 38 kVec2f_GrSLType,
35 kDefault_GrSLPrecision, 39 kDefault_GrSLPrecision,
36 "DstTextureUpperLeft", 40 "DstTextureUpperLeft",
37 &dstTopLeftName); 41 &dstTopLeftName);
38 fDstScaleUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi lity, 42 fDstScaleUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi lity,
39 kVec2f_GrSLType, 43 kVec2f_GrSLType,
40 kDefault_GrSLPrecision, 44 kDefault_GrSLPrecision,
41 "DstTextureCoordScale", 45 "DstTextureCoordScale",
42 &dstCoordScaleName); 46 &dstCoordScaleName);
43 const char* fragPos = fsBuilder->fragmentPosition(); 47 const char* fragPos = fsBuilder->fragmentPosition();
44 48
45 fsBuilder->codeAppend("// Read color from copy of the destination.\n"); 49 fsBuilder->codeAppend("// Read color from copy of the destination.\n");
46 fsBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", 50 fsBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;",
47 fragPos, dstTopLeftName, dstCoordScaleName); 51 fragPos, dstTopLeftName, dstCoordScaleName);
48 52
49 if (!topDown) { 53 if (!topDown) {
50 fsBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); 54 fsBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;");
51 } 55 }
52 56
53 fsBuilder->codeAppendf("vec4 %s = ", dstColor); 57 fsBuilder->codeAppendf("vec4 %s = ", dstColor);
54 fsBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec2f _GrSLType); 58 fsBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec2f _GrSLType);
55 fsBuilder->codeAppend(";"); 59 fsBuilder->codeAppend(";");
56 } 60 }
57 61
58 this->onEmitCode(args); 62 this->emitBlendCodeForDstRead(args.fPB, args.fInputColor, dstColor, args.fOu tputPrimary,
63 args.fXP);
64
65 // Apply coverage.
66 if (args.fXP.readsCoverage()) {
67 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;",
68 args.fOutputPrimary, args.fInputCoverage,
69 args.fOutputPrimary, args.fInputCoverage, dstColo r);
70 }
59 } 71 }
60 72
61 void GrGLXferProcessor::setData(const GrGLProgramDataManager& pdm, const GrXferP rocessor& xp) { 73 void GrGLXferProcessor::setData(const GrGLProgramDataManager& pdm, const GrXferP rocessor& xp) {
62 if (xp.getDstTexture()) { 74 if (xp.getDstTexture()) {
63 if (fDstTopLeftUni.isValid()) { 75 if (fDstTopLeftUni.isValid()) {
64 pdm.set2f(fDstTopLeftUni, static_cast<GrGLfloat>(xp.dstTextureOffset ().fX), 76 pdm.set2f(fDstTopLeftUni, static_cast<GrGLfloat>(xp.dstTextureOffset ().fX),
65 static_cast<GrGLfloat>(xp.dstTextureOffset().fY)); 77 static_cast<GrGLfloat>(xp.dstTextureOffset().fY));
66 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(), 78 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(),
67 1.f / xp.getDstTexture()->height()); 79 1.f / xp.getDstTexture()->height());
68 } else { 80 } else {
69 SkASSERT(!fDstScaleUni.isValid()); 81 SkASSERT(!fDstScaleUni.isValid());
70 } 82 }
71 } else { 83 } else {
72 SkASSERT(!fDstTopLeftUni.isValid()); 84 SkASSERT(!fDstTopLeftUni.isValid());
73 SkASSERT(!fDstScaleUni.isValid()); 85 SkASSERT(!fDstScaleUni.isValid());
74 } 86 }
75 this->onSetData(pdm, xp); 87 this->onSetData(pdm, xp);
76 } 88 }
77 89
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLXferProcessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698