1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/client/CompositableClient.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,182 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/layers/CompositableClient.h" 1.10 +#include <stdint.h> // for uint64_t, uint32_t 1.11 +#include "gfxPlatform.h" // for gfxPlatform 1.12 +#include "mozilla/layers/CompositableForwarder.h" 1.13 +#include "mozilla/layers/TextureClient.h" // for TextureClient, etc 1.14 +#include "mozilla/layers/TextureClientOGL.h" 1.15 +#include "mozilla/mozalloc.h" // for operator delete, etc 1.16 +#ifdef XP_WIN 1.17 +#include "gfxWindowsPlatform.h" // for gfxWindowsPlatform 1.18 +#include "mozilla/layers/TextureD3D11.h" 1.19 +#include "mozilla/layers/TextureD3D9.h" 1.20 +#endif 1.21 + 1.22 +using namespace mozilla::gfx; 1.23 + 1.24 +namespace mozilla { 1.25 +namespace layers { 1.26 + 1.27 +/** 1.28 + * IPDL actor used by CompositableClient to match with its corresponding 1.29 + * CompositableHost on the compositor side. 1.30 + * 1.31 + * CompositableChild is owned by a CompositableClient. 1.32 + */ 1.33 +class CompositableChild : public PCompositableChild 1.34 +{ 1.35 +public: 1.36 + CompositableChild() 1.37 + : mCompositableClient(nullptr), mAsyncID(0) 1.38 + { 1.39 + MOZ_COUNT_CTOR(CompositableChild); 1.40 + } 1.41 + 1.42 + ~CompositableChild() 1.43 + { 1.44 + MOZ_COUNT_DTOR(CompositableChild); 1.45 + } 1.46 + 1.47 + virtual void ActorDestroy(ActorDestroyReason) MOZ_OVERRIDE { 1.48 + if (mCompositableClient) { 1.49 + mCompositableClient->mCompositableChild = nullptr; 1.50 + } 1.51 + } 1.52 + 1.53 + CompositableClient* mCompositableClient; 1.54 + 1.55 + uint64_t mAsyncID; 1.56 +}; 1.57 + 1.58 +PCompositableChild* 1.59 +CompositableClient::CreateIPDLActor() 1.60 +{ 1.61 + return new CompositableChild(); 1.62 +} 1.63 + 1.64 +bool 1.65 +CompositableClient::DestroyIPDLActor(PCompositableChild* actor) 1.66 +{ 1.67 + delete actor; 1.68 + return true; 1.69 +} 1.70 + 1.71 +void 1.72 +CompositableClient::InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID) 1.73 +{ 1.74 + MOZ_ASSERT(aActor); 1.75 + CompositableChild* child = static_cast<CompositableChild*>(aActor); 1.76 + mCompositableChild = child; 1.77 + child->mCompositableClient = this; 1.78 + child->mAsyncID = aAsyncID; 1.79 +} 1.80 + 1.81 +CompositableClient* 1.82 +CompositableClient::FromIPDLActor(PCompositableChild* aActor) 1.83 +{ 1.84 + MOZ_ASSERT(aActor); 1.85 + return static_cast<CompositableChild*>(aActor)->mCompositableClient; 1.86 +} 1.87 + 1.88 +CompositableClient::CompositableClient(CompositableForwarder* aForwarder, 1.89 + TextureFlags aTextureFlags) 1.90 +: mCompositableChild(nullptr) 1.91 +, mForwarder(aForwarder) 1.92 +, mTextureFlags(aTextureFlags) 1.93 +{ 1.94 + MOZ_COUNT_CTOR(CompositableClient); 1.95 +} 1.96 + 1.97 +CompositableClient::~CompositableClient() 1.98 +{ 1.99 + MOZ_COUNT_DTOR(CompositableClient); 1.100 + Destroy(); 1.101 +} 1.102 + 1.103 +LayersBackend 1.104 +CompositableClient::GetCompositorBackendType() const 1.105 +{ 1.106 + return mForwarder->GetCompositorBackendType(); 1.107 +} 1.108 + 1.109 +void 1.110 +CompositableClient::SetIPDLActor(CompositableChild* aChild) 1.111 +{ 1.112 + mCompositableChild = aChild; 1.113 +} 1.114 + 1.115 +PCompositableChild* 1.116 +CompositableClient::GetIPDLActor() const 1.117 +{ 1.118 + return mCompositableChild; 1.119 +} 1.120 + 1.121 +bool 1.122 +CompositableClient::Connect() 1.123 +{ 1.124 + if (!GetForwarder() || GetIPDLActor()) { 1.125 + return false; 1.126 + } 1.127 + GetForwarder()->Connect(this); 1.128 + return true; 1.129 +} 1.130 + 1.131 +void 1.132 +CompositableClient::Destroy() 1.133 +{ 1.134 + if (!mCompositableChild) { 1.135 + return; 1.136 + } 1.137 + mCompositableChild->mCompositableClient = nullptr; 1.138 + PCompositableChild::Send__delete__(mCompositableChild); 1.139 + mCompositableChild = nullptr; 1.140 +} 1.141 + 1.142 +uint64_t 1.143 +CompositableClient::GetAsyncID() const 1.144 +{ 1.145 + if (mCompositableChild) { 1.146 + return mCompositableChild->mAsyncID; 1.147 + } 1.148 + return 0; // zero is always an invalid async ID 1.149 +} 1.150 + 1.151 +TemporaryRef<BufferTextureClient> 1.152 +CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, 1.153 + TextureFlags aTextureFlags, 1.154 + gfx::BackendType aMoz2DBackend) 1.155 +{ 1.156 + return TextureClient::CreateBufferTextureClient(GetForwarder(), aFormat, 1.157 + aTextureFlags | mTextureFlags, 1.158 + aMoz2DBackend); 1.159 +} 1.160 + 1.161 +TemporaryRef<TextureClient> 1.162 +CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, 1.163 + TextureFlags aTextureFlags, 1.164 + gfx::BackendType aMoz2DBackend, 1.165 + const IntSize& aSizeHint) 1.166 +{ 1.167 + return TextureClient::CreateTextureClientForDrawing(GetForwarder(), aFormat, 1.168 + aTextureFlags | mTextureFlags, 1.169 + aMoz2DBackend, 1.170 + aSizeHint); 1.171 +} 1.172 + 1.173 +bool 1.174 +CompositableClient::AddTextureClient(TextureClient* aClient) 1.175 +{ 1.176 + return aClient->InitIPDLActor(mForwarder); 1.177 +} 1.178 + 1.179 +void 1.180 +CompositableClient::OnTransaction() 1.181 +{ 1.182 +} 1.183 + 1.184 +} // namespace layers 1.185 +} // namespace mozilla