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

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: Clean up. 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
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/WebGraphicsContext3D.h" 44 #include "public/platform/WebGraphicsContext3D.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 PassOwnPtr<Extensions3DUtil> extensionsUtil, 129 PassOwnPtr<Extensions3DUtil> extensionsUtil,
129 bool discardFramebufferSupported, 130 bool discardFramebufferSupported,
130 bool wantAlphaChannel, 131 bool wantAlphaChannel,
131 bool premultipliedAlpha, 132 bool premultipliedAlpha,
132 PreserveDrawingBuffer preserve) 133 PreserveDrawingBuffer preserve)
133 : m_preserveDrawingBuffer(preserve) 134 : m_preserveDrawingBuffer(preserve)
134 , m_scissorEnabled(false) 135 , m_scissorEnabled(false)
135 , m_texture2DBinding(0) 136 , m_texture2DBinding(0)
136 , m_drawFramebufferBinding(0) 137 , m_drawFramebufferBinding(0)
137 , m_readFramebufferBinding(0) 138 , m_readFramebufferBinding(0)
139 , m_renderbufferBinding(0)
138 , m_activeTextureUnit(GL_TEXTURE0) 140 , m_activeTextureUnit(GL_TEXTURE0)
139 , m_contextProvider(std::move(contextProvider)) 141 , m_contextProvider(std::move(contextProvider))
140 , m_context(m_contextProvider->context3d()) 142 , m_context(m_contextProvider->context3d())
141 , m_gl(m_contextProvider->contextGL()) 143 , m_gl(m_contextProvider->contextGL())
142 , m_extensionsUtil(std::move(extensionsUtil)) 144 , m_extensionsUtil(std::move(extensionsUtil))
143 , m_size(-1, -1) 145 , m_size(-1, -1)
144 , m_discardFramebufferSupported(discardFramebufferSupported) 146 , m_discardFramebufferSupported(discardFramebufferSupported)
145 , m_wantAlphaChannel(wantAlphaChannel) 147 , m_wantAlphaChannel(wantAlphaChannel)
146 , m_premultipliedAlpha(premultipliedAlpha) 148 , m_premultipliedAlpha(premultipliedAlpha)
147 , m_hasImplicitStencilBuffer(false) 149 , m_hasImplicitStencilBuffer(false)
148 , m_fbo(0) 150 , m_fbo(0)
149 , m_depthStencilBuffer(0) 151 , m_depthStencilBuffer(0)
150 , m_multisampleFBO(0) 152 , m_multisampleFBO(0)
153 , m_multisampleIntermediateFBO(0)
154 , m_multisampleIntermediateRenderbuffer(0)
151 , m_multisampleColorBuffer(0) 155 , m_multisampleColorBuffer(0)
152 , m_contentsChanged(true) 156 , m_contentsChanged(true)
153 , m_contentsChangeCommitted(false) 157 , m_contentsChangeCommitted(false)
154 , m_bufferClearNeeded(false) 158 , m_bufferClearNeeded(false)
155 , m_antiAliasingMode(None) 159 , m_antiAliasingMode(None)
156 , m_maxTextureSize(0) 160 , m_maxTextureSize(0)
157 , m_sampleCount(0) 161 , m_sampleCount(0)
158 , m_packAlignment(4) 162 , m_packAlignment(4)
159 , m_destructionInProgress(false) 163 , m_destructionInProgress(false)
160 , m_isHidden(false) 164 , m_isHidden(false)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 222
219 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality) 223 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality)
220 { 224 {
221 if (m_filterQuality != filterQuality) { 225 if (m_filterQuality != filterQuality) {
222 m_filterQuality = filterQuality; 226 m_filterQuality = filterQuality;
223 if (m_layer) 227 if (m_layer)
224 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); 228 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality);
225 } 229 }
226 } 230 }
227 231
232 bool DrawingBuffer::requiresRGBEmulation()
233 {
234 // When an explicit resolve is required, clients draw into a render buffer
235 // which is never backed by an IOSurface.
236 if (m_antiAliasingMode == MSAAExplicitResolve)
237 return false;
238 return !m_drawFramebufferBinding && !m_wantAlphaChannel && m_colorBuffer.ima geId && contextProvider()->getCapabilities().chromium_image_rgb_emulation;
239 }
240
228 void DrawingBuffer::freeRecycledMailboxes() 241 void DrawingBuffer::freeRecycledMailboxes()
229 { 242 {
230 if (m_recycledMailboxQueue.isEmpty()) 243 if (m_recycledMailboxQueue.isEmpty())
231 return; 244 return;
232 while (!m_recycledMailboxQueue.isEmpty()) 245 while (!m_recycledMailboxQueue.isEmpty())
233 deleteMailbox(m_recycledMailboxQueue.takeLast()); 246 deleteMailbox(m_recycledMailboxQueue.takeLast());
234 } 247 }
235 248
236 bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt ernalBitmap* bitmap) 249 bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt ernalBitmap* bitmap)
237 { 250 {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ASSERT_NOT_REACHED(); 349 ASSERT_NOT_REACHED();
337 } 350 }
338 351
339 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters() 352 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters()
340 { 353 {
341 #if OS(MACOSX) 354 #if OS(MACOSX)
342 // A CHROMIUM_image backed texture requires a specialized set of parameters 355 // A CHROMIUM_image backed texture requires a specialized set of parameters
343 // on OSX. 356 // on OSX.
344 TextureParameters parameters; 357 TextureParameters parameters;
345 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; 358 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB;
346 parameters.internalColorFormat = GL_RGBA; 359
347 parameters.internalRenderbufferFormat = GL_RGBA8_OES; 360 if (m_wantAlphaChannel) {
348 parameters.colorFormat = GL_RGBA; 361 parameters.creationInternalColorFormat = GL_RGBA;
362 parameters.internalColorFormat = GL_RGBA;
363 parameters.internalRenderbufferFormat = GL_RGBA8_OES;
364 } else if (contextProvider()->getCapabilities().chromium_image_rgb_emulation ) {
365 parameters.creationInternalColorFormat = GL_RGB;
366 parameters.internalColorFormat = GL_RGBA;
367 parameters.internalRenderbufferFormat = GL_RGB8_OES;
368 } else {
369 parameters.creationInternalColorFormat = GL_RGB;
370 parameters.internalColorFormat = GL_RGB;
371 parameters.internalRenderbufferFormat = GL_RGB8_OES;
372 }
373
374 // Unused.
Ken Russell (switch to Gerrit) 2016/04/29 09:33:09 Unused when CHROMIUM_image is being used, right? D
erikchen 2016/05/03 22:58:07 Correct. I updated the comment. Fallback textures
375 parameters.colorFormat = 0;
349 return parameters; 376 return parameters;
350 #else 377 #else
351 return defaultTextureParameters(); 378 return defaultTextureParameters();
352 #endif 379 #endif
353 } 380 }
354 381
355 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() 382 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters()
356 { 383 {
357 TextureParameters parameters; 384 TextureParameters parameters;
358 parameters.target = GL_TEXTURE_2D; 385 parameters.target = GL_TEXTURE_2D;
359 if (m_wantAlphaChannel) { 386 if (m_wantAlphaChannel) {
360 parameters.internalColorFormat = GL_RGBA; 387 parameters.internalColorFormat = GL_RGBA;
388 parameters.creationInternalColorFormat = GL_RGBA;
361 parameters.colorFormat = GL_RGBA; 389 parameters.colorFormat = GL_RGBA;
362 parameters.internalRenderbufferFormat = GL_RGBA8_OES; 390 parameters.internalRenderbufferFormat = GL_RGBA8_OES;
363 } else { 391 } else {
364 parameters.internalColorFormat = GL_RGB; 392 parameters.internalColorFormat = GL_RGB;
393 parameters.creationInternalColorFormat = GL_RGB;
365 parameters.colorFormat = GL_RGB; 394 parameters.colorFormat = GL_RGB;
366 parameters.internalRenderbufferFormat = GL_RGB8_OES; 395 parameters.internalRenderbufferFormat = GL_RGB8_OES;
367 } 396 }
368 return parameters; 397 return parameters;
369 } 398 }
370 399
371 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail box& mailbox) 400 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail box& mailbox)
372 { 401 {
373 ASSERT(m_textureMailboxes.size()); 402 ASSERT(m_textureMailboxes.size());
374 // Ensure not to call the destructor until deleteMailbox() is completed. 403 // Ensure not to call the destructor until deleteMailbox() is completed.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 608
580 if (m_multisampleFBO) 609 if (m_multisampleFBO)
581 m_gl->DeleteFramebuffers(1, &m_multisampleFBO); 610 m_gl->DeleteFramebuffers(1, &m_multisampleFBO);
582 611
583 if (m_fbo) 612 if (m_fbo)
584 m_gl->DeleteFramebuffers(1, &m_fbo); 613 m_gl->DeleteFramebuffers(1, &m_fbo);
585 614
586 if (m_multisampleColorBuffer) 615 if (m_multisampleColorBuffer)
587 m_gl->DeleteRenderbuffers(1, &m_multisampleColorBuffer); 616 m_gl->DeleteRenderbuffers(1, &m_multisampleColorBuffer);
588 617
618 if (m_multisampleIntermediateFBO)
619 m_gl->DeleteFramebuffers(1, &m_multisampleIntermediateFBO);
620
621 if (m_multisampleIntermediateRenderbuffer)
622 m_gl->DeleteRenderbuffers(1, &m_multisampleIntermediateRenderbuffer);
623
589 if (m_depthStencilBuffer) 624 if (m_depthStencilBuffer)
590 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer); 625 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer);
591 626
592 if (m_colorBuffer.textureId) { 627 if (m_colorBuffer.textureId) {
593 deleteChromiumImageForTexture(&m_colorBuffer); 628 deleteChromiumImageForTexture(&m_colorBuffer);
594 m_gl->DeleteTextures(1, &m_colorBuffer.textureId); 629 m_gl->DeleteTextures(1, &m_colorBuffer.textureId);
595 } 630 }
596 631
597 setSize(IntSize()); 632 setSize(IntSize());
598 633
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } while (!adjustedSize.isEmpty()); 777 } while (!adjustedSize.isEmpty());
743 778
744 setSize(adjustedSize); 779 setSize(adjustedSize);
745 780
746 if (adjustedSize.isEmpty()) 781 if (adjustedSize.isEmpty())
747 return false; 782 return false;
748 } 783 }
749 784
750 m_gl->Disable(GL_SCISSOR_TEST); 785 m_gl->Disable(GL_SCISSOR_TEST);
751 m_gl->ClearColor(0, 0, 0, 0); 786 m_gl->ClearColor(0, 0, 0, 0);
752 m_gl->ColorMask(true, true, true, true); 787 m_gl->ColorMask(true, true, true, !requiresRGBEmulation());
753 788
754 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 789 GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
755 if (!!m_depthStencilBuffer) { 790 if (!!m_depthStencilBuffer) {
756 m_gl->ClearDepthf(1.0f); 791 m_gl->ClearDepthf(1.0f);
757 clearMask |= GL_DEPTH_BUFFER_BIT; 792 clearMask |= GL_DEPTH_BUFFER_BIT;
758 m_gl->DepthMask(true); 793 m_gl->DepthMask(true);
759 } 794 }
760 if (!!m_depthStencilBuffer) { 795 if (!!m_depthStencilBuffer) {
761 m_gl->ClearStencil(0); 796 m_gl->ClearStencil(0);
762 clearMask |= GL_STENCIL_BUFFER_BIT; 797 clearMask |= GL_STENCIL_BUFFER_BIT;
763 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); 798 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
764 } 799 }
765 800
766 clearFramebuffers(clearMask); 801 clearFramebuffers(clearMask);
802 m_gl->ColorMask(true, true, true, true);
Ken Russell (switch to Gerrit) 2016/04/29 09:33:09 Were callers relying on this to set the color mask
erikchen 2016/05/03 22:58:07 No. I removed this call.
767 return true; 803 return true;
768 } 804 }
769 805
770 void DrawingBuffer::commit() 806 void DrawingBuffer::commit()
771 { 807 {
772 if (m_multisampleFBO && !m_contentsChangeCommitted) { 808 if (m_multisampleFBO && !m_contentsChangeCommitted) {
773 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); 809 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO);
774 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); 810 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
775 811
776 if (m_scissorEnabled) 812 if (m_scissorEnabled)
777 m_gl->Disable(GL_SCISSOR_TEST); 813 m_gl->Disable(GL_SCISSOR_TEST);
778 814
779 int width = m_size.width(); 815 int width = m_size.width();
780 int height = m_size.height(); 816 int height = m_size.height();
781 // Use NEAREST, because there is no scale performed during the blit. 817 // Use NEAREST, because there is no scale performed during the blit.
782 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); 818 GLuint filter = GL_NEAREST;
819
820 // If the destination has a different color format than the source, then
821 // first resolve to an intermediary renderbuffer with the same color
822 // format.
823 // If this extra blit proves to be a performance problem, it can be
824 // bypassed on most GPUs by performing client side GL_RGBA emulation on
825 // the source renderbuffer.
826 // https://bugs.chromium.org/p/chromium/issues/detail?id=595948#c30
827 if (m_colorBuffer.parameters.internalColorFormat == GL_RGBA && m_colorBu ffer.parameters.internalRenderbufferFormat == GL_RGB8_OES) {
828 if (!m_multisampleIntermediateFBO) {
829 DCHECK(!m_multisampleIntermediateRenderbuffer);
Zhenyao Mo 2016/04/29 22:54:16 These two names are misleading. The intermediate
erikchen 2016/05/03 22:58:08 Done.
830 m_gl->GenRenderbuffers(1, &m_multisampleIntermediateRenderbuffer );
831 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleIntermediat eRenderbuffer);
Ken Russell (switch to Gerrit) 2016/04/29 09:33:09 Is resizing of m_multisampleIntermediateRenderbuff
erikchen 2016/05/03 22:58:07 No, it wasn't. I added a test: https://codereview.
832 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_RGB8, width, heigh t);
833
834 m_gl->GenFramebuffers(1, &m_multisampleIntermediateFBO);
835 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_multisampleIn termediateFBO);
836 m_gl->FramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_ANGLE, GL_COLO R_ATTACHMENT0, GL_RENDERBUFFER, m_multisampleIntermediateRenderbuffer);
837 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_renderbufferBinding);
838 }
839
840 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_multisampleInterm ediateFBO);
841 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, heig ht, GL_COLOR_BUFFER_BIT, filter);
842
843 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleInterm ediateFBO);
844 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
845 }
846
847 m_gl->BlitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, filter);
783 848
784 if (m_scissorEnabled) 849 if (m_scissorEnabled)
785 m_gl->Enable(GL_SCISSOR_TEST); 850 m_gl->Enable(GL_SCISSOR_TEST);
786 } 851 }
787 852
788 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 853 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
789 if (m_antiAliasingMode == ScreenSpaceAntialiasing) { 854 if (m_antiAliasingMode == ScreenSpaceAntialiasing) {
790 m_gl->ApplyScreenSpaceAntialiasingCHROMIUM(); 855 m_gl->ApplyScreenSpaceAntialiasingCHROMIUM();
791 } 856 }
792 m_contentsChangeCommitted = true; 857 m_contentsChangeCommitted = true;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) 991 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info)
927 { 992 {
928 if (info->imageId) { 993 if (info->imageId) {
929 m_gl->BindTexture(info->parameters.target, info->textureId); 994 m_gl->BindTexture(info->parameters.target, info->textureId);
930 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); 995 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId);
931 m_gl->DestroyImageCHROMIUM(info->imageId); 996 m_gl->DestroyImageCHROMIUM(info->imageId);
932 info->imageId = 0; 997 info->imageId = 0;
933 } 998 }
934 } 999 }
935 1000
1001 void DrawingBuffer::clearChromiumImageIfNecessary(const TextureInfo& info)
1002 {
1003 if (m_wantAlphaChannel)
Zhenyao Mo 2016/04/29 22:54:15 You can also return early if we don't need to emul
erikchen 2016/05/03 22:58:07 Done.
1004 return;
1005
1006 GLuint fbo = 0;
1007 m_gl->GenFramebuffers(1, &fbo);
1008 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo);
1009 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame ters.target, info.textureId, 0);
1010 m_gl->ClearColor(0, 0, 0, 1);
1011 m_gl->ColorMask(false, false, false, true);
Ken Russell (switch to Gerrit) 2016/04/29 09:33:09 Is it deliberate that only the alpha channel is be
erikchen 2016/05/03 22:58:07 Yes. I updated the name of this method to be clear
1012 m_gl->Clear(GL_COLOR_BUFFER_BIT);
1013 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame ters.target, 0, 0);
1014 m_gl->DeleteFramebuffers(1, &fbo);
1015 restoreFramebufferBindings();
Zhenyao Mo 2016/04/29 22:54:16 Should we also restore clear color and clear mask
erikchen 2016/05/03 22:58:07 Yes. Done.
1016 }
1017
936 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I ntSize& size) 1018 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I ntSize& size)
937 { 1019 {
938 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose
939 // behavior mimics a texture with internal format GL_RGB.
940 // https://crbug.com/581777.
941 if (!m_wantAlphaChannel)
942 return createDefaultTextureAndAllocateMemory(size);
943
944 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) 1020 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled())
945 return createDefaultTextureAndAllocateMemory(size); 1021 return createDefaultTextureAndAllocateMemory(size);
946 1022
947 // First, try to allocate a CHROMIUM_image. This always has the potential to 1023 // First, try to allocate a CHROMIUM_image. This always has the potential to
948 // fail. 1024 // fail.
949 TextureParameters parameters = chromiumImageTextureParameters(); 1025 TextureParameters parameters = chromiumImageTextureParameters();
950 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size .height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); 1026 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size .height(), parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM);
951 if (!imageId) 1027 if (!imageId)
952 return createDefaultTextureAndAllocateMemory(size); 1028 return createDefaultTextureAndAllocateMemory(size);
953 1029
954 GLuint textureId = createColorTexture(parameters); 1030 GLuint textureId = createColorTexture(parameters);
955 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); 1031 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId);
956 1032
957 TextureInfo info; 1033 TextureInfo info;
958 info.textureId = textureId; 1034 info.textureId = textureId;
959 info.imageId = imageId; 1035 info.imageId = imageId;
960 info.parameters = parameters; 1036 info.parameters = parameters;
1037 clearChromiumImageIfNecessary(info);
961 return info; 1038 return info;
962 } 1039 }
963 1040
964 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size) 1041 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size)
965 { 1042 {
966 TextureParameters parameters = defaultTextureParameters(); 1043 TextureParameters parameters = defaultTextureParameters();
967 GLuint textureId = createColorTexture(parameters); 1044 GLuint textureId = createColorTexture(parameters);
968 texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); 1045 texImage2DResourceSafe(parameters.target, 0, parameters.creationInternalColo rFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYT E);
969 1046
970 DrawingBuffer::TextureInfo info; 1047 DrawingBuffer::TextureInfo info;
971 info.textureId = textureId; 1048 info.textureId = textureId;
972 info.parameters = parameters; 1049 info.parameters = parameters;
973 return info; 1050 return info;
974 } 1051 }
975 1052
976 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) 1053 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size)
977 { 1054 {
978 ASSERT(info->textureId); 1055 ASSERT(info->textureId);
979 if (info->imageId) { 1056 if (info->imageId) {
980 deleteChromiumImageForTexture(info); 1057 deleteChromiumImageForTexture(info);
981 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); 1058 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s ize.height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIU M);
982 if (info->imageId) { 1059 if (info->imageId) {
983 m_gl->BindTexture(info->parameters.target, info->textureId); 1060 m_gl->BindTexture(info->parameters.target, info->textureId);
984 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId) ; 1061 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId) ;
1062 clearChromiumImageIfNecessary(*info);
985 return; 1063 return;
986 } 1064 }
987 1065
988 // If the desired texture target is different, there's no way to fall ba ck 1066 // If the desired texture target is different, there's no way to fall ba ck
989 // to a non CHROMIUM_image texture. 1067 // to a non CHROMIUM_image texture.
990 if (chromiumImageTextureParameters().target != defaultTextureParameters( ).target) 1068 if (chromiumImageTextureParameters().target != defaultTextureParameters( ).target)
991 return; 1069 return;
992 } 1070 }
993 1071
994 m_gl->BindTexture(info->parameters.target, info->textureId); 1072 m_gl->BindTexture(info->parameters.target, info->textureId);
995 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN SIGNED_BYTE); 1073 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.creation InternalColorFormat, size.width(), size.height(), 0, info->parameters.colorForma t, GL_UNSIGNED_BYTE);
996 } 1074 }
997 1075
998 void DrawingBuffer::attachColorBufferToCurrentFBO() 1076 void DrawingBuffer::attachColorBufferToCurrentFBO()
999 { 1077 {
1000 GLenum target = m_colorBuffer.parameters.target; 1078 GLenum target = m_colorBuffer.parameters.target;
1001 1079
1002 m_gl->BindTexture(target, m_colorBuffer.textureId); 1080 m_gl->BindTexture(target, m_colorBuffer.textureId);
1003 1081
1004 if (m_antiAliasingMode == MSAAImplicitResolve) 1082 if (m_antiAliasingMode == MSAAImplicitResolve)
1005 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); 1083 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount);
1006 else 1084 else
1007 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_colorBuffer.textureId, 0); 1085 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, m_colorBuffer.textureId, 0);
1008 1086
1009 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); 1087 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding);
1010 } 1088 }
1011 1089
1012 } // namespace blink 1090 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698