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

Side by Side Diff: components/mus/gles2/command_buffer_driver.cc

Issue 1346113003: Mandoline: WebGL: Pass context creation attributes to GPU. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 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 "components/mus/gles2/command_buffer_driver.h" 5 #include "components/mus/gles2/command_buffer_driver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "components/mus/gles2/command_buffer_type_conversions.h" 10 #include "components/mus/gles2/command_buffer_type_conversions.h"
(...skipping 28 matching lines...) Expand all
39 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) 39 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state)
40 : client_(nullptr), gpu_state_(gpu_state), weak_factory_(this) {} 40 : client_(nullptr), gpu_state_(gpu_state), weak_factory_(this) {}
41 41
42 CommandBufferDriver::~CommandBufferDriver() { 42 CommandBufferDriver::~CommandBufferDriver() {
43 DestroyDecoder(); 43 DestroyDecoder();
44 } 44 }
45 45
46 void CommandBufferDriver::Initialize( 46 void CommandBufferDriver::Initialize(
47 mojo::CommandBufferSyncClientPtr sync_client, 47 mojo::CommandBufferSyncClientPtr sync_client,
48 mojo::CommandBufferLostContextObserverPtr loss_observer, 48 mojo::CommandBufferLostContextObserverPtr loss_observer,
49 mojo::ScopedSharedBufferHandle shared_state) { 49 mojo::ScopedSharedBufferHandle shared_state,
50 mojo::Array<int32_t> attribs) {
50 sync_client_ = sync_client.Pass(); 51 sync_client_ = sync_client.Pass();
51 loss_observer_ = loss_observer.Pass(); 52 loss_observer_ = loss_observer.Pass();
52 bool success = DoInitialize(shared_state.Pass()); 53 bool success = DoInitialize(shared_state.Pass(), attribs.Pass());
53 mojo::GpuCapabilitiesPtr capabilities = 54 mojo::GpuCapabilitiesPtr capabilities =
54 success ? mojo::GpuCapabilities::From(decoder_->GetCapabilities()) 55 success ? mojo::GpuCapabilities::From(decoder_->GetCapabilities())
55 : nullptr; 56 : nullptr;
56 sync_client_->DidInitialize(success, capabilities.Pass()); 57 sync_client_->DidInitialize(success, capabilities.Pass());
57 } 58 }
58 59
59 bool CommandBufferDriver::MakeCurrent() { 60 bool CommandBufferDriver::MakeCurrent() {
60 if (!decoder_) 61 if (!decoder_)
61 return false; 62 return false;
62 if (decoder_->MakeCurrent()) 63 if (decoder_->MakeCurrent())
63 return true; 64 return true;
64 DLOG(ERROR) << "Context lost because MakeCurrent failed."; 65 DLOG(ERROR) << "Context lost because MakeCurrent failed.";
65 gpu::error::ContextLostReason reason = 66 gpu::error::ContextLostReason reason =
66 static_cast<gpu::error::ContextLostReason>( 67 static_cast<gpu::error::ContextLostReason>(
67 decoder_->GetContextLostReason()); 68 decoder_->GetContextLostReason());
68 command_buffer_->SetContextLostReason(reason); 69 command_buffer_->SetContextLostReason(reason);
69 command_buffer_->SetParseError(gpu::error::kLostContext); 70 command_buffer_->SetParseError(gpu::error::kLostContext);
70 OnContextLost(reason); 71 OnContextLost(reason);
71 return false; 72 return false;
72 } 73 }
73 74
74 bool CommandBufferDriver::DoInitialize( 75 bool CommandBufferDriver::DoInitialize(
75 mojo::ScopedSharedBufferHandle shared_state) { 76 mojo::ScopedSharedBufferHandle shared_state,
77 mojo::Array<int32_t> attribs) {
78 gpu::gles2::ContextCreationAttribHelper attrib_helper;
79 if (!attrib_helper.Parse(attribs.storage()))
80 return false;
81
76 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); 82 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
77 83
78 if (!surface_.get()) 84 if (!surface_.get())
79 return false; 85 return false;
80 86
81 // TODO(piman): virtual contexts, gpu preference. 87 // TODO(piman): virtual contexts, gpu preference.
82 context_ = gfx::GLContext::CreateGLContext( 88 context_ = gfx::GLContext::CreateGLContext(
83 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu); 89 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu);
84 if (!context_.get()) 90 if (!context_.get())
85 return false; 91 return false;
86 92
87 if (!context_->MakeCurrent(surface_.get())) 93 if (!context_->MakeCurrent(surface_.get()))
88 return false; 94 return false;
89 95
90 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but 96 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but
91 // only needs to be per-thread. 97 // only needs to be per-thread.
92 bool bind_generates_resource = false; 98 const bool bind_generates_resource = attrib_helper.bind_generates_resource;
93 scoped_refptr<gpu::gles2::ContextGroup> context_group = 99 scoped_refptr<gpu::gles2::ContextGroup> context_group =
94 new gpu::gles2::ContextGroup( 100 new gpu::gles2::ContextGroup(
95 gpu_state_->mailbox_manager(), new GpuMemoryTracker, 101 gpu_state_->mailbox_manager(), new GpuMemoryTracker,
96 new gpu::gles2::ShaderTranslatorCache, 102 new gpu::gles2::ShaderTranslatorCache,
97 new gpu::gles2::FramebufferCompletenessCache, nullptr, nullptr, 103 new gpu::gles2::FramebufferCompletenessCache, nullptr, nullptr,
98 nullptr, bind_generates_resource); 104 nullptr, bind_generates_resource);
99 105
100 command_buffer_.reset( 106 command_buffer_.reset(
101 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); 107 new gpu::CommandBufferService(context_group->transfer_buffer_manager()));
102 bool result = command_buffer_->Initialize(); 108 bool result = command_buffer_->Initialize();
103 DCHECK(result); 109 DCHECK(result);
104 110
105 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); 111 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get()));
106 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), 112 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(),
107 decoder_.get())); 113 decoder_.get()));
108 decoder_->set_engine(scheduler_.get()); 114 decoder_->set_engine(scheduler_.get());
109 decoder_->SetResizeCallback( 115 decoder_->SetResizeCallback(
110 base::Bind(&CommandBufferDriver::OnResize, base::Unretained(this))); 116 base::Bind(&CommandBufferDriver::OnResize, base::Unretained(this)));
111 decoder_->SetWaitSyncPointCallback(base::Bind( 117 decoder_->SetWaitSyncPointCallback(base::Bind(
112 &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this))); 118 &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this)));
113 119
114 gpu::gles2::DisallowedFeatures disallowed_features; 120 gpu::gles2::DisallowedFeatures disallowed_features;
115 121
116 // TODO(piman): attributes.
117 const bool offscreen = true; 122 const bool offscreen = true;
118 std::vector<int32> attrib_vector; 123 std::vector<int32> attrib_vector;
124 attrib_helper.Serialize(&attrib_vector);
119 if (!decoder_->Initialize(surface_, context_, offscreen, gfx::Size(1, 1), 125 if (!decoder_->Initialize(surface_, context_, offscreen, gfx::Size(1, 1),
120 disallowed_features, attrib_vector)) 126 disallowed_features, attrib_vector))
121 return false; 127 return false;
122 128
123 command_buffer_->SetPutOffsetChangeCallback(base::Bind( 129 command_buffer_->SetPutOffsetChangeCallback(base::Bind(
124 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); 130 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get())));
125 command_buffer_->SetGetBufferChangeCallback(base::Bind( 131 command_buffer_->SetGetBufferChangeCallback(base::Bind(
126 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); 132 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get())));
127 command_buffer_->SetParseErrorCallback( 133 command_buffer_->SetParseErrorCallback(
128 base::Bind(&CommandBufferDriver::OnParseError, base::Unretained(this))); 134 base::Bind(&CommandBufferDriver::OnParseError, base::Unretained(this)));
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 302
297 void CommandBufferDriver::DestroyDecoder() { 303 void CommandBufferDriver::DestroyDecoder() {
298 if (decoder_) { 304 if (decoder_) {
299 bool have_context = decoder_->MakeCurrent(); 305 bool have_context = decoder_->MakeCurrent();
300 decoder_->Destroy(have_context); 306 decoder_->Destroy(have_context);
301 decoder_.reset(); 307 decoder_.reset();
302 } 308 }
303 } 309 }
304 310
305 } // namespace gles2 311 } // namespace gles2
OLDNEW
« no previous file with comments | « components/mus/gles2/command_buffer_driver.h ('k') | components/mus/gles2/command_buffer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698