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

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: include x11 pixmap tracker Created 6 years, 6 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 "base/lazy_instance.h"
9 #include "content/common/gpu/gpu_channel.h" 10 #include "content/common/gpu/gpu_channel.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
23 #if defined(USE_X11)
24 #include "ui/gl/x11_pixmap_tracker.h"
25 #endif
26
22 namespace content { 27 namespace content {
28 namespace {
29
30 #if defined(USE_X11)
31 class X11PixmapTrackerImpl : public gfx::X11PixmapTracker {
32 public:
33 // Overridden from gfx::X11PixmapTracker:
34 virtual XID AcquirePixmap(int primary_id, int secondary_id) OVERRIDE {
35 DCHECK(thread_checker_.CalledOnValidThread());
36 X11PixmapMapKey key(primary_id, secondary_id);
37 X11PixmapMap::iterator it = pixmaps_.find(key);
38 if (it == pixmaps_.end())
39 return 0;
40 XID pixmap = it->second;
41 pixmaps_.erase(it);
42 return pixmap;
43 }
44
45 void AddPixmap(XID pixmap, int pixmap_id, int child_process_id) {
46 DCHECK(thread_checker_.CalledOnValidThread());
47 X11PixmapMapKey key(pixmap_id, child_process_id);
48 DCHECK(pixmaps_.find(key) == pixmaps_.end());
49 pixmaps_[key] = pixmap;
50 }
51
52 void RemoveAllPixmaps(int child_process_id) {
53 DCHECK(thread_checker_.CalledOnValidThread());
54 X11PixmapMap::iterator it = pixmaps_.begin();
55 while (it != pixmaps_.end()) {
56 if (it->first.second == child_process_id)
57 pixmaps_.erase(it++);
58 else
59 ++it;
60 }
61 }
62
63 private:
64 typedef std::pair<int, int> X11PixmapMapKey;
65 typedef base::hash_map<X11PixmapMapKey, XID> X11PixmapMap;
66 X11PixmapMap pixmaps_;
67 base::ThreadChecker thread_checker_;
68 };
69 base::LazyInstance<X11PixmapTrackerImpl> g_x11_pixmap_tracker =
70 LAZY_INSTANCE_INITIALIZER;
piman 2014/06/13 17:14:21 Why not simply making it a member of GpuChannelMan
reveman 2014/06/13 18:50:34 No other reason than hiding as much as possible in
71 #endif
72
73 } // namespace
23 74
24 GpuChannelManager::ImageOperation::ImageOperation( 75 GpuChannelManager::ImageOperation::ImageOperation(
25 int32 sync_point, base::Closure callback) 76 int32 sync_point, base::Closure callback)
26 : sync_point(sync_point), 77 : sync_point(sync_point),
27 callback(callback) { 78 callback(callback) {
28 } 79 }
29 80
30 GpuChannelManager::ImageOperation::~ImageOperation() { 81 GpuChannelManager::ImageOperation::~ImageOperation() {
31 } 82 }
32 83
33 GpuChannelManager::GpuChannelManager(MessageRouter* router, 84 GpuChannelManager::GpuChannelManager(MessageRouter* router,
34 GpuWatchdog* watchdog, 85 GpuWatchdog* watchdog,
35 base::MessageLoopProxy* io_message_loop, 86 base::MessageLoopProxy* io_message_loop,
36 base::WaitableEvent* shutdown_event) 87 base::WaitableEvent* shutdown_event)
37 : weak_factory_(this), 88 : weak_factory_(this),
38 io_message_loop_(io_message_loop), 89 io_message_loop_(io_message_loop),
39 shutdown_event_(shutdown_event), 90 shutdown_event_(shutdown_event),
40 router_(router), 91 router_(router),
41 gpu_memory_manager_( 92 gpu_memory_manager_(
42 this, 93 this,
43 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), 94 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit),
44 watchdog_(watchdog), 95 watchdog_(watchdog),
45 sync_point_manager_(new SyncPointManager) { 96 sync_point_manager_(new SyncPointManager) {
46 DCHECK(router_); 97 DCHECK(router_);
47 DCHECK(io_message_loop); 98 DCHECK(io_message_loop);
48 DCHECK(shutdown_event); 99 DCHECK(shutdown_event);
100 #if defined(USE_X11)
101 gfx::X11PixmapTracker::InitInstance(g_x11_pixmap_tracker.Pointer());
102 #endif
49 } 103 }
50 104
51 GpuChannelManager::~GpuChannelManager() { 105 GpuChannelManager::~GpuChannelManager() {
52 gpu_channels_.clear(); 106 gpu_channels_.clear();
53 if (default_offscreen_surface_.get()) { 107 if (default_offscreen_surface_.get()) {
54 default_offscreen_surface_->Destroy(); 108 default_offscreen_surface_->Destroy();
55 default_offscreen_surface_ = NULL; 109 default_offscreen_surface_ = NULL;
56 } 110 }
57 DCHECK(image_operations_.empty()); 111 DCHECK(image_operations_.empty());
58 } 112 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 gpu_channels_.set(client_id, channel.Pass()); 205 gpu_channels_.set(client_id, channel.Pass());
152 206
153 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); 207 Send(new GpuHostMsg_ChannelEstablished(channel_handle));
154 } 208 }
155 209
156 void GpuChannelManager::OnCloseChannel( 210 void GpuChannelManager::OnCloseChannel(
157 const IPC::ChannelHandle& channel_handle) { 211 const IPC::ChannelHandle& channel_handle) {
158 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); 212 for (GpuChannelMap::iterator iter = gpu_channels_.begin();
159 iter != gpu_channels_.end(); ++iter) { 213 iter != gpu_channels_.end(); ++iter) {
160 if (iter->second->GetChannelName() == channel_handle.name) { 214 if (iter->second->GetChannelName() == channel_handle.name) {
215 #if defined(USE_X11)
216 g_x11_pixmap_tracker.Pointer()->RemoveAllPixmaps(iter->first);
217 #endif
161 gpu_channels_.erase(iter); 218 gpu_channels_.erase(iter);
162 return; 219 return;
163 } 220 }
164 } 221 }
165 } 222 }
166 223
167 void GpuChannelManager::OnCreateViewCommandBuffer( 224 void GpuChannelManager::OnCreateViewCommandBuffer(
168 const gfx::GLSurfaceHandle& window, 225 const gfx::GLSurfaceHandle& window,
169 int32 surface_id, 226 int32 surface_id,
170 int32 client_id, 227 int32 client_id,
171 const GPUCreateCommandBufferConfig& init_params, 228 const GPUCreateCommandBufferConfig& init_params,
172 int32 route_id) { 229 int32 route_id) {
173 DCHECK(surface_id); 230 DCHECK(surface_id);
174 bool succeeded = false; 231 bool succeeded = false;
175 232
176 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); 233 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id);
177 if (iter != gpu_channels_.end()) { 234 if (iter != gpu_channels_.end()) {
178 succeeded = iter->second->CreateViewCommandBuffer( 235 succeeded = iter->second->CreateViewCommandBuffer(
179 window, surface_id, init_params, route_id); 236 window, surface_id, init_params, route_id);
180 } 237 }
181 238
182 Send(new GpuHostMsg_CommandBufferCreated(succeeded)); 239 Send(new GpuHostMsg_CommandBufferCreated(succeeded));
183 } 240 }
184 241
185 void GpuChannelManager::CreateImage( 242 void GpuChannelManager::CreateImage(
186 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { 243 const gfx::GpuMemoryBufferHandle& handle,
187 gfx::Size size; 244 const gfx::Size& size,
245 unsigned internalformat,
246 int32 client_id,
247 int32 image_id) {
248 switch (handle.type) {
249 #if defined(USE_X11)
250 case gfx::X11_PIXMAP_BUFFER:
251 g_x11_pixmap_tracker.Pointer()->AddPixmap(handle.pixmap,
252 handle.global_id.primary_id,
253 handle.global_id.secondary_id);
254 break;
255 #endif
256 default:
257 NOTIMPLEMENTED();
258 break;
259 }
188 260
189 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); 261 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id);
190 if (iter != gpu_channels_.end()) { 262 Send(new GpuHostMsg_ImageCreated(
191 iter->second->CreateImage(window, image_id, &size); 263 iter != gpu_channels_.end()
192 } 264 ? iter->second->CreateImage(handle, size, internalformat, image_id)
193 265 : false));
194 Send(new GpuHostMsg_ImageCreated(size));
195 } 266 }
196 267
197 void GpuChannelManager::OnCreateImage( 268 void GpuChannelManager::OnCreateImage(
198 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { 269 const gfx::GpuMemoryBufferHandle& handle,
270 const gfx::Size& size,
271 unsigned internalformat,
272 int32 client_id,
273 int32 image_id) {
199 DCHECK(image_id); 274 DCHECK(image_id);
200 275
201 if (image_operations_.empty()) { 276 if (image_operations_.empty()) {
202 CreateImage(window, client_id, image_id); 277 CreateImage(handle, size, internalformat, client_id, image_id);
203 } else { 278 } else {
204 image_operations_.push_back( 279 image_operations_.push_back(
205 new ImageOperation(0, base::Bind(&GpuChannelManager::CreateImage, 280 new ImageOperation(0, base::Bind(&GpuChannelManager::CreateImage,
206 base::Unretained(this), 281 base::Unretained(this),
207 window, 282 handle,
283 size,
284 internalformat,
208 client_id, 285 client_id,
209 image_id))); 286 image_id)));
210 } 287 }
211 } 288 }
212 289
213 void GpuChannelManager::DeleteImage(int32 client_id, int32 image_id) { 290 void GpuChannelManager::DeleteImage(int32 client_id, int32 image_id) {
214 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); 291 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id);
215 if (iter != gpu_channels_.end()) { 292 if (iter != gpu_channels_.end()) {
216 iter->second->DeleteImage(image_id); 293 iter->second->DeleteImage(image_id);
217 } 294 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 388
312 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { 389 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() {
313 if (!default_offscreen_surface_.get()) { 390 if (!default_offscreen_surface_.get()) {
314 default_offscreen_surface_ = 391 default_offscreen_surface_ =
315 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); 392 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size());
316 } 393 }
317 return default_offscreen_surface_.get(); 394 return default_offscreen_surface_.get();
318 } 395 }
319 396
320 } // namespace content 397 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698