Index: content/common/gpu/gpu_channel_manager.cc |
diff --git a/content/common/gpu/gpu_channel_manager.cc b/content/common/gpu/gpu_channel_manager.cc |
index 899da86e45f047842ab902387c699c612cdb8844..dfc09cb83cf9df88a51e93a9ddc813f3a19f5bc3 100644 |
--- a/content/common/gpu/gpu_channel_manager.cc |
+++ b/content/common/gpu/gpu_channel_manager.cc |
@@ -6,6 +6,7 @@ |
#include "base/bind.h" |
#include "base/command_line.h" |
+#include "base/lazy_instance.h" |
#include "content/common/gpu/gpu_channel.h" |
#include "content/common/gpu/gpu_memory_manager.h" |
#include "content/common/gpu/gpu_messages.h" |
@@ -19,7 +20,57 @@ |
#include "ui/gl/gl_bindings.h" |
#include "ui/gl/gl_share_group.h" |
+#if defined(USE_X11) |
+#include "ui/gl/x11_pixmap_tracker.h" |
+#endif |
+ |
namespace content { |
+namespace { |
+ |
+#if defined(USE_X11) |
+class X11PixmapTrackerImpl : public gfx::X11PixmapTracker { |
+ public: |
+ // Overridden from gfx::X11PixmapTracker: |
+ virtual XID AcquirePixmap(int primary_id, int secondary_id) OVERRIDE { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ X11PixmapMapKey key(primary_id, secondary_id); |
+ X11PixmapMap::iterator it = pixmaps_.find(key); |
+ if (it == pixmaps_.end()) |
+ return 0; |
+ XID pixmap = it->second; |
+ pixmaps_.erase(it); |
+ return pixmap; |
+ } |
+ |
+ void AddPixmap(XID pixmap, int pixmap_id, int child_process_id) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ X11PixmapMapKey key(pixmap_id, child_process_id); |
+ DCHECK(pixmaps_.find(key) == pixmaps_.end()); |
+ pixmaps_[key] = pixmap; |
+ } |
+ |
+ void RemoveAllPixmaps(int child_process_id) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ X11PixmapMap::iterator it = pixmaps_.begin(); |
+ while (it != pixmaps_.end()) { |
+ if (it->first.second == child_process_id) |
+ pixmaps_.erase(it++); |
+ else |
+ ++it; |
+ } |
+ } |
+ |
+ private: |
+ typedef std::pair<int, int> X11PixmapMapKey; |
+ typedef base::hash_map<X11PixmapMapKey, XID> X11PixmapMap; |
+ X11PixmapMap pixmaps_; |
+ base::ThreadChecker thread_checker_; |
+}; |
+base::LazyInstance<X11PixmapTrackerImpl> g_x11_pixmap_tracker = |
+ 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
|
+#endif |
+ |
+} // namespace |
GpuChannelManager::ImageOperation::ImageOperation( |
int32 sync_point, base::Closure callback) |
@@ -46,6 +97,9 @@ GpuChannelManager::GpuChannelManager(MessageRouter* router, |
DCHECK(router_); |
DCHECK(io_message_loop); |
DCHECK(shutdown_event); |
+#if defined(USE_X11) |
+ gfx::X11PixmapTracker::InitInstance(g_x11_pixmap_tracker.Pointer()); |
+#endif |
} |
GpuChannelManager::~GpuChannelManager() { |
@@ -158,6 +212,9 @@ void GpuChannelManager::OnCloseChannel( |
for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
iter != gpu_channels_.end(); ++iter) { |
if (iter->second->GetChannelName() == channel_handle.name) { |
+#if defined(USE_X11) |
+ g_x11_pixmap_tracker.Pointer()->RemoveAllPixmaps(iter->first); |
+#endif |
gpu_channels_.erase(iter); |
return; |
} |
@@ -183,28 +240,48 @@ void GpuChannelManager::OnCreateViewCommandBuffer( |
} |
void GpuChannelManager::CreateImage( |
- gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { |
- gfx::Size size; |
- |
- GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
- if (iter != gpu_channels_.end()) { |
- iter->second->CreateImage(window, image_id, &size); |
+ const gfx::GpuMemoryBufferHandle& handle, |
+ const gfx::Size& size, |
+ unsigned internalformat, |
+ int32 client_id, |
+ int32 image_id) { |
+ switch (handle.type) { |
+#if defined(USE_X11) |
+ case gfx::X11_PIXMAP_BUFFER: |
+ g_x11_pixmap_tracker.Pointer()->AddPixmap(handle.pixmap, |
+ handle.global_id.primary_id, |
+ handle.global_id.secondary_id); |
+ break; |
+#endif |
+ default: |
+ NOTIMPLEMENTED(); |
+ break; |
} |
- Send(new GpuHostMsg_ImageCreated(size)); |
+ GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
+ Send(new GpuHostMsg_ImageCreated( |
+ iter != gpu_channels_.end() |
+ ? iter->second->CreateImage(handle, size, internalformat, image_id) |
+ : false)); |
} |
void GpuChannelManager::OnCreateImage( |
- gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { |
+ const gfx::GpuMemoryBufferHandle& handle, |
+ const gfx::Size& size, |
+ unsigned internalformat, |
+ int32 client_id, |
+ int32 image_id) { |
DCHECK(image_id); |
if (image_operations_.empty()) { |
- CreateImage(window, client_id, image_id); |
+ CreateImage(handle, size, internalformat, client_id, image_id); |
} else { |
image_operations_.push_back( |
new ImageOperation(0, base::Bind(&GpuChannelManager::CreateImage, |
base::Unretained(this), |
- window, |
+ handle, |
+ size, |
+ internalformat, |
client_id, |
image_id))); |
} |