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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 private: | 75 private: |
76 blink::WebGraphicsContext3D* m_context; | 76 blink::WebGraphicsContext3D* m_context; |
77 GLenum m_oldActiveTextureUnit; | 77 GLenum m_oldActiveTextureUnit; |
78 Platform3DObject m_oldTextureUnitZeroId; | 78 Platform3DObject m_oldTextureUnitZeroId; |
79 }; | 79 }; |
80 | 80 |
81 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsCon text3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr <ContextEvictionManager> contextEvictionManager) | 81 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsCon text3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr <ContextEvictionManager> contextEvictionManager) |
82 { | 82 { |
83 ASSERT(context); | 83 ASSERT(context); |
84 Extensions3DUtil extensionsUtil(context.get()); | 84 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g et()); |
bajones
2014/04/23 23:52:52
I wonder if the patch couldn't be made cleaner by:
| |
85 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr amebuffer_multisample") | 85 if (!extensionsUtil) { |
86 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); | 86 // This might be the first time we notice that the WebGraphicsContext3D is lost. |
87 return nullptr; | |
88 } | |
89 bool multisampleSupported = extensionsUtil->supportsExtension("GL_CHROMIUM_f ramebuffer_multisample") | |
90 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); | |
87 if (multisampleSupported) { | 91 if (multisampleSupported) { |
88 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp le"); | 92 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisam ple"); |
89 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 93 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
90 } | 94 } |
91 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_ packed_depth_stencil"); | 95 bool packedDepthStencilSupported = extensionsUtil->supportsExtension("GL_OES _packed_depth_stencil"); |
92 if (packedDepthStencilSupported) | 96 if (packedDepthStencilSupported) |
93 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 97 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
94 | 98 |
95 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, mu ltisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManage r)); | 99 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, ex tensionsUtil.release(), multisampleSupported, packedDepthStencilSupported, prese rve, contextEvictionManager)); |
96 if (!drawingBuffer->initialize(size)) | 100 if (!drawingBuffer->initialize(size)) |
97 return PassRefPtr<DrawingBuffer>(); | 101 return PassRefPtr<DrawingBuffer>(); |
98 return drawingBuffer.release(); | 102 return drawingBuffer.release(); |
99 } | 103 } |
100 | 104 |
101 DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context, | 105 DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context, |
106 PassOwnPtr<Extensions3DUtil> extensionsUtil, | |
102 bool multisampleExtensionSupported, | 107 bool multisampleExtensionSupported, |
103 bool packedDepthStencilExtensionSupported, | 108 bool packedDepthStencilExtensionSupported, |
104 PreserveDrawingBuffer preserve, | 109 PreserveDrawingBuffer preserve, |
105 PassRefPtr<ContextEvictionManager> contextEvictionManager) | 110 PassRefPtr<ContextEvictionManager> contextEvictionManager) |
106 : m_preserveDrawingBuffer(preserve) | 111 : m_preserveDrawingBuffer(preserve) |
107 , m_scissorEnabled(false) | 112 , m_scissorEnabled(false) |
108 , m_texture2DBinding(0) | 113 , m_texture2DBinding(0) |
109 , m_framebufferBinding(0) | 114 , m_framebufferBinding(0) |
110 , m_activeTextureUnit(GL_TEXTURE0) | 115 , m_activeTextureUnit(GL_TEXTURE0) |
111 , m_context(context) | 116 , m_context(context) |
117 , m_extensionsUtil(extensionsUtil) | |
112 , m_size(-1, -1) | 118 , m_size(-1, -1) |
113 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 119 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
114 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) | 120 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) |
115 , m_fbo(0) | 121 , m_fbo(0) |
116 , m_colorBuffer(0) | 122 , m_colorBuffer(0) |
117 , m_frontColorBuffer(0) | 123 , m_frontColorBuffer(0) |
118 , m_depthStencilBuffer(0) | 124 , m_depthStencilBuffer(0) |
119 , m_depthBuffer(0) | 125 , m_depthBuffer(0) |
120 , m_stencilBuffer(0) | 126 , m_stencilBuffer(0) |
121 , m_multisampleFBO(0) | 127 , m_multisampleFBO(0) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); | 280 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |
275 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); | 281 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
276 returnMailbox->textureId = textureId; | 282 returnMailbox->textureId = textureId; |
277 returnMailbox->size = m_size; | 283 returnMailbox->size = m_size; |
278 m_textureMailboxes.append(returnMailbox); | 284 m_textureMailboxes.append(returnMailbox); |
279 return returnMailbox.release(); | 285 return returnMailbox.release(); |
280 } | 286 } |
281 | 287 |
282 bool DrawingBuffer::initialize(const IntSize& size) | 288 bool DrawingBuffer::initialize(const IntSize& size) |
283 { | 289 { |
290 if (!m_context->makeContextCurrent()) { | |
291 // The new context is lost; it wasn't allocated successfully. | |
292 // Need to try to restore the context again later. | |
293 return false; | |
294 } | |
295 | |
284 m_attributes = m_context->getContextAttributes(); | 296 m_attributes = m_context->getContextAttributes(); |
285 Extensions3DUtil extensionsUtil(m_context.get()); | |
286 | 297 |
287 if (m_attributes.alpha) { | 298 if (m_attributes.alpha) { |
288 m_internalColorFormat = GL_RGBA; | 299 m_internalColorFormat = GL_RGBA; |
289 m_colorFormat = GL_RGBA; | 300 m_colorFormat = GL_RGBA; |
290 m_internalRenderbufferFormat = GL_RGBA8_OES; | 301 m_internalRenderbufferFormat = GL_RGBA8_OES; |
291 } else { | 302 } else { |
292 m_internalColorFormat = GL_RGB; | 303 m_internalColorFormat = GL_RGB; |
293 m_colorFormat = GL_RGB; | 304 m_colorFormat = GL_RGB; |
294 m_internalRenderbufferFormat = GL_RGB8_OES; | 305 m_internalRenderbufferFormat = GL_RGB8_OES; |
295 } | 306 } |
296 | 307 |
297 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 308 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); |
298 | 309 |
299 int maxSampleCount = 0; | 310 int maxSampleCount = 0; |
300 m_multisampleMode = None; | 311 m_multisampleMode = None; |
301 if (m_attributes.antialias && m_multisampleExtensionSupported) { | 312 if (m_attributes.antialias && m_multisampleExtensionSupported) { |
302 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 313 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
303 m_multisampleMode = ExplicitResolve; | 314 m_multisampleMode = ExplicitResolve; |
304 if (extensionsUtil.supportsExtension("GL_EXT_multisampled_render_to_text ure")) | 315 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) |
305 m_multisampleMode = ImplicitResolve; | 316 m_multisampleMode = ImplicitResolve; |
306 } | 317 } |
307 m_sampleCount = std::min(4, maxSampleCount); | 318 m_sampleCount = std::min(4, maxSampleCount); |
308 | 319 |
309 m_fbo = m_context->createFramebuffer(); | 320 m_fbo = m_context->createFramebuffer(); |
310 | 321 |
311 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 322 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
312 m_colorBuffer = createColorTexture(); | 323 m_colorBuffer = createColorTexture(); |
313 if (m_multisampleMode == ImplicitResolve) | 324 if (m_multisampleMode == ImplicitResolve) |
314 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); | 325 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
929 } | 940 } |
930 } | 941 } |
931 | 942 |
932 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment) | 943 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment) |
933 { | 944 { |
934 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8); | 945 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8); |
935 m_context->texImage2D(target, level, internalformat, width, height, border, format, type, 0); | 946 m_context->texImage2D(target, level, internalformat, width, height, border, format, type, 0); |
936 } | 947 } |
937 | 948 |
938 } // namespace WebCore | 949 } // namespace WebCore |
OLD | NEW |