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

Side by Side Diff: content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.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: Add GpuMemoryBufferFactory interface 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/common/gpu/gpu_memory_buffer_factory_x11_pixmap.h"
6
7 #include "base/containers/hash_tables.h"
8 #include "base/lazy_instance.h"
9 #include "base/threading/thread_checker.h"
10
11 #if defined(USE_X11)
12 #include "ui/gl/x11_pixmap_tracker.h"
13 #endif
14
15 namespace content {
16 namespace {
17
18 class X11PixmapTrackerImpl : public gfx::X11PixmapTracker {
19 public:
20 // Overridden from gfx::X11PixmapTracker:
21 virtual XID AcquirePixmap(int primary_id, int secondary_id) OVERRIDE {
22 DCHECK(thread_checker_.CalledOnValidThread());
23 X11PixmapMapKey key(primary_id, secondary_id);
24 X11PixmapMap::iterator it = pixmaps_.find(key);
25 if (it == pixmaps_.end())
26 return 0;
27 XID pixmap = it->second;
28 pixmaps_.erase(it);
29 return pixmap;
30 }
31
32 void AddPixmap(XID pixmap, int pixmap_id, int client_id) {
33 DCHECK(thread_checker_.CalledOnValidThread());
34 X11PixmapMapKey key(pixmap_id, client_id);
35 DCHECK(pixmaps_.find(key) == pixmaps_.end());
36 pixmaps_[key] = pixmap;
37 }
38
39 void RemovePixmap(int pixmap_id, int client_id) {
40 DCHECK(thread_checker_.CalledOnValidThread());
41 X11PixmapMapKey key(pixmap_id, client_id);
42 X11PixmapMap::iterator it = pixmaps_.find(key);
43 if (it != pixmaps_.end())
44 pixmaps_.erase(it);
45 }
46
47 private:
48 typedef std::pair<int, int> X11PixmapMapKey;
49 typedef base::hash_map<X11PixmapMapKey, XID> X11PixmapMap;
50 X11PixmapMap pixmaps_;
51 base::ThreadChecker thread_checker_;
52 };
53
54 base::LazyInstance<X11PixmapTrackerImpl> g_x11_pixmap_tracker =
55 LAZY_INSTANCE_INITIALIZER;
56
57 } // namespace
58
59 // static
60 void GpuMemoryBufferFactoryX11Pixmap::Initialize() {
61 gfx::X11PixmapTracker::InitInstance(g_x11_pixmap_tracker.Pointer());
62 }
63
64 // static
65 void GpuMemoryBufferFactoryX11Pixmap::CreateGpuMemoryBuffer(
66 const gfx::GpuMemoryBufferHandle& handle) {
67 g_x11_pixmap_tracker.Pointer()->AddPixmap(handle.pixmap,
68 handle.global_id.primary_id,
69 handle.global_id.secondary_id);
70 }
71
72 // static
73 void GpuMemoryBufferFactoryX11Pixmap::DestroyGpuMemoryBuffer(
74 const gfx::GpuMemoryBufferHandle& handle) {
75 g_x11_pixmap_tracker.Pointer()->RemovePixmap(handle.global_id.primary_id,
76 handle.global_id.secondary_id);
77 }
78
79 // static
80 bool GpuMemoryBufferFactoryX11Pixmap::RequestAccessToGpuMemoryBuffer(
81 const gfx::GpuMemoryBufferHandle& handle,
82 int client_id) {
83 return handle.global_id.secondary_id == client_id;
84 }
85
86 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698