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 "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 SkDebugf("\n"); | 144 SkDebugf("\n"); |
145 SkDebugf("%s", this->glCaps().dump().c_str()); | 145 SkDebugf("%s", this->glCaps().dump().c_str()); |
146 } | 146 } |
147 | 147 |
148 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); | 148 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); |
149 | 149 |
150 SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVe
rtexAttribs); | 150 SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVe
rtexAttribs); |
151 | 151 |
152 fLastSuccessfulStencilFmtIdx = 0; | 152 fLastSuccessfulStencilFmtIdx = 0; |
153 fHWProgramID = 0; | 153 fHWProgramID = 0; |
| 154 fTempSrcFBOID = 0; |
| 155 fTempDstFBOID = 0; |
| 156 fStencilClearFBOID = 0; |
154 | 157 |
155 if (this->glCaps().pathRenderingSupport()) { | 158 if (this->glCaps().pathRenderingSupport()) { |
156 fPathRendering.reset(new GrGLPathRendering(this)); | 159 fPathRendering.reset(new GrGLPathRendering(this)); |
157 } | 160 } |
158 } | 161 } |
159 | 162 |
160 GrGLGpu::~GrGLGpu() { | 163 GrGLGpu::~GrGLGpu() { |
161 if (0 != fHWProgramID) { | 164 if (0 != fHWProgramID) { |
162 // detach the current program so there is no confusion on OpenGL's part | 165 // detach the current program so there is no confusion on OpenGL's part |
163 // that we want it to be deleted | 166 // that we want it to be deleted |
164 SkASSERT(fHWProgramID == fCurrentProgram->programID()); | 167 SkASSERT(fHWProgramID == fCurrentProgram->programID()); |
165 GL_CALL(UseProgram(0)); | 168 GL_CALL(UseProgram(0)); |
166 } | 169 } |
167 | 170 |
168 if (fTempSrcFBO) { | 171 if (0 != fTempSrcFBOID) { |
169 fTempSrcFBO->release(this->glInterface()); | 172 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); |
170 fTempSrcFBO.reset(NULL); | |
171 } | 173 } |
172 if (fTempDstFBO) { | 174 if (0 != fTempDstFBOID) { |
173 fTempDstFBO->release(this->glInterface()); | 175 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); |
174 fTempDstFBO.reset(NULL); | |
175 } | 176 } |
176 if (fStencilClearFBO) { | 177 if (0 != fStencilClearFBOID) { |
177 fStencilClearFBO->release(this->glInterface()); | 178 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); |
178 fStencilClearFBO.reset(NULL); | |
179 } | 179 } |
180 | 180 |
181 delete fProgramCache; | 181 delete fProgramCache; |
182 } | 182 } |
183 | 183 |
184 void GrGLGpu::contextAbandoned() { | 184 void GrGLGpu::contextAbandoned() { |
185 INHERITED::contextAbandoned(); | 185 INHERITED::contextAbandoned(); |
186 fProgramCache->abandon(); | 186 fProgramCache->abandon(); |
187 fHWProgramID = 0; | 187 fHWProgramID = 0; |
188 if (fTempSrcFBO) { | 188 fTempSrcFBOID = 0; |
189 fTempSrcFBO->abandon(); | 189 fTempDstFBOID = 0; |
190 fTempSrcFBO.reset(NULL); | 190 fStencilClearFBOID = 0; |
191 } | |
192 if (fTempDstFBO) { | |
193 fTempDstFBO->abandon(); | |
194 fTempDstFBO.reset(NULL); | |
195 } | |
196 if (fStencilClearFBO) { | |
197 fStencilClearFBO->abandon(); | |
198 fStencilClearFBO.reset(NULL); | |
199 } | |
200 | |
201 if (this->glCaps().pathRenderingSupport()) { | 191 if (this->glCaps().pathRenderingSupport()) { |
202 this->glPathRendering()->abandonGpuResources(); | 192 this->glPathRendering()->abandonGpuResources(); |
203 } | 193 } |
204 } | 194 } |
205 | 195 |
206 /////////////////////////////////////////////////////////////////////////////// | 196 /////////////////////////////////////////////////////////////////////////////// |
207 GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig, | 197 GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig, |
208 GrPixelConfig surfaceConfig) co
nst { | 198 GrPixelConfig surfaceConfig) co
nst { |
209 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig
) { | 199 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig
) { |
210 return kBGRA_8888_GrPixelConfig; | 200 return kBGRA_8888_GrPixelConfig; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 fHWStencilSettings.invalidate(); | 324 fHWStencilSettings.invalidate(); |
335 fHWStencilTestEnabled = kUnknown_TriState; | 325 fHWStencilTestEnabled = kUnknown_TriState; |
336 } | 326 } |
337 | 327 |
338 // Vertex | 328 // Vertex |
339 if (resetBits & kVertex_GrGLBackendState) { | 329 if (resetBits & kVertex_GrGLBackendState) { |
340 fHWGeometryState.invalidate(); | 330 fHWGeometryState.invalidate(); |
341 } | 331 } |
342 | 332 |
343 if (resetBits & kRenderTarget_GrGLBackendState) { | 333 if (resetBits & kRenderTarget_GrGLBackendState) { |
344 for (size_t i = 0; i < SK_ARRAY_COUNT(fHWFBOBinding); ++i) { | 334 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
345 fHWFBOBinding[i].invalidate(); | |
346 } | |
347 } | 335 } |
348 | 336 |
349 if (resetBits & kPathRendering_GrGLBackendState) { | 337 if (resetBits & kPathRendering_GrGLBackendState) { |
350 if (this->caps()->pathRenderingSupport()) { | 338 if (this->caps()->pathRenderingSupport()) { |
351 this->glPathRendering()->resetContext(); | 339 this->glPathRendering()->resetContext(); |
352 } | 340 } |
353 } | 341 } |
354 | 342 |
355 // we assume these values | 343 // we assume these values |
356 if (resetBits & kPixelStore_GrGLBackendState) { | 344 if (resetBits & kPixelStore_GrGLBackendState) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 425 } |
438 if (NULL == texture) { | 426 if (NULL == texture) { |
439 return NULL; | 427 return NULL; |
440 } | 428 } |
441 | 429 |
442 return texture; | 430 return texture; |
443 } | 431 } |
444 | 432 |
445 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc) { | 433 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc) { |
446 GrGLRenderTarget::IDDesc idDesc; | 434 GrGLRenderTarget::IDDesc idDesc; |
447 GrGLuint fboID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); | 435 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); |
448 idDesc.fRenderFBO.reset(SkNEW_ARGS(GrGLFBO, (fboID))); | |
449 idDesc.fMSColorRenderbufferID = 0; | 436 idDesc.fMSColorRenderbufferID = 0; |
| 437 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
450 idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle; | 438 idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle; |
451 | 439 |
452 GrSurfaceDesc desc; | 440 GrSurfaceDesc desc; |
453 desc.fConfig = wrapDesc.fConfig; | 441 desc.fConfig = wrapDesc.fConfig; |
454 desc.fFlags = kCheckAllocation_GrSurfaceFlag; | 442 desc.fFlags = kCheckAllocation_GrSurfaceFlag; |
455 desc.fWidth = wrapDesc.fWidth; | 443 desc.fWidth = wrapDesc.fWidth; |
456 desc.fHeight = wrapDesc.fHeight; | 444 desc.fHeight = wrapDesc.fHeight; |
457 desc.fSampleCnt = wrapDesc.fSampleCnt; | 445 desc.fSampleCnt = wrapDesc.fSampleCnt; |
458 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); | 446 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
459 | 447 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 case GrGLCaps::kNone_MSFBOType: | 807 case GrGLCaps::kNone_MSFBOType: |
820 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf
fers."); | 808 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf
fers."); |
821 break; | 809 break; |
822 } | 810 } |
823 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));; | 811 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));; |
824 } | 812 } |
825 | 813 |
826 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted
, GrGLuint texID, | 814 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted
, GrGLuint texID, |
827 GrGLRenderTarget::IDDesc* idDesc) { | 815 GrGLRenderTarget::IDDesc* idDesc) { |
828 idDesc->fMSColorRenderbufferID = 0; | 816 idDesc->fMSColorRenderbufferID = 0; |
| 817 idDesc->fRTFBOID = 0; |
| 818 idDesc->fTexFBOID = 0; |
829 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : | 819 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : |
830 GrGpuResource::kUncached_LifeCycle; | 820 GrGpuResource::kUncached_LifeCycle; |
831 | 821 |
832 GrGLenum status; | 822 GrGLenum status; |
833 | 823 |
834 GrGLenum msColorFormat = 0; // suppress warning | 824 GrGLenum msColorFormat = 0; // suppress warning |
835 GrGLenum fboTarget = 0; // suppress warning | |
836 | 825 |
837 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO
Type()) { | 826 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO
Type()) { |
838 goto FAILED; | 827 goto FAILED; |
839 } | 828 } |
840 | 829 |
841 idDesc->fTextureFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface()))); | 830 GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID)); |
842 if (!idDesc->fTextureFBO->isValid()) { | 831 if (!idDesc->fTexFBOID) { |
843 goto FAILED; | 832 goto FAILED; |
844 } | 833 } |
845 | 834 |
| 835 |
846 // If we are using multisampling we will create two FBOS. We render to one a
nd then resolve to | 836 // If we are using multisampling we will create two FBOS. We render to one a
nd then resolve to |
847 // the texture bound to the other. The exception is the IMG multisample exte
nsion. With this | 837 // the texture bound to the other. The exception is the IMG multisample exte
nsion. With this |
848 // extension the texture is multisampled when rendered to and then auto-reso
lves it when it is | 838 // extension the texture is multisampled when rendered to and then auto-reso
lves it when it is |
849 // rendered from. | 839 // rendered from. |
850 if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { | 840 if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { |
851 idDesc->fRenderFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface()))); | 841 GL_CALL(GenFramebuffers(1, &idDesc->fRTFBOID)); |
852 if (!idDesc->fRenderFBO->isValid()) { | |
853 goto FAILED; | |
854 } | |
855 GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); | 842 GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); |
856 if (!idDesc->fMSColorRenderbufferID || | 843 if (!idDesc->fRTFBOID || |
| 844 !idDesc->fMSColorRenderbufferID || |
857 !this->configToGLFormats(desc.fConfig, | 845 !this->configToGLFormats(desc.fConfig, |
858 // ES2 and ES3 require sized internal forma
ts for rb storage. | 846 // ES2 and ES3 require sized internal forma
ts for rb storage. |
859 kGLES_GrGLStandard == this->glStandard(), | 847 kGLES_GrGLStandard == this->glStandard(), |
860 &msColorFormat, | 848 &msColorFormat, |
861 NULL, | 849 NULL, |
862 NULL)) { | 850 NULL)) { |
863 goto FAILED; | 851 goto FAILED; |
864 } | 852 } |
865 } else { | 853 } else { |
866 idDesc->fRenderFBO.reset(SkRef(idDesc->fTextureFBO.get())); | 854 idDesc->fRTFBOID = idDesc->fTexFBOID; |
867 } | 855 } |
868 | 856 |
869 if (idDesc->fRenderFBO != idDesc->fTextureFBO) { | 857 // below here we may bind the FBO |
| 858 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 859 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
870 SkASSERT(desc.fSampleCnt > 0); | 860 SkASSERT(desc.fSampleCnt > 0); |
871 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); | 861 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); |
872 if (!renderbuffer_storage_msaa(fGLContext, | 862 if (!renderbuffer_storage_msaa(fGLContext, |
873 desc.fSampleCnt, | 863 desc.fSampleCnt, |
874 msColorFormat, | 864 msColorFormat, |
875 desc.fWidth, desc.fHeight)) { | 865 desc.fWidth, desc.fHeight)) { |
876 goto FAILED; | 866 goto FAILED; |
877 } | 867 } |
878 fboTarget = this->bindFBOForAddingAttachments(idDesc->fRenderFBO); | 868 fStats.incRenderTargetBinds(); |
879 GL_CALL(FramebufferRenderbuffer(fboTarget, | 869 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); |
880 GR_GL_COLOR_ATTACHMENT0, | 870 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
881 GR_GL_RENDERBUFFER, | 871 GR_GL_COLOR_ATTACHMENT0, |
882 idDesc->fMSColorRenderbufferID)); | 872 GR_GL_RENDERBUFFER, |
| 873 idDesc->fMSColorRenderbufferID)); |
883 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 874 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
884 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 875 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
885 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 876 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
886 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 877 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
887 goto FAILED; | 878 goto FAILED; |
888 } | 879 } |
889 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); | 880 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); |
890 } | 881 } |
891 } | 882 } |
892 fboTarget = this->bindFBOForAddingAttachments(idDesc->fTextureFBO); | 883 fStats.incRenderTargetBinds(); |
| 884 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); |
893 | 885 |
894 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { | 886 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { |
895 GL_CALL(FramebufferTexture2DMultisample(fboTarget, | 887 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
896 GR_GL_COLOR_ATTACHMENT0, | 888 GR_GL_COLOR_ATTACHMENT0, |
897 GR_GL_TEXTURE_2D, | 889 GR_GL_TEXTURE_2D, |
898 texID, 0, desc.fSampleCnt)); | 890 texID, 0, desc.fSampleCnt)); |
899 } else { | 891 } else { |
900 GL_CALL(FramebufferTexture2D(fboTarget, | 892 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
901 GR_GL_COLOR_ATTACHMENT0, | 893 GR_GL_COLOR_ATTACHMENT0, |
902 GR_GL_TEXTURE_2D, | 894 GR_GL_TEXTURE_2D, |
903 texID, 0)); | 895 texID, 0)); |
904 } | 896 } |
905 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 897 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
906 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 898 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
907 GL_CALL_RET(status, CheckFramebufferStatus(fboTarget)); | 899 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
908 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 900 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
909 goto FAILED; | 901 goto FAILED; |
910 } | 902 } |
911 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); | 903 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); |
912 } | 904 } |
913 | 905 |
914 return true; | 906 return true; |
915 | 907 |
916 FAILED: | 908 FAILED: |
917 if (idDesc->fMSColorRenderbufferID) { | 909 if (idDesc->fMSColorRenderbufferID) { |
918 GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); | 910 GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); |
919 } | 911 } |
920 if (idDesc->fRenderFBO) { | 912 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
921 idDesc->fRenderFBO->release(this->glInterface()); | 913 GL_CALL(DeleteFramebuffers(1, &idDesc->fRTFBOID)); |
922 } | 914 } |
923 if (idDesc->fTextureFBO) { | 915 if (idDesc->fTexFBOID) { |
924 idDesc->fTextureFBO->release(this->glInterface()); | 916 GL_CALL(DeleteFramebuffers(1, &idDesc->fTexFBOID)); |
925 } | 917 } |
926 return false; | 918 return false; |
927 } | 919 } |
928 | 920 |
929 // good to set a break-point here to know when createTexture fails | 921 // good to set a break-point here to know when createTexture fails |
930 static GrTexture* return_null_texture() { | 922 static GrTexture* return_null_texture() { |
931 // SkDEBUGFAIL("null texture"); | 923 // SkDEBUGFAIL("null texture"); |
932 return NULL; | 924 return NULL; |
933 } | 925 } |
934 | 926 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 get_stencil_rb_sizes(this->glInterface(), &format); | 1179 get_stencil_rb_sizes(this->glInterface(), &format); |
1188 SkAutoTUnref<GrGLStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, | 1180 SkAutoTUnref<GrGLStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
1189 (this, sbDesc, width, height,
samples, format))); | 1181 (this, sbDesc, width, height,
samples, format))); |
1190 if (this->attachStencilBufferToRenderTarget(sb, rt)) { | 1182 if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
1191 fLastSuccessfulStencilFmtIdx = sIdx; | 1183 fLastSuccessfulStencilFmtIdx = sIdx; |
1192 rt->renderTargetPriv().didAttachStencilBuffer(sb); | 1184 rt->renderTargetPriv().didAttachStencilBuffer(sb); |
1193 | 1185 |
1194 // Clear the stencil buffer. We use a special purpose FBO for th
is so that the | 1186 // Clear the stencil buffer. We use a special purpose FBO for th
is so that the |
1195 // entire stencil buffer is cleared, even if it is attached to a
n FBO with a | 1187 // entire stencil buffer is cleared, even if it is attached to a
n FBO with a |
1196 // smaller color target. | 1188 // smaller color target. |
1197 if (!fStencilClearFBO) { | 1189 if (0 == fStencilClearFBOID) { |
1198 fStencilClearFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterfac
e()))); | 1190 GL_CALL(GenFramebuffers(1, &fStencilClearFBOID)); |
1199 } | 1191 } |
1200 SkASSERT(fStencilClearFBO->isValid()); | |
1201 GrGLenum fboTarget = this->bindFBOForAddingAttachments(fStencilC
learFBO); | |
1202 | 1192 |
1203 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1193 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID)); |
| 1194 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1195 fStats.incRenderTargetBinds(); |
| 1196 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1204 GR_GL_STENCIL_ATTACHMENT, | 1197 GR_GL_STENCIL_ATTACHMENT, |
1205 GR_GL_RENDERBUFFER, sbDesc.fRend
erbufferID)); | 1198 GR_GL_RENDERBUFFER, sbDesc.fRend
erbufferID)); |
1206 if (sFmt.fPacked) { | 1199 if (sFmt.fPacked) { |
1207 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1200 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1208 GR_GL_DEPTH_ATTACHMENT, | 1201 GR_GL_DEPTH_ATTACHMENT, |
1209 GR_GL_RENDERBUFFER, sbDesc.f
RenderbufferID)); | 1202 GR_GL_RENDERBUFFER, sbDesc.f
RenderbufferID)); |
1210 } | 1203 } |
1211 | 1204 |
1212 GL_CALL(ClearStencil(0)); | 1205 GL_CALL(ClearStencil(0)); |
1213 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | 1206 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
1214 | 1207 |
1215 // Unbind the SB from the FBO so that we don't keep it alive. | 1208 // Unbind the SB from the FBO so that we don't keep it alive. |
1216 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1209 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1217 GR_GL_STENCIL_ATTACHMENT, | 1210 GR_GL_STENCIL_ATTACHMENT, |
1218 GR_GL_RENDERBUFFER, 0)); | 1211 GR_GL_RENDERBUFFER, 0)); |
1219 if (sFmt.fPacked) { | 1212 if (sFmt.fPacked) { |
1220 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1213 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1221 GR_GL_DEPTH_ATTACHMENT, | 1214 GR_GL_DEPTH_ATTACHMENT, |
1222 GR_GL_RENDERBUFFER, 0)); | 1215 GR_GL_RENDERBUFFER, 0)); |
1223 } | 1216 } |
1224 | 1217 |
1225 return true; | 1218 return true; |
1226 } | 1219 } |
1227 // Remove the scratch key from this resource so we don't grab it fro
m the cache ever | 1220 // Remove the scratch key from this resource so we don't grab it fro
m the cache ever |
1228 // again. | 1221 // again. |
1229 sb->resourcePriv().removeScratchKey(); | 1222 sb->resourcePriv().removeScratchKey(); |
1230 // Set this to 0 since we handed the valid ID off to the failed sten
cil buffer resource. | 1223 // Set this to 0 since we handed the valid ID off to the failed sten
cil buffer resource. |
1231 sbDesc.fRenderbufferID = 0; | 1224 sbDesc.fRenderbufferID = 0; |
1232 } | 1225 } |
1233 } | 1226 } |
1234 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); | 1227 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); |
1235 return false; | 1228 return false; |
1236 } | 1229 } |
1237 | 1230 |
1238 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar
get* rt) { | 1231 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar
get* rt) { |
1239 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); | 1232 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
| 1233 |
| 1234 GrGLuint fbo = glrt->renderFBOID(); |
| 1235 |
1240 if (NULL == sb) { | 1236 if (NULL == sb) { |
1241 if (rt->renderTargetPriv().getStencilBuffer()) { | 1237 if (rt->renderTargetPriv().getStencilBuffer()) { |
1242 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1238 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1243 GR_GL_STENCIL_ATTACHMENT, | 1239 GR_GL_STENCIL_ATTACHMENT, |
1244 GR_GL_RENDERBUFFER, 0)); | 1240 GR_GL_RENDERBUFFER, 0)); |
1245 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1241 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1246 GR_GL_DEPTH_ATTACHMENT, | 1242 GR_GL_DEPTH_ATTACHMENT, |
1247 GR_GL_RENDERBUFFER, 0)); | 1243 GR_GL_RENDERBUFFER, 0)); |
1248 #ifdef SK_DEBUG | 1244 #ifdef SK_DEBUG |
1249 GrGLenum status; | 1245 GrGLenum status; |
1250 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1246 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1251 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | 1247 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
1252 #endif | 1248 #endif |
1253 } | 1249 } |
1254 return true; | 1250 return true; |
1255 } else { | 1251 } else { |
1256 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); | 1252 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
1257 GrGLuint rb = glsb->renderbufferID(); | 1253 GrGLuint rb = glsb->renderbufferID(); |
1258 | 1254 |
1259 GrGLenum fboTarget = this->bindFBOForAddingAttachments(glrt->renderFBO()
); | 1255 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
1260 | 1256 fStats.incRenderTargetBinds(); |
1261 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1257 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1258 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1262 GR_GL_STENCIL_ATTACHMENT, | 1259 GR_GL_STENCIL_ATTACHMENT, |
1263 GR_GL_RENDERBUFFER, rb)); | 1260 GR_GL_RENDERBUFFER, rb)); |
1264 if (glsb->format().fPacked) { | 1261 if (glsb->format().fPacked) { |
1265 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1262 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1266 GR_GL_DEPTH_ATTACHMENT, | 1263 GR_GL_DEPTH_ATTACHMENT, |
1267 GR_GL_RENDERBUFFER, rb)); | 1264 GR_GL_RENDERBUFFER, rb)); |
1268 } else { | 1265 } else { |
1269 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1266 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1270 GR_GL_DEPTH_ATTACHMENT, | 1267 GR_GL_DEPTH_ATTACHMENT, |
1271 GR_GL_RENDERBUFFER, 0)); | 1268 GR_GL_RENDERBUFFER, 0)); |
1272 } | 1269 } |
1273 | 1270 |
1274 GrGLenum status; | 1271 GrGLenum status; |
1275 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(),
glsb->format())) { | 1272 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(),
glsb->format())) { |
1276 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1273 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1277 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 1274 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
1278 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1275 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1279 GR_GL_STENCIL_ATTACHMENT, | 1276 GR_GL_STENCIL_ATTACHMENT, |
1280 GR_GL_RENDERBUFFER, 0)); | 1277 GR_GL_RENDERBUFFER, 0)); |
1281 if (glsb->format().fPacked) { | 1278 if (glsb->format().fPacked) { |
1282 GL_CALL(FramebufferRenderbuffer(fboTarget, | 1279 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1283 GR_GL_DEPTH_ATTACHMENT, | 1280 GR_GL_DEPTH_ATTACHMENT, |
1284 GR_GL_RENDERBUFFER, 0)); | 1281 GR_GL_RENDERBUFFER, 0)); |
1285 } | 1282 } |
1286 return false; | 1283 return false; |
1287 } else { | 1284 } else { |
1288 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( | 1285 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( |
1289 rt->config(), | 1286 rt->config(), |
1290 glsb->format()); | 1287 glsb->format()); |
1291 } | 1288 } |
1292 } | 1289 } |
1293 return true; | 1290 return true; |
1294 } | 1291 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 | 1416 |
1420 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr
acker); | 1417 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr
acker); |
1421 | 1418 |
1422 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); | 1419 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); |
1423 this->flushStencil(pipeline.getStencil()); | 1420 this->flushStencil(pipeline.getStencil()); |
1424 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); | 1421 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); |
1425 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), isLineDraw); | 1422 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), isLineDraw); |
1426 | 1423 |
1427 // This must come after textures are flushed because a texture may need | 1424 // This must come after textures are flushed because a texture may need |
1428 // to be msaa-resolved (which will modify bound FBO state). | 1425 // to be msaa-resolved (which will modify bound FBO state). |
1429 this->prepareToDrawToRenderTarget(glRT, NULL); | 1426 this->flushRenderTarget(glRT, NULL); |
1430 | 1427 |
1431 return true; | 1428 return true; |
1432 } | 1429 } |
1433 | 1430 |
1434 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, | 1431 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, |
1435 const GrDrawTarget::DrawInfo& info, | 1432 const GrDrawTarget::DrawInfo& info, |
1436 size_t* indexOffsetInBytes) { | 1433 size_t* indexOffsetInBytes) { |
1437 GrGLVertexBuffer* vbuf; | 1434 GrGLVertexBuffer* vbuf; |
1438 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); | 1435 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); |
1439 | 1436 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 // flushScissor expects rect to be clipped to the target. | 1513 // flushScissor expects rect to be clipped to the target. |
1517 clippedRect = *rect; | 1514 clippedRect = *rect; |
1518 SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height()); | 1515 SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height()); |
1519 if (clippedRect.intersect(rtRect)) { | 1516 if (clippedRect.intersect(rtRect)) { |
1520 rect = &clippedRect; | 1517 rect = &clippedRect; |
1521 } else { | 1518 } else { |
1522 return; | 1519 return; |
1523 } | 1520 } |
1524 } | 1521 } |
1525 | 1522 |
1526 this->prepareToDrawToRenderTarget(glRT, rect); | 1523 this->flushRenderTarget(glRT, rect); |
1527 GrScissorState scissorState; | 1524 GrScissorState scissorState; |
1528 if (rect) { | 1525 if (rect) { |
1529 scissorState.set(*rect); | 1526 scissorState.set(*rect); |
1530 } | 1527 } |
1531 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); | 1528 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); |
1532 | 1529 |
1533 GrGLfloat r, g, b, a; | 1530 GrGLfloat r, g, b, a; |
1534 static const GrGLfloat scale255 = 1.f / 255.f; | 1531 static const GrGLfloat scale255 = 1.f / 255.f; |
1535 a = GrColorUnpackA(color) * scale255; | 1532 a = GrColorUnpackA(color) * scale255; |
1536 GrGLfloat scaleRGB = scale255; | 1533 GrGLfloat scaleRGB = scale255; |
1537 r = GrColorUnpackR(color) * scaleRGB; | 1534 r = GrColorUnpackR(color) * scaleRGB; |
1538 g = GrColorUnpackG(color) * scaleRGB; | 1535 g = GrColorUnpackG(color) * scaleRGB; |
1539 b = GrColorUnpackB(color) * scaleRGB; | 1536 b = GrColorUnpackB(color) * scaleRGB; |
1540 | 1537 |
1541 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); | 1538 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
1542 fHWWriteToColor = kYes_TriState; | 1539 fHWWriteToColor = kYes_TriState; |
1543 GL_CALL(ClearColor(r, g, b, a)); | 1540 GL_CALL(ClearColor(r, g, b, a)); |
1544 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); | 1541 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
1545 } | 1542 } |
1546 | 1543 |
1547 void GrGLGpu::discard(GrRenderTarget* renderTarget) { | 1544 void GrGLGpu::discard(GrRenderTarget* renderTarget) { |
1548 SkASSERT(renderTarget); | 1545 SkASSERT(renderTarget); |
1549 if (!this->caps()->discardRenderTargetSupport()) { | 1546 if (!this->caps()->discardRenderTargetSupport()) { |
1550 return; | 1547 return; |
1551 } | 1548 } |
1552 | 1549 |
1553 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); | 1550 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
1554 GrGLenum fboTarget = this->bindFBO(kDraw_FBOBinding, glRT->renderFBO()); | 1551 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { |
| 1552 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1553 fStats.incRenderTargetBinds(); |
| 1554 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); |
| 1555 } |
1555 switch (this->glCaps().invalidateFBType()) { | 1556 switch (this->glCaps().invalidateFBType()) { |
1556 case GrGLCaps::kNone_InvalidateFBType: | 1557 case GrGLCaps::kNone_InvalidateFBType: |
1557 SkFAIL("Should never get here."); | 1558 SkFAIL("Should never get here."); |
1558 break; | 1559 break; |
1559 case GrGLCaps::kInvalidate_InvalidateFBType: | 1560 case GrGLCaps::kInvalidate_InvalidateFBType: |
1560 if (glRT->renderFBO()->isDefaultFramebuffer()) { | 1561 if (0 == glRT->renderFBOID()) { |
1561 // When rendering to the default framebuffer the legal values f
or attachments | 1562 // When rendering to the default framebuffer the legal values f
or attachments |
1562 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment | 1563 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment |
1563 // types. | 1564 // types. |
1564 static const GrGLenum attachments[] = { GR_GL_COLOR }; | 1565 static const GrGLenum attachments[] = { GR_GL_COLOR }; |
1565 GL_CALL(InvalidateFramebuffer(fboTarget, SK_ARRAY_COUNT(attachme
nts), | 1566 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(
attachments), |
1566 attachments)); | 1567 attachments)); |
1567 } else { | 1568 } else { |
1568 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0
}; | 1569 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0
}; |
1569 GL_CALL(InvalidateFramebuffer(fboTarget, SK_ARRAY_COUNT(attachme
nts), | 1570 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(
attachments), |
1570 attachments)); | 1571 attachments)); |
1571 } | 1572 } |
1572 break; | 1573 break; |
1573 case GrGLCaps::kDiscard_InvalidateFBType: { | 1574 case GrGLCaps::kDiscard_InvalidateFBType: { |
1574 if (glRT->renderFBO()->isDefaultFramebuffer()) { | 1575 if (0 == glRT->renderFBOID()) { |
1575 // When rendering to the default framebuffer the legal values f
or attachments | 1576 // When rendering to the default framebuffer the legal values f
or attachments |
1576 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment | 1577 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari
ous FBO attachment |
1577 // types. See glDiscardFramebuffer() spec. | 1578 // types. See glDiscardFramebuffer() spec. |
1578 static const GrGLenum attachments[] = { GR_GL_COLOR }; | 1579 static const GrGLenum attachments[] = { GR_GL_COLOR }; |
1579 GL_CALL(DiscardFramebuffer(fboTarget, SK_ARRAY_COUNT(attachments
), | 1580 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(att
achments), |
1580 attachments)); | 1581 attachments)); |
1581 } else { | 1582 } else { |
1582 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0
}; | 1583 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0
}; |
1583 GL_CALL(DiscardFramebuffer(fboTarget, SK_ARRAY_COUNT(attachments
), | 1584 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(att
achments), |
1584 attachments)); | 1585 attachments)); |
1585 } | 1586 } |
1586 break; | 1587 break; |
1587 } | 1588 } |
1588 } | 1589 } |
1589 renderTarget->flagAsResolved(); | 1590 renderTarget->flagAsResolved(); |
1590 } | 1591 } |
1591 | 1592 |
1592 | 1593 |
1593 void GrGLGpu::clearStencil(GrRenderTarget* target) { | 1594 void GrGLGpu::clearStencil(GrRenderTarget* target) { |
1594 if (NULL == target) { | 1595 if (NULL == target) { |
1595 return; | 1596 return; |
1596 } | 1597 } |
1597 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); | 1598 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
1598 this->prepareToDrawToRenderTarget(glRT, &SkIRect::EmptyIRect()); | 1599 this->flushRenderTarget(glRT, &SkIRect::EmptyIRect()); |
1599 | 1600 |
1600 this->disableScissor(); | 1601 this->disableScissor(); |
1601 | 1602 |
1602 GL_CALL(StencilMask(0xffffffff)); | 1603 GL_CALL(StencilMask(0xffffffff)); |
1603 GL_CALL(ClearStencil(0)); | 1604 GL_CALL(ClearStencil(0)); |
1604 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | 1605 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
1605 fHWStencilSettings.invalidate(); | 1606 fHWStencilSettings.invalidate(); |
1606 } | 1607 } |
1607 | 1608 |
1608 void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bo
ol insideClip) { | 1609 void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bo
ol insideClip) { |
(...skipping 15 matching lines...) Expand all Loading... |
1624 // zero the client's clip bits. So we just clear the whole thing. | 1625 // zero the client's clip bits. So we just clear the whole thing. |
1625 static const GrGLint clipStencilMask = ~0; | 1626 static const GrGLint clipStencilMask = ~0; |
1626 #endif | 1627 #endif |
1627 GrGLint value; | 1628 GrGLint value; |
1628 if (insideClip) { | 1629 if (insideClip) { |
1629 value = (1 << (stencilBitCount - 1)); | 1630 value = (1 << (stencilBitCount - 1)); |
1630 } else { | 1631 } else { |
1631 value = 0; | 1632 value = 0; |
1632 } | 1633 } |
1633 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); | 1634 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
1634 this->prepareToDrawToRenderTarget(glRT, &SkIRect::EmptyIRect()); | 1635 this->flushRenderTarget(glRT, &SkIRect::EmptyIRect()); |
1635 | 1636 |
1636 GrScissorState scissorState; | 1637 GrScissorState scissorState; |
1637 scissorState.set(rect); | 1638 scissorState.set(rect); |
1638 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); | 1639 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); |
1639 | 1640 |
1640 GL_CALL(StencilMask((uint32_t) clipStencilMask)); | 1641 GL_CALL(StencilMask((uint32_t) clipStencilMask)); |
1641 GL_CALL(ClearStencil(value)); | 1642 GL_CALL(ClearStencil(value)); |
1642 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | 1643 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
1643 fHWStencilSettings.invalidate(); | 1644 fHWStencilSettings.invalidate(); |
1644 } | 1645 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 size_t bpp = GrBytesPerPixel(config); | 1695 size_t bpp = GrBytesPerPixel(config); |
1695 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, | 1696 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, |
1696 &left, &top, &width, &height, | 1697 &left, &top, &width, &height, |
1697 const_cast<const void**>(&buffer), | 1698 const_cast<const void**>(&buffer), |
1698 &rowBytes)) { | 1699 &rowBytes)) { |
1699 return false; | 1700 return false; |
1700 } | 1701 } |
1701 | 1702 |
1702 // resolve the render target if necessary | 1703 // resolve the render target if necessary |
1703 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); | 1704 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
1704 if (tgt->getResolveType() == GrGLRenderTarget::kCantResolve_ResolveType) { | 1705 switch (tgt->getResolveType()) { |
1705 return false; | 1706 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1707 return false; |
| 1708 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1709 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); |
| 1710 break; |
| 1711 case GrGLRenderTarget::kCanResolve_ResolveType: |
| 1712 this->onResolveRenderTarget(tgt); |
| 1713 // we don't track the state of the READ FBO ID. |
| 1714 fStats.incRenderTargetBinds(); |
| 1715 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1716 tgt->textureFBOID())); |
| 1717 break; |
| 1718 default: |
| 1719 SkFAIL("Unknown resolve type"); |
1706 } | 1720 } |
1707 if (tgt->getResolveType() == GrGLRenderTarget::kCanResolve_ResolveType) { | |
1708 this->onResolveRenderTarget(tgt); | |
1709 } | |
1710 this->bindFBO(kRead_FBOBinding, tgt->textureFBO()); | |
1711 | 1721 |
1712 const GrGLIRect& glvp = tgt->getViewport(); | 1722 const GrGLIRect& glvp = tgt->getViewport(); |
1713 | 1723 |
1714 // the read rect is viewport-relative | 1724 // the read rect is viewport-relative |
1715 GrGLIRect readRect; | 1725 GrGLIRect readRect; |
1716 readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); | 1726 readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); |
1717 | 1727 |
1718 size_t tightRowBytes = bpp * width; | 1728 size_t tightRowBytes = bpp * width; |
1719 if (0 == rowBytes) { | 1729 if (0 == rowBytes) { |
1720 rowBytes = tightRowBytes; | 1730 rowBytes = tightRowBytes; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 char* bottom = top + (height - 1) * rowBytes; | 1775 char* bottom = top + (height - 1) * rowBytes; |
1766 for (int y = 0; y < halfY; y++) { | 1776 for (int y = 0; y < halfY; y++) { |
1767 memcpy(tmpRow, top, tightRowBytes); | 1777 memcpy(tmpRow, top, tightRowBytes); |
1768 memcpy(top, bottom, tightRowBytes); | 1778 memcpy(top, bottom, tightRowBytes); |
1769 memcpy(bottom, tmpRow, tightRowBytes); | 1779 memcpy(bottom, tmpRow, tightRowBytes); |
1770 top += rowBytes; | 1780 top += rowBytes; |
1771 bottom -= rowBytes; | 1781 bottom -= rowBytes; |
1772 } | 1782 } |
1773 } | 1783 } |
1774 } else { | 1784 } else { |
1775 SkASSERT(readDst != buffer); | 1785 SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes); |
1776 SkASSERT(rowBytes != tightRowBytes); | |
1777 // copy from readDst to buffer while flipping y | 1786 // copy from readDst to buffer while flipping y |
1778 // const int halfY = height >> 1; | 1787 // const int halfY = height >> 1; |
1779 const char* src = reinterpret_cast<const char*>(readDst); | 1788 const char* src = reinterpret_cast<const char*>(readDst); |
1780 char* dst = reinterpret_cast<char*>(buffer); | 1789 char* dst = reinterpret_cast<char*>(buffer); |
1781 if (flipY) { | 1790 if (flipY) { |
1782 dst += (height-1) * rowBytes; | 1791 dst += (height-1) * rowBytes; |
1783 } | 1792 } |
1784 for (int y = 0; y < height; y++) { | 1793 for (int y = 0; y < height; y++) { |
1785 memcpy(dst, src, tightRowBytes); | 1794 memcpy(dst, src, tightRowBytes); |
1786 src += readDstRowBytes; | 1795 src += readDstRowBytes; |
1787 if (!flipY) { | 1796 if (!flipY) { |
1788 dst += rowBytes; | 1797 dst += rowBytes; |
1789 } else { | 1798 } else { |
1790 dst -= rowBytes; | 1799 dst -= rowBytes; |
1791 } | 1800 } |
1792 } | 1801 } |
1793 } | 1802 } |
1794 return true; | 1803 return true; |
1795 } | 1804 } |
1796 | 1805 |
1797 GrGLenum GrGLGpu::bindFBO(FBOBinding binding, const GrGLFBO* fbo) { | 1806 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ |
1798 SkASSERT(fbo); | |
1799 SkASSERT(fbo->isValid()); | |
1800 GrGLenum target; | |
1801 HWFBOBinding* hwFBOState; | |
1802 if (!this->glCaps().usesMSAARenderBuffers()) { | |
1803 target = GR_GL_FRAMEBUFFER; | |
1804 hwFBOState = &fHWFBOBinding[0]; | |
1805 } else { | |
1806 target = kDraw_FBOBinding == binding ? GR_GL_DRAW_FRAMEBUFFER : GR_GL_RE
AD_FRAMEBUFFER; | |
1807 hwFBOState = &fHWFBOBinding[binding]; | |
1808 } | |
1809 | 1807 |
1810 if (hwFBOState->fFBO != fbo) { | 1808 SkASSERT(target); |
| 1809 |
| 1810 uint32_t rtID = target->getUniqueID(); |
| 1811 if (fHWBoundRenderTargetUniqueID != rtID) { |
1811 fStats.incRenderTargetBinds(); | 1812 fStats.incRenderTargetBinds(); |
1812 GL_CALL(BindFramebuffer(target, fbo->fboID())); | 1813 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); |
1813 hwFBOState->fFBO.reset(SkRef(fbo)); | 1814 #ifdef SK_DEBUG |
1814 } | 1815 // don't do this check in Chromium -- this is causing |
1815 return target; | 1816 // lots of repeated command buffer flushes when the compositor is |
1816 } | 1817 // rendering with Ganesh, which is really slow; even too slow for |
1817 | 1818 // Debug mode. |
1818 GrGLenum GrGLGpu::bindFBOForAddingAttachments(const GrGLFBO* fbo) { | 1819 if (!this->glContext().isChromium()) { |
1819 if (this->glCaps().bindFBOToReadAndDrawForAddingAttachments()) { | 1820 GrGLenum status; |
1820 if (fHWFBOBinding[kDraw_FBOBinding].fFBO != fbo || | 1821 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1821 fHWFBOBinding[kRead_FBOBinding].fFBO != fbo) { | 1822 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
1822 fStats.incRenderTargetBinds(); | 1823 SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x
\n", status); |
1823 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo->fboID())); | 1824 } |
1824 fHWFBOBinding[kDraw_FBOBinding].fFBO.reset(SkRef(fbo)); | |
1825 fHWFBOBinding[kRead_FBOBinding].fFBO.reset(SkRef(fbo)); | |
1826 } | 1825 } |
1827 return GR_GL_FRAMEBUFFER; | 1826 #endif |
1828 } else { | 1827 fHWBoundRenderTargetUniqueID = rtID; |
1829 return this->bindFBO(kDraw_FBOBinding, fbo); | 1828 const GrGLIRect& vp = target->getViewport(); |
1830 } | 1829 if (fHWViewport != vp) { |
1831 } | 1830 vp.pushToGLViewport(this->glInterface()); |
1832 | 1831 fHWViewport = vp; |
1833 void GrGLGpu::setViewport(const GrGLIRect& viewport) { | |
1834 if (viewport != fHWViewport) { | |
1835 viewport.pushToGLViewport(this->glInterface()); | |
1836 fHWViewport = viewport; | |
1837 } | |
1838 } | |
1839 | |
1840 void GrGLGpu::prepareToDrawToRenderTarget(GrGLRenderTarget* target, const SkIRec
t* bound) { | |
1841 SkASSERT(target); | |
1842 this->bindFBO(kDraw_FBOBinding, target->renderFBO()); | |
1843 | |
1844 #ifdef SK_DEBUG | |
1845 // don't do this check in Chromium -- this is causing | |
1846 // lots of repeated command buffer flushes when the compositor is | |
1847 // rendering with Ganesh, which is really slow; even too slow for | |
1848 // Debug mode. | |
1849 if (!this->glContext().isChromium()) { | |
1850 GrGLenum status; | |
1851 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | |
1852 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | |
1853 SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x\n",
status); | |
1854 } | 1832 } |
1855 } | 1833 } |
1856 #endif | |
1857 this->setViewport(target->getViewport()); | |
1858 if (NULL == bound || !bound->isEmpty()) { | 1834 if (NULL == bound || !bound->isEmpty()) { |
1859 target->flagAsNeedingResolve(bound); | 1835 target->flagAsNeedingResolve(bound); |
1860 } | 1836 } |
1861 | 1837 |
1862 GrTexture *texture = target->asTexture(); | 1838 GrTexture *texture = target->asTexture(); |
1863 if (texture) { | 1839 if (texture) { |
1864 texture->texturePriv().dirtyMipMaps(true); | 1840 texture->texturePriv().dirtyMipMaps(true); |
1865 } | 1841 } |
1866 } | 1842 } |
1867 | 1843 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 | 1912 |
1937 void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) { | 1913 void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) { |
1938 this->flushColorWrite(false); | 1914 this->flushColorWrite(false); |
1939 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 1915 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
1940 | 1916 |
1941 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); | 1917 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); |
1942 SkISize size = SkISize::Make(rt->width(), rt->height()); | 1918 SkISize size = SkISize::Make(rt->width(), rt->height()); |
1943 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o
rigin()); | 1919 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o
rigin()); |
1944 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); | 1920 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); |
1945 this->flushHWAAState(rt, state.fUseHWAA, false); | 1921 this->flushHWAAState(rt, state.fUseHWAA, false); |
1946 this->prepareToDrawToRenderTarget(rt, NULL); | 1922 this->flushRenderTarget(rt, NULL); |
1947 | 1923 |
1948 fPathRendering->stencilPath(path, *state.fStencil); | 1924 fPathRendering->stencilPath(path, *state.fStencil); |
1949 } | 1925 } |
1950 | 1926 |
1951 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, | 1927 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, |
1952 const GrStencilSettings& stencil) { | 1928 const GrStencilSettings& stencil) { |
1953 if (!this->flushGLState(args, false)) { | 1929 if (!this->flushGLState(args, false)) { |
1954 return; | 1930 return; |
1955 } | 1931 } |
1956 fPathRendering->drawPath(path, stencil); | 1932 fPathRendering->drawPath(path, stencil); |
(...skipping 12 matching lines...) Expand all Loading... |
1969 } | 1945 } |
1970 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, | 1946 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, |
1971 transformType, count, stencil); | 1947 transformType, count, stencil); |
1972 } | 1948 } |
1973 | 1949 |
1974 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { | 1950 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |
1975 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1951 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
1976 if (rt->needsResolve()) { | 1952 if (rt->needsResolve()) { |
1977 // Some extensions automatically resolves the texture when it is read. | 1953 // Some extensions automatically resolves the texture when it is read. |
1978 if (this->glCaps().usesMSAARenderBuffers()) { | 1954 if (this->glCaps().usesMSAARenderBuffers()) { |
1979 SkASSERT(rt->textureFBO() != rt->renderFBO()); | 1955 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
1980 this->bindFBO(kRead_FBOBinding, rt->renderFBO()); | 1956 fStats.incRenderTargetBinds(); |
1981 this->bindFBO(kDraw_FBOBinding, rt->textureFBO()); | 1957 fStats.incRenderTargetBinds(); |
| 1958 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 1959 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
| 1960 // make sure we go through flushRenderTarget() since we've modified |
| 1961 // the bound DRAW FBO ID. |
| 1962 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
1982 const GrGLIRect& vp = rt->getViewport(); | 1963 const GrGLIRect& vp = rt->getViewport(); |
1983 const SkIRect dirtyRect = rt->getResolveRect(); | 1964 const SkIRect dirtyRect = rt->getResolveRect(); |
1984 | 1965 |
1985 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { | 1966 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { |
1986 // Apple's extension uses the scissor as the blit bounds. | 1967 // Apple's extension uses the scissor as the blit bounds. |
1987 GrScissorState scissorState; | 1968 GrScissorState scissorState; |
1988 scissorState.set(dirtyRect); | 1969 scissorState.set(dirtyRect); |
1989 this->flushScissor(scissorState, vp, rt->origin()); | 1970 this->flushScissor(scissorState, vp, rt->origin()); |
1990 GL_CALL(ResolveMultisampleFramebuffer()); | 1971 GL_CALL(ResolveMultisampleFramebuffer()); |
1991 } else { | 1972 } else { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2534 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSub
Image | 2515 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSub
Image |
2535 // and BGRA isn't in the spec. There doesn't appear to be any extension that
adds it. Perhaps | 2516 // and BGRA isn't in the spec. There doesn't appear to be any extension that
adds it. Perhaps |
2536 // many drivers would allow it to work, but ANGLE does not. | 2517 // many drivers would allow it to work, but ANGLE does not. |
2537 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalF
ormat() && | 2518 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalF
ormat() && |
2538 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig =
= src->config())) { | 2519 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig =
= src->config())) { |
2539 return false; | 2520 return false; |
2540 } | 2521 } |
2541 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->as
RenderTarget()); | 2522 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->as
RenderTarget()); |
2542 // If dst is multisampled (and uses an extension where there is a separate M
SAA renderbuffer) | 2523 // If dst is multisampled (and uses an extension where there is a separate M
SAA renderbuffer) |
2543 // then we don't want to copy to the texture but to the MSAA buffer. | 2524 // then we don't want to copy to the texture but to the MSAA buffer. |
2544 if (dstRT && dstRT->renderFBO() != dstRT->textureFBO()) { | 2525 if (dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) { |
2545 return false; | 2526 return false; |
2546 } | 2527 } |
2547 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); | 2528 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); |
2548 // If the src is multisampled (and uses an extension where there is a separa
te MSAA | 2529 // If the src is multisampled (and uses an extension where there is a separa
te MSAA |
2549 // renderbuffer) then it is an invalid operation to call CopyTexSubImage | 2530 // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
2550 if (srcRT && srcRT->renderFBO() != srcRT->textureFBO()) { | 2531 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
2551 return false; | 2532 return false; |
2552 } | 2533 } |
2553 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && | 2534 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && |
2554 dst->asTexture() && | 2535 dst->asTexture() && |
2555 dst->origin() == src->origin() && | 2536 dst->origin() == src->origin() && |
2556 !GrPixelConfigIsCompressed(src->config())) { | 2537 !GrPixelConfigIsCompressed(src->config())) { |
2557 return true; | 2538 return true; |
2558 } else { | 2539 } else { |
2559 return false; | 2540 return false; |
2560 } | 2541 } |
2561 } | 2542 } |
2562 | 2543 |
2563 } | 2544 } |
2564 | 2545 |
2565 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is | 2546 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is |
2566 // relative to is output. | 2547 // relative to is output. |
2567 GrGLGpu::FBOBinding GrGLGpu::bindSurfaceAsFBOForCopy(GrSurface* surface, FBOBind
ing binding, | 2548 GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLI
Rect* viewport, |
2568 GrGLIRect* viewport) { | 2549 TempFBOTarget tempFBOTarget) { |
2569 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); | 2550 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); |
2570 if (NULL == rt) { | 2551 if (NULL == rt) { |
2571 SkASSERT(surface->asTexture()); | 2552 SkASSERT(surface->asTexture()); |
2572 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); | 2553 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); |
2573 GrGLFBO* tempFBO; | 2554 GrGLuint* tempFBOID; |
| 2555 tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTem
pDstFBOID; |
2574 | 2556 |
2575 if (kRead_FBOBinding == binding) { | 2557 if (0 == *tempFBOID) { |
2576 if (!fTempSrcFBO) { | 2558 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID)); |
2577 fTempSrcFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface()))); | |
2578 SkASSERT(fTempSrcFBO->isValid()); | |
2579 } | |
2580 tempFBO = fTempSrcFBO; | |
2581 } else { | |
2582 SkASSERT(kDraw_FBOBinding == binding); | |
2583 if (!fTempDstFBO) { | |
2584 fTempDstFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface()))); | |
2585 SkASSERT(fTempDstFBO->isValid()); | |
2586 } | |
2587 tempFBO = fTempDstFBO; | |
2588 } | 2559 } |
2589 | 2560 |
2590 GrGLenum target = this->bindFBO(binding, tempFBO); | 2561 fStats.incRenderTargetBinds(); |
2591 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(target, | 2562 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, *tempFBOID)); |
| 2563 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
2592 GR_GL_COLOR_ATTACHM
ENT0, | 2564 GR_GL_COLOR_ATTACHM
ENT0, |
2593 GR_GL_TEXTURE_2D, | 2565 GR_GL_TEXTURE_2D, |
2594 texID, | 2566 texID, |
2595 0)); | 2567 0)); |
2596 viewport->fLeft = 0; | 2568 viewport->fLeft = 0; |
2597 viewport->fBottom = 0; | 2569 viewport->fBottom = 0; |
2598 viewport->fWidth = surface->width(); | 2570 viewport->fWidth = surface->width(); |
2599 viewport->fHeight = surface->height(); | 2571 viewport->fHeight = surface->height(); |
2600 return binding; | 2572 return *tempFBOID; |
2601 } else { | 2573 } else { |
2602 this->bindFBO(binding, rt->renderFBO()); | 2574 GrGLuint tempFBOID = 0; |
| 2575 fStats.incRenderTargetBinds(); |
| 2576 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); |
2603 *viewport = rt->getViewport(); | 2577 *viewport = rt->getViewport(); |
2604 return kInvalidFBOBinding; | 2578 return tempFBOID; |
2605 } | 2579 } |
2606 } | 2580 } |
2607 | 2581 |
2608 void GrGLGpu::unbindSurfaceAsFBOForCopy(FBOBinding binding) { | 2582 void GrGLGpu::unbindTextureFromFBO(GrGLenum fboTarget) { |
2609 if (kInvalidFBOBinding == binding) { | 2583 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
2610 return; | |
2611 } | |
2612 GrGLFBO* tempFBO = kDraw_FBOBinding == binding ? fTempSrcFBO : fTempDstFBO; | |
2613 GrGLenum target = this->bindFBO(binding, tempFBO); | |
2614 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(target, | |
2615 GR_GL_COLOR_ATTACHMENT0
, | 2584 GR_GL_COLOR_ATTACHMENT0
, |
2616 GR_GL_TEXTURE_2D, | 2585 GR_GL_TEXTURE_2D, |
2617 0, | 2586 0, |
2618 0)); | 2587 0)); |
2619 } | 2588 } |
2620 | 2589 |
2621 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc)
{ | 2590 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc)
{ |
2622 // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If
neither are | 2591 // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If
neither are |
2623 // possible and we return false to fallback to creating a render target dst
for render-to- | 2592 // possible and we return false to fallback to creating a render target dst
for render-to- |
2624 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger
ing temporary fbo | 2593 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger
ing temporary fbo |
(...skipping 10 matching lines...) Expand all Loading... |
2635 desc->fConfig = kBGRA_8888_GrPixelConfig; | 2604 desc->fConfig = kBGRA_8888_GrPixelConfig; |
2636 return true; | 2605 return true; |
2637 } | 2606 } |
2638 return false; | 2607 return false; |
2639 } else if (NULL == src->asRenderTarget()) { | 2608 } else if (NULL == src->asRenderTarget()) { |
2640 // CopyTexSubImage2D or fbo blit would require creating a temp fbo for t
he src. | 2609 // CopyTexSubImage2D or fbo blit would require creating a temp fbo for t
he src. |
2641 return false; | 2610 return false; |
2642 } | 2611 } |
2643 | 2612 |
2644 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); | 2613 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); |
2645 if (srcRT && srcRT->renderFBO() != srcRT->textureFBO()) { | 2614 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
2646 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up
for FBO blit or | 2615 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up
for FBO blit or |
2647 // fail. | 2616 // fail. |
2648 if (this->caps()->isConfigRenderable(src->config(), false)) { | 2617 if (this->caps()->isConfigRenderable(src->config(), false)) { |
2649 desc->fOrigin = kDefault_GrSurfaceOrigin; | 2618 desc->fOrigin = kDefault_GrSurfaceOrigin; |
2650 desc->fFlags = kRenderTarget_GrSurfaceFlag; | 2619 desc->fFlags = kRenderTarget_GrSurfaceFlag; |
2651 desc->fConfig = src->config(); | 2620 desc->fConfig = src->config(); |
2652 return true; | 2621 return true; |
2653 } | 2622 } |
2654 return false; | 2623 return false; |
2655 } | 2624 } |
2656 | 2625 |
2657 // We'll do a CopyTexSubImage. Make the dst a plain old texture. | 2626 // We'll do a CopyTexSubImage. Make the dst a plain old texture. |
2658 desc->fConfig = src->config(); | 2627 desc->fConfig = src->config(); |
2659 desc->fOrigin = src->origin(); | 2628 desc->fOrigin = src->origin(); |
2660 desc->fFlags = kNone_GrSurfaceFlags; | 2629 desc->fFlags = kNone_GrSurfaceFlags; |
2661 return true; | 2630 return true; |
2662 } | 2631 } |
2663 | 2632 |
2664 bool GrGLGpu::copySurface(GrSurface* dst, | 2633 bool GrGLGpu::copySurface(GrSurface* dst, |
2665 GrSurface* src, | 2634 GrSurface* src, |
2666 const SkIRect& srcRect, | 2635 const SkIRect& srcRect, |
2667 const SkIPoint& dstPoint) { | 2636 const SkIPoint& dstPoint) { |
2668 bool copied = false; | 2637 bool copied = false; |
2669 if (can_copy_texsubimage(dst, src, this)) { | 2638 if (can_copy_texsubimage(dst, src, this)) { |
| 2639 GrGLuint srcFBO; |
2670 GrGLIRect srcVP; | 2640 GrGLIRect srcVP; |
2671 FBOBinding srcFBOBinding = this->bindSurfaceAsFBOForCopy(src, kRead_FBOB
inding, &srcVP); | 2641 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_Tem
pFBOTarget); |
2672 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); | 2642 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); |
2673 SkASSERT(dstTex); | 2643 SkASSERT(dstTex); |
| 2644 // We modified the bound FBO |
| 2645 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
2674 GrGLIRect srcGLRect; | 2646 GrGLIRect srcGLRect; |
2675 srcGLRect.setRelativeTo(srcVP, | 2647 srcGLRect.setRelativeTo(srcVP, |
2676 srcRect.fLeft, | 2648 srcRect.fLeft, |
2677 srcRect.fTop, | 2649 srcRect.fTop, |
2678 srcRect.width(), | 2650 srcRect.width(), |
2679 srcRect.height(), | 2651 srcRect.height(), |
2680 src->origin()); | 2652 src->origin()); |
2681 | 2653 |
2682 this->setScratchTextureUnit(); | 2654 this->setScratchTextureUnit(); |
2683 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); | 2655 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); |
2684 GrGLint dstY; | 2656 GrGLint dstY; |
2685 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { | 2657 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { |
2686 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); | 2658 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); |
2687 } else { | 2659 } else { |
2688 dstY = dstPoint.fY; | 2660 dstY = dstPoint.fY; |
2689 } | 2661 } |
2690 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, | 2662 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, |
2691 dstPoint.fX, dstY, | 2663 dstPoint.fX, dstY, |
2692 srcGLRect.fLeft, srcGLRect.fBottom, | 2664 srcGLRect.fLeft, srcGLRect.fBottom, |
2693 srcGLRect.fWidth, srcGLRect.fHeight)); | 2665 srcGLRect.fWidth, srcGLRect.fHeight)); |
2694 copied = true; | 2666 copied = true; |
2695 this->unbindSurfaceAsFBOForCopy(srcFBOBinding); | 2667 if (srcFBO) { |
| 2668 this->unbindTextureFromFBO(GR_GL_FRAMEBUFFER); |
| 2669 } |
2696 } else if (can_blit_framebuffer(dst, src, this)) { | 2670 } else if (can_blit_framebuffer(dst, src, this)) { |
2697 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, | 2671 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
2698 srcRect.width(), srcRect.height()); | 2672 srcRect.width(), srcRect.height()); |
2699 bool selfOverlap = false; | 2673 bool selfOverlap = false; |
2700 if (dst == src) { | 2674 if (dst == src) { |
2701 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); | 2675 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); |
2702 } | 2676 } |
2703 | 2677 |
2704 if (!selfOverlap) { | 2678 if (!selfOverlap) { |
| 2679 GrGLuint dstFBO; |
| 2680 GrGLuint srcFBO; |
2705 GrGLIRect dstVP; | 2681 GrGLIRect dstVP; |
2706 GrGLIRect srcVP; | 2682 GrGLIRect srcVP; |
2707 FBOBinding dstFBOBinding = this->bindSurfaceAsFBOForCopy(dst, kDraw_
FBOBinding, &dstVP); | 2683 dstFBO = this->bindSurfaceAsFBO(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP, |
2708 FBOBinding srcFBOBinding = this->bindSurfaceAsFBOForCopy(src, kRead_
FBOBinding, &srcVP); | 2684 kDst_TempFBOTarget); |
2709 | 2685 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_READ_FRAMEBUFFER, &srcVP, |
| 2686 kSrc_TempFBOTarget); |
| 2687 // We modified the bound FBO |
| 2688 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
2710 GrGLIRect srcGLRect; | 2689 GrGLIRect srcGLRect; |
2711 GrGLIRect dstGLRect; | 2690 GrGLIRect dstGLRect; |
2712 srcGLRect.setRelativeTo(srcVP, | 2691 srcGLRect.setRelativeTo(srcVP, |
2713 srcRect.fLeft, | 2692 srcRect.fLeft, |
2714 srcRect.fTop, | 2693 srcRect.fTop, |
2715 srcRect.width(), | 2694 srcRect.width(), |
2716 srcRect.height(), | 2695 srcRect.height(), |
2717 src->origin()); | 2696 src->origin()); |
2718 dstGLRect.setRelativeTo(dstVP, | 2697 dstGLRect.setRelativeTo(dstVP, |
2719 dstRect.fLeft, | 2698 dstRect.fLeft, |
(...skipping 17 matching lines...) Expand all Loading... |
2737 } | 2716 } |
2738 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, | 2717 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, |
2739 srcY0, | 2718 srcY0, |
2740 srcGLRect.fLeft + srcGLRect.fWidth, | 2719 srcGLRect.fLeft + srcGLRect.fWidth, |
2741 srcY1, | 2720 srcY1, |
2742 dstGLRect.fLeft, | 2721 dstGLRect.fLeft, |
2743 dstGLRect.fBottom, | 2722 dstGLRect.fBottom, |
2744 dstGLRect.fLeft + dstGLRect.fWidth, | 2723 dstGLRect.fLeft + dstGLRect.fWidth, |
2745 dstGLRect.fBottom + dstGLRect.fHeight, | 2724 dstGLRect.fBottom + dstGLRect.fHeight, |
2746 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); | 2725 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
2747 this->unbindSurfaceAsFBOForCopy(dstFBOBinding); | 2726 if (dstFBO) { |
2748 this->unbindSurfaceAsFBOForCopy(srcFBOBinding); | 2727 this->unbindTextureFromFBO(GR_GL_DRAW_FRAMEBUFFER); |
| 2728 } |
| 2729 if (srcFBO) { |
| 2730 this->unbindTextureFromFBO(GR_GL_READ_FRAMEBUFFER); |
| 2731 } |
2749 copied = true; | 2732 copied = true; |
2750 } | 2733 } |
2751 } | 2734 } |
2752 return copied; | 2735 return copied; |
2753 } | 2736 } |
2754 | 2737 |
2755 bool GrGLGpu::canCopySurface(const GrSurface* dst, | 2738 bool GrGLGpu::canCopySurface(const GrSurface* dst, |
2756 const GrSurface* src, | 2739 const GrSurface* src, |
2757 const SkIRect& srcRect, | 2740 const SkIRect& srcRect, |
2758 const SkIPoint& dstPoint) { | 2741 const SkIPoint& dstPoint) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2814 this->setVertexArrayID(gpu, 0); | 2797 this->setVertexArrayID(gpu, 0); |
2815 } | 2798 } |
2816 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2799 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2817 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2800 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2818 fDefaultVertexArrayAttribState.resize(attrCount); | 2801 fDefaultVertexArrayAttribState.resize(attrCount); |
2819 } | 2802 } |
2820 attribState = &fDefaultVertexArrayAttribState; | 2803 attribState = &fDefaultVertexArrayAttribState; |
2821 } | 2804 } |
2822 return attribState; | 2805 return attribState; |
2823 } | 2806 } |
OLD | NEW |