Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/layers/CompositableClient.h" |
michael@0 | 7 | #include <stdint.h> // for uint64_t, uint32_t |
michael@0 | 8 | #include "gfxPlatform.h" // for gfxPlatform |
michael@0 | 9 | #include "mozilla/layers/CompositableForwarder.h" |
michael@0 | 10 | #include "mozilla/layers/TextureClient.h" // for TextureClient, etc |
michael@0 | 11 | #include "mozilla/layers/TextureClientOGL.h" |
michael@0 | 12 | #include "mozilla/mozalloc.h" // for operator delete, etc |
michael@0 | 13 | #ifdef XP_WIN |
michael@0 | 14 | #include "gfxWindowsPlatform.h" // for gfxWindowsPlatform |
michael@0 | 15 | #include "mozilla/layers/TextureD3D11.h" |
michael@0 | 16 | #include "mozilla/layers/TextureD3D9.h" |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | using namespace mozilla::gfx; |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace layers { |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * IPDL actor used by CompositableClient to match with its corresponding |
michael@0 | 26 | * CompositableHost on the compositor side. |
michael@0 | 27 | * |
michael@0 | 28 | * CompositableChild is owned by a CompositableClient. |
michael@0 | 29 | */ |
michael@0 | 30 | class CompositableChild : public PCompositableChild |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | CompositableChild() |
michael@0 | 34 | : mCompositableClient(nullptr), mAsyncID(0) |
michael@0 | 35 | { |
michael@0 | 36 | MOZ_COUNT_CTOR(CompositableChild); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | ~CompositableChild() |
michael@0 | 40 | { |
michael@0 | 41 | MOZ_COUNT_DTOR(CompositableChild); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | virtual void ActorDestroy(ActorDestroyReason) MOZ_OVERRIDE { |
michael@0 | 45 | if (mCompositableClient) { |
michael@0 | 46 | mCompositableClient->mCompositableChild = nullptr; |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | CompositableClient* mCompositableClient; |
michael@0 | 51 | |
michael@0 | 52 | uint64_t mAsyncID; |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | PCompositableChild* |
michael@0 | 56 | CompositableClient::CreateIPDLActor() |
michael@0 | 57 | { |
michael@0 | 58 | return new CompositableChild(); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | bool |
michael@0 | 62 | CompositableClient::DestroyIPDLActor(PCompositableChild* actor) |
michael@0 | 63 | { |
michael@0 | 64 | delete actor; |
michael@0 | 65 | return true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | CompositableClient::InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID) |
michael@0 | 70 | { |
michael@0 | 71 | MOZ_ASSERT(aActor); |
michael@0 | 72 | CompositableChild* child = static_cast<CompositableChild*>(aActor); |
michael@0 | 73 | mCompositableChild = child; |
michael@0 | 74 | child->mCompositableClient = this; |
michael@0 | 75 | child->mAsyncID = aAsyncID; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | CompositableClient* |
michael@0 | 79 | CompositableClient::FromIPDLActor(PCompositableChild* aActor) |
michael@0 | 80 | { |
michael@0 | 81 | MOZ_ASSERT(aActor); |
michael@0 | 82 | return static_cast<CompositableChild*>(aActor)->mCompositableClient; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | CompositableClient::CompositableClient(CompositableForwarder* aForwarder, |
michael@0 | 86 | TextureFlags aTextureFlags) |
michael@0 | 87 | : mCompositableChild(nullptr) |
michael@0 | 88 | , mForwarder(aForwarder) |
michael@0 | 89 | , mTextureFlags(aTextureFlags) |
michael@0 | 90 | { |
michael@0 | 91 | MOZ_COUNT_CTOR(CompositableClient); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | CompositableClient::~CompositableClient() |
michael@0 | 95 | { |
michael@0 | 96 | MOZ_COUNT_DTOR(CompositableClient); |
michael@0 | 97 | Destroy(); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | LayersBackend |
michael@0 | 101 | CompositableClient::GetCompositorBackendType() const |
michael@0 | 102 | { |
michael@0 | 103 | return mForwarder->GetCompositorBackendType(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | void |
michael@0 | 107 | CompositableClient::SetIPDLActor(CompositableChild* aChild) |
michael@0 | 108 | { |
michael@0 | 109 | mCompositableChild = aChild; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | PCompositableChild* |
michael@0 | 113 | CompositableClient::GetIPDLActor() const |
michael@0 | 114 | { |
michael@0 | 115 | return mCompositableChild; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | bool |
michael@0 | 119 | CompositableClient::Connect() |
michael@0 | 120 | { |
michael@0 | 121 | if (!GetForwarder() || GetIPDLActor()) { |
michael@0 | 122 | return false; |
michael@0 | 123 | } |
michael@0 | 124 | GetForwarder()->Connect(this); |
michael@0 | 125 | return true; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | void |
michael@0 | 129 | CompositableClient::Destroy() |
michael@0 | 130 | { |
michael@0 | 131 | if (!mCompositableChild) { |
michael@0 | 132 | return; |
michael@0 | 133 | } |
michael@0 | 134 | mCompositableChild->mCompositableClient = nullptr; |
michael@0 | 135 | PCompositableChild::Send__delete__(mCompositableChild); |
michael@0 | 136 | mCompositableChild = nullptr; |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | uint64_t |
michael@0 | 140 | CompositableClient::GetAsyncID() const |
michael@0 | 141 | { |
michael@0 | 142 | if (mCompositableChild) { |
michael@0 | 143 | return mCompositableChild->mAsyncID; |
michael@0 | 144 | } |
michael@0 | 145 | return 0; // zero is always an invalid async ID |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | TemporaryRef<BufferTextureClient> |
michael@0 | 149 | CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, |
michael@0 | 150 | TextureFlags aTextureFlags, |
michael@0 | 151 | gfx::BackendType aMoz2DBackend) |
michael@0 | 152 | { |
michael@0 | 153 | return TextureClient::CreateBufferTextureClient(GetForwarder(), aFormat, |
michael@0 | 154 | aTextureFlags | mTextureFlags, |
michael@0 | 155 | aMoz2DBackend); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | TemporaryRef<TextureClient> |
michael@0 | 159 | CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, |
michael@0 | 160 | TextureFlags aTextureFlags, |
michael@0 | 161 | gfx::BackendType aMoz2DBackend, |
michael@0 | 162 | const IntSize& aSizeHint) |
michael@0 | 163 | { |
michael@0 | 164 | return TextureClient::CreateTextureClientForDrawing(GetForwarder(), aFormat, |
michael@0 | 165 | aTextureFlags | mTextureFlags, |
michael@0 | 166 | aMoz2DBackend, |
michael@0 | 167 | aSizeHint); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | bool |
michael@0 | 171 | CompositableClient::AddTextureClient(TextureClient* aClient) |
michael@0 | 172 | { |
michael@0 | 173 | return aClient->InitIPDLActor(mForwarder); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | void |
michael@0 | 177 | CompositableClient::OnTransaction() |
michael@0 | 178 | { |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | } // namespace layers |
michael@0 | 182 | } // namespace mozilla |