Line data Source code
1 : /*
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 :
8 : #include "GrGLSLPrimitiveProcessor.h"
9 :
10 : #include "GrCoordTransform.h"
11 : #include "glsl/GrGLSLFragmentShaderBuilder.h"
12 : #include "glsl/GrGLSLUniformHandler.h"
13 : #include "glsl/GrGLSLVertexShaderBuilder.h"
14 :
15 0 : SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
16 : const GrCoordTransform& coordTransform) {
17 : SkMatrix combined;
18 0 : combined.setConcat(coordTransform.getMatrix(), localMatrix);
19 0 : if (coordTransform.normalize()) {
20 0 : SkASSERT(coordTransform.texture());
21 0 : combined.postIDiv(coordTransform.texture()->width(), coordTransform.texture()->height());
22 : }
23 :
24 0 : if (coordTransform.reverseY()) {
25 : // combined.postScale(1,-1);
26 : // combined.postTranslate(0,1);
27 0 : combined.set(SkMatrix::kMSkewY,
28 0 : combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
29 0 : combined.set(SkMatrix::kMScaleY,
30 0 : combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
31 0 : combined.set(SkMatrix::kMTransY,
32 0 : combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
33 : }
34 0 : return combined;
35 : }
36 :
37 0 : void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
38 : GrGLSLUniformHandler* uniformHandler,
39 : const char* outputName,
40 : UniformHandle* colorUniform) {
41 0 : SkASSERT(colorUniform);
42 : const char* stagedLocalVarName;
43 : *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
44 : kVec4f_GrSLType,
45 : kDefault_GrSLPrecision,
46 : "Color",
47 0 : &stagedLocalVarName);
48 0 : fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
49 0 : }
50 :
51 : //////////////////////////////////////////////////////////////////////////////
52 :
53 0 : const GrCoordTransform* GrGLSLPrimitiveProcessor::FPCoordTransformHandler::nextCoordTransform() {
54 : #ifdef SK_DEBUG
55 0 : SkASSERT(nullptr == fCurr || fAddedCoord);
56 0 : fAddedCoord = false;
57 0 : fCurr = fIter.next();
58 0 : return fCurr;
59 : #else
60 : return fIter.next();
61 : #endif
62 : }
|