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

Side by Side Diff: content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698