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

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

Issue 1953623002: Clean up multisampled color mask workaround for DrawingBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp40_drawingbuffer_cleanup
Patch Set: Comments from kbr and fix up a conditional. 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 { 199 {
200 if (m_filterQuality != filterQuality) { 200 if (m_filterQuality != filterQuality) {
201 m_filterQuality = filterQuality; 201 m_filterQuality = filterQuality;
202 if (m_layer) 202 if (m_layer)
203 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); 203 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality);
204 } 204 }
205 } 205 }
206 206
207 bool DrawingBuffer::requiresAlphaChannelToBePreserved() 207 bool DrawingBuffer::requiresAlphaChannelToBePreserved()
208 { 208 {
209 // When an explicit resolve is required, clients draw into a render buffer 209 return !m_drawFramebufferBinding && defaultBufferRequiresAlphaChannelToBePre served();
210 // which is never backed by an IOSurface. 210 }
211 if (m_antiAliasingMode == MSAAExplicitResolve) 211
212 return false; 212 bool DrawingBuffer::defaultBufferRequiresAlphaChannelToBePreserved()
213 return !m_drawFramebufferBinding && !m_wantAlphaChannel && m_colorBuffer.ima geId && contextProvider()->getCapabilities().chromium_image_rgb_emulation; 213 {
214 if (wantExplicitResolve()) {
215 return !m_wantAlphaChannel && getMultisampledRenderbufferFormat() == GL_ RGBA8_OES;
216 }
217
218 return !m_wantAlphaChannel && m_colorBuffer.imageId && contextProvider()->ge tCapabilities().chromium_image_rgb_emulation;
214 } 219 }
215 220
216 void DrawingBuffer::freeRecycledMailboxes() 221 void DrawingBuffer::freeRecycledMailboxes()
217 { 222 {
218 if (m_recycledMailboxQueue.isEmpty()) 223 if (m_recycledMailboxQueue.isEmpty())
219 return; 224 return;
220 while (!m_recycledMailboxQueue.isEmpty()) 225 while (!m_recycledMailboxQueue.isEmpty())
221 deleteMailbox(m_recycledMailboxQueue.takeLast()); 226 deleteMailbox(m_recycledMailboxQueue.takeLast());
222 } 227 }
223 228
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 { 328 {
324 #if OS(MACOSX) 329 #if OS(MACOSX)
325 // A CHROMIUM_image backed texture requires a specialized set of parameters 330 // A CHROMIUM_image backed texture requires a specialized set of parameters
326 // on OSX. 331 // on OSX.
327 TextureParameters parameters; 332 TextureParameters parameters;
328 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; 333 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB;
329 334
330 if (m_wantAlphaChannel) { 335 if (m_wantAlphaChannel) {
331 parameters.creationInternalColorFormat = GL_RGBA; 336 parameters.creationInternalColorFormat = GL_RGBA;
332 parameters.internalColorFormat = GL_RGBA; 337 parameters.internalColorFormat = GL_RGBA;
333 parameters.internalRenderbufferFormat = GL_RGBA8_OES;
334 } else if (contextProvider()->getCapabilities().chromium_image_rgb_emulation ) { 338 } else if (contextProvider()->getCapabilities().chromium_image_rgb_emulation ) {
335 parameters.creationInternalColorFormat = GL_RGB; 339 parameters.creationInternalColorFormat = GL_RGB;
336 parameters.internalColorFormat = GL_RGBA; 340 parameters.internalColorFormat = GL_RGBA;
337 parameters.internalRenderbufferFormat = GL_RGB8_OES;
338 } else { 341 } else {
339 parameters.creationInternalColorFormat = GL_RGB; 342 parameters.creationInternalColorFormat = GL_RGB;
340 parameters.internalColorFormat = GL_RGB; 343 parameters.internalColorFormat = GL_RGB;
341 parameters.internalRenderbufferFormat = GL_RGB8_OES;
342 } 344 }
343 345
344 // Unused when CHROMIUM_image is being used. 346 // Unused when CHROMIUM_image is being used.
345 parameters.colorFormat = 0; 347 parameters.colorFormat = 0;
346 return parameters; 348 return parameters;
347 #else 349 #else
348 return defaultTextureParameters(); 350 return defaultTextureParameters();
349 #endif 351 #endif
350 } 352 }
351 353
352 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() 354 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters()
353 { 355 {
354 TextureParameters parameters; 356 TextureParameters parameters;
355 parameters.target = GL_TEXTURE_2D; 357 parameters.target = GL_TEXTURE_2D;
356 if (m_wantAlphaChannel) { 358 if (m_wantAlphaChannel) {
357 parameters.internalColorFormat = GL_RGBA; 359 parameters.internalColorFormat = GL_RGBA;
358 parameters.creationInternalColorFormat = GL_RGBA; 360 parameters.creationInternalColorFormat = GL_RGBA;
359 parameters.colorFormat = GL_RGBA; 361 parameters.colorFormat = GL_RGBA;
360 parameters.internalRenderbufferFormat = GL_RGBA8_OES;
361 } else { 362 } else {
362 parameters.internalColorFormat = GL_RGB; 363 parameters.internalColorFormat = GL_RGB;
363 parameters.creationInternalColorFormat = GL_RGB; 364 parameters.creationInternalColorFormat = GL_RGB;
364 parameters.colorFormat = GL_RGB; 365 parameters.colorFormat = GL_RGB;
365 parameters.internalRenderbufferFormat = GL_RGB8_OES;
366 } 366 }
367 return parameters; 367 return parameters;
368 } 368 }
369 369
370 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail box& mailbox) 370 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail box& mailbox)
371 { 371 {
372 ASSERT(m_textureMailboxes.size()); 372 ASSERT(m_textureMailboxes.size());
373 // Ensure not to call the destructor until deleteMailbox() is completed. 373 // Ensure not to call the destructor until deleteMailbox() is completed.
374 RefPtr<DrawingBuffer> self = this; 374 RefPtr<DrawingBuffer> self = this;
375 deleteMailbox(mailbox); 375 deleteMailbox(mailbox);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 581
582 if (m_multisampleFBO) 582 if (m_multisampleFBO)
583 m_gl->DeleteFramebuffers(1, &m_multisampleFBO); 583 m_gl->DeleteFramebuffers(1, &m_multisampleFBO);
584 584
585 if (m_fbo) 585 if (m_fbo)
586 m_gl->DeleteFramebuffers(1, &m_fbo); 586 m_gl->DeleteFramebuffers(1, &m_fbo);
587 587
588 if (m_multisampleRenderbuffer) 588 if (m_multisampleRenderbuffer)
589 m_gl->DeleteRenderbuffers(1, &m_multisampleRenderbuffer); 589 m_gl->DeleteRenderbuffers(1, &m_multisampleRenderbuffer);
590 590
591 if (m_intermediateFBO)
592 m_gl->DeleteFramebuffers(1, &m_intermediateFBO);
593
594 if (m_intermediateRenderbuffer)
595 m_gl->DeleteRenderbuffers(1, &m_intermediateRenderbuffer);
596
597 if (m_depthStencilBuffer) 591 if (m_depthStencilBuffer)
598 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer); 592 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer);
599 593
600 if (m_colorBuffer.textureId) { 594 if (m_colorBuffer.textureId) {
601 deleteChromiumImageForTexture(&m_colorBuffer); 595 deleteChromiumImageForTexture(&m_colorBuffer);
602 m_gl->DeleteTextures(1, &m_colorBuffer.textureId); 596 m_gl->DeleteTextures(1, &m_colorBuffer.textureId);
603 } 597 }
604 598
605 setSize(IntSize()); 599 setSize(IntSize());
606 600
(...skipping 18 matching lines...) Expand all
625 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 619 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
626 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 620 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
627 return offscreenColorTexture; 621 return offscreenColorTexture;
628 } 622 }
629 623
630 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) 624 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size)
631 { 625 {
632 DCHECK(wantExplicitResolve()); 626 DCHECK(wantExplicitResolve());
633 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); 627 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
634 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleRenderbuffer); 628 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleRenderbuffer);
635 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.height( )); 629 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, getMultisampledRenderbufferFormat(), size.width(), size.height());
636 630
637 if (m_gl->GetError() == GL_OUT_OF_MEMORY) 631 if (m_gl->GetError() == GL_OUT_OF_MEMORY)
638 return false; 632 return false;
639 633
640 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDE RBUFFER, m_multisampleRenderbuffer); 634 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDE RBUFFER, m_multisampleRenderbuffer);
641 635
642 if (m_intermediateFBO) {
643 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_intermediateFBO);
644 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_intermediateRenderbuffer);
645 m_gl->RenderbufferStorage(GL_RENDERBUFFER, m_colorBuffer.parameters.inte rnalRenderbufferFormat, size.width(), size.height());
646
647 if (m_gl->GetError() == GL_OUT_OF_MEMORY)
648 return false;
649
650 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R ENDERBUFFER, m_intermediateRenderbuffer);
651 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL ETE)
652 return false;
653
654 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
655 }
656 return true; 636 return true;
657 } 637 }
658 638
659 void DrawingBuffer::resizeDepthStencil(const IntSize& size) 639 void DrawingBuffer::resizeDepthStencil(const IntSize& size)
660 { 640 {
661 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo); 641 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo);
662 if (!m_depthStencilBuffer) 642 if (!m_depthStencilBuffer)
663 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer); 643 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer);
664 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); 644 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
665 if (m_antiAliasingMode == MSAAImplicitResolve) 645 if (m_antiAliasingMode == MSAAImplicitResolve)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 break; 733 break;
754 } while (!adjustedSize.isEmpty()); 734 } while (!adjustedSize.isEmpty());
755 735
756 setSize(adjustedSize); 736 setSize(adjustedSize);
757 737
758 if (adjustedSize.isEmpty()) 738 if (adjustedSize.isEmpty())
759 return false; 739 return false;
760 } 740 }
761 741
762 m_gl->Disable(GL_SCISSOR_TEST); 742 m_gl->Disable(GL_SCISSOR_TEST);
763 m_gl->ClearColor(0, 0, 0, 0); 743 m_gl->ClearColor(0, 0, 0, defaultBufferRequiresAlphaChannelToBePreserved() ? 1 : 0);
764 m_gl->ColorMask(true, true, true, !requiresAlphaChannelToBePreserved()); 744 m_gl->ColorMask(true, true, true, true);
765 745
766 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 746 GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
767 if (!!m_depthStencilBuffer) { 747 if (!!m_depthStencilBuffer) {
768 m_gl->ClearDepthf(1.0f); 748 m_gl->ClearDepthf(1.0f);
769 clearMask |= GL_DEPTH_BUFFER_BIT; 749 clearMask |= GL_DEPTH_BUFFER_BIT;
770 m_gl->DepthMask(true); 750 m_gl->DepthMask(true);
771 } 751 }
772 if (!!m_depthStencilBuffer) { 752 if (!!m_depthStencilBuffer) {
773 m_gl->ClearStencil(0); 753 m_gl->ClearStencil(0);
774 clearMask |= GL_STENCIL_BUFFER_BIT; 754 clearMask |= GL_STENCIL_BUFFER_BIT;
(...skipping 11 matching lines...) Expand all
786 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); 766 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
787 767
788 if (m_scissorEnabled) 768 if (m_scissorEnabled)
789 m_gl->Disable(GL_SCISSOR_TEST); 769 m_gl->Disable(GL_SCISSOR_TEST);
790 770
791 int width = m_size.width(); 771 int width = m_size.width();
792 int height = m_size.height(); 772 int height = m_size.height();
793 // Use NEAREST, because there is no scale performed during the blit. 773 // Use NEAREST, because there is no scale performed during the blit.
794 GLuint filter = GL_NEAREST; 774 GLuint filter = GL_NEAREST;
795 775
796 // If the destination has a different color format than the source, then 776 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, filter);
797 // first resolve to an intermediary renderbuffer with the same color
798 // format.
799 // If this extra blit proves to be a performance problem, it can be
800 // bypassed on most GPUs by performing client side GL_RGBA emulation on
801 // the source renderbuffer.
802 // https://bugs.chromium.org/p/chromium/issues/detail?id=595948#c30
803 if (m_colorBuffer.parameters.internalColorFormat == GL_RGBA && m_colorBu ffer.parameters.internalRenderbufferFormat == GL_RGB8_OES) {
804 if (!m_intermediateFBO) {
805 DCHECK(!m_intermediateRenderbuffer);
806 m_gl->GenRenderbuffers(1, &m_intermediateRenderbuffer);
807 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_intermediateRenderbuff er);
808 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_RGB8, width, heigh t);
809 777
810 m_gl->GenFramebuffers(1, &m_intermediateFBO); 778 // On old AMD GPUs on OS X, glColorMask doesn't work correctly for
811 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_intermediateF BO); 779 // multisampled renderbuffers and the alpha channel can be overwritten.
812 m_gl->FramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_ANGLE, GL_COLO R_ATTACHMENT0, GL_RENDERBUFFER, m_intermediateRenderbuffer); 780 // Clear the alpha channel of |m_fbo|.
813 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_renderbufferBinding); 781 if (defaultBufferRequiresAlphaChannelToBePreserved()
814 } 782 && contextProvider()->getCapabilities().disable_webgl_multisampling_ color_mask_usage) {
783 m_gl->ClearColor(0, 0, 0, 1);
784 m_gl->ColorMask(false, false, false, true);
785 m_gl->Clear(GL_COLOR_BUFFER_BIT);
815 786
816 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_intermediateFBO); 787 m_gl->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], m_clearColor[3]);
817 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, heig ht, GL_COLOR_BUFFER_BIT, filter); 788 m_gl->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], m_co lorMask[3]);
818
819 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_intermediateFBO);
820 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
821 } 789 }
822 790
823 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, filter);
824
825 if (m_scissorEnabled) 791 if (m_scissorEnabled)
826 m_gl->Enable(GL_SCISSOR_TEST); 792 m_gl->Enable(GL_SCISSOR_TEST);
827 } 793 }
828 794
829 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 795 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
830 if (m_antiAliasingMode == ScreenSpaceAntialiasing) { 796 if (m_antiAliasingMode == ScreenSpaceAntialiasing) {
831 m_gl->ApplyScreenSpaceAntialiasingCHROMIUM(); 797 m_gl->ApplyScreenSpaceAntialiasingCHROMIUM();
832 } 798 }
833 m_contentsChangeCommitted = true; 799 m_contentsChangeCommitted = true;
834 } 800 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 bool DrawingBuffer::wantExplicitResolve() 1037 bool DrawingBuffer::wantExplicitResolve()
1072 { 1038 {
1073 return m_antiAliasingMode == MSAAExplicitResolve; 1039 return m_antiAliasingMode == MSAAExplicitResolve;
1074 } 1040 }
1075 1041
1076 bool DrawingBuffer::wantDepthOrStencil() 1042 bool DrawingBuffer::wantDepthOrStencil()
1077 { 1043 {
1078 return m_wantDepth || m_wantStencil; 1044 return m_wantDepth || m_wantStencil;
1079 } 1045 }
1080 1046
1047 GLenum DrawingBuffer::getMultisampledRenderbufferFormat()
1048 {
1049 DCHECK(wantExplicitResolve());
1050 if (m_wantAlphaChannel)
1051 return GL_RGBA8_OES;
1052 if (m_colorBuffer.imageId && contextProvider()->getCapabilities().chromium_i mage_rgb_emulation)
1053 return GL_RGBA8_OES;
1054 return GL_RGB8_OES;
1055 }
1056
1081 void DrawingBuffer::restoreTextureBindings() 1057 void DrawingBuffer::restoreTextureBindings()
1082 { 1058 {
1083 // This class potentially modifies the bindings for GL_TEXTURE_2D and 1059 // This class potentially modifies the bindings for GL_TEXTURE_2D and
1084 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since 1060 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since
1085 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. 1061 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE.
1086 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); 1062 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding);
1087 } 1063 }
1088 1064
1089 } // namespace blink 1065 } // 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