blob: d9d17e53564ce4455229dc23ecf080b90553caf8 [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"
Robert Phillips646e4292017-06-13 12:44:56 -040011#include "GrTexture.h"
egdaniel2d721d32015-11-11 13:06:05 -080012#include "glsl/GrGLSLFragmentShaderBuilder.h"
Brian Osmanac1e4962017-05-25 11:34:38 -040013#include "glsl/GrGLSLProgramBuilder.h"
egdaniel7ea439b2015-12-03 09:20:44 -080014#include "glsl/GrGLSLUniformHandler.h"
15#include "glsl/GrGLSLVertexShaderBuilder.h"
joshualitt8072caa2015-02-12 14:20:52 -080016
egdaniele659a582015-11-13 09:55:43 -080017SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
18 const GrCoordTransform& coordTransform) {
joshualitt8072caa2015-02-12 14:20:52 -080019 SkMatrix combined;
Brian Salomon2ebd0c82016-10-03 17:15:28 -040020 combined.setConcat(coordTransform.getMatrix(), localMatrix);
Robert Phillips67c18d62017-01-20 12:44:06 -050021 if (coordTransform.normalize()) {
Robert Phillips18166ee2017-06-01 12:55:44 -040022 combined.postIDiv(coordTransform.peekTexture()->width(),
23 coordTransform.peekTexture()->height());
Robert Phillips67c18d62017-01-20 12:44:06 -050024 }
25
joshualitt8072caa2015-02-12 14:20:52 -080026 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
cdalton85285412016-02-18 12:37:07 -080039void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
egdaniel7ea439b2015-12-03 09:20:44 -080040 GrGLSLUniformHandler* uniformHandler,
egdaniele659a582015-11-13 09:55:43 -080041 const char* outputName,
42 UniformHandle* colorUniform) {
joshualittb8c241a2015-05-19 08:23:30 -070043 SkASSERT(colorUniform);
44 const char* stagedLocalVarName;
cdalton5e58cee2016-02-11 12:49:47 -080045 *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
Brian Salomon1d816b92017-08-17 11:07:59 -040046 kVec4f_GrSLType,
47 kDefault_GrSLPrecision,
egdaniel7ea439b2015-12-03 09:20:44 -080048 "Color",
49 &stagedLocalVarName);
egdaniel4ca2e602015-11-18 08:01:26 -080050 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
Brian Osmanac1e4962017-05-25 11:34:38 -040051 if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) {
Brian Salomon1d816b92017-08-17 11:07:59 -040052 fragBuilder->codeAppendf("%s = max(%s, float4(0, 0, 0, 0));", outputName, outputName);
Brian Osmanac1e4962017-05-25 11:34:38 -040053 }
joshualitt8072caa2015-02-12 14:20:52 -080054}
bsalomona624bf32016-09-20 09:12:47 -070055
56//////////////////////////////////////////////////////////////////////////////
57
58const 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}