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