Chromium Code Reviews| 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/browser/browser_io_surface_manager_mac.h" | 5 #include "content/browser/browser_io_surface_manager_mac.h" |
| 6 | 6 |
| 7 #include <servers/bootstrap.h> | 7 #include <servers/bootstrap.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } | 192 } |
| 193 | 193 |
| 194 union { | 194 union { |
| 195 mach_msg_header_t header; | 195 mach_msg_header_t header; |
| 196 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; | 196 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; |
| 197 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; | 197 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; |
| 198 } reply = {{0}}; | 198 } reply = {{0}}; |
| 199 | 199 |
| 200 switch (request.msg.header.msgh_id) { | 200 switch (request.msg.header.msgh_id) { |
| 201 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: | 201 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: |
| 202 if (!HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, | 202 HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, |
| 203 &reply.register_io_surface)) { | 203 &reply.register_io_surface); |
| 204 return; | |
| 205 } | |
| 206 break; | 204 break; |
| 207 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: | 205 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: |
| 208 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); | 206 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); |
| 209 // Unregister requests are asynchronous and do not require a reply as | 207 // Unregister requests are asynchronous and do not require a reply as |
| 210 // there is no guarantee for how quickly an IO surface is removed from | 208 // there is no guarantee for how quickly an IO surface is removed from |
| 211 // the IOSurfaceManager instance after it has been deleted by a child | 209 // the IOSurfaceManager instance after it has been deleted by a child |
| 212 // process. | 210 // process. |
| 213 return; | 211 return; |
| 214 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: | 212 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: |
| 215 if (!HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, | 213 HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, |
| 216 &reply.acquire_io_surface)) { | 214 &reply.acquire_io_surface); |
| 217 return; | |
| 218 } | |
| 219 break; | 215 break; |
| 220 default: | 216 default: |
| 221 LOG(ERROR) << "Unknown message received!"; | 217 LOG(ERROR) << "Unknown message received!"; |
| 222 return; | 218 return; |
| 223 } | 219 } |
| 224 | 220 |
| 225 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, | 221 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, |
| 226 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, | 222 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, |
| 227 MACH_PORT_NULL); | 223 MACH_PORT_NULL); |
| 228 if (kr != KERN_SUCCESS) { | 224 if (kr != KERN_SUCCESS) { |
| 229 MACH_LOG(ERROR, kr) << "mach_msg"; | 225 MACH_LOG(ERROR, kr) << "mach_msg"; |
| 230 } | 226 } |
| 231 } | 227 } |
| 232 | 228 |
| 233 bool BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( | 229 void BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( |
| 234 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, | 230 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, |
| 235 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { | 231 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { |
| 236 base::AutoLock lock(lock_); | 232 base::AutoLock lock(lock_); |
| 237 | 233 |
| 238 IOSurfaceManagerToken token; | 234 IOSurfaceManagerToken token; |
| 239 static_assert(sizeof(request.token_name) == sizeof(token.name), | 235 static_assert(sizeof(request.token_name) == sizeof(token.name), |
| 240 "Mach message token size doesn't match expectation."); | 236 "Mach message token size doesn't match expectation."); |
| 241 token.SetName(request.token_name); | 237 token.SetName(request.token_name); |
| 242 if (token.IsZero() || token != gpu_process_token_) { | 238 if (token.IsZero() || token != gpu_process_token_) { |
| 243 LOG(ERROR) << "Illegal message from non-GPU process!"; | 239 LOG(ERROR) << "Illegal message from non-GPU process!"; |
| 244 return false; | 240 reply->result = false; |
|
reveman
2015/09/17 18:58:16
You'll need to set reply->header.msgh_bits/msgh_re
ccameron
2015/09/18 18:06:13
Done.
| |
| 241 return; | |
| 245 } | 242 } |
| 246 | 243 |
| 247 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); | 244 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); |
| 248 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( | 245 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( |
| 249 request.io_surface_port.name))); | 246 request.io_surface_port.name))); |
| 250 | 247 |
| 251 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); | 248 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); |
| 252 reply->header.msgh_remote_port = request.header.msgh_remote_port; | 249 reply->header.msgh_remote_port = request.header.msgh_remote_port; |
| 253 reply->header.msgh_size = sizeof(*reply); | 250 reply->header.msgh_size = sizeof(*reply); |
| 254 reply->result = true; | 251 reply->result = true; |
| 255 return true; | |
| 256 } | 252 } |
| 257 | 253 |
| 258 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( | 254 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( |
| 259 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { | 255 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { |
| 260 base::AutoLock lock(lock_); | 256 base::AutoLock lock(lock_); |
| 261 | 257 |
| 262 IOSurfaceManagerToken token; | 258 IOSurfaceManagerToken token; |
| 263 static_assert(sizeof(request.token_name) == sizeof(token.name), | 259 static_assert(sizeof(request.token_name) == sizeof(token.name), |
| 264 "Mach message token size doesn't match expectation."); | 260 "Mach message token size doesn't match expectation."); |
| 265 token.SetName(request.token_name); | 261 token.SetName(request.token_name); |
| 266 if (token.IsZero() || token != gpu_process_token_) { | 262 if (token.IsZero() || token != gpu_process_token_) { |
| 267 LOG(ERROR) << "Illegal message from non-GPU process!"; | 263 LOG(ERROR) << "Illegal message from non-GPU process!"; |
| 268 return false; | 264 return false; |
| 269 } | 265 } |
| 270 | 266 |
| 271 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); | 267 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); |
| 272 io_surfaces_.erase(key); | 268 io_surfaces_.erase(key); |
| 273 return true; | 269 return true; |
| 274 } | 270 } |
| 275 | 271 |
| 276 bool BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( | 272 void BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( |
| 277 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, | 273 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, |
| 278 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { | 274 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { |
| 279 base::AutoLock lock(lock_); | 275 base::AutoLock lock(lock_); |
| 280 | 276 |
| 281 IOSurfaceManagerToken token; | 277 IOSurfaceManagerToken token; |
| 282 static_assert(sizeof(request.token_name) == sizeof(token.name), | 278 static_assert(sizeof(request.token_name) == sizeof(token.name), |
| 283 "Mach message token size doesn't match expectation."); | 279 "Mach message token size doesn't match expectation."); |
| 284 token.SetName(request.token_name); | 280 token.SetName(request.token_name); |
| 285 auto child_process_id_it = child_process_ids_.find(token); | 281 auto child_process_id_it = child_process_ids_.find(token); |
| 286 if (child_process_id_it == child_process_ids_.end()) { | 282 if (child_process_id_it == child_process_ids_.end()) { |
| 287 LOG(ERROR) << "Illegal message from non-child process!"; | 283 LOG(ERROR) << "Illegal message from non-child process!"; |
| 288 return false; | 284 reply->result = false; |
|
reveman
2015/09/17 18:58:16
Same here.
ccameron
2015/09/18 18:06:13
Done.
| |
| 285 return; | |
| 289 } | 286 } |
| 290 | 287 |
| 291 reply->header.msgh_bits = | 288 reply->header.msgh_bits = |
| 292 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; | 289 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; |
| 293 reply->header.msgh_remote_port = request.header.msgh_remote_port; | 290 reply->header.msgh_remote_port = request.header.msgh_remote_port; |
| 294 reply->header.msgh_size = sizeof(*reply); | 291 reply->header.msgh_size = sizeof(*reply); |
| 292 reply->result = true; | |
| 295 | 293 |
| 296 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), | 294 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), |
| 297 child_process_id_it->second); | 295 child_process_id_it->second); |
| 298 auto it = io_surfaces_.find(key); | 296 auto it = io_surfaces_.find(key); |
| 299 if (it == io_surfaces_.end()) { | 297 if (it == io_surfaces_.end()) { |
| 300 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; | 298 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; |
| 301 return true; | 299 return; |
| 302 } | 300 } |
| 303 | 301 |
| 304 reply->body.msgh_descriptor_count = 1; | 302 reply->body.msgh_descriptor_count = 1; |
| 305 reply->io_surface_port.name = it->second->get(); | 303 reply->io_surface_port.name = it->second->get(); |
| 306 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; | 304 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; |
| 307 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; | 305 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; |
| 308 return true; | |
| 309 } | 306 } |
| 310 | 307 |
| 311 } // namespace content | 308 } // namespace content |
| OLD | NEW |