blob: 23bb249af7aea5e0cab141477288ee931a7874af [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
egdaniel7ea439b2015-12-03 09:20:44 -080010#include "GrCoordTransform.h"
egdaniel2d721d32015-11-11 13:06:05 -080011#include "glsl/GrGLSLFragmentShaderBuilder.h"
egdaniel7ea439b2015-12-03 09:20:44 -080012#include "glsl/GrGLSLUniformHandler.h"
13#include "glsl/GrGLSLVertexShaderBuilder.h"
joshualitt8072caa2015-02-12 14:20:52 -080014
egdaniele659a582015-11-13 09:55:43 -080015SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
16 const GrCoordTransform& coordTransform) {
joshualitt8072caa2015-02-12 14:20:52 -080017 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
egdaniel7ea439b2015-12-03 09:20:44 -080037void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLFragmentBuilder* fragBuilder,
38 GrGLSLUniformHandler* uniformHandler,
egdaniele659a582015-11-13 09:55:43 -080039 const char* outputName,
40 UniformHandle* colorUniform) {
joshualittb8c241a2015-05-19 08:23:30 -070041 SkASSERT(colorUniform);
42 const char* stagedLocalVarName;
egdaniel7ea439b2015-12-03 09:20:44 -080043 *colorUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
44 kVec4f_GrSLType,
45 kDefault_GrSLPrecision,
46 "Color",
47 &stagedLocalVarName);
egdaniel4ca2e602015-11-18 08:01:26 -080048 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
joshualitt8072caa2015-02-12 14:20:52 -080049}