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

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

Issue 1856933002: WebGL GL_RGB emulation to support IOSurfaces on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from kbr. Created 4 years, 7 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 | « third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | 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 (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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/graphics/gpu/DrawingBuffer.h" 31 #include "platform/graphics/gpu/DrawingBuffer.h"
32 32
33 #include "gpu/command_buffer/client/gles2_interface.h" 33 #include "gpu/command_buffer/client/gles2_interface.h"
34 #include "gpu/command_buffer/common/capabilities.h"
34 #include "platform/RuntimeEnabledFeatures.h" 35 #include "platform/RuntimeEnabledFeatures.h"
35 #include "platform/TraceEvent.h" 36 #include "platform/TraceEvent.h"
36 #include "platform/graphics/GraphicsLayer.h" 37 #include "platform/graphics/GraphicsLayer.h"
37 #include "platform/graphics/ImageBuffer.h" 38 #include "platform/graphics/ImageBuffer.h"
38 #include "platform/graphics/gpu/Extensions3DUtil.h" 39 #include "platform/graphics/gpu/Extensions3DUtil.h"
39 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
40 #include "public/platform/WebCompositorSupport.h" 41 #include "public/platform/WebCompositorSupport.h"
41 #include "public/platform/WebExternalBitmap.h" 42 #include "public/platform/WebExternalBitmap.h"
42 #include "public/platform/WebExternalTextureLayer.h" 43 #include "public/platform/WebExternalTextureLayer.h"
43 #include "public/platform/WebGraphicsContext3DProvider.h" 44 #include "public/platform/WebGraphicsContext3DProvider.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 PassOwnPtr<Extensions3DUtil> extensionsUtil, 128 PassOwnPtr<Extensions3DUtil> extensionsUtil,
128 bool discardFramebufferSupported, 129 bool discardFramebufferSupported,
129 bool wantAlphaChannel, 130 bool wantAlphaChannel,
130 bool premultipliedAlpha, 131 bool premultipliedAlpha,
131 PreserveDrawingBuffer preserve) 132 PreserveDrawingBuffer preserve)
132 : m_preserveDrawingBuffer(preserve) 133 : m_preserveDrawingBuffer(preserve)
133 , m_scissorEnabled(false) 134 , m_scissorEnabled(false)
134 , m_texture2DBinding(0) 135 , m_texture2DBinding(0)
135 , m_drawFramebufferBinding(0) 136 , m_drawFramebufferBinding(0)
136 , m_readFramebufferBinding(0) 137 , m_readFramebufferBinding(0)
138 , m_renderbufferBinding(0)
137 , m_activeTextureUnit(GL_TEXTURE0) 139 , m_activeTextureUnit(GL_TEXTURE0)
138 , m_contextProvider(std::move(contextProvider)) 140 , m_contextProvider(std::move(contextProvider))
139 , m_gl(m_contextProvider->contextGL()) 141 , m_gl(m_contextProvider->contextGL())
140 , m_extensionsUtil(std::move(extensionsUtil)) 142 , m_extensionsUtil(std::move(extensionsUtil))
141 , m_size(-1, -1) 143 , m_size(-1, -1)
142 , m_discardFramebufferSupported(discardFramebufferSupported) 144 , m_discardFramebufferSupported(discardFramebufferSupported)
143 , m_wantAlphaChannel(wantAlphaChannel) 145 , m_wantAlphaChannel(wantAlphaChannel)
144 , m_premultipliedAlpha(premultipliedAlpha) 146 , m_premultipliedAlpha(premultipliedAlpha)
145 , m_hasImplicitStencilBuffer(false) 147 , m_hasImplicitStencilBuffer(false)
146 , m_fbo(0) 148 , m_fbo(0)
147 , m_depthStencilBuffer(0) 149 , m_depthStencilBuffer(0)
148 , m_multisampleFBO(0) 150 , m_multisampleFBO(0)
151 , m_intermediateFBO(0)
152 , m_intermediateRenderbuffer(0)
149 , m_multisampleColorBuffer(0) 153 , m_multisampleColorBuffer(0)
150 , m_contentsChanged(true) 154 , m_contentsChanged(true)
151 , m_contentsChangeCommitted(false) 155 , m_contentsChangeCommitted(false)
152 , m_bufferClearNeeded(false) 156 , m_bufferClearNeeded(false)
153 , m_antiAliasingMode(None) 157 , m_antiAliasingMode(None)
154 , m_maxTextureSize(0) 158 , m_maxTextureSize(0)
155 , m_sampleCount(0) 159 , m_sampleCount(0)
156 , m_packAlignment(4) 160 , m_packAlignment(4)
157 , m_destructionInProgress(false) 161 , m_destructionInProgress(false)
158 , m_isHidden(false) 162 , m_isHidden(false)
159 , m_filterQuality(kLow_SkFilterQuality) 163 , m_filterQuality(kLow_SkFilterQuality)
160 { 164 {
165 memset(m_colorMask, 0, 4 * sizeof(GLboolean));
166 memset(m_clearColor, 0, 4 * sizeof(GLfloat));
161 // Used by browser tests to detect the use of a DrawingBuffer. 167 // Used by browser tests to detect the use of a DrawingBuffer.
162 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", TRACE_EVENT_SCOPE_ GLOBAL); 168 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", TRACE_EVENT_SCOPE_ GLOBAL);
163 } 169 }
164 170
165 DrawingBuffer::~DrawingBuffer() 171 DrawingBuffer::~DrawingBuffer()
166 { 172 {
167 ASSERT(m_destructionInProgress); 173 ASSERT(m_destructionInProgress);
168 ASSERT(m_textureMailboxes.isEmpty()); 174 ASSERT(m_textureMailboxes.isEmpty());
169 m_layer.clear(); 175 m_layer.clear();
170 m_contextProvider.clear(); 176 m_contextProvider.clear();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 217
212 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality) 218 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality)
213 { 219 {
214 if (m_filterQuality != filterQuality) { 220 if (m_filterQuality != filterQuality) {
215 m_filterQuality = filterQuality; 221 m_filterQuality = filterQuality;
216 if (m_layer) 222 if (m_layer)
217 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); 223 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality);
218 } 224 }
219 } 225 }
220 226
227 bool DrawingBuffer::requiresRGBEmulation()
228 {
229 // When an explicit resolve is required, clients draw into a render buffer
230 // which is never backed by an IOSurface.
231 if (m_antiAliasingMode == MSAAExplicitResolve)
232 return false;
233 return !m_drawFramebufferBinding && !m_wantAlphaChannel && m_colorBuffer.ima geId && contextProvider()->getCapabilities().chromium_image_rgb_emulation;
234 }
235
221 void DrawingBuffer::freeRecycledMailboxes() 236 void DrawingBuffer::freeRecycledMailboxes()
222 { 237 {
223 if (m_recycledMailboxQueue.isEmpty()) 238 if (m_recycledMailboxQueue.isEmpty())
224 return; 239 return;
225 while (!m_recycledMailboxQueue.isEmpty()) 240 while (!m_recycledMailboxQueue.isEmpty())
226 deleteMailbox(m_recycledMailboxQueue.takeLast()); 241 deleteMailbox(m_recycledMailboxQueue.takeLast());
227 } 242 }
228 243
229 bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt ernalBitmap* bitmap) 244 bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt ernalBitmap* bitmap)
230 { 245 {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 ASSERT_NOT_REACHED(); 344 ASSERT_NOT_REACHED();
330 } 345 }
331 346
332 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters() 347 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters()
333 { 348 {
334 #if OS(MACOSX) 349 #if OS(MACOSX)
335 // A CHROMIUM_image backed texture requires a specialized set of parameters 350 // A CHROMIUM_image backed texture requires a specialized set of parameters
336 // on OSX. 351 // on OSX.
337 TextureParameters parameters; 352 TextureParameters parameters;
338 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; 353 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB;
339 parameters.internalColorFormat = GL_RGBA; 354
340 parameters.internalRenderbufferFormat = GL_RGBA8_OES; 355 if (m_wantAlphaChannel) {
341 parameters.colorFormat = GL_RGBA; 356 parameters.creationInternalColorFormat = GL_RGBA;
357 parameters.internalColorFormat = GL_RGBA;
358 parameters.internalRenderbufferFormat = GL_RGBA8_OES;
359 } else if (contextProvider()->getCapabilities().chromium_image_rgb_emulation ) {
360 parameters.creationInternalColorFormat = GL_RGB;
361 parameters.internalColorFormat = GL_RGBA;
362 parameters.internalRenderbufferFormat = GL_RGB8_OES;
363 } else {
364 parameters.creationInternalColorFormat = GL_RGB;
365 parameters.internalColorFormat = GL_RGB;
366 parameters.internalRenderbufferFormat = GL_RGB8_OES;
367 }
368
369 // Unused when CHROMIUM_image is being used.
370 parameters.colorFormat = 0;
342 return parameters; 371 return parameters;
343 #else 372 #else
344 return defaultTextureParameters(); 373 return defaultTextureParameters();
345 #endif 374 #endif
346 } 375 }
347 376
348 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() 377 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters()
349 { 378 {
350 TextureParameters parameters; 379 TextureParameters parameters;
351 parameters.target = GL_TEXTURE_2D; 380 parameters.target = GL_TEXTURE_2D;
352 if (m_wantAlphaChannel) { 381 if (m_wantAlphaChannel) {
353 parameters.internalColorFormat = GL_RGBA; 382 parameters.internalColorFormat = GL_RGBA;
383 parameters.creationInternalColorFormat = GL_RGBA;
354 parameters.colorFormat = GL_RGBA; 384 parameters.colorFormat = GL_RGBA;
355 parameters.internalRenderbufferFormat = GL_RGBA8_OES; 385 parameters.internalRenderbufferFormat = GL_RGBA8_OES;
356 } else { 386 } else {
357 parameters.internalColorFormat = GL_RGB; 387 parameters.internalColorFormat = GL_RGB;
388 parameters.creationInternalColorFormat = GL_RGB;
358 parameters.colorFormat = GL_RGB; 389 parameters.colorFormat = GL_RGB;
359 parameters.internalRenderbufferFormat = GL_RGB8_OES; 390 parameters.internalRenderbufferFormat = GL_RGB8_OES;
360 } 391 }
361 return parameters; 392 return parameters;
362 } 393 }
363 394
364 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail box& mailbox) 395 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail box& mailbox)
365 { 396 {
366 ASSERT(m_textureMailboxes.size()); 397 ASSERT(m_textureMailboxes.size());
367 // Ensure not to call the destructor until deleteMailbox() is completed. 398 // Ensure not to call the destructor until deleteMailbox() is completed.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 603
573 if (m_multisampleFBO) 604 if (m_multisampleFBO)
574 m_gl->DeleteFramebuffers(1, &m_multisampleFBO); 605 m_gl->DeleteFramebuffers(1, &m_multisampleFBO);
575 606
576 if (m_fbo) 607 if (m_fbo)
577 m_gl->DeleteFramebuffers(1, &m_fbo); 608 m_gl->DeleteFramebuffers(1, &m_fbo);
578 609
579 if (m_multisampleColorBuffer) 610 if (m_multisampleColorBuffer)
580 m_gl->DeleteRenderbuffers(1, &m_multisampleColorBuffer); 611 m_gl->DeleteRenderbuffers(1, &m_multisampleColorBuffer);
581 612
613 if (m_intermediateFBO)
614 m_gl->DeleteFramebuffers(1, &m_intermediateFBO);
615
616 if (m_intermediateRenderbuffer)
617 m_gl->DeleteRenderbuffers(1, &m_intermediateRenderbuffer);
618
582 if (m_depthStencilBuffer) 619 if (m_depthStencilBuffer)
583 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer); 620 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer);
584 621
585 if (m_colorBuffer.textureId) { 622 if (m_colorBuffer.textureId) {
586 deleteChromiumImageForTexture(&m_colorBuffer); 623 deleteChromiumImageForTexture(&m_colorBuffer);
587 m_gl->DeleteTextures(1, &m_colorBuffer.textureId); 624 m_gl->DeleteTextures(1, &m_colorBuffer.textureId);
588 } 625 }
589 626
590 setSize(IntSize()); 627 setSize(IntSize());
591 628
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo unt, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.hei ght()); 679 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo unt, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.hei ght());
643 680
644 if (m_gl->GetError() == GL_OUT_OF_MEMORY) 681 if (m_gl->GetError() == GL_OUT_OF_MEMORY)
645 return false; 682 return false;
646 683
647 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R ENDERBUFFER, m_multisampleColorBuffer); 684 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R ENDERBUFFER, m_multisampleColorBuffer);
648 if (wantDepthOrStencilBuffer) 685 if (wantDepthOrStencilBuffer)
649 resizeDepthStencil(size); 686 resizeDepthStencil(size);
650 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL ETE) 687 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL ETE)
651 return false; 688 return false;
689
690 if (m_intermediateFBO) {
691 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_intermediateFBO);
692 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_intermediateRenderbuffer);
693 m_gl->RenderbufferStorage(GL_RENDERBUFFER, m_colorBuffer.parameters. internalRenderbufferFormat, size.width(), size.height());
694
695 if (m_gl->GetError() == GL_OUT_OF_MEMORY)
696 return false;
697
698 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_intermediateRenderbuffer);
699 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_C OMPLETE)
700 return false;
701
702 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
703 }
652 } 704 }
653 705
654 return true; 706 return true;
655 } 707 }
656 708
657 void DrawingBuffer::resizeDepthStencil(const IntSize& size) 709 void DrawingBuffer::resizeDepthStencil(const IntSize& size)
658 { 710 {
659 if (!m_depthStencilBuffer) 711 if (!m_depthStencilBuffer)
660 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer); 712 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer);
661 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); 713 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } while (!adjustedSize.isEmpty()); 787 } while (!adjustedSize.isEmpty());
736 788
737 setSize(adjustedSize); 789 setSize(adjustedSize);
738 790
739 if (adjustedSize.isEmpty()) 791 if (adjustedSize.isEmpty())
740 return false; 792 return false;
741 } 793 }
742 794
743 m_gl->Disable(GL_SCISSOR_TEST); 795 m_gl->Disable(GL_SCISSOR_TEST);
744 m_gl->ClearColor(0, 0, 0, 0); 796 m_gl->ClearColor(0, 0, 0, 0);
745 m_gl->ColorMask(true, true, true, true); 797 m_gl->ColorMask(true, true, true, !requiresRGBEmulation());
746 798
747 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 799 GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
748 if (!!m_depthStencilBuffer) { 800 if (!!m_depthStencilBuffer) {
749 m_gl->ClearDepthf(1.0f); 801 m_gl->ClearDepthf(1.0f);
750 clearMask |= GL_DEPTH_BUFFER_BIT; 802 clearMask |= GL_DEPTH_BUFFER_BIT;
751 m_gl->DepthMask(true); 803 m_gl->DepthMask(true);
752 } 804 }
753 if (!!m_depthStencilBuffer) { 805 if (!!m_depthStencilBuffer) {
754 m_gl->ClearStencil(0); 806 m_gl->ClearStencil(0);
755 clearMask |= GL_STENCIL_BUFFER_BIT; 807 clearMask |= GL_STENCIL_BUFFER_BIT;
756 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); 808 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
757 } 809 }
758 810
759 clearFramebuffers(clearMask); 811 clearFramebuffers(clearMask);
760 return true; 812 return true;
761 } 813 }
762 814
763 void DrawingBuffer::commit() 815 void DrawingBuffer::commit()
764 { 816 {
765 if (m_multisampleFBO && !m_contentsChangeCommitted) { 817 if (m_multisampleFBO && !m_contentsChangeCommitted) {
766 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); 818 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO);
767 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); 819 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
768 820
769 if (m_scissorEnabled) 821 if (m_scissorEnabled)
770 m_gl->Disable(GL_SCISSOR_TEST); 822 m_gl->Disable(GL_SCISSOR_TEST);
771 823
772 int width = m_size.width(); 824 int width = m_size.width();
773 int height = m_size.height(); 825 int height = m_size.height();
774 // Use NEAREST, because there is no scale performed during the blit. 826 // Use NEAREST, because there is no scale performed during the blit.
775 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); 827 GLuint filter = GL_NEAREST;
828
829 // If the destination has a different color format than the source, then
830 // first resolve to an intermediary renderbuffer with the same color
831 // format.
832 // If this extra blit proves to be a performance problem, it can be
833 // bypassed on most GPUs by performing client side GL_RGBA emulation on
834 // the source renderbuffer.
835 // https://bugs.chromium.org/p/chromium/issues/detail?id=595948#c30
836 if (m_colorBuffer.parameters.internalColorFormat == GL_RGBA && m_colorBu ffer.parameters.internalRenderbufferFormat == GL_RGB8_OES) {
837 if (!m_intermediateFBO) {
838 DCHECK(!m_intermediateRenderbuffer);
839 m_gl->GenRenderbuffers(1, &m_intermediateRenderbuffer);
840 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_intermediateRenderbuff er);
841 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_RGB8, width, heigh t);
842
843 m_gl->GenFramebuffers(1, &m_intermediateFBO);
844 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_intermediateF BO);
845 m_gl->FramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_ANGLE, GL_COLO R_ATTACHMENT0, GL_RENDERBUFFER, m_intermediateRenderbuffer);
846 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_renderbufferBinding);
847 }
848
849 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_intermediateFBO);
850 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, heig ht, GL_COLOR_BUFFER_BIT, filter);
851
852 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_intermediateFBO);
853 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
854 }
855
856 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, filter);
776 857
777 if (m_scissorEnabled) 858 if (m_scissorEnabled)
778 m_gl->Enable(GL_SCISSOR_TEST); 859 m_gl->Enable(GL_SCISSOR_TEST);
779 } 860 }
780 861
781 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 862 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
782 if (m_antiAliasingMode == ScreenSpaceAntialiasing) { 863 if (m_antiAliasingMode == ScreenSpaceAntialiasing) {
783 m_gl->ApplyScreenSpaceAntialiasingCHROMIUM(); 864 m_gl->ApplyScreenSpaceAntialiasingCHROMIUM();
784 } 865 }
785 m_contentsChangeCommitted = true; 866 m_contentsChangeCommitted = true;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) 1000 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info)
920 { 1001 {
921 if (info->imageId) { 1002 if (info->imageId) {
922 m_gl->BindTexture(info->parameters.target, info->textureId); 1003 m_gl->BindTexture(info->parameters.target, info->textureId);
923 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); 1004 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId);
924 m_gl->DestroyImageCHROMIUM(info->imageId); 1005 m_gl->DestroyImageCHROMIUM(info->imageId);
925 info->imageId = 0; 1006 info->imageId = 0;
926 } 1007 }
927 } 1008 }
928 1009
1010 void DrawingBuffer::clearChromiumImageAlpha(const TextureInfo& info)
1011 {
1012 if (m_wantAlphaChannel)
1013 return;
1014 if (!contextProvider()->getCapabilities().chromium_image_rgb_emulation)
1015 return;
1016
1017 GLuint fbo = 0;
1018 m_gl->GenFramebuffers(1, &fbo);
1019 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo);
1020 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame ters.target, info.textureId, 0);
1021 m_gl->ClearColor(0, 0, 0, 1);
1022 m_gl->ColorMask(false, false, false, true);
1023 m_gl->Clear(GL_COLOR_BUFFER_BIT);
1024 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame ters.target, 0, 0);
1025 m_gl->DeleteFramebuffers(1, &fbo);
1026 restoreFramebufferBindings();
1027 m_gl->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], m_clearC olor[3]);
1028 m_gl->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], m_colorMask[ 3]);
1029 }
1030
929 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I ntSize& size) 1031 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I ntSize& size)
930 { 1032 {
931 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose
932 // behavior mimics a texture with internal format GL_RGB.
933 // https://crbug.com/581777.
934 if (!m_wantAlphaChannel)
935 return createDefaultTextureAndAllocateMemory(size);
936
937 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) 1033 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled())
938 return createDefaultTextureAndAllocateMemory(size); 1034 return createDefaultTextureAndAllocateMemory(size);
939 1035
940 // First, try to allocate a CHROMIUM_image. This always has the potential to 1036 // First, try to allocate a CHROMIUM_image. This always has the potential to
941 // fail. 1037 // fail.
942 TextureParameters parameters = chromiumImageTextureParameters(); 1038 TextureParameters parameters = chromiumImageTextureParameters();
943 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size .height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); 1039 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size .height(), parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM);
944 if (!imageId) 1040 if (!imageId)
945 return createDefaultTextureAndAllocateMemory(size); 1041 return createDefaultTextureAndAllocateMemory(size);
946 1042
947 GLuint textureId = createColorTexture(parameters); 1043 GLuint textureId = createColorTexture(parameters);
948 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); 1044 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId);
949 1045
950 TextureInfo info; 1046 TextureInfo info;
951 info.textureId = textureId; 1047 info.textureId = textureId;
952 info.imageId = imageId; 1048 info.imageId = imageId;
953 info.parameters = parameters; 1049 info.parameters = parameters;
1050 clearChromiumImageAlpha(info);
954 return info; 1051 return info;
955 } 1052 }
956 1053
957 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size) 1054 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size)
958 { 1055 {
959 TextureParameters parameters = defaultTextureParameters(); 1056 TextureParameters parameters = defaultTextureParameters();
960 GLuint textureId = createColorTexture(parameters); 1057 GLuint textureId = createColorTexture(parameters);
961 texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); 1058 texImage2DResourceSafe(parameters.target, 0, parameters.creationInternalColo rFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYT E);
962 1059
963 DrawingBuffer::TextureInfo info; 1060 DrawingBuffer::TextureInfo info;
964 info.textureId = textureId; 1061 info.textureId = textureId;
965 info.parameters = parameters; 1062 info.parameters = parameters;
966 return info; 1063 return info;
967 } 1064 }
968 1065
969 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) 1066 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size)
970 { 1067 {
971 ASSERT(info->textureId); 1068 ASSERT(info->textureId);
972 if (info->imageId) { 1069 if (info->imageId) {
973 deleteChromiumImageForTexture(info); 1070 deleteChromiumImageForTexture(info);
974 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); 1071 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s ize.height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIU M);
975 if (info->imageId) { 1072 if (info->imageId) {
976 m_gl->BindTexture(info->parameters.target, info->textureId); 1073 m_gl->BindTexture(info->parameters.target, info->textureId);
977 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId) ; 1074 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId) ;
1075 clearChromiumImageAlpha(*info);
978 return; 1076 return;
979 } 1077 }
980 1078
981 // If the desired texture target is different, there's no way to fall ba ck 1079 // If the desired texture target is different, there's no way to fall ba ck
982 // to a non CHROMIUM_image texture. 1080 // to a non CHROMIUM_image texture.
983 if (chromiumImageTextureParameters().target != defaultTextureParameters( ).target) 1081 if (chromiumImageTextureParameters().target != defaultTextureParameters( ).target)
984 return; 1082 return;
985 } 1083 }
986 1084
987 m_gl->BindTexture(info->parameters.target, info->textureId); 1085 m_gl->BindTexture(info->parameters.target, info->textureId);
988 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN SIGNED_BYTE); 1086 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.creation InternalColorFormat, size.width(), size.height(), 0, info->parameters.colorForma t, GL_UNSIGNED_BYTE);
989 } 1087 }
990 1088
991 void DrawingBuffer::attachColorBufferToCurrentFBO() 1089 void DrawingBuffer::attachColorBufferToCurrentFBO()
992 { 1090 {
993 GLenum target = m_colorBuffer.parameters.target; 1091 GLenum target = m_colorBuffer.parameters.target;
994 1092
995 m_gl->BindTexture(target, m_colorBuffer.textureId); 1093 m_gl->BindTexture(target, m_colorBuffer.textureId);
996 1094
997 if (m_antiAliasingMode == MSAAImplicitResolve) 1095 if (m_antiAliasingMode == MSAAImplicitResolve)
998 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); 1096 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount);
999 else 1097 else
1000 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_colorBuffer.textureId, 0); 1098 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_colorBuffer.textureId, 0);
1001 1099
1002 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); 1100 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding);
1003 } 1101 }
1004 1102
1005 } // namespace blink 1103 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698