blob: 24f21ffe7a77b09e077a99c5bf548c32c28fdb36 [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;
Brian Salomon2ebd0c82016-10-03 17:15:28 -040018 combined.setConcat(coordTransform.getMatrix(), localMatrix);
joshualitt8072caa2015-02-12 14:20:52 -080019 if (coordTransform.reverseY()) {
20 // combined.postScale(1,-1);
21 // combined.postTranslate(0,1);
22 combined.set(SkMatrix::kMSkewY,
23 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
24 combined.set(SkMatrix::kMScaleY,
25 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
26 combined.set(SkMatrix::kMTransY,
27 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
28 }
29 return combined;
30}
31
cdalton85285412016-02-18 12:37:07 -080032void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
egdaniel7ea439b2015-12-03 09:20:44 -080033 GrGLSLUniformHandler* uniformHandler,
egdaniele659a582015-11-13 09:55:43 -080034 const char* outputName,
35 UniformHandle* colorUniform) {
joshualittb8c241a2015-05-19 08:23:30 -070036 SkASSERT(colorUniform);
37 const char* stagedLocalVarName;
cdalton5e58cee2016-02-11 12:49:47 -080038 *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
egdaniel7ea439b2015-12-03 09:20:44 -080039 kVec4f_GrSLType,
40 kDefault_GrSLPrecision,
41 "Color",
42 &stagedLocalVarName);
egdaniel4ca2e602015-11-18 08:01:26 -080043 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
joshualitt8072caa2015-02-12 14:20:52 -080044}
bsalomona624bf32016-09-20 09:12:47 -070045
46//////////////////////////////////////////////////////////////////////////////
47
48const GrCoordTransform* GrGLSLPrimitiveProcessor::FPCoordTransformHandler::nextCoordTransform() {
49#ifdef SK_DEBUG
50 SkASSERT(nullptr == fCurr || fAddedCoord);
51 fAddedCoord = false;
52 fCurr = fIter.next();
53 return fCurr;
54#else
55 return fIter.next();
56#endif
57}