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 { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CHECK(!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 CHECK_EQ(KERN_SUCCESS, kr); |
103 MACH_LOG(ERROR, kr) << "mach_port_allocate"; | |
104 return nullptr; | |
105 } | |
106 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); | 103 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port); |
107 | 104 |
108 union { | 105 union { |
109 IOSurfaceManagerHostMsg_AcquireIOSurface request; | 106 IOSurfaceManagerHostMsg_AcquireIOSurface request; |
110 struct { | 107 struct { |
111 IOSurfaceManagerMsg_AcquireIOSurfaceReply msg; | 108 IOSurfaceManagerMsg_AcquireIOSurfaceReply msg; |
112 mach_msg_trailer_t trailer; | 109 mach_msg_trailer_t trailer; |
113 } reply; | 110 } reply; |
114 } data = {{{0}}}; | 111 } data = {{{0}}}; |
115 data.request.header.msgh_bits = | 112 data.request.header.msgh_bits = |
116 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); | 113 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); |
117 data.request.header.msgh_remote_port = service_port_.get(); | 114 data.request.header.msgh_remote_port = service_port_.get(); |
118 data.request.header.msgh_local_port = reply_port; | 115 data.request.header.msgh_local_port = reply_port; |
119 data.request.header.msgh_size = sizeof(data.request); | 116 data.request.header.msgh_size = sizeof(data.request); |
120 data.request.header.msgh_id = IOSurfaceManagerHostMsg_AcquireIOSurface::ID; | 117 data.request.header.msgh_id = IOSurfaceManagerHostMsg_AcquireIOSurface::ID; |
121 data.request.io_surface_id = io_surface_id.id; | 118 data.request.io_surface_id = io_surface_id.id; |
122 memcpy(data.request.token_name, token_.name, sizeof(token_.name)); | 119 memcpy(data.request.token_name, token_.name, sizeof(token_.name)); |
123 | 120 |
124 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG, | 121 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG, |
125 sizeof(data.request), sizeof(data.reply), reply_port, | 122 sizeof(data.request), sizeof(data.reply), reply_port, |
126 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); | 123 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); |
127 if (kr != KERN_SUCCESS) { | 124 CHECK_EQ(KERN_SUCCESS, kr); |
128 MACH_LOG(ERROR, kr) << "mach_msg"; | 125 CHECK(data.reply.msg.result); |
129 return nullptr; | |
130 } | |
131 if (!data.reply.msg.result) { | |
132 DLOG(ERROR) << "Browser refused AcquireIOSurface request"; | |
133 return nullptr; | |
134 } | |
135 | 126 |
136 // Deallocate the right after creating an IOSurface reference. | 127 // Deallocate the right after creating an IOSurface reference. |
137 base::mac::ScopedMachSendRight scoped_io_surface_right( | 128 base::mac::ScopedMachSendRight scoped_io_surface_right( |
138 data.reply.msg.io_surface_port.name); | 129 data.reply.msg.io_surface_port.name); |
139 | 130 |
140 return IOSurfaceLookupFromMachPort(scoped_io_surface_right.get()); | 131 IOSurfaceRef io_surface = |
| 132 IOSurfaceLookupFromMachPort(scoped_io_surface_right.get()); |
| 133 CHECK(io_surface); |
| 134 return io_surface; |
141 } | 135 } |
142 | 136 |
143 ChildIOSurfaceManager::ChildIOSurfaceManager() {} | 137 ChildIOSurfaceManager::ChildIOSurfaceManager() {} |
144 | 138 |
145 ChildIOSurfaceManager::~ChildIOSurfaceManager() {} | 139 ChildIOSurfaceManager::~ChildIOSurfaceManager() {} |
146 | 140 |
147 } // namespace content | 141 } // namespace content |
OLD | NEW |