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

Side by Side Diff: content/common/gpu/gpu_channel_manager.cc

Issue 540443002: Enable sync allocation of GpuMemoryBuffers from the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « content/common/gpu/gpu_channel_manager.h ('k') | content/gpu/gpu_child_thread.cc » ('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 (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/gpu_channel_manager.h" 5 #include "content/common/gpu/gpu_channel_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "content/common/gpu/gpu_channel.h" 9 #include "content/common/gpu/gpu_channel.h"
10 #include "content/common/gpu/gpu_memory_buffer_factory.h" 10 #include "content/common/gpu/gpu_memory_buffer_factory.h"
11 #include "content/common/gpu/gpu_memory_manager.h" 11 #include "content/common/gpu/gpu_memory_manager.h"
12 #include "content/common/gpu/gpu_messages.h" 12 #include "content/common/gpu/gpu_messages.h"
13 #include "content/common/gpu/sync_point_manager.h" 13 #include "content/common/gpu/sync_point_manager.h"
14 #include "content/common/message_router.h" 14 #include "content/common/message_router.h"
15 #include "gpu/command_buffer/service/feature_info.h" 15 #include "gpu/command_buffer/service/feature_info.h"
16 #include "gpu/command_buffer/service/gpu_switches.h" 16 #include "gpu/command_buffer/service/gpu_switches.h"
17 #include "gpu/command_buffer/service/mailbox_manager.h" 17 #include "gpu/command_buffer/service/mailbox_manager.h"
18 #include "gpu/command_buffer/service/memory_program_cache.h" 18 #include "gpu/command_buffer/service/memory_program_cache.h"
19 #include "gpu/command_buffer/service/shader_translator_cache.h" 19 #include "gpu/command_buffer/service/shader_translator_cache.h"
20 #include "ipc/message_filter.h"
20 #include "ui/gl/gl_bindings.h" 21 #include "ui/gl/gl_bindings.h"
21 #include "ui/gl/gl_share_group.h" 22 #include "ui/gl/gl_share_group.h"
22 23
23 namespace content { 24 namespace content {
24 25
26 namespace {
27
28 class GpuChannelManagerMessageFilter : public IPC::MessageFilter {
29 public:
30 GpuChannelManagerMessageFilter(
31 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
32 : sender_(NULL), gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {}
33
34 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE {
35 DCHECK(!sender_);
36 sender_ = sender;
37 }
38
39 virtual void OnFilterRemoved() OVERRIDE {
40 DCHECK(sender_);
41 sender_ = NULL;
42 }
43
44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
45 DCHECK(sender_);
46 bool handled = true;
47 IPC_BEGIN_MESSAGE_MAP(GpuChannelManagerMessageFilter, message)
48 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
49 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP()
51 return handled;
52 }
53
54 protected:
55 virtual ~GpuChannelManagerMessageFilter() {}
56
57 void OnCreateGpuMemoryBuffer(const gfx::GpuMemoryBufferHandle& handle,
58 const gfx::Size& size,
59 unsigned internalformat,
60 unsigned usage) {
61 TRACE_EVENT2("gpu",
62 "GpuChannelManagerMessageFilter::OnCreateGpuMemoryBuffer",
63 "primary_id",
64 handle.global_id.primary_id,
65 "secondary_id",
66 handle.global_id.secondary_id);
67 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated(
68 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
69 handle, size, internalformat, usage)));
70 }
71
72 IPC::Sender* sender_;
73 GpuMemoryBufferFactory* gpu_memory_buffer_factory_;
74 };
75 }
76
25 GpuChannelManager::GpuMemoryBufferOperation::GpuMemoryBufferOperation( 77 GpuChannelManager::GpuMemoryBufferOperation::GpuMemoryBufferOperation(
26 int32 sync_point, 78 int32 sync_point,
27 base::Closure callback) 79 base::Closure callback)
28 : sync_point(sync_point), callback(callback) { 80 : sync_point(sync_point), callback(callback) {
29 } 81 }
30 82
31 GpuChannelManager::GpuMemoryBufferOperation::~GpuMemoryBufferOperation() { 83 GpuChannelManager::GpuMemoryBufferOperation::~GpuMemoryBufferOperation() {
32 } 84 }
33 85
34 GpuChannelManager::GpuChannelManager(MessageRouter* router, 86 GpuChannelManager::GpuChannelManager(MessageRouter* router,
35 GpuWatchdog* watchdog, 87 GpuWatchdog* watchdog,
36 base::MessageLoopProxy* io_message_loop, 88 base::MessageLoopProxy* io_message_loop,
37 base::WaitableEvent* shutdown_event) 89 base::WaitableEvent* shutdown_event,
90 IPC::SyncChannel* channel)
38 : weak_factory_(this), 91 : weak_factory_(this),
39 io_message_loop_(io_message_loop), 92 io_message_loop_(io_message_loop),
40 shutdown_event_(shutdown_event), 93 shutdown_event_(shutdown_event),
41 router_(router), 94 router_(router),
42 gpu_memory_manager_( 95 gpu_memory_manager_(
43 this, 96 this,
44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), 97 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit),
45 watchdog_(watchdog), 98 watchdog_(watchdog),
46 sync_point_manager_(new SyncPointManager), 99 sync_point_manager_(new SyncPointManager),
47 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()) { 100 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()),
101 channel_(channel),
102 filter_(new GpuChannelManagerMessageFilter(
103 gpu_memory_buffer_factory_.get())) {
48 DCHECK(router_); 104 DCHECK(router_);
49 DCHECK(io_message_loop); 105 DCHECK(io_message_loop);
50 DCHECK(shutdown_event); 106 DCHECK(shutdown_event);
107 channel_->AddFilter(filter_.get());
51 } 108 }
52 109
53 GpuChannelManager::~GpuChannelManager() { 110 GpuChannelManager::~GpuChannelManager() {
54 gpu_channels_.clear(); 111 gpu_channels_.clear();
55 if (default_offscreen_surface_.get()) { 112 if (default_offscreen_surface_.get()) {
56 default_offscreen_surface_->Destroy(); 113 default_offscreen_surface_->Destroy();
57 default_offscreen_surface_ = NULL; 114 default_offscreen_surface_ = NULL;
58 } 115 }
59 DCHECK(gpu_memory_buffer_operations_.empty()); 116 DCHECK(gpu_memory_buffer_operations_.empty());
60 } 117 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return iter->second; 160 return iter->second;
104 } 161 }
105 162
106 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { 163 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) {
107 bool handled = true; 164 bool handled = true;
108 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) 165 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg)
109 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) 166 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel)
110 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) 167 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
111 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, 168 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer,
112 OnCreateViewCommandBuffer) 169 OnCreateViewCommandBuffer)
113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) 170 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) 171 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
116 IPC_MESSAGE_UNHANDLED(handled = false) 172 IPC_MESSAGE_UNHANDLED(handled = false)
117 IPC_END_MESSAGE_MAP() 173 IPC_END_MESSAGE_MAP()
118 return handled; 174 return handled;
119 } 175 }
120 176
121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } 177 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); }
122 178
123 void GpuChannelManager::OnEstablishChannel(int client_id, 179 void GpuChannelManager::OnEstablishChannel(int client_id,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED; 237 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED;
182 238
183 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); 239 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id);
184 if (iter != gpu_channels_.end()) { 240 if (iter != gpu_channels_.end()) {
185 result = iter->second->CreateViewCommandBuffer( 241 result = iter->second->CreateViewCommandBuffer(
186 window, surface_id, init_params, route_id); 242 window, surface_id, init_params, route_id);
187 } 243 }
188 244
189 Send(new GpuHostMsg_CommandBufferCreated(result)); 245 Send(new GpuHostMsg_CommandBufferCreated(result));
190 } 246 }
191 247 void GpuChannelManager::DestroyGpuMemoryBuffer(
192 void GpuChannelManager::CreateGpuMemoryBuffer( 248 const gfx::GpuMemoryBufferHandle& handle) {
193 const gfx::GpuMemoryBufferHandle& handle, 249 io_message_loop_->PostTask(
194 const gfx::Size& size, 250 FROM_HERE,
195 unsigned internalformat, 251 base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO,
196 unsigned usage) { 252 base::Unretained(this),
197 Send(new GpuHostMsg_GpuMemoryBufferCreated( 253 handle));
198 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
199 handle, size, internalformat, usage)));
200 } 254 }
201 255
202 void GpuChannelManager::OnCreateGpuMemoryBuffer( 256 void GpuChannelManager::DestroyGpuMemoryBufferOnIO(
203 const gfx::GpuMemoryBufferHandle& handle,
204 const gfx::Size& size,
205 unsigned internalformat,
206 unsigned usage) {
207 if (gpu_memory_buffer_operations_.empty()) {
208 CreateGpuMemoryBuffer(handle, size, internalformat, usage);
209 } else {
piman 2014/09/04 17:21:33 Is this logic not needed any more? It used to be t
alexst (slow to review) 2014/09/04 17:46:02 These are identified by an int pair, one of which
210 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation(
211 0,
212 base::Bind(&GpuChannelManager::CreateGpuMemoryBuffer,
213 base::Unretained(this),
214 handle,
215 size,
216 internalformat,
217 usage)));
218 }
219 }
220
221 void GpuChannelManager::DestroyGpuMemoryBuffer(
222 const gfx::GpuMemoryBufferHandle& handle) { 257 const gfx::GpuMemoryBufferHandle& handle) {
223 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); 258 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle);
224 } 259 }
225 260
226 void GpuChannelManager::OnDestroyGpuMemoryBuffer( 261 void GpuChannelManager::OnDestroyGpuMemoryBuffer(
227 const gfx::GpuMemoryBufferHandle& handle, 262 const gfx::GpuMemoryBufferHandle& handle,
228 int32 sync_point) { 263 int32 sync_point) {
229 if (!sync_point && gpu_memory_buffer_operations_.empty()) { 264 if (!sync_point && gpu_memory_buffer_operations_.empty()) {
230 DestroyGpuMemoryBuffer(handle); 265 DestroyGpuMemoryBuffer(handle);
231 } else { 266 } else {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 338
304 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { 339 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() {
305 if (!default_offscreen_surface_.get()) { 340 if (!default_offscreen_surface_.get()) {
306 default_offscreen_surface_ = 341 default_offscreen_surface_ =
307 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); 342 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size());
308 } 343 }
309 return default_offscreen_surface_.get(); 344 return default_offscreen_surface_.get();
310 } 345 }
311 346
312 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_channel_manager.h ('k') | content/gpu/gpu_child_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698