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

Side by Side Diff: Source/platform/graphics/gpu/DrawingBuffer.cpp

Issue 1120953002: WebGL 2: add read/write framebuffer binding points to related APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed zmo@'s feedback: WebGLFramebuffer::isBound need to be updated Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved. 2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context, 128 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context,
129 PassOwnPtr<Extensions3DUtil> extensionsUtil, 129 PassOwnPtr<Extensions3DUtil> extensionsUtil,
130 bool multisampleExtensionSupported, 130 bool multisampleExtensionSupported,
131 bool packedDepthStencilExtensionSupported, 131 bool packedDepthStencilExtensionSupported,
132 bool discardFramebufferSupported, 132 bool discardFramebufferSupported,
133 PreserveDrawingBuffer preserve, 133 PreserveDrawingBuffer preserve,
134 WebGraphicsContext3D::Attributes requestedAttributes) 134 WebGraphicsContext3D::Attributes requestedAttributes)
135 : m_preserveDrawingBuffer(preserve) 135 : m_preserveDrawingBuffer(preserve)
136 , m_scissorEnabled(false) 136 , m_scissorEnabled(false)
137 , m_texture2DBinding(0) 137 , m_texture2DBinding(0)
138 , m_framebufferBinding(0) 138 , m_drawFramebufferBinding(0)
139 , m_readFramebufferBinding(0)
139 , m_activeTextureUnit(GL_TEXTURE0) 140 , m_activeTextureUnit(GL_TEXTURE0)
140 , m_context(context) 141 , m_context(context)
141 , m_extensionsUtil(extensionsUtil) 142 , m_extensionsUtil(extensionsUtil)
142 , m_size(-1, -1) 143 , m_size(-1, -1)
143 , m_requestedAttributes(requestedAttributes) 144 , m_requestedAttributes(requestedAttributes)
144 , m_multisampleExtensionSupported(multisampleExtensionSupported) 145 , m_multisampleExtensionSupported(multisampleExtensionSupported)
145 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) 146 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d)
146 , m_discardFramebufferSupported(discardFramebufferSupported) 147 , m_discardFramebufferSupported(discardFramebufferSupported)
147 , m_fbo(0) 148 , m_fbo(0)
148 , m_depthStencilBuffer(0) 149 , m_depthStencilBuffer(0)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 295
295 if (m_discardFramebufferSupported) { 296 if (m_discardFramebufferSupported) {
296 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch. 297 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch.
297 const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT TACHMENT, GL_STENCIL_ATTACHMENT}; 298 const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT TACHMENT, GL_STENCIL_ATTACHMENT};
298 m_context->discardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); 299 m_context->discardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments);
299 } 300 }
300 } else { 301 } else {
301 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId, f rontColorBufferMailbox->textureInfo.textureId, GL_RGBA, GL_UNSIGNED_BYTE); 302 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId, f rontColorBufferMailbox->textureInfo.textureId, GL_RGBA, GL_UNSIGNED_BYTE);
302 } 303 }
303 304
304 restoreFramebufferBinding(); 305 restoreFramebufferBindings();
305 m_contentsChanged = false; 306 m_contentsChanged = false;
306 307
307 m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo .textureId, GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name); 308 m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo .textureId, GL_TEXTURE_2D, frontColorBufferMailbox->mailbox.name);
308 m_context->flush(); 309 m_context->flush();
309 frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); 310 frontColorBufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint();
310 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex tureInfo.imageId != 0; 311 frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex tureInfo.imageId != 0;
311 setBufferClearNeeded(true); 312 setBufferClearNeeded(true);
312 313
313 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h as live mailboxes 314 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h as live mailboxes
314 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); 315 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 m_actualAttributes.antialias = multisample(); 471 m_actualAttributes.antialias = multisample();
471 return true; 472 return true;
472 } 473 }
473 474
474 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor m3DObject texture, GLenum internalFormat, 475 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor m3DObject texture, GLenum internalFormat,
475 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceDrawi ngBuffer sourceBuffer) 476 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceDrawi ngBuffer sourceBuffer)
476 { 477 {
477 if (m_contentsChanged) { 478 if (m_contentsChanged) {
478 if (m_multisampleMode != None) { 479 if (m_multisampleMode != None) {
479 commit(); 480 commit();
480 restoreFramebufferBinding(); 481 restoreFramebufferBindings();
481 } 482 }
482 m_context->flush(); 483 m_context->flush();
483 } 484 }
484 485
485 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm at, destType, level)) 486 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm at, destType, level))
486 return false; 487 return false;
487 488
488 // Contexts may be in a different share group. We must transfer the texture through a mailbox first 489 // Contexts may be in a different share group. We must transfer the texture through a mailbox first
489 WebExternalTextureMailbox mailbox; 490 WebExternalTextureMailbox mailbox;
490 GLint textureId = 0; 491 GLint textureId = 0;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 m_context->blitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, hei ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); 811 m_context->blitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, hei ght, GL_COLOR_BUFFER_BIT, GL_NEAREST);
811 812
812 if (m_scissorEnabled) 813 if (m_scissorEnabled)
813 m_context->enable(GL_SCISSOR_TEST); 814 m_context->enable(GL_SCISSOR_TEST);
814 } 815 }
815 816
816 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 817 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
817 m_contentsChangeCommitted = true; 818 m_contentsChangeCommitted = true;
818 } 819 }
819 820
820 void DrawingBuffer::restoreFramebufferBinding() 821 void DrawingBuffer::restoreFramebufferBindings()
821 { 822 {
822 if (!m_framebufferBinding) { 823 if (m_drawFramebufferBinding && m_readFramebufferBinding) {
823 bind(); 824 if (m_drawFramebufferBinding == m_readFramebufferBinding) {
825 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_readFramebufferBinding) ;
826 } else {
827 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBin ding);
828 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFramebufferBin ding);
829 }
824 return; 830 return;
825 } 831 }
826 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); 832 if (!m_drawFramebufferBinding && !m_readFramebufferBinding) {
833 bind(GL_FRAMEBUFFER);
834 return;
835 }
836 if (!m_drawFramebufferBinding) {
837 bind(GL_DRAW_FRAMEBUFFER);
838 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBinding );
839 } else {
840 bind(GL_READ_FRAMEBUFFER);
841 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFramebufferBinding );
842 }
827 } 843 }
828 844
829 bool DrawingBuffer::multisample() const 845 bool DrawingBuffer::multisample() const
830 { 846 {
831 return m_multisampleMode != None; 847 return m_multisampleMode != None;
832 } 848 }
833 849
834 void DrawingBuffer::bind(GLenum target) 850 void DrawingBuffer::bind(GLenum target)
835 { 851 {
836 m_context->bindFramebuffer(target, m_multisampleFBO ? m_multisampleFBO : m_f bo); 852 if (target != GL_READ_FRAMEBUFFER)
853 m_context->bindFramebuffer(target, m_multisampleFBO ? m_multisampleFBO : m_fbo);
854 else
855 m_context->bindFramebuffer(target, m_fbo);
837 } 856 }
838 857
839 void DrawingBuffer::setPackAlignment(GLint param) 858 void DrawingBuffer::setPackAlignment(GLint param)
840 { 859 {
841 m_packAlignment = param; 860 m_packAlignment = param;
842 } 861 }
843 862
844 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) 863 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer)
845 { 864 {
846 paintFramebufferToCanvas(framebuffer(), size().width(), size().height(), !m_ actualAttributes.premultipliedAlpha, imageBuffer); 865 paintFramebufferToCanvas(framebuffer(), size().width(), size().height(), !m_ actualAttributes.premultipliedAlpha, imageBuffer);
(...skipping 23 matching lines...) Expand all
870 } 889 }
871 890
872 readBackFramebuffer(static_cast<unsigned char*>(pixels.data()), width, heigh t, ReadbackRGBA, WebGLImageConversion::AlphaDoNothing); 891 readBackFramebuffer(static_cast<unsigned char*>(pixels.data()), width, heigh t, ReadbackRGBA, WebGLImageConversion::AlphaDoNothing);
873 flipVertically(static_cast<uint8_t*>(pixels.data()), width, height); 892 flipVertically(static_cast<uint8_t*>(pixels.data()), width, height);
874 893
875 if (fbo) { 894 if (fbo) {
876 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL _TEXTURE_2D, 0, 0); 895 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL _TEXTURE_2D, 0, 0);
877 m_context->deleteFramebuffer(fbo); 896 m_context->deleteFramebuffer(fbo);
878 } 897 }
879 898
880 restoreFramebufferBinding(); 899 restoreFramebufferBindings();
881 900
882 pixels.transfer(contents); 901 pixels.transfer(contents);
883 return true; 902 return true;
884 } 903 }
885 904
886 void DrawingBuffer::paintFramebufferToCanvas(int framebuffer, int width, int hei ght, bool premultiplyAlpha, ImageBuffer* imageBuffer) 905 void DrawingBuffer::paintFramebufferToCanvas(int framebuffer, int width, int hei ght, bool premultiplyAlpha, ImageBuffer* imageBuffer)
887 { 906 {
888 unsigned char* pixels = 0; 907 unsigned char* pixels = 0;
889 908
890 const SkBitmap& canvasBitmap = imageBuffer->bitmap(); 909 const SkBitmap& canvasBitmap = imageBuffer->bitmap();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) 1013 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info)
995 { 1014 {
996 if (info->imageId) { 1015 if (info->imageId) {
997 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); 1016 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId);
998 m_context->destroyImageCHROMIUM(info->imageId); 1017 m_context->destroyImageCHROMIUM(info->imageId);
999 info->imageId = 0; 1018 info->imageId = 0;
1000 } 1019 }
1001 } 1020 }
1002 1021
1003 } // namespace blink 1022 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698