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

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

Issue 970613003: Revert of Improve tracking of bound FBOs in GrGLGpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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;
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
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
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
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->bindFBO(kDraw_FBOBinding, 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->bindFBO(kDraw_FBOBinding, 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
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()); 1192
1201 GrGLenum fboTarget = this->bindFBO(kDraw_FBOBinding, fStencilCle arFBO); 1193 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID));
1202 GL_CALL(FramebufferRenderbuffer(fboTarget, 1194 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1195 fStats.incRenderTargetBinds();
1196 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1203 GR_GL_STENCIL_ATTACHMENT, 1197 GR_GL_STENCIL_ATTACHMENT,
1204 GR_GL_RENDERBUFFER, sbDesc.fRend erbufferID)); 1198 GR_GL_RENDERBUFFER, sbDesc.fRend erbufferID));
1205 if (sFmt.fPacked) { 1199 if (sFmt.fPacked) {
1206 GL_CALL(FramebufferRenderbuffer(fboTarget, 1200 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1207 GR_GL_DEPTH_ATTACHMENT, 1201 GR_GL_DEPTH_ATTACHMENT,
1208 GR_GL_RENDERBUFFER, sbDesc.f RenderbufferID)); 1202 GR_GL_RENDERBUFFER, sbDesc.f RenderbufferID));
1209 } 1203 }
1210 1204
1211 GL_CALL(ClearStencil(0)); 1205 GL_CALL(ClearStencil(0));
1212 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1206 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1213 1207
1214 // 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.
1215 GL_CALL(FramebufferRenderbuffer(fboTarget, 1209 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1216 GR_GL_STENCIL_ATTACHMENT, 1210 GR_GL_STENCIL_ATTACHMENT,
1217 GR_GL_RENDERBUFFER, 0)); 1211 GR_GL_RENDERBUFFER, 0));
1218 if (sFmt.fPacked) { 1212 if (sFmt.fPacked) {
1219 GL_CALL(FramebufferRenderbuffer(fboTarget, 1213 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1220 GR_GL_DEPTH_ATTACHMENT, 1214 GR_GL_DEPTH_ATTACHMENT,
1221 GR_GL_RENDERBUFFER, 0)); 1215 GR_GL_RENDERBUFFER, 0));
1222 } 1216 }
1223 1217
1224 return true; 1218 return true;
1225 } 1219 }
1226 // 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
1227 // again. 1221 // again.
1228 sb->resourcePriv().removeScratchKey(); 1222 sb->resourcePriv().removeScratchKey();
1229 // 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.
1230 sbDesc.fRenderbufferID = 0; 1224 sbDesc.fRenderbufferID = 0;
1231 } 1225 }
1232 } 1226 }
1233 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); 1227 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID));
1234 return false; 1228 return false;
1235 } 1229 }
1236 1230
1237 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) { 1231 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) {
1238 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); 1232 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt);
1233
1234 GrGLuint fbo = glrt->renderFBOID();
1235
1239 if (NULL == sb) { 1236 if (NULL == sb) {
1240 if (rt->renderTargetPriv().getStencilBuffer()) { 1237 if (rt->renderTargetPriv().getStencilBuffer()) {
1241 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1238 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1242 GR_GL_STENCIL_ATTACHMENT, 1239 GR_GL_STENCIL_ATTACHMENT,
1243 GR_GL_RENDERBUFFER, 0)); 1240 GR_GL_RENDERBUFFER, 0));
1244 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1241 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1245 GR_GL_DEPTH_ATTACHMENT, 1242 GR_GL_DEPTH_ATTACHMENT,
1246 GR_GL_RENDERBUFFER, 0)); 1243 GR_GL_RENDERBUFFER, 0));
1247 #ifdef SK_DEBUG 1244 #ifdef SK_DEBUG
1248 GrGLenum status; 1245 GrGLenum status;
1249 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1246 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1250 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); 1247 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
1251 #endif 1248 #endif
1252 } 1249 }
1253 return true; 1250 return true;
1254 } else { 1251 } else {
1255 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); 1252 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb);
1256 GrGLuint rb = glsb->renderbufferID(); 1253 GrGLuint rb = glsb->renderbufferID();
1257 1254
1258 GrGLenum fboTarget = this->bindFBO(kDraw_FBOBinding, glrt->renderFBO()); 1255 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1259 1256 fStats.incRenderTargetBinds();
1260 GL_CALL(FramebufferRenderbuffer(fboTarget, 1257 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
1258 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1261 GR_GL_STENCIL_ATTACHMENT, 1259 GR_GL_STENCIL_ATTACHMENT,
1262 GR_GL_RENDERBUFFER, rb)); 1260 GR_GL_RENDERBUFFER, rb));
1263 if (glsb->format().fPacked) { 1261 if (glsb->format().fPacked) {
1264 GL_CALL(FramebufferRenderbuffer(fboTarget, 1262 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1265 GR_GL_DEPTH_ATTACHMENT, 1263 GR_GL_DEPTH_ATTACHMENT,
1266 GR_GL_RENDERBUFFER, rb)); 1264 GR_GL_RENDERBUFFER, rb));
1267 } else { 1265 } else {
1268 GL_CALL(FramebufferRenderbuffer(fboTarget, 1266 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1269 GR_GL_DEPTH_ATTACHMENT, 1267 GR_GL_DEPTH_ATTACHMENT,
1270 GR_GL_RENDERBUFFER, 0)); 1268 GR_GL_RENDERBUFFER, 0));
1271 } 1269 }
1272 1270
1273 GrGLenum status; 1271 GrGLenum status;
1274 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) { 1272 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) {
1275 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1273 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1276 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 1274 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
1277 GL_CALL(FramebufferRenderbuffer(fboTarget, 1275 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1278 GR_GL_STENCIL_ATTACHMENT, 1276 GR_GL_STENCIL_ATTACHMENT,
1279 GR_GL_RENDERBUFFER, 0)); 1277 GR_GL_RENDERBUFFER, 0));
1280 if (glsb->format().fPacked) { 1278 if (glsb->format().fPacked) {
1281 GL_CALL(FramebufferRenderbuffer(fboTarget, 1279 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1282 GR_GL_DEPTH_ATTACHMENT, 1280 GR_GL_DEPTH_ATTACHMENT,
1283 GR_GL_RENDERBUFFER, 0)); 1281 GR_GL_RENDERBUFFER, 0));
1284 } 1282 }
1285 return false; 1283 return false;
1286 } else { 1284 } else {
1287 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( 1285 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified(
1288 rt->config(), 1286 rt->config(),
1289 glsb->format()); 1287 glsb->format());
1290 } 1288 }
1291 } 1289 }
1292 return true; 1290 return true;
1293 } 1291 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 1416
1419 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr acker); 1417 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr acker);
1420 1418
1421 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget()); 1419 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
1422 this->flushStencil(pipeline.getStencil()); 1420 this->flushStencil(pipeline.getStencil());
1423 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 1421 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
1424 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), isLineDraw); 1422 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), isLineDraw);
1425 1423
1426 // 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
1427 // to be msaa-resolved (which will modify bound FBO state). 1425 // to be msaa-resolved (which will modify bound FBO state).
1428 this->prepareToDrawToRenderTarget(glRT, NULL); 1426 this->flushRenderTarget(glRT, NULL);
1429 1427
1430 return true; 1428 return true;
1431 } 1429 }
1432 1430
1433 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, 1431 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
1434 const GrDrawTarget::DrawInfo& info, 1432 const GrDrawTarget::DrawInfo& info,
1435 size_t* indexOffsetInBytes) { 1433 size_t* indexOffsetInBytes) {
1436 GrGLVertexBuffer* vbuf; 1434 GrGLVertexBuffer* vbuf;
1437 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); 1435 vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
1438 1436
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 // flushScissor expects rect to be clipped to the target. 1513 // flushScissor expects rect to be clipped to the target.
1516 clippedRect = *rect; 1514 clippedRect = *rect;
1517 SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height()); 1515 SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height());
1518 if (clippedRect.intersect(rtRect)) { 1516 if (clippedRect.intersect(rtRect)) {
1519 rect = &clippedRect; 1517 rect = &clippedRect;
1520 } else { 1518 } else {
1521 return; 1519 return;
1522 } 1520 }
1523 } 1521 }
1524 1522
1525 this->prepareToDrawToRenderTarget(glRT, rect); 1523 this->flushRenderTarget(glRT, rect);
1526 GrScissorState scissorState; 1524 GrScissorState scissorState;
1527 if (rect) { 1525 if (rect) {
1528 scissorState.set(*rect); 1526 scissorState.set(*rect);
1529 } 1527 }
1530 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); 1528 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin());
1531 1529
1532 GrGLfloat r, g, b, a; 1530 GrGLfloat r, g, b, a;
1533 static const GrGLfloat scale255 = 1.f / 255.f; 1531 static const GrGLfloat scale255 = 1.f / 255.f;
1534 a = GrColorUnpackA(color) * scale255; 1532 a = GrColorUnpackA(color) * scale255;
1535 GrGLfloat scaleRGB = scale255; 1533 GrGLfloat scaleRGB = scale255;
1536 r = GrColorUnpackR(color) * scaleRGB; 1534 r = GrColorUnpackR(color) * scaleRGB;
1537 g = GrColorUnpackG(color) * scaleRGB; 1535 g = GrColorUnpackG(color) * scaleRGB;
1538 b = GrColorUnpackB(color) * scaleRGB; 1536 b = GrColorUnpackB(color) * scaleRGB;
1539 1537
1540 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));
1541 fHWWriteToColor = kYes_TriState; 1539 fHWWriteToColor = kYes_TriState;
1542 GL_CALL(ClearColor(r, g, b, a)); 1540 GL_CALL(ClearColor(r, g, b, a));
1543 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); 1541 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
1544 } 1542 }
1545 1543
1546 void GrGLGpu::discard(GrRenderTarget* renderTarget) { 1544 void GrGLGpu::discard(GrRenderTarget* renderTarget) {
1547 SkASSERT(renderTarget); 1545 SkASSERT(renderTarget);
1548 if (!this->caps()->discardRenderTargetSupport()) { 1546 if (!this->caps()->discardRenderTargetSupport()) {
1549 return; 1547 return;
1550 } 1548 }
1551 1549
1552 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); 1550 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
1553 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 }
1554 switch (this->glCaps().invalidateFBType()) { 1556 switch (this->glCaps().invalidateFBType()) {
1555 case GrGLCaps::kNone_InvalidateFBType: 1557 case GrGLCaps::kNone_InvalidateFBType:
1556 SkFAIL("Should never get here."); 1558 SkFAIL("Should never get here.");
1557 break; 1559 break;
1558 case GrGLCaps::kInvalidate_InvalidateFBType: 1560 case GrGLCaps::kInvalidate_InvalidateFBType:
1559 if (glRT->renderFBO()->isDefaultFramebuffer()) { 1561 if (0 == glRT->renderFBOID()) {
1560 // 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
1561 // 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
1562 // types. 1564 // types.
1563 static const GrGLenum attachments[] = { GR_GL_COLOR }; 1565 static const GrGLenum attachments[] = { GR_GL_COLOR };
1564 GL_CALL(InvalidateFramebuffer(fboTarget, SK_ARRAY_COUNT(attachme nts), 1566 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT( attachments),
1565 attachments)); 1567 attachments));
1566 } else { 1568 } else {
1567 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 }; 1569 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 };
1568 GL_CALL(InvalidateFramebuffer(fboTarget, SK_ARRAY_COUNT(attachme nts), 1570 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT( attachments),
1569 attachments)); 1571 attachments));
1570 } 1572 }
1571 break; 1573 break;
1572 case GrGLCaps::kDiscard_InvalidateFBType: { 1574 case GrGLCaps::kDiscard_InvalidateFBType: {
1573 if (glRT->renderFBO()->isDefaultFramebuffer()) { 1575 if (0 == glRT->renderFBOID()) {
1574 // 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
1575 // 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
1576 // types. See glDiscardFramebuffer() spec. 1578 // types. See glDiscardFramebuffer() spec.
1577 static const GrGLenum attachments[] = { GR_GL_COLOR }; 1579 static const GrGLenum attachments[] = { GR_GL_COLOR };
1578 GL_CALL(DiscardFramebuffer(fboTarget, SK_ARRAY_COUNT(attachments ), 1580 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(att achments),
1579 attachments)); 1581 attachments));
1580 } else { 1582 } else {
1581 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 }; 1583 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 };
1582 GL_CALL(DiscardFramebuffer(fboTarget, SK_ARRAY_COUNT(attachments ), 1584 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(att achments),
1583 attachments)); 1585 attachments));
1584 } 1586 }
1585 break; 1587 break;
1586 } 1588 }
1587 } 1589 }
1588 renderTarget->flagAsResolved(); 1590 renderTarget->flagAsResolved();
1589 } 1591 }
1590 1592
1591 1593
1592 void GrGLGpu::clearStencil(GrRenderTarget* target) { 1594 void GrGLGpu::clearStencil(GrRenderTarget* target) {
1593 if (NULL == target) { 1595 if (NULL == target) {
1594 return; 1596 return;
1595 } 1597 }
1596 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); 1598 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
1597 this->prepareToDrawToRenderTarget(glRT, &SkIRect::EmptyIRect()); 1599 this->flushRenderTarget(glRT, &SkIRect::EmptyIRect());
1598 1600
1599 this->disableScissor(); 1601 this->disableScissor();
1600 1602
1601 GL_CALL(StencilMask(0xffffffff)); 1603 GL_CALL(StencilMask(0xffffffff));
1602 GL_CALL(ClearStencil(0)); 1604 GL_CALL(ClearStencil(0));
1603 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1605 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1604 fHWStencilSettings.invalidate(); 1606 fHWStencilSettings.invalidate();
1605 } 1607 }
1606 1608
1607 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
1623 // 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.
1624 static const GrGLint clipStencilMask = ~0; 1626 static const GrGLint clipStencilMask = ~0;
1625 #endif 1627 #endif
1626 GrGLint value; 1628 GrGLint value;
1627 if (insideClip) { 1629 if (insideClip) {
1628 value = (1 << (stencilBitCount - 1)); 1630 value = (1 << (stencilBitCount - 1));
1629 } else { 1631 } else {
1630 value = 0; 1632 value = 0;
1631 } 1633 }
1632 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); 1634 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
1633 this->prepareToDrawToRenderTarget(glRT, &SkIRect::EmptyIRect()); 1635 this->flushRenderTarget(glRT, &SkIRect::EmptyIRect());
1634 1636
1635 GrScissorState scissorState; 1637 GrScissorState scissorState;
1636 scissorState.set(rect); 1638 scissorState.set(rect);
1637 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); 1639 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin());
1638 1640
1639 GL_CALL(StencilMask((uint32_t) clipStencilMask)); 1641 GL_CALL(StencilMask((uint32_t) clipStencilMask));
1640 GL_CALL(ClearStencil(value)); 1642 GL_CALL(ClearStencil(value));
1641 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1643 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1642 fHWStencilSettings.invalidate(); 1644 fHWStencilSettings.invalidate();
1643 } 1645 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 size_t bpp = GrBytesPerPixel(config); 1695 size_t bpp = GrBytesPerPixel(config);
1694 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, 1696 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp,
1695 &left, &top, &width, &height, 1697 &left, &top, &width, &height,
1696 const_cast<const void**>(&buffer), 1698 const_cast<const void**>(&buffer),
1697 &rowBytes)) { 1699 &rowBytes)) {
1698 return false; 1700 return false;
1699 } 1701 }
1700 1702
1701 // resolve the render target if necessary 1703 // resolve the render target if necessary
1702 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); 1704 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target);
1703 if (tgt->getResolveType() == GrGLRenderTarget::kCantResolve_ResolveType) { 1705 switch (tgt->getResolveType()) {
1704 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");
1705 } 1720 }
1706 if (tgt->getResolveType() == GrGLRenderTarget::kCanResolve_ResolveType) {
1707 this->onResolveRenderTarget(tgt);
1708 }
1709 this->bindFBO(kRead_FBOBinding, tgt->textureFBO());
1710 1721
1711 const GrGLIRect& glvp = tgt->getViewport(); 1722 const GrGLIRect& glvp = tgt->getViewport();
1712 1723
1713 // the read rect is viewport-relative 1724 // the read rect is viewport-relative
1714 GrGLIRect readRect; 1725 GrGLIRect readRect;
1715 readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); 1726 readRect.setRelativeTo(glvp, left, top, width, height, target->origin());
1716 1727
1717 size_t tightRowBytes = bpp * width; 1728 size_t tightRowBytes = bpp * width;
1718 if (0 == rowBytes) { 1729 if (0 == rowBytes) {
1719 rowBytes = tightRowBytes; 1730 rowBytes = tightRowBytes;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 char* bottom = top + (height - 1) * rowBytes; 1775 char* bottom = top + (height - 1) * rowBytes;
1765 for (int y = 0; y < halfY; y++) { 1776 for (int y = 0; y < halfY; y++) {
1766 memcpy(tmpRow, top, tightRowBytes); 1777 memcpy(tmpRow, top, tightRowBytes);
1767 memcpy(top, bottom, tightRowBytes); 1778 memcpy(top, bottom, tightRowBytes);
1768 memcpy(bottom, tmpRow, tightRowBytes); 1779 memcpy(bottom, tmpRow, tightRowBytes);
1769 top += rowBytes; 1780 top += rowBytes;
1770 bottom -= rowBytes; 1781 bottom -= rowBytes;
1771 } 1782 }
1772 } 1783 }
1773 } else { 1784 } else {
1774 SkASSERT(readDst != buffer); 1785 SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes);
1775 SkASSERT(rowBytes != tightRowBytes);
1776 // copy from readDst to buffer while flipping y 1786 // copy from readDst to buffer while flipping y
1777 // const int halfY = height >> 1; 1787 // const int halfY = height >> 1;
1778 const char* src = reinterpret_cast<const char*>(readDst); 1788 const char* src = reinterpret_cast<const char*>(readDst);
1779 char* dst = reinterpret_cast<char*>(buffer); 1789 char* dst = reinterpret_cast<char*>(buffer);
1780 if (flipY) { 1790 if (flipY) {
1781 dst += (height-1) * rowBytes; 1791 dst += (height-1) * rowBytes;
1782 } 1792 }
1783 for (int y = 0; y < height; y++) { 1793 for (int y = 0; y < height; y++) {
1784 memcpy(dst, src, tightRowBytes); 1794 memcpy(dst, src, tightRowBytes);
1785 src += readDstRowBytes; 1795 src += readDstRowBytes;
1786 if (!flipY) { 1796 if (!flipY) {
1787 dst += rowBytes; 1797 dst += rowBytes;
1788 } else { 1798 } else {
1789 dst -= rowBytes; 1799 dst -= rowBytes;
1790 } 1800 }
1791 } 1801 }
1792 } 1802 }
1793 return true; 1803 return true;
1794 } 1804 }
1795 1805
1796 GrGLenum GrGLGpu::bindFBO(FBOBinding binding, const GrGLFBO* fbo) { 1806 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound) {
1797 SkASSERT(fbo);
1798 SkASSERT(fbo->isValid());
1799 GrGLenum target;
1800 HWFBOBinding* hwFBOState;
1801 if (!this->glCaps().usesMSAARenderBuffers()) {
1802 target = GR_GL_FRAMEBUFFER;
1803 hwFBOState = &fHWFBOBinding[0];
1804 } else {
1805 target = kDraw_FBOBinding == binding ? GR_GL_DRAW_FRAMEBUFFER : GR_GL_RE AD_FRAMEBUFFER;
1806 hwFBOState = &fHWFBOBinding[binding];
1807 }
1808 1807
1809 if (hwFBOState->fFBO != fbo) { 1808 SkASSERT(target);
1809
1810 uint32_t rtID = target->getUniqueID();
1811 if (fHWBoundRenderTargetUniqueID != rtID) {
1810 fStats.incRenderTargetBinds(); 1812 fStats.incRenderTargetBinds();
1811 GL_CALL(BindFramebuffer(target, fbo->fboID())); 1813 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID()));
1812 hwFBOState->fFBO.reset(SkRef(fbo));
1813 }
1814 return target;
1815 }
1816
1817 void GrGLGpu::setViewport(const GrGLIRect& viewport) {
1818 if (viewport != fHWViewport) {
1819 viewport.pushToGLViewport(this->glInterface());
1820 fHWViewport = viewport;
1821 }
1822 }
1823
1824 void GrGLGpu::prepareToDrawToRenderTarget(GrGLRenderTarget* target, const SkIRec t* bound) {
1825 SkASSERT(target);
1826 this->bindFBO(kDraw_FBOBinding, target->renderFBO());
1827
1828 #ifdef SK_DEBUG 1814 #ifdef SK_DEBUG
1829 // don't do this check in Chromium -- this is causing 1815 // don't do this check in Chromium -- this is causing
1830 // lots of repeated command buffer flushes when the compositor is 1816 // lots of repeated command buffer flushes when the compositor is
1831 // rendering with Ganesh, which is really slow; even too slow for 1817 // rendering with Ganesh, which is really slow; even too slow for
1832 // Debug mode. 1818 // Debug mode.
1833 if (!this->glContext().isChromium()) { 1819 if (!this->glContext().isChromium()) {
1834 GrGLenum status; 1820 GrGLenum status;
1835 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1821 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1836 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 1822 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
1837 SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x\n", status); 1823 SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x \n", status);
1824 }
1825 }
1826 #endif
1827 fHWBoundRenderTargetUniqueID = rtID;
1828 const GrGLIRect& vp = target->getViewport();
1829 if (fHWViewport != vp) {
1830 vp.pushToGLViewport(this->glInterface());
1831 fHWViewport = vp;
1838 } 1832 }
1839 } 1833 }
1840 #endif
1841 this->setViewport(target->getViewport());
1842 if (NULL == bound || !bound->isEmpty()) { 1834 if (NULL == bound || !bound->isEmpty()) {
1843 target->flagAsNeedingResolve(bound); 1835 target->flagAsNeedingResolve(bound);
1844 } 1836 }
1845 1837
1846 GrTexture *texture = target->asTexture(); 1838 GrTexture *texture = target->asTexture();
1847 if (texture) { 1839 if (texture) {
1848 texture->texturePriv().dirtyMipMaps(true); 1840 texture->texturePriv().dirtyMipMaps(true);
1849 } 1841 }
1850 } 1842 }
1851 1843
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 1912
1921 void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) { 1913 void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) {
1922 this->flushColorWrite(false); 1914 this->flushColorWrite(false);
1923 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 1915 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
1924 1916
1925 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); 1917 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget);
1926 SkISize size = SkISize::Make(rt->width(), rt->height()); 1918 SkISize size = SkISize::Make(rt->width(), rt->height());
1927 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o rigin()); 1919 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o rigin());
1928 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); 1920 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin());
1929 this->flushHWAAState(rt, state.fUseHWAA, false); 1921 this->flushHWAAState(rt, state.fUseHWAA, false);
1930 this->prepareToDrawToRenderTarget(rt, NULL); 1922 this->flushRenderTarget(rt, NULL);
1931 1923
1932 fPathRendering->stencilPath(path, *state.fStencil); 1924 fPathRendering->stencilPath(path, *state.fStencil);
1933 } 1925 }
1934 1926
1935 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, 1927 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path,
1936 const GrStencilSettings& stencil) { 1928 const GrStencilSettings& stencil) {
1937 if (!this->flushGLState(args, false)) { 1929 if (!this->flushGLState(args, false)) {
1938 return; 1930 return;
1939 } 1931 }
1940 fPathRendering->drawPath(path, stencil); 1932 fPathRendering->drawPath(path, stencil);
(...skipping 12 matching lines...) Expand all
1953 } 1945 }
1954 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, 1946 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues,
1955 transformType, count, stencil); 1947 transformType, count, stencil);
1956 } 1948 }
1957 1949
1958 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { 1950 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) {
1959 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); 1951 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
1960 if (rt->needsResolve()) { 1952 if (rt->needsResolve()) {
1961 // Some extensions automatically resolves the texture when it is read. 1953 // Some extensions automatically resolves the texture when it is read.
1962 if (this->glCaps().usesMSAARenderBuffers()) { 1954 if (this->glCaps().usesMSAARenderBuffers()) {
1963 SkASSERT(rt->textureFBO() != rt->renderFBO()); 1955 SkASSERT(rt->textureFBOID() != rt->renderFBOID());
1964 this->bindFBO(kRead_FBOBinding, rt->renderFBO()); 1956 fStats.incRenderTargetBinds();
1965 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;
1966 const GrGLIRect& vp = rt->getViewport(); 1963 const GrGLIRect& vp = rt->getViewport();
1967 const SkIRect dirtyRect = rt->getResolveRect(); 1964 const SkIRect dirtyRect = rt->getResolveRect();
1968 1965
1969 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { 1966 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) {
1970 // Apple's extension uses the scissor as the blit bounds. 1967 // Apple's extension uses the scissor as the blit bounds.
1971 GrScissorState scissorState; 1968 GrScissorState scissorState;
1972 scissorState.set(dirtyRect); 1969 scissorState.set(dirtyRect);
1973 this->flushScissor(scissorState, vp, rt->origin()); 1970 this->flushScissor(scissorState, vp, rt->origin());
1974 GL_CALL(ResolveMultisampleFramebuffer()); 1971 GL_CALL(ResolveMultisampleFramebuffer());
1975 } else { 1972 } else {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 // 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
2519 // 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
2520 // many drivers would allow it to work, but ANGLE does not. 2517 // many drivers would allow it to work, but ANGLE does not.
2521 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalF ormat() && 2518 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalF ormat() &&
2522 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig = = src->config())) { 2519 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig = = src->config())) {
2523 return false; 2520 return false;
2524 } 2521 }
2525 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->as RenderTarget()); 2522 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->as RenderTarget());
2526 // 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)
2527 // 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.
2528 if (dstRT && dstRT->renderFBO() != dstRT->textureFBO()) { 2525 if (dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) {
2529 return false; 2526 return false;
2530 } 2527 }
2531 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget()); 2528 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget());
2532 // 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
2533 // renderbuffer) then it is an invalid operation to call CopyTexSubImage 2530 // renderbuffer) then it is an invalid operation to call CopyTexSubImage
2534 if (srcRT && srcRT->renderFBO() != srcRT->textureFBO()) { 2531 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
2535 return false; 2532 return false;
2536 } 2533 }
2537 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) && 2534 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) &&
2538 dst->asTexture() && 2535 dst->asTexture() &&
2539 dst->origin() == src->origin() && 2536 dst->origin() == src->origin() &&
2540 !GrPixelConfigIsCompressed(src->config())) { 2537 !GrPixelConfigIsCompressed(src->config())) {
2541 return true; 2538 return true;
2542 } else { 2539 } else {
2543 return false; 2540 return false;
2544 } 2541 }
2545 } 2542 }
2546 2543
2547 } 2544 }
2548 2545
2549 // 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
2550 // relative to is output. 2547 // relative to is output.
2551 GrGLGpu::FBOBinding GrGLGpu::bindSurfaceAsFBOForCopy(GrSurface* surface, FBOBind ing binding, 2548 GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLI Rect* viewport,
2552 GrGLIRect* viewport) { 2549 TempFBOTarget tempFBOTarget) {
2553 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge t()); 2550 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge t());
2554 if (NULL == rt) { 2551 if (NULL == rt) {
2555 SkASSERT(surface->asTexture()); 2552 SkASSERT(surface->asTexture());
2556 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur eID(); 2553 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur eID();
2557 GrGLFBO* tempFBO; 2554 GrGLuint* tempFBOID;
2555 tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTem pDstFBOID;
2558 2556
2559 if (kRead_FBOBinding == binding) { 2557 if (0 == *tempFBOID) {
2560 if (!fTempSrcFBO) { 2558 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID));
2561 fTempSrcFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface())));
2562 SkASSERT(fTempSrcFBO->isValid());
2563 }
2564 tempFBO = fTempSrcFBO;
2565 } else {
2566 SkASSERT(kDraw_FBOBinding == binding);
2567 if (!fTempDstFBO) {
2568 fTempDstFBO.reset(SkNEW_ARGS(GrGLFBO, (this->glInterface())));
2569 SkASSERT(fTempDstFBO->isValid());
2570 }
2571 tempFBO = fTempDstFBO;
2572 } 2559 }
2573 2560
2574 GrGLenum target = this->bindFBO(binding, tempFBO); 2561 fStats.incRenderTargetBinds();
2575 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(target, 2562 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, *tempFBOID));
2563 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget,
2576 GR_GL_COLOR_ATTACHM ENT0, 2564 GR_GL_COLOR_ATTACHM ENT0,
2577 GR_GL_TEXTURE_2D, 2565 GR_GL_TEXTURE_2D,
2578 texID, 2566 texID,
2579 0)); 2567 0));
2580 viewport->fLeft = 0; 2568 viewport->fLeft = 0;
2581 viewport->fBottom = 0; 2569 viewport->fBottom = 0;
2582 viewport->fWidth = surface->width(); 2570 viewport->fWidth = surface->width();
2583 viewport->fHeight = surface->height(); 2571 viewport->fHeight = surface->height();
2584 return binding; 2572 return *tempFBOID;
2585 } else { 2573 } else {
2586 this->bindFBO(binding, rt->renderFBO()); 2574 GrGLuint tempFBOID = 0;
2575 fStats.incRenderTargetBinds();
2576 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO ID()));
2587 *viewport = rt->getViewport(); 2577 *viewport = rt->getViewport();
2588 return kInvalidFBOBinding; 2578 return tempFBOID;
2589 } 2579 }
2590 } 2580 }
2591 2581
2592 void GrGLGpu::unbindSurfaceAsFBOForCopy(FBOBinding binding) { 2582 void GrGLGpu::unbindTextureFromFBO(GrGLenum fboTarget) {
2593 if (kInvalidFBOBinding == binding) { 2583 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget,
2594 return;
2595 }
2596 GrGLFBO* tempFBO = kDraw_FBOBinding == binding ? fTempSrcFBO : fTempDstFBO;
2597 GrGLenum target = this->bindFBO(binding, tempFBO);
2598 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(target,
2599 GR_GL_COLOR_ATTACHMENT0 , 2584 GR_GL_COLOR_ATTACHMENT0 ,
2600 GR_GL_TEXTURE_2D, 2585 GR_GL_TEXTURE_2D,
2601 0, 2586 0,
2602 0)); 2587 0));
2603 } 2588 }
2604 2589
2605 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) { 2590 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) {
2606 // 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
2607 // 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-
2608 // 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
2619 desc->fConfig = kBGRA_8888_GrPixelConfig; 2604 desc->fConfig = kBGRA_8888_GrPixelConfig;
2620 return true; 2605 return true;
2621 } 2606 }
2622 return false; 2607 return false;
2623 } else if (NULL == src->asRenderTarget()) { 2608 } else if (NULL == src->asRenderTarget()) {
2624 // 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.
2625 return false; 2610 return false;
2626 } 2611 }
2627 2612
2628 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget()); 2613 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget());
2629 if (srcRT && srcRT->renderFBO() != srcRT->textureFBO()) { 2614 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
2630 // 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
2631 // fail. 2616 // fail.
2632 if (this->caps()->isConfigRenderable(src->config(), false)) { 2617 if (this->caps()->isConfigRenderable(src->config(), false)) {
2633 desc->fOrigin = kDefault_GrSurfaceOrigin; 2618 desc->fOrigin = kDefault_GrSurfaceOrigin;
2634 desc->fFlags = kRenderTarget_GrSurfaceFlag; 2619 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2635 desc->fConfig = src->config(); 2620 desc->fConfig = src->config();
2636 return true; 2621 return true;
2637 } 2622 }
2638 return false; 2623 return false;
2639 } 2624 }
2640 2625
2641 // 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.
2642 desc->fConfig = src->config(); 2627 desc->fConfig = src->config();
2643 desc->fOrigin = src->origin(); 2628 desc->fOrigin = src->origin();
2644 desc->fFlags = kNone_GrSurfaceFlags; 2629 desc->fFlags = kNone_GrSurfaceFlags;
2645 return true; 2630 return true;
2646 } 2631 }
2647 2632
2648 bool GrGLGpu::copySurface(GrSurface* dst, 2633 bool GrGLGpu::copySurface(GrSurface* dst,
2649 GrSurface* src, 2634 GrSurface* src,
2650 const SkIRect& srcRect, 2635 const SkIRect& srcRect,
2651 const SkIPoint& dstPoint) { 2636 const SkIPoint& dstPoint) {
2652 bool copied = false; 2637 bool copied = false;
2653 if (can_copy_texsubimage(dst, src, this)) { 2638 if (can_copy_texsubimage(dst, src, this)) {
2639 GrGLuint srcFBO;
2654 GrGLIRect srcVP; 2640 GrGLIRect srcVP;
2655 FBOBinding srcFBOBinding = this->bindSurfaceAsFBOForCopy(src, kRead_FBOB inding, &srcVP); 2641 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_Tem pFBOTarget);
2656 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); 2642 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture());
2657 SkASSERT(dstTex); 2643 SkASSERT(dstTex);
2644 // We modified the bound FBO
2645 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
2658 GrGLIRect srcGLRect; 2646 GrGLIRect srcGLRect;
2659 srcGLRect.setRelativeTo(srcVP, 2647 srcGLRect.setRelativeTo(srcVP,
2660 srcRect.fLeft, 2648 srcRect.fLeft,
2661 srcRect.fTop, 2649 srcRect.fTop,
2662 srcRect.width(), 2650 srcRect.width(),
2663 srcRect.height(), 2651 srcRect.height(),
2664 src->origin()); 2652 src->origin());
2665 2653
2666 this->setScratchTextureUnit(); 2654 this->setScratchTextureUnit();
2667 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); 2655 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID()));
2668 GrGLint dstY; 2656 GrGLint dstY;
2669 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { 2657 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) {
2670 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); 2658 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight);
2671 } else { 2659 } else {
2672 dstY = dstPoint.fY; 2660 dstY = dstPoint.fY;
2673 } 2661 }
2674 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, 2662 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0,
2675 dstPoint.fX, dstY, 2663 dstPoint.fX, dstY,
2676 srcGLRect.fLeft, srcGLRect.fBottom, 2664 srcGLRect.fLeft, srcGLRect.fBottom,
2677 srcGLRect.fWidth, srcGLRect.fHeight)); 2665 srcGLRect.fWidth, srcGLRect.fHeight));
2678 copied = true; 2666 copied = true;
2679 this->unbindSurfaceAsFBOForCopy(srcFBOBinding); 2667 if (srcFBO) {
2668 this->unbindTextureFromFBO(GR_GL_FRAMEBUFFER);
2669 }
2680 } else if (can_blit_framebuffer(dst, src, this)) { 2670 } else if (can_blit_framebuffer(dst, src, this)) {
2681 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, 2671 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2682 srcRect.width(), srcRect.height()); 2672 srcRect.width(), srcRect.height());
2683 bool selfOverlap = false; 2673 bool selfOverlap = false;
2684 if (dst == src) { 2674 if (dst == src) {
2685 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); 2675 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect);
2686 } 2676 }
2687 2677
2688 if (!selfOverlap) { 2678 if (!selfOverlap) {
2679 GrGLuint dstFBO;
2680 GrGLuint srcFBO;
2689 GrGLIRect dstVP; 2681 GrGLIRect dstVP;
2690 GrGLIRect srcVP; 2682 GrGLIRect srcVP;
2691 FBOBinding dstFBOBinding = this->bindSurfaceAsFBOForCopy(dst, kDraw_ FBOBinding, &dstVP); 2683 dstFBO = this->bindSurfaceAsFBO(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP,
2692 FBOBinding srcFBOBinding = this->bindSurfaceAsFBOForCopy(src, kRead_ FBOBinding, &srcVP); 2684 kDst_TempFBOTarget);
2693 2685 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_READ_FRAMEBUFFER, &srcVP,
2686 kSrc_TempFBOTarget);
2687 // We modified the bound FBO
2688 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
2694 GrGLIRect srcGLRect; 2689 GrGLIRect srcGLRect;
2695 GrGLIRect dstGLRect; 2690 GrGLIRect dstGLRect;
2696 srcGLRect.setRelativeTo(srcVP, 2691 srcGLRect.setRelativeTo(srcVP,
2697 srcRect.fLeft, 2692 srcRect.fLeft,
2698 srcRect.fTop, 2693 srcRect.fTop,
2699 srcRect.width(), 2694 srcRect.width(),
2700 srcRect.height(), 2695 srcRect.height(),
2701 src->origin()); 2696 src->origin());
2702 dstGLRect.setRelativeTo(dstVP, 2697 dstGLRect.setRelativeTo(dstVP,
2703 dstRect.fLeft, 2698 dstRect.fLeft,
(...skipping 17 matching lines...) Expand all
2721 } 2716 }
2722 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, 2717 GL_CALL(BlitFramebuffer(srcGLRect.fLeft,
2723 srcY0, 2718 srcY0,
2724 srcGLRect.fLeft + srcGLRect.fWidth, 2719 srcGLRect.fLeft + srcGLRect.fWidth,
2725 srcY1, 2720 srcY1,
2726 dstGLRect.fLeft, 2721 dstGLRect.fLeft,
2727 dstGLRect.fBottom, 2722 dstGLRect.fBottom,
2728 dstGLRect.fLeft + dstGLRect.fWidth, 2723 dstGLRect.fLeft + dstGLRect.fWidth,
2729 dstGLRect.fBottom + dstGLRect.fHeight, 2724 dstGLRect.fBottom + dstGLRect.fHeight,
2730 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); 2725 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
2731 this->unbindSurfaceAsFBOForCopy(dstFBOBinding); 2726 if (dstFBO) {
2732 this->unbindSurfaceAsFBOForCopy(srcFBOBinding); 2727 this->unbindTextureFromFBO(GR_GL_DRAW_FRAMEBUFFER);
2728 }
2729 if (srcFBO) {
2730 this->unbindTextureFromFBO(GR_GL_READ_FRAMEBUFFER);
2731 }
2733 copied = true; 2732 copied = true;
2734 } 2733 }
2735 } 2734 }
2736 return copied; 2735 return copied;
2737 } 2736 }
2738 2737
2739 bool GrGLGpu::canCopySurface(const GrSurface* dst, 2738 bool GrGLGpu::canCopySurface(const GrSurface* dst,
2740 const GrSurface* src, 2739 const GrSurface* src,
2741 const SkIRect& srcRect, 2740 const SkIRect& srcRect,
2742 const SkIPoint& dstPoint) { 2741 const SkIPoint& dstPoint) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 this->setVertexArrayID(gpu, 0); 2797 this->setVertexArrayID(gpu, 0);
2799 } 2798 }
2800 int attrCount = gpu->glCaps().maxVertexAttributes(); 2799 int attrCount = gpu->glCaps().maxVertexAttributes();
2801 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2800 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2802 fDefaultVertexArrayAttribState.resize(attrCount); 2801 fDefaultVertexArrayAttribState.resize(attrCount);
2803 } 2802 }
2804 attribState = &fDefaultVertexArrayAttribState; 2803 attribState = &fDefaultVertexArrayAttribState;
2805 } 2804 }
2806 return attribState; 2805 return attribState;
2807 } 2806 }
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