OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
6 | 6 |
7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
10 #endif | 10 #endif |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/metrics/field_trial.h" | 23 #include "base/metrics/field_trial.h" |
24 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
25 #include "base/profiler/scoped_tracker.h" | 25 #include "base/profiler/scoped_tracker.h" |
26 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
27 #include "gpu/GLES2/gl2extchromium.h" | 27 #include "gpu/GLES2/gl2extchromium.h" |
28 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 28 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
29 #include "gpu/command_buffer/client/gles2_implementation.h" | 29 #include "gpu/command_buffer/client/gles2_implementation.h" |
30 #include "gpu/command_buffer/client/gles2_trace_implementation.h" | 30 #include "gpu/command_buffer/client/gles2_trace_implementation.h" |
31 #include "gpu/command_buffer/client/gpu_switches.h" | 31 #include "gpu/command_buffer/client/gpu_switches.h" |
| 32 #include "gpu/command_buffer/client/shared_memory_limits.h" |
32 #include "gpu/command_buffer/client/transfer_buffer.h" | 33 #include "gpu/command_buffer/client/transfer_buffer.h" |
33 #include "gpu/command_buffer/common/constants.h" | 34 #include "gpu/command_buffer/common/constants.h" |
34 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 35 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
35 #include "gpu/command_buffer/common/mailbox.h" | 36 #include "gpu/command_buffer/common/mailbox.h" |
36 #include "gpu/ipc/client/gpu_channel_host.h" | 37 #include "gpu/ipc/client/gpu_channel_host.h" |
37 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 38 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
38 #include "third_party/skia/include/core/SkTypes.h" | 39 #include "third_party/skia/include/core/SkTypes.h" |
39 | 40 |
40 namespace content { | 41 namespace content { |
41 | 42 |
(...skipping 19 matching lines...) Expand all Loading... |
61 scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> group = | 62 scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> group = |
62 new WebGraphicsContext3DCommandBufferImpl::ShareGroup(); | 63 new WebGraphicsContext3DCommandBufferImpl::ShareGroup(); |
63 share_groups[host] = group; | 64 share_groups[host] = group; |
64 return group; | 65 return group; |
65 } | 66 } |
66 return it->second; | 67 return it->second; |
67 } | 68 } |
68 | 69 |
69 } // namespace anonymous | 70 } // namespace anonymous |
70 | 71 |
71 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits::SharedMemoryLimits() | |
72 : command_buffer_size(kDefaultCommandBufferSize), | |
73 start_transfer_buffer_size(kDefaultStartTransferBufferSize), | |
74 min_transfer_buffer_size(kDefaultMinTransferBufferSize), | |
75 max_transfer_buffer_size(kDefaultMaxTransferBufferSize), | |
76 mapped_memory_reclaim_limit(gpu::gles2::GLES2Implementation::kNoLimit) {} | |
77 | |
78 WebGraphicsContext3DCommandBufferImpl::ShareGroup::ShareGroup() { | 72 WebGraphicsContext3DCommandBufferImpl::ShareGroup::ShareGroup() { |
79 } | 73 } |
80 | 74 |
81 WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() { | 75 WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() { |
82 DCHECK(contexts_.empty()); | 76 DCHECK(contexts_.empty()); |
83 } | 77 } |
84 | 78 |
85 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | 79 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( |
86 gpu::SurfaceHandle surface_handle, | 80 gpu::SurfaceHandle surface_handle, |
87 const GURL& active_url, | 81 const GURL& active_url, |
88 gpu::GpuChannelHost* host, | 82 gpu::GpuChannelHost* host, |
89 const gpu::gles2::ContextCreationAttribHelper& attributes, | 83 const gpu::gles2::ContextCreationAttribHelper& attributes, |
90 gfx::GpuPreference gpu_preference, | 84 gfx::GpuPreference gpu_preference, |
91 bool share_resources, | 85 bool share_resources, |
92 bool automatic_flushes, | 86 bool automatic_flushes, |
93 const SharedMemoryLimits& limits, | |
94 WebGraphicsContext3DCommandBufferImpl* share_context) | 87 WebGraphicsContext3DCommandBufferImpl* share_context) |
95 : automatic_flushes_(automatic_flushes), | 88 : automatic_flushes_(automatic_flushes), |
96 attributes_(attributes), | 89 attributes_(attributes), |
97 host_(host), | 90 host_(host), |
98 surface_handle_(surface_handle), | 91 surface_handle_(surface_handle), |
99 active_url_(active_url), | 92 active_url_(active_url), |
100 gpu_preference_(gpu_preference), | 93 gpu_preference_(gpu_preference), |
101 mem_limits_(limits), | |
102 weak_ptr_factory_(this) { | 94 weak_ptr_factory_(this) { |
103 DCHECK(host); | 95 DCHECK(host); |
104 switch (attributes.context_type) { | 96 switch (attributes.context_type) { |
105 case gpu::gles2::CONTEXT_TYPE_OPENGLES2: | 97 case gpu::gles2::CONTEXT_TYPE_OPENGLES2: |
106 case gpu::gles2::CONTEXT_TYPE_OPENGLES3: | 98 case gpu::gles2::CONTEXT_TYPE_OPENGLES3: |
107 context_type_ = CONTEXT_TYPE_UNKNOWN; | 99 context_type_ = CONTEXT_TYPE_UNKNOWN; |
108 case gpu::gles2::CONTEXT_TYPE_WEBGL1: | 100 case gpu::gles2::CONTEXT_TYPE_WEBGL1: |
109 case gpu::gles2::CONTEXT_TYPE_WEBGL2: | 101 case gpu::gles2::CONTEXT_TYPE_WEBGL2: |
110 context_type_ = OFFSCREEN_CONTEXT_FOR_WEBGL; | 102 context_type_ = OFFSCREEN_CONTEXT_FOR_WEBGL; |
111 } | 103 } |
112 if (share_context) { | 104 if (share_context) { |
113 DCHECK(!share_resources); | 105 DCHECK(!share_resources); |
114 share_group_ = share_context->share_group_; | 106 share_group_ = share_context->share_group_; |
115 } else if (share_resources) { | 107 } else if (share_resources) { |
116 share_group_ = GetDefaultShareGroupForHost(host); | 108 share_group_ = GetDefaultShareGroupForHost(host); |
117 } else { | 109 } else { |
118 share_group_ = make_scoped_refptr(new ShareGroup); | 110 share_group_ = make_scoped_refptr(new ShareGroup); |
119 } | 111 } |
120 } | 112 } |
121 | 113 |
122 WebGraphicsContext3DCommandBufferImpl:: | 114 WebGraphicsContext3DCommandBufferImpl:: |
123 ~WebGraphicsContext3DCommandBufferImpl() { | 115 ~WebGraphicsContext3DCommandBufferImpl() { |
124 if (real_gl_) | 116 if (real_gl_) |
125 real_gl_->SetLostContextCallback(base::Closure()); | 117 real_gl_->SetLostContextCallback(base::Closure()); |
126 | 118 |
127 Destroy(); | 119 Destroy(); |
128 } | 120 } |
129 | 121 |
130 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { | 122 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL( |
| 123 const gpu::SharedMemoryLimits& memory_limits) { |
131 if (initialized_) | 124 if (initialized_) |
132 return true; | 125 return true; |
133 | 126 |
134 if (initialize_failed_) | 127 if (initialize_failed_) |
135 return false; | 128 return false; |
136 | 129 |
137 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 130 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); |
138 | 131 |
139 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. | 132 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. |
140 tracked_objects::ScopedTracker tracking_profile( | 133 tracked_objects::ScopedTracker tracking_profile( |
141 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 134 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
142 "125248 WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL")); | 135 "125248 WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL")); |
143 | 136 |
144 if (!CreateContext()) { | 137 if (!CreateContext(memory_limits)) { |
145 Destroy(); | 138 Destroy(); |
146 | 139 |
147 initialize_failed_ = true; | 140 initialize_failed_ = true; |
148 return false; | 141 return false; |
149 } | 142 } |
150 | 143 |
151 real_gl_->SetLostContextCallback( | 144 real_gl_->SetLostContextCallback( |
152 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost, | 145 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost, |
153 // The callback is unset in the destructor. | 146 // The callback is unset in the destructor. |
154 base::Unretained(this))); | 147 base::Unretained(this))); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 << "Context dead on arrival. Last error: " | 185 << "Context dead on arrival. Last error: " |
193 << command_buffer_->GetLastError(); | 186 << command_buffer_->GetLastError(); |
194 // Initialize the command buffer. | 187 // Initialize the command buffer. |
195 bool result = command_buffer_->Initialize(); | 188 bool result = command_buffer_->Initialize(); |
196 LOG_IF(ERROR, !result) << "CommandBufferProxy::Initialize failed."; | 189 LOG_IF(ERROR, !result) << "CommandBufferProxy::Initialize failed."; |
197 if (!result) | 190 if (!result) |
198 UmaRecordContextInitFailed(context_type_); | 191 UmaRecordContextInitFailed(context_type_); |
199 return result; | 192 return result; |
200 } | 193 } |
201 | 194 |
202 bool WebGraphicsContext3DCommandBufferImpl::CreateContext() { | 195 bool WebGraphicsContext3DCommandBufferImpl::CreateContext( |
| 196 const gpu::SharedMemoryLimits& memory_limits) { |
203 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext"); | 197 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext"); |
204 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group; | 198 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group; |
205 | 199 |
206 std::unique_ptr<base::AutoLock> share_group_lock; | 200 std::unique_ptr<base::AutoLock> share_group_lock; |
207 bool add_to_share_group = false; | 201 bool add_to_share_group = false; |
208 if (!command_buffer_) { | 202 if (!command_buffer_) { |
209 WebGraphicsContext3DCommandBufferImpl* share_context = NULL; | 203 WebGraphicsContext3DCommandBufferImpl* share_context = NULL; |
210 | 204 |
211 share_group_lock.reset(new base::AutoLock(share_group_->lock())); | 205 share_group_lock.reset(new base::AutoLock(share_group_->lock())); |
212 share_context = share_group_->GetAnyContextLocked(); | 206 share_context = share_group_->GetAnyContextLocked(); |
213 | 207 |
214 if (!InitializeCommandBuffer(share_context)) { | 208 if (!InitializeCommandBuffer(share_context)) { |
215 LOG(ERROR) << "Failed to initialize command buffer."; | 209 LOG(ERROR) << "Failed to initialize command buffer."; |
216 return false; | 210 return false; |
217 } | 211 } |
218 | 212 |
219 if (share_context) | 213 if (share_context) |
220 gles2_share_group = share_context->GetImplementation()->share_group(); | 214 gles2_share_group = share_context->GetImplementation()->share_group(); |
221 | 215 |
222 add_to_share_group = true; | 216 add_to_share_group = true; |
223 } | 217 } |
224 | 218 |
225 // Create the GLES2 helper, which writes the command buffer protocol. | 219 // Create the GLES2 helper, which writes the command buffer protocol. |
226 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 220 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
227 if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) { | 221 if (!gles2_helper_->Initialize(memory_limits.command_buffer_size)) { |
228 LOG(ERROR) << "Failed to initialize GLES2CmdHelper."; | 222 LOG(ERROR) << "Failed to initialize GLES2CmdHelper."; |
229 return false; | 223 return false; |
230 } | 224 } |
231 | 225 |
232 if (!automatic_flushes_) | 226 if (!automatic_flushes_) |
233 gles2_helper_->SetAutomaticFlushes(false); | 227 gles2_helper_->SetAutomaticFlushes(false); |
234 // Create a transfer buffer used to copy resources between the renderer | 228 // Create a transfer buffer used to copy resources between the renderer |
235 // process and the GPU process. | 229 // process and the GPU process. |
236 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); | 230 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); |
237 | 231 |
238 DCHECK(host_.get()); | 232 DCHECK(host_.get()); |
239 | 233 |
240 const bool bind_generates_resource = attributes_.bind_generates_resource; | 234 const bool bind_generates_resource = attributes_.bind_generates_resource; |
241 const bool lose_context_when_out_of_memory = | 235 const bool lose_context_when_out_of_memory = |
242 attributes_.lose_context_when_out_of_memory; | 236 attributes_.lose_context_when_out_of_memory; |
243 const bool support_client_side_arrays = false; | 237 const bool support_client_side_arrays = false; |
244 | 238 |
245 // Create the object exposing the OpenGL API. | 239 // Create the object exposing the OpenGL API. |
246 real_gl_.reset(new gpu::gles2::GLES2Implementation( | 240 real_gl_.reset(new gpu::gles2::GLES2Implementation( |
247 gles2_helper_.get(), gles2_share_group.get(), transfer_buffer_.get(), | 241 gles2_helper_.get(), gles2_share_group.get(), transfer_buffer_.get(), |
248 bind_generates_resource, lose_context_when_out_of_memory, | 242 bind_generates_resource, lose_context_when_out_of_memory, |
249 support_client_side_arrays, command_buffer_.get())); | 243 support_client_side_arrays, command_buffer_.get())); |
250 SetGLInterface(real_gl_.get()); | 244 SetGLInterface(real_gl_.get()); |
251 | 245 |
252 if (!real_gl_->Initialize( | 246 if (!real_gl_->Initialize(memory_limits.start_transfer_buffer_size, |
253 mem_limits_.start_transfer_buffer_size, | 247 memory_limits.min_transfer_buffer_size, |
254 mem_limits_.min_transfer_buffer_size, | 248 memory_limits.max_transfer_buffer_size, |
255 mem_limits_.max_transfer_buffer_size, | 249 memory_limits.mapped_memory_reclaim_limit)) { |
256 mem_limits_.mapped_memory_reclaim_limit)) { | |
257 LOG(ERROR) << "Failed to initialize GLES2Implementation."; | 250 LOG(ERROR) << "Failed to initialize GLES2Implementation."; |
258 return false; | 251 return false; |
259 } | 252 } |
260 | 253 |
261 if (add_to_share_group) | 254 if (add_to_share_group) |
262 share_group_->AddContextLocked(this); | 255 share_group_->AddContextLocked(this); |
263 | 256 |
264 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 257 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
265 switches::kEnableGpuClientTracing)) { | 258 switches::kEnableGpuClientTracing)) { |
266 trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(GetGLInterface())); | 259 trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(GetGLInterface())); |
267 SetGLInterface(trace_gl_.get()); | 260 SetGLInterface(trace_gl_.get()); |
268 } | 261 } |
269 return true; | 262 return true; |
270 } | 263 } |
271 | 264 |
272 bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread() { | 265 bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread( |
273 if (!MaybeInitializeGL()) { | 266 const gpu::SharedMemoryLimits& memory_limits) { |
| 267 if (!MaybeInitializeGL(memory_limits)) { |
274 DLOG(ERROR) << "Failed to initialize context."; | 268 DLOG(ERROR) << "Failed to initialize context."; |
275 return false; | 269 return false; |
276 } | 270 } |
277 if (gpu::error::IsError(command_buffer_->GetLastError())) { | 271 if (gpu::error::IsError(command_buffer_->GetLastError())) { |
278 LOG(ERROR) << "Context dead on arrival. Last error: " | 272 LOG(ERROR) << "Context dead on arrival. Last error: " |
279 << command_buffer_->GetLastError(); | 273 << command_buffer_->GetLastError(); |
280 return false; | 274 return false; |
281 } | 275 } |
282 | 276 |
283 return true; | 277 return true; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 { | 316 { |
323 base::AutoLock lock(g_default_share_groups_lock.Get()); | 317 base::AutoLock lock(g_default_share_groups_lock.Get()); |
324 g_default_share_groups.Get().erase(host_.get()); | 318 g_default_share_groups.Get().erase(host_.get()); |
325 } | 319 } |
326 | 320 |
327 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 321 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
328 UmaRecordContextLost(context_type_, state.error, state.context_lost_reason); | 322 UmaRecordContextLost(context_type_, state.error, state.context_lost_reason); |
329 } | 323 } |
330 | 324 |
331 } // namespace content | 325 } // namespace content |
OLD | NEW |