| Index: content/browser/gpu/browser_native_pixmap_manager_ozone.cc
|
| diff --git a/content/browser/gpu/browser_native_pixmap_manager_ozone.cc b/content/browser/gpu/browser_native_pixmap_manager_ozone.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7a4e1b6bb682b9348f19ad319e509222b3f2ebfe
|
| --- /dev/null
|
| +++ b/content/browser/gpu/browser_native_pixmap_manager_ozone.cc
|
| @@ -0,0 +1,119 @@
|
| +// Copyright 2015 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/browser/gpu/browser_native_pixmap_manager_ozone.h"
|
| +
|
| +#include "base/memory/singleton.h"
|
| +#include "base/posix/eintr_wrapper.h"
|
| +#include "content/common/gpu/native_pixmap_manager_ozone_messages.h"
|
| +#include "content/public/browser/browser_message_filter.h"
|
| +#include "ui/ozone/public/ozone_platform.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +class BrowserNativePixmapManagerMessageFilter : public BrowserMessageFilter {
|
| + public:
|
| + explicit BrowserNativePixmapManagerMessageFilter(
|
| + BrowserNativePixmapManager* manager)
|
| + : BrowserMessageFilter(BrowserNativePixmapManagerMsgStart),
|
| + manager_(manager) {}
|
| +
|
| + bool OnMessageReceived(const IPC::Message& message) override {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(BrowserNativePixmapManagerMessageFilter, message)
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(
|
| + BrowserNativePixmapManagerMsg_SyncGetVirtualDevice,
|
| + OnGetVirtualDevice)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| + }
|
| +
|
| + private:
|
| + ~BrowserNativePixmapManagerMessageFilter() override {}
|
| +
|
| + void OnGetVirtualDevice(IPC::Message* reply) {
|
| + DCHECK(manager_);
|
| + manager_->GetVirtualDeviceForChildProcess(base::Bind(
|
| + &BrowserNativePixmapManagerMessageFilter::VirtualDeviceRelpied, this,
|
| + reply));
|
| + }
|
| + void VirtualDeviceRelpied(IPC::Message* reply,
|
| + const base::FileDescriptor& device) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + BrowserNativePixmapManagerMsg_SyncGetVirtualDevice::WriteReplyParams(
|
| + reply, device);
|
| + Send(reply);
|
| + }
|
| +
|
| + BrowserNativePixmapManager* manager_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BrowserNativePixmapManagerMessageFilter);
|
| +};
|
| +
|
| +void DupVirtualDeviceFd(
|
| + int device_fd,
|
| + const BrowserNativePixmapManager::FileDescriptorCallback& callback) {
|
| + int duped_fd = -1;
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + duped_fd = HANDLE_EINTR(dup(device_fd));
|
| + if (duped_fd < 0) {
|
| + PLOG(ERROR) << "dup() failed.";
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(callback, base::FileDescriptor()));
|
| + return;
|
| + }
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(callback, base::FileDescriptor(duped_fd, true)));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +struct BrowserNativePixmapManagerTrait
|
| + : public DefaultSingletonTraits<BrowserNativePixmapManager> {
|
| + static BrowserNativePixmapManager* New() {
|
| + BrowserNativePixmapManager* manager = new BrowserNativePixmapManager();
|
| + manager->Initialize(ui::OzonePlatform::GetInstance()->GetVirtualDeviceFd());
|
| + return manager;
|
| + }
|
| +};
|
| +
|
| +// static
|
| +BrowserNativePixmapManager* BrowserNativePixmapManager::GetInstance() {
|
| + return Singleton<BrowserNativePixmapManager,
|
| + BrowserNativePixmapManagerTrait>::get();
|
| +}
|
| +
|
| +BrowserNativePixmapManager::BrowserNativePixmapManager() {}
|
| +
|
| +BrowserNativePixmapManager::~BrowserNativePixmapManager() {}
|
| +
|
| +void BrowserNativePixmapManager::Initialize(
|
| + const base::FileDescriptor& device_fd) {
|
| + pixmap_manager_ = ui::NativePixmapManager::Create(device_fd);
|
| + device_fd_ = device_fd;
|
| +}
|
| +
|
| +std::vector<ui::NativePixmapManager::Configuration>
|
| +BrowserNativePixmapManager::GetSupportedNativePixmapConfigurations() const {
|
| + return pixmap_manager_->GetSupportedNativePixmapConfigurations();
|
| +}
|
| +
|
| +void BrowserNativePixmapManager::GetVirtualDeviceForChildProcess(
|
| + const FileDescriptorCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
|
| + pool->PostWorkerTask(
|
| + FROM_HERE, base::Bind(&DupVirtualDeviceFd, device_fd_.fd, callback));
|
| +}
|
| +
|
| +BrowserMessageFilter* BrowserNativePixmapManager::CreateMessageFilter() {
|
| + return new BrowserNativePixmapManagerMessageFilter(this);
|
| +}
|
| +
|
| +} // namespace content
|
|
|