| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "GrGLProgramDesc.h" | 7 #include "GrGLProgramDesc.h" |
| 8 | 8 |
| 9 #include "GrGLProcessor.h" | 9 #include "GrGLProcessor.h" |
| 10 #include "GrProcessor.h" | 10 #include "GrProcessor.h" |
| 11 #include "GrGpuGL.h" | 11 #include "GrGpuGL.h" |
| 12 #include "GrOptDrawState.h" | 12 #include "GrOptDrawState.h" |
| 13 #include "SkChecksum.h" | 13 #include "SkChecksum.h" |
| 14 #include "gl/builders/GrGLFragmentShaderBuilder.h" | 14 #include "gl/builders/GrGLFragmentShaderBuilder.h" |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * The key for an individual coord transform is made up of a matrix type and a b
it that | |
| 18 * indicates the source of the input coords. | |
| 19 */ | |
| 20 enum { | |
| 21 kMatrixTypeKeyBits = 1, | |
| 22 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, | |
| 23 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits), | |
| 24 kTransformKeyBits = kMatrixTypeKeyBits + 1, | |
| 25 }; | |
| 26 | |
| 27 /** | |
| 28 * We specialize the vertex code for each of these matrix types. | |
| 29 */ | |
| 30 enum MatrixType { | |
| 31 kNoPersp_MatrixType = 0, | |
| 32 kGeneral_MatrixType = 1, | |
| 33 }; | |
| 34 | |
| 35 /** | |
| 36 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic
h channels are | 17 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic
h channels are |
| 37 * present in the texture's config. swizzleComponentMask indicates the channels
present in the | 18 * present in the texture's config. swizzleComponentMask indicates the channels
present in the |
| 38 * shader swizzle. | 19 * shader swizzle. |
| 39 */ | 20 */ |
| 40 static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, | 21 static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, |
| 41 uint32_t configComponentMask, | 22 uint32_t configComponentMask, |
| 42 uint32_t swizzleComponentMask) { | 23 uint32_t swizzleComponentMask) { |
| 43 if (caps.textureSwizzleSupport()) { | 24 if (caps.textureSwizzleSupport()) { |
| 44 // Any remapping is handled using texture swizzling not shader modificat
ions. | 25 // Any remapping is handled using texture swizzling not shader modificat
ions. |
| 45 return false; | 26 return false; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 const GrGeometryProcessor::VertexAttribArray& vars = proc.getAttribs(); | 46 const GrGeometryProcessor::VertexAttribArray& vars = proc.getAttribs(); |
| 66 int numAttributes = vars.count(); | 47 int numAttributes = vars.count(); |
| 67 SkASSERT(numAttributes <= GrGeometryProcessor::kMaxVertexAttribs); | 48 SkASSERT(numAttributes <= GrGeometryProcessor::kMaxVertexAttribs); |
| 68 for (int a = 0; a < numAttributes; ++a) { | 49 for (int a = 0; a < numAttributes; ++a) { |
| 69 uint32_t value = 1 << a; | 50 uint32_t value = 1 << a; |
| 70 key |= value; | 51 key |= value; |
| 71 } | 52 } |
| 72 return key; | 53 return key; |
| 73 } | 54 } |
| 74 | 55 |
| 75 static uint32_t gen_transform_key(const GrPendingFragmentStage& stage, | 56 /** |
| 76 bool useExplicitLocalCoords) { | 57 * The key for an individual coord transform is made up of a matrix type, a prec
ision, and a bit |
| 58 * that indicates the source of the input coords. |
| 59 */ |
| 60 enum { |
| 61 kMatrixTypeKeyBits = 1, |
| 62 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, |
| 63 |
| 64 kPrecisionBits = 2, |
| 65 kPrecisionShift = kMatrixTypeKeyBits, |
| 66 |
| 67 kPositionCoords_Flag = (1 << (kPrecisionShift + kPrecisionBits)), |
| 68 |
| 69 kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 1, |
| 70 }; |
| 71 |
| 72 GR_STATIC_ASSERT(GrShaderVar::kHigh_Precision < (1 << kPrecisionBits)); |
| 73 |
| 74 /** |
| 75 * We specialize the vertex code for each of these matrix types. |
| 76 */ |
| 77 enum MatrixType { |
| 78 kNoPersp_MatrixType = 0, |
| 79 kGeneral_MatrixType = 1, |
| 80 }; |
| 81 |
| 82 static uint32_t gen_transform_key(const GrPendingFragmentStage& stage, bool useE
xplicitLocalCoords) { |
| 77 uint32_t totalKey = 0; | 83 uint32_t totalKey = 0; |
| 78 int numTransforms = stage.getProcessor()->numTransforms(); | 84 int numTransforms = stage.getProcessor()->numTransforms(); |
| 79 for (int t = 0; t < numTransforms; ++t) { | 85 for (int t = 0; t < numTransforms; ++t) { |
| 80 uint32_t key = 0; | 86 uint32_t key = 0; |
| 81 if (stage.isPerspectiveCoordTransform(t)) { | 87 if (stage.isPerspectiveCoordTransform(t)) { |
| 82 key |= kGeneral_MatrixType; | 88 key |= kGeneral_MatrixType; |
| 83 } else { | 89 } else { |
| 84 key |= kNoPersp_MatrixType; | 90 key |= kNoPersp_MatrixType; |
| 85 } | 91 } |
| 86 | 92 |
| 87 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTran
sform(t); | 93 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTran
sform(t); |
| 88 if (kLocal_GrCoordSet != coordTransform.sourceCoords() && useExplicitLoc
alCoords) { | 94 if (kLocal_GrCoordSet != coordTransform.sourceCoords() && useExplicitLoc
alCoords) { |
| 89 key |= kPositionCoords_Flag; | 95 key |= kPositionCoords_Flag; |
| 90 } | 96 } |
| 97 |
| 98 SkASSERT(coordTransform.precision() <= (1 << kPrecisionBits)); |
| 99 key |= (coordTransform.precision() << kPrecisionShift); |
| 100 |
| 91 key <<= kTransformKeyBits * t; | 101 key <<= kTransformKeyBits * t; |
| 102 |
| 92 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to
overlap | 103 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to
overlap |
| 93 totalKey |= key; | 104 totalKey |= key; |
| 94 } | 105 } |
| 95 return totalKey; | 106 return totalKey; |
| 96 } | 107 } |
| 97 | 108 |
| 98 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { | 109 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { |
| 99 uint32_t key = 0; | 110 uint32_t key = 0; |
| 100 int numTextures = proc.numTextures(); | 111 int numTextures = proc.numTextures(); |
| 101 for (int t = 0; t < numTextures; ++t) { | 112 for (int t = 0; t < numTextures; ++t) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 261 } |
| 251 | 262 |
| 252 header->fPrimaryOutputType = descInfo.fPrimaryOutputType; | 263 header->fPrimaryOutputType = descInfo.fPrimaryOutputType; |
| 253 header->fSecondaryOutputType = descInfo.fSecondaryOutputType; | 264 header->fSecondaryOutputType = descInfo.fSecondaryOutputType; |
| 254 | 265 |
| 255 header->fColorEffectCnt = optState.numColorStages(); | 266 header->fColorEffectCnt = optState.numColorStages(); |
| 256 header->fCoverageEffectCnt = optState.numCoverageStages(); | 267 header->fCoverageEffectCnt = optState.numCoverageStages(); |
| 257 desc->finalize(); | 268 desc->finalize(); |
| 258 return true; | 269 return true; |
| 259 } | 270 } |
| OLD | NEW |