michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_layers_CompositorChild_h michael@0: #define mozilla_layers_CompositorChild_h michael@0: michael@0: #include "base/basictypes.h" // for DISALLOW_EVIL_CONSTRUCTORS michael@0: #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 michael@0: #include "mozilla/Attributes.h" // for MOZ_OVERRIDE michael@0: #include "mozilla/ipc/ProtocolUtils.h" michael@0: #include "mozilla/layers/PCompositorChild.h" michael@0: #include "nsAutoPtr.h" // for nsRefPtr michael@0: #include "nsClassHashtable.h" // for nsClassHashtable michael@0: #include "nsCOMPtr.h" // for nsCOMPtr michael@0: #include "nsHashKeys.h" // for nsUint64HashKey michael@0: #include "nsISupportsImpl.h" // for NS_INLINE_DECL_REFCOUNTING michael@0: michael@0: class nsIObserver; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class ClientLayerManager; michael@0: class CompositorParent; michael@0: class FrameMetrics; michael@0: michael@0: class CompositorChild MOZ_FINAL : public PCompositorChild michael@0: { michael@0: NS_INLINE_DECL_REFCOUNTING(CompositorChild) michael@0: public: michael@0: CompositorChild(ClientLayerManager *aLayerManager); michael@0: michael@0: void Destroy(); michael@0: michael@0: /** michael@0: * Lookup the FrameMetrics shared by the compositor process with the michael@0: * associated FrameMetrics::ViewID. The returned FrameMetrics is used michael@0: * in progressive paint calculations. michael@0: */ michael@0: bool LookupCompositorFrameMetrics(const FrameMetrics::ViewID aId, FrameMetrics&); michael@0: michael@0: /** michael@0: * We're asked to create a new Compositor in response to an Opens() michael@0: * or Bridge() request from our parent process. The Transport is to michael@0: * the compositor's context. michael@0: */ michael@0: static PCompositorChild* michael@0: Create(Transport* aTransport, ProcessId aOtherProcess); michael@0: michael@0: static CompositorChild* Get(); michael@0: michael@0: static bool ChildProcessHasCompositor() { return sCompositor != nullptr; } michael@0: michael@0: virtual bool RecvInvalidateAll() MOZ_OVERRIDE; michael@0: michael@0: virtual bool RecvDidComposite(const uint64_t& aId) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: virtual ~CompositorChild(); michael@0: michael@0: virtual PLayerTransactionChild* michael@0: AllocPLayerTransactionChild(const nsTArray& aBackendHints, michael@0: const uint64_t& aId, michael@0: TextureFactoryIdentifier* aTextureFactoryIdentifier, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool DeallocPLayerTransactionChild(PLayerTransactionChild *aChild) MOZ_OVERRIDE; michael@0: michael@0: virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; michael@0: michael@0: virtual bool RecvSharedCompositorFrameMetrics(const mozilla::ipc::SharedMemoryBasic::Handle& metrics, michael@0: const CrossProcessMutexHandle& handle, michael@0: const uint32_t& aAPZCId) MOZ_OVERRIDE; michael@0: michael@0: virtual bool RecvReleaseSharedCompositorFrameMetrics(const ViewID& aId, michael@0: const uint32_t& aAPZCId) MOZ_OVERRIDE; michael@0: michael@0: // Class used to store the shared FrameMetrics, mutex, and APZCId in a hash table michael@0: class SharedFrameMetricsData { michael@0: public: michael@0: SharedFrameMetricsData( michael@0: const mozilla::ipc::SharedMemoryBasic::Handle& metrics, michael@0: const CrossProcessMutexHandle& handle, michael@0: const uint32_t& aAPZCId); michael@0: michael@0: ~SharedFrameMetricsData(); michael@0: michael@0: void CopyFrameMetrics(FrameMetrics* aFrame); michael@0: FrameMetrics::ViewID GetViewID(); michael@0: uint32_t GetAPZCId(); michael@0: michael@0: private: michael@0: // Pointer to the class that allows access to the shared memory that contains michael@0: // the shared FrameMetrics michael@0: mozilla::ipc::SharedMemoryBasic* mBuffer; michael@0: CrossProcessMutex* mMutex; michael@0: // Unique ID of the APZC that is sharing the FrameMetrics michael@0: uint32_t mAPZCId; michael@0: }; michael@0: michael@0: nsRefPtr mLayerManager; michael@0: michael@0: // The ViewID of the FrameMetrics is used as the key for this hash table. michael@0: // While this should be safe to use since the ViewID is unique michael@0: nsClassHashtable mFrameMetricsTable; michael@0: michael@0: // When we're in a child process, this is the process-global michael@0: // compositor that we use to forward transactions directly to the michael@0: // compositor context in another process. michael@0: static CompositorChild* sCompositor; michael@0: michael@0: DISALLOW_EVIL_CONSTRUCTORS(CompositorChild); michael@0: }; michael@0: michael@0: } // layers michael@0: } // mozilla michael@0: michael@0: #endif // mozilla_layers_CompositorChild_h