blob: 70b58cda94f2d85a747dd3dd32d0f73273d83522 [file] [log] [blame]
joshualitt8072caa2015-02-12 14:20:52 -08001/*
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
egdaniele659a582015-11-13 09:55:43 -08008#include "GrGLSLPrimitiveProcessor.h"
joshualitt8072caa2015-02-12 14:20:52 -08009
egdaniel2d721d32015-11-11 13:06:05 -080010#include "glsl/GrGLSLProgramBuilder.h"
11#include "glsl/GrGLSLFragmentShaderBuilder.h"
joshualitt8072caa2015-02-12 14:20:52 -080012
egdaniele659a582015-11-13 09:55:43 -080013SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
14 const GrCoordTransform& coordTransform) {
joshualitt8072caa2015-02-12 14:20:52 -080015 SkMatrix combined;
16 // We only apply the localmatrix to localcoords
17 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
18 combined.setConcat(coordTransform.getMatrix(), localMatrix);
19 } else {
20 combined = coordTransform.getMatrix();
21 }
22 if (coordTransform.reverseY()) {
23 // combined.postScale(1,-1);
24 // combined.postTranslate(0,1);
25 combined.set(SkMatrix::kMSkewY,
26 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
27 combined.set(SkMatrix::kMScaleY,
28 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
29 combined.set(SkMatrix::kMTransY,
30 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
31 }
32 return combined;
33}
34
egdaniele659a582015-11-13 09:55:43 -080035void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLGPBuilder* pb,
egdaniel4ca2e602015-11-18 08:01:26 -080036 GrGLSLFragmentBuilder* fragBuilder,
egdaniele659a582015-11-13 09:55:43 -080037 const char* outputName,
38 UniformHandle* colorUniform) {
joshualittb8c241a2015-05-19 08:23:30 -070039 SkASSERT(colorUniform);
40 const char* stagedLocalVarName;
egdaniel2d721d32015-11-11 13:06:05 -080041 *colorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
joshualittb8c241a2015-05-19 08:23:30 -070042 kVec4f_GrSLType,
43 kDefault_GrSLPrecision,
44 "Color",
45 &stagedLocalVarName);
egdaniel4ca2e602015-11-18 08:01:26 -080046 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
joshualitt8072caa2015-02-12 14:20:52 -080047}