diff options
author | rsesek <rsesek@chromium.org> | 2016-01-04 19:37:11 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-05 03:37:59 +0000 |
commit | 5c7c3e9be27c3a79e9462e3d275780b0bc6ad559 (patch) | |
tree | d93135846c0d49a3ed299428fdbecdc17d5c4946 | |
parent | dac52d56619f9586c387a723f4f6578467f39a88 (diff) | |
download | chromium_src-5c7c3e9be27c3a79e9462e3d275780b0bc6ad559.zip chromium_src-5c7c3e9be27c3a79e9462e3d275780b0bc6ad559.tar.gz chromium_src-5c7c3e9be27c3a79e9462e3d275780b0bc6ad559.tar.bz2 |
Replace IOSurfaceManager by directly passing IOSurface Mach ports over Chrome IPC.
IOSurfaceManager was created as a mechanism to exchange IOSurfaces using Mach
ports, at a time when Chrome IPC was unable to broker Mach port attachments. As
part of fixing https://crbug.com/466437, Chrome IPC grew the capability to also
also send Mach ports as part of a message.
With this new capability, the custom Mach IPC channel used by IOSurfaceManager
is no longer necessary, and its complexity can be removed.
BUG=569226,323304
Review URL: https://codereview.chromium.org/1532813002
Cr-Commit-Position: refs/heads/master@{#367474}
46 files changed, 157 insertions, 1567 deletions
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc index a686b02..3b5f88a 100644 --- a/content/app/content_main_runner.cc +++ b/content/app/content_main_runner.cc @@ -90,9 +90,7 @@ #if !defined(OS_IOS) #include "base/power_monitor/power_monitor_device_source.h" #include "content/app/mac/mac_init.h" -#include "content/browser/browser_io_surface_manager_mac.h" #include "content/browser/mach_broker_mac.h" -#include "content/child/child_io_surface_manager_mac.h" #include "content/common/sandbox_init_mac.h" #endif // !OS_IOS #endif // OS_WIN @@ -652,19 +650,6 @@ class ContentMainRunnerImpl : public ContentMainRunner { (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { MachBroker::ChildSendTaskPortToParent(); } - - if (!command_line.HasSwitch(switches::kSingleProcess) && - !process_type.empty() && (process_type == switches::kRendererProcess || - process_type == switches::kGpuProcess)) { - base::mac::ScopedMachSendRight service_port = - BrowserIOSurfaceManager::LookupServicePort(getppid()); - if (service_port.is_valid()) { - ChildIOSurfaceManager::GetInstance()->set_service_port( - service_port.release()); - gfx::IOSurfaceManager::SetInstance( - ChildIOSurfaceManager::GetInstance()); - } - } #elif defined(OS_WIN) base::win::SetupCRT(command_line); #endif diff --git a/content/browser/bootstrap_sandbox_manager_mac.cc b/content/browser/bootstrap_sandbox_manager_mac.cc index 48d2549..61d1b1e 100644 --- a/content/browser/bootstrap_sandbox_manager_mac.cc +++ b/content/browser/bootstrap_sandbox_manager_mac.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "base/mac/mac_util.h" -#include "content/browser/browser_io_surface_manager_mac.h" #include "content/browser/mach_broker_mac.h" #include "content/common/sandbox_init_mac.h" #include "content/public/browser/browser_thread.h" @@ -79,11 +78,6 @@ void BootstrapSandboxManager::RegisterRendererPolicy() { policy.rules["com.apple.windowserver.active"] = sandbox::Rule(sandbox::POLICY_ALLOW); - // Allow renderers to contact the IOSurfaceManager in the browser to share - // accelerated surfaces. - policy.rules[BrowserIOSurfaceManager::GetMachPortName()] = - sandbox::Rule(sandbox::POLICY_ALLOW); - // Allow access to launchservicesd on 10.10+ otherwise the renderer will crash // attempting to get its ASN. http://crbug.com/533537 if (base::mac::IsOSYosemiteOrLater()) { diff --git a/content/browser/browser_io_surface_manager_mac.cc b/content/browser/browser_io_surface_manager_mac.cc deleted file mode 100644 index d859ee7..0000000 --- a/content/browser/browser_io_surface_manager_mac.cc +++ /dev/null @@ -1,331 +0,0 @@ -// 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/browser_io_surface_manager_mac.h" - -#include <servers/bootstrap.h> - -#include <string> - -#include "base/logging.h" -#include "base/mac/foundation_util.h" -#include "base/mac/mach_logging.h" -#include "base/strings/stringprintf.h" -#include "content/browser/gpu/browser_gpu_channel_host_factory.h" - -namespace content { -namespace { - -// Returns the Mach port name to use when sending or receiving messages. |pid| -// is the process ID of the service. -std::string GetMachPortNameByPid(pid_t pid) { - return base::StringPrintf("%s.iosurfacemgr.%d", base::mac::BaseBundleID(), - pid); -} - -// Amount of time to wait before giving up when sending a reply message. -const int kSendReplyTimeoutMs = 100; - -} // namespace - -// static -BrowserIOSurfaceManager* BrowserIOSurfaceManager::GetInstance() { - return base::Singleton< - BrowserIOSurfaceManager, - base::LeakySingletonTraits<BrowserIOSurfaceManager>>::get(); -} - -// static -base::mac::ScopedMachSendRight BrowserIOSurfaceManager::LookupServicePort( - pid_t pid) { - // Look up the named IOSurfaceManager port that's been registered with - // the bootstrap server. - mach_port_t port; - kern_return_t kr = - bootstrap_look_up(bootstrap_port, - GetMachPortNameByPid(pid).c_str(), - &port); - if (kr != KERN_SUCCESS) { - BOOTSTRAP_LOG(ERROR, kr) << "bootstrap_look_up"; - return base::mac::ScopedMachSendRight(); - } - - return base::mac::ScopedMachSendRight(port); -} - -// static -std::string BrowserIOSurfaceManager::GetMachPortName() { - return GetMachPortNameByPid(getpid()); -} - -bool BrowserIOSurfaceManager::RegisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) { - base::AutoLock lock(lock_); - - IOSurfaceMapKey key(io_surface_id, client_id); - DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); - io_surfaces_.insert( - std::make_pair(key, base::ScopedCFTypeRef<IOSurfaceRef>(io_surface))); - return true; -} - -void BrowserIOSurfaceManager::UnregisterIOSurface( - gfx::IOSurfaceId io_surface_id, - int client_id) { - base::AutoLock lock(lock_); - - IOSurfaceMapKey key(io_surface_id, client_id); - DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); - io_surfaces_.erase(key); -} - -IOSurfaceRef BrowserIOSurfaceManager::AcquireIOSurface( - gfx::IOSurfaceId io_surface_id) { - base::AutoLock lock(lock_); - - IOSurfaceMapKey key( - io_surface_id, - BrowserGpuChannelHostFactory::instance()->GetGpuChannelId()); - auto it = io_surfaces_.find(key); - if (it == io_surfaces_.end()) { - LOG(ERROR) << "Invalid Id for IOSurface " << io_surface_id.id; - return nullptr; - } - - IOSurfaceRef io_surface = it->second; - CFRetain(io_surface); - return io_surface; -} - -void BrowserIOSurfaceManager::EnsureRunning() { - base::AutoLock lock(lock_); - - if (initialized_) - return; - - // Do not attempt to reinitialize in the event of failure. - initialized_ = true; - - if (!Initialize()) { - LOG(ERROR) << "Failed to initialize the BrowserIOSurfaceManager"; - } -} - -IOSurfaceManagerToken BrowserIOSurfaceManager::GenerateGpuProcessToken() { - base::AutoLock lock(lock_); - - DCHECK(gpu_process_token_.IsZero()); - gpu_process_token_ = IOSurfaceManagerToken::Generate(); - DCHECK(gpu_process_token_.Verify()); - return gpu_process_token_; -} - -void BrowserIOSurfaceManager::InvalidateGpuProcessToken() { - base::AutoLock lock(lock_); - - DCHECK(!gpu_process_token_.IsZero()); - gpu_process_token_.SetZero(); - io_surfaces_.clear(); -} - -IOSurfaceManagerToken BrowserIOSurfaceManager::GenerateChildProcessToken( - int child_process_id) { - base::AutoLock lock(lock_); - - IOSurfaceManagerToken token = IOSurfaceManagerToken::Generate(); - DCHECK(token.Verify()); - child_process_ids_[token] = child_process_id; - return token; -} - -void BrowserIOSurfaceManager::InvalidateChildProcessToken( - const IOSurfaceManagerToken& token) { - base::AutoLock lock(lock_); - - DCHECK(child_process_ids_.find(token) != child_process_ids_.end()); - child_process_ids_.erase(token); -} - -BrowserIOSurfaceManager::BrowserIOSurfaceManager() : initialized_(false) { -} - -BrowserIOSurfaceManager::~BrowserIOSurfaceManager() { -} - -bool BrowserIOSurfaceManager::Initialize() { - lock_.AssertAcquired(); - DCHECK(!server_port_.is_valid()); - - // Check in with launchd and publish the service name. - mach_port_t port; - kern_return_t kr = bootstrap_check_in( - bootstrap_port, GetMachPortName().c_str(), &port); - if (kr != KERN_SUCCESS) { - BOOTSTRAP_LOG(ERROR, kr) << "bootstrap_check_in"; - return false; - } - server_port_.reset(port); - - // Start the dispatch source. - std::string queue_name = - base::StringPrintf("%s.IOSurfaceManager", base::mac::BaseBundleID()); - dispatch_source_.reset( - new base::DispatchSourceMach(queue_name.c_str(), server_port_.get(), ^{ - HandleRequest(); - })); - dispatch_source_->Resume(); - - return true; -} - -void BrowserIOSurfaceManager::HandleRequest() { - struct { - union { - mach_msg_header_t header; - IOSurfaceManagerHostMsg_RegisterIOSurface register_io_surface; - IOSurfaceManagerHostMsg_UnregisterIOSurface unregister_io_surface; - IOSurfaceManagerHostMsg_AcquireIOSurface acquire_io_surface; - } msg; - mach_msg_trailer_t trailer; - } request = {{{0}}}; - request.msg.header.msgh_size = sizeof(request); - request.msg.header.msgh_local_port = server_port_.get(); - - kern_return_t kr = - mach_msg(&request.msg.header, MACH_RCV_MSG, 0, sizeof(request), - server_port_.get(), MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - if (kr != KERN_SUCCESS) { - MACH_LOG(ERROR, kr) << "mach_msg"; - return; - } - - union { - mach_msg_header_t header; - IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; - IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; - } reply = {{0}}; - - switch (request.msg.header.msgh_id) { - case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: - HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, - &reply.register_io_surface); - break; - case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: - HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); - // Unregister requests are asynchronous and do not require a reply as - // there is no guarantee for how quickly an IO surface is removed from - // the IOSurfaceManager instance after it has been deleted by a child - // process. - return; - case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: - HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, - &reply.acquire_io_surface); - break; - default: - LOG(ERROR) << "Unknown message received!"; - return; - } - - kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, - reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, - MACH_PORT_NULL); - if (kr != KERN_SUCCESS) { - MACH_LOG(ERROR, kr) << "mach_msg"; - } -} - -void BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( - const IOSurfaceManagerHostMsg_RegisterIOSurface& request, - IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { - base::AutoLock lock(lock_); - - reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); - reply->header.msgh_remote_port = request.header.msgh_remote_port; - reply->header.msgh_size = sizeof(*reply); - reply->body.msgh_descriptor_count = 0; - reply->result = false; - - IOSurfaceManagerToken token; - static_assert(sizeof(request.token_name) == sizeof(token.name), - "Mach message token size doesn't match expectation."); - token.SetName(request.token_name); - if (token.IsZero() || token != gpu_process_token_) { - LOG(ERROR) << "Illegal message from non-GPU process!"; - return; - } - - base::mac::ScopedMachSendRight io_surface_port(request.io_surface_port.name); - base::ScopedCFTypeRef<IOSurfaceRef> io_surface( - IOSurfaceLookupFromMachPort(io_surface_port.get())); - if (!io_surface) { - LOG(ERROR) << "Failed to open registered IOSurface port!"; - return; - } - IOSurfaceMapKey key(gfx::IOSurfaceId(request.io_surface_id), - request.client_id); - io_surfaces_.insert(std::make_pair(key, io_surface)); - reply->result = true; -} - -bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( - const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { - base::AutoLock lock(lock_); - - IOSurfaceManagerToken token; - static_assert(sizeof(request.token_name) == sizeof(token.name), - "Mach message token size doesn't match expectation."); - token.SetName(request.token_name); - if (token.IsZero() || token != gpu_process_token_) { - LOG(ERROR) << "Illegal message from non-GPU process!"; - return false; - } - - IOSurfaceMapKey key(gfx::IOSurfaceId(request.io_surface_id), - request.client_id); - io_surfaces_.erase(key); - return true; -} - -void BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( - const IOSurfaceManagerHostMsg_AcquireIOSurface& request, - IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { - base::AutoLock lock(lock_); - - reply->header.msgh_bits = - MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; - reply->header.msgh_remote_port = request.header.msgh_remote_port; - reply->header.msgh_size = sizeof(*reply); - reply->body.msgh_descriptor_count = 0; - reply->result = false; - reply->io_surface_port.name = MACH_PORT_NULL; - reply->io_surface_port.disposition = 0; - reply->io_surface_port.type = 0; - - IOSurfaceManagerToken token; - static_assert(sizeof(request.token_name) == sizeof(token.name), - "Mach message token size doesn't match expectation."); - token.SetName(request.token_name); - auto child_process_id_it = child_process_ids_.find(token); - if (child_process_id_it == child_process_ids_.end()) { - LOG(ERROR) << "Illegal message from non-child process!"; - return; - } - - reply->result = true; - IOSurfaceMapKey key(gfx::IOSurfaceId(request.io_surface_id), - child_process_id_it->second); - auto it = io_surfaces_.find(key); - if (it == io_surfaces_.end()) { - LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; - return; - } - - reply->body.msgh_descriptor_count = 1; - reply->io_surface_port.name = IOSurfaceCreateMachPort(it->second); - reply->io_surface_port.disposition = MACH_MSG_TYPE_MOVE_SEND; - reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; -} - -} // namespace content diff --git a/content/browser/browser_io_surface_manager_mac.h b/content/browser/browser_io_surface_manager_mac.h deleted file mode 100644 index 021d6fd..0000000 --- a/content/browser/browser_io_surface_manager_mac.h +++ /dev/null @@ -1,130 +0,0 @@ -// 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. - -#ifndef CONTENT_BROWSER_BROWSER_IO_SURFACE_MANAGER_MAC_H_ -#define CONTENT_BROWSER_BROWSER_IO_SURFACE_MANAGER_MAC_H_ - -#include <IOSurface/IOSurface.h> -#include <mach/mach.h> - -#include <map> -#include <utility> - -#include "base/containers/scoped_ptr_hash_map.h" -#include "base/mac/dispatch_source_mach.h" -#include "base/mac/scoped_cftyperef.h" -#include "base/mac/scoped_mach_port.h" -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/singleton.h" -#include "base/synchronization/lock.h" -#include "content/common/content_export.h" -#include "content/common/mac/io_surface_manager_messages.h" -#include "content/common/mac/io_surface_manager_token.h" -#include "ui/gfx/mac/io_surface_manager.h" - -namespace content { - -// TODO(ericrk): Use gfx::GenericSharedMemoryId as the |io_surface_id| in -// this file. Allows for more type-safe usage of GpuMemoryBufferIds as the -// type of the |io_surface_id|, as it is a typedef of -// gfx::GenericSharedMemoryId. - -// Implementation of IOSurfaceManager that provides a mechanism for child -// processes to register and acquire IOSurfaces through a Mach service. -class CONTENT_EXPORT BrowserIOSurfaceManager : public gfx::IOSurfaceManager { - public: - // Returns the global BrowserIOSurfaceManager. - static BrowserIOSurfaceManager* GetInstance(); - - // Look up the IOSurfaceManager service port that's been registered with - // the bootstrap server. |pid| is the process ID of the service. - static base::mac::ScopedMachSendRight LookupServicePort(pid_t pid); - - // Returns the name of the service registered with the bootstrap server. - static std::string GetMachPortName(); - - // Overridden from IOSurfaceManager: - bool RegisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) override; - void UnregisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id) override; - IOSurfaceRef AcquireIOSurface(gfx::IOSurfaceId io_surface_id) override; - - // Performs any necessary setup that cannot happen in the constructor. - void EnsureRunning(); - - // Generate a unique unguessable token that the GPU process can use to - // register/unregister IOSurface for use by clients. - IOSurfaceManagerToken GenerateGpuProcessToken(); - - // Invalidate the previously generated GPU process token. - void InvalidateGpuProcessToken(); - - // Generate a unique unguessable token that the child process associated - // |child_process_id| can use to acquire IOSurface references. - IOSurfaceManagerToken GenerateChildProcessToken(int child_process_id); - - // Invalidate a previously generated child process token. - void InvalidateChildProcessToken(const IOSurfaceManagerToken& token); - - private: - friend class BrowserIOSurfaceManagerTest; - friend struct base::DefaultSingletonTraits<BrowserIOSurfaceManager>; - - BrowserIOSurfaceManager(); - ~BrowserIOSurfaceManager() override; - - // Performs any initialization work. - bool Initialize(); - - // Message handler that is invoked on |dispatch_source_| when an - // incoming message needs to be received. - void HandleRequest(); - - // Message handlers that are invoked from HandleRequest. - void HandleRegisterIOSurfaceRequest( - const IOSurfaceManagerHostMsg_RegisterIOSurface& request, - IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply); - bool HandleUnregisterIOSurfaceRequest( - const IOSurfaceManagerHostMsg_UnregisterIOSurface& request); - void HandleAcquireIOSurfaceRequest( - const IOSurfaceManagerHostMsg_AcquireIOSurface& request, - IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply); - - // Whether or not the class has been initialized. - bool initialized_; - - // The Mach port on which the server listens. - base::mac::ScopedMachReceiveRight server_port_; - - // The dispatch source and queue on which Mach messages will be received. - scoped_ptr<base::DispatchSourceMach> dispatch_source_; - - // Stores the IOSurfaces for all GPU clients. The key contains the IOSurface - // id and the Child process unique id of the owner. - using IOSurfaceMapKey = std::pair<gfx::IOSurfaceId, int>; - using IOSurfaceMap = - std::map<IOSurfaceMapKey, base::ScopedCFTypeRef<IOSurfaceRef>>; - IOSurfaceMap io_surfaces_; - - // Stores the Child process unique id (RenderProcessHost ID) for every - // token. - using ChildProcessIdMap = std::map<IOSurfaceManagerToken, int>; - ChildProcessIdMap child_process_ids_; - - // Stores the GPU process token. - IOSurfaceManagerToken gpu_process_token_; - - // Mutex that guards |initialized_|, |io_surfaces_|, |child_process_ids_| - // and |gpu_process_token_|. - base::Lock lock_; - - DISALLOW_COPY_AND_ASSIGN(BrowserIOSurfaceManager); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_BROWSER_IO_SURFACE_MANAGER_MAC_H_ diff --git a/content/browser/browser_io_surface_manager_mac_unittest.cc b/content/browser/browser_io_surface_manager_mac_unittest.cc deleted file mode 100644 index 38de070..0000000 --- a/content/browser/browser_io_surface_manager_mac_unittest.cc +++ /dev/null @@ -1,331 +0,0 @@ -// 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/browser_io_surface_manager_mac.h" - -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/gfx/mac/io_surface_manager.h" - -namespace content { - -class BrowserIOSurfaceManagerTest : public testing::Test { - public: - void EnsureRunning() { io_surface_manager_.EnsureRunning(); } - - IOSurfaceManagerToken GenerateGpuProcessToken() { - return io_surface_manager_.GenerateGpuProcessToken(); - } - - void InvalidateGpuProcessToken() { - io_surface_manager_.InvalidateGpuProcessToken(); - } - - IOSurfaceManagerToken GenerateChildProcessToken(int child_process_id) { - return io_surface_manager_.GenerateChildProcessToken(child_process_id); - } - - void InvalidateChildProcessToken(const IOSurfaceManagerToken& token) { - io_surface_manager_.InvalidateChildProcessToken(token); - } - - bool HandleRegisterIOSurfaceRequest( - const IOSurfaceManagerHostMsg_RegisterIOSurface& request, - IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { - io_surface_manager_.HandleRegisterIOSurfaceRequest(request, reply); - return reply->result; - } - - bool HandleUnregisterIOSurfaceRequest( - const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { - return io_surface_manager_.HandleUnregisterIOSurfaceRequest(request); - } - - bool HandleAcquireIOSurfaceRequest( - const IOSurfaceManagerHostMsg_AcquireIOSurface& request, - IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { - io_surface_manager_.HandleAcquireIOSurfaceRequest(request, reply); - return reply->result; - } - - // Helper function used to register an IOSurface for testing. - void RegisterIOSurface(const IOSurfaceManagerToken& gpu_process_token, - int io_surface_id, - int client_id, - mach_port_t io_surface_port) { - IOSurfaceManagerHostMsg_RegisterIOSurface request = {{0}}; - IOSurfaceManagerMsg_RegisterIOSurfaceReply reply = {{0}}; - request.io_surface_id = io_surface_id; - request.client_id = client_id; - request.io_surface_port.name = GetIOSurfaceMachPort(); - memcpy(request.token_name, gpu_process_token.name, - sizeof(gpu_process_token.name)); - ASSERT_TRUE(HandleRegisterIOSurfaceRequest(request, &reply)); - ASSERT_TRUE(reply.result); - } - - mach_port_t GetIOSurfaceMachPort() { - if (!io_surface_) { - io_surface_.reset(gfx::IOSurfaceManager::CreateIOSurface( - gfx::Size(32, 32), gfx::BufferFormat::BGRA_8888)); - io_surface_port_.reset(IOSurfaceCreateMachPort(io_surface_)); - } - return io_surface_port_.get(); - } - - private: - BrowserIOSurfaceManager io_surface_manager_; - base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; - base::mac::ScopedMachSendRight io_surface_port_; -}; - -TEST_F(BrowserIOSurfaceManagerTest, EnsureRunning) { - EnsureRunning(); - base::mac::ScopedMachSendRight service_port = - BrowserIOSurfaceManager::LookupServicePort(getpid()); - EXPECT_TRUE(service_port.is_valid()); -} - -TEST_F(BrowserIOSurfaceManagerTest, RegisterIOSurfaceSucceeds) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - - base::ScopedCFTypeRef<IOSurfaceRef> io_surface( - gfx::IOSurfaceManager::CreateIOSurface(gfx::Size(32, 32), - gfx::BufferFormat::BGRA_8888)); - base::mac::ScopedMachSendRight io_surface_port( - IOSurfaceCreateMachPort(io_surface)); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - - IOSurfaceManagerHostMsg_RegisterIOSurface request = {{0}}; - IOSurfaceManagerMsg_RegisterIOSurfaceReply reply = {{0}}; - - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - request.io_surface_port.name = GetIOSurfaceMachPort(); - memcpy(request.token_name, gpu_process_token.name, - sizeof(gpu_process_token.name)); - EXPECT_TRUE(HandleRegisterIOSurfaceRequest(request, &reply)); - EXPECT_TRUE(reply.result); -} - -TEST_F(BrowserIOSurfaceManagerTest, RegisterIOSurfaceFailsWithInvalidToken) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - - IOSurfaceManagerHostMsg_RegisterIOSurface request = {{0}}; - IOSurfaceManagerMsg_RegisterIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - // Fails as request doesn't contain a valid token. - EXPECT_FALSE(HandleRegisterIOSurfaceRequest(request, &reply)); -} - -TEST_F(BrowserIOSurfaceManagerTest, - RegisterIOSurfaceFailsWithChildProcessToken) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - - IOSurfaceManagerToken child_process_token = - GenerateChildProcessToken(kClientId); - - IOSurfaceManagerHostMsg_RegisterIOSurface request = {{0}}; - IOSurfaceManagerMsg_RegisterIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - memcpy(request.token_name, child_process_token.name, - sizeof(child_process_token.name)); - // Fails as child process is not allowed to register IOSurfaces. - EXPECT_FALSE(HandleRegisterIOSurfaceRequest(request, &reply)); -} - -TEST_F(BrowserIOSurfaceManagerTest, RegisterIOSurfaceFailsWithInvalidPort) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - const mach_port_t kIOInvalidSurfacePortId = 100u; - - base::ScopedCFTypeRef<IOSurfaceRef> io_surface( - gfx::IOSurfaceManager::CreateIOSurface(gfx::Size(32, 32), - gfx::BufferFormat::BGRA_8888)); - base::mac::ScopedMachSendRight io_surface_port( - IOSurfaceCreateMachPort(io_surface)); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - - IOSurfaceManagerHostMsg_RegisterIOSurface request = {{0}}; - IOSurfaceManagerMsg_RegisterIOSurfaceReply reply = {{0}}; - - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - request.io_surface_port.name = kIOInvalidSurfacePortId; - memcpy(request.token_name, gpu_process_token.name, - sizeof(gpu_process_token.name)); - EXPECT_FALSE(HandleRegisterIOSurfaceRequest(request, &reply)); - EXPECT_FALSE(reply.result); -} - -TEST_F(BrowserIOSurfaceManagerTest, UnregisterIOSurfaceSucceeds) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, 0); - - IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - memcpy(request.token_name, gpu_process_token.name, - sizeof(gpu_process_token.name)); - EXPECT_TRUE(HandleUnregisterIOSurfaceRequest(request)); -} - -TEST_F(BrowserIOSurfaceManagerTest, UnregisterIOSurfaceFailsWithInvalidToken) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, 0); - - IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - // Fails as request doesn't contain valid GPU token. - EXPECT_FALSE(HandleUnregisterIOSurfaceRequest(request)); -} - -TEST_F(BrowserIOSurfaceManagerTest, - UnregisterIOSurfaceFailsWithChildProcessToken) { - const int kIOSurfaceId = 1; - const int kClientId = 1; - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - IOSurfaceManagerToken child_process_token = - GenerateChildProcessToken(kClientId); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, 0); - - IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; - request.io_surface_id = kIOSurfaceId; - request.client_id = kClientId; - memcpy(request.token_name, child_process_token.name, - sizeof(child_process_token.name)); - // Fails as child process is not allowed to unregister IOSurfaces. - EXPECT_FALSE(HandleUnregisterIOSurfaceRequest(request)); -} - -TEST_F(BrowserIOSurfaceManagerTest, AcquireIOSurfaceSucceeds) { - const int kIOSurfaceId = 10; - const int kClientId = 1; - const mach_port_t io_surface_port = GetIOSurfaceMachPort(); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - IOSurfaceManagerToken child_process_token = - GenerateChildProcessToken(kClientId); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, - io_surface_port); - - IOSurfaceManagerHostMsg_AcquireIOSurface request = {{0}}; - IOSurfaceManagerMsg_AcquireIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - memcpy(request.token_name, child_process_token.name, - sizeof(child_process_token.name)); - EXPECT_TRUE(HandleAcquireIOSurfaceRequest(request, &reply)); -} - -TEST_F(BrowserIOSurfaceManagerTest, AcquireIOSurfaceFailsWithInvalidToken) { - const int kIOSurfaceId = 10; - const int kClientId = 1; - const mach_port_t io_surface_port = GetIOSurfaceMachPort(); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, - io_surface_port); - - IOSurfaceManagerHostMsg_AcquireIOSurface request = {{0}}; - IOSurfaceManagerMsg_AcquireIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - // Fails as request doesn't contain valid token. - EXPECT_FALSE(HandleAcquireIOSurfaceRequest(request, &reply)); -} - -TEST_F(BrowserIOSurfaceManagerTest, - AcquireIOSurfaceFailsWithWrongChildProcessToken) { - const int kIOSurfaceId = 10; - const int kClientId1 = 1; - const int kClientId2 = 2; - const mach_port_t io_surface_port = GetIOSurfaceMachPort(); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - IOSurfaceManagerToken child_process_token2 = - GenerateChildProcessToken(kClientId2); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId1, - io_surface_port); - - IOSurfaceManagerHostMsg_AcquireIOSurface request = {{0}}; - IOSurfaceManagerMsg_AcquireIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - memcpy(request.token_name, child_process_token2.name, - sizeof(child_process_token2.name)); - EXPECT_TRUE(HandleAcquireIOSurfaceRequest(request, &reply)); - // Fails as child process 2 is not allowed to acquire this IOSurface. - EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), - reply.io_surface_port.name); -} - -TEST_F(BrowserIOSurfaceManagerTest, - AcquireIOSurfaceFailsAfterInvalidatingChildProcessToken) { - const int kIOSurfaceId = 10; - const int kClientId = 1; - const mach_port_t io_surface_port = GetIOSurfaceMachPort(); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - IOSurfaceManagerToken child_process_token = - GenerateChildProcessToken(kClientId); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, - io_surface_port); - - InvalidateChildProcessToken(child_process_token); - - IOSurfaceManagerHostMsg_AcquireIOSurface request = {{0}}; - IOSurfaceManagerMsg_AcquireIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - memcpy(request.token_name, child_process_token.name, - sizeof(child_process_token.name)); - // Fails as token is no longer valid. - EXPECT_FALSE(HandleAcquireIOSurfaceRequest(request, &reply)); -} - -TEST_F(BrowserIOSurfaceManagerTest, - AcquireIOSurfaceAfterInvalidatingGpuProcessToken) { - const int kIOSurfaceId = 10; - const int kClientId = 1; - const mach_port_t io_surface_port = GetIOSurfaceMachPort(); - - IOSurfaceManagerToken gpu_process_token = GenerateGpuProcessToken(); - IOSurfaceManagerToken child_process_token = - GenerateChildProcessToken(kClientId); - - RegisterIOSurface(gpu_process_token, kIOSurfaceId, kClientId, - io_surface_port); - - InvalidateGpuProcessToken(); - - IOSurfaceManagerHostMsg_AcquireIOSurface request = {{0}}; - IOSurfaceManagerMsg_AcquireIOSurfaceReply reply = {{0}}; - request.io_surface_id = kIOSurfaceId; - memcpy(request.token_name, child_process_token.name, - sizeof(child_process_token.name)); - EXPECT_TRUE(HandleAcquireIOSurfaceRequest(request, &reply)); - // Should return invalid port. - EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), - reply.io_surface_port.name); -} - -} // namespace content diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc index 5daf100..732f0e2 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -111,10 +111,8 @@ #if defined(OS_MACOSX) && !defined(OS_IOS) #include "base/memory/memory_pressure_monitor_mac.h" #include "content/browser/bootstrap_sandbox_manager_mac.h" -#include "content/browser/browser_io_surface_manager_mac.h" #include "content/browser/cocoa/system_hotkey_helper_mac.h" #include "content/browser/compositor/browser_compositor_view_mac.h" -#include "content/browser/in_process_io_surface_manager_mac.h" #include "content/browser/theme_helper_mac.h" #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" #endif @@ -662,17 +660,6 @@ void BrowserMainLoop::PostMainMessageLoopStart() { #endif #if defined(OS_MACOSX) && !defined(OS_IOS) - { - TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:IOSurfaceManager"); - if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { - gfx::IOSurfaceManager::SetInstance( - InProcessIOSurfaceManager::GetInstance()); - } else { - gfx::IOSurfaceManager::SetInstance( - BrowserIOSurfaceManager::GetInstance()); - } - } - if (BootstrapSandboxManager::ShouldEnable()) { TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:BootstrapSandbox"); diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc index b0052d5..40d78e0 100644 --- a/content/browser/child_process_launcher.cc +++ b/content/browser/child_process_launcher.cc @@ -30,7 +30,6 @@ #include "content/public/common/sandbox_init.h" #elif defined(OS_MACOSX) #include "content/browser/bootstrap_sandbox_manager_mac.h" -#include "content/browser/browser_io_surface_manager_mac.h" #include "content/browser/mach_broker_mac.h" #include "sandbox/mac/bootstrap_sandbox.h" #include "sandbox/mac/pre_exec_delegate.h" @@ -243,9 +242,6 @@ void LaunchOnLauncherThread(const NotifyCallback& callback, // check-in from the new process. broker->EnsureRunning(); - // Make sure the IOSurfaceManager service is running. - BrowserIOSurfaceManager::GetInstance()->EnsureRunning(); - const SandboxType sandbox_type = delegate->GetSandboxType(); scoped_ptr<sandbox::PreExecDelegate> pre_exec_delegate; if (BootstrapSandboxManager::ShouldEnable()) { diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc index 05e8005..913d7e1 100644 --- a/content/browser/gpu/gpu_process_host.cc +++ b/content/browser/gpu/gpu_process_host.cc @@ -72,11 +72,6 @@ #include "ui/gfx/x/x11_switches.h" #endif -#if defined(OS_MACOSX) && !defined(OS_IOS) -#include "content/browser/browser_io_surface_manager_mac.h" -#include "content/common/child_process_messages.h" -#endif - #if defined(OS_MACOSX) #include "content/browser/renderer_host/render_widget_resize_helper_mac.h" #endif @@ -451,13 +446,6 @@ GpuProcessHost::~GpuProcessHost() { queued_messages_.pop(); } -#if defined(OS_MACOSX) && !defined(OS_IOS) - if (!io_surface_manager_token_.IsZero()) { - BrowserIOSurfaceManager::GetInstance()->InvalidateGpuProcessToken(); - io_surface_manager_token_.SetZero(); - } -#endif - // This is only called on the IO thread so no race against the constructor // for another GpuProcessHost. if (g_gpu_process_hosts[kind_] == this) @@ -568,14 +556,6 @@ bool GpuProcessHost::Init() { if (!Send(new GpuMsg_Initialize())) return false; -#if defined(OS_MACOSX) && !defined(OS_IOS) - io_surface_manager_token_ = - BrowserIOSurfaceManager::GetInstance()->GenerateGpuProcessToken(); - // Note: A valid IOSurface manager token needs to be sent to the Gpu process - // before any GpuMemoryBuffer allocation requests can be sent. - Send(new ChildProcessMsg_SetIOSurfaceManagerToken(io_surface_manager_token_)); -#endif - return true; } @@ -937,13 +917,6 @@ void GpuProcessHost::ForceShutdown() { if (g_gpu_process_hosts[kind_] == this) g_gpu_process_hosts[kind_] = NULL; -#if defined(OS_MACOSX) && !defined(OS_IOS) - if (!io_surface_manager_token_.IsZero()) { - BrowserIOSurfaceManager::GetInstance()->InvalidateGpuProcessToken(); - io_surface_manager_token_.SetZero(); - } -#endif - process_->ForceShutdown(); } diff --git a/content/browser/gpu/gpu_process_host.h b/content/browser/gpu/gpu_process_host.h index 74d9927..60001e6 100644 --- a/content/browser/gpu/gpu_process_host.h +++ b/content/browser/gpu/gpu_process_host.h @@ -34,10 +34,6 @@ #include "ui/gfx/native_widget_types.h" #include "url/gurl.h" -#if defined(OS_MACOSX) && !defined(OS_IOS) -#include "content/common/mac/io_surface_manager_token.h" -#endif - struct GPUCreateCommandBufferConfig; namespace IPC { @@ -295,12 +291,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate, std::string shader_prefix_key_; -#if defined(OS_MACOSX) && !defined(OS_IOS) - // Unique unguessable token that the GPU process is using to register - // IOSurfaces. - IOSurfaceManagerToken io_surface_manager_token_; -#endif - // Browser-side Mojo endpoint which sets up a Mojo channel with the child // process and contains the browser's ServiceRegistry. scoped_ptr<MojoApplicationHost> mojo_application_host_; diff --git a/content/browser/gpu/gpu_process_host_ui_shim.cc b/content/browser/gpu/gpu_process_host_ui_shim.cc index 4b84d6d..083c99d 100644 --- a/content/browser/gpu/gpu_process_host_ui_shim.cc +++ b/content/browser/gpu/gpu_process_host_ui_shim.cc @@ -26,7 +26,6 @@ #include "content/public/browser/browser_thread.h" #if defined(OS_MACOSX) -#include "content/browser/browser_io_surface_manager_mac.h" #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" #endif @@ -246,24 +245,12 @@ void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( content::GpuSurfaceTracker::Get()->AcquireNativeWidget( params.surface_id); base::ScopedCFTypeRef<IOSurfaceRef> io_surface; - CAContextID ca_context_id = 0; - - switch (ui::GetSurfaceHandleType(params.surface_handle)) { - case ui::kSurfaceHandleTypeIOSurface: { - IOSurfaceID io_surface_id = - ui::IOSurfaceIDFromSurfaceHandle(params.surface_handle); - io_surface.reset( - BrowserIOSurfaceManager::GetInstance()->AcquireIOSurface( - gfx::GenericSharedMemoryId(io_surface_id))); - break; - } - case ui::kSurfaceHandleTypeCAContext: { - ca_context_id = ui::CAContextIDFromSurfaceHandle(params.surface_handle); - break; - } - default: - DLOG(ERROR) << "Unrecognized accelerated frame type."; - return; + CAContextID ca_context_id = params.ca_context_id; + + DCHECK((params.ca_context_id == 0) ^ + (params.io_surface.get() == MACH_PORT_NULL)); + if (params.io_surface.get()) { + io_surface.reset(IOSurfaceLookupFromMachPort(params.io_surface)); } ui::AcceleratedWidgetMacGotFrame(native_widget, ca_context_id, io_surface, diff --git a/content/browser/in_process_io_surface_manager_mac.cc b/content/browser/in_process_io_surface_manager_mac.cc deleted file mode 100644 index 70f18a7..0000000 --- a/content/browser/in_process_io_surface_manager_mac.cc +++ /dev/null @@ -1,54 +0,0 @@ -// 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/in_process_io_surface_manager_mac.h" - -#include "base/logging.h" - -namespace content { - -// static -InProcessIOSurfaceManager* InProcessIOSurfaceManager::GetInstance() { - return base::Singleton< - InProcessIOSurfaceManager, - base::LeakySingletonTraits<InProcessIOSurfaceManager>>::get(); -} - -bool InProcessIOSurfaceManager::RegisterIOSurface( - gfx::IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) { - base::AutoLock lock(lock_); - - DCHECK(io_surfaces_.find(io_surface_id) == io_surfaces_.end()); - io_surfaces_.add(io_surface_id, - make_scoped_ptr(new base::mac::ScopedMachSendRight( - IOSurfaceCreateMachPort(io_surface)))); - return true; -} - -void InProcessIOSurfaceManager::UnregisterIOSurface( - gfx::IOSurfaceId io_surface_id, - int client_id) { - base::AutoLock lock(lock_); - - DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end()); - io_surfaces_.erase(io_surface_id); -} - -IOSurfaceRef InProcessIOSurfaceManager::AcquireIOSurface( - gfx::IOSurfaceId io_surface_id) { - base::AutoLock lock(lock_); - - DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end()); - return IOSurfaceLookupFromMachPort(io_surfaces_.get(io_surface_id)->get()); -} - -InProcessIOSurfaceManager::InProcessIOSurfaceManager() { -} - -InProcessIOSurfaceManager::~InProcessIOSurfaceManager() { -} - -} // namespace content diff --git a/content/browser/in_process_io_surface_manager_mac.h b/content/browser/in_process_io_surface_manager_mac.h deleted file mode 100644 index 6016e65..0000000 --- a/content/browser/in_process_io_surface_manager_mac.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -#ifndef CONTENT_BROWSER_IN_PROCESS_IO_SURFACE_MANAGER_MAC_H_ -#define CONTENT_BROWSER_IN_PROCESS_IO_SURFACE_MANAGER_MAC_H_ - -#include "base/containers/scoped_ptr_hash_map.h" -#include "base/mac/scoped_mach_port.h" -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/singleton.h" -#include "base/synchronization/lock.h" -#include "content/common/content_export.h" -#include "ui/gfx/mac/io_surface_manager.h" - -namespace content { - -class CONTENT_EXPORT InProcessIOSurfaceManager : public gfx::IOSurfaceManager { - public: - static InProcessIOSurfaceManager* GetInstance(); - - // Overridden from IOSurfaceManager: - bool RegisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) override; - void UnregisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id) override; - IOSurfaceRef AcquireIOSurface(gfx::IOSurfaceId io_surface_id) override; - - private: - friend struct base::DefaultSingletonTraits<InProcessIOSurfaceManager>; - - InProcessIOSurfaceManager(); - ~InProcessIOSurfaceManager() override; - - using IOSurfaceMap = - base::ScopedPtrHashMap<gfx::IOSurfaceId, - scoped_ptr<base::mac::ScopedMachSendRight>>; - IOSurfaceMap io_surfaces_; - base::Lock lock_; - - DISALLOW_COPY_AND_ASSIGN(InProcessIOSurfaceManager); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_IN_PROCESS_IO_SURFACE_MANAGER_MAC_H_ diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index cf90419..83a4bd7 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -197,7 +197,6 @@ #if defined(OS_MACOSX) && !defined(OS_IOS) #include "content/browser/bootstrap_sandbox_manager_mac.h" -#include "content/browser/browser_io_surface_manager_mac.h" #include "content/browser/mach_broker_mac.h" #endif @@ -1887,14 +1886,6 @@ void RenderProcessHostImpl::Cleanup() { // Remove ourself from the list of renderer processes so that we can't be // reused in between now and when the Delete task runs. UnregisterHost(GetID()); - -#if defined(OS_MACOSX) && !defined(OS_IOS) - if (!io_surface_manager_token_.IsZero()) { - BrowserIOSurfaceManager::GetInstance()->InvalidateChildProcessToken( - io_surface_manager_token_); - io_surface_manager_token_.SetZero(); - } -#endif } } @@ -2501,13 +2492,6 @@ void RenderProcessHostImpl::OnProcessLaunched() { UpdateProcessPriority(); } -#if defined(OS_MACOSX) && !defined(OS_IOS) - io_surface_manager_token_ = - BrowserIOSurfaceManager::GetInstance()->GenerateChildProcessToken( - GetID()); - Send(new ChildProcessMsg_SetIOSurfaceManagerToken(io_surface_manager_token_)); -#endif - // NOTE: This needs to be before sending queued messages because // ExtensionService uses this notification to initialize the renderer process // with state that must be there before any JavaScript executes. diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index c9cc5ac..7915495 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -30,10 +30,6 @@ #include "ui/gfx/gpu_memory_buffer.h" #include "ui/gl/gpu_switching_observer.h" -#if defined(OS_MACOSX) && !defined(OS_IOS) -#include "content/common/mac/io_surface_manager_token.h" -#endif - namespace base { class CommandLine; class MessageLoop; @@ -498,12 +494,6 @@ class CONTENT_EXPORT RenderProcessHostImpl // Whether or not the CHROMIUM_subscribe_uniform WebGL extension is enabled bool subscribe_uniform_enabled_; -#if defined(OS_MACOSX) && !defined(OS_IOS) - // Unique unguessable token that the child process is using to acquire - // IOSurface references. - IOSurfaceManagerToken io_surface_manager_token_; -#endif - bool channel_connected_; bool sent_render_process_ready_; diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index e4a9f42..8a8f916 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -69,7 +69,6 @@ #include "third_party/WebKit/public/platform/WebScreenInfo.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #import "third_party/mozilla/ComplexTextInputPanel.h" -#include "ui/accelerated_widget_mac/surface_handle_types.h" #include "ui/base/cocoa/animation_utils.h" #import "ui/base/cocoa/fullscreen_window_manager.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" diff --git a/content/child/child_io_surface_manager_mac.cc b/content/child/child_io_surface_manager_mac.cc deleted file mode 100644 index e766c1c..0000000 --- a/content/child/child_io_surface_manager_mac.cc +++ /dev/null @@ -1,150 +0,0 @@ -// 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/child/child_io_surface_manager_mac.h" - -#include "base/mac/mach_logging.h" -#include "content/common/mac/io_surface_manager_messages.h" - -namespace content { - -// static -ChildIOSurfaceManager* ChildIOSurfaceManager::GetInstance() { - return base::Singleton< - ChildIOSurfaceManager, - base::LeakySingletonTraits<ChildIOSurfaceManager>>::get(); -} - -bool ChildIOSurfaceManager::RegisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) { - DCHECK(service_port_.is_valid()); - CHECK(!token_.IsZero()); - - mach_port_t reply_port; - kern_return_t kr = mach_port_allocate(mach_task_self(), - MACH_PORT_RIGHT_RECEIVE, &reply_port); - if (kr != KERN_SUCCESS) { - MACH_LOG(ERROR, kr) << "mach_port_allocate"; - return false; - } - base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); - - // Deallocate the right after sending a copy to the parent. - base::mac::ScopedMachSendRight scoped_io_surface_right( - IOSurfaceCreateMachPort(io_surface)); - - union { - IOSurfaceManagerHostMsg_RegisterIOSurface request; - struct { - IOSurfaceManagerMsg_RegisterIOSurfaceReply msg; - mach_msg_trailer_t trailer; - } reply; - } data = {{{0}}}; - data.request.header.msgh_bits = - MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE) | - MACH_MSGH_BITS_COMPLEX; - data.request.header.msgh_remote_port = service_port_.get(); - data.request.header.msgh_local_port = reply_port; - data.request.header.msgh_size = sizeof(data.request); - data.request.header.msgh_id = IOSurfaceManagerHostMsg_RegisterIOSurface::ID; - data.request.body.msgh_descriptor_count = 1; - data.request.io_surface_port.name = scoped_io_surface_right.get(); - data.request.io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; - data.request.io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; - data.request.io_surface_id = io_surface_id.id; - data.request.client_id = client_id; - memcpy(data.request.token_name, token_.name, sizeof(token_.name)); - - kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG, - sizeof(data.request), sizeof(data.reply), reply_port, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - if (kr != KERN_SUCCESS) { - MACH_LOG(ERROR, kr) << "mach_msg"; - return false; - } - - return data.reply.msg.result; -} - -void ChildIOSurfaceManager::UnregisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id) { - DCHECK(service_port_.is_valid()); - CHECK(!token_.IsZero()); - - IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; - request.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); - request.header.msgh_remote_port = service_port_.get(); - request.header.msgh_local_port = MACH_PORT_NULL; - request.header.msgh_size = sizeof(request); - request.header.msgh_id = IOSurfaceManagerHostMsg_UnregisterIOSurface::ID; - request.io_surface_id = io_surface_id.id; - request.client_id = client_id; - memcpy(request.token_name, token_.name, sizeof(token_.name)); - - kern_return_t kr = - mach_msg(&request.header, MACH_SEND_MSG, sizeof(request), 0, - MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - if (kr != KERN_SUCCESS) { - MACH_LOG(ERROR, kr) << "mach_msg"; - } -} - -IOSurfaceRef ChildIOSurfaceManager::AcquireIOSurface( - gfx::IOSurfaceId io_surface_id) { - DCHECK(service_port_.is_valid()); - CHECK(!token_.IsZero()); - - mach_port_t reply_port; - kern_return_t kr = mach_port_allocate(mach_task_self(), - MACH_PORT_RIGHT_RECEIVE, &reply_port); - CHECK_EQ(KERN_SUCCESS, kr); - base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); - - union { - IOSurfaceManagerHostMsg_AcquireIOSurface request; - struct { - IOSurfaceManagerMsg_AcquireIOSurfaceReply msg; - mach_msg_trailer_t trailer; - } reply; - } data = {{{0}}}; - data.request.header.msgh_bits = - MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); - data.request.header.msgh_remote_port = service_port_.get(); - data.request.header.msgh_local_port = reply_port; - data.request.header.msgh_size = sizeof(data.request); - data.request.header.msgh_id = IOSurfaceManagerHostMsg_AcquireIOSurface::ID; - data.request.io_surface_id = io_surface_id.id; - memcpy(data.request.token_name, token_.name, sizeof(token_.name)); - - kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG, - sizeof(data.request), sizeof(data.reply), reply_port, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - if (kr != KERN_SUCCESS) { - MACH_LOG(ERROR, kr) << "mach_msg"; - return nullptr; - } - if (!data.reply.msg.result) { - DLOG(ERROR) << "Browser refused AcquireIOSurface request"; - return nullptr; - } - - // Deallocate the right after creating an IOSurface reference. - base::mac::ScopedMachSendRight scoped_io_surface_right( - data.reply.msg.io_surface_port.name); - - // If a port was successfully received, it should be valid, and opening it - // should not fail. - CHECK(scoped_io_surface_right.is_valid()); - IOSurfaceRef io_surface = IOSurfaceLookupFromMachPort( - scoped_io_surface_right.get()); - CHECK(io_surface); - return io_surface; -} - -ChildIOSurfaceManager::ChildIOSurfaceManager() {} - -ChildIOSurfaceManager::~ChildIOSurfaceManager() {} - -} // namespace content diff --git a/content/child/child_io_surface_manager_mac.h b/content/child/child_io_surface_manager_mac.h deleted file mode 100644 index 6c849fb..0000000 --- a/content/child/child_io_surface_manager_mac.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -#ifndef CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_ -#define CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_ - -#include "base/mac/scoped_mach_port.h" -#include "base/macros.h" -#include "base/memory/singleton.h" -#include "content/common/content_export.h" -#include "content/common/mac/io_surface_manager_token.h" -#include "ui/gfx/mac/io_surface_manager.h" - -namespace content { - -// Implementation of IOSurfaceManager that registers and acquires IOSurfaces -// through a Mach service. -class CONTENT_EXPORT ChildIOSurfaceManager : public gfx::IOSurfaceManager { - public: - // Returns the global ChildIOSurfaceManager. - static ChildIOSurfaceManager* GetInstance(); - - // Overridden from IOSurfaceManager: - bool RegisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) override; - void UnregisterIOSurface(gfx::IOSurfaceId io_surface_id, - int client_id) override; - IOSurfaceRef AcquireIOSurface(gfx::IOSurfaceId io_surface_id) override; - - // Set the service Mach port. Ownership of |service_port| is passed to the - // manager. - // Note: This can be called on any thread but must happen before the - // thread-safe IOSurfaceManager interface is used. It is the responsibility - // of users of this class to ensure there are no races. - void set_service_port(mach_port_t service_port) { - service_port_.reset(service_port); - } - - // Set the token used when communicating with the Mach service. - // Note: This can be called on any thread but must happen before the - // thread-safe IOSurfaceManager interface is used. It is the responsibility - // of users of this class to ensure there are no races. - void set_token(const IOSurfaceManagerToken& token) { - token_ = token; - } - - private: - friend struct base::DefaultSingletonTraits<ChildIOSurfaceManager>; - - ChildIOSurfaceManager(); - ~ChildIOSurfaceManager() override; - - base::mac::ScopedMachSendRight service_port_; - IOSurfaceManagerToken token_; - - DISALLOW_COPY_AND_ASSIGN(ChildIOSurfaceManager); -}; - -} // namespace content - -#endif // CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_ diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc index 3c6d869..d9b02b2 100644 --- a/content/child/child_thread_impl.cc +++ b/content/child/child_thread_impl.cc @@ -70,10 +70,6 @@ #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" #endif -#if defined(OS_MACOSX) -#include "content/child/child_io_surface_manager_mac.h" -#endif - #if defined(USE_OZONE) #include "ui/ozone/public/client_native_pixmap_factory.h" #endif @@ -179,29 +175,6 @@ class SuicideOnChannelErrorFilter : public IPC::MessageFilter { #endif // OS(POSIX) -#if defined(OS_MACOSX) -class IOSurfaceManagerFilter : public IPC::MessageFilter { - public: - // Overridden from IPC::MessageFilter: - bool OnMessageReceived(const IPC::Message& message) override { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(IOSurfaceManagerFilter, message) - IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIOSurfaceManagerToken, - OnSetIOSurfaceManagerToken) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; - } - - protected: - ~IOSurfaceManagerFilter() override {} - - void OnSetIOSurfaceManagerToken(const IOSurfaceManagerToken& token) { - ChildIOSurfaceManager::GetInstance()->set_token(token); - } -}; -#endif - #if defined(USE_OZONE) class ClientNativePixmapFactoryFilter : public IPC::MessageFilter { public: @@ -481,10 +454,6 @@ void ChildThreadImpl::Init(const Options& options) { channel_->AddFilter(new SuicideOnChannelErrorFilter()); #endif -#if defined(OS_MACOSX) - channel_->AddFilter(new IOSurfaceManagerFilter()); -#endif - #if defined(USE_OZONE) channel_->AddFilter(new ClientNativePixmapFactoryFilter()); #endif diff --git a/content/common/child_process_messages.h b/content/common/child_process_messages.h index 7516ec8..b4ee49f 100644 --- a/content/common/child_process_messages.h +++ b/content/common/child_process_messages.h @@ -23,10 +23,6 @@ #include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/ipc/gfx_param_traits.h" -#if defined(OS_MACOSX) -#include "content/common/mac/io_surface_manager_token.h" -#endif - IPC_ENUM_TRAITS_MAX_VALUE(tracked_objects::ThreadData::Status, tracked_objects::ThreadData::STATUS_LAST) @@ -77,6 +73,8 @@ IPC_STRUCT_TRAITS_BEGIN(gfx::GpuMemoryBufferHandle) IPC_STRUCT_TRAITS_MEMBER(stride) #if defined(USE_OZONE) IPC_STRUCT_TRAITS_MEMBER(native_pixmap_handle) +#elif defined(OS_MACOSX) + IPC_STRUCT_TRAITS_MEMBER(mach_port) #endif IPC_STRUCT_TRAITS_END() @@ -124,13 +122,6 @@ IPC_MESSAGE_CONTROL1(ChildProcessMsg_GetChildHistogramData, IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetProcessBackgrounded, bool /* background */) -#if defined(OS_MACOSX) -// Sent to child processes to tell them what token to use when registering -// and/or acquiring IOSurfaces. -IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetIOSurfaceManagerToken, - content::IOSurfaceManagerToken /* token */) -#endif - // Sends a pipe used by the child process to broker passing of Mojo handles. IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetMojoParentPipeHandle, IPC::PlatformFileForTransit /* handle */) diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc index 9794bbf..2df9994 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc @@ -7,7 +7,7 @@ #include "base/logging.h" #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" #include "ui/gfx/buffer_format_util.h" -#include "ui/gfx/mac/io_surface_manager.h" +#include "ui/gfx/mac/io_surface.h" namespace content { namespace { @@ -25,8 +25,7 @@ uint32_t LockFlags(gfx::BufferUsage usage) { return 0; } -void FreeIOSurfaceForTesting(gfx::GpuMemoryBufferId id) { - gfx::IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, 0); +void NoOp() { } } // namespace @@ -54,7 +53,7 @@ GpuMemoryBufferImplIOSurface::CreateFromHandle( gfx::BufferUsage usage, const DestructionCallback& callback) { base::ScopedCFTypeRef<IOSurfaceRef> io_surface( - gfx::IOSurfaceManager::GetInstance()->AcquireIOSurface(handle.id)); + IOSurfaceLookupFromMachPort(handle.mach_port.get())); if (!io_surface) return nullptr; @@ -78,15 +77,13 @@ base::Closure GpuMemoryBufferImplIOSurface::AllocateForTesting( gfx::BufferUsage usage, gfx::GpuMemoryBufferHandle* handle) { base::ScopedCFTypeRef<IOSurfaceRef> io_surface( - gfx::IOSurfaceManager::CreateIOSurface(size, format)); + gfx::CreateIOSurface(size, format)); DCHECK(io_surface); gfx::GpuMemoryBufferId kBufferId(1); - bool rv = gfx::IOSurfaceManager::GetInstance()->RegisterIOSurface( - kBufferId, 0, io_surface); - DCHECK(rv); handle->type = gfx::IO_SURFACE_BUFFER; handle->id = kBufferId; - return base::Bind(&FreeIOSurfaceForTesting, kBufferId); + handle->mach_port.reset(IOSurfaceCreateMachPort(io_surface)); + return base::Bind(&NoOp); } bool GpuMemoryBufferImplIOSurface::Map() { diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc index f8a74d6..49fab37 100644 --- a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc +++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc @@ -9,7 +9,7 @@ #include "base/logging.h" #include "content/common/gpu/client/gpu_memory_buffer_impl.h" #include "ui/gfx/buffer_format_util.h" -#include "ui/gfx/mac/io_surface_manager.h" +#include "ui/gfx/mac/io_surface.h" #include "ui/gl/gl_image_io_surface.h" namespace content { @@ -49,15 +49,10 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( int client_id, gfx::PluginWindowHandle surface_handle) { base::ScopedCFTypeRef<IOSurfaceRef> io_surface( - gfx::IOSurfaceManager::CreateIOSurface(size, format)); + gfx::CreateIOSurface(size, format)); if (!io_surface) return gfx::GpuMemoryBufferHandle(); - if (!gfx::IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, - io_surface)) { - return gfx::GpuMemoryBufferHandle(); - } - { base::AutoLock lock(io_surfaces_lock_); @@ -69,6 +64,7 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( gfx::GpuMemoryBufferHandle handle; handle.type = gfx::IO_SURFACE_BUFFER; handle.id = id; + handle.mach_port.reset(IOSurfaceCreateMachPort(io_surface)); return handle; } @@ -93,8 +89,6 @@ void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); io_surfaces_.erase(key); } - - gfx::IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id); } gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.h b/content/common/gpu/gpu_memory_buffer_factory_io_surface.h index 753e160..d2fd00d 100644 --- a/content/common/gpu/gpu_memory_buffer_factory_io_surface.h +++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.h @@ -19,7 +19,7 @@ #include "gpu/command_buffer/service/image_factory.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/gpu_memory_buffer.h" -#include "ui/gfx/mac/io_surface_manager.h" +#include "ui/gfx/mac/io_surface.h" namespace gl { class GLImage; @@ -67,6 +67,8 @@ class CONTENT_EXPORT GpuMemoryBufferFactoryIOSurface typedef std::pair<gfx::IOSurfaceId, int> IOSurfaceMapKey; typedef base::hash_map<IOSurfaceMapKey, base::ScopedCFTypeRef<IOSurfaceRef>> IOSurfaceMap; + // TOOD(reveman): Remove |io_surfaces_| and allow IOSurface backed GMBs to be + // used with any GPU process by passing a mach_port to CreateImageCHROMIUM. IOSurfaceMap io_surfaces_; base::Lock io_surfaces_lock_; diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 2f84f97..961c33f 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -46,6 +46,9 @@ #if defined(OS_ANDROID) #include "content/common/android/surface_texture_peer.h" +#elif defined(OS_MACOSX) +#include "ui/base/cocoa/remote_layer_api.h" +#include "ui/gfx/mac/io_surface.h" #endif #undef IPC_MESSAGE_EXPORT @@ -120,7 +123,9 @@ IPC_STRUCT_END() #if defined(OS_MACOSX) IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params) IPC_STRUCT_MEMBER(int32_t, surface_id) - IPC_STRUCT_MEMBER(uint64_t, surface_handle) + // Only one of ca_context_id or io_surface may be non-0. + IPC_STRUCT_MEMBER(CAContextID, ca_context_id) + IPC_STRUCT_MEMBER(gfx::ScopedRefCountedIOSurfaceMachPort, io_surface) IPC_STRUCT_MEMBER(int32_t, route_id) IPC_STRUCT_MEMBER(gfx::Size, size) IPC_STRUCT_MEMBER(float, scale_factor) diff --git a/content/common/gpu/image_transport_surface_overlay_mac.mm b/content/common/gpu/image_transport_surface_overlay_mac.mm index 5a95068..594a6d1 100644 --- a/content/common/gpu/image_transport_surface_overlay_mac.mm +++ b/content/common/gpu/image_transport_surface_overlay_mac.mm @@ -24,7 +24,6 @@ typedef void* GLeglImageOES; #include "base/mac/scoped_cftyperef.h" #include "content/common/gpu/gpu_messages.h" #include "ui/accelerated_widget_mac/io_surface_context.h" -#include "ui/accelerated_widget_mac/surface_handle_types.h" #include "ui/base/cocoa/animation_utils.h" #include "ui/base/cocoa/remote_layer_api.h" #include "ui/base/ui_base_switches.h" @@ -465,11 +464,10 @@ void ImageTransportSurfaceOverlayMac::DisplayFirstPendingSwapImmediately() { // Send acknowledgement to the browser. GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; if (use_remote_layer_api_) { - params.surface_handle = - ui::SurfaceHandleFromCAContextID([ca_context_ contextId]); + params.ca_context_id = [ca_context_ contextId]; } else { - params.surface_handle = - ui::SurfaceHandleFromIOSurfaceID(current_root_plane_->io_surface_id); + params.io_surface.reset( + IOSurfaceCreateMachPort(current_root_plane_->io_surface)); } params.size = swap->pixel_size; params.scale_factor = swap->scale_factor; diff --git a/content/common/mac/io_surface_manager_messages.h b/content/common/mac/io_surface_manager_messages.h deleted file mode 100644 index d72d2b3..0000000 --- a/content/common/mac/io_surface_manager_messages.h +++ /dev/null @@ -1,67 +0,0 @@ -// 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. - -#ifndef CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_MESSAGES_H_ -#define CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_MESSAGES_H_ - -#include <mach/message.h> - -#include "content/common/mac/io_surface_manager_token.h" - -// Mach messages used for child processes. - -// Message IDs. -// Note: we currently use __LINE__ to give unique IDs to messages. -// They're unique since all messages are defined in this file. -#define MACH_MESSAGE_ID() __LINE__ - -namespace content { - -// Messages sent from the child process to the browser. - -struct IOSurfaceManagerHostMsg_RegisterIOSurface { - enum { ID = MACH_MESSAGE_ID() }; - mach_msg_header_t header; - mach_msg_body_t body; - mach_msg_port_descriptor_t io_surface_port; - IOSurfaceManagerToken::Name token_name; - int io_surface_id; - int client_id; -}; - -struct IOSurfaceManagerHostMsg_UnregisterIOSurface { - enum { ID = MACH_MESSAGE_ID() }; - mach_msg_header_t header; - mach_msg_body_t body; - IOSurfaceManagerToken::Name token_name; - int io_surface_id; - int client_id; -}; - -struct IOSurfaceManagerHostMsg_AcquireIOSurface { - enum { ID = MACH_MESSAGE_ID() }; - mach_msg_header_t header; - mach_msg_body_t body; - IOSurfaceManagerToken::Name token_name; - int io_surface_id; -}; - -// Messages sent from the browser to the child process. - -struct IOSurfaceManagerMsg_RegisterIOSurfaceReply { - mach_msg_header_t header; - mach_msg_body_t body; - boolean_t result; -}; - -struct IOSurfaceManagerMsg_AcquireIOSurfaceReply { - mach_msg_header_t header; - mach_msg_body_t body; - mach_msg_port_descriptor_t io_surface_port; - boolean_t result; -}; - -} // namespace content - -#endif // CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_MESSAGES_H_ diff --git a/content/common/mac/io_surface_manager_token.h b/content/common/mac/io_surface_manager_token.h deleted file mode 100644 index cdaebf6..0000000 --- a/content/common/mac/io_surface_manager_token.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -#ifndef CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_TOKEN_H_ -#define CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_TOKEN_H_ - -#include "gpu/command_buffer/common/mailbox.h" - -namespace content { - -using IOSurfaceManagerToken = gpu::Mailbox; - -} // namespace content - -#endif // CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_TOKEN_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 737efe8..259b5ed 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -445,8 +445,6 @@ 'browser/browser_child_process_host_impl.cc', 'browser/browser_child_process_host_impl.h', 'browser/browser_context.cc', - 'browser/browser_io_surface_manager_mac.cc', - 'browser/browser_io_surface_manager_mac.h', 'browser/browser_ipc_logging.cc', 'browser/browser_main.cc', 'browser/browser_main.h', @@ -851,8 +849,6 @@ 'browser/host_zoom_level_context.h', 'browser/host_zoom_map_impl.cc', 'browser/host_zoom_map_impl.h', - 'browser/in_process_io_surface_manager_mac.cc', - 'browser/in_process_io_surface_manager_mac.h', 'browser/indexed_db/indexed_db.h', 'browser/indexed_db/indexed_db_active_blob_registry.cc', 'browser/indexed_db/indexed_db_active_blob_registry.h', diff --git a/content/content_child.gypi b/content/content_child.gypi index 824fddf..bf17bcf 100644 --- a/content/content_child.gypi +++ b/content/content_child.gypi @@ -64,8 +64,6 @@ 'child/child_gpu_memory_buffer_manager.h', 'child/child_histogram_message_filter.cc', 'child/child_histogram_message_filter.h', - 'child/child_io_surface_manager_mac.cc', - 'child/child_io_surface_manager_mac.h', 'child/child_message_filter.cc', 'child/child_message_filter.h', 'child/child_process.cc', diff --git a/content/content_common.gypi b/content/content_common.gypi index d5d97a8..7eb25c8 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -420,8 +420,6 @@ 'common/mac/font_descriptor.mm', 'common/mac/font_loader.h', 'common/mac/font_loader.mm', - 'common/mac/io_surface_manager_messages.h', - 'common/mac/io_surface_manager_token.h', 'common/manifest_manager_messages.h', 'common/media/aec_dump_messages.h', 'common/media/audio_messages.h', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index a9a647bd..ae660cc 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -367,7 +367,6 @@ 'browser/blob_storage/blob_async_builder_host_unittest.cc', 'browser/blob_storage/blob_async_transport_strategy_unittest.cc', 'browser/blob_storage/blob_storage_registry_unittest.cc', - 'browser/browser_io_surface_manager_mac_unittest.cc', 'browser/browser_thread_unittest.cc', 'browser/browser_url_handler_impl_unittest.cc', 'browser/byte_stream_unittest.cc', diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc index 97d66ff..2cb9731 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -23,7 +23,6 @@ #include "base/mac/scoped_nsautorelease_pool.h" #if !defined(OS_IOS) #include "base/test/mock_chrome_application_mac.h" -#include "content/browser/in_process_io_surface_manager_mac.h" #endif #endif @@ -111,9 +110,6 @@ void ContentTestSuite::Initialize() { SurfaceTextureManager::SetInstance( InProcessSurfaceTextureManager::GetInstance()); #endif -#if defined(OS_MACOSX) && !defined(OS_IOS) - gfx::IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance()); -#endif #if defined(USE_OZONE) if (!is_child_process) { client_native_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); diff --git a/ui/accelerated_widget_mac/BUILD.gn b/ui/accelerated_widget_mac/BUILD.gn index 5e6680e..69d2213 100644 --- a/ui/accelerated_widget_mac/BUILD.gn +++ b/ui/accelerated_widget_mac/BUILD.gn @@ -12,8 +12,6 @@ component("accelerated_widget_mac") { "display_link_mac.h", "io_surface_context.h", "io_surface_context.mm", - "surface_handle_types.cc", - "surface_handle_types.h", "window_resize_helper_mac.cc", "window_resize_helper_mac.h", ] diff --git a/ui/accelerated_widget_mac/accelerated_widget_mac.gyp b/ui/accelerated_widget_mac/accelerated_widget_mac.gyp index 6dce667..a062ef7 100644 --- a/ui/accelerated_widget_mac/accelerated_widget_mac.gyp +++ b/ui/accelerated_widget_mac/accelerated_widget_mac.gyp @@ -19,8 +19,6 @@ 'display_link_mac.h', 'io_surface_context.h', 'io_surface_context.mm', - 'surface_handle_types.cc', - 'surface_handle_types.h', 'window_resize_helper_mac.cc', 'window_resize_helper_mac.h', ], diff --git a/ui/accelerated_widget_mac/accelerated_widget_mac.h b/ui/accelerated_widget_mac/accelerated_widget_mac.h index 6b514c8..696dc18 100644 --- a/ui/accelerated_widget_mac/accelerated_widget_mac.h +++ b/ui/accelerated_widget_mac/accelerated_widget_mac.h @@ -12,7 +12,7 @@ #include "base/macros.h" #include "base/time/time.h" #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" -#include "ui/accelerated_widget_mac/surface_handle_types.h" +#include "ui/base/cocoa/remote_layer_api.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_widget_types.h" @@ -20,7 +20,6 @@ #if defined(__OBJC__) #import <Cocoa/Cocoa.h> #import "base/mac/scoped_nsobject.h" -#include "ui/base/cocoa/remote_layer_api.h" #endif // __OBJC__ class SkCanvas; diff --git a/ui/accelerated_widget_mac/surface_handle_types.cc b/ui/accelerated_widget_mac/surface_handle_types.cc deleted file mode 100644 index 3569962..0000000 --- a/ui/accelerated_widget_mac/surface_handle_types.cc +++ /dev/null @@ -1,53 +0,0 @@ -// 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 "ui/accelerated_widget_mac/surface_handle_types.h" - -#include "base/logging.h" - -namespace ui { -namespace { - -// The type of the handle is stored in the upper 64 bits. -const uint64_t kTypeMask = 0xFFFFFFFFull << 32; - -const uint64_t kTypeIOSurface = 0x01010101ull << 32; -const uint64_t kTypeCAContext = 0x02020202ull << 32; - -// To make it a bit less likely that we'll just cast off the top bits of the -// handle to get the ID, XOR lower bits with a type-specific mask. -const uint32_t kXORMaskIOSurface = 0x01010101; -const uint32_t kXORMaskCAContext = 0x02020202; - -} // namespace - -SurfaceHandleType GetSurfaceHandleType(uint64_t surface_handle) { - switch(surface_handle & kTypeMask) { - case kTypeIOSurface: - return kSurfaceHandleTypeIOSurface; - case kTypeCAContext: - return kSurfaceHandleTypeCAContext; - } - return kSurfaceHandleTypeInvalid; -} - -IOSurfaceID IOSurfaceIDFromSurfaceHandle(uint64_t surface_handle) { - DCHECK_EQ(kSurfaceHandleTypeIOSurface, GetSurfaceHandleType(surface_handle)); - return static_cast<uint32_t>(surface_handle) ^ kXORMaskIOSurface; -} - -CAContextID CAContextIDFromSurfaceHandle(uint64_t surface_handle) { - DCHECK_EQ(kSurfaceHandleTypeCAContext, GetSurfaceHandleType(surface_handle)); - return static_cast<uint32_t>(surface_handle) ^ kXORMaskCAContext; -} - -uint64_t SurfaceHandleFromIOSurfaceID(IOSurfaceID io_surface_id) { - return kTypeIOSurface | (io_surface_id ^ kXORMaskIOSurface); -} - -uint64_t SurfaceHandleFromCAContextID(CAContextID ca_context_id) { - return kTypeCAContext | (ca_context_id ^ kXORMaskCAContext); -} - -} // namespace ui diff --git a/ui/accelerated_widget_mac/surface_handle_types.h b/ui/accelerated_widget_mac/surface_handle_types.h deleted file mode 100644 index 23723e8..0000000 --- a/ui/accelerated_widget_mac/surface_handle_types.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -#ifndef UI_ACCELERATED_WIDGET_MAC_SURFACE_HANDLE_TYPES_H_ -#define UI_ACCELERATED_WIDGET_MAC_SURFACE_HANDLE_TYPES_H_ - -#include <IOSurface/IOSurface.h> -#include <OpenGL/CGLIOSurface.h> -#include <stdint.h> - -#include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" -#include "ui/base/cocoa/remote_layer_api.h" - -namespace ui { - -// The surface handle passed between the GPU and browser process may refer to -// an IOSurface or a CAContext. These helper functions must be used to identify -// and translate between the types. -enum SurfaceHandleType { - kSurfaceHandleTypeInvalid, - kSurfaceHandleTypeIOSurface, - kSurfaceHandleTypeCAContext, -}; - -ACCELERATED_WIDGET_MAC_EXPORT -SurfaceHandleType GetSurfaceHandleType(uint64_t surface_handle); - -ACCELERATED_WIDGET_MAC_EXPORT -CAContextID CAContextIDFromSurfaceHandle(uint64_t surface_handle); - -ACCELERATED_WIDGET_MAC_EXPORT -IOSurfaceID IOSurfaceIDFromSurfaceHandle(uint64_t surface_handle); - -ACCELERATED_WIDGET_MAC_EXPORT -uint64_t SurfaceHandleFromIOSurfaceID(IOSurfaceID io_surface_id); - -ACCELERATED_WIDGET_MAC_EXPORT -uint64_t SurfaceHandleFromCAContextID(CAContextID ca_context_id); - -} // namespace ui - -#endif // UI_ACCELERATED_WIDGET_MAC_SURFACE_HANDLE_TYPES_H_ diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index c40a4a3..66b58e8 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -133,8 +133,8 @@ component("gfx") { "linux_font_delegate.h", "mac/coordinate_conversion.h", "mac/coordinate_conversion.mm", - "mac/io_surface_manager.cc", - "mac/io_surface_manager.h", + "mac/io_surface.cc", + "mac/io_surface.h", "mac/nswindow_frame_controls.h", "mac/nswindow_frame_controls.mm", "mac/scoped_cocoa_disable_screen_updates.h", diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index 307ad04..d9e8078 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -123,10 +123,10 @@ 'animation/throb_animation.h', 'animation/tween.cc', 'animation/tween.h', - 'break_list.h', 'blit.cc', 'blit.h', 'break_list.h', + 'break_list.h', 'buffer_format_util.cc', 'buffer_format_util.h', 'canvas.cc', @@ -217,8 +217,8 @@ 'linux_font_delegate.h', 'mac/coordinate_conversion.h', 'mac/coordinate_conversion.mm', - 'mac/io_surface_manager.cc', - 'mac/io_surface_manager.h', + 'mac/io_surface.cc', + 'mac/io_surface.h', 'mac/nswindow_frame_controls.h', 'mac/nswindow_frame_controls.mm', 'mac/scoped_cocoa_disable_screen_updates.h', @@ -525,8 +525,8 @@ 'test/fontconfig_util_linux.h', 'test/gfx_util.cc', 'test/gfx_util.h', - 'test/test_screen.h', 'test/test_screen.cc', + 'test/test_screen.h', 'test/ui_cocoa_test_helper.h', 'test/ui_cocoa_test_helper.mm', ], diff --git a/ui/gfx/gpu_memory_buffer.cc b/ui/gfx/gpu_memory_buffer.cc index f70badb..4bad70e 100644 --- a/ui/gfx/gpu_memory_buffer.cc +++ b/ui/gfx/gpu_memory_buffer.cc @@ -20,4 +20,6 @@ GpuMemoryBufferHandle::GpuMemoryBufferHandle() : type(EMPTY_BUFFER), id(0), handle(base::SharedMemory::NULLHandle()) { } +GpuMemoryBufferHandle::~GpuMemoryBufferHandle() {} + } // namespace gfx diff --git a/ui/gfx/gpu_memory_buffer.h b/ui/gfx/gpu_memory_buffer.h index 6b769c8..ee1de2b 100644 --- a/ui/gfx/gpu_memory_buffer.h +++ b/ui/gfx/gpu_memory_buffer.h @@ -18,6 +18,8 @@ #if defined(USE_OZONE) #include "ui/gfx/native_pixmap_handle_ozone.h" +#elif defined(OS_MACOSX) +#include "ui/gfx/mac/io_surface.h" #endif extern "C" typedef struct _ClientBuffer* ClientBuffer; @@ -37,6 +39,7 @@ using GpuMemoryBufferId = GenericSharedMemoryId; struct GFX_EXPORT GpuMemoryBufferHandle { GpuMemoryBufferHandle(); + ~GpuMemoryBufferHandle(); bool is_null() const { return type == EMPTY_BUFFER; } GpuMemoryBufferType type; GpuMemoryBufferId id; @@ -45,6 +48,8 @@ struct GFX_EXPORT GpuMemoryBufferHandle { int32_t stride; #if defined(USE_OZONE) NativePixmapHandle native_pixmap_handle; +#elif defined(OS_MACOSX) + ScopedRefCountedIOSurfaceMachPort mach_port; #endif }; diff --git a/ui/gfx/ipc/gfx_param_traits.cc b/ui/gfx/ipc/gfx_param_traits.cc index 2eeefbf..a49e1da 100644 --- a/ui/gfx/ipc/gfx_param_traits.cc +++ b/ui/gfx/ipc/gfx_param_traits.cc @@ -16,6 +16,10 @@ #include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/range/range.h" +#if defined(OS_MACOSX) +#include "ipc/mach_port_mac.h" +#endif + namespace { struct SkBitmap_Data { @@ -340,6 +344,33 @@ void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) { l->append(")"); } +#if defined(OS_MACOSX) && !defined(OS_IOS) +void ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Write( + Message* m, + const param_type p) { + MachPortMac mach_port_mac(p.get()); + ParamTraits<MachPortMac>::Write(m, mach_port_mac); +} + +bool ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Read( + const Message* m, + base::PickleIterator* iter, + param_type* r) { + MachPortMac mach_port_mac; + if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac)) + return false; + r->reset(mach_port_mac.get_mach_port()); + return true; +} + +void ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Log( + const param_type& p, + std::string* l) { + l->append("IOSurface Mach send right: "); + LogParam(p.get(), l); +} +#endif // defined(OS_MACOSX) && !defined(OS_IOS) + } // namespace IPC // Generate param traits write methods. diff --git a/ui/gfx/ipc/gfx_param_traits.h b/ui/gfx/ipc/gfx_param_traits.h index 337505a..b7280ef 100644 --- a/ui/gfx/ipc/gfx_param_traits.h +++ b/ui/gfx/ipc/gfx_param_traits.h @@ -13,6 +13,10 @@ #include "ui/gfx/ipc/gfx_ipc_export.h" #include "ui/gfx/ipc/gfx_param_traits_macros.h" +#if defined(OS_MACOSX) && !defined(OS_IOS) +#include "ui/gfx/mac/io_surface.h" +#endif + class SkBitmap; namespace gfx { @@ -131,6 +135,20 @@ struct GFX_IPC_EXPORT ParamTraits<gfx::ScrollOffset> { static void Log(const param_type& p, std::string* l); }; +#if defined(OS_MACOSX) && !defined(OS_IOS) +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort> { + typedef gfx::ScopedRefCountedIOSurfaceMachPort param_type; + static void Write(Message* m, const param_type p); + // Note: Read() passes ownership of the Mach send right from the IPC message + // to the ScopedRefCountedIOSurfaceMachPort. Therefore, Read() may only be + // called once for a given message, otherwise the singular right will be + // managed and released by two objects. + static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; +#endif // defined(OS_MACOSX) && !defined(OS_IOS) + } // namespace IPC #endif // UI_GFX_IPC_GFX_PARAM_TRAITS_H_ diff --git a/ui/gfx/mac/io_surface_manager.cc b/ui/gfx/mac/io_surface.cc index 9e3e9cf..8c748bc 100644 --- a/ui/gfx/mac/io_surface_manager.cc +++ b/ui/gfx/mac/io_surface.cc @@ -2,21 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/gfx/mac/io_surface_manager.h" +#include "ui/gfx/mac/io_surface.h" -#include <IOSurface/IOSurface.h> #include <stddef.h> #include <stdint.h> #include "base/logging.h" -#include "base/mac/scoped_cftyperef.h" +#include "base/mac/mach_logging.h" #include "base/macros.h" #include "ui/gfx/buffer_format_util.h" namespace gfx { -namespace { -IOSurfaceManager* g_instance = NULL; +namespace { void AddIntegerValue(CFMutableDictionaryRef dictionary, const CFStringRef key, @@ -89,21 +87,28 @@ int32_t PixelFormat(gfx::BufferFormat format) { } // namespace +namespace internal { + // static -IOSurfaceManager* IOSurfaceManager::GetInstance() { - DCHECK(g_instance); - return g_instance; +mach_port_t IOSurfaceMachPortTraits::Retain(mach_port_t port) { + kern_return_t kr = + mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, 1); + MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) + << "IOSurfaceMachPortTraits::Retain mach_port_mod_refs"; + return port; } // static -void IOSurfaceManager::SetInstance(IOSurfaceManager* instance) { - DCHECK(!g_instance || !instance); - g_instance = instance; +void IOSurfaceMachPortTraits::Release(mach_port_t port) { + kern_return_t kr = + mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, -1); + MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) + << "IOSurfaceMachPortTraits::Release mach_port_mod_refs"; } -// static -IOSurfaceRef IOSurfaceManager::CreateIOSurface(const gfx::Size& size, - gfx::BufferFormat format) { +} // namespace internal + +IOSurfaceRef CreateIOSurface(const gfx::Size& size, gfx::BufferFormat format) { size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); @@ -146,4 +151,4 @@ IOSurfaceRef IOSurfaceManager::CreateIOSurface(const gfx::Size& size, return IOSurfaceCreate(properties); } -} // namespace content +} // namespace gfx diff --git a/ui/gfx/mac/io_surface.h b/ui/gfx/mac/io_surface.h new file mode 100644 index 0000000..4c24fe4 --- /dev/null +++ b/ui/gfx/mac/io_surface.h @@ -0,0 +1,43 @@ +// 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. + +#ifndef UI_GFX_MAC_IO_SURFACE_H_ +#define UI_GFX_MAC_IO_SURFACE_H_ + +#include <IOSurface/IOSurface.h> +#include <mach/mach.h> + +#include "base/mac/scoped_cftyperef.h" +#include "ui/gfx/buffer_types.h" +#include "ui/gfx/generic_shared_memory_id.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/gfx_export.h" + +namespace gfx { + +namespace internal { + +struct IOSurfaceMachPortTraits { + GFX_EXPORT static mach_port_t InvalidValue() { return MACH_PORT_NULL; } + GFX_EXPORT static mach_port_t Retain(mach_port_t); + GFX_EXPORT static void Release(mach_port_t); +}; + +} // namespace internal + +using IOSurfaceId = GenericSharedMemoryId; + +// Helper function to create an IOSurface with a specified size and format. +GFX_EXPORT IOSurfaceRef CreateIOSurface(const Size& size, BufferFormat format); + +// A scoper for handling Mach port names that are send rights for IOSurfaces. +// This scoper is both copyable and assignable, which will increase the kernel +// reference count of the right. On destruction, the reference count is +// decremented. +using ScopedRefCountedIOSurfaceMachPort = + base::ScopedTypeRef<mach_port_t, internal::IOSurfaceMachPortTraits>; + +} // namespace gfx + +#endif // UI_GFX_MAC_IO_SURFACE_H_ diff --git a/ui/gfx/mac/io_surface_manager.h b/ui/gfx/mac/io_surface_manager.h deleted file mode 100644 index 130214c..0000000 --- a/ui/gfx/mac/io_surface_manager.h +++ /dev/null @@ -1,50 +0,0 @@ -// 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. - -#ifndef CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_H_ -#define CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_H_ - -#include <IOSurface/IOSurface.h> - -#include "ui/gfx/buffer_types.h" -#include "ui/gfx/generic_shared_memory_id.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/gfx_export.h" - -namespace gfx { - -using IOSurfaceId = GenericSharedMemoryId; - -// This interface provides a mechanism for different processes to securely -// share IOSurfaces. A process can register an IOSurface for use in another -// process and the client ID provided with registration determines the process -// that can acquire a reference to the IOSurface. -class GFX_EXPORT IOSurfaceManager { - public: - static IOSurfaceManager* GetInstance(); - static void SetInstance(IOSurfaceManager* instance); - - // Helper function to create an IOSurface with a specified size and format. - static IOSurfaceRef CreateIOSurface(const Size& size, BufferFormat format); - - // Register an IO surface for use in another process. - virtual bool RegisterIOSurface(IOSurfaceId io_surface_id, - int client_id, - IOSurfaceRef io_surface) = 0; - - // Unregister an IO surface previously registered for use in another - // process. - virtual void UnregisterIOSurface(IOSurfaceId io_surface_id, - int client_id) = 0; - - // Acquire IO surface reference for a registered IO surface. - virtual IOSurfaceRef AcquireIOSurface(IOSurfaceId io_surface_id) = 0; - - protected: - virtual ~IOSurfaceManager() {} -}; - -} // namespace content - -#endif // CONTENT_COMMON_MAC_IO_SURFACE_MANAGER_H_ diff --git a/ui/gl/gl_image_io_surface_unittest.cc b/ui/gl/gl_image_io_surface_unittest.cc index 8936ada..487366f 100644 --- a/ui/gl/gl_image_io_surface_unittest.cc +++ b/ui/gl/gl_image_io_surface_unittest.cc @@ -7,7 +7,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/buffer_format_util.h" -#include "ui/gfx/mac/io_surface_manager.h" +#include "ui/gfx/mac/io_surface.h" #include "ui/gl/gl_image_io_surface.h" #include "ui/gl/test/gl_image_test_template.h" @@ -21,8 +21,7 @@ class GLImageIOSurfaceTestDelegate { const uint8_t color[4]) const { scoped_refptr<GLImageIOSurface> image(new GLImageIOSurface( size, GLImageIOSurface::GetInternalFormatForTesting(format))); - IOSurfaceRef surface_ref = - gfx::IOSurfaceManager::CreateIOSurface(size, format); + IOSurfaceRef surface_ref = gfx::CreateIOSurface(size, format); IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr); EXPECT_NE(status, kIOReturnCannotLock); for (size_t plane = 0; plane < NumberOfPlanesForBufferFormat(format); |