Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 949263002: Improve tracking of bound FBOs in GrGLGpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add enum value for copy tex src Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLNoOpInterface.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
157 154
158 if (this->glCaps().pathRenderingSupport()) { 155 if (this->glCaps().pathRenderingSupport()) {
159 fPathRendering.reset(new GrGLPathRendering(this)); 156 fPathRendering.reset(new GrGLPathRendering(this));
160 } 157 }
161 } 158 }
162 159
163 GrGLGpu::~GrGLGpu() { 160 GrGLGpu::~GrGLGpu() {
164 if (0 != fHWProgramID) { 161 if (0 != fHWProgramID) {
165 // detach the current program so there is no confusion on OpenGL's part 162 // detach the current program so there is no confusion on OpenGL's part
166 // that we want it to be deleted 163 // that we want it to be deleted
167 SkASSERT(fHWProgramID == fCurrentProgram->programID()); 164 SkASSERT(fHWProgramID == fCurrentProgram->programID());
168 GL_CALL(UseProgram(0)); 165 GL_CALL(UseProgram(0));
169 } 166 }
170 167
171 if (0 != fTempSrcFBOID) { 168 if (fTempSrcFBO) {
172 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); 169 fTempSrcFBO->release(this->glInterface());
170 fTempSrcFBO.reset(NULL);
173 } 171 }
174 if (0 != fTempDstFBOID) { 172 if (fTempDstFBO) {
175 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); 173 fTempDstFBO->release(this->glInterface());
174 fTempDstFBO.reset(NULL);
176 } 175 }
177 if (0 != fStencilClearFBOID) { 176 if (fStencilClearFBO) {
178 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); 177 fStencilClearFBO->release(this->glInterface());
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 fTempSrcFBOID = 0; 188 if (fTempSrcFBO) {
189 fTempDstFBOID = 0; 189 fTempSrcFBO->abandon();
190 fStencilClearFBOID = 0; 190 fTempSrcFBO.reset(NULL);
191 }
192 if (fTempDstFBO) {
193 fTempDstFBO->abandon();
194 fTempDstFBO.reset(NULL);
195 }
196 if (fStencilClearFBO) {
197 fStencilClearFBO->abandon();
198 fStencilClearFBO.reset(NULL);
199 }
200
191 if (this->glCaps().pathRenderingSupport()) { 201 if (this->glCaps().pathRenderingSupport()) {
192 this->glPathRendering()->abandonGpuResources(); 202 this->glPathRendering()->abandonGpuResources();
193 } 203 }
194 } 204 }
195 205
196 /////////////////////////////////////////////////////////////////////////////// 206 ///////////////////////////////////////////////////////////////////////////////
197 GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig, 207 GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig,
198 GrPixelConfig surfaceConfig) co nst { 208 GrPixelConfig surfaceConfig) co nst {
199 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig ) { 209 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig ) {
200 return kBGRA_8888_GrPixelConfig; 210 return kBGRA_8888_GrPixelConfig;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 fHWStencilSettings.invalidate(); 334 fHWStencilSettings.invalidate();
325 fHWStencilTestEnabled = kUnknown_TriState; 335 fHWStencilTestEnabled = kUnknown_TriState;
326 } 336 }
327 337
328 // Vertex 338 // Vertex
329 if (resetBits & kVertex_GrGLBackendState) { 339 if (resetBits & kVertex_GrGLBackendState) {
330 fHWGeometryState.invalidate(); 340 fHWGeometryState.invalidate();
331 } 341 }
332 342
333 if (resetBits & kRenderTarget_GrGLBackendState) { 343 if (resetBits & kRenderTarget_GrGLBackendState) {
334 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 344 for (size_t i = 0; i < SK_ARRAY_COUNT(fHWFBOBinding); ++i) {
345 fHWFBOBinding[i].invalidate();
346 }
335 } 347 }
336 348
337 if (resetBits & kPathRendering_GrGLBackendState) { 349 if (resetBits & kPathRendering_GrGLBackendState) {
338 if (this->caps()->pathRenderingSupport()) { 350 if (this->caps()->pathRenderingSupport()) {
339 this->glPathRendering()->resetContext(); 351 this->glPathRendering()->resetContext();
340 } 352 }
341 } 353 }
342 354
343 // we assume these values 355 // we assume these values
344 if (resetBits & kPixelStore_GrGLBackendState) { 356 if (resetBits & kPixelStore_GrGLBackendState) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 437 }
426 if (NULL == texture) { 438 if (NULL == texture) {
427 return NULL; 439 return NULL;
428 } 440 }
429 441
430 return texture; 442 return texture;
431 } 443 }
432 444
433 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc) { 445 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc) {
434 GrGLRenderTarget::IDDesc idDesc; 446 GrGLRenderTarget::IDDesc idDesc;
435 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); 447 GrGLuint fboID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
448 idDesc.fRenderFBO.reset(SkNEW_ARGS(GrGLFBO, (fboID)));
436 idDesc.fMSColorRenderbufferID = 0; 449 idDesc.fMSColorRenderbufferID = 0;
437 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
438 idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle; 450 idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle;
439 451
440 GrSurfaceDesc desc; 452 GrSurfaceDesc desc;
441 desc.fConfig = wrapDesc.fConfig; 453 desc.fConfig = wrapDesc.fConfig;
442 desc.fFlags = kCheckAllocation_GrSurfaceFlag; 454 desc.fFlags = kCheckAllocation_GrSurfaceFlag;
443 desc.fWidth = wrapDesc.fWidth; 455 desc.fWidth = wrapDesc.fWidth;
444 desc.fHeight = wrapDesc.fHeight; 456 desc.fHeight = wrapDesc.fHeight;
445 desc.fSampleCnt = wrapDesc.fSampleCnt; 457 desc.fSampleCnt = wrapDesc.fSampleCnt;
446 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); 458 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
447 459
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 case GrGLCaps::kNone_MSFBOType: 819 case GrGLCaps::kNone_MSFBOType:
808 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf fers."); 820 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf fers.");
809 break; 821 break;
810 } 822 }
811 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); 823 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));
812 } 824 }
813 825
814 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted , GrGLuint texID, 826 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted , GrGLuint texID,
815 GrGLRenderTarget::IDDesc* idDesc) { 827 GrGLRenderTarget::IDDesc* idDesc) {
816 idDesc->fMSColorRenderbufferID = 0; 828 idDesc->fMSColorRenderbufferID = 0;
817 idDesc->fRTFBOID = 0;
818 idDesc->fTexFBOID = 0;
819 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : 829 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
820 GrGpuResource::kUncached_LifeCycle; 830 GrGpuResource::kUncached_LifeCycle;
821 831
822 GrGLenum status; 832 GrGLenum status;
823 833
824 GrGLenum msColorFormat = 0; // suppress warning 834 GrGLenum msColorFormat = 0; // suppress warning
835 GrGLenum fboTarget = 0; // suppress warning
825 836
826 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) { 837 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) {
827 goto FAILED; 838 goto FAILED;
828 } 839 }
829 840
830 GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID)); 841 idDesc->fTextureFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface())));
831 if (!idDesc->fTexFBOID) { 842 if (!idDesc->fTextureFBO->isValid()) {
832 goto FAILED; 843 goto FAILED;
833 } 844 }
834 845
835
836 // If we are using multisampling we will create two FBOS. We render to one a nd then resolve to 846 // If we are using multisampling we will create two FBOS. We render to one a nd then resolve to
837 // the texture bound to the other. The exception is the IMG multisample exte nsion. With this 847 // the texture bound to the other. The exception is the IMG multisample exte nsion. With this
838 // extension the texture is multisampled when rendered to and then auto-reso lves it when it is 848 // extension the texture is multisampled when rendered to and then auto-reso lves it when it is
839 // rendered from. 849 // rendered from.
840 if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { 850 if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) {
841 GL_CALL(GenFramebuffers(1, &idDesc->fRTFBOID)); 851 idDesc->fRenderFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface())));
852 if (!idDesc->fRenderFBO->isValid()) {
853 goto FAILED;
854 }
842 GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); 855 GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID));
843 if (!idDesc->fRTFBOID || 856 if (!idDesc->fMSColorRenderbufferID ||
844 !idDesc->fMSColorRenderbufferID ||
845 !this->configToGLFormats(desc.fConfig, 857 !this->configToGLFormats(desc.fConfig,
846 // ES2 and ES3 require sized internal forma ts for rb storage. 858 // ES2 and ES3 require sized internal forma ts for rb storage.
847 kGLES_GrGLStandard == this->glStandard(), 859 kGLES_GrGLStandard == this->glStandard(),
848 &msColorFormat, 860 &msColorFormat,
849 NULL, 861 NULL,
850 NULL)) { 862 NULL)) {
851 goto FAILED; 863 goto FAILED;
852 } 864 }
853 } else { 865 } else {
854 idDesc->fRTFBOID = idDesc->fTexFBOID; 866 idDesc->fRenderFBO.reset(SkRef(idDesc->fTextureFBO.get()));
855 } 867 }
856 868
857 // below here we may bind the FBO 869 if (idDesc->fRenderFBO != idDesc->fTextureFBO) {
858 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
859 if (idDesc->fRTFBOID != idDesc->fTexFBOID) {
860 SkASSERT(desc.fSampleCnt > 0); 870 SkASSERT(desc.fSampleCnt > 0);
861 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe rID)); 871 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe rID));
862 if (!renderbuffer_storage_msaa(fGLContext, 872 if (!renderbuffer_storage_msaa(fGLContext,
863 desc.fSampleCnt, 873 desc.fSampleCnt,
864 msColorFormat, 874 msColorFormat,
865 desc.fWidth, desc.fHeight)) { 875 desc.fWidth, desc.fHeight)) {
866 goto FAILED; 876 goto FAILED;
867 } 877 }
868 fStats.incRenderTargetBinds(); 878 fboTarget = this->bindFBO(kChangeAttachments_FBOBinding, idDesc->fRender FBO);
869 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); 879 GL_CALL(FramebufferRenderbuffer(fboTarget,
870 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 880 GR_GL_COLOR_ATTACHMENT0,
871 GR_GL_COLOR_ATTACHMENT0, 881 GR_GL_RENDERBUFFER,
872 GR_GL_RENDERBUFFER, 882 idDesc->fMSColorRenderbufferID));
873 idDesc->fMSColorRenderbufferID));
874 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || 883 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) ||
875 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { 884 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) {
876 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 885 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
877 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 886 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
878 goto FAILED; 887 goto FAILED;
879 } 888 }
880 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); 889 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig);
881 } 890 }
882 } 891 }
883 fStats.incRenderTargetBinds(); 892 fboTarget = this->bindFBO(kChangeAttachments_FBOBinding, idDesc->fTextureFBO );
884 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID));
885 893
886 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { 894 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) {
887 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, 895 GL_CALL(FramebufferTexture2DMultisample(fboTarget,
888 GR_GL_COLOR_ATTACHMENT0, 896 GR_GL_COLOR_ATTACHMENT0,
889 GR_GL_TEXTURE_2D, 897 GR_GL_TEXTURE_2D,
890 texID, 0, desc.fSampleCnt)); 898 texID, 0, desc.fSampleCnt));
891 } else { 899 } else {
892 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, 900 GL_CALL(FramebufferTexture2D(fboTarget,
893 GR_GL_COLOR_ATTACHMENT0, 901 GR_GL_COLOR_ATTACHMENT0,
894 GR_GL_TEXTURE_2D, 902 GR_GL_TEXTURE_2D,
895 texID, 0)); 903 texID, 0));
896 } 904 }
897 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || 905 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) ||
898 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { 906 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) {
899 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 907 GL_CALL_RET(status, CheckFramebufferStatus(fboTarget));
900 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 908 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
901 goto FAILED; 909 goto FAILED;
902 } 910 }
903 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); 911 fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig);
904 } 912 }
905 913
906 return true; 914 return true;
907 915
908 FAILED: 916 FAILED:
909 if (idDesc->fMSColorRenderbufferID) { 917 if (idDesc->fMSColorRenderbufferID) {
910 GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); 918 GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID));
911 } 919 }
912 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { 920 if (idDesc->fRenderFBO) {
913 GL_CALL(DeleteFramebuffers(1, &idDesc->fRTFBOID)); 921 idDesc->fRenderFBO->release(this->glInterface());
914 } 922 }
915 if (idDesc->fTexFBOID) { 923 if (idDesc->fTextureFBO) {
916 GL_CALL(DeleteFramebuffers(1, &idDesc->fTexFBOID)); 924 idDesc->fTextureFBO->release(this->glInterface());
917 } 925 }
918 return false; 926 return false;
919 } 927 }
920 928
921 // good to set a break-point here to know when createTexture fails 929 // good to set a break-point here to know when createTexture fails
922 static GrTexture* return_null_texture() { 930 static GrTexture* return_null_texture() {
923 // SkDEBUGFAIL("null texture"); 931 // SkDEBUGFAIL("null texture");
924 return NULL; 932 return NULL;
925 } 933 }
926 934
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 get_stencil_rb_sizes(this->glInterface(), &format); 1187 get_stencil_rb_sizes(this->glInterface(), &format);
1180 SkAutoTUnref<GrGLStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, 1188 SkAutoTUnref<GrGLStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer,
1181 (this, sbDesc, width, height, samples, format))); 1189 (this, sbDesc, width, height, samples, format)));
1182 if (this->attachStencilBufferToRenderTarget(sb, rt)) { 1190 if (this->attachStencilBufferToRenderTarget(sb, rt)) {
1183 fLastSuccessfulStencilFmtIdx = sIdx; 1191 fLastSuccessfulStencilFmtIdx = sIdx;
1184 rt->renderTargetPriv().didAttachStencilBuffer(sb); 1192 rt->renderTargetPriv().didAttachStencilBuffer(sb);
1185 1193
1186 // Clear the stencil buffer. We use a special purpose FBO for th is so that the 1194 // Clear the stencil buffer. We use a special purpose FBO for th is so that the
1187 // entire stencil buffer is cleared, even if it is attached to a n FBO with a 1195 // entire stencil buffer is cleared, even if it is attached to a n FBO with a
1188 // smaller color target. 1196 // smaller color target.
1189 if (0 == fStencilClearFBOID) { 1197 if (!fStencilClearFBO) {
1190 GL_CALL(GenFramebuffers(1, &fStencilClearFBOID)); 1198 fStencilClearFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterfac e())));
1191 } 1199 }
1200 SkASSERT(fStencilClearFBO->isValid());
1201 GrGLenum fboTarget = this->bindFBO(kClear_FBOBinding, fStencilCl earFBO);
1192 1202
1193 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID)); 1203 GL_CALL(FramebufferRenderbuffer(fboTarget,
1194 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1195 fStats.incRenderTargetBinds();
1196 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1197 GR_GL_STENCIL_ATTACHMENT, 1204 GR_GL_STENCIL_ATTACHMENT,
1198 GR_GL_RENDERBUFFER, sbDesc.fRend erbufferID)); 1205 GR_GL_RENDERBUFFER, sbDesc.fRend erbufferID));
1199 if (sFmt.fPacked) { 1206 if (sFmt.fPacked) {
1200 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1207 GL_CALL(FramebufferRenderbuffer(fboTarget,
1201 GR_GL_DEPTH_ATTACHMENT, 1208 GR_GL_DEPTH_ATTACHMENT,
1202 GR_GL_RENDERBUFFER, sbDesc.f RenderbufferID)); 1209 GR_GL_RENDERBUFFER, sbDesc.f RenderbufferID));
1203 } 1210 }
1204 1211
1205 GL_CALL(ClearStencil(0)); 1212 GL_CALL(ClearStencil(0));
1206 // Many GL implementations seem to have trouble with clearing an FBO with only 1213 // Many GL implementations seem to have trouble with clearing an FBO with only
1207 // a stencil buffer. 1214 // a stencil buffer.
1208 GrGLuint tempRB; 1215 GrGLuint tempRB;
1209 GL_CALL(GenRenderbuffers(1, &tempRB)); 1216 GL_CALL(GenRenderbuffers(1, &tempRB));
1210 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, tempRB)); 1217 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, tempRB));
1218
1211 if (samples > 0) { 1219 if (samples > 0) {
1212 renderbuffer_storage_msaa(fGLContext, samples, GR_GL_RGBA8, width, height); 1220 renderbuffer_storage_msaa(fGLContext, samples, GR_GL_RGBA8, width, height);
1213 } else { 1221 } else {
1214 GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, height)); 1222 GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, height));
1215 } 1223 }
1216 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1224 GL_CALL(FramebufferRenderbuffer(fboTarget,
1217 GR_GL_COLOR_ATTACHMENT0, 1225 GR_GL_COLOR_ATTACHMENT0,
1218 GR_GL_RENDERBUFFER, tempRB)); 1226 GR_GL_RENDERBUFFER, tempRB));
1219 1227
1220 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1228 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1221 1229
1222 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1230 GL_CALL(FramebufferRenderbuffer(fboTarget,
1223 GR_GL_COLOR_ATTACHMENT0, 1231 GR_GL_COLOR_ATTACHMENT0,
1224 GR_GL_RENDERBUFFER, 0)); 1232 GR_GL_RENDERBUFFER, 0));
1225 GL_CALL(DeleteRenderbuffers(1, &tempRB)); 1233 GL_CALL(DeleteRenderbuffers(1, &tempRB));
1226 1234
1227 // Unbind the SB from the FBO so that we don't keep it alive. 1235 // Unbind the SB from the FBO so that we don't keep it alive.
1228 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1236 GL_CALL(FramebufferRenderbuffer(fboTarget,
1229 GR_GL_STENCIL_ATTACHMENT, 1237 GR_GL_STENCIL_ATTACHMENT,
1230 GR_GL_RENDERBUFFER, 0)); 1238 GR_GL_RENDERBUFFER, 0));
1231 if (sFmt.fPacked) { 1239 if (sFmt.fPacked) {
1232 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1240 GL_CALL(FramebufferRenderbuffer(fboTarget,
1233 GR_GL_DEPTH_ATTACHMENT, 1241 GR_GL_DEPTH_ATTACHMENT,
1234 GR_GL_RENDERBUFFER, 0)); 1242 GR_GL_RENDERBUFFER, 0));
1235 } 1243 }
1236 1244
1237 return true; 1245 return true;
1238 } 1246 }
1239 // Remove the scratch key from this resource so we don't grab it fro m the cache ever 1247 // Remove the scratch key from this resource so we don't grab it fro m the cache ever
1240 // again. 1248 // again.
1241 sb->resourcePriv().removeScratchKey(); 1249 sb->resourcePriv().removeScratchKey();
1242 // Set this to 0 since we handed the valid ID off to the failed sten cil buffer resource. 1250 // Set this to 0 since we handed the valid ID off to the failed sten cil buffer resource.
1243 sbDesc.fRenderbufferID = 0; 1251 sbDesc.fRenderbufferID = 0;
1244 } 1252 }
1245 } 1253 }
1246 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); 1254 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID));
1247 return false; 1255 return false;
1248 } 1256 }
1249 1257
1250 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) { 1258 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) {
1251 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); 1259 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt);
1252
1253 GrGLuint fbo = glrt->renderFBOID();
1254
1255 if (NULL == sb) { 1260 if (NULL == sb) {
1256 if (rt->renderTargetPriv().getStencilBuffer()) { 1261 if (rt->renderTargetPriv().getStencilBuffer()) {
1257 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1262 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1258 GR_GL_STENCIL_ATTACHMENT, 1263 GR_GL_STENCIL_ATTACHMENT,
1259 GR_GL_RENDERBUFFER, 0)); 1264 GR_GL_RENDERBUFFER, 0));
1260 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1265 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1261 GR_GL_DEPTH_ATTACHMENT, 1266 GR_GL_DEPTH_ATTACHMENT,
1262 GR_GL_RENDERBUFFER, 0)); 1267 GR_GL_RENDERBUFFER, 0));
1263 #ifdef SK_DEBUG 1268 #ifdef SK_DEBUG
1264 GrGLenum status; 1269 GrGLenum status;
1265 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1270 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1266 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); 1271 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
1267 #endif 1272 #endif
1268 } 1273 }
1269 return true; 1274 return true;
1270 } else { 1275 } else {
1271 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); 1276 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb);
1272 GrGLuint rb = glsb->renderbufferID(); 1277 GrGLuint rb = glsb->renderbufferID();
1278 GrGLenum fboTarget = this->bindFBO(kChangeAttachments_FBOBinding, glrt-> renderFBO());
1273 1279
1274 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 1280 GL_CALL(FramebufferRenderbuffer(fboTarget,
1275 fStats.incRenderTargetBinds();
1276 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
1277 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1278 GR_GL_STENCIL_ATTACHMENT, 1281 GR_GL_STENCIL_ATTACHMENT,
1279 GR_GL_RENDERBUFFER, rb)); 1282 GR_GL_RENDERBUFFER, rb));
1280 if (glsb->format().fPacked) { 1283 if (glsb->format().fPacked) {
1281 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1284 GL_CALL(FramebufferRenderbuffer(fboTarget,
1282 GR_GL_DEPTH_ATTACHMENT, 1285 GR_GL_DEPTH_ATTACHMENT,
1283 GR_GL_RENDERBUFFER, rb)); 1286 GR_GL_RENDERBUFFER, rb));
1284 } else { 1287 } else {
1285 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1288 GL_CALL(FramebufferRenderbuffer(fboTarget,
1286 GR_GL_DEPTH_ATTACHMENT, 1289 GR_GL_DEPTH_ATTACHMENT,
1287 GR_GL_RENDERBUFFER, 0)); 1290 GR_GL_RENDERBUFFER, 0));
1288 } 1291 }
1289 1292
1290 GrGLenum status; 1293 GrGLenum status;
1291 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) { 1294 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) {
1292 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1295 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1293 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 1296 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
1294 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1297 GL_CALL(FramebufferRenderbuffer(fboTarget,
1295 GR_GL_STENCIL_ATTACHMENT, 1298 GR_GL_STENCIL_ATTACHMENT,
1296 GR_GL_RENDERBUFFER, 0)); 1299 GR_GL_RENDERBUFFER, 0));
1297 if (glsb->format().fPacked) { 1300 if (glsb->format().fPacked) {
1298 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1301 GL_CALL(FramebufferRenderbuffer(fboTarget,
1299 GR_GL_DEPTH_ATTACHMENT, 1302 GR_GL_DEPTH_ATTACHMENT,
1300 GR_GL_RENDERBUFFER, 0)); 1303 GR_GL_RENDERBUFFER, 0));
1301 } 1304 }
1302 return false; 1305 return false;
1303 } else { 1306 } else {
1304 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( 1307 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified(
1305 rt->config(), 1308 rt->config(),
1306 glsb->format()); 1309 glsb->format());
1307 } 1310 }
1308 } 1311 }
1309 return true; 1312 return true;
1310 } 1313 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 } 1425 }
1423 1426
1424 fCurrentProgram.get()->ref(); 1427 fCurrentProgram.get()->ref();
1425 1428
1426 GrGLuint programID = fCurrentProgram->programID(); 1429 GrGLuint programID = fCurrentProgram->programID();
1427 if (fHWProgramID != programID) { 1430 if (fHWProgramID != programID) {
1428 GL_CALL(UseProgram(programID)); 1431 GL_CALL(UseProgram(programID));
1429 fHWProgramID = programID; 1432 fHWProgramID = programID;
1430 } 1433 }
1431 1434
1432 if (blendInfo.fWriteColor) {
1433 this->flushBlend(blendInfo);
1434 }
1435 1435
1436 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr acker); 1436 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr acker);
1437 1437
1438 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget()); 1438 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
1439
1439 this->flushStencil(pipeline.getStencil()); 1440 this->flushStencil(pipeline.getStencil());
1440 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 1441 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
1441 this->flushHWAAState(glRT, pipeline.isHWAntialiasState()); 1442 this->flushHWAAState(glRT, pipeline.isHWAntialiasState());
1442 1443
1443 // This must come after textures are flushed because a texture may need 1444 // This must come after textures are flushed because a texture may need
1444 // to be msaa-resolved (which will modify bound FBO state). 1445 // to be msaa-resolved (which will modify bound FBO and scissor state).
1445 this->flushRenderTarget(glRT, NULL); 1446 this->bindFBO(kDraw_FBOBinding, glRT->renderFBO());
1447 this->setViewport(glRT->getViewport());
1448 if (blendInfo.fWriteColor) {
1449 this->flushBlend(blendInfo);
1450 this->markSurfaceContentsDirty(glRT, NULL);
1451 }
1446 1452
1447 return true; 1453 return true;
1448 } 1454 }
1449 1455
1450 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, 1456 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
1451 const GrDrawTarget::DrawInfo& info, 1457 const GrDrawTarget::DrawInfo& info,
1452 size_t* indexOffsetInBytes) { 1458 size_t* indexOffsetInBytes) {
1453 GrGLVertexBuffer* vbuf; 1459 GrGLVertexBuffer* vbuf;
1454 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); 1460 vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
1455 1461
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 // flushScissor expects rect to be clipped to the target. 1538 // flushScissor expects rect to be clipped to the target.
1533 clippedRect = *rect; 1539 clippedRect = *rect;
1534 SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height()); 1540 SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height());
1535 if (clippedRect.intersect(rtRect)) { 1541 if (clippedRect.intersect(rtRect)) {
1536 rect = &clippedRect; 1542 rect = &clippedRect;
1537 } else { 1543 } else {
1538 return; 1544 return;
1539 } 1545 }
1540 } 1546 }
1541 1547
1542 this->flushRenderTarget(glRT, rect); 1548 this->bindFBO(kClear_FBOBinding, glRT->renderFBO());
1549 this->markSurfaceContentsDirty(glRT, rect);
1543 GrScissorState scissorState; 1550 GrScissorState scissorState;
1544 if (rect) { 1551 if (rect) {
1545 scissorState.set(*rect); 1552 scissorState.set(*rect);
1546 } 1553 }
1547 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); 1554 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin());
1548 1555
1549 GrGLfloat r, g, b, a; 1556 GrGLfloat r, g, b, a;
1550 static const GrGLfloat scale255 = 1.f / 255.f; 1557 static const GrGLfloat scale255 = 1.f / 255.f;
1551 a = GrColorUnpackA(color) * scale255; 1558 a = GrColorUnpackA(color) * scale255;
1552 GrGLfloat scaleRGB = scale255; 1559 GrGLfloat scaleRGB = scale255;
1553 r = GrColorUnpackR(color) * scaleRGB; 1560 r = GrColorUnpackR(color) * scaleRGB;
1554 g = GrColorUnpackG(color) * scaleRGB; 1561 g = GrColorUnpackG(color) * scaleRGB;
1555 b = GrColorUnpackB(color) * scaleRGB; 1562 b = GrColorUnpackB(color) * scaleRGB;
1556 1563
1557 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); 1564 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
1558 fHWWriteToColor = kYes_TriState; 1565 fHWWriteToColor = kYes_TriState;
1559 GL_CALL(ClearColor(r, g, b, a)); 1566 GL_CALL(ClearColor(r, g, b, a));
1560 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); 1567 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
1561 } 1568 }
1562 1569
1563 void GrGLGpu::discard(GrRenderTarget* renderTarget) { 1570 void GrGLGpu::discard(GrRenderTarget* renderTarget) {
1564 SkASSERT(renderTarget); 1571 SkASSERT(renderTarget);
1565 if (!this->caps()->discardRenderTargetSupport()) { 1572 if (!this->caps()->discardRenderTargetSupport()) {
1566 return; 1573 return;
1567 } 1574 }
1568 1575
1569 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); 1576 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
1570 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { 1577 GrGLenum fboTarget = this->bindFBO(kDiscard_FBOBinding, glRT->renderFBO());
1571 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1572 fStats.incRenderTargetBinds();
1573 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID()));
1574 }
1575 switch (this->glCaps().invalidateFBType()) { 1578 switch (this->glCaps().invalidateFBType()) {
1576 case GrGLCaps::kNone_InvalidateFBType: 1579 case GrGLCaps::kNone_InvalidateFBType:
1577 SkFAIL("Should never get here."); 1580 SkFAIL("Should never get here.");
1578 break; 1581 break;
1579 case GrGLCaps::kInvalidate_InvalidateFBType: 1582 case GrGLCaps::kInvalidate_InvalidateFBType:
1580 if (0 == glRT->renderFBOID()) { 1583 if (glRT->renderFBO()->isDefaultFramebuffer()) {
1581 // When rendering to the default framebuffer the legal values f or attachments 1584 // When rendering to the default framebuffer the legal values f or attachments
1582 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari ous FBO attachment 1585 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari ous FBO attachment
1583 // types. 1586 // types.
1584 static const GrGLenum attachments[] = { GR_GL_COLOR }; 1587 static const GrGLenum attachments[] = { GR_GL_COLOR };
1585 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT( attachments), 1588 GL_CALL(InvalidateFramebuffer(fboTarget, SK_ARRAY_COUNT(attachme nts),
1586 attachments)); 1589 attachments));
1587 } else { 1590 } else {
1588 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 }; 1591 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 };
1589 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT( attachments), 1592 GL_CALL(InvalidateFramebuffer(fboTarget, SK_ARRAY_COUNT(attachme nts),
1590 attachments)); 1593 attachments));
1591 } 1594 }
1592 break; 1595 break;
1593 case GrGLCaps::kDiscard_InvalidateFBType: { 1596 case GrGLCaps::kDiscard_InvalidateFBType: {
1594 if (0 == glRT->renderFBOID()) { 1597 if (glRT->renderFBO()->isDefaultFramebuffer()) {
1595 // When rendering to the default framebuffer the legal values f or attachments 1598 // When rendering to the default framebuffer the legal values f or attachments
1596 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari ous FBO attachment 1599 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the vari ous FBO attachment
1597 // types. See glDiscardFramebuffer() spec. 1600 // types. See glDiscardFramebuffer() spec.
1598 static const GrGLenum attachments[] = { GR_GL_COLOR }; 1601 static const GrGLenum attachments[] = { GR_GL_COLOR };
1599 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(att achments), 1602 GL_CALL(DiscardFramebuffer(fboTarget, SK_ARRAY_COUNT(attachments ),
1600 attachments)); 1603 attachments));
1601 } else { 1604 } else {
1602 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 }; 1605 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 };
1603 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(att achments), 1606 GL_CALL(DiscardFramebuffer(fboTarget, SK_ARRAY_COUNT(attachments ),
1604 attachments)); 1607 attachments));
1605 } 1608 }
1606 break; 1609 break;
1607 } 1610 }
1608 } 1611 }
1609 renderTarget->flagAsResolved(); 1612 renderTarget->flagAsResolved();
1610 } 1613 }
1611 1614
1612 1615
1613 void GrGLGpu::clearStencil(GrRenderTarget* target) { 1616 void GrGLGpu::clearStencil(GrRenderTarget* target) {
1614 if (NULL == target) { 1617 if (NULL == target) {
1615 return; 1618 return;
1616 } 1619 }
1617 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); 1620 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
1618 this->flushRenderTarget(glRT, &SkIRect::EmptyIRect()); 1621 this->bindFBO(kClear_FBOBinding, glRT->renderFBO());
1619 1622
1620 this->disableScissor(); 1623 this->disableScissor();
1621 1624
1622 GL_CALL(StencilMask(0xffffffff)); 1625 GL_CALL(StencilMask(0xffffffff));
1623 GL_CALL(ClearStencil(0)); 1626 GL_CALL(ClearStencil(0));
1624 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1627 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1625 fHWStencilSettings.invalidate(); 1628 fHWStencilSettings.invalidate();
1626 } 1629 }
1627 1630
1628 void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bo ol insideClip) { 1631 void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bo ol insideClip) {
(...skipping 15 matching lines...) Expand all
1644 // zero the client's clip bits. So we just clear the whole thing. 1647 // zero the client's clip bits. So we just clear the whole thing.
1645 static const GrGLint clipStencilMask = ~0; 1648 static const GrGLint clipStencilMask = ~0;
1646 #endif 1649 #endif
1647 GrGLint value; 1650 GrGLint value;
1648 if (insideClip) { 1651 if (insideClip) {
1649 value = (1 << (stencilBitCount - 1)); 1652 value = (1 << (stencilBitCount - 1));
1650 } else { 1653 } else {
1651 value = 0; 1654 value = 0;
1652 } 1655 }
1653 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); 1656 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
1654 this->flushRenderTarget(glRT, &SkIRect::EmptyIRect()); 1657 this->bindFBO(kClear_FBOBinding, glRT->renderFBO());
1655 1658
1656 GrScissorState scissorState; 1659 GrScissorState scissorState;
1657 scissorState.set(rect); 1660 scissorState.set(rect);
1658 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); 1661 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin());
1659 1662
1660 GL_CALL(StencilMask((uint32_t) clipStencilMask)); 1663 GL_CALL(StencilMask((uint32_t) clipStencilMask));
1661 GL_CALL(ClearStencil(value)); 1664 GL_CALL(ClearStencil(value));
1662 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1665 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1663 fHWStencilSettings.invalidate(); 1666 fHWStencilSettings.invalidate();
1664 } 1667 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 size_t bpp = GrBytesPerPixel(config); 1717 size_t bpp = GrBytesPerPixel(config);
1715 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, 1718 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp,
1716 &left, &top, &width, &height, 1719 &left, &top, &width, &height,
1717 const_cast<const void**>(&buffer), 1720 const_cast<const void**>(&buffer),
1718 &rowBytes)) { 1721 &rowBytes)) {
1719 return false; 1722 return false;
1720 } 1723 }
1721 1724
1722 // resolve the render target if necessary 1725 // resolve the render target if necessary
1723 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); 1726 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target);
1724 switch (tgt->getResolveType()) { 1727 if (tgt->getResolveType() == GrGLRenderTarget::kCantResolve_ResolveType) {
1725 case GrGLRenderTarget::kCantResolve_ResolveType: 1728 return false;
1726 return false;
1727 case GrGLRenderTarget::kAutoResolves_ResolveType:
1728 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI Rect::EmptyIRect());
1729 break;
1730 case GrGLRenderTarget::kCanResolve_ResolveType:
1731 this->onResolveRenderTarget(tgt);
1732 // we don't track the state of the READ FBO ID.
1733 fStats.incRenderTargetBinds();
1734 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
1735 tgt->textureFBOID()));
1736 break;
1737 default:
1738 SkFAIL("Unknown resolve type");
1739 } 1729 }
1730 if (tgt->getResolveType() == GrGLRenderTarget::kCanResolve_ResolveType) {
1731 this->onResolveRenderTarget(tgt);
1732 }
1733 this->bindFBO(kReadPixels_FBOBinding, tgt->textureFBO());
1740 1734
1741 const GrGLIRect& glvp = tgt->getViewport(); 1735 const GrGLIRect& glvp = tgt->getViewport();
1742 1736
1743 // the read rect is viewport-relative 1737 // the read rect is viewport-relative
1744 GrGLIRect readRect; 1738 GrGLIRect readRect;
1745 readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); 1739 readRect.setRelativeTo(glvp, left, top, width, height, target->origin());
1746 1740
1747 size_t tightRowBytes = bpp * width; 1741 size_t tightRowBytes = bpp * width;
1748 if (0 == rowBytes) { 1742 if (0 == rowBytes) {
1749 rowBytes = tightRowBytes; 1743 rowBytes = tightRowBytes;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 char* bottom = top + (height - 1) * rowBytes; 1788 char* bottom = top + (height - 1) * rowBytes;
1795 for (int y = 0; y < halfY; y++) { 1789 for (int y = 0; y < halfY; y++) {
1796 memcpy(tmpRow, top, tightRowBytes); 1790 memcpy(tmpRow, top, tightRowBytes);
1797 memcpy(top, bottom, tightRowBytes); 1791 memcpy(top, bottom, tightRowBytes);
1798 memcpy(bottom, tmpRow, tightRowBytes); 1792 memcpy(bottom, tmpRow, tightRowBytes);
1799 top += rowBytes; 1793 top += rowBytes;
1800 bottom -= rowBytes; 1794 bottom -= rowBytes;
1801 } 1795 }
1802 } 1796 }
1803 } else { 1797 } else {
1804 SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes); 1798 SkASSERT(readDst != buffer);
1799 SkASSERT(rowBytes != tightRowBytes);
1805 // copy from readDst to buffer while flipping y 1800 // copy from readDst to buffer while flipping y
1806 // const int halfY = height >> 1; 1801 // const int halfY = height >> 1;
1807 const char* src = reinterpret_cast<const char*>(readDst); 1802 const char* src = reinterpret_cast<const char*>(readDst);
1808 char* dst = reinterpret_cast<char*>(buffer); 1803 char* dst = reinterpret_cast<char*>(buffer);
1809 if (flipY) { 1804 if (flipY) {
1810 dst += (height-1) * rowBytes; 1805 dst += (height-1) * rowBytes;
1811 } 1806 }
1812 for (int y = 0; y < height; y++) { 1807 for (int y = 0; y < height; y++) {
1813 memcpy(dst, src, tightRowBytes); 1808 memcpy(dst, src, tightRowBytes);
1814 src += readDstRowBytes; 1809 src += readDstRowBytes;
1815 if (!flipY) { 1810 if (!flipY) {
1816 dst += rowBytes; 1811 dst += rowBytes;
1817 } else { 1812 } else {
1818 dst -= rowBytes; 1813 dst -= rowBytes;
1819 } 1814 }
1820 } 1815 }
1821 } 1816 }
1822 return true; 1817 return true;
1823 } 1818 }
1824 1819
1825 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound) { 1820 GrGLenum GrGLGpu::bindFBO(FBOBinding binding, const GrGLFBO* fbo) {
1821 SkASSERT(fbo);
1822 SkASSERT(fbo->isValid());
1823
1824 enum {
1825 kDraw = 0,
1826 kRead = 1
1827 };
1826 1828
1827 SkASSERT(target); 1829 bool useGLFramebuffer = !this->glCaps().usesMSAARenderBuffers() ||
1830 (this->glCaps().preferBindingToReadAndDrawFramebuffer() &&
1831 kBlitSrc_FBOBinding != binding && kBlitDst_FBOBinding != binding);
1828 1832
1829 uint32_t rtID = target->getUniqueID(); 1833 if (useGLFramebuffer) {
1830 if (fHWBoundRenderTargetUniqueID != rtID) { 1834 SkASSERT(kBlitSrc_FBOBinding != binding);
1831 fStats.incRenderTargetBinds(); 1835 fStats.incRenderTargetBinds();
1832 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); 1836 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo->fboID()));
1833 #ifdef SK_DEBUG 1837 fHWFBOBinding[kDraw].fFBO.reset(SkRef(fbo));
1834 // don't do this check in Chromium -- this is causing 1838 fHWFBOBinding[kRead].fFBO.reset(SkRef(fbo));
1835 // lots of repeated command buffer flushes when the compositor is 1839 return GR_GL_FRAMEBUFFER;
1836 // rendering with Ganesh, which is really slow; even too slow for
1837 // Debug mode.
1838 if (!this->glContext().isChromium()) {
1839 GrGLenum status;
1840 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1841 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
1842 SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x \n", status);
1843 }
1844 }
1845 #endif
1846 fHWBoundRenderTargetUniqueID = rtID;
1847 const GrGLIRect& vp = target->getViewport();
1848 if (fHWViewport != vp) {
1849 vp.pushToGLViewport(this->glInterface());
1850 fHWViewport = vp;
1851 }
1852 } 1840 }
1853 if (NULL == bound || !bound->isEmpty()) { 1841 GrGLenum target = 0;
1854 target->flagAsNeedingResolve(bound); 1842 HWFBOBinding* hwFBOBinding = NULL;
1843 switch (binding) {
1844 case kDraw_FBOBinding:
1845 case kClear_FBOBinding:
1846 case kDiscard_FBOBinding:
1847 case kChangeAttachments_FBOBinding:
1848 case kBlitDst_FBOBinding:
1849 target = GR_GL_DRAW_FRAMEBUFFER;
1850 hwFBOBinding = &fHWFBOBinding[kDraw];
1851 break;
1852
1853 case kReadPixels_FBOBinding:
1854 case kBlitSrc_FBOBinding:
1855 case kCopyTexSrc_FBOBinding:
1856 target = GR_GL_READ_FRAMEBUFFER;
1857 hwFBOBinding = &fHWFBOBinding[kRead];
1858 break;
1855 } 1859 }
1860 fStats.incRenderTargetBinds();
1861 GL_CALL(BindFramebuffer(target, fbo->fboID()));
1862 hwFBOBinding->fFBO.reset(SkRef(fbo));
1863 return target;
1864 }
1856 1865
1857 GrTexture *texture = target->asTexture(); 1866 void GrGLGpu::setViewport(const GrGLIRect& viewport) {
1858 if (texture) { 1867 if (viewport != fHWViewport) {
1859 texture->texturePriv().dirtyMipMaps(true); 1868 viewport.pushToGLViewport(this->glInterface());
1869 fHWViewport = viewport;
1860 } 1870 }
1861 } 1871 }
1862 1872
1873 void GrGLGpu::markSurfaceContentsDirty(GrSurface* surface, const SkIRect* bounds ) {
1874 if (NULL == bounds || !bounds->isEmpty()) {
1875 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderT arget());
1876 if (rt) {
1877 rt->flagAsNeedingResolve(bounds);
1878 }
1879 GrGLTexture* texture = static_cast<GrGLTexture*>(surface->asTexture());
1880 if (texture) {
1881 texture->texturePriv().dirtyMipMaps(true);
1882 }
1883 }
1884 }
1885
1863 GrGLenum gPrimitiveType2GLMode[] = { 1886 GrGLenum gPrimitiveType2GLMode[] = {
1864 GR_GL_TRIANGLES, 1887 GR_GL_TRIANGLES,
1865 GR_GL_TRIANGLE_STRIP, 1888 GR_GL_TRIANGLE_STRIP,
1866 GR_GL_TRIANGLE_FAN, 1889 GR_GL_TRIANGLE_FAN,
1867 GR_GL_POINTS, 1890 GR_GL_POINTS,
1868 GR_GL_LINES, 1891 GR_GL_LINES,
1869 GR_GL_LINE_STRIP 1892 GR_GL_LINE_STRIP
1870 }; 1893 };
1871 1894
1872 #define SWAP_PER_DRAW 0 1895 #define SWAP_PER_DRAW 0
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 1954
1932 void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) { 1955 void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) {
1933 this->flushColorWrite(false); 1956 this->flushColorWrite(false);
1934 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 1957 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
1935 1958
1936 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); 1959 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget);
1937 SkISize size = SkISize::Make(rt->width(), rt->height()); 1960 SkISize size = SkISize::Make(rt->width(), rt->height());
1938 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o rigin()); 1961 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o rigin());
1939 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); 1962 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin());
1940 this->flushHWAAState(rt, state.fUseHWAA); 1963 this->flushHWAAState(rt, state.fUseHWAA);
1941 this->flushRenderTarget(rt, NULL); 1964 this->bindFBO(kDraw_FBOBinding, rt->renderFBO());
1942 1965 this->setViewport(rt->getViewport());
1943 fPathRendering->stencilPath(path, *state.fStencil); 1966 fPathRendering->stencilPath(path, *state.fStencil);
1944 } 1967 }
1945 1968
1946 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, 1969 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path,
1947 const GrStencilSettings& stencil) { 1970 const GrStencilSettings& stencil) {
1948 if (!this->flushGLState(args)) { 1971 if (!this->flushGLState(args)) {
1949 return; 1972 return;
1950 } 1973 }
1951 fPathRendering->drawPath(path, stencil); 1974 fPathRendering->drawPath(path, stencil);
1952 } 1975 }
(...skipping 11 matching lines...) Expand all
1964 } 1987 }
1965 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, 1988 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues,
1966 transformType, count, stencil); 1989 transformType, count, stencil);
1967 } 1990 }
1968 1991
1969 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { 1992 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) {
1970 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); 1993 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
1971 if (rt->needsResolve()) { 1994 if (rt->needsResolve()) {
1972 // Some extensions automatically resolves the texture when it is read. 1995 // Some extensions automatically resolves the texture when it is read.
1973 if (this->glCaps().usesMSAARenderBuffers()) { 1996 if (this->glCaps().usesMSAARenderBuffers()) {
1974 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); 1997 SkASSERT(rt->textureFBO() != rt->renderFBO());
1975 fStats.incRenderTargetBinds(); 1998 this->bindFBO(kBlitSrc_FBOBinding, rt->renderFBO());
1976 fStats.incRenderTargetBinds(); 1999 this->bindFBO(kBlitDst_FBOBinding, rt->textureFBO());
1977 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID()));
1978 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())) ;
1979 // make sure we go through flushRenderTarget() since we've modified
1980 // the bound DRAW FBO ID.
1981 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1982 const GrGLIRect& vp = rt->getViewport(); 2000 const GrGLIRect& vp = rt->getViewport();
1983 const SkIRect dirtyRect = rt->getResolveRect(); 2001 const SkIRect dirtyRect = rt->getResolveRect();
1984 2002
1985 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { 2003 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) {
1986 // Apple's extension uses the scissor as the blit bounds. 2004 // Apple's extension uses the scissor as the blit bounds.
1987 GrScissorState scissorState; 2005 GrScissorState scissorState;
1988 scissorState.set(dirtyRect); 2006 scissorState.set(dirtyRect);
1989 this->flushScissor(scissorState, vp, rt->origin()); 2007 this->flushScissor(scissorState, vp, rt->origin());
1990 GL_CALL(ResolveMultisampleFramebuffer()); 2008 GL_CALL(ResolveMultisampleFramebuffer());
1991 } else { 2009 } else {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSub Image 2543 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSub Image
2526 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps 2544 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2527 // many drivers would allow it to work, but ANGLE does not. 2545 // many drivers would allow it to work, but ANGLE does not.
2528 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalF ormat() && 2546 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalF ormat() &&
2529 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig = = src->config())) { 2547 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig = = src->config())) {
2530 return false; 2548 return false;
2531 } 2549 }
2532 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->as RenderTarget()); 2550 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->as RenderTarget());
2533 // If dst is multisampled (and uses an extension where there is a separate M SAA renderbuffer) 2551 // If dst is multisampled (and uses an extension where there is a separate M SAA renderbuffer)
2534 // then we don't want to copy to the texture but to the MSAA buffer. 2552 // then we don't want to copy to the texture but to the MSAA buffer.
2535 if (dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) { 2553 if (dstRT && dstRT->renderFBO() != dstRT->textureFBO()) {
2536 return false; 2554 return false;
2537 } 2555 }
2538 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget()); 2556 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget());
2539 // If the src is multisampled (and uses an extension where there is a separa te MSAA 2557 // If the src is multisampled (and uses an extension where there is a separa te MSAA
2540 // renderbuffer) then it is an invalid operation to call CopyTexSubImage 2558 // renderbuffer) then it is an invalid operation to call CopyTexSubImage
2541 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { 2559 if (srcRT && srcRT->renderFBO() != srcRT->textureFBO()) {
2542 return false; 2560 return false;
2543 } 2561 }
2544 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) && 2562 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) &&
2545 dst->asTexture() && 2563 dst->asTexture() &&
2546 dst->origin() == src->origin() && 2564 dst->origin() == src->origin() &&
2547 !GrPixelConfigIsCompressed(src->config())) { 2565 !GrPixelConfigIsCompressed(src->config())) {
2548 return true; 2566 return true;
2549 } else { 2567 } else {
2550 return false; 2568 return false;
2551 } 2569 }
2552 } 2570 }
2553 2571
2554 } 2572 }
2555 2573
2556 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha t the copy rect is 2574 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha t the copy rect is
2557 // relative to is output. 2575 // relative to is output.
2558 GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLI Rect* viewport, 2576 GrGLGpu::FBOBinding GrGLGpu::bindSurfaceAsFBOForCopy(GrSurface* surface, FBOBind ing binding,
2559 TempFBOTarget tempFBOTarget) { 2577 GrGLIRect* viewport) {
2560 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge t()); 2578 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge t());
2561 if (NULL == rt) { 2579 if (NULL == rt) {
2562 SkASSERT(surface->asTexture()); 2580 SkASSERT(surface->asTexture());
2563 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur eID(); 2581 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur eID();
2564 GrGLuint* tempFBOID; 2582 GrGLFBO* tempFBO;
2565 tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTem pDstFBOID;
2566 2583
2567 if (0 == *tempFBOID) { 2584 if (kBlitSrc_FBOBinding == binding || kCopyTexSrc_FBOBinding == binding) {
2568 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID)); 2585 if (!fTempSrcFBO) {
2586 fTempSrcFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface())));
2587 SkASSERT(fTempSrcFBO->isValid());
2588 }
2589 tempFBO = fTempSrcFBO;
2590 } else {
2591 SkASSERT(kBlitDst_FBOBinding == binding);
2592 if (!fTempDstFBO) {
2593 fTempDstFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface())));
2594 SkASSERT(fTempDstFBO->isValid());
2595 }
2596 tempFBO = fTempDstFBO;
2569 } 2597 }
2570 2598
2571 fStats.incRenderTargetBinds(); 2599 GrGLenum target = this->bindFBO(binding, tempFBO);
2572 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, *tempFBOID)); 2600 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(target,
2573 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget,
2574 GR_GL_COLOR_ATTACHM ENT0, 2601 GR_GL_COLOR_ATTACHM ENT0,
2575 GR_GL_TEXTURE_2D, 2602 GR_GL_TEXTURE_2D,
2576 texID, 2603 texID,
2577 0)); 2604 0));
2578 viewport->fLeft = 0; 2605 viewport->fLeft = 0;
2579 viewport->fBottom = 0; 2606 viewport->fBottom = 0;
2580 viewport->fWidth = surface->width(); 2607 viewport->fWidth = surface->width();
2581 viewport->fHeight = surface->height(); 2608 viewport->fHeight = surface->height();
2582 return *tempFBOID; 2609 return binding;
2583 } else { 2610 } else {
2584 GrGLuint tempFBOID = 0; 2611 this->bindFBO(binding, rt->renderFBO());
2585 fStats.incRenderTargetBinds();
2586 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO ID()));
2587 *viewport = rt->getViewport(); 2612 *viewport = rt->getViewport();
2588 return tempFBOID; 2613 return kInvalidFBOBinding;
2589 } 2614 }
2590 } 2615 }
2591 2616
2592 void GrGLGpu::unbindTextureFromFBO(GrGLenum fboTarget) { 2617 void GrGLGpu::unbindSurfaceAsFBOForCopy(FBOBinding binding) {
2593 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, 2618 if (kInvalidFBOBinding == binding) {
2619 return;
2620 }
2621 GrGLFBO* tempFBO = kBlitDst_FBOBinding == binding ? fTempSrcFBO : fTempDstFB O;
2622 GrGLenum target = this->bindFBO(binding, tempFBO);
2623 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(target,
2594 GR_GL_COLOR_ATTACHMENT0 , 2624 GR_GL_COLOR_ATTACHMENT0 ,
2595 GR_GL_TEXTURE_2D, 2625 GR_GL_TEXTURE_2D,
2596 0, 2626 0,
2597 0)); 2627 0));
2598 } 2628 }
2599 2629
2600 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) { 2630 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) {
2601 // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If neither are 2631 // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2602 // possible and we return false to fallback to creating a render target dst for render-to- 2632 // possible and we return false to fallback to creating a render target dst for render-to-
2603 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger ing temporary fbo 2633 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger ing temporary fbo
(...skipping 10 matching lines...) Expand all
2614 desc->fConfig = kBGRA_8888_GrPixelConfig; 2644 desc->fConfig = kBGRA_8888_GrPixelConfig;
2615 return true; 2645 return true;
2616 } 2646 }
2617 return false; 2647 return false;
2618 } else if (NULL == src->asRenderTarget()) { 2648 } else if (NULL == src->asRenderTarget()) {
2619 // CopyTexSubImage2D or fbo blit would require creating a temp fbo for t he src. 2649 // CopyTexSubImage2D or fbo blit would require creating a temp fbo for t he src.
2620 return false; 2650 return false;
2621 } 2651 }
2622 2652
2623 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget()); 2653 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget());
2624 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { 2654 if (srcRT && srcRT->renderFBO() != srcRT->textureFBO()) {
2625 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO blit or 2655 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO blit or
2626 // fail. 2656 // fail.
2627 if (this->caps()->isConfigRenderable(src->config(), false)) { 2657 if (this->caps()->isConfigRenderable(src->config(), false)) {
2628 desc->fOrigin = kDefault_GrSurfaceOrigin; 2658 desc->fOrigin = kDefault_GrSurfaceOrigin;
2629 desc->fFlags = kRenderTarget_GrSurfaceFlag; 2659 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2630 desc->fConfig = src->config(); 2660 desc->fConfig = src->config();
2631 return true; 2661 return true;
2632 } 2662 }
2633 return false; 2663 return false;
2634 } 2664 }
2635 2665
2636 // We'll do a CopyTexSubImage. Make the dst a plain old texture. 2666 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
2637 desc->fConfig = src->config(); 2667 desc->fConfig = src->config();
2638 desc->fOrigin = src->origin(); 2668 desc->fOrigin = src->origin();
2639 desc->fFlags = kNone_GrSurfaceFlags; 2669 desc->fFlags = kNone_GrSurfaceFlags;
2640 return true; 2670 return true;
2641 } 2671 }
2642 2672
2643 bool GrGLGpu::copySurface(GrSurface* dst, 2673 bool GrGLGpu::copySurface(GrSurface* dst,
2644 GrSurface* src, 2674 GrSurface* src,
2645 const SkIRect& srcRect, 2675 const SkIRect& srcRect,
2646 const SkIPoint& dstPoint) { 2676 const SkIPoint& dstPoint) {
2647 bool copied = false; 2677 bool copied = false;
2678 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2679 srcRect.width(), srcRect.height());
2648 if (can_copy_texsubimage(dst, src, this)) { 2680 if (can_copy_texsubimage(dst, src, this)) {
2649 GrGLuint srcFBO;
2650 GrGLIRect srcVP; 2681 GrGLIRect srcVP;
2651 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_Tem pFBOTarget); 2682 FBOBinding srcFBOBinding = this->bindSurfaceAsFBOForCopy(src, kCopyTexSr c_FBOBinding,
2683 &srcVP);
2652 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); 2684 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture());
2653 SkASSERT(dstTex); 2685 SkASSERT(dstTex);
2654 // We modified the bound FBO
2655 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
2656 GrGLIRect srcGLRect; 2686 GrGLIRect srcGLRect;
2657 srcGLRect.setRelativeTo(srcVP, 2687 srcGLRect.setRelativeTo(srcVP,
2658 srcRect.fLeft, 2688 srcRect.fLeft,
2659 srcRect.fTop, 2689 srcRect.fTop,
2660 srcRect.width(), 2690 srcRect.width(),
2661 srcRect.height(), 2691 srcRect.height(),
2662 src->origin()); 2692 src->origin());
2663 2693
2664 this->setScratchTextureUnit(); 2694 this->setScratchTextureUnit();
2665 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); 2695 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID()));
2666 GrGLint dstY; 2696 GrGLint dstY;
2667 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { 2697 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) {
2668 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); 2698 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight);
2669 } else { 2699 } else {
2670 dstY = dstPoint.fY; 2700 dstY = dstPoint.fY;
2671 } 2701 }
2672 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, 2702 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0,
2673 dstPoint.fX, dstY, 2703 dstPoint.fX, dstY,
2674 srcGLRect.fLeft, srcGLRect.fBottom, 2704 srcGLRect.fLeft, srcGLRect.fBottom,
2675 srcGLRect.fWidth, srcGLRect.fHeight)); 2705 srcGLRect.fWidth, srcGLRect.fHeight));
2676 copied = true; 2706 copied = true;
2677 if (srcFBO) { 2707 this->unbindSurfaceAsFBOForCopy(srcFBOBinding);
2678 this->unbindTextureFromFBO(GR_GL_FRAMEBUFFER);
2679 }
2680 } else if (can_blit_framebuffer(dst, src, this)) { 2708 } else if (can_blit_framebuffer(dst, src, this)) {
2681 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2682 srcRect.width(), srcRect.height());
2683 bool selfOverlap = false; 2709 bool selfOverlap = false;
2684 if (dst == src) { 2710 if (dst == src) {
2685 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); 2711 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect);
2686 } 2712 }
2687 2713
2688 if (!selfOverlap) { 2714 if (!selfOverlap) {
2689 GrGLuint dstFBO;
2690 GrGLuint srcFBO;
2691 GrGLIRect dstVP; 2715 GrGLIRect dstVP;
2692 GrGLIRect srcVP; 2716 GrGLIRect srcVP;
2693 dstFBO = this->bindSurfaceAsFBO(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP, 2717 FBOBinding dstFBOBinding = this->bindSurfaceAsFBOForCopy(dst, kBlitD st_FBOBinding,
2694 kDst_TempFBOTarget); 2718 &dstVP);
2695 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_READ_FRAMEBUFFER, &srcVP, 2719 FBOBinding srcFBOBinding = this->bindSurfaceAsFBOForCopy(src, kBlitS rc_FBOBinding,
2696 kSrc_TempFBOTarget); 2720 &srcVP);
2697 // We modified the bound FBO 2721
2698 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
2699 GrGLIRect srcGLRect; 2722 GrGLIRect srcGLRect;
2700 GrGLIRect dstGLRect; 2723 GrGLIRect dstGLRect;
2701 srcGLRect.setRelativeTo(srcVP, 2724 srcGLRect.setRelativeTo(srcVP,
2702 srcRect.fLeft, 2725 srcRect.fLeft,
2703 srcRect.fTop, 2726 srcRect.fTop,
2704 srcRect.width(), 2727 srcRect.width(),
2705 srcRect.height(), 2728 srcRect.height(),
2706 src->origin()); 2729 src->origin());
2707 dstGLRect.setRelativeTo(dstVP, 2730 dstGLRect.setRelativeTo(dstVP,
2708 dstRect.fLeft, 2731 dstRect.fLeft,
(...skipping 17 matching lines...) Expand all
2726 } 2749 }
2727 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, 2750 GL_CALL(BlitFramebuffer(srcGLRect.fLeft,
2728 srcY0, 2751 srcY0,
2729 srcGLRect.fLeft + srcGLRect.fWidth, 2752 srcGLRect.fLeft + srcGLRect.fWidth,
2730 srcY1, 2753 srcY1,
2731 dstGLRect.fLeft, 2754 dstGLRect.fLeft,
2732 dstGLRect.fBottom, 2755 dstGLRect.fBottom,
2733 dstGLRect.fLeft + dstGLRect.fWidth, 2756 dstGLRect.fLeft + dstGLRect.fWidth,
2734 dstGLRect.fBottom + dstGLRect.fHeight, 2757 dstGLRect.fBottom + dstGLRect.fHeight,
2735 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); 2758 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
2736 if (dstFBO) { 2759 this->unbindSurfaceAsFBOForCopy(dstFBOBinding);
2737 this->unbindTextureFromFBO(GR_GL_DRAW_FRAMEBUFFER); 2760 this->unbindSurfaceAsFBOForCopy(srcFBOBinding);
2738 }
2739 if (srcFBO) {
2740 this->unbindTextureFromFBO(GR_GL_READ_FRAMEBUFFER);
2741 }
2742 copied = true; 2761 copied = true;
2743 } 2762 }
2744 } 2763 }
2764 if (copied) {
2765 this->markSurfaceContentsDirty(dst, &dstRect);
2766 }
2745 return copied; 2767 return copied;
2746 } 2768 }
2747 2769
2748 bool GrGLGpu::canCopySurface(const GrSurface* dst, 2770 bool GrGLGpu::canCopySurface(const GrSurface* dst,
2749 const GrSurface* src, 2771 const GrSurface* src,
2750 const SkIRect& srcRect, 2772 const SkIRect& srcRect,
2751 const SkIPoint& dstPoint) { 2773 const SkIPoint& dstPoint) {
2752 // This mirrors the logic in onCopySurface. 2774 // This mirrors the logic in onCopySurface.
2753 if (can_copy_texsubimage(dst, src, this)) { 2775 if (can_copy_texsubimage(dst, src, this)) {
2754 return true; 2776 return true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 this->setVertexArrayID(gpu, 0); 2837 this->setVertexArrayID(gpu, 0);
2816 } 2838 }
2817 int attrCount = gpu->glCaps().maxVertexAttributes(); 2839 int attrCount = gpu->glCaps().maxVertexAttributes();
2818 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2840 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2819 fDefaultVertexArrayAttribState.resize(attrCount); 2841 fDefaultVertexArrayAttribState.resize(attrCount);
2820 } 2842 }
2821 attribState = &fDefaultVertexArrayAttribState; 2843 attribState = &fDefaultVertexArrayAttribState;
2822 } 2844 }
2823 return attribState; 2845 return attribState;
2824 } 2846 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLNoOpInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698