• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrGLSLPrimitiveProcessor.h"
9 
10 #include "GrCoordTransform.h"
11 #include "GrTexture.h"
12 #include "glsl/GrGLSLFragmentShaderBuilder.h"
13 #include "glsl/GrGLSLProgramBuilder.h"
14 #include "glsl/GrGLSLUniformHandler.h"
15 #include "glsl/GrGLSLVertexShaderBuilder.h"
16 
GetTransformMatrix(const SkMatrix & localMatrix,const GrCoordTransform & coordTransform)17 SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
18                                                       const GrCoordTransform& coordTransform) {
19     SkMatrix combined;
20     combined.setConcat(coordTransform.getMatrix(), localMatrix);
21     if (coordTransform.normalize()) {
22         combined.postIDiv(coordTransform.peekTexture()->width(),
23                           coordTransform.peekTexture()->height());
24     }
25 
26     if (coordTransform.reverseY()) {
27         // combined.postScale(1,-1);
28         // combined.postTranslate(0,1);
29         combined.set(SkMatrix::kMSkewY,
30             combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
31         combined.set(SkMatrix::kMScaleY,
32             combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
33         combined.set(SkMatrix::kMTransY,
34             combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
35     }
36     return combined;
37 }
38 
setupUniformColor(GrGLSLPPFragmentBuilder * fragBuilder,GrGLSLUniformHandler * uniformHandler,const char * outputName,UniformHandle * colorUniform)39 void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
40                                                  GrGLSLUniformHandler* uniformHandler,
41                                                  const char* outputName,
42                                                  UniformHandle* colorUniform) {
43     SkASSERT(colorUniform);
44     const char* stagedLocalVarName;
45     *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
46                                                kVec4f_GrSLType,
47                                                kDefault_GrSLPrecision,
48                                                "Color",
49                                                &stagedLocalVarName);
50     fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
51     if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) {
52         fragBuilder->codeAppendf("%s = max(%s, vec4(0, 0, 0, 0));", outputName, outputName);
53     }
54 }
55 
56 //////////////////////////////////////////////////////////////////////////////
57 
nextCoordTransform()58 const GrCoordTransform* GrGLSLPrimitiveProcessor::FPCoordTransformHandler::nextCoordTransform() {
59 #ifdef SK_DEBUG
60     SkASSERT(nullptr == fCurr || fAddedCoord);
61     fAddedCoord = false;
62     fCurr = fIter.next();
63     return fCurr;
64 #else
65     return fIter.next();
66 #endif
67 }
68