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

Side by Side Diff: content/browser/gpu/browser_native_pixmap_manager_ozone.cc

Issue 1248713002: ozone: ClientPixmapManager passes VGEM fd from browser to renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to lastest crrev.com/1128113011 Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 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/browser/gpu/browser_native_pixmap_manager_ozone.h"
6
7 #include "base/memory/singleton.h"
8 #include "base/posix/eintr_wrapper.h"
9 #include "content/common/gpu/native_pixmap_manager_ozone_messages.h"
10 #include "content/public/browser/browser_message_filter.h"
11 #include "ui/ozone/public/ozone_platform.h"
12
13 namespace content {
14
15 namespace {
16
17 class BrowserNativePixmapManagerMessageFilter : public BrowserMessageFilter {
18 public:
19 explicit BrowserNativePixmapManagerMessageFilter(
20 BrowserNativePixmapManager* manager)
21 : BrowserMessageFilter(BrowserNativePixmapManagerMsgStart),
22 manager_(manager) {}
23
24 bool OnMessageReceived(const IPC::Message& message) override {
25 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP(BrowserNativePixmapManagerMessageFilter, message)
27 IPC_MESSAGE_HANDLER_DELAY_REPLY(
28 BrowserNativePixmapManagerMsg_SyncGetVirtualDevice,
29 OnGetVirtualDevice)
30 IPC_MESSAGE_UNHANDLED(handled = false)
31 IPC_END_MESSAGE_MAP()
32 return handled;
33 }
34
35 private:
36 ~BrowserNativePixmapManagerMessageFilter() override {}
37
38 void OnGetVirtualDevice(IPC::Message* reply) {
39 DCHECK(manager_);
40 manager_->GetVirtualDeviceForChildProcess(base::Bind(
41 &BrowserNativePixmapManagerMessageFilter::VirtualDeviceRelpied, this,
42 reply));
43 }
44 void VirtualDeviceRelpied(IPC::Message* reply,
45 const base::FileDescriptor& device) {
46 DCHECK_CURRENTLY_ON(BrowserThread::IO);
47 BrowserNativePixmapManagerMsg_SyncGetVirtualDevice::WriteReplyParams(
48 reply, device);
49 Send(reply);
50 }
51
52 BrowserNativePixmapManager* manager_;
53
54 DISALLOW_COPY_AND_ASSIGN(BrowserNativePixmapManagerMessageFilter);
55 };
56
57 void DupVirtualDeviceFd(
58 int device_fd,
59 const BrowserNativePixmapManager::FileDescriptorCallback& callback) {
60 int duped_fd = -1;
61 base::ThreadRestrictions::AssertIOAllowed();
62 duped_fd = HANDLE_EINTR(dup(device_fd));
63 if (duped_fd < 0) {
64 PLOG(ERROR) << "dup() failed.";
65 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
66 base::Bind(callback, base::FileDescriptor()));
67 return;
68 }
69
70 BrowserThread::PostTask(
71 BrowserThread::IO, FROM_HERE,
72 base::Bind(callback, base::FileDescriptor(duped_fd, true)));
73 }
74
75 } // namespace
76
77 struct BrowserNativePixmapManagerTrait
78 : public DefaultSingletonTraits<BrowserNativePixmapManager> {
79 static BrowserNativePixmapManager* New() {
80 BrowserNativePixmapManager* manager = new BrowserNativePixmapManager();
81 manager->Initialize(ui::OzonePlatform::GetInstance()->GetVirtualDeviceFd());
82 return manager;
83 }
84 };
85
86 // static
87 BrowserNativePixmapManager* BrowserNativePixmapManager::GetInstance() {
88 return Singleton<BrowserNativePixmapManager,
89 BrowserNativePixmapManagerTrait>::get();
90 }
91
92 BrowserNativePixmapManager::BrowserNativePixmapManager() {}
93
94 BrowserNativePixmapManager::~BrowserNativePixmapManager() {}
95
96 void BrowserNativePixmapManager::Initialize(
97 const base::FileDescriptor& device_fd) {
98 pixmap_manager_ = ui::NativePixmapManager::Create(device_fd);
99 device_fd_ = device_fd;
100 }
101
102 std::vector<ui::NativePixmapManager::Configuration>
103 BrowserNativePixmapManager::GetSupportedNativePixmapConfigurations() const {
104 return pixmap_manager_->GetSupportedNativePixmapConfigurations();
105 }
106
107 void BrowserNativePixmapManager::GetVirtualDeviceForChildProcess(
108 const FileDescriptorCallback& callback) {
109 DCHECK_CURRENTLY_ON(BrowserThread::IO);
110 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
111 pool->PostWorkerTask(
112 FROM_HERE, base::Bind(&DupVirtualDeviceFd, device_fd_.fd, callback));
113 }
114
115 BrowserMessageFilter* BrowserNativePixmapManager::CreateMessageFilter() {
116 return new BrowserNativePixmapManagerMessageFilter(this);
117 }
118
119 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/browser_native_pixmap_manager_ozone.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698