OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLStencilAttachment.h" | 10 #include "GrGLStencilAttachment.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); | 150 GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
151 GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); | 151 GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
152 GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); | 152 GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
153 | 153 |
154 // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope | 154 // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
155 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gXfermodeCoeff2Blend)); | 155 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
156 } | 156 } |
157 | 157 |
158 /////////////////////////////////////////////////////////////////////////////// | 158 /////////////////////////////////////////////////////////////////////////////// |
159 | 159 |
| 160 GrGpu* GrGLGpu::Create(GrBackendContext backendContext, GrContext* context) { |
| 161 SkAutoTUnref<const GrGLInterface> glInterface( |
| 162 reinterpret_cast<const GrGLInterface*>(backendContext)); |
| 163 if (!glInterface) { |
| 164 glInterface.reset(GrGLDefaultInterface()); |
| 165 } else { |
| 166 glInterface->ref(); |
| 167 } |
| 168 if (!glInterface) { |
| 169 return NULL; |
| 170 } |
| 171 GrGLContext* glContext = GrGLContext::Create(glInterface); |
| 172 if (glContext) { |
| 173 return SkNEW_ARGS(GrGLGpu, (glContext, context)); |
| 174 } |
| 175 return NULL; |
| 176 } |
| 177 |
160 static bool gPrintStartupSpew; | 178 static bool gPrintStartupSpew; |
161 | 179 |
162 GrGLGpu::GrGLGpu(const GrGLContext& ctx, GrContext* context) | 180 GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context) |
163 : GrGpu(context) | 181 : GrGpu(context) |
164 , fGLContext(ctx) { | 182 , fGLContext(ctx) { |
165 | 183 SkASSERT(ctx); |
166 SkASSERT(ctx.isInitialized()); | 184 fCaps.reset(SkRef(ctx->caps())); |
167 fCaps.reset(SkRef(ctx.caps())); | |
168 | 185 |
169 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); | 186 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); |
170 | 187 |
171 GrGLClearErr(fGLContext.interface()); | 188 GrGLClearErr(this->glInterface()); |
172 if (gPrintStartupSpew) { | 189 if (gPrintStartupSpew) { |
173 const GrGLubyte* vendor; | 190 const GrGLubyte* vendor; |
174 const GrGLubyte* renderer; | 191 const GrGLubyte* renderer; |
175 const GrGLubyte* version; | 192 const GrGLubyte* version; |
176 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); | 193 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
177 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); | 194 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
178 GL_CALL_RET(version, GetString(GR_GL_VERSION)); | 195 GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
179 SkDebugf("------------------------- create GrGLGpu %p --------------\n", | 196 SkDebugf("------------------------- create GrGLGpu %p --------------\n", |
180 this); | 197 this); |
181 SkDebugf("------ VENDOR %s\n", vendor); | 198 SkDebugf("------ VENDOR %s\n", vendor); |
182 SkDebugf("------ RENDERER %s\n", renderer); | 199 SkDebugf("------ RENDERER %s\n", renderer); |
183 SkDebugf("------ VERSION %s\n", version); | 200 SkDebugf("------ VERSION %s\n", version); |
184 SkDebugf("------ EXTENSIONS\n"); | 201 SkDebugf("------ EXTENSIONS\n"); |
185 ctx.extensions().print(); | 202 this->glContext().extensions().print(); |
186 SkDebugf("\n"); | 203 SkDebugf("\n"); |
187 SkDebugf("%s", this->glCaps().dump().c_str()); | 204 SkDebugf("%s", this->glCaps().dump().c_str()); |
188 } | 205 } |
189 | 206 |
190 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); | 207 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); |
191 | 208 |
192 SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVe
rtexAttribs); | 209 SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVe
rtexAttribs); |
193 | 210 |
194 fLastSuccessfulStencilFmtIdx = 0; | 211 fLastSuccessfulStencilFmtIdx = 0; |
195 fHWProgramID = 0; | 212 fHWProgramID = 0; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // Since ES doesn't support glPointSize at all we always use the VS
to | 341 // Since ES doesn't support glPointSize at all we always use the VS
to |
325 // set the point size | 342 // set the point size |
326 GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE)); | 343 GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE)); |
327 | 344 |
328 // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It is
n't | 345 // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It is
n't |
329 // currently part of our gl interface. There are probably others as | 346 // currently part of our gl interface. There are probably others as |
330 // well. | 347 // well. |
331 } | 348 } |
332 | 349 |
333 if (kGLES_GrGLStandard == this->glStandard() && | 350 if (kGLES_GrGLStandard == this->glStandard() && |
334 fGLContext.hasExtension("GL_ARM_shader_framebuffer_fetch")) { | 351 this->hasExtension("GL_ARM_shader_framebuffer_fetch")) { |
335 // The arm extension requires specifically enabling MSAA fetching pe
r sample. | 352 // The arm extension requires specifically enabling MSAA fetching pe
r sample. |
336 // On some devices this may have a perf hit. Also multiple render t
argets are disabled | 353 // On some devices this may have a perf hit. Also multiple render t
argets are disabled |
337 GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); | 354 GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); |
338 } | 355 } |
339 fHWWriteToColor = kUnknown_TriState; | 356 fHWWriteToColor = kUnknown_TriState; |
340 // we only ever use lines in hairline mode | 357 // we only ever use lines in hairline mode |
341 GL_CALL(LineWidth(1)); | 358 GL_CALL(LineWidth(1)); |
342 } | 359 } |
343 | 360 |
344 if (resetBits & kMSAAEnable_GrGLBackendState) { | 361 if (resetBits & kMSAAEnable_GrGLBackendState) { |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 left, top, | 822 left, top, |
806 width, height, | 823 width, height, |
807 internalFormat, | 824 internalFormat, |
808 SkToInt(dataSize), | 825 SkToInt(dataSize), |
809 data)); | 826 data)); |
810 } | 827 } |
811 | 828 |
812 return true; | 829 return true; |
813 } | 830 } |
814 | 831 |
815 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 832 static bool renderbuffer_storage_msaa(const GrGLContext& ctx, |
816 int sampleCount, | 833 int sampleCount, |
817 GrGLenum format, | 834 GrGLenum format, |
818 int width, int height) { | 835 int width, int height) { |
819 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); | 836 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
820 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); | 837 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); |
821 switch (ctx.caps()->msFBOType()) { | 838 switch (ctx.caps()->msFBOType()) { |
822 case GrGLCaps::kDesktop_ARB_MSFBOType: | 839 case GrGLCaps::kDesktop_ARB_MSFBOType: |
823 case GrGLCaps::kDesktop_EXT_MSFBOType: | 840 case GrGLCaps::kDesktop_EXT_MSFBOType: |
824 case GrGLCaps::kES_3_0_MSFBOType: | 841 case GrGLCaps::kES_3_0_MSFBOType: |
825 GL_ALLOC_CALL(ctx.interface(), | 842 GL_ALLOC_CALL(ctx.interface(), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 } | 909 } |
893 } else { | 910 } else { |
894 idDesc->fRTFBOID = idDesc->fTexFBOID; | 911 idDesc->fRTFBOID = idDesc->fTexFBOID; |
895 } | 912 } |
896 | 913 |
897 // below here we may bind the FBO | 914 // below here we may bind the FBO |
898 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 915 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
899 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { | 916 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
900 SkASSERT(desc.fSampleCnt > 0); | 917 SkASSERT(desc.fSampleCnt > 0); |
901 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); | 918 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); |
902 if (!renderbuffer_storage_msaa(fGLContext, | 919 if (!renderbuffer_storage_msaa(*fGLContext, |
903 desc.fSampleCnt, | 920 desc.fSampleCnt, |
904 msColorFormat, | 921 msColorFormat, |
905 desc.fWidth, desc.fHeight)) { | 922 desc.fWidth, desc.fHeight)) { |
906 goto FAILED; | 923 goto FAILED; |
907 } | 924 } |
908 fStats.incRenderTargetBinds(); | 925 fStats.incRenderTargetBinds(); |
909 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); | 926 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); |
910 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 927 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
911 GR_GL_COLOR_ATTACHMENT0, | 928 GR_GL_COLOR_ATTACHMENT0, |
912 GR_GL_RENDERBUFFER, | 929 GR_GL_RENDERBUFFER, |
913 idDesc->fMSColorRenderbufferID)); | 930 idDesc->fMSColorRenderbufferID)); |
914 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 931 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
915 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 932 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
916 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 933 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
917 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 934 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
918 goto FAILED; | 935 goto FAILED; |
919 } | 936 } |
920 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); | 937 fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); |
921 } | 938 } |
922 } | 939 } |
923 fStats.incRenderTargetBinds(); | 940 fStats.incRenderTargetBinds(); |
924 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); | 941 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); |
925 | 942 |
926 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { | 943 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { |
927 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, | 944 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
928 GR_GL_COLOR_ATTACHMENT0, | 945 GR_GL_COLOR_ATTACHMENT0, |
929 GR_GL_TEXTURE_2D, | 946 GR_GL_TEXTURE_2D, |
930 texID, 0, desc.fSampleCnt)); | 947 texID, 0, desc.fSampleCnt)); |
931 } else { | 948 } else { |
932 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 949 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
933 GR_GL_COLOR_ATTACHMENT0, | 950 GR_GL_COLOR_ATTACHMENT0, |
934 GR_GL_TEXTURE_2D, | 951 GR_GL_TEXTURE_2D, |
935 texID, 0)); | 952 texID, 0)); |
936 } | 953 } |
937 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 954 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
938 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 955 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
939 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 956 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
940 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 957 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
941 goto FAILED; | 958 goto FAILED; |
942 } | 959 } |
943 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); | 960 fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); |
944 } | 961 } |
945 | 962 |
946 return true; | 963 return true; |
947 | 964 |
948 FAILED: | 965 FAILED: |
949 if (idDesc->fMSColorRenderbufferID) { | 966 if (idDesc->fMSColorRenderbufferID) { |
950 GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); | 967 GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); |
951 } | 968 } |
952 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { | 969 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
953 GL_CALL(DeleteFramebuffers(1, &idDesc->fRTFBOID)); | 970 GL_CALL(DeleteFramebuffers(1, &idDesc->fRTFBOID)); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 // we start with the last stencil format that succeeded in hopes | 1172 // we start with the last stencil format that succeeded in hopes |
1156 // that we won't go through this loop more than once after the | 1173 // that we won't go through this loop more than once after the |
1157 // first (painful) stencil creation. | 1174 // first (painful) stencil creation. |
1158 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; | 1175 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
1159 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sI
dx]; | 1176 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sI
dx]; |
1160 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1177 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
1161 // we do this "if" so that we don't call the multisample | 1178 // we do this "if" so that we don't call the multisample |
1162 // version on a GL that doesn't have an MSAA extension. | 1179 // version on a GL that doesn't have an MSAA extension. |
1163 bool created; | 1180 bool created; |
1164 if (samples > 0) { | 1181 if (samples > 0) { |
1165 created = renderbuffer_storage_msaa(fGLContext, | 1182 created = renderbuffer_storage_msaa(*fGLContext, |
1166 samples, | 1183 samples, |
1167 sFmt.fInternalFormat, | 1184 sFmt.fInternalFormat, |
1168 width, height); | 1185 width, height); |
1169 } else { | 1186 } else { |
1170 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERB
UFFER, | 1187 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERB
UFFER, |
1171 sFmt.fInterna
lFormat, | 1188 sFmt.fInterna
lFormat, |
1172 width, height
)); | 1189 width, height
)); |
1173 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI
nterface())); | 1190 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI
nterface())); |
1174 } | 1191 } |
1175 if (created) { | 1192 if (created) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1313 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1297 GR_GL_STENCIL_ATTACHMENT, | 1314 GR_GL_STENCIL_ATTACHMENT, |
1298 GR_GL_RENDERBUFFER, 0)); | 1315 GR_GL_RENDERBUFFER, 0)); |
1299 if (glsb->format().fPacked) { | 1316 if (glsb->format().fPacked) { |
1300 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1317 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1301 GR_GL_DEPTH_ATTACHMENT, | 1318 GR_GL_DEPTH_ATTACHMENT, |
1302 GR_GL_RENDERBUFFER, 0)); | 1319 GR_GL_RENDERBUFFER, 0)); |
1303 } | 1320 } |
1304 return false; | 1321 return false; |
1305 } else { | 1322 } else { |
1306 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( | 1323 fGLContext->caps()->markColorConfigAndStencilFormatAsVerified( |
1307 rt->config(), | 1324 rt->config(), |
1308 glsb->format()); | 1325 glsb->format()); |
1309 } | 1326 } |
1310 } | 1327 } |
1311 return true; | 1328 return true; |
1312 } | 1329 } |
1313 } | 1330 } |
1314 | 1331 |
1315 //////////////////////////////////////////////////////////////////////////////// | 1332 //////////////////////////////////////////////////////////////////////////////// |
1316 | 1333 |
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2873 this->setVertexArrayID(gpu, 0); | 2890 this->setVertexArrayID(gpu, 0); |
2874 } | 2891 } |
2875 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2892 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2876 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2893 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2877 fDefaultVertexArrayAttribState.resize(attrCount); | 2894 fDefaultVertexArrayAttribState.resize(attrCount); |
2878 } | 2895 } |
2879 attribState = &fDefaultVertexArrayAttribState; | 2896 attribState = &fDefaultVertexArrayAttribState; |
2880 } | 2897 } |
2881 return attribState; | 2898 return attribState; |
2882 } | 2899 } |
OLD | NEW |