blob: d32766c3fcc9229bfcfee4766a9c45d8ec19be9a [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"
Brian Osmanac1e4962017-05-25 11:34:38 -040012#include "glsl/GrGLSLProgramBuilder.h"
egdaniel7ea439b2015-12-03 09:20:44 -080013#include "glsl/GrGLSLUniformHandler.h"
14#include "glsl/GrGLSLVertexShaderBuilder.h"
joshualitt8072caa2015-02-12 14:20:52 -080015
egdaniele659a582015-11-13 09:55:43 -080016SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
17 const GrCoordTransform& coordTransform) {
joshualitt8072caa2015-02-12 14:20:52 -080018 SkMatrix combined;
Brian Salomon2ebd0c82016-10-03 17:15:28 -040019 combined.setConcat(coordTransform.getMatrix(), localMatrix);
Robert Phillips67c18d62017-01-20 12:44:06 -050020 if (coordTransform.normalize()) {
21 SkASSERT(coordTransform.texture());
22 combined.postIDiv(coordTransform.texture()->width(), coordTransform.texture()->height());
23 }
24
joshualitt8072caa2015-02-12 14:20:52 -080025 if (coordTransform.reverseY()) {
26 // combined.postScale(1,-1);
27 // combined.postTranslate(0,1);
28 combined.set(SkMatrix::kMSkewY,
29 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
30 combined.set(SkMatrix::kMScaleY,
31 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
32 combined.set(SkMatrix::kMTransY,
33 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
34 }
35 return combined;
36}
37
cdalton85285412016-02-18 12:37:07 -080038void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
egdaniel7ea439b2015-12-03 09:20:44 -080039 GrGLSLUniformHandler* uniformHandler,
egdaniele659a582015-11-13 09:55:43 -080040 const char* outputName,
41 UniformHandle* colorUniform) {
joshualittb8c241a2015-05-19 08:23:30 -070042 SkASSERT(colorUniform);
43 const char* stagedLocalVarName;
cdalton5e58cee2016-02-11 12:49:47 -080044 *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
egdaniel7ea439b2015-12-03 09:20:44 -080045 kVec4f_GrSLType,
46 kDefault_GrSLPrecision,
47 "Color",
48 &stagedLocalVarName);
egdaniel4ca2e602015-11-18 08:01:26 -080049 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
Brian Osmanac1e4962017-05-25 11:34:38 -040050 if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) {
51 fragBuilder->codeAppendf("%s = max(%s, vec4(0, 0, 0, 0));", outputName, outputName);
52 }
joshualitt8072caa2015-02-12 14:20:52 -080053}
bsalomona624bf32016-09-20 09:12:47 -070054
55//////////////////////////////////////////////////////////////////////////////
56
57const GrCoordTransform* GrGLSLPrimitiveProcessor::FPCoordTransformHandler::nextCoordTransform() {
58#ifdef SK_DEBUG
59 SkASSERT(nullptr == fCurr || fAddedCoord);
60 fAddedCoord = false;
61 fCurr = fIter.next();
62 return fCurr;
63#else
64 return fIter.next();
65#endif
66}