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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, | 89 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, |
90 const GrPrimitiveProcessor& primProc, | 90 const GrPrimitiveProcessor& primProc, |
91 const GrPipeline& pipeline, | 91 const GrPipeline& pipeline, |
92 const GrGLGpu* gpu, | 92 const GrGLGpu* gpu, |
93 const GrBatchTracker& batchTracker) { | 93 const GrBatchTracker& batchTracker) { |
94 // The descriptor is used as a cache key. Thus when a field of the | 94 // The descriptor is used as a cache key. Thus when a field of the |
95 // descriptor will not affect program generation (because of the attribute | 95 // descriptor will not affect program generation (because of the attribute |
96 // bindings in use or other descriptor field settings) it should be set | 96 // bindings in use or other descriptor field settings) it should be set |
97 // to a canonical value to avoid duplicate programs with different keys. | 97 // to a canonical value to avoid duplicate programs with different keys. |
98 | 98 |
| 99 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc; |
| 100 |
99 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); | 101 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); |
100 // Make room for everything up to the effect keys. | 102 // Make room for everything up to the effect keys. |
101 desc->fKey.reset(); | 103 glDesc->key().reset(); |
102 desc->fKey.push_back_n(kProcessorKeysOffset); | 104 glDesc->key().push_back_n(kProcessorKeysOffset); |
103 | 105 |
104 GrProcessorKeyBuilder b(&desc->fKey); | 106 GrProcessorKeyBuilder b(&glDesc->key()); |
105 | 107 |
106 primProc.getGLProcessorKey(batchTracker, gpu->glCaps(), &b); | 108 primProc.getGLProcessorKey(batchTracker, gpu->glCaps(), &b); |
107 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) { | 109 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) { |
108 desc->fKey.reset(); | 110 glDesc->key().reset(); |
109 return false; | 111 return false; |
110 } | 112 } |
111 | 113 |
112 for (int s = 0; s < pipeline.numFragmentStages(); ++s) { | 114 for (int s = 0; s < pipeline.numFragmentStages(); ++s) { |
113 const GrPendingFragmentStage& fps = pipeline.getFragmentStage(s); | 115 const GrPendingFragmentStage& fps = pipeline.getFragmentStage(s); |
114 const GrFragmentProcessor& fp = *fps.processor(); | 116 const GrFragmentProcessor& fp = *fps.processor(); |
115 fp.getGLProcessorKey(gpu->glCaps(), &b); | 117 fp.getGLProcessorKey(gpu->glCaps(), &b); |
116 if (!get_meta_key(fp, gpu->glCaps(), primProc.getTransformKey(fp.coordTr
ansforms()), &b)) { | 118 if (!get_meta_key(fp, gpu->glCaps(), primProc.getTransformKey(fp.coordTr
ansforms()), &b)) { |
117 desc->fKey.reset(); | 119 glDesc->key().reset(); |
118 return false; | 120 return false; |
119 } | 121 } |
120 } | 122 } |
121 | 123 |
122 const GrXferProcessor& xp = *pipeline.getXferProcessor(); | 124 const GrXferProcessor& xp = *pipeline.getXferProcessor(); |
123 xp.getGLProcessorKey(gpu->glCaps(), &b); | 125 xp.getGLProcessorKey(gpu->glCaps(), &b); |
124 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) { | 126 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) { |
125 desc->fKey.reset(); | 127 glDesc->key().reset(); |
126 return false; | 128 return false; |
127 } | 129 } |
128 | 130 |
129 // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------
------------------- | 131 // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------
------------------- |
130 // Because header is a pointer into the dynamic array, we can't push any new
data into the key | 132 // Because header is a pointer into the dynamic array, we can't push any new
data into the key |
131 // below here. | 133 // below here. |
132 KeyHeader* header = desc->atOffset<KeyHeader, kHeaderOffset>(); | 134 KeyHeader* header = glDesc->atOffset<KeyHeader, kHeaderOffset>(); |
133 | 135 |
134 // make sure any padding in the header is zeroed. | 136 // make sure any padding in the header is zeroed. |
135 memset(header, 0, kHeaderSize); | 137 memset(header, 0, kHeaderSize); |
136 | 138 |
137 if (pipeline.readsFragPosition()) { | 139 if (pipeline.readsFragPosition()) { |
138 header->fFragPosKey = | 140 header->fFragPosKey = |
139 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget(), | 141 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget(), |
140 gpu->glCaps())
; | 142 gpu->glCaps())
; |
141 } else { | 143 } else { |
142 header->fFragPosKey = 0; | 144 header->fFragPosKey = 0; |
143 } | 145 } |
144 | 146 |
145 header->fColorEffectCnt = pipeline.numColorFragmentStages(); | 147 header->fColorEffectCnt = pipeline.numColorFragmentStages(); |
146 header->fCoverageEffectCnt = pipeline.numCoverageFragmentStages(); | 148 header->fCoverageEffectCnt = pipeline.numCoverageFragmentStages(); |
147 desc->finalize(); | 149 glDesc->finalize(); |
148 return true; | 150 return true; |
149 } | 151 } |
OLD | NEW |