| 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/GrTexture.h" | 
|---|
| 11 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" | 
|---|
| 12 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" | 
|---|
| 13 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" | 
|---|
| 14 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" | 
|---|
| 15 |  | 
|---|
| 16 | void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLFPFragmentBuilder* fragBuilder, | 
|---|
| 17 | GrGLSLUniformHandler* uniformHandler, | 
|---|
| 18 | const char* outputName, | 
|---|
| 19 | UniformHandle* colorUniform) { | 
|---|
| 20 | SkASSERT(colorUniform); | 
|---|
| 21 | const char* stagedLocalVarName; | 
|---|
| 22 | *colorUniform = uniformHandler->addUniform(nullptr, | 
|---|
| 23 | kFragment_GrShaderFlag, | 
|---|
| 24 | kHalf4_GrSLType, | 
|---|
| 25 | "Color", | 
|---|
| 26 | &stagedLocalVarName); | 
|---|
| 27 | fragBuilder->codeAppendf( "%s = %s;", outputName, stagedLocalVarName); | 
|---|
| 28 | if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) { | 
|---|
| 29 | fragBuilder->codeAppendf( "%s = max(%s, half4(0, 0, 0, 0));", outputName, outputName); | 
|---|
| 30 | } | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 34 |  | 
|---|
| 35 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler::FPCoordTransformHandler( | 
|---|
| 36 | const GrPipeline& pipeline, SkTArray<GrShaderVar>* transformedCoordVars) | 
|---|
| 37 | : fIter(pipeline), fTransformedCoordVars(transformedCoordVars) { | 
|---|
| 38 | while (fIter && !fIter->usesVaryingCoordsDirectly()) { | 
|---|
| 39 | ++fIter; | 
|---|
| 40 | } | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | const GrFragmentProcessor& GrGLSLPrimitiveProcessor::FPCoordTransformHandler::get() const { | 
|---|
| 44 | return *fIter; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler& | 
|---|
| 48 | GrGLSLPrimitiveProcessor::FPCoordTransformHandler::operator++() { | 
|---|
| 49 | SkASSERT(fAddedCoord); | 
|---|
| 50 | do { | 
|---|
| 51 | ++fIter; | 
|---|
| 52 | } while (fIter && !fIter->usesVaryingCoordsDirectly()); | 
|---|
| 53 | SkDEBUGCODE(fAddedCoord = false;) | 
|---|
| 54 | return *this; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|