blob: 8e6099e87de5692abeb4a38be9a78ff476685778 [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"
Chris Daltonc17bf322017-10-24 10:59:03 -060015#include "glsl/GrGLSLVertexGeoBuilder.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()) {
Brian Salomon10273c12018-12-04 12:34:41 -050027 if (coordTransform.normalize()) {
28 // combined.postScale(1,-1);
29 // combined.postTranslate(0,1);
30 combined.set(SkMatrix::kMSkewY,
31 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
32 combined.set(SkMatrix::kMScaleY,
33 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
34 combined.set(SkMatrix::kMTransY,
35 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
36 } else {
37 // combined.postScale(1, -1);
38 // combined.postTranslate(0,1);
39 SkScalar h = coordTransform.peekTexture()->height();
40 combined.set(SkMatrix::kMSkewY,
41 h * combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
42 combined.set(SkMatrix::kMScaleY,
43 h * combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
44 combined.set(SkMatrix::kMTransY,
45 h * combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
46 }
joshualitt8072caa2015-02-12 14:20:52 -080047 }
48 return combined;
49}
50
Chris Dalton60283612018-02-14 13:38:14 -070051void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLFPFragmentBuilder* fragBuilder,
egdaniel7ea439b2015-12-03 09:20:44 -080052 GrGLSLUniformHandler* uniformHandler,
egdaniele659a582015-11-13 09:55:43 -080053 const char* outputName,
54 UniformHandle* colorUniform) {
joshualittb8c241a2015-05-19 08:23:30 -070055 SkASSERT(colorUniform);
56 const char* stagedLocalVarName;
cdalton5e58cee2016-02-11 12:49:47 -080057 *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040058 kHalf4_GrSLType,
egdaniel7ea439b2015-12-03 09:20:44 -080059 "Color",
60 &stagedLocalVarName);
egdaniel4ca2e602015-11-18 08:01:26 -080061 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
Brian Osmanac1e4962017-05-25 11:34:38 -040062 if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -040063 fragBuilder->codeAppendf("%s = max(%s, half4(0, 0, 0, 0));", outputName, outputName);
Brian Osmanac1e4962017-05-25 11:34:38 -040064 }
joshualitt8072caa2015-02-12 14:20:52 -080065}
bsalomona624bf32016-09-20 09:12:47 -070066
67//////////////////////////////////////////////////////////////////////////////
68
69const GrCoordTransform* GrGLSLPrimitiveProcessor::FPCoordTransformHandler::nextCoordTransform() {
70#ifdef SK_DEBUG
71 SkASSERT(nullptr == fCurr || fAddedCoord);
72 fAddedCoord = false;
73 fCurr = fIter.next();
74 return fCurr;
75#else
76 return fIter.next();
77#endif
78}