Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef CONTENT_BROWSER_BROWSER_IO_SURFACE_MANAGER_MAC_H_ | |
| 6 #define CONTENT_BROWSER_BROWSER_IO_SURFACE_MANAGER_MAC_H_ | |
| 7 | |
| 8 #include <mach/mach.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "base/containers/scoped_ptr_hash_map.h" | |
| 14 #include "base/mac/dispatch_source_mach.h" | |
| 15 #include "base/mac/scoped_mach_port.h" | |
| 16 #include "base/macros.h" | |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/memory/singleton.h" | |
| 19 #include "base/synchronization/lock.h" | |
| 20 #include "content/common/mac/io_surface_manager.h" | |
| 21 #include "content/common/mac/io_surface_manager_messages.h" | |
| 22 #include "gpu/command_buffer/common/mailbox.h" | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 // Implementation of IOSurfaceManager that provides a mechanism for child | |
| 27 // processes to register and acquire IOSurfaces through a Mach service. | |
| 28 class CONTENT_EXPORT BrowserIOSurfaceManager : public IOSurfaceManager { | |
| 29 public: | |
| 30 // Returns the global BrowserIOSurfaceManager. | |
| 31 static BrowserIOSurfaceManager* GetInstance(); | |
| 32 | |
| 33 // Look up the IOSurfaceManager service port that's been registered with | |
| 34 // the bootstrap server. |pid| is the process ID of the service. | |
| 35 static mach_port_t LookupServicePort(pid_t pid); | |
|
Robert Sesek
2015/05/19 23:26:23
This should return in a scoper to ensure proper li
| |
| 36 | |
| 37 // Overridden from IOSurfaceManager: | |
| 38 bool RegisterIOSurface(int io_surface_id, | |
| 39 int client_id, | |
| 40 IOSurfaceRef io_surface) override; | |
| 41 void UnregisterIOSurface(int io_surface_id, int client_id) override; | |
| 42 IOSurfaceRef AcquireIOSurface(int io_surface_id) override; | |
| 43 | |
| 44 // Performs any necessary setup that cannot happen in the constructor. | |
| 45 void EnsureRunning(); | |
| 46 | |
| 47 // Get the unique unguessable mailbox name that the GPU process can | |
| 48 // use to register/unregister IOSurface for use by clients. | |
| 49 gpu::Mailbox GetGpuProcessMailbox() const; | |
| 50 | |
| 51 // Generate a unique unguessable mailbox name that the child process | |
| 52 // associated |child_process_id| can use to acquire IOSurface references. | |
| 53 gpu::Mailbox GenerateChildProcessMailbox(int child_process_id); | |
| 54 | |
| 55 // Invalidate a previously generated mailbox name. | |
| 56 void InvalidateChildProcessMailbox(const gpu::Mailbox& mailbox); | |
| 57 | |
| 58 private: | |
| 59 friend class BrowserIOSurfaceManagerTest; | |
| 60 friend struct DefaultSingletonTraits<BrowserIOSurfaceManager>; | |
| 61 | |
| 62 BrowserIOSurfaceManager(); | |
| 63 ~BrowserIOSurfaceManager() override; | |
| 64 | |
| 65 // Performs any initialization work. | |
| 66 bool Initialize(); | |
| 67 | |
| 68 // Message handler that is invoked on |dispatch_source_| when an | |
| 69 // incoming message needs to be received. | |
| 70 void HandleRequest(); | |
| 71 | |
| 72 // Message handlers that are invoked from HandleRequest. | |
| 73 bool HandleRegisterIOSurfaceRequest( | |
| 74 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, | |
| 75 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply); | |
| 76 bool HandleUnregisterIOSurfaceRequest( | |
| 77 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request); | |
| 78 bool HandleAcquireIOSurfaceRequest( | |
| 79 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, | |
| 80 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply); | |
| 81 | |
| 82 // Whether or not the class has been initialized. | |
| 83 bool initialized_; | |
| 84 | |
| 85 // The Mach port on which the server listens. | |
| 86 base::mac::ScopedMachReceiveRight server_port_; | |
| 87 | |
| 88 // The dispatch source and queue on which Mach messages will be received. | |
| 89 scoped_ptr<base::DispatchSourceMach> dispatch_source_; | |
| 90 | |
| 91 // Stores the IOSurfces for all GPU clients. | |
| 92 using IOSurfaceMapKey = std::pair<int, int>; | |
| 93 using IOSurfaceMap = | |
| 94 base::ScopedPtrHashMap<IOSurfaceMapKey, | |
| 95 scoped_ptr<base::mac::ScopedMachSendRight>>; | |
| 96 IOSurfaceMap io_surfaces_; | |
| 97 | |
| 98 // Stores the Child process unique id (RenderProcessHost ID) for every | |
| 99 // mailbox. | |
| 100 using ChildProcessIdMap = std::map<gpu::Mailbox, int>; | |
| 101 ChildProcessIdMap child_process_ids_; | |
| 102 | |
| 103 // Stores the GPU process mailbox. | |
| 104 const gpu::Mailbox gpu_process_mailbox_; | |
| 105 | |
| 106 // Mutex that guards |io_surfaces_| and |child_process_ids_|. | |
| 107 mutable base::Lock lock_; | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(BrowserIOSurfaceManager); | |
| 110 }; | |
| 111 | |
| 112 } // namespace content | |
| 113 | |
| 114 #endif // CONTENT_BROWSER_BROWSER_IO_SURFACE_MANAGER_MAC_H_ | |
| OLD | NEW |