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.
5 #ifndef CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_
6 #define CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_
8 #include "base/mac/scoped_mach_port.h"
9 #include "base/macros.h"
10 #include "base/memory/singleton.h"
11 #include "content/common/mac/io_surface_manager.h"
12 #include "content/common/mac/io_surface_manager_token.h"
16 // Implementation of IOSurfaceManager that registers and acquires IOSurfaces
17 // through a Mach service.
18 class CONTENT_EXPORT ChildIOSurfaceManager
: public IOSurfaceManager
{
20 // Returns the global ChildIOSurfaceManager.
21 static ChildIOSurfaceManager
* GetInstance();
23 // Overridden from IOSurfaceManager:
24 bool RegisterIOSurface(IOSurfaceId io_surface_id
,
26 IOSurfaceRef io_surface
) override
;
27 void UnregisterIOSurface(IOSurfaceId io_surface_id
, int client_id
) override
;
28 IOSurfaceRef
AcquireIOSurface(IOSurfaceId io_surface_id
) override
;
30 // Set the service Mach port. Ownership of |service_port| is passed to the
32 // Note: This can be called on any thread but must happen before the
33 // thread-safe IOSurfaceManager interface is used. It is the responsibility
34 // of users of this class to ensure there are no races.
35 void set_service_port(mach_port_t service_port
) {
36 service_port_
.reset(service_port
);
39 // Set the token used when communicating with the Mach service.
40 // Note: This can be called on any thread but must happen before the
41 // thread-safe IOSurfaceManager interface is used. It is the responsibility
42 // of users of this class to ensure there are no races.
43 void set_token(const IOSurfaceManagerToken
& token
) {
48 friend struct base::DefaultSingletonTraits
<ChildIOSurfaceManager
>;
50 ChildIOSurfaceManager();
51 ~ChildIOSurfaceManager() override
;
53 base::mac::ScopedMachSendRight service_port_
;
54 IOSurfaceManagerToken token_
;
56 DISALLOW_COPY_AND_ASSIGN(ChildIOSurfaceManager
);
59 } // namespace content
61 #endif // CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_