Vibration API: convert implementation to java mojo-service.
[chromium-blink-merge.git] / content / child / child_io_surface_manager_mac.h
blob40098e4e3a564f688411a94e056d7619630fa375
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 "base/synchronization/waitable_event.h"
12 #include "base/threading/platform_thread.h"
13 #include "content/common/mac/io_surface_manager.h"
14 #include "content/common/mac/io_surface_manager_token.h"
16 namespace content {
18 // Implementation of IOSurfaceManager that registers and acquires IOSurfaces
19 // through a Mach service.
20 class CONTENT_EXPORT ChildIOSurfaceManager : public IOSurfaceManager {
21 public:
22 // Returns the global ChildIOSurfaceManager.
23 static ChildIOSurfaceManager* GetInstance();
25 // Overridden from IOSurfaceManager:
26 bool RegisterIOSurface(int io_surface_id,
27 int client_id,
28 IOSurfaceRef io_surface) override;
29 void UnregisterIOSurface(int io_surface_id, int client_id) override;
30 IOSurfaceRef AcquireIOSurface(int io_surface_id) override;
32 // Set the service Mach port. Ownership of |service_port| is passed to the
33 // manager.
34 void set_service_port(mach_port_t service_port) {
35 service_port_.reset(service_port);
38 // Set the token used when communicating with the Mach service.
39 void set_token(const IOSurfaceManagerToken& token) {
40 token_ = token;
41 #if !defined(NDEBUG)
42 set_token_thread_id_ = base::PlatformThread::CurrentRef();
43 #endif
44 set_token_event_.Signal();
47 private:
48 friend struct DefaultSingletonTraits<ChildIOSurfaceManager>;
50 ChildIOSurfaceManager();
51 ~ChildIOSurfaceManager() override;
53 base::mac::ScopedMachSendRight service_port_;
54 IOSurfaceManagerToken token_;
55 #if !defined(NDEBUG)
56 base::PlatformThreadRef set_token_thread_id_;
57 #endif
58 base::WaitableEvent set_token_event_;
60 DISALLOW_COPY_AND_ASSIGN(ChildIOSurfaceManager);
63 } // namespace content
65 #endif // CONTENT_CHILD_CHILD_IO_SURFACE_MANAGER_MAC_H_