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 | 7 |
8 #include "GrGLProgramDesc.h" | 8 #include "GrGLProgramDesc.h" |
9 #include "GrBackendEffectFactory.h" | 9 #include "GrBackendEffectFactory.h" |
10 #include "GrDrawEffect.h" | 10 #include "GrDrawEffect.h" |
11 #include "GrEffect.h" | 11 #include "GrEffect.h" |
12 #include "GrGLShaderBuilder.h" | 12 #include "GrGLShaderBuilder.h" |
13 #include "GrGpuGL.h" | 13 #include "GrGpuGL.h" |
14 | 14 |
15 #include "SkChecksum.h" | 15 #include "SkChecksum.h" |
16 | 16 |
17 static inline bool get_key_and_update_stats(const GrEffectStage& stage, | 17 bool GrGLProgramDesc::GetEffectKeyAndUpdateStats(const GrEffectStage& stage, |
18 const GrGLCaps& caps, | 18 const GrGLCaps& caps, |
19 bool useExplicitLocalCoords, | 19 bool useExplicitLocalCoords, |
20 GrEffectKeyBuilder* b, | 20 GrEffectKeyBuilder* b, |
21 bool* setTrueIfReadsDst, | 21 uint16_t* effectKeySize, |
22 bool* setTrueIfReadsPos, | 22 bool* setTrueIfReadsDst, |
23 bool* setTrueIfHasVertexCode) { | 23 bool* setTrueIfReadsPos, |
| 24 bool* setTrueIfHasVertexCode) { |
24 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); | 25 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); |
25 GrDrawEffect drawEffect(stage, useExplicitLocalCoords); | 26 GrDrawEffect drawEffect(stage, useExplicitLocalCoords); |
26 if (stage.getEffect()->willReadDstColor()) { | 27 if (stage.getEffect()->willReadDstColor()) { |
27 *setTrueIfReadsDst = true; | 28 *setTrueIfReadsDst = true; |
28 } | 29 } |
29 if (stage.getEffect()->willReadFragmentPosition()) { | 30 if (stage.getEffect()->willReadFragmentPosition()) { |
30 *setTrueIfReadsPos = true; | 31 *setTrueIfReadsPos = true; |
31 } | 32 } |
32 if (stage.getEffect()->hasVertexCode()) { | 33 if (stage.getEffect()->hasVertexCode()) { |
33 *setTrueIfHasVertexCode = true; | 34 *setTrueIfHasVertexCode = true; |
34 } | 35 } |
35 return factory.getGLEffectKey(drawEffect, caps, b); | 36 factory.getGLEffectKey(drawEffect, caps, b); |
| 37 size_t size = b->size(); |
| 38 if (size > SK_MaxU16) { |
| 39 *effectKeySize = 0; // suppresses a warning. |
| 40 return false; |
| 41 } |
| 42 *effectKeySize = SkToU16(size); |
| 43 if (!GrGLProgramEffects::GenEffectMetaKey(drawEffect, caps, b)) { |
| 44 return false; |
| 45 } |
| 46 return true; |
36 } | 47 } |
37 | 48 |
38 bool GrGLProgramDesc::Build(const GrDrawState& drawState, | 49 bool GrGLProgramDesc::Build(const GrDrawState& drawState, |
39 GrGpu::DrawType drawType, | 50 GrGpu::DrawType drawType, |
40 GrDrawState::BlendOptFlags blendOpts, | 51 GrDrawState::BlendOptFlags blendOpts, |
41 GrBlendCoeff srcCoeff, | 52 GrBlendCoeff srcCoeff, |
42 GrBlendCoeff dstCoeff, | 53 GrBlendCoeff dstCoeff, |
43 const GrGpuGL* gpu, | 54 const GrGpuGL* gpu, |
44 const GrDeviceCoordTexture* dstCopy, | 55 const GrDeviceCoordTexture* dstCopy, |
45 SkTArray<const GrEffectStage*, true>* colorStages, | 56 SkTArray<const GrEffectStage*, true>* colorStages, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // We use vertexshader-less shader programs only when drawing paths. | 109 // We use vertexshader-less shader programs only when drawing paths. |
99 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType || | 110 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType || |
100 GrGpu::kDrawPaths_DrawType == drawType); | 111 GrGpu::kDrawPaths_DrawType == drawType); |
101 int numStages = 0; | 112 int numStages = 0; |
102 if (!skipColor) { | 113 if (!skipColor) { |
103 numStages += drawState.numColorStages() - firstEffectiveColorStage; | 114 numStages += drawState.numColorStages() - firstEffectiveColorStage; |
104 } | 115 } |
105 if (!skipCoverage) { | 116 if (!skipCoverage) { |
106 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage
; | 117 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage
; |
107 } | 118 } |
108 GR_STATIC_ASSERT(0 == kEffectKeyLengthsOffset % sizeof(uint32_t)); | 119 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
109 // Make room for everything up to and including the array of offsets to effe
ct keys. | 120 // Make room for everything up to and including the array of offsets to effe
ct keys. |
110 desc->fKey.reset(); | 121 desc->fKey.reset(); |
111 desc->fKey.push_back_n(kEffectKeyLengthsOffset + sizeof(uint32_t) * numStage
s); | 122 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_
t) * numStages); |
112 | 123 |
113 size_t offset = desc->fKey.count(); | 124 int offsetAndSizeIndex = 0; |
114 int offsetIndex = 0; | |
115 | 125 |
116 bool effectKeySuccess = true; | 126 bool effectKeySuccess = true; |
117 if (!skipColor) { | 127 if (!skipColor) { |
118 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); +
+s) { | 128 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); +
+s) { |
119 uint32_t* offsetLocation = reinterpret_cast<uint32_t*>(desc->fKey.be
gin() + | 129 uint16_t* offsetAndSize = |
120 kEffectKeyLen
gthsOffset + | 130 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse
tsAndLengthOffset + |
121 offsetIndex *
sizeof(uint32_t)); | 131 offsetAndSizeIndex * 2 * sizeof(uint
16_t)); |
122 *offsetLocation = offset; | |
123 ++offsetIndex; | |
124 | 132 |
125 GrEffectKeyBuilder b(&desc->fKey); | 133 GrEffectKeyBuilder b(&desc->fKey); |
126 effectKeySuccess |= get_key_and_update_stats(drawState.getColorStage
(s), gpu->glCaps(), | 134 uint16_t effectKeySize; |
127 requiresLocalCoordAttri
b, &b, &readsDst, | 135 uint32_t effectOffset = desc->fKey.count(); |
128 &readFragPosition, &has
VertexCode); | 136 effectKeySuccess |= GetEffectKeyAndUpdateStats( |
129 offset += b.size(); | 137 drawState.getColorStage(s), gpu->glCaps(), |
| 138 requiresLocalCoordAttrib, &b, |
| 139 &effectKeySize, &readsDst, |
| 140 &readFragPosition, &hasVertexCode); |
| 141 effectKeySuccess |= (effectOffset <= SK_MaxU16); |
| 142 |
| 143 offsetAndSize[0] = SkToU16(effectOffset); |
| 144 offsetAndSize[1] = effectKeySize; |
| 145 ++offsetAndSizeIndex; |
130 } | 146 } |
131 } | 147 } |
132 if (!skipCoverage) { | 148 if (!skipCoverage) { |
133 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage
s(); ++s) { | 149 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage
s(); ++s) { |
134 uint32_t* offsetLocation = reinterpret_cast<uint32_t*>(desc->fKey.be
gin() + | 150 uint16_t* offsetAndSize = |
135 kEffectKeyLen
gthsOffset + | 151 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse
tsAndLengthOffset + |
136 offsetIndex *
sizeof(uint32_t)); | 152 offsetAndSizeIndex * 2 * sizeof(uint
16_t)); |
137 *offsetLocation = offset; | 153 |
138 ++offsetIndex; | |
139 GrEffectKeyBuilder b(&desc->fKey); | 154 GrEffectKeyBuilder b(&desc->fKey); |
140 effectKeySuccess |= get_key_and_update_stats(drawState.getCoverageSt
age(s), | 155 uint16_t effectKeySize; |
141 gpu->glCaps(), requires
LocalCoordAttrib, | 156 uint32_t effectOffset = desc->fKey.count(); |
142 &b, &readsDst, &readFra
gPosition, | 157 effectKeySuccess |= GetEffectKeyAndUpdateStats( |
143 &hasVertexCode); | 158 drawState.getCoverageStage(s), gpu->glCaps()
, |
144 offset += b.size(); | 159 requiresLocalCoordAttrib, &b, |
| 160 &effectKeySize, &readsDst, |
| 161 &readFragPosition, &hasVertexCode); |
| 162 effectKeySuccess |= (effectOffset <= SK_MaxU16); |
| 163 |
| 164 offsetAndSize[0] = SkToU16(effectOffset); |
| 165 offsetAndSize[1] = effectKeySize; |
| 166 ++offsetAndSizeIndex; |
145 } | 167 } |
146 } | 168 } |
147 if (!effectKeySuccess) { | 169 if (!effectKeySuccess) { |
148 desc->fKey.reset(); | 170 desc->fKey.reset(); |
149 return false; | 171 return false; |
150 } | 172 } |
151 | 173 |
152 KeyHeader* header = desc->header(); | 174 KeyHeader* header = desc->header(); |
153 // make sure any padding in the header is zeroed. | 175 // make sure any padding in the header is zeroed. |
154 memset(desc->header(), 0, kHeaderSize); | 176 memset(desc->header(), 0, kHeaderSize); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 *checksum = 0; | 325 *checksum = 0; |
304 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); | 326 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k
eyLength); |
305 } | 327 } |
306 | 328 |
307 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 329 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
308 size_t keyLength = other.keyLength(); | 330 size_t keyLength = other.keyLength(); |
309 fKey.reset(keyLength); | 331 fKey.reset(keyLength); |
310 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 332 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
311 return *this; | 333 return *this; |
312 } | 334 } |
OLD | NEW |