Index: content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.cc |
diff --git a/content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.cc b/content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b75411314c9d7888d09b4211c5ff5b3bde8301b2 |
--- /dev/null |
+++ b/content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.cc |
@@ -0,0 +1,86 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.h" |
+ |
+#include "base/containers/hash_tables.h" |
+#include "base/lazy_instance.h" |
+#include "base/threading/thread_checker.h" |
+ |
+#if defined(USE_X11) |
+#include "ui/gl/x11_pixmap_tracker.h" |
+#endif |
+ |
+namespace content { |
+namespace { |
+ |
+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 client_id) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ X11PixmapMapKey key(pixmap_id, client_id); |
+ DCHECK(pixmaps_.find(key) == pixmaps_.end()); |
+ pixmaps_[key] = pixmap; |
+ } |
+ |
+ void RemovePixmap(int pixmap_id, int client_id) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ X11PixmapMapKey key(pixmap_id, client_id); |
+ X11PixmapMap::iterator it = pixmaps_.find(key); |
+ if (it != pixmaps_.end()) |
+ pixmaps_.erase(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; |
+ |
+} // namespace |
+ |
+// static |
+void GpuMemoryBufferFactoryX11Pixmap::Initialize() { |
+ gfx::X11PixmapTracker::InitInstance(g_x11_pixmap_tracker.Pointer()); |
+} |
+ |
+// static |
+void GpuMemoryBufferFactoryX11Pixmap::CreateGpuMemoryBuffer( |
+ const gfx::GpuMemoryBufferHandle& handle) { |
+ g_x11_pixmap_tracker.Pointer()->AddPixmap(handle.pixmap, |
+ handle.global_id.primary_id, |
+ handle.global_id.secondary_id); |
+} |
+ |
+// static |
+void GpuMemoryBufferFactoryX11Pixmap::DestroyGpuMemoryBuffer( |
+ const gfx::GpuMemoryBufferHandle& handle) { |
+ g_x11_pixmap_tracker.Pointer()->RemovePixmap(handle.global_id.primary_id, |
+ handle.global_id.secondary_id); |
+} |
+ |
+// static |
+bool GpuMemoryBufferFactoryX11Pixmap::RequestAccessToGpuMemoryBuffer( |
+ const gfx::GpuMemoryBufferHandle& handle, |
+ int client_id) { |
+ return handle.global_id.secondary_id == client_id; |
+} |
+ |
+} // namespace content |