OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h" | 7 #include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h" |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #ifndef GL_GLEXT_PROTOTYPES | 10 #ifndef GL_GLEXT_PROTOTYPES |
11 #define GL_GLEXT_PROTOTYPES 1 | 11 #define GL_GLEXT_PROTOTYPES 1 |
12 #endif | 12 #endif |
13 #include <GLES2/gl2ext.h> | 13 #include <GLES2/gl2ext.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/renderer/gpu_channel_host.h" | 22 #include "chrome/renderer/gpu_channel_host.h" |
23 #include "chrome/renderer/render_thread.h" | 23 #include "chrome/renderer/render_thread.h" |
24 #include "chrome/renderer/render_view.h" | 24 #include "chrome/renderer/render_view.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
26 | 26 |
27 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() | 27 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() |
28 : context_(NULL), | 28 : context_(NULL), |
29 web_view_(NULL), | 29 web_view_(NULL), |
30 #if defined(OS_MACOSX) | |
31 plugin_handle_(NULL), | |
32 #endif // defined(OS_MACOSX) | |
33 cached_width_(0), | 30 cached_width_(0), |
34 cached_height_(0), | 31 cached_height_(0), |
35 bound_fbo_(0) { | 32 bound_fbo_(0) { |
36 } | 33 } |
37 | 34 |
38 WebGraphicsContext3DCommandBufferImpl:: | 35 WebGraphicsContext3DCommandBufferImpl:: |
39 ~WebGraphicsContext3DCommandBufferImpl() { | 36 ~WebGraphicsContext3DCommandBufferImpl() { |
40 #if defined(OS_MACOSX) | |
41 if (web_view_) { | |
42 DCHECK(plugin_handle_ != gfx::kNullPluginWindow); | |
43 RenderView* renderview = RenderView::FromWebView(web_view_); | |
44 // The RenderView might already have been freed, but in its | |
45 // destructor it destroys all fake plugin window handles it | |
46 // allocated. | |
47 if (renderview) { | |
48 renderview->DestroyFakePluginWindowHandle(plugin_handle_); | |
49 } | |
50 plugin_handle_ = gfx::kNullPluginWindow; | |
51 } | |
52 #endif | |
53 if (context_) { | 37 if (context_) { |
54 ggl::DestroyContext(context_); | 38 ggl::DestroyContext(context_); |
55 } | 39 } |
56 } | 40 } |
57 | 41 |
58 static const char* kWebGraphicsContext3DPerferredGLExtensions = | 42 static const char* kWebGraphicsContext3DPerferredGLExtensions = |
59 "GL_OES_packed_depth_stencil " | 43 "GL_OES_packed_depth_stencil " |
60 "GL_OES_depth24 " | 44 "GL_OES_depth24 " |
61 "GL_CHROMIUM_webglsl"; | 45 "GL_CHROMIUM_webglsl"; |
62 | 46 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 4); | 78 4); |
95 if (attributes.canRecoverFromContextLoss == false) { | 79 if (attributes.canRecoverFromContextLoss == false) { |
96 if (gpu_info.can_lose_context()) | 80 if (gpu_info.can_lose_context()) |
97 return false; | 81 return false; |
98 } | 82 } |
99 | 83 |
100 if (render_directly_to_web_view) { | 84 if (render_directly_to_web_view) { |
101 RenderView* renderview = RenderView::FromWebView(web_view); | 85 RenderView* renderview = RenderView::FromWebView(web_view); |
102 if (!renderview) | 86 if (!renderview) |
103 return false; | 87 return false; |
104 gfx::NativeViewId view_id; | 88 |
105 #if !defined(OS_MACOSX) | |
106 view_id = renderview->host_window(); | |
107 #else | |
108 plugin_handle_ = renderview->AllocateFakePluginWindowHandle( | |
109 /*opaque=*/true, /*root=*/true); | |
110 view_id = static_cast<gfx::NativeViewId>(plugin_handle_); | |
111 #endif | |
112 web_view_ = web_view; | 89 web_view_ = web_view; |
113 context_ = ggl::CreateViewContext( | 90 context_ = ggl::CreateViewContext( |
114 host, | 91 host, |
115 view_id, | |
116 renderview->routing_id(), | 92 renderview->routing_id(), |
117 kWebGraphicsContext3DPerferredGLExtensions, | 93 kWebGraphicsContext3DPerferredGLExtensions, |
118 attribs); | 94 attribs); |
119 if (context_) { | 95 if (context_) { |
120 ggl::SetSwapBuffersCallback( | 96 ggl::SetSwapBuffersCallback( |
121 context_, | 97 context_, |
122 NewCallback(this, | 98 NewCallback(this, |
123 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffers)); | 99 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffers)); |
124 } | 100 } |
125 } else { | 101 } else { |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 | 1029 |
1054 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffers() { | 1030 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffers() { |
1055 // This may be called after tear-down of the RenderView. | 1031 // This may be called after tear-down of the RenderView. |
1056 RenderView* renderview = | 1032 RenderView* renderview = |
1057 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 1033 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
1058 if (renderview) | 1034 if (renderview) |
1059 renderview->DidFlushPaint(); | 1035 renderview->DidFlushPaint(); |
1060 } | 1036 } |
1061 | 1037 |
1062 #endif // defined(ENABLE_GPU) | 1038 #endif // defined(ENABLE_GPU) |
OLD | NEW |