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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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 "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
34 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
35 #include "platform/graphics/GraphicsLayer.h" | 36 #include "platform/graphics/GraphicsLayer.h" |
36 #include "platform/graphics/ImageBuffer.h" | 37 #include "platform/graphics/ImageBuffer.h" |
37 #include "platform/graphics/gpu/Extensions3DUtil.h" | 38 #include "platform/graphics/gpu/Extensions3DUtil.h" |
38 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
39 #include "public/platform/WebCompositorSupport.h" | 40 #include "public/platform/WebCompositorSupport.h" |
40 #include "public/platform/WebExternalBitmap.h" | 41 #include "public/platform/WebExternalBitmap.h" |
41 #include "public/platform/WebExternalTextureLayer.h" | 42 #include "public/platform/WebExternalTextureLayer.h" |
42 #include "public/platform/WebGraphicsContext3D.h" | 43 #include "public/platform/WebGraphicsContext3D.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 91 |
91 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3D>
context, const IntSize& size, PreserveDrawingBuffer preserve, WebGraphicsContex
t3D::Attributes requestedAttributes) | 92 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3D>
context, const IntSize& size, PreserveDrawingBuffer preserve, WebGraphicsContex
t3D::Attributes requestedAttributes) |
92 { | 93 { |
93 ASSERT(context); | 94 ASSERT(context); |
94 | 95 |
95 if (shouldFailDrawingBufferCreationForTesting) { | 96 if (shouldFailDrawingBufferCreationForTesting) { |
96 shouldFailDrawingBufferCreationForTesting = false; | 97 shouldFailDrawingBufferCreationForTesting = false; |
97 return nullptr; | 98 return nullptr; |
98 } | 99 } |
99 | 100 |
100 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g
et()); | 101 gpu::gles2::GLES2Interface* gl = context->getGLES2Interface(); |
| 102 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g
et(), gl); |
101 if (!extensionsUtil->isValid()) { | 103 if (!extensionsUtil->isValid()) { |
102 // This might be the first time we notice that the WebGraphicsContext3D
is lost. | 104 // This might be the first time we notice that the WebGraphicsContext3D
is lost. |
103 return nullptr; | 105 return nullptr; |
104 } | 106 } |
105 ASSERT(extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil")); | 107 ASSERT(extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil")); |
106 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 108 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
107 bool multisampleSupported = (extensionsUtil->supportsExtension("GL_CHROMIUM_
framebuffer_multisample") | 109 bool multisampleSupported = (extensionsUtil->supportsExtension("GL_CHROMIUM_
framebuffer_multisample") |
108 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_text
ure")) | 110 || extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_text
ure")) |
109 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); | 111 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); |
110 if (multisampleSupported) { | 112 if (multisampleSupported) { |
111 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 113 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
112 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le")) | 114 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp
le")) |
113 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); | 115 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); |
114 else | 116 else |
115 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); | 117 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); |
116 } | 118 } |
117 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); | 119 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); |
118 if (discardFramebufferSupported) | 120 if (discardFramebufferSupported) |
119 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 121 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
120 | 122 |
121 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontext), extensionsUtil.release(), multisampleSupported, discardFramebufferSuppo
rted, preserve, requestedAttributes)); | 123 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontext), gl, extensionsUtil.release(), multisampleSupported, discardFramebufferS
upported, preserve, requestedAttributes)); |
122 if (!drawingBuffer->initialize(size)) { | 124 if (!drawingBuffer->initialize(size)) { |
123 drawingBuffer->beginDestruction(); | 125 drawingBuffer->beginDestruction(); |
124 return PassRefPtr<DrawingBuffer>(); | 126 return PassRefPtr<DrawingBuffer>(); |
125 } | 127 } |
126 return drawingBuffer.release(); | 128 return drawingBuffer.release(); |
127 } | 129 } |
128 | 130 |
129 void DrawingBuffer::forceNextDrawingBufferCreationToFail() | 131 void DrawingBuffer::forceNextDrawingBufferCreationToFail() |
130 { | 132 { |
131 shouldFailDrawingBufferCreationForTesting = true; | 133 shouldFailDrawingBufferCreationForTesting = true; |
132 } | 134 } |
133 | 135 |
134 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context, | 136 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context, gpu::gles
2::GLES2Interface* gl, PassOwnPtr<Extensions3DUtil> extensionsUtil, bool multisa
mpleExtensionSupported, bool discardFramebufferSupported, PreserveDrawingBuffer
preserve, WebGraphicsContext3D::Attributes requestedAttributes) |
135 PassOwnPtr<Extensions3DUtil> extensionsUtil, | |
136 bool multisampleExtensionSupported, | |
137 bool discardFramebufferSupported, | |
138 PreserveDrawingBuffer preserve, | |
139 WebGraphicsContext3D::Attributes requestedAttributes) | |
140 : m_preserveDrawingBuffer(preserve) | 137 : m_preserveDrawingBuffer(preserve) |
141 , m_scissorEnabled(false) | 138 , m_scissorEnabled(false) |
142 , m_texture2DBinding(0) | 139 , m_texture2DBinding(0) |
143 , m_drawFramebufferBinding(0) | 140 , m_drawFramebufferBinding(0) |
144 , m_readFramebufferBinding(0) | 141 , m_readFramebufferBinding(0) |
145 , m_activeTextureUnit(GL_TEXTURE0) | 142 , m_activeTextureUnit(GL_TEXTURE0) |
146 , m_context(std::move(context)) | 143 , m_context(std::move(context)) |
| 144 , m_gl(gl) |
147 , m_extensionsUtil(std::move(extensionsUtil)) | 145 , m_extensionsUtil(std::move(extensionsUtil)) |
148 , m_size(-1, -1) | 146 , m_size(-1, -1) |
149 , m_requestedAttributes(requestedAttributes) | 147 , m_requestedAttributes(requestedAttributes) |
150 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 148 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
151 , m_discardFramebufferSupported(discardFramebufferSupported) | 149 , m_discardFramebufferSupported(discardFramebufferSupported) |
152 , m_fbo(0) | 150 , m_fbo(0) |
153 , m_depthStencilBuffer(0) | 151 , m_depthStencilBuffer(0) |
154 , m_multisampleFBO(0) | 152 , m_multisampleFBO(0) |
155 , m_multisampleColorBuffer(0) | 153 , m_multisampleColorBuffer(0) |
156 , m_contentsChanged(true) | 154 , m_contentsChanged(true) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h
as live mailboxes | 311 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h
as live mailboxes |
314 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); | 312 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); |
315 frontColorBufferMailbox->m_parentDrawingBuffer = this; | 313 frontColorBufferMailbox->m_parentDrawingBuffer = this; |
316 *outMailbox = frontColorBufferMailbox->mailbox; | 314 *outMailbox = frontColorBufferMailbox->mailbox; |
317 m_frontColorBuffer = { frontColorBufferMailbox->textureInfo, frontColorBuffe
rMailbox->mailbox }; | 315 m_frontColorBuffer = { frontColorBufferMailbox->textureInfo, frontColorBuffe
rMailbox->mailbox }; |
318 return true; | 316 return true; |
319 } | 317 } |
320 | 318 |
321 void DrawingBuffer::mailboxReleased(const WebExternalTextureMailbox& mailbox, bo
ol lostResource) | 319 void DrawingBuffer::mailboxReleased(const WebExternalTextureMailbox& mailbox, bo
ol lostResource) |
322 { | 320 { |
323 if (m_destructionInProgress || m_context->isContextLost() || lostResource ||
m_isHidden) { | 321 if (m_destructionInProgress || m_gl->GetGraphicsResetStatusKHR() != GL_NO_ER
ROR || lostResource || m_isHidden) { |
324 mailboxReleasedWithoutRecycling(mailbox); | 322 mailboxReleasedWithoutRecycling(mailbox); |
325 return; | 323 return; |
326 } | 324 } |
327 | 325 |
328 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | 326 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { |
329 RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i]; | 327 RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i]; |
330 if (nameEquals(mailboxInfo->mailbox, mailbox)) { | 328 if (nameEquals(mailboxInfo->mailbox, mailbox)) { |
331 memcpy(mailboxInfo->mailbox.syncToken, mailbox.syncToken, | 329 memcpy(mailboxInfo->mailbox.syncToken, mailbox.syncToken, |
332 sizeof(mailboxInfo->mailbox.syncToken)); | 330 sizeof(mailboxInfo->mailbox.syncToken)); |
333 mailboxInfo->mailbox.validSyncToken = mailbox.validSyncToken; | 331 mailboxInfo->mailbox.validSyncToken = mailbox.validSyncToken; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); | 435 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); |
438 m_textureMailboxes.remove(i); | 436 m_textureMailboxes.remove(i); |
439 return; | 437 return; |
440 } | 438 } |
441 } | 439 } |
442 ASSERT_NOT_REACHED(); | 440 ASSERT_NOT_REACHED(); |
443 } | 441 } |
444 | 442 |
445 bool DrawingBuffer::initialize(const IntSize& size) | 443 bool DrawingBuffer::initialize(const IntSize& size) |
446 { | 444 { |
447 if (m_context->isContextLost()) { | 445 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
448 // Need to try to restore the context again later. | 446 // Need to try to restore the context again later. |
449 return false; | 447 return false; |
450 } | 448 } |
451 | 449 |
452 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 450 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); |
453 | 451 |
454 int maxSampleCount = 0; | 452 int maxSampleCount = 0; |
455 m_antiAliasingMode = None; | 453 m_antiAliasingMode = None; |
456 if (m_requestedAttributes.antialias && m_multisampleExtensionSupported) { | 454 if (m_requestedAttributes.antialias && m_multisampleExtensionSupported) { |
457 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 455 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
(...skipping 25 matching lines...) Expand all Loading... |
483 m_context->getIntegerv(GL_DEPTH_BITS, &depthBits); | 481 m_context->getIntegerv(GL_DEPTH_BITS, &depthBits); |
484 m_actualAttributes.depth = depthBits > 0; | 482 m_actualAttributes.depth = depthBits > 0; |
485 } | 483 } |
486 if (m_requestedAttributes.stencil) { | 484 if (m_requestedAttributes.stencil) { |
487 WGC3Dint stencilBits = 0; | 485 WGC3Dint stencilBits = 0; |
488 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); | 486 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); |
489 m_actualAttributes.stencil = stencilBits > 0; | 487 m_actualAttributes.stencil = stencilBits > 0; |
490 } | 488 } |
491 m_actualAttributes.antialias = multisample(); | 489 m_actualAttributes.antialias = multisample(); |
492 | 490 |
493 if (m_context->isContextLost()) { | 491 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
494 // It's possible that the drawing buffer allocation provokes a context l
oss, so check again just in case. http://crbug.com/512302 | 492 // It's possible that the drawing buffer allocation provokes a context l
oss, so check again just in case. http://crbug.com/512302 |
495 return false; | 493 return false; |
496 } | 494 } |
497 | 495 |
498 return true; | 496 return true; |
499 } | 497 } |
500 | 498 |
501 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
m3DObject texture, GLenum internalFormat, | 499 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
m3DObject texture, GLenum internalFormat, |
502 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceDrawi
ngBuffer sourceBuffer) | 500 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceDrawi
ngBuffer sourceBuffer) |
503 { | 501 { |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1030 |
1033 if (m_antiAliasingMode == MSAAImplicitResolve) | 1031 if (m_antiAliasingMode == MSAAImplicitResolve) |
1034 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 1032 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |
1035 else | 1033 else |
1036 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ta
rget, m_colorBuffer.textureId, 0); | 1034 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ta
rget, m_colorBuffer.textureId, 0); |
1037 | 1035 |
1038 m_context->bindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1036 m_context->bindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
1039 } | 1037 } |
1040 | 1038 |
1041 } // namespace blink | 1039 } // namespace blink |
OLD | NEW |