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