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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 126 } |
127 | 127 |
128 is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; | 128 is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
129 | 129 |
130 // This implementation always renders offscreen regardless of | 130 // This implementation always renders offscreen regardless of |
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 gl_surface_.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); |
137 gfx::Size(1, 1))); | |
138 if (!surface->Initialize()) | |
139 return false; | |
140 | 137 |
141 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), | 138 if (!gl_surface_.get()) { |
142 share_context)); | 139 if (!is_gles2_) |
| 140 return false; |
| 141 |
| 142 // Embedded systems have smaller limit on number of GL contexts. Sometimes |
| 143 // failure of GL context creation is because of existing GL contexts |
| 144 // referenced by JavaScript garbages. Collect garbage and try again. |
| 145 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving |
| 146 // a page unload event, iterate down any live WebGraphicsContext3D instances |
| 147 // and force them to drop their contexts, sending a context lost event if |
| 148 // necessary. |
| 149 webView->mainFrame()->collectGarbage(); |
| 150 |
| 151 gl_surface_.reset(gfx::GLSurface::CreateOffscreenGLSurface( |
| 152 gfx::Size(1, 1))); |
| 153 if (!gl_surface_.get()) |
| 154 return false; |
| 155 } |
| 156 |
| 157 gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, |
| 158 gl_surface_.get())); |
143 if (!gl_context_.get()) { | 159 if (!gl_context_.get()) { |
144 if (!is_gles2_) | 160 if (!is_gles2_) |
145 return false; | 161 return false; |
146 | 162 |
147 // Embedded systems have smaller limit on number of GL contexts. Sometimes | 163 // Embedded systems have smaller limit on number of GL contexts. Sometimes |
148 // failure of GL context creation is because of existing GL contexts | 164 // failure of GL context creation is because of existing GL contexts |
149 // referenced by JavaScript garbages. Collect garbage and try again. | 165 // referenced by JavaScript garbages. Collect garbage and try again. |
150 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving | 166 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving |
151 // a page unload event, iterate down any live WebGraphicsContext3D instances | 167 // a page unload event, iterate down any live WebGraphicsContext3D instances |
152 // and force them to drop their contexts, sending a context lost event if | 168 // and force them to drop their contexts, sending a context lost event if |
153 // necessary. | 169 // necessary. |
154 webView->mainFrame()->collectGarbage(); | 170 webView->mainFrame()->collectGarbage(); |
155 | 171 |
156 surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); | 172 gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, |
157 | 173 gl_surface_.get())); |
158 gl_context_.reset(gfx::GLContext::CreateGLContext( | |
159 surface.release(), | |
160 share_context)); | |
161 if (!gl_context_.get()) | 174 if (!gl_context_.get()) |
162 return false; | 175 return false; |
163 } | 176 } |
164 | 177 |
165 attributes_ = attributes; | 178 attributes_ = attributes; |
166 | 179 |
167 // FIXME: for the moment we disable multisampling for the compositor. | 180 // FIXME: for the moment we disable multisampling for the compositor. |
168 // It actually works in this implementation, but there are a few | 181 // It actually works in this implementation, but there are a few |
169 // considerations. First, we likely want to reduce the fuzziness in | 182 // considerations. First, we likely want to reduce the fuzziness in |
170 // these tests as much as possible because we want to run pixel tests. | 183 // these tests as much as possible because we want to run pixel tests. |
171 // Second, Mesa's multisampling doesn't seem to antialias straight | 184 // Second, Mesa's multisampling doesn't seem to antialias straight |
172 // edges in some CSS 3D samples. Third, we don't have multisampling | 185 // 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 | 186 // support for the compositor in the normal case at the time of this |
174 // writing. | 187 // writing. |
175 if (render_directly_to_web_view) | 188 if (render_directly_to_web_view) |
176 attributes_.antialias = false; | 189 attributes_.antialias = false; |
177 | 190 |
178 if (!gl_context_->MakeCurrent()) { | 191 if (!gl_context_->MakeCurrent(gl_surface_.get())) { |
179 gl_context_.reset(); | 192 gl_context_.reset(); |
180 return false; | 193 return false; |
181 } | 194 } |
182 | 195 |
183 const char* extensions = | 196 const char* extensions = |
184 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); | 197 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
185 DCHECK(extensions); | 198 DCHECK(extensions); |
186 have_ext_framebuffer_object_ = | 199 have_ext_framebuffer_object_ = |
187 strstr(extensions, "GL_EXT_framebuffer_object") != NULL; | 200 strstr(extensions, "GL_EXT_framebuffer_object") != NULL; |
188 have_ext_framebuffer_multisample_ = | 201 have_ext_framebuffer_multisample_ = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 x + width, y + height, | 276 x + width, y + height, |
264 x, y, | 277 x, y, |
265 x + width, y + height, | 278 x + width, y + height, |
266 GL_COLOR_BUFFER_BIT, GL_NEAREST); | 279 GL_COLOR_BUFFER_BIT, GL_NEAREST); |
267 } | 280 } |
268 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); | 281 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); |
269 } | 282 } |
270 } | 283 } |
271 | 284 |
272 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { | 285 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { |
273 return gl_context_->MakeCurrent(); | 286 return gl_context_->MakeCurrent(gl_surface_.get()); |
274 } | 287 } |
275 | 288 |
276 int WebGraphicsContext3DInProcessCommandBufferImpl::width() { | 289 int WebGraphicsContext3DInProcessCommandBufferImpl::width() { |
277 return cached_width_; | 290 return cached_width_; |
278 } | 291 } |
279 | 292 |
280 int WebGraphicsContext3DInProcessCommandBufferImpl::height() { | 293 int WebGraphicsContext3DInProcessCommandBufferImpl::height() { |
281 return cached_height_; | 294 return cached_height_; |
282 } | 295 } |
283 | 296 |
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 else | 1653 else |
1641 ShGetObjectCode(compiler, entry->translated_source.get()); | 1654 ShGetObjectCode(compiler, entry->translated_source.get()); |
1642 } | 1655 } |
1643 entry->is_valid = true; | 1656 entry->is_valid = true; |
1644 return true; | 1657 return true; |
1645 } | 1658 } |
1646 | 1659 |
1647 } // namespace gpu | 1660 } // namespace gpu |
1648 } // namespace webkit | 1661 } // namespace webkit |
1649 | 1662 |
OLD | NEW |