Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t o_texture"); | 98 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t o_texture"); |
| 99 } | 99 } |
| 100 bool packedDepthStencilSupported = extensionsUtil->supportsExtension("GL_OES _packed_depth_stencil"); | 100 bool packedDepthStencilSupported = extensionsUtil->supportsExtension("GL_OES _packed_depth_stencil"); |
| 101 if (packedDepthStencilSupported) | 101 if (packedDepthStencilSupported) |
| 102 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 102 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
| 103 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer"); | 103 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer"); |
| 104 if (discardFramebufferSupported) | 104 if (discardFramebufferSupported) |
| 105 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 105 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
| 106 | 106 |
| 107 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, ex tensionsUtil.release(), multisampleSupported, packedDepthStencilSupported, disca rdFramebufferSupported, preserve, requestedAttributes)); | 107 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, ex tensionsUtil.release(), multisampleSupported, packedDepthStencilSupported, disca rdFramebufferSupported, preserve, requestedAttributes)); |
| 108 drawingBuffer->validateBackbuffer(); | |
| 108 if (!drawingBuffer->initialize(size)) { | 109 if (!drawingBuffer->initialize(size)) { |
| 109 drawingBuffer->beginDestruction(); | 110 drawingBuffer->beginDestruction(); |
| 110 return PassRefPtr<DrawingBuffer>(); | 111 return PassRefPtr<DrawingBuffer>(); |
| 111 } | 112 } |
| 112 return drawingBuffer.release(); | 113 return drawingBuffer.release(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context, | 116 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context, |
| 116 PassOwnPtr<Extensions3DUtil> extensionsUtil, | 117 PassOwnPtr<Extensions3DUtil> extensionsUtil, |
| 117 bool multisampleExtensionSupported, | 118 bool multisampleExtensionSupported, |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 ASSERT_NOT_REACHED(); | 397 ASSERT_NOT_REACHED(); |
| 397 } | 398 } |
| 398 | 399 |
| 399 bool DrawingBuffer::initialize(const IntSize& size) | 400 bool DrawingBuffer::initialize(const IntSize& size) |
| 400 { | 401 { |
| 401 if (m_context->isContextLost()) { | 402 if (m_context->isContextLost()) { |
| 402 // Need to try to restore the context again later. | 403 // Need to try to restore the context again later. |
| 403 return false; | 404 return false; |
| 404 } | 405 } |
| 405 | 406 |
| 406 if (m_requestedAttributes.alpha) { | 407 // Type of color format should be selected based on |
| 408 // alpha attribute & texture format supported on GPU's | |
| 409 if (m_requestedAttributes.alpha || !isRGBTextureSupported()) { | |
| 407 m_internalColorFormat = GL_RGBA; | 410 m_internalColorFormat = GL_RGBA; |
| 408 m_colorFormat = GL_RGBA; | 411 m_colorFormat = GL_RGBA; |
| 409 m_internalRenderbufferFormat = GL_RGBA8_OES; | 412 m_internalRenderbufferFormat = GL_RGBA8_OES; |
| 410 } else { | 413 } else { |
| 411 m_internalColorFormat = GL_RGB; | 414 m_internalColorFormat = GL_RGB; |
| 412 m_colorFormat = GL_RGB; | 415 m_colorFormat = GL_RGB; |
| 413 m_internalRenderbufferFormat = GL_RGB8_OES; | 416 m_internalRenderbufferFormat = GL_RGB8_OES; |
| 414 } | 417 } |
| 415 | 418 |
| 416 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 419 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 break; | 759 break; |
| 757 } while (!adjustedSize.isEmpty()); | 760 } while (!adjustedSize.isEmpty()); |
| 758 | 761 |
| 759 setSize(adjustedSize); | 762 setSize(adjustedSize); |
| 760 | 763 |
| 761 if (adjustedSize.isEmpty()) | 764 if (adjustedSize.isEmpty()) |
| 762 return false; | 765 return false; |
| 763 } | 766 } |
| 764 | 767 |
| 765 m_context->disable(GL_SCISSOR_TEST); | 768 m_context->disable(GL_SCISSOR_TEST); |
| 766 m_context->clearColor(0, 0, 0, 0); | 769 |
| 767 m_context->colorMask(true, true, true, true); | 770 if (!m_requestedAttributes.alpha && !isRGBTextureSupported()) { |
| 771 // This case signifies that requested alpha attribute is false, even tho ugh | |
| 772 // DrawingBuffer choosen backbuffer as GL_RGBA format (due to GPU limita tions). | |
| 773 // 1. So ensure alpha channel should be cleared to 1.0 | |
| 774 // 2. colormask should be disabled (Turn off rendering to alpha) | |
| 775 m_context->clearColor(0, 0, 0, 1); | |
| 776 m_context->colorMask(true, true, true, false); | |
|
Ken Russell (switch to Gerrit)
2015/04/06 21:43:18
This won't work -- the color mask applies to clear
| |
| 777 } else { | |
| 778 m_context->clearColor(0, 0, 0, 0); | |
| 779 m_context->colorMask(true, true, true, true); | |
| 780 } | |
| 768 | 781 |
| 769 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 782 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
| 770 if (m_actualAttributes.depth) { | 783 if (m_actualAttributes.depth) { |
| 771 m_context->clearDepth(1.0f); | 784 m_context->clearDepth(1.0f); |
| 772 clearMask |= GL_DEPTH_BUFFER_BIT; | 785 clearMask |= GL_DEPTH_BUFFER_BIT; |
| 773 m_context->depthMask(true); | 786 m_context->depthMask(true); |
| 774 } | 787 } |
| 775 if (m_actualAttributes.stencil) { | 788 if (m_actualAttributes.stencil) { |
| 776 m_context->clearStencil(0); | 789 m_context->clearStencil(0); |
| 777 clearMask |= GL_STENCIL_BUFFER_BIT; | 790 clearMask |= GL_STENCIL_BUFFER_BIT; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 | 993 |
| 981 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 994 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
| 982 { | 995 { |
| 983 if (info->imageId) { | 996 if (info->imageId) { |
| 984 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 997 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
| 985 m_context->destroyImageCHROMIUM(info->imageId); | 998 m_context->destroyImageCHROMIUM(info->imageId); |
| 986 info->imageId = 0; | 999 info->imageId = 0; |
| 987 } | 1000 } |
| 988 } | 1001 } |
| 989 | 1002 |
| 1003 void DrawingBuffer::validateBackbuffer() | |
| 1004 { | |
| 1005 // One time validation is required for GL_RGB texture | |
|
Ken Russell (switch to Gerrit)
2015/04/06 21:43:18
I'm sorry, but I'm not comfortable doing this code
Ken Russell (switch to Gerrit)
2015/04/06 21:44:54
Also -- on request from another engineer on Blink,
| |
| 1006 // so that DrawingBuffer can choose format for the backbuffer correctly. | |
| 1007 // DrawingBuffer tries to allocate GL_RGB texture in case of alpha attribute false | |
| 1008 // and fails because GL_RGB not supported on specific GPU's (e.g Mali- 2/3/4 00 family). | |
| 1009 Platform3DObject fbo = m_context->createFramebuffer(); | |
| 1010 m_context->bindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| 1011 unsigned offscreenRGBTexture = createColorTexture(); | |
| 1012 m_context->texImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED _BYTE, 0); | |
| 1013 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX TURE_2D, offscreenRGBTexture, 0); | |
| 1014 m_RGBTextureSupported = m_context->checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; | |
| 1015 | |
| 1016 if (fbo) | |
|
Ken Russell (switch to Gerrit)
2015/04/06 21:43:18
Also m_context_>bindFramebuffer(GL_FRAMEBUFFER, 0)
| |
| 1017 m_context->deleteFramebuffer(fbo); | |
| 1018 | |
| 1019 if (offscreenRGBTexture) | |
| 1020 m_context->deleteTexture(offscreenRGBTexture); | |
| 1021 } | |
| 1022 | |
| 990 } // namespace blink | 1023 } // namespace blink |
| OLD | NEW |