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

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

Issue 331723003: gpu: Remove Create/DeleteImage IPC by adding an X11_PIXMAP_BUFFER GpuMemoryBuffer type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wip Created 6 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 | Annotate | Revision Log
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_manager.h" 11 #include "content/common/gpu/gpu_memory_manager.h"
11 #include "content/common/gpu/gpu_messages.h" 12 #include "content/common/gpu/gpu_messages.h"
12 #include "content/common/gpu/sync_point_manager.h" 13 #include "content/common/gpu/sync_point_manager.h"
13 #include "content/common/message_router.h" 14 #include "content/common/message_router.h"
14 #include "gpu/command_buffer/service/feature_info.h" 15 #include "gpu/command_buffer/service/feature_info.h"
15 #include "gpu/command_buffer/service/gpu_switches.h" 16 #include "gpu/command_buffer/service/gpu_switches.h"
16 #include "gpu/command_buffer/service/mailbox_manager.h" 17 #include "gpu/command_buffer/service/mailbox_manager.h"
17 #include "gpu/command_buffer/service/memory_program_cache.h" 18 #include "gpu/command_buffer/service/memory_program_cache.h"
18 #include "gpu/command_buffer/service/shader_translator_cache.h" 19 #include "gpu/command_buffer/service/shader_translator_cache.h"
19 #include "ui/gl/gl_bindings.h" 20 #include "ui/gl/gl_bindings.h"
20 #include "ui/gl/gl_share_group.h" 21 #include "ui/gl/gl_share_group.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 GpuChannelManager::ImageOperation::ImageOperation( 25 GpuChannelManager::GpuMemoryBufferOperation::GpuMemoryBufferOperation(
25 int32 sync_point, base::Closure callback) 26 int32 sync_point,
26 : sync_point(sync_point), 27 base::Closure callback)
27 callback(callback) { 28 : sync_point(sync_point), callback(callback) {
28 } 29 }
29 30
30 GpuChannelManager::ImageOperation::~ImageOperation() { 31 GpuChannelManager::GpuMemoryBufferOperation::~GpuMemoryBufferOperation() {
31 } 32 }
32 33
33 GpuChannelManager::GpuChannelManager(MessageRouter* router, 34 GpuChannelManager::GpuChannelManager(MessageRouter* router,
34 GpuWatchdog* watchdog, 35 GpuWatchdog* watchdog,
35 base::MessageLoopProxy* io_message_loop, 36 base::MessageLoopProxy* io_message_loop,
36 base::WaitableEvent* shutdown_event) 37 base::WaitableEvent* shutdown_event)
37 : weak_factory_(this), 38 : weak_factory_(this),
38 io_message_loop_(io_message_loop), 39 io_message_loop_(io_message_loop),
39 shutdown_event_(shutdown_event), 40 shutdown_event_(shutdown_event),
40 router_(router), 41 router_(router),
41 gpu_memory_manager_( 42 gpu_memory_manager_(
42 this, 43 this,
43 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), 44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit),
44 watchdog_(watchdog), 45 watchdog_(watchdog),
45 sync_point_manager_(new SyncPointManager) { 46 sync_point_manager_(new SyncPointManager),
47 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()) {
46 DCHECK(router_); 48 DCHECK(router_);
47 DCHECK(io_message_loop); 49 DCHECK(io_message_loop);
48 DCHECK(shutdown_event); 50 DCHECK(shutdown_event);
49 } 51 }
50 52
51 GpuChannelManager::~GpuChannelManager() { 53 GpuChannelManager::~GpuChannelManager() {
52 gpu_channels_.clear(); 54 gpu_channels_.clear();
53 if (default_offscreen_surface_.get()) { 55 if (default_offscreen_surface_.get()) {
54 default_offscreen_surface_->Destroy(); 56 default_offscreen_surface_->Destroy();
55 default_offscreen_surface_ = NULL; 57 default_offscreen_surface_ = NULL;
56 } 58 }
57 DCHECK(image_operations_.empty()); 59 DCHECK(gpu_memory_buffer_operations_.empty());
58 } 60 }
59 61
60 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { 62 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() {
61 if (!program_cache_.get() && 63 if (!program_cache_.get() &&
62 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || 64 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary ||
63 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && 65 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) &&
64 !CommandLine::ForCurrentProcess()->HasSwitch( 66 !CommandLine::ForCurrentProcess()->HasSwitch(
65 switches::kDisableGpuProgramCache)) { 67 switches::kDisableGpuProgramCache)) {
66 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); 68 program_cache_.reset(new gpu::gles2::MemoryProgramCache());
67 } 69 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return iter->second; 103 return iter->second;
102 } 104 }
103 105
104 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { 106 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) {
105 bool handled = true; 107 bool handled = true;
106 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) 108 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg)
107 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) 109 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel)
108 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) 110 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
109 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, 111 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer,
110 OnCreateViewCommandBuffer) 112 OnCreateViewCommandBuffer)
111 IPC_MESSAGE_HANDLER(GpuMsg_CreateImage, OnCreateImage)
112 IPC_MESSAGE_HANDLER(GpuMsg_DeleteImage, OnDeleteImage)
113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) 113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) 114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) 115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
116 IPC_MESSAGE_UNHANDLED(handled = false) 116 IPC_MESSAGE_UNHANDLED(handled = false)
117 IPC_END_MESSAGE_MAP() 117 IPC_END_MESSAGE_MAP()
118 return handled; 118 return handled;
119 } 119 }
120 120
121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } 121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); }
122 122
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); 176 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id);
177 if (iter != gpu_channels_.end()) { 177 if (iter != gpu_channels_.end()) {
178 succeeded = iter->second->CreateViewCommandBuffer( 178 succeeded = iter->second->CreateViewCommandBuffer(
179 window, surface_id, init_params, route_id); 179 window, surface_id, init_params, route_id);
180 } 180 }
181 181
182 Send(new GpuHostMsg_CommandBufferCreated(succeeded)); 182 Send(new GpuHostMsg_CommandBufferCreated(succeeded));
183 } 183 }
184 184
185 void GpuChannelManager::CreateImage( 185 void GpuChannelManager::CreateGpuMemoryBuffer(
186 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { 186 const gfx::GpuMemoryBufferHandle& handle,
187 gfx::Size size; 187 const gfx::Size& size,
188 188 unsigned internalformat,
189 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); 189 unsigned usage) {
190 if (iter != gpu_channels_.end()) { 190 if (gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
191 iter->second->CreateImage(window, image_id, &size); 191 handle, size, internalformat, usage)) {
192 } 192 Send(new GpuHostMsg_GpuMemoryBufferCreated(handle));
193
194 Send(new GpuHostMsg_ImageCreated(size));
195 }
196
197 void GpuChannelManager::OnCreateImage(
198 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) {
199 DCHECK(image_id);
200
201 if (image_operations_.empty()) {
202 CreateImage(window, client_id, image_id);
203 } else { 193 } else {
204 image_operations_.push_back( 194 Send(new GpuHostMsg_GpuMemoryBufferCreated(gfx::GpuMemoryBufferHandle()));
205 new ImageOperation(0, base::Bind(&GpuChannelManager::CreateImage,
206 base::Unretained(this),
207 window,
208 client_id,
209 image_id)));
210 }
211 }
212
213 void GpuChannelManager::DeleteImage(int32 client_id, int32 image_id) {
214 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id);
215 if (iter != gpu_channels_.end()) {
216 iter->second->DeleteImage(image_id);
217 }
218 }
219
220 void GpuChannelManager::OnDeleteImage(
221 int32 client_id, int32 image_id, int32 sync_point) {
222 DCHECK(image_id);
223
224 if (!sync_point && image_operations_.empty()) {
225 DeleteImage(client_id, image_id);
226 } else {
227 image_operations_.push_back(
228 new ImageOperation(sync_point,
229 base::Bind(&GpuChannelManager::DeleteImage,
230 base::Unretained(this),
231 client_id,
232 image_id)));
233 if (sync_point) {
234 sync_point_manager()->AddSyncPointCallback(
235 sync_point,
236 base::Bind(&GpuChannelManager::OnDeleteImageSyncPointRetired,
237 base::Unretained(this),
238 image_operations_.back()));
239 }
240 }
241 }
242
243 void GpuChannelManager::OnDeleteImageSyncPointRetired(
244 ImageOperation* image_operation) {
245 // Mark operation as no longer having a pending sync point.
246 image_operation->sync_point = 0;
247
248 // De-queue operations until we reach a pending sync point.
249 while (!image_operations_.empty()) {
250 // Check if operation has a pending sync point.
251 if (image_operations_.front()->sync_point)
252 return;
253
254 image_operations_.front()->callback.Run();
255 delete image_operations_.front();
256 image_operations_.pop_front();
257 } 195 }
258 } 196 }
259 197
260 void GpuChannelManager::OnCreateGpuMemoryBuffer( 198 void GpuChannelManager::OnCreateGpuMemoryBuffer(
261 const gfx::GpuMemoryBufferHandle& handle, 199 const gfx::GpuMemoryBufferHandle& handle,
262 const gfx::Size& size, 200 const gfx::Size& size,
263 unsigned internalformat, 201 unsigned internalformat,
264 unsigned usage) { 202 unsigned usage) {
265 Send(new GpuHostMsg_GpuMemoryBufferCreated(gfx::GpuMemoryBufferHandle())); 203 if (gpu_memory_buffer_operations_.empty()) {
204 CreateGpuMemoryBuffer(handle, size, internalformat, usage);
205 } else {
206 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation(
207 0,
208 base::Bind(&GpuChannelManager::CreateGpuMemoryBuffer,
209 base::Unretained(this),
210 handle,
211 size,
212 internalformat,
213 usage)));
214 }
215 }
216
217 void GpuChannelManager::DestroyGpuMemoryBuffer(
218 const gfx::GpuMemoryBufferHandle& handle) {
219 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle);
266 } 220 }
267 221
268 void GpuChannelManager::OnDestroyGpuMemoryBuffer( 222 void GpuChannelManager::OnDestroyGpuMemoryBuffer(
269 const gfx::GpuMemoryBufferHandle& handle, 223 const gfx::GpuMemoryBufferHandle& handle,
270 int32 sync_point) { 224 int32 sync_point) {
225 if (!sync_point && gpu_memory_buffer_operations_.empty()) {
226 DestroyGpuMemoryBuffer(handle);
227 } else {
228 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation(
229 sync_point,
230 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer,
231 base::Unretained(this),
232 handle)));
233 if (sync_point) {
234 sync_point_manager()->AddSyncPointCallback(
235 sync_point,
236 base::Bind(
237 &GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired,
238 base::Unretained(this),
239 gpu_memory_buffer_operations_.back()));
240 }
241 }
242 }
243
244 void GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired(
245 GpuMemoryBufferOperation* gpu_memory_buffer_operation) {
246 // Mark operation as no longer having a pending sync point.
247 gpu_memory_buffer_operation->sync_point = 0;
248
249 // De-queue operations until we reach a pending sync point.
250 while (!gpu_memory_buffer_operations_.empty()) {
251 // Check if operation has a pending sync point.
252 if (gpu_memory_buffer_operations_.front()->sync_point)
253 break;
254
255 gpu_memory_buffer_operations_.front()->callback.Run();
256 delete gpu_memory_buffer_operations_.front();
257 gpu_memory_buffer_operations_.pop_front();
258 }
271 } 259 }
272 260
273 void GpuChannelManager::OnLoadedShader(std::string program_proto) { 261 void GpuChannelManager::OnLoadedShader(std::string program_proto) {
274 if (program_cache()) 262 if (program_cache())
275 program_cache()->LoadProgram(program_proto); 263 program_cache()->LoadProgram(program_proto);
276 } 264 }
277 265
278 bool GpuChannelManager::HandleMessagesScheduled() { 266 bool GpuChannelManager::HandleMessagesScheduled() {
279 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); 267 for (GpuChannelMap::iterator iter = gpu_channels_.begin();
280 iter != gpu_channels_.end(); ++iter) { 268 iter != gpu_channels_.end(); ++iter) {
(...skipping 30 matching lines...) Expand all
311 299
312 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { 300 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() {
313 if (!default_offscreen_surface_.get()) { 301 if (!default_offscreen_surface_.get()) {
314 default_offscreen_surface_ = 302 default_offscreen_surface_ =
315 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); 303 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size());
316 } 304 }
317 return default_offscreen_surface_.get(); 305 return default_offscreen_surface_.get();
318 } 306 }
319 307
320 } // namespace content 308 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698