OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/child_io_surface_manager_mac.h" | 5 #include "content/child/child_io_surface_manager_mac.h" |
6 | 6 |
7 #include "base/mac/mach_logging.h" | 7 #include "base/mac/mach_logging.h" |
8 #include "content/common/mac/io_surface_manager_messages.h" | 8 #include "content/common/mac/io_surface_manager_messages.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 // static | 12 // static |
13 ChildIOSurfaceManager* ChildIOSurfaceManager::GetInstance() { | 13 ChildIOSurfaceManager* ChildIOSurfaceManager::GetInstance() { |
14 return base::Singleton< | 14 return base::Singleton< |
15 ChildIOSurfaceManager, | 15 ChildIOSurfaceManager, |
16 base::LeakySingletonTraits<ChildIOSurfaceManager>>::get(); | 16 base::LeakySingletonTraits<ChildIOSurfaceManager>>::get(); |
17 } | 17 } |
18 | 18 |
19 bool ChildIOSurfaceManager::RegisterIOSurface(gfx::IOSurfaceId io_surface_id, | 19 bool ChildIOSurfaceManager::RegisterIOSurface(gfx::IOSurfaceId io_surface_id, |
20 int client_id, | 20 int client_id, |
21 IOSurfaceRef io_surface) { | 21 IOSurfaceRef io_surface) { |
22 DCHECK(service_port_.is_valid()); | 22 DCHECK(service_port_.is_valid()); |
23 DCHECK(!token_.IsZero()); | 23 CHECK(!token_.IsZero()); |
24 | 24 |
25 mach_port_t reply_port; | 25 mach_port_t reply_port; |
26 kern_return_t kr = mach_port_allocate(mach_task_self(), | 26 kern_return_t kr = mach_port_allocate(mach_task_self(), |
27 MACH_PORT_RIGHT_RECEIVE, &reply_port); | 27 MACH_PORT_RIGHT_RECEIVE, &reply_port); |
28 if (kr != KERN_SUCCESS) { | 28 if (kr != KERN_SUCCESS) { |
29 MACH_LOG(ERROR, kr) << "mach_port_allocate"; | 29 MACH_LOG(ERROR, kr) << "mach_port_allocate"; |
30 return false; | 30 return false; |
31 } | 31 } |
32 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); | 32 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); |
33 | 33 |
(...skipping 30 matching lines...) Expand all Loading... |
64 MACH_LOG(ERROR, kr) << "mach_msg"; | 64 MACH_LOG(ERROR, kr) << "mach_msg"; |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 return data.reply.msg.result; | 68 return data.reply.msg.result; |
69 } | 69 } |
70 | 70 |
71 void ChildIOSurfaceManager::UnregisterIOSurface(gfx::IOSurfaceId io_surface_id, | 71 void ChildIOSurfaceManager::UnregisterIOSurface(gfx::IOSurfaceId io_surface_id, |
72 int client_id) { | 72 int client_id) { |
73 DCHECK(service_port_.is_valid()); | 73 DCHECK(service_port_.is_valid()); |
74 DCHECK(!token_.IsZero()); | 74 CHECK(!token_.IsZero()); |
75 | 75 |
76 IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; | 76 IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; |
77 request.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); | 77 request.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); |
78 request.header.msgh_remote_port = service_port_.get(); | 78 request.header.msgh_remote_port = service_port_.get(); |
79 request.header.msgh_local_port = MACH_PORT_NULL; | 79 request.header.msgh_local_port = MACH_PORT_NULL; |
80 request.header.msgh_size = sizeof(request); | 80 request.header.msgh_size = sizeof(request); |
81 request.header.msgh_id = IOSurfaceManagerHostMsg_UnregisterIOSurface::ID; | 81 request.header.msgh_id = IOSurfaceManagerHostMsg_UnregisterIOSurface::ID; |
82 request.io_surface_id = io_surface_id.id; | 82 request.io_surface_id = io_surface_id.id; |
83 request.client_id = client_id; | 83 request.client_id = client_id; |
84 memcpy(request.token_name, token_.name, sizeof(token_.name)); | 84 memcpy(request.token_name, token_.name, sizeof(token_.name)); |
85 | 85 |
86 kern_return_t kr = | 86 kern_return_t kr = |
87 mach_msg(&request.header, MACH_SEND_MSG, sizeof(request), 0, | 87 mach_msg(&request.header, MACH_SEND_MSG, sizeof(request), 0, |
88 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); | 88 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); |
89 if (kr != KERN_SUCCESS) { | 89 if (kr != KERN_SUCCESS) { |
90 MACH_LOG(ERROR, kr) << "mach_msg"; | 90 MACH_LOG(ERROR, kr) << "mach_msg"; |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 IOSurfaceRef ChildIOSurfaceManager::AcquireIOSurface( | 94 IOSurfaceRef ChildIOSurfaceManager::AcquireIOSurface( |
95 gfx::IOSurfaceId io_surface_id) { | 95 gfx::IOSurfaceId io_surface_id) { |
96 DCHECK(service_port_.is_valid()); | 96 DCHECK(service_port_.is_valid()); |
97 DCHECK(!token_.IsZero()); | 97 CHECK(!token_.IsZero()); |
98 | 98 |
99 mach_port_t reply_port; | 99 mach_port_t reply_port; |
100 kern_return_t kr = mach_port_allocate(mach_task_self(), | 100 kern_return_t kr = mach_port_allocate(mach_task_self(), |
101 MACH_PORT_RIGHT_RECEIVE, &reply_port); | 101 MACH_PORT_RIGHT_RECEIVE, &reply_port); |
102 if (kr != KERN_SUCCESS) { | 102 if (kr != KERN_SUCCESS) { |
103 MACH_LOG(ERROR, kr) << "mach_port_allocate"; | 103 MACH_LOG(ERROR, kr) << "mach_port_allocate"; |
104 return nullptr; | 104 return nullptr; |
105 } | 105 } |
106 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); | 106 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); |
107 | 107 |
(...skipping 30 matching lines...) Expand all Loading... |
138 data.reply.msg.io_surface_port.name); | 138 data.reply.msg.io_surface_port.name); |
139 | 139 |
140 return IOSurfaceLookupFromMachPort(scoped_io_surface_right.get()); | 140 return IOSurfaceLookupFromMachPort(scoped_io_surface_right.get()); |
141 } | 141 } |
142 | 142 |
143 ChildIOSurfaceManager::ChildIOSurfaceManager() {} | 143 ChildIOSurfaceManager::ChildIOSurfaceManager() {} |
144 | 144 |
145 ChildIOSurfaceManager::~ChildIOSurfaceManager() {} | 145 ChildIOSurfaceManager::~ChildIOSurfaceManager() {} |
146 | 146 |
147 } // namespace content | 147 } // namespace content |
OLD | NEW |