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

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 678953002: Default geometry processor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix dm bug Created 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "gl/builders/GrGLProgramBuilder.h" 10 #include "gl/builders/GrGLProgramBuilder.h"
11 #include "gl/GrGLProcessor.h" 11 #include "gl/GrGLProcessor.h"
12 #include "gl/GrGLGeometryProcessor.h" 12 #include "gl/GrGLGeometryProcessor.h"
13 #include "GrTBackendProcessorFactory.h" 13 #include "GrTBackendProcessorFactory.h"
14 #include "SkColorPriv.h" 14 #include "SkColorPriv.h"
15 #include "GrGeometryProcessor.h" 15 #include "GrGeometryProcessor.h"
16 16
17 /////////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////////
18 class GrGLAlignedRectEffect; 18 class GrGLAlignedRectEffect;
19 19
20 // Axis Aligned special case 20 // Axis Aligned special case
21 class GrAlignedRectEffect : public GrGeometryProcessor { 21 class GrAlignedRectEffect : public GrGeometryProcessor {
bsalomon 2014/10/27 13:43:43 Why don't we just delete these unused effects (sep
22 public: 22 public:
23 static GrGeometryProcessor* Create() { 23 static GrGeometryProcessor* Create() {
24 GR_CREATE_STATIC_PROCESSOR(gAlignedRectEffect, GrAlignedRectEffect, ()); 24 GR_CREATE_STATIC_PROCESSOR(gAlignedRectEffect, GrAlignedRectEffect, ());
25 gAlignedRectEffect->ref(); 25 gAlignedRectEffect->ref();
26 return gAlignedRectEffect; 26 return gAlignedRectEffect;
27 } 27 }
28 28
29 virtual ~GrAlignedRectEffect() {} 29 virtual ~GrAlignedRectEffect() {}
30 30
31 static const char* Name() { return "AlignedRectEdge"; } 31 static const char* Name() { return "AlignedRectEdge"; }
(...skipping 13 matching lines...) Expand all
45 // setup the varying for the Axis aligned rect effect 45 // setup the varying for the Axis aligned rect effect
46 // xy -> interpolated offset 46 // xy -> interpolated offset
47 // zw -> w/2+0.5, h/2+0.5 47 // zw -> w/2+0.5, h/2+0.5
48 GrGLVertToFrag v(kVec4f_GrSLType); 48 GrGLVertToFrag v(kVec4f_GrSLType);
49 args.fPB->addVarying("Rect", &v); 49 args.fPB->addVarying("Rect", &v);
50 50
51 const GrShaderVar& inRect = args.fGP.cast<GrAlignedRectEffect>().inR ect(); 51 const GrShaderVar& inRect = args.fGP.cast<GrAlignedRectEffect>().inR ect();
52 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 52 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
53 vsBuilder->codeAppendf("\t%s = %s;\n", v.fsIn(), inRect.c_str()); 53 vsBuilder->codeAppendf("\t%s = %s;\n", v.fsIn(), inRect.c_str());
54 54
55 // setup position varying
56 vsBuilder->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", args.fGP.uVi ewM(),
57 args.fGP.inPosition());
58 vsBuilder->transformPositionToDeviceSpace("pos3");
59
55 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r(); 60 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
56 // TODO: compute all these offsets, spans, and scales in the VS 61 // TODO: compute all these offsets, spans, and scales in the VS
57 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", v .fsIn()); 62 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", v .fsIn());
58 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", v .fsIn()); 63 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", v .fsIn());
59 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 64 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
60 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 65 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
61 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 66 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
62 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 67 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
63 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 68 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
64 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 69 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 175 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
171 vsBuilder->codeAppendf("%s = %s;", rectEdge.vsOut(), rectEffect.inRe ctEdge().c_str()); 176 vsBuilder->codeAppendf("%s = %s;", rectEdge.vsOut(), rectEffect.inRe ctEdge().c_str());
172 177
173 // setup the varying for width/2+.5 and height/2+.5 178 // setup the varying for width/2+.5 and height/2+.5
174 GrGLVertToFrag widthHeight(kVec2f_GrSLType); 179 GrGLVertToFrag widthHeight(kVec2f_GrSLType);
175 args.fPB->addVarying("WidthHeight", &widthHeight); 180 args.fPB->addVarying("WidthHeight", &widthHeight);
176 vsBuilder->codeAppendf("%s = %s;", 181 vsBuilder->codeAppendf("%s = %s;",
177 widthHeight.vsOut(), 182 widthHeight.vsOut(),
178 rectEffect.inWidthHeight().c_str()); 183 rectEffect.inWidthHeight().c_str());
179 184
185 // setup position varying
186 vsBuilder->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", args.fGP.uVi ewM(),
187 args.fGP.inPosition());
188 vsBuilder->transformPositionToDeviceSpace("pos3");
189
180 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r(); 190 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
181 // TODO: compute all these offsets, spans, and scales in the VS 191 // TODO: compute all these offsets, spans, and scales in the VS
182 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", w idthHeight.fsIn()); 192 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", w idthHeight.fsIn());
183 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", w idthHeight.fsIn()); 193 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", w idthHeight.fsIn());
184 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 194 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
185 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 195 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
186 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 196 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
187 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 197 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
188 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 198 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
189 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 199 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 // can't call mapRect for devInside since it calls sort 926 // can't call mapRect for devInside since it calls sort
917 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 927 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
918 928
919 if (devInside.isEmpty()) { 929 if (devInside.isEmpty()) {
920 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); 930 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside);
921 return; 931 return;
922 } 932 }
923 933
924 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true); 934 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true);
925 } 935 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698