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_impl.h" | 5 #include "webkit/gpu/webgraphicscontext3d_in_process_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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 glDeleteTextures(1, &texture_); | 84 glDeleteTextures(1, &texture_); |
85 glDeleteFramebuffersEXT(1, ©_texture_to_parent_texture_fbo_); | 85 glDeleteFramebuffersEXT(1, ©_texture_to_parent_texture_fbo_); |
86 #ifdef FLIP_FRAMEBUFFER_VERTICALLY | 86 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
87 if (scanline_) | 87 if (scanline_) |
88 delete[] scanline_; | 88 delete[] scanline_; |
89 #endif | 89 #endif |
90 glDeleteFramebuffersEXT(1, &fbo_); | 90 glDeleteFramebuffersEXT(1, &fbo_); |
91 | 91 |
92 gl_context_->Destroy(); | 92 gl_context_->Destroy(); |
| 93 gl_surface_->Destroy(); |
93 | 94 |
94 for (ShaderSourceMap::iterator ii = shader_source_map_.begin(); | 95 for (ShaderSourceMap::iterator ii = shader_source_map_.begin(); |
95 ii != shader_source_map_.end(); ++ii) { | 96 ii != shader_source_map_.end(); ++ii) { |
96 if (ii->second) | 97 if (ii->second) |
97 delete ii->second; | 98 delete ii->second; |
98 } | 99 } |
99 AngleDestroyCompilers(); | 100 AngleDestroyCompilers(); |
100 } | 101 } |
101 | 102 |
102 bool WebGraphicsContext3DInProcessImpl::initialize( | 103 bool WebGraphicsContext3DInProcessImpl::initialize( |
(...skipping 23 matching lines...) Expand all Loading... |
126 } | 127 } |
127 | 128 |
128 is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; | 129 is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
129 | 130 |
130 // This implementation always renders offscreen regardless of | 131 // This implementation always renders offscreen regardless of |
131 // whether render_directly_to_web_view is true. Both DumpRenderTree | 132 // whether render_directly_to_web_view is true. Both DumpRenderTree |
132 // and test_shell paint first to an intermediate offscreen buffer | 133 // and test_shell paint first to an intermediate offscreen buffer |
133 // and from there to the window, and WebViewImpl::paint already | 134 // and from there to the window, and WebViewImpl::paint already |
134 // correctly handles the case where the compositor is active but | 135 // correctly handles the case where the compositor is active but |
135 // the output needs to go to a WebCanvas. | 136 // the output needs to go to a WebCanvas. |
136 scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface( | 137 gl_surface_.reset(gfx::GLSurface::CreateOffscreenGLSurface( |
137 gfx::Size(1, 1))); | 138 gfx::Size(1, 1))); |
138 if (!surface.get()) { | 139 if (!gl_surface_.get()) { |
139 if (!is_gles2_) | 140 if (!is_gles2_) |
140 return false; | 141 return false; |
141 | 142 |
142 // Embedded systems have smaller limit on number of GL contexts. Sometimes | 143 // Embedded systems have smaller limit on number of GL contexts. Sometimes |
143 // failure of GL context creation is because of existing GL contexts | 144 // failure of GL context creation is because of existing GL contexts |
144 // referenced by JavaScript garbages. Collect garbage and try again. | 145 // referenced by JavaScript garbages. Collect garbage and try again. |
145 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving | 146 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving |
146 // a page unload event, iterate down any live WebGraphicsContext3D instances | 147 // 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 // and force them to drop their contexts, sending a context lost event if |
148 // necessary. | 149 // necessary. |
149 webView->mainFrame()->collectGarbage(); | 150 webView->mainFrame()->collectGarbage(); |
150 surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); | 151 |
151 if (!surface.get()) | 152 gl_surface_.reset( |
| 153 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); |
| 154 if (!gl_surface_.get()) |
152 return false; | 155 return false; |
153 } | 156 } |
154 | 157 |
155 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), | 158 gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, |
156 share_context)); | 159 gl_surface_.get())); |
157 if (!gl_context_.get()) | 160 if (!gl_context_.get()) { |
158 return false; | 161 if (!is_gles2_) |
| 162 return false; |
| 163 |
| 164 // Embedded systems have smaller limit on number of GL contexts. Sometimes |
| 165 // failure of GL context creation is because of existing GL contexts |
| 166 // referenced by JavaScript garbages. Collect garbage and try again. |
| 167 // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving |
| 168 // a page unload event, iterate down any live WebGraphicsContext3D instances |
| 169 // and force them to drop their contexts, sending a context lost event if |
| 170 // necessary. |
| 171 webView->mainFrame()->collectGarbage(); |
| 172 |
| 173 gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, |
| 174 gl_surface_.get())); |
| 175 if (!gl_context_.get()) |
| 176 return false; |
| 177 } |
159 | 178 |
160 attributes_ = attributes; | 179 attributes_ = attributes; |
161 | 180 |
162 // FIXME: for the moment we disable multisampling for the compositor. | 181 // FIXME: for the moment we disable multisampling for the compositor. |
163 // It actually works in this implementation, but there are a few | 182 // It actually works in this implementation, but there are a few |
164 // considerations. First, we likely want to reduce the fuzziness in | 183 // considerations. First, we likely want to reduce the fuzziness in |
165 // these tests as much as possible because we want to run pixel tests. | 184 // these tests as much as possible because we want to run pixel tests. |
166 // Second, Mesa's multisampling doesn't seem to antialias straight | 185 // Second, Mesa's multisampling doesn't seem to antialias straight |
167 // edges in some CSS 3D samples. Third, we don't have multisampling | 186 // edges in some CSS 3D samples. Third, we don't have multisampling |
168 // support for the compositor in the normal case at the time of this | 187 // support for the compositor in the normal case at the time of this |
169 // writing. | 188 // writing. |
170 if (render_directly_to_web_view) | 189 if (render_directly_to_web_view) |
171 attributes_.antialias = false; | 190 attributes_.antialias = false; |
172 | 191 |
173 if (!gl_context_->MakeCurrent()) { | 192 if (!gl_context_->MakeCurrent(gl_surface_.get())) { |
174 gl_context_.reset(); | 193 gl_context_.reset(); |
175 return false; | 194 return false; |
176 } | 195 } |
177 | 196 |
178 const char* extensions = | 197 const char* extensions = |
179 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); | 198 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
180 DCHECK(extensions); | 199 DCHECK(extensions); |
181 have_ext_framebuffer_object_ = | 200 have_ext_framebuffer_object_ = |
182 strstr(extensions, "GL_EXT_framebuffer_object") != NULL; | 201 strstr(extensions, "GL_EXT_framebuffer_object") != NULL; |
183 have_ext_framebuffer_multisample_ = | 202 have_ext_framebuffer_multisample_ = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 x + width, y + height, | 277 x + width, y + height, |
259 x, y, | 278 x, y, |
260 x + width, y + height, | 279 x + width, y + height, |
261 GL_COLOR_BUFFER_BIT, GL_NEAREST); | 280 GL_COLOR_BUFFER_BIT, GL_NEAREST); |
262 } | 281 } |
263 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); | 282 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); |
264 } | 283 } |
265 } | 284 } |
266 | 285 |
267 bool WebGraphicsContext3DInProcessImpl::makeContextCurrent() { | 286 bool WebGraphicsContext3DInProcessImpl::makeContextCurrent() { |
268 return gl_context_->MakeCurrent(); | 287 return gl_context_->MakeCurrent(gl_surface_.get()); |
269 } | 288 } |
270 | 289 |
271 int WebGraphicsContext3DInProcessImpl::width() { | 290 int WebGraphicsContext3DInProcessImpl::width() { |
272 return cached_width_; | 291 return cached_width_; |
273 } | 292 } |
274 | 293 |
275 int WebGraphicsContext3DInProcessImpl::height() { | 294 int WebGraphicsContext3DInProcessImpl::height() { |
276 return cached_height_; | 295 return cached_height_; |
277 } | 296 } |
278 | 297 |
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 strncpy(entry->translated_source.get(), entry->source.get(), length); | 1653 strncpy(entry->translated_source.get(), entry->source.get(), length); |
1635 else | 1654 else |
1636 ShGetObjectCode(compiler, entry->translated_source.get()); | 1655 ShGetObjectCode(compiler, entry->translated_source.get()); |
1637 } | 1656 } |
1638 entry->is_valid = true; | 1657 entry->is_valid = true; |
1639 return true; | 1658 return true; |
1640 } | 1659 } |
1641 | 1660 |
1642 } // namespace gpu | 1661 } // namespace gpu |
1643 } // namespace webkit | 1662 } // namespace webkit |
OLD | NEW |