michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: #include "mozilla/layers/CompositableClient.h" michael@0: #include // for uint64_t, uint32_t michael@0: #include "gfxPlatform.h" // for gfxPlatform michael@0: #include "mozilla/layers/CompositableForwarder.h" michael@0: #include "mozilla/layers/TextureClient.h" // for TextureClient, etc michael@0: #include "mozilla/layers/TextureClientOGL.h" michael@0: #include "mozilla/mozalloc.h" // for operator delete, etc michael@0: #ifdef XP_WIN michael@0: #include "gfxWindowsPlatform.h" // for gfxWindowsPlatform michael@0: #include "mozilla/layers/TextureD3D11.h" michael@0: #include "mozilla/layers/TextureD3D9.h" michael@0: #endif michael@0: michael@0: using namespace mozilla::gfx; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: /** michael@0: * IPDL actor used by CompositableClient to match with its corresponding michael@0: * CompositableHost on the compositor side. michael@0: * michael@0: * CompositableChild is owned by a CompositableClient. michael@0: */ michael@0: class CompositableChild : public PCompositableChild michael@0: { michael@0: public: michael@0: CompositableChild() michael@0: : mCompositableClient(nullptr), mAsyncID(0) michael@0: { michael@0: MOZ_COUNT_CTOR(CompositableChild); michael@0: } michael@0: michael@0: ~CompositableChild() michael@0: { michael@0: MOZ_COUNT_DTOR(CompositableChild); michael@0: } michael@0: michael@0: virtual void ActorDestroy(ActorDestroyReason) MOZ_OVERRIDE { michael@0: if (mCompositableClient) { michael@0: mCompositableClient->mCompositableChild = nullptr; michael@0: } michael@0: } michael@0: michael@0: CompositableClient* mCompositableClient; michael@0: michael@0: uint64_t mAsyncID; michael@0: }; michael@0: michael@0: PCompositableChild* michael@0: CompositableClient::CreateIPDLActor() michael@0: { michael@0: return new CompositableChild(); michael@0: } michael@0: michael@0: bool michael@0: CompositableClient::DestroyIPDLActor(PCompositableChild* actor) michael@0: { michael@0: delete actor; michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: CompositableClient::InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID) michael@0: { michael@0: MOZ_ASSERT(aActor); michael@0: CompositableChild* child = static_cast(aActor); michael@0: mCompositableChild = child; michael@0: child->mCompositableClient = this; michael@0: child->mAsyncID = aAsyncID; michael@0: } michael@0: michael@0: CompositableClient* michael@0: CompositableClient::FromIPDLActor(PCompositableChild* aActor) michael@0: { michael@0: MOZ_ASSERT(aActor); michael@0: return static_cast(aActor)->mCompositableClient; michael@0: } michael@0: michael@0: CompositableClient::CompositableClient(CompositableForwarder* aForwarder, michael@0: TextureFlags aTextureFlags) michael@0: : mCompositableChild(nullptr) michael@0: , mForwarder(aForwarder) michael@0: , mTextureFlags(aTextureFlags) michael@0: { michael@0: MOZ_COUNT_CTOR(CompositableClient); michael@0: } michael@0: michael@0: CompositableClient::~CompositableClient() michael@0: { michael@0: MOZ_COUNT_DTOR(CompositableClient); michael@0: Destroy(); michael@0: } michael@0: michael@0: LayersBackend michael@0: CompositableClient::GetCompositorBackendType() const michael@0: { michael@0: return mForwarder->GetCompositorBackendType(); michael@0: } michael@0: michael@0: void michael@0: CompositableClient::SetIPDLActor(CompositableChild* aChild) michael@0: { michael@0: mCompositableChild = aChild; michael@0: } michael@0: michael@0: PCompositableChild* michael@0: CompositableClient::GetIPDLActor() const michael@0: { michael@0: return mCompositableChild; michael@0: } michael@0: michael@0: bool michael@0: CompositableClient::Connect() michael@0: { michael@0: if (!GetForwarder() || GetIPDLActor()) { michael@0: return false; michael@0: } michael@0: GetForwarder()->Connect(this); michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: CompositableClient::Destroy() michael@0: { michael@0: if (!mCompositableChild) { michael@0: return; michael@0: } michael@0: mCompositableChild->mCompositableClient = nullptr; michael@0: PCompositableChild::Send__delete__(mCompositableChild); michael@0: mCompositableChild = nullptr; michael@0: } michael@0: michael@0: uint64_t michael@0: CompositableClient::GetAsyncID() const michael@0: { michael@0: if (mCompositableChild) { michael@0: return mCompositableChild->mAsyncID; michael@0: } michael@0: return 0; // zero is always an invalid async ID michael@0: } michael@0: michael@0: TemporaryRef michael@0: CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, michael@0: TextureFlags aTextureFlags, michael@0: gfx::BackendType aMoz2DBackend) michael@0: { michael@0: return TextureClient::CreateBufferTextureClient(GetForwarder(), aFormat, michael@0: aTextureFlags | mTextureFlags, michael@0: aMoz2DBackend); michael@0: } michael@0: michael@0: TemporaryRef michael@0: CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, michael@0: TextureFlags aTextureFlags, michael@0: gfx::BackendType aMoz2DBackend, michael@0: const IntSize& aSizeHint) michael@0: { michael@0: return TextureClient::CreateTextureClientForDrawing(GetForwarder(), aFormat, michael@0: aTextureFlags | mTextureFlags, michael@0: aMoz2DBackend, michael@0: aSizeHint); michael@0: } michael@0: michael@0: bool michael@0: CompositableClient::AddTextureClient(TextureClient* aClient) michael@0: { michael@0: return aClient->InitIPDLActor(mForwarder); michael@0: } michael@0: michael@0: void michael@0: CompositableClient::OnTransaction() michael@0: { michael@0: } michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla