| 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 "GrGLGpu.h" | 11 #include "GrGLGpu.h" |
| 12 #include "GrOptDrawState.h" | 12 #include "GrPipeline.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 * 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 |
| 18 * 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 |
| 19 * shader swizzle. | 19 * shader swizzle. |
| 20 */ | 20 */ |
| 21 static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, | 21 static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, |
| 22 uint32_t configComponentMask, | 22 uint32_t configComponentMask, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 uint32_t* key = b->add32n(2); | 83 uint32_t* key = b->add32n(2); |
| 84 key[0] = (textureKey << 16 | transformKey); | 84 key[0] = (textureKey << 16 | transformKey); |
| 85 key[1] = (classID << 16 | SkToU16(processorKeySize)); | 85 key[1] = (classID << 16 | SkToU16(processorKeySize)); |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, | 89 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, |
| 90 const GrPrimitiveProcessor& primProc, | 90 const GrPrimitiveProcessor& primProc, |
| 91 const GrOptDrawState& optState, | 91 const GrPipeline& pipeline, |
| 92 const GrProgramDesc::DescInfo& descInfo, | 92 const GrProgramDesc::DescInfo& descInfo, |
| 93 const GrGLGpu* gpu, | 93 const GrGLGpu* gpu, |
| 94 const GrBatchTracker& batchTracker) { | 94 const GrBatchTracker& batchTracker) { |
| 95 // The descriptor is used as a cache key. Thus when a field of the | 95 // The descriptor is used as a cache key. Thus when a field of the |
| 96 // descriptor will not affect program generation (because of the attribute | 96 // descriptor will not affect program generation (because of the attribute |
| 97 // bindings in use or other descriptor field settings) it should be set | 97 // bindings in use or other descriptor field settings) it should be set |
| 98 // to a canonical value to avoid duplicate programs with different keys. | 98 // to a canonical value to avoid duplicate programs with different keys. |
| 99 | 99 |
| 100 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); | 100 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); |
| 101 // Make room for everything up to the effect keys. | 101 // Make room for everything up to the effect keys. |
| 102 desc->fKey.reset(); | 102 desc->fKey.reset(); |
| 103 desc->fKey.push_back_n(kProcessorKeysOffset); | 103 desc->fKey.push_back_n(kProcessorKeysOffset); |
| 104 | 104 |
| 105 GrProcessorKeyBuilder b(&desc->fKey); | 105 GrProcessorKeyBuilder b(&desc->fKey); |
| 106 | 106 |
| 107 primProc.getGLProcessorKey(batchTracker, gpu->glCaps(), &b); | 107 primProc.getGLProcessorKey(batchTracker, gpu->glCaps(), &b); |
| 108 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) { | 108 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) { |
| 109 desc->fKey.reset(); | 109 desc->fKey.reset(); |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 for (int s = 0; s < optState.numFragmentStages(); ++s) { | 113 for (int s = 0; s < pipeline.numFragmentStages(); ++s) { |
| 114 const GrPendingFragmentStage& fps = optState.getFragmentStage(s); | 114 const GrPendingFragmentStage& fps = pipeline.getFragmentStage(s); |
| 115 const GrFragmentProcessor& fp = *fps.processor(); | 115 const GrFragmentProcessor& fp = *fps.processor(); |
| 116 fp.getGLProcessorKey(gpu->glCaps(), &b); | 116 fp.getGLProcessorKey(gpu->glCaps(), &b); |
| 117 if (!get_meta_key(fp, gpu->glCaps(), primProc.getTransformKey(fp.coordTr
ansforms()), &b)) { | 117 if (!get_meta_key(fp, gpu->glCaps(), primProc.getTransformKey(fp.coordTr
ansforms()), &b)) { |
| 118 desc->fKey.reset(); | 118 desc->fKey.reset(); |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 const GrXferProcessor& xp = *optState.getXferProcessor(); | 123 const GrXferProcessor& xp = *pipeline.getXferProcessor(); |
| 124 xp.getGLProcessorKey(gpu->glCaps(), &b); | 124 xp.getGLProcessorKey(gpu->glCaps(), &b); |
| 125 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) { | 125 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) { |
| 126 desc->fKey.reset(); | 126 desc->fKey.reset(); |
| 127 return false; | 127 return false; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------
------------------- | 130 // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------
------------------- |
| 131 // Because header is a pointer into the dynamic array, we can't push any new
data into the key | 131 // Because header is a pointer into the dynamic array, we can't push any new
data into the key |
| 132 // below here. | 132 // below here. |
| 133 KeyHeader* header = desc->atOffset<KeyHeader, kHeaderOffset>(); | 133 KeyHeader* header = desc->atOffset<KeyHeader, kHeaderOffset>(); |
| 134 | 134 |
| 135 // make sure any padding in the header is zeroed. | 135 // make sure any padding in the header is zeroed. |
| 136 memset(header, 0, kHeaderSize); | 136 memset(header, 0, kHeaderSize); |
| 137 | 137 |
| 138 if (descInfo.fReadsDst) { | 138 if (descInfo.fReadsDst) { |
| 139 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); | 139 const GrDeviceCoordTexture* dstCopy = pipeline.getDstCopy(); |
| 140 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); | 140 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); |
| 141 const GrTexture* dstCopyTexture = NULL; | 141 const GrTexture* dstCopyTexture = NULL; |
| 142 if (dstCopy) { | 142 if (dstCopy) { |
| 143 dstCopyTexture = dstCopy->texture(); | 143 dstCopyTexture = dstCopy->texture(); |
| 144 } | 144 } |
| 145 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, | 145 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe
xture, |
| 146 gpu->glCa
ps()); | 146 gpu->glCa
ps()); |
| 147 SkASSERT(0 != header->fDstReadKey); | 147 SkASSERT(0 != header->fDstReadKey); |
| 148 } else { | 148 } else { |
| 149 header->fDstReadKey = 0; | 149 header->fDstReadKey = 0; |
| 150 } | 150 } |
| 151 | 151 |
| 152 if (descInfo.fReadsFragPosition) { | 152 if (descInfo.fReadsFragPosition) { |
| 153 header->fFragPosKey = | 153 header->fFragPosKey = |
| 154 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe
nderTarget(), | 154 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget(), |
| 155 gpu->glCaps())
; | 155 gpu->glCaps())
; |
| 156 } else { | 156 } else { |
| 157 header->fFragPosKey = 0; | 157 header->fFragPosKey = 0; |
| 158 } | 158 } |
| 159 | 159 |
| 160 header->fColorEffectCnt = optState.numColorStages(); | 160 header->fColorEffectCnt = pipeline.numColorStages(); |
| 161 header->fCoverageEffectCnt = optState.numCoverageStages(); | 161 header->fCoverageEffectCnt = pipeline.numCoverageStages(); |
| 162 desc->finalize(); | 162 desc->finalize(); |
| 163 return true; | 163 return true; |
| 164 } | 164 } |
| OLD | NEW |