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

Side by Side Diff: gpu/command_buffer/service/in_process_command_buffer.cc

Issue 2107783003: Pass initial size and GPU preference via context attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp fix Created 4 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "gpu/command_buffer/service/in_process_command_buffer.h" 5 #include "gpu/command_buffer/service/in_process_command_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (!MakeCurrent()) 244 if (!MakeCurrent())
245 return; 245 return;
246 246
247 executor_->PutChanged(); 247 executor_->PutChanged();
248 } 248 }
249 249
250 bool InProcessCommandBuffer::Initialize( 250 bool InProcessCommandBuffer::Initialize(
251 scoped_refptr<gl::GLSurface> surface, 251 scoped_refptr<gl::GLSurface> surface,
252 bool is_offscreen, 252 bool is_offscreen,
253 gfx::AcceleratedWidget window, 253 gfx::AcceleratedWidget window,
254 const gfx::Size& size,
255 const gles2::ContextCreationAttribHelper& attribs, 254 const gles2::ContextCreationAttribHelper& attribs,
256 gl::GpuPreference gpu_preference,
257 InProcessCommandBuffer* share_group, 255 InProcessCommandBuffer* share_group,
258 GpuMemoryBufferManager* gpu_memory_buffer_manager, 256 GpuMemoryBufferManager* gpu_memory_buffer_manager,
259 ImageFactory* image_factory) { 257 ImageFactory* image_factory) {
260 DCHECK(!share_group || service_.get() == share_group->service_.get()); 258 DCHECK(!share_group || service_.get() == share_group->service_.get());
261 259
262 if (surface) { 260 if (surface) {
263 // GPU thread must be the same as client thread due to GLSurface not being 261 // GPU thread must be the same as client thread due to GLSurface not being
264 // thread safe. 262 // thread safe.
265 sequence_checker_.reset(new base::SequenceChecker); 263 sequence_checker_.reset(new base::SequenceChecker);
266 surface_ = surface; 264 surface_ = surface;
267 } else { 265 } else {
268 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 266 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get();
269 client_thread_weak_ptr_ = client_thread_weak_ptr_factory_.GetWeakPtr(); 267 client_thread_weak_ptr_ = client_thread_weak_ptr_factory_.GetWeakPtr();
270 } 268 }
271 269
272 gpu::Capabilities capabilities; 270 gpu::Capabilities capabilities;
273 InitializeOnGpuThreadParams params(is_offscreen, 271 InitializeOnGpuThreadParams params(is_offscreen, window, attribs,
274 window, 272 &capabilities, share_group, image_factory);
275 size,
276 attribs,
277 gpu_preference,
278 &capabilities,
279 share_group,
280 image_factory);
281 273
282 base::Callback<bool(void)> init_task = 274 base::Callback<bool(void)> init_task =
283 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, 275 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread,
284 base::Unretained(this), 276 base::Unretained(this), params);
285 params);
286 277
287 base::WaitableEvent completion( 278 base::WaitableEvent completion(
288 base::WaitableEvent::ResetPolicy::MANUAL, 279 base::WaitableEvent::ResetPolicy::MANUAL,
289 base::WaitableEvent::InitialState::NOT_SIGNALED); 280 base::WaitableEvent::InitialState::NOT_SIGNALED);
290 bool result = false; 281 bool result = false;
291 QueueTask( 282 QueueTask(
292 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); 283 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion));
293 completion.Wait(); 284 completion.Wait();
294 285
295 gpu_memory_buffer_manager_ = gpu_memory_buffer_manager; 286 gpu_memory_buffer_manager_ = gpu_memory_buffer_manager;
296 287
297 if (result) { 288 if (result) {
298 capabilities_ = capabilities; 289 capabilities_ = capabilities;
299 capabilities_.image = capabilities_.image && gpu_memory_buffer_manager_; 290 capabilities_.image = capabilities_.image && gpu_memory_buffer_manager_;
300 } 291 }
301 292
302 return result; 293 return result;
303 } 294 }
304 295
305 bool InProcessCommandBuffer::InitializeOnGpuThread( 296 bool InProcessCommandBuffer::InitializeOnGpuThread(
306 const InitializeOnGpuThreadParams& params) { 297 const InitializeOnGpuThreadParams& params) {
307 CheckSequencedThread(); 298 CheckSequencedThread();
308 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); 299 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr();
309 300
310 DCHECK(params.size.width() >= 0 && params.size.height() >= 0);
311
312 TransferBufferManager* manager = new TransferBufferManager(nullptr); 301 TransferBufferManager* manager = new TransferBufferManager(nullptr);
313 transfer_buffer_manager_ = manager; 302 transfer_buffer_manager_ = manager;
314 manager->Initialize(); 303 manager->Initialize();
315 304
316 std::unique_ptr<CommandBufferService> command_buffer( 305 std::unique_ptr<CommandBufferService> command_buffer(
317 new CommandBufferService(transfer_buffer_manager_.get())); 306 new CommandBufferService(transfer_buffer_manager_.get()));
318 command_buffer->SetPutOffsetChangeCallback(base::Bind( 307 command_buffer->SetPutOffsetChangeCallback(base::Bind(
319 &InProcessCommandBuffer::PumpCommandsOnGpuThread, gpu_thread_weak_ptr_)); 308 &InProcessCommandBuffer::PumpCommandsOnGpuThread, gpu_thread_weak_ptr_));
320 command_buffer->SetParseErrorCallback(base::Bind( 309 command_buffer->SetParseErrorCallback(base::Bind(
321 &InProcessCommandBuffer::OnContextLostOnGpuThread, gpu_thread_weak_ptr_)); 310 &InProcessCommandBuffer::OnContextLostOnGpuThread, gpu_thread_weak_ptr_));
(...skipping 17 matching lines...) Expand all
339 executor_.reset(new CommandExecutor(command_buffer.get(), decoder_.get(), 328 executor_.reset(new CommandExecutor(command_buffer.get(), decoder_.get(),
340 decoder_.get())); 329 decoder_.get()));
341 command_buffer->SetGetBufferChangeCallback(base::Bind( 330 command_buffer->SetGetBufferChangeCallback(base::Bind(
342 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); 331 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get())));
343 command_buffer_ = std::move(command_buffer); 332 command_buffer_ = std::move(command_buffer);
344 333
345 decoder_->set_engine(executor_.get()); 334 decoder_->set_engine(executor_.get());
346 335
347 if (!surface_.get()) { 336 if (!surface_.get()) {
348 if (params.is_offscreen) 337 if (params.is_offscreen)
349 surface_ = gl::init::CreateOffscreenGLSurface(params.size); 338 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size());
350 else 339 else
351 surface_ = gl::init::CreateViewGLSurface(params.window); 340 surface_ = gl::init::CreateViewGLSurface(params.window);
352 } 341 }
353 342
354 if (!surface_.get()) { 343 if (!surface_.get()) {
355 LOG(ERROR) << "Could not create GLSurface."; 344 LOG(ERROR) << "Could not create GLSurface.";
356 DestroyOnGpuThread(); 345 DestroyOnGpuThread();
357 return false; 346 return false;
358 } 347 }
359 348
360 sync_point_order_data_ = SyncPointOrderData::Create(); 349 sync_point_order_data_ = SyncPointOrderData::Create();
361 sync_point_client_ = service_->sync_point_manager()->CreateSyncPointClient( 350 sync_point_client_ = service_->sync_point_manager()->CreateSyncPointClient(
362 sync_point_order_data_, GetNamespaceID(), GetCommandBufferID()); 351 sync_point_order_data_, GetNamespaceID(), GetCommandBufferID());
363 352
364 if (service_->UseVirtualizedGLContexts() || 353 if (service_->UseVirtualizedGLContexts() ||
365 decoder_->GetContextGroup() 354 decoder_->GetContextGroup()
366 ->feature_info() 355 ->feature_info()
367 ->workarounds() 356 ->workarounds()
368 .use_virtualized_gl_contexts) { 357 .use_virtualized_gl_contexts) {
369 context_ = gl_share_group_->GetSharedContext(); 358 context_ = gl_share_group_->GetSharedContext();
370 if (!context_.get()) { 359 if (!context_.get()) {
371 context_ = gl::init::CreateGLContext( 360 context_ = gl::init::CreateGLContext(
372 gl_share_group_.get(), surface_.get(), params.gpu_preference); 361 gl_share_group_.get(), surface_.get(), params.attribs.gpu_preference);
373 gl_share_group_->SetSharedContext(context_.get()); 362 gl_share_group_->SetSharedContext(context_.get());
374 } 363 }
375 364
376 context_ = new GLContextVirtual( 365 context_ = new GLContextVirtual(
377 gl_share_group_.get(), context_.get(), decoder_->AsWeakPtr()); 366 gl_share_group_.get(), context_.get(), decoder_->AsWeakPtr());
378 if (context_->Initialize(surface_.get(), params.gpu_preference)) { 367 if (context_->Initialize(surface_.get(), params.attribs.gpu_preference)) {
379 VLOG(1) << "Created virtual GL context."; 368 VLOG(1) << "Created virtual GL context.";
380 } else { 369 } else {
381 context_ = NULL; 370 context_ = NULL;
382 } 371 }
383 } else { 372 } else {
384 context_ = gl::init::CreateGLContext(gl_share_group_.get(), surface_.get(), 373 context_ = gl::init::CreateGLContext(gl_share_group_.get(), surface_.get(),
385 params.gpu_preference); 374 params.attribs.gpu_preference);
386 } 375 }
387 376
388 if (!context_.get()) { 377 if (!context_.get()) {
389 LOG(ERROR) << "Could not create GLContext."; 378 LOG(ERROR) << "Could not create GLContext.";
390 DestroyOnGpuThread(); 379 DestroyOnGpuThread();
391 return false; 380 return false;
392 } 381 }
393 382
394 if (!context_->MakeCurrent(surface_.get())) { 383 if (!context_->MakeCurrent(surface_.get())) {
395 LOG(ERROR) << "Could not make context current."; 384 LOG(ERROR) << "Could not make context current.";
396 DestroyOnGpuThread(); 385 DestroyOnGpuThread();
397 return false; 386 return false;
398 } 387 }
399 388
400 if (!decoder_->GetContextGroup()->has_program_cache() && 389 if (!decoder_->GetContextGroup()->has_program_cache() &&
401 !decoder_->GetContextGroup() 390 !decoder_->GetContextGroup()
402 ->feature_info() 391 ->feature_info()
403 ->workarounds() 392 ->workarounds()
404 .disable_program_cache) { 393 .disable_program_cache) {
405 decoder_->GetContextGroup()->set_program_cache(service_->program_cache()); 394 decoder_->GetContextGroup()->set_program_cache(service_->program_cache());
406 } 395 }
407 396
408 gles2::DisallowedFeatures disallowed_features; 397 gles2::DisallowedFeatures disallowed_features;
409 disallowed_features.gpu_memory_manager = true; 398 disallowed_features.gpu_memory_manager = true;
410 if (!decoder_->Initialize(surface_, 399 if (!decoder_->Initialize(surface_,
411 context_, 400 context_,
412 params.is_offscreen, 401 params.is_offscreen,
413 params.size,
414 disallowed_features, 402 disallowed_features,
415 params.attribs)) { 403 params.attribs)) {
416 LOG(ERROR) << "Could not initialize decoder."; 404 LOG(ERROR) << "Could not initialize decoder.";
417 DestroyOnGpuThread(); 405 DestroyOnGpuThread();
418 return false; 406 return false;
419 } 407 }
420 *params.capabilities = decoder_->GetCapabilities(); 408 *params.capabilities = decoder_->GetCapabilities();
421 409
422 decoder_->SetFenceSyncReleaseCallback( 410 decoder_->SetFenceSyncReleaseCallback(
423 base::Bind(&InProcessCommandBuffer::FenceSyncReleaseOnGpuThread, 411 base::Bind(&InProcessCommandBuffer::FenceSyncReleaseOnGpuThread,
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 framebuffer_completeness_cache_ = 1069 framebuffer_completeness_cache_ =
1082 new gpu::gles2::FramebufferCompletenessCache; 1070 new gpu::gles2::FramebufferCompletenessCache;
1083 return framebuffer_completeness_cache_; 1071 return framebuffer_completeness_cache_;
1084 } 1072 }
1085 1073
1086 SyncPointManager* GpuInProcessThread::sync_point_manager() { 1074 SyncPointManager* GpuInProcessThread::sync_point_manager() {
1087 return sync_point_manager_; 1075 return sync_point_manager_;
1088 } 1076 }
1089 1077
1090 } // namespace gpu 1078 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/in_process_command_buffer.h ('k') | gpu/command_buffer/tests/gl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698