Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: content/child/child_io_surface_manager_mac.cc

Issue 1137453002: content: Pass IOSurface references using Mach IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsesek's review Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/child_io_surface_manager_mac.h"
6
7 #include "base/mac/mach_logging.h"
8 #include "content/common/mac/io_surface_manager_messages.h"
9
10 namespace content {
11
12 // static
13 ChildIOSurfaceManager* ChildIOSurfaceManager::GetInstance() {
14 return Singleton<ChildIOSurfaceManager,
15 LeakySingletonTraits<ChildIOSurfaceManager>>::get();
16 }
17
18 bool ChildIOSurfaceManager::RegisterIOSurface(int io_surface_id,
19 int client_id,
20 IOSurfaceRef io_surface) {
21 mach_port_t reply_port;
22 kern_return_t kr = mach_port_allocate(mach_task_self(),
23 MACH_PORT_RIGHT_RECEIVE, &reply_port);
24 if (kr != KERN_SUCCESS) {
25 MACH_LOG(ERROR, kr) << "mach_port_allocate";
26 return false;
27 }
28 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port);
29
30 // Deallocate the right after sending a copy to the parent.
31 base::mac::ScopedMachSendRight scoped_io_surface_right(
32 IOSurfaceCreateMachPort(io_surface));
33
34 union {
35 IOSurfaceManagerHostMsg_RegisterIOSurface request;
36 struct {
37 IOSurfaceManagerMsg_RegisterIOSurfaceReply msg;
38 mach_msg_trailer_t trailer;
39 } reply;
40 } data = {{{0}}};
41 data.request.header.msgh_bits =
42 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE) |
43 MACH_MSGH_BITS_COMPLEX;
44 DCHECK(service_port_.is_valid());
Robert Sesek 2015/06/01 21:58:06 Move this DCHECK to the top of the function.
reveman 2015/06/02 22:48:07 Done. Moved all DCHECKs in this file to the top of
45 data.request.header.msgh_remote_port = service_port_;
46 data.request.header.msgh_local_port = reply_port;
47 data.request.header.msgh_size = sizeof(data.request);
48 data.request.header.msgh_id = IOSurfaceManagerHostMsg_RegisterIOSurface::ID;
49 data.request.body.msgh_descriptor_count = 1;
50 data.request.io_surface_port.name = scoped_io_surface_right;
51 data.request.io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND;
52 data.request.io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR;
53 data.request.io_surface_id = io_surface_id;
54 data.request.client_id = client_id;
55 DCHECK(!token_.IsZero());
56 memcpy(data.request.token_name, token_.name, sizeof(token_.name));
57
58 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG,
59 sizeof(data.request), sizeof(data.reply), reply_port,
60 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
61 if (kr != KERN_SUCCESS) {
62 MACH_LOG(ERROR, kr) << "mach_msg";
63 return false;
64 }
65
66 return data.reply.msg.result;
67 }
68
69 void ChildIOSurfaceManager::UnregisterIOSurface(int io_surface_id,
70 int client_id) {
71 IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}};
72 request.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
73 DCHECK(service_port_.is_valid());
74 request.header.msgh_remote_port = service_port_;
75 request.header.msgh_local_port = MACH_PORT_NULL;
76 request.header.msgh_size = sizeof(request);
77 request.header.msgh_id = IOSurfaceManagerHostMsg_UnregisterIOSurface::ID;
78 request.io_surface_id = io_surface_id;
79 request.client_id = client_id;
80 DCHECK(!token_.IsZero());
81 memcpy(request.token_name, token_.name, sizeof(token_.name));
82
83 kern_return_t kr =
84 mach_msg(&request.header, MACH_SEND_MSG, sizeof(request), 0,
85 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
86 if (kr != KERN_SUCCESS) {
87 MACH_LOG(ERROR, kr) << "mach_msg";
88 }
89 }
90
91 IOSurfaceRef ChildIOSurfaceManager::AcquireIOSurface(int io_surface_id) {
92 mach_port_t reply_port;
93 kern_return_t kr = mach_port_allocate(mach_task_self(),
94 MACH_PORT_RIGHT_RECEIVE, &reply_port);
95 if (kr != KERN_SUCCESS) {
96 MACH_LOG(ERROR, kr) << "mach_port_allocate";
97 return nullptr;
98 }
99 base::mac::ScopedMachReceiveRight scoped_receive_right(reply_port);
100
101 union {
102 IOSurfaceManagerHostMsg_AcquireIOSurface request;
103 struct {
104 IOSurfaceManagerMsg_AcquireIOSurfaceReply msg;
105 mach_msg_trailer_t trailer;
106 } reply;
107 } data = {{{0}}};
108 data.request.header.msgh_bits =
109 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
110 DCHECK(service_port_.is_valid());
111 data.request.header.msgh_remote_port = service_port_;
112 data.request.header.msgh_local_port = reply_port;
113 data.request.header.msgh_size = sizeof(data.request);
114 data.request.header.msgh_id = IOSurfaceManagerHostMsg_AcquireIOSurface::ID;
115 data.request.io_surface_id = io_surface_id;
116 DCHECK(!token_.IsZero());
117 memcpy(data.request.token_name, token_.name, sizeof(token_.name));
118
119 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG,
120 sizeof(data.request), sizeof(data.reply), reply_port,
121 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
122 if (kr != KERN_SUCCESS) {
123 MACH_LOG(ERROR, kr) << "mach_msg";
124 return nullptr;
125 }
126
127 // Deallocate the right after creating an IOSurface reference.
128 base::mac::ScopedMachSendRight scoped_io_surface_right(
129 data.reply.msg.io_surface_port.name);
130
131 return IOSurfaceLookupFromMachPort(scoped_io_surface_right);
132 }
133
134 ChildIOSurfaceManager::ChildIOSurfaceManager() {
135 }
136
137 ChildIOSurfaceManager::~ChildIOSurfaceManager() {
138 }
139
140 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698