/src/mozilla-central/gfx/layers/composite/CompositableHost.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 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 | | #include "CompositableHost.h" |
8 | | #include <map> // for _Rb_tree_iterator, map, etc |
9 | | #include <utility> // for pair |
10 | | #include "ContentHost.h" // for ContentHostDoubleBuffered, etc |
11 | | #include "Effects.h" // for EffectMask, Effect, etc |
12 | | #include "gfxUtils.h" |
13 | | #include "ImageHost.h" // for ImageHostBuffered, etc |
14 | | #include "TiledContentHost.h" // for TiledContentHost |
15 | | #include "mozilla/gfx/gfxVars.h" |
16 | | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
17 | | #include "mozilla/layers/TextureHost.h" // for TextureHost, etc |
18 | | #include "mozilla/layers/WebRenderImageHost.h" |
19 | | #include "mozilla/RefPtr.h" // for nsRefPtr |
20 | | #include "nsDebug.h" // for NS_WARNING |
21 | | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
22 | | #include "gfxPlatform.h" // for gfxPlatform |
23 | | #include "IPDLActor.h" |
24 | | |
25 | | namespace mozilla { |
26 | | |
27 | | using namespace gfx; |
28 | | |
29 | | namespace layers { |
30 | | |
31 | | class Compositor; |
32 | | |
33 | | CompositableHost::CompositableHost(const TextureInfo& aTextureInfo) |
34 | | : mTextureInfo(aTextureInfo) |
35 | | , mCompositorBridgeID(0) |
36 | | , mLayer(nullptr) |
37 | | , mFlashCounter(0) |
38 | | , mAttached(false) |
39 | | , mKeepAttached(false) |
40 | 0 | { |
41 | 0 | MOZ_COUNT_CTOR(CompositableHost); |
42 | 0 | } |
43 | | |
44 | | CompositableHost::~CompositableHost() |
45 | 0 | { |
46 | 0 | MOZ_COUNT_DTOR(CompositableHost); |
47 | 0 | } |
48 | | |
49 | | void |
50 | | CompositableHost::UseTextureHost(const nsTArray<TimedTexture>& aTextures) |
51 | 0 | { |
52 | 0 | if (mTextureSourceProvider) { |
53 | 0 | for (auto& texture : aTextures) { |
54 | 0 | texture.mTexture->SetTextureSourceProvider(mTextureSourceProvider); |
55 | 0 | } |
56 | 0 | } |
57 | 0 | } |
58 | | |
59 | | void |
60 | | CompositableHost::UseComponentAlphaTextures(TextureHost* aTextureOnBlack, |
61 | | TextureHost* aTextureOnWhite) |
62 | 0 | { |
63 | 0 | MOZ_ASSERT(aTextureOnBlack && aTextureOnWhite); |
64 | 0 | if (mTextureSourceProvider) { |
65 | 0 | aTextureOnBlack->SetTextureSourceProvider(mTextureSourceProvider); |
66 | 0 | aTextureOnWhite->SetTextureSourceProvider(mTextureSourceProvider); |
67 | 0 | } |
68 | 0 | } |
69 | | |
70 | | void |
71 | | CompositableHost::RemoveTextureHost(TextureHost* aTexture) |
72 | 0 | {} |
73 | | |
74 | | void |
75 | | CompositableHost::SetTextureSourceProvider(TextureSourceProvider* aProvider) |
76 | 0 | { |
77 | 0 | MOZ_ASSERT(aProvider); |
78 | 0 | mTextureSourceProvider = aProvider; |
79 | 0 | } |
80 | | |
81 | | bool |
82 | | CompositableHost::AddMaskEffect(EffectChain& aEffects, |
83 | | const gfx::Matrix4x4& aTransform) |
84 | 0 | { |
85 | 0 | CompositableTextureSourceRef source; |
86 | 0 | RefPtr<TextureHost> host = GetAsTextureHost(); |
87 | 0 |
|
88 | 0 | if (!host) { |
89 | 0 | NS_WARNING("Using compositable with no valid TextureHost as mask"); |
90 | 0 | return false; |
91 | 0 | } |
92 | 0 |
|
93 | 0 | if (!host->Lock()) { |
94 | 0 | NS_WARNING("Failed to lock the mask texture"); |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 |
|
98 | 0 | if (!host->BindTextureSource(source)) { |
99 | 0 | NS_WARNING("The TextureHost was successfully locked but can't provide a TextureSource"); |
100 | 0 | host->Unlock(); |
101 | 0 | return false; |
102 | 0 | } |
103 | 0 | MOZ_ASSERT(source); |
104 | 0 |
|
105 | 0 | RefPtr<EffectMask> effect = new EffectMask(source, |
106 | 0 | source->GetSize(), |
107 | 0 | aTransform); |
108 | 0 | aEffects.mSecondaryEffects[EffectTypes::MASK] = effect; |
109 | 0 | return true; |
110 | 0 | } |
111 | | |
112 | | void |
113 | | CompositableHost::RemoveMaskEffect() |
114 | 0 | { |
115 | 0 | RefPtr<TextureHost> host = GetAsTextureHost(); |
116 | 0 | if (host) { |
117 | 0 | host->Unlock(); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | /* static */ already_AddRefed<CompositableHost> |
122 | | CompositableHost::Create(const TextureInfo& aTextureInfo, bool aUseWebRender) |
123 | 0 | { |
124 | 0 | RefPtr<CompositableHost> result; |
125 | 0 | switch (aTextureInfo.mCompositableType) { |
126 | 0 | case CompositableType::IMAGE_BRIDGE: |
127 | 0 | NS_ERROR("Cannot create an image bridge compositable this way"); |
128 | 0 | break; |
129 | 0 | case CompositableType::CONTENT_TILED: |
130 | 0 | result = new TiledContentHost(aTextureInfo); |
131 | 0 | break; |
132 | 0 | case CompositableType::IMAGE: |
133 | 0 | if (aUseWebRender) { |
134 | 0 | result = new WebRenderImageHost(aTextureInfo); |
135 | 0 | } else { |
136 | 0 | result = new ImageHost(aTextureInfo); |
137 | 0 | } |
138 | 0 | break; |
139 | 0 | case CompositableType::CONTENT_SINGLE: |
140 | 0 | if (aUseWebRender) { |
141 | 0 | result = new WebRenderImageHost(aTextureInfo); |
142 | 0 | } else { |
143 | 0 | result = new ContentHostSingleBuffered(aTextureInfo); |
144 | 0 | } |
145 | 0 | break; |
146 | 0 | case CompositableType::CONTENT_DOUBLE: |
147 | 0 | MOZ_ASSERT(!aUseWebRender); |
148 | 0 | result = new ContentHostDoubleBuffered(aTextureInfo); |
149 | 0 | break; |
150 | 0 | default: |
151 | 0 | NS_ERROR("Unknown CompositableType"); |
152 | 0 | } |
153 | 0 | return result.forget(); |
154 | 0 | } |
155 | | |
156 | | void |
157 | | CompositableHost::DumpTextureHost(std::stringstream& aStream, TextureHost* aTexture) |
158 | 0 | { |
159 | 0 | if (!aTexture) { |
160 | 0 | return; |
161 | 0 | } |
162 | 0 | RefPtr<gfx::DataSourceSurface> dSurf = aTexture->GetAsSurface(); |
163 | 0 | if (!dSurf) { |
164 | 0 | return; |
165 | 0 | } |
166 | 0 | aStream << gfxUtils::GetAsDataURI(dSurf).get(); |
167 | 0 | } |
168 | | |
169 | | HostLayerManager* |
170 | | CompositableHost::GetLayerManager() const |
171 | 0 | { |
172 | 0 | if (!mLayer || !mLayer->Manager()) { |
173 | 0 | return nullptr; |
174 | 0 | } |
175 | 0 | return mLayer->Manager()->AsHostLayerManager(); |
176 | 0 | } |
177 | | |
178 | | TextureSourceProvider* |
179 | | CompositableHost::GetTextureSourceProvider() const |
180 | 0 | { |
181 | 0 | return mTextureSourceProvider; |
182 | 0 | } |
183 | | |
184 | | } // namespace layers |
185 | | } // namespace mozilla |