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 "glsl/GrGLSLFragmentShaderBuilder.h"
12 #include "glsl/GrGLSLUniformHandler.h"
13 #include "glsl/GrGLSLVertexShaderBuilder.h"
14 
GetTransformMatrix(const SkMatrix & localMatrix,const GrCoordTransform & coordTransform)15 SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
16                                                       const GrCoordTransform& coordTransform) {
17     SkMatrix combined;
18     // We only apply the localmatrix to localcoords
19     if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
20         combined.setConcat(coordTransform.getMatrix(), localMatrix);
21     } else {
22         combined = coordTransform.getMatrix();
23     }
24     if (coordTransform.reverseY()) {
25         // combined.postScale(1,-1);
26         // combined.postTranslate(0,1);
27         combined.set(SkMatrix::kMSkewY,
28             combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
29         combined.set(SkMatrix::kMScaleY,
30             combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
31         combined.set(SkMatrix::kMTransY,
32             combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
33     }
34     return combined;
35 }
36 
setupUniformColor(GrGLSLPPFragmentBuilder * fragBuilder,GrGLSLUniformHandler * uniformHandler,const char * outputName,UniformHandle * colorUniform)37 void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
38                                                  GrGLSLUniformHandler* uniformHandler,
39                                                  const char* outputName,
40                                                  UniformHandle* colorUniform) {
41     SkASSERT(colorUniform);
42     const char* stagedLocalVarName;
43     *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
44                                                kVec4f_GrSLType,
45                                                kDefault_GrSLPrecision,
46                                                "Color",
47                                                &stagedLocalVarName);
48     fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
49 }
50