| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // whether render_directly_to_web_view is true. Both DumpRenderTree | 131 // whether render_directly_to_web_view is true. Both DumpRenderTree |
| 132 // and test_shell paint first to an intermediate offscreen buffer | 132 // and test_shell paint first to an intermediate offscreen buffer |
| 133 // and from there to the window, and WebViewImpl::paint already | 133 // and from there to the window, and WebViewImpl::paint already |
| 134 // correctly handles the case where the compositor is active but | 134 // correctly handles the case where the compositor is active but |
| 135 // the output needs to go to a WebCanvas. | 135 // the output needs to go to a WebCanvas. |
| 136 scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface( | 136 scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface( |
| 137 gfx::Size(1, 1))); | 137 gfx::Size(1, 1))); |
| 138 if (!surface->Initialize()) | 138 if (!surface->Initialize()) |
| 139 return false; | 139 return false; |
| 140 | 140 |
| 141 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), | 141 gl_context_.reset(gfx::GLContext::CreateGLContext(share_context)); |
| 142 share_context)); | |
| 143 if (!gl_context_.get()) { | 142 if (!gl_context_.get()) { |
| 144 if (!is_gles2_) | 143 if (!is_gles2_) |
| 145 return false; | 144 return false; |
| 146 | 145 |
| 147 // Embedded systems have smaller limit on number of GL contexts. Sometimes | 146 // Embedded systems have smaller limit on number of GL contexts. Sometimes |
| 148 // failure of GL context creation is because of existing GL contexts | 147 // failure of GL context creation is because of existing GL contexts |
| 149 // referenced by JavaScript garbages. Collect garbage and try again. | 148 // referenced by JavaScript garbages. Collect garbage and try again. |
| 150 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving | 149 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving |
| 151 // a page unload event, iterate down any live WebGraphicsContext3D instances | 150 // a page unload event, iterate down any live WebGraphicsContext3D instances |
| 152 // and force them to drop their contexts, sending a context lost event if | 151 // and force them to drop their contexts, sending a context lost event if |
| 153 // necessary. | 152 // necessary. |
| 154 webView->mainFrame()->collectGarbage(); | 153 webView->mainFrame()->collectGarbage(); |
| 155 | 154 |
| 156 surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); | 155 surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); |
| 157 | 156 |
| 158 gl_context_.reset(gfx::GLContext::CreateGLContext( | 157 gl_context_.reset(gfx::GLContext::CreateGLContext(share_context)); |
| 159 surface.release(), | |
| 160 share_context)); | |
| 161 if (!gl_context_.get()) | 158 if (!gl_context_.get()) |
| 162 return false; | 159 return false; |
| 163 } | 160 } |
| 164 | 161 |
| 165 attributes_ = attributes; | 162 attributes_ = attributes; |
| 166 | 163 |
| 167 // FIXME: for the moment we disable multisampling for the compositor. | 164 // FIXME: for the moment we disable multisampling for the compositor. |
| 168 // It actually works in this implementation, but there are a few | 165 // It actually works in this implementation, but there are a few |
| 169 // considerations. First, we likely want to reduce the fuzziness in | 166 // considerations. First, we likely want to reduce the fuzziness in |
| 170 // these tests as much as possible because we want to run pixel tests. | 167 // these tests as much as possible because we want to run pixel tests. |
| 171 // Second, Mesa's multisampling doesn't seem to antialias straight | 168 // Second, Mesa's multisampling doesn't seem to antialias straight |
| 172 // edges in some CSS 3D samples. Third, we don't have multisampling | 169 // edges in some CSS 3D samples. Third, we don't have multisampling |
| 173 // support for the compositor in the normal case at the time of this | 170 // support for the compositor in the normal case at the time of this |
| 174 // writing. | 171 // writing. |
| 175 if (render_directly_to_web_view) | 172 if (render_directly_to_web_view) |
| 176 attributes_.antialias = false; | 173 attributes_.antialias = false; |
| 177 | 174 |
| 178 if (!gl_context_->MakeCurrent()) { | 175 if (!gl_context_->MakeCurrent(gl_surface_.get())) { |
| 179 gl_context_.reset(); | 176 gl_context_.reset(); |
| 180 return false; | 177 return false; |
| 181 } | 178 } |
| 182 | 179 |
| 183 const char* extensions = | 180 const char* extensions = |
| 184 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); | 181 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 185 DCHECK(extensions); | 182 DCHECK(extensions); |
| 186 have_ext_framebuffer_object_ = | 183 have_ext_framebuffer_object_ = |
| 187 strstr(extensions, "GL_EXT_framebuffer_object") != NULL; | 184 strstr(extensions, "GL_EXT_framebuffer_object") != NULL; |
| 188 have_ext_framebuffer_multisample_ = | 185 have_ext_framebuffer_multisample_ = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 x + width, y + height, | 260 x + width, y + height, |
| 264 x, y, | 261 x, y, |
| 265 x + width, y + height, | 262 x + width, y + height, |
| 266 GL_COLOR_BUFFER_BIT, GL_NEAREST); | 263 GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 267 } | 264 } |
| 268 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); | 265 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); |
| 269 } | 266 } |
| 270 } | 267 } |
| 271 | 268 |
| 272 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { | 269 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { |
| 273 return gl_context_->MakeCurrent(); | 270 return gl_context_->MakeCurrent(gl_surface_.get()); |
| 274 } | 271 } |
| 275 | 272 |
| 276 int WebGraphicsContext3DInProcessCommandBufferImpl::width() { | 273 int WebGraphicsContext3DInProcessCommandBufferImpl::width() { |
| 277 return cached_width_; | 274 return cached_width_; |
| 278 } | 275 } |
| 279 | 276 |
| 280 int WebGraphicsContext3DInProcessCommandBufferImpl::height() { | 277 int WebGraphicsContext3DInProcessCommandBufferImpl::height() { |
| 281 return cached_height_; | 278 return cached_height_; |
| 282 } | 279 } |
| 283 | 280 |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 else | 1637 else |
| 1641 ShGetObjectCode(compiler, entry->translated_source.get()); | 1638 ShGetObjectCode(compiler, entry->translated_source.get()); |
| 1642 } | 1639 } |
| 1643 entry->is_valid = true; | 1640 entry->is_valid = true; |
| 1644 return true; | 1641 return true; |
| 1645 } | 1642 } |
| 1646 | 1643 |
| 1647 } // namespace gpu | 1644 } // namespace gpu |
| 1648 } // namespace webkit | 1645 } // namespace webkit |
| 1649 | 1646 |
| OLD | NEW |