Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc

Issue 7669072: Use 3D graphics context shareResources flag to decide whether a context should share resources. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #if defined(ENABLE_GPU) 5 #if defined(ENABLE_GPU)
6 6
7 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" 7 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
8 8
9 #include "gpu/GLES2/gl2.h" 9 #include "gpu/GLES2/gl2.h"
10 #ifndef GL_GLEXT_PROTOTYPES 10 #ifndef GL_GLEXT_PROTOTYPES
(...skipping 15 matching lines...) Expand all
26 #include "content/renderer/render_thread.h" 26 #include "content/renderer/render_thread.h"
27 #include "content/renderer/render_view.h" 27 #include "content/renderer/render_view.h"
28 #include "gpu/command_buffer/client/gles2_implementation.h" 28 #include "gpu/command_buffer/client/gles2_implementation.h"
29 #include "gpu/command_buffer/common/constants.h" 29 #include "gpu/command_buffer/common/constants.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
33 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" 33 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h"
34 34
35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > 35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> >
36 g_all_contexts(base::LINKER_INITIALIZED); 36 g_all_shared_contexts(base::LINKER_INITIALIZED);
37 37
38 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() 38 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
39 : context_(NULL), 39 : context_(NULL),
40 gl_(NULL), 40 gl_(NULL),
41 web_view_(NULL), 41 web_view_(NULL),
42 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
43 plugin_handle_(NULL), 43 plugin_handle_(NULL),
44 #endif // defined(OS_MACOSX) 44 #endif // defined(OS_MACOSX)
45 context_lost_callback_(0), 45 context_lost_callback_(0),
46 context_lost_reason_(GL_NO_ERROR), 46 context_lost_reason_(GL_NO_ERROR),
47 swapbuffers_complete_callback_(0), 47 swapbuffers_complete_callback_(0),
48 cached_width_(0), 48 cached_width_(0),
49 cached_height_(0), 49 cached_height_(0),
50 bound_fbo_(0) { 50 bound_fbo_(0) {
51 } 51 }
52 52
53 WebGraphicsContext3DCommandBufferImpl:: 53 WebGraphicsContext3DCommandBufferImpl::
54 ~WebGraphicsContext3DCommandBufferImpl() { 54 ~WebGraphicsContext3DCommandBufferImpl() {
55 g_all_contexts.Pointer()->erase(this); 55 g_all_shared_contexts.Pointer()->erase(this);
56 delete context_; 56 delete context_;
57 } 57 }
58 58
59 // This string should only be passed for WebGL contexts. Nothing ELSE!!! 59 // This string should only be passed for WebGL contexts. Nothing ELSE!!!
60 // Compositor contexts, Canvas2D contexts, Pepper Contexts, nor any other use of 60 // Compositor contexts, Canvas2D contexts, Pepper Contexts, nor any other use of
61 // a context should not pass this string. 61 // a context should not pass this string.
62 static const char* kWebGLPreferredGLExtensions = 62 static const char* kWebGLPreferredGLExtensions =
63 "GL_OES_packed_depth_stencil " 63 "GL_OES_packed_depth_stencil "
64 "GL_OES_depth24 " 64 "GL_OES_depth24 "
65 "GL_CHROMIUM_webglsl"; 65 "GL_CHROMIUM_webglsl";
(...skipping 20 matching lines...) Expand all
86 const int depth_size = attributes.depth ? 24 : 0; 86 const int depth_size = attributes.depth ? 24 : 0;
87 const int stencil_size = attributes.stencil ? 8 : 0; 87 const int stencil_size = attributes.stencil ? 8 : 0;
88 const int samples = attributes.antialias ? 4 : 0; 88 const int samples = attributes.antialias ? 4 : 0;
89 const int sample_buffers = attributes.antialias ? 1 : 0; 89 const int sample_buffers = attributes.antialias ? 1 : 0;
90 const int32 attribs[] = { 90 const int32 attribs[] = {
91 RendererGLContext::ALPHA_SIZE, alpha_size, 91 RendererGLContext::ALPHA_SIZE, alpha_size,
92 RendererGLContext::DEPTH_SIZE, depth_size, 92 RendererGLContext::DEPTH_SIZE, depth_size,
93 RendererGLContext::STENCIL_SIZE, stencil_size, 93 RendererGLContext::STENCIL_SIZE, stencil_size,
94 RendererGLContext::SAMPLES, samples, 94 RendererGLContext::SAMPLES, samples,
95 RendererGLContext::SAMPLE_BUFFERS, sample_buffers, 95 RendererGLContext::SAMPLE_BUFFERS, sample_buffers,
96 RendererGLContext::SHARE_RESOURCES, attributes.shareResources ? 1 : 0,
97 RendererGLContext::BIND_GENERATES_RESOURCES, 0,
96 RendererGLContext::NONE, 98 RendererGLContext::NONE,
97 }; 99 };
98 100
99 const char* preferred_extensions = attributes.noExtensions ? 101 const char* preferred_extensions = attributes.noExtensions ?
100 kWebGLPreferredGLExtensions : "*"; 102 kWebGLPreferredGLExtensions : "*";
101 103
102 const GPUInfo& gpu_info = host->gpu_info(); 104 const GPUInfo& gpu_info = host->gpu_info();
103 UMA_HISTOGRAM_ENUMERATION( 105 UMA_HISTOGRAM_ENUMERATION(
104 "GPU.WebGraphicsContext3D_Init_CanLoseContext", 106 "GPU.WebGraphicsContext3D_Init_CanLoseContext",
105 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, 107 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context,
106 4); 108 4);
107 if (attributes.canRecoverFromContextLoss == false) { 109 if (attributes.canRecoverFromContextLoss == false) {
108 if (gpu_info.can_lose_context) 110 if (gpu_info.can_lose_context)
109 return false; 111 return false;
110 } 112 }
111 113
112 GURL active_url; 114 GURL active_url;
113 if (web_view && web_view->mainFrame()) 115 if (web_view && web_view->mainFrame())
114 active_url = GURL(web_view->mainFrame()->document().url()); 116 active_url = GURL(web_view->mainFrame()->document().url());
115 117
116 // HACK: Assume this is a WebGL context by looking for the noExtensions
117 // attribute. WebGL contexts must not go in the share group because they
118 // rely on destruction of the context to clean up owned resources. Putting
119 // them in a share group would prevent this from happening.
120 RendererGLContext* share_group = NULL; 118 RendererGLContext* share_group = NULL;
121 if (!attributes.noExtensions) { 119 if (attributes.shareResources) {
122 share_group = g_all_contexts.Pointer()->empty() ? 120 share_group = g_all_shared_contexts.Pointer()->empty() ?
123 NULL : (*g_all_contexts.Pointer()->begin())->context_; 121 NULL : (*g_all_shared_contexts.Pointer()->begin())->context_;
124 } 122 }
125 123
126 if (render_directly_to_web_view) { 124 if (render_directly_to_web_view) {
127 RenderView* renderview = RenderView::FromWebView(web_view); 125 RenderView* renderview = RenderView::FromWebView(web_view);
128 if (!renderview) 126 if (!renderview)
129 return false; 127 return false;
130 128
131 web_view_ = web_view; 129 web_view_ = web_view;
132 context_ = RendererGLContext::CreateViewContext( 130 context_ = RendererGLContext::CreateViewContext(
133 host, 131 host,
134 renderview->routing_id(), 132 renderview->routing_id(),
135 !attributes.noExtensions,
136 share_group, 133 share_group,
137 preferred_extensions, 134 preferred_extensions,
138 attribs, 135 attribs,
139 active_url); 136 active_url);
140 if (context_) { 137 if (context_) {
141 context_->SetSwapBuffersCallback( 138 context_->SetSwapBuffersCallback(
142 NewCallback(this, 139 NewCallback(this,
143 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); 140 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete));
144 } 141 }
145 } else { 142 } else {
146 context_ = RendererGLContext::CreateOffscreenContext( 143 context_ = RendererGLContext::CreateOffscreenContext(
147 host, 144 host,
148 gfx::Size(1, 1), 145 gfx::Size(1, 1),
149 !attributes.noExtensions,
150 share_group, 146 share_group,
151 preferred_extensions, 147 preferred_extensions,
152 attribs, 148 attribs,
153 active_url); 149 active_url);
154 web_view_ = NULL; 150 web_view_ = NULL;
155 } 151 }
156 if (!context_) 152 if (!context_)
157 return false; 153 return false;
158 154
159 gl_ = context_->GetImplementation(); 155 gl_ = context_->GetImplementation();
(...skipping 17 matching lines...) Expand all
177 getIntegerv(GL_DEPTH_BITS, &depth_bits); 173 getIntegerv(GL_DEPTH_BITS, &depth_bits);
178 attributes_.depth = depth_bits > 0; 174 attributes_.depth = depth_bits > 0;
179 GLint stencil_bits = 0; 175 GLint stencil_bits = 0;
180 getIntegerv(GL_STENCIL_BITS, &stencil_bits); 176 getIntegerv(GL_STENCIL_BITS, &stencil_bits);
181 attributes_.stencil = stencil_bits > 0; 177 attributes_.stencil = stencil_bits > 0;
182 GLint samples = 0; 178 GLint samples = 0;
183 getIntegerv(GL_SAMPLES, &samples); 179 getIntegerv(GL_SAMPLES, &samples);
184 attributes_.antialias = samples > 0; 180 attributes_.antialias = samples > 0;
185 } 181 }
186 182
187 if (!attributes.noExtensions) 183 if (attributes.shareResources)
188 g_all_contexts.Pointer()->insert(this); 184 g_all_shared_contexts.Pointer()->insert(this);
189 185
190 return true; 186 return true;
191 } 187 }
192 188
193 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { 189 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
194 return RendererGLContext::MakeCurrent(context_); 190 return RendererGLContext::MakeCurrent(context_);
195 } 191 }
196 192
197 int WebGraphicsContext3DCommandBufferImpl::width() { 193 int WebGraphicsContext3DCommandBufferImpl::width() {
198 return cached_width_; 194 return cached_width_;
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 context_lost_callback_->onContextLost(); 1054 context_lost_callback_->onContextLost();
1059 } 1055 }
1060 1056
1061 RenderView* renderview = 1057 RenderView* renderview =
1062 web_view_ ? RenderView::FromWebView(web_view_) : NULL; 1058 web_view_ ? RenderView::FromWebView(web_view_) : NULL;
1063 if (renderview) 1059 if (renderview)
1064 renderview->OnViewContextSwapBuffersAborted(); 1060 renderview->OnViewContextSwapBuffersAborted();
1065 } 1061 }
1066 1062
1067 #endif // defined(ENABLE_GPU) 1063 #endif // defined(ENABLE_GPU)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698