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 "src/gpu/glsl/GrGLSLPrimitiveProcessor.h" |
9 | |
10 | #include "src/gpu/GrCoordTransform.h" |
11 | #include "src/gpu/GrTexture.h" |
12 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
13 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
14 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
15 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" |
16 | |
17 | SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const GrCoordTransform& coordTransform, |
18 | const SkMatrix& preMatrix) { |
19 | SkMatrix combined; |
20 | combined.setConcat(coordTransform.matrix(), preMatrix); |
21 | if (coordTransform.normalize()) { |
22 | SkMatrixPriv::PostIDiv(&combined, coordTransform.peekTexture()->width(), |
23 | coordTransform.peekTexture()->height()); |
24 | } |
25 | |
26 | if (coordTransform.reverseY()) { |
27 | 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 | } |
47 | } |
48 | return combined; |
49 | } |
50 | |
51 | void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLFPFragmentBuilder* fragBuilder, |
52 | GrGLSLUniformHandler* uniformHandler, |
53 | const char* outputName, |
54 | UniformHandle* colorUniform) { |
55 | SkASSERT(colorUniform); |
56 | const char* stagedLocalVarName; |
57 | *colorUniform = uniformHandler->addUniform(nullptr, |
58 | kFragment_GrShaderFlag, |
59 | kHalf4_GrSLType, |
60 | "Color" , |
61 | &stagedLocalVarName); |
62 | fragBuilder->codeAppendf("%s = %s;" , outputName, stagedLocalVarName); |
63 | if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) { |
64 | fragBuilder->codeAppendf("%s = max(%s, half4(0, 0, 0, 0));" , outputName, outputName); |
65 | } |
66 | } |
67 | |
68 | ////////////////////////////////////////////////////////////////////////////// |
69 | |
70 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler::FPCoordTransformHandler( |
71 | const GrPipeline& pipeline, SkTArray<TransformVar>* transformedCoordVars) |
72 | : fIter(pipeline), fTransformedCoordVars(transformedCoordVars) {} |
73 | |
74 | std::pair<const GrCoordTransform&, const GrFragmentProcessor&> |
75 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler::get() const { |
76 | return *fIter; |
77 | } |
78 | |
79 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler& |
80 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler::operator++() { |
81 | SkASSERT(fAddedCoord); |
82 | ++fIter; |
83 | SkDEBUGCODE(fAddedCoord = false;) |
84 | return *this; |
85 | } |
86 | |