|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set sw=2 ts=8 et tw=80 : */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_layers_CompositorChild_h |
|
8 #define mozilla_layers_CompositorChild_h |
|
9 |
|
10 #include "base/basictypes.h" // for DISALLOW_EVIL_CONSTRUCTORS |
|
11 #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 |
|
12 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
|
13 #include "mozilla/ipc/ProtocolUtils.h" |
|
14 #include "mozilla/layers/PCompositorChild.h" |
|
15 #include "nsAutoPtr.h" // for nsRefPtr |
|
16 #include "nsClassHashtable.h" // for nsClassHashtable |
|
17 #include "nsCOMPtr.h" // for nsCOMPtr |
|
18 #include "nsHashKeys.h" // for nsUint64HashKey |
|
19 #include "nsISupportsImpl.h" // for NS_INLINE_DECL_REFCOUNTING |
|
20 |
|
21 class nsIObserver; |
|
22 |
|
23 namespace mozilla { |
|
24 namespace layers { |
|
25 |
|
26 class ClientLayerManager; |
|
27 class CompositorParent; |
|
28 class FrameMetrics; |
|
29 |
|
30 class CompositorChild MOZ_FINAL : public PCompositorChild |
|
31 { |
|
32 NS_INLINE_DECL_REFCOUNTING(CompositorChild) |
|
33 public: |
|
34 CompositorChild(ClientLayerManager *aLayerManager); |
|
35 |
|
36 void Destroy(); |
|
37 |
|
38 /** |
|
39 * Lookup the FrameMetrics shared by the compositor process with the |
|
40 * associated FrameMetrics::ViewID. The returned FrameMetrics is used |
|
41 * in progressive paint calculations. |
|
42 */ |
|
43 bool LookupCompositorFrameMetrics(const FrameMetrics::ViewID aId, FrameMetrics&); |
|
44 |
|
45 /** |
|
46 * We're asked to create a new Compositor in response to an Opens() |
|
47 * or Bridge() request from our parent process. The Transport is to |
|
48 * the compositor's context. |
|
49 */ |
|
50 static PCompositorChild* |
|
51 Create(Transport* aTransport, ProcessId aOtherProcess); |
|
52 |
|
53 static CompositorChild* Get(); |
|
54 |
|
55 static bool ChildProcessHasCompositor() { return sCompositor != nullptr; } |
|
56 |
|
57 virtual bool RecvInvalidateAll() MOZ_OVERRIDE; |
|
58 |
|
59 virtual bool RecvDidComposite(const uint64_t& aId) MOZ_OVERRIDE; |
|
60 |
|
61 private: |
|
62 // Private destructor, to discourage deletion outside of Release(): |
|
63 virtual ~CompositorChild(); |
|
64 |
|
65 virtual PLayerTransactionChild* |
|
66 AllocPLayerTransactionChild(const nsTArray<LayersBackend>& aBackendHints, |
|
67 const uint64_t& aId, |
|
68 TextureFactoryIdentifier* aTextureFactoryIdentifier, |
|
69 bool* aSuccess) MOZ_OVERRIDE; |
|
70 |
|
71 virtual bool DeallocPLayerTransactionChild(PLayerTransactionChild *aChild) MOZ_OVERRIDE; |
|
72 |
|
73 virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
74 |
|
75 virtual bool RecvSharedCompositorFrameMetrics(const mozilla::ipc::SharedMemoryBasic::Handle& metrics, |
|
76 const CrossProcessMutexHandle& handle, |
|
77 const uint32_t& aAPZCId) MOZ_OVERRIDE; |
|
78 |
|
79 virtual bool RecvReleaseSharedCompositorFrameMetrics(const ViewID& aId, |
|
80 const uint32_t& aAPZCId) MOZ_OVERRIDE; |
|
81 |
|
82 // Class used to store the shared FrameMetrics, mutex, and APZCId in a hash table |
|
83 class SharedFrameMetricsData { |
|
84 public: |
|
85 SharedFrameMetricsData( |
|
86 const mozilla::ipc::SharedMemoryBasic::Handle& metrics, |
|
87 const CrossProcessMutexHandle& handle, |
|
88 const uint32_t& aAPZCId); |
|
89 |
|
90 ~SharedFrameMetricsData(); |
|
91 |
|
92 void CopyFrameMetrics(FrameMetrics* aFrame); |
|
93 FrameMetrics::ViewID GetViewID(); |
|
94 uint32_t GetAPZCId(); |
|
95 |
|
96 private: |
|
97 // Pointer to the class that allows access to the shared memory that contains |
|
98 // the shared FrameMetrics |
|
99 mozilla::ipc::SharedMemoryBasic* mBuffer; |
|
100 CrossProcessMutex* mMutex; |
|
101 // Unique ID of the APZC that is sharing the FrameMetrics |
|
102 uint32_t mAPZCId; |
|
103 }; |
|
104 |
|
105 nsRefPtr<ClientLayerManager> mLayerManager; |
|
106 |
|
107 // The ViewID of the FrameMetrics is used as the key for this hash table. |
|
108 // While this should be safe to use since the ViewID is unique |
|
109 nsClassHashtable<nsUint64HashKey, SharedFrameMetricsData> mFrameMetricsTable; |
|
110 |
|
111 // When we're in a child process, this is the process-global |
|
112 // compositor that we use to forward transactions directly to the |
|
113 // compositor context in another process. |
|
114 static CompositorChild* sCompositor; |
|
115 |
|
116 DISALLOW_EVIL_CONSTRUCTORS(CompositorChild); |
|
117 }; |
|
118 |
|
119 } // layers |
|
120 } // mozilla |
|
121 |
|
122 #endif // mozilla_layers_CompositorChild_h |