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

Side by Side Diff: services/ui/public/cpp/gpu/gpu.cc

Issue 2965103002: gpu: Make the mus-gpu client-lib test-friendly. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « services/ui/public/cpp/gpu/gpu.h ('k') | services/ui/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/ui/public/cpp/gpu/gpu.h" 5 #include "services/ui/public/cpp/gpu/gpu.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "gpu/command_buffer/common/scheduling_priority.h" 11 #include "gpu/command_buffer/common/scheduling_priority.h"
12 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" 12 #include "mojo/public/cpp/bindings/sync_call_restrictions.h"
13 #include "mojo/public/cpp/system/platform_handle.h" 13 #include "mojo/public/cpp/system/platform_handle.h"
14 #include "services/service_manager/public/cpp/connector.h" 14 #include "services/service_manager/public/cpp/connector.h"
15 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" 15 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h"
16 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" 16 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
17 #include "services/ui/public/interfaces/constants.mojom.h" 17 #include "services/ui/public/interfaces/constants.mojom.h"
18 #include "services/ui/public/interfaces/gpu.mojom.h" 18 #include "services/ui/public/interfaces/gpu.mojom.h"
19 19
20 namespace ui { 20 namespace ui {
21 21
22 Gpu::Gpu(service_manager::Connector* connector, 22 namespace {
23 const std::string& service_name, 23
24 mojom::GpuPtr DefaultFactory(service_manager::Connector* connector,
25 const std::string& service_name) {
26 mojom::GpuPtr gpu_ptr;
27 connector->BindInterface(service_name, &gpu_ptr);
28 return gpu_ptr;
29 }
30
31 } // namespace
32
33 Gpu::Gpu(GpuPtrFactory factory,
24 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
25 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 35 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
26 io_task_runner_(std::move(task_runner)), 36 io_task_runner_(std::move(task_runner)),
27 connector_(connector), 37 factory_(std::move(factory)),
28 service_name_(service_name),
29 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 38 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
30 base::WaitableEvent::InitialState::NOT_SIGNALED) { 39 base::WaitableEvent::InitialState::NOT_SIGNALED) {
31 DCHECK(main_task_runner_); 40 DCHECK(main_task_runner_);
32 DCHECK(connector_);
33 mojom::GpuPtr gpu_ptr;
34 connector_->BindInterface(service_name_, &gpu_ptr);
35 gpu_memory_buffer_manager_ = 41 gpu_memory_buffer_manager_ =
36 base::MakeUnique<ClientGpuMemoryBufferManager>(std::move(gpu_ptr)); 42 base::MakeUnique<ClientGpuMemoryBufferManager>(factory_.Run());
37 if (!io_task_runner_) { 43 if (!io_task_runner_) {
38 io_thread_.reset(new base::Thread("GPUIOThread")); 44 io_thread_.reset(new base::Thread("GPUIOThread"));
39 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); 45 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
40 thread_options.priority = base::ThreadPriority::NORMAL; 46 thread_options.priority = base::ThreadPriority::NORMAL;
41 CHECK(io_thread_->StartWithOptions(thread_options)); 47 CHECK(io_thread_->StartWithOptions(thread_options));
42 io_task_runner_ = io_thread_->task_runner(); 48 io_task_runner_ = io_thread_->task_runner();
43 } 49 }
44 } 50 }
45 51
46 Gpu::~Gpu() { 52 Gpu::~Gpu() {
47 DCHECK(IsMainThread()); 53 DCHECK(IsMainThread());
48 shutdown_event_.Signal(); 54 shutdown_event_.Signal();
49 if (gpu_channel_) 55 if (gpu_channel_)
50 gpu_channel_->DestroyChannel(); 56 gpu_channel_->DestroyChannel();
51 } 57 }
52 58
53 // static 59 // static
54 std::unique_ptr<Gpu> Gpu::Create( 60 std::unique_ptr<Gpu> Gpu::Create(
55 service_manager::Connector* connector, 61 service_manager::Connector* connector,
56 const std::string& service_name, 62 const std::string& service_name,
57 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
58 return base::WrapUnique( 64 GpuPtrFactory factory =
59 new Gpu(connector, service_name, std::move(task_runner))); 65 base::BindRepeating(&DefaultFactory, connector, service_name);
66 return base::WrapUnique(new Gpu(std::move(factory), std::move(task_runner)));
60 } 67 }
61 68
62 scoped_refptr<cc::ContextProvider> Gpu::CreateContextProvider( 69 scoped_refptr<cc::ContextProvider> Gpu::CreateContextProvider(
63 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { 70 scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
64 int32_t stream_id = 0; 71 int32_t stream_id = 0;
65 gpu::SchedulingPriority stream_priority = gpu::SchedulingPriority::kNormal; 72 gpu::SchedulingPriority stream_priority = gpu::SchedulingPriority::kNormal;
66 73
67 constexpr bool automatic_flushes = false; 74 constexpr bool automatic_flushes = false;
68 constexpr bool support_locking = false; 75 constexpr bool support_locking = false;
69 76
(...skipping 19 matching lines...) Expand all
89 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); 96 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel();
90 if (channel) { 97 if (channel) {
91 main_task_runner_->PostTask(FROM_HERE, 98 main_task_runner_->PostTask(FROM_HERE,
92 base::Bind(callback, std::move(channel))); 99 base::Bind(callback, std::move(channel)));
93 return; 100 return;
94 } 101 }
95 establish_callbacks_.push_back(callback); 102 establish_callbacks_.push_back(callback);
96 if (gpu_) 103 if (gpu_)
97 return; 104 return;
98 105
99 connector_->BindInterface(service_name_, &gpu_); 106 gpu_ = factory_.Run();
100 gpu_->EstablishGpuChannel( 107 gpu_->EstablishGpuChannel(
101 base::Bind(&Gpu::OnEstablishedGpuChannel, base::Unretained(this))); 108 base::Bind(&Gpu::OnEstablishedGpuChannel, base::Unretained(this)));
102 } 109 }
103 110
104 scoped_refptr<gpu::GpuChannelHost> Gpu::EstablishGpuChannelSync() { 111 scoped_refptr<gpu::GpuChannelHost> Gpu::EstablishGpuChannelSync() {
105 DCHECK(IsMainThread()); 112 DCHECK(IsMainThread());
106 if (GetGpuChannel()) 113 if (GetGpuChannel())
107 return gpu_channel_; 114 return gpu_channel_;
108 115
109 int client_id = 0; 116 int client_id = 0;
110 mojo::ScopedMessagePipeHandle channel_handle; 117 mojo::ScopedMessagePipeHandle channel_handle;
111 gpu::GPUInfo gpu_info; 118 gpu::GPUInfo gpu_info;
112 connector_->BindInterface(service_name_, &gpu_); 119 gpu_ = factory_.Run();
113
114 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; 120 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
115 if (!gpu_->EstablishGpuChannel(&client_id, &channel_handle, &gpu_info)) { 121 if (!gpu_->EstablishGpuChannel(&client_id, &channel_handle, &gpu_info)) {
116 DLOG(WARNING) 122 DLOG(WARNING)
117 << "Channel encountered error while establishing gpu channel."; 123 << "Channel encountered error while establishing gpu channel.";
118 return nullptr; 124 return nullptr;
119 } 125 }
120 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info); 126 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info);
121 return gpu_channel_; 127 return gpu_channel_;
122 } 128 }
123 129
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 MojoResult result = mojo::UnwrapSharedMemoryHandle( 179 MojoResult result = mojo::UnwrapSharedMemoryHandle(
174 std::move(handle), &platform_handle, &shared_memory_size, &readonly); 180 std::move(handle), &platform_handle, &shared_memory_size, &readonly);
175 if (result != MOJO_RESULT_OK) 181 if (result != MOJO_RESULT_OK)
176 return nullptr; 182 return nullptr;
177 DCHECK_EQ(shared_memory_size, size); 183 DCHECK_EQ(shared_memory_size, size);
178 184
179 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); 185 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
180 } 186 }
181 187
182 } // namespace ui 188 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/gpu/gpu.h ('k') | services/ui/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698