• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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 "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
9 
10 #include "include/gpu/GrTypes.h"
11 #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
12 #include "src/gpu/glsl/GrGLSLVarying.h"
13 
emitNormalizedSkPosition(SkString * out,const char * devPos,GrSLType devPosType)14 void GrGLSLVertexGeoBuilder::emitNormalizedSkPosition(SkString* out, const char* devPos,
15                                                       GrSLType devPosType) {
16     if (this->getProgramBuilder()->snapVerticesToPixelCenters()) {
17         if (kFloat3_GrSLType == devPosType) {
18             const char* p = devPos;
19             out->appendf("{float2 _posTmp = %s.xy / %s.z;", p, p);
20         } else {
21             SkASSERT(kFloat2_GrSLType == devPosType);
22             out->appendf("{float2 _posTmp = %s;", devPos);
23         }
24         out->appendf("_posTmp = floor(_posTmp) + float2(0.5);"
25                      "sk_Position = _posTmp.xy01;}");
26     } else if (kFloat3_GrSLType == devPosType) {
27         out->appendf("sk_Position = %s.xy0z;", devPos);
28     } else {
29         SkASSERT(kFloat2_GrSLType == devPosType);
30         out->appendf("sk_Position = %s.xy01;", devPos);
31     }
32 }
33 
onFinalize()34 void GrGLSLVertexBuilder::onFinalize() {
35     // We could have the GrGeometryProcessor do this, but its just easier to have it performed
36     // here. If we ever need to set variable pointsize, then we can reinvestigate.
37     if (this->getProgramBuilder()->hasPointSize()) {
38         this->codeAppend("sk_PointSize = 1.0;");
39     }
40     fProgramBuilder->varyingHandler()->getVertexDecls(&this->inputs(), &this->outputs());
41 }
42