blob: 0cb7e4d541ae08625328fd59cdcbe17e7f4a8915 [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,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040046 kHalf4_GrSLType,
egdaniel7ea439b2015-12-03 09:20:44 -080047 "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()) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051 fragBuilder->codeAppendf("%s = max(%s, half4(0, 0, 0, 0));", outputName, outputName);
Brian Osmanac1e4962017-05-25 11:34:38 -040052 }
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}