/src/mozilla-central/gfx/layers/wr/WebRenderTextureHost.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 "WebRenderTextureHost.h" |
8 | | |
9 | | #include "mozilla/layers/ImageDataSerializer.h" |
10 | | #include "mozilla/layers/LayersSurfaces.h" |
11 | | #include "mozilla/webrender/RenderThread.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace layers { |
15 | | |
16 | | WebRenderTextureHost::WebRenderTextureHost(const SurfaceDescriptor& aDesc, |
17 | | TextureFlags aFlags, |
18 | | TextureHost* aTexture, |
19 | | wr::ExternalImageId& aExternalImageId) |
20 | | : TextureHost(aFlags) |
21 | | , mExternalImageId(aExternalImageId) |
22 | 0 | { |
23 | 0 | // The wrapped textureHost will be used in WebRender, and the WebRender could |
24 | 0 | // run at another thread. It's hard to control the life-time when gecko |
25 | 0 | // receives PTextureParent destroy message. It's possible that textureHost is |
26 | 0 | // still used by WebRender. So, we only accept the textureHost without |
27 | 0 | // DEALLOCATE_CLIENT flag here. If the buffer deallocation is controlled by |
28 | 0 | // parent, we could do something to make sure the wrapped textureHost is not |
29 | 0 | // used by WebRender and then release it. |
30 | 0 | MOZ_ASSERT(!(aFlags & TextureFlags::DEALLOCATE_CLIENT)); |
31 | 0 |
|
32 | 0 | MOZ_COUNT_CTOR(WebRenderTextureHost); |
33 | 0 | mWrappedTextureHost = aTexture; |
34 | 0 |
|
35 | 0 | CreateRenderTextureHost(aDesc, aTexture); |
36 | 0 | } |
37 | | |
38 | | WebRenderTextureHost::~WebRenderTextureHost() |
39 | 0 | { |
40 | 0 | MOZ_COUNT_DTOR(WebRenderTextureHost); |
41 | 0 | wr::RenderThread::Get()->UnregisterExternalImage(wr::AsUint64(mExternalImageId)); |
42 | 0 | } |
43 | | |
44 | | void |
45 | | WebRenderTextureHost::CreateRenderTextureHost(const layers::SurfaceDescriptor& aDesc, |
46 | | TextureHost* aTexture) |
47 | 0 | { |
48 | 0 | MOZ_ASSERT(aTexture); |
49 | 0 |
|
50 | 0 | aTexture->CreateRenderTexture(mExternalImageId); |
51 | 0 | } |
52 | | |
53 | | bool |
54 | | WebRenderTextureHost::Lock() |
55 | 0 | { |
56 | 0 | MOZ_ASSERT_UNREACHABLE("unexpected to be called"); |
57 | 0 | return false; |
58 | 0 | } |
59 | | |
60 | | void |
61 | | WebRenderTextureHost::Unlock() |
62 | 0 | { |
63 | 0 | MOZ_ASSERT_UNREACHABLE("unexpected to be called"); |
64 | 0 | } |
65 | | |
66 | | bool |
67 | | WebRenderTextureHost::BindTextureSource(CompositableTextureSourceRef& aTexture) |
68 | 0 | { |
69 | 0 | MOZ_ASSERT_UNREACHABLE("unexpected to be called"); |
70 | 0 | return false; |
71 | 0 | } |
72 | | |
73 | | already_AddRefed<gfx::DataSourceSurface> |
74 | | WebRenderTextureHost::GetAsSurface() |
75 | 0 | { |
76 | 0 | if (!mWrappedTextureHost) { |
77 | 0 | return nullptr; |
78 | 0 | } |
79 | 0 | return mWrappedTextureHost->GetAsSurface(); |
80 | 0 | } |
81 | | |
82 | | void |
83 | | WebRenderTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider) |
84 | 0 | { |
85 | 0 | } |
86 | | |
87 | | YUVColorSpace |
88 | | WebRenderTextureHost::GetYUVColorSpace() const |
89 | 0 | { |
90 | 0 | if (mWrappedTextureHost) { |
91 | 0 | return mWrappedTextureHost->GetYUVColorSpace(); |
92 | 0 | } |
93 | 0 | return YUVColorSpace::UNKNOWN; |
94 | 0 | } |
95 | | |
96 | | gfx::IntSize |
97 | | WebRenderTextureHost::GetSize() const |
98 | 0 | { |
99 | 0 | if (!mWrappedTextureHost) { |
100 | 0 | return gfx::IntSize(); |
101 | 0 | } |
102 | 0 | return mWrappedTextureHost->GetSize(); |
103 | 0 | } |
104 | | |
105 | | gfx::SurfaceFormat |
106 | | WebRenderTextureHost::GetFormat() const |
107 | 0 | { |
108 | 0 | if (!mWrappedTextureHost) { |
109 | 0 | return gfx::SurfaceFormat::UNKNOWN; |
110 | 0 | } |
111 | 0 | return mWrappedTextureHost->GetFormat(); |
112 | 0 | } |
113 | | |
114 | | gfx::SurfaceFormat |
115 | | WebRenderTextureHost::GetReadFormat() const |
116 | 0 | { |
117 | 0 | if (!mWrappedTextureHost) { |
118 | 0 | return gfx::SurfaceFormat::UNKNOWN; |
119 | 0 | } |
120 | 0 | return mWrappedTextureHost->GetReadFormat(); |
121 | 0 | } |
122 | | |
123 | | int32_t |
124 | | WebRenderTextureHost::GetRGBStride() |
125 | 0 | { |
126 | 0 | if (!mWrappedTextureHost) { |
127 | 0 | return 0; |
128 | 0 | } |
129 | 0 | gfx::SurfaceFormat format = GetFormat(); |
130 | 0 | if (GetFormat() == gfx::SurfaceFormat::YUV) { |
131 | 0 | // XXX this stride is used until yuv image rendering by webrender is used. |
132 | 0 | // Software converted RGB buffers strides are aliened to 16 |
133 | 0 | return gfx::GetAlignedStride<16>(GetSize().width, BytesPerPixel(gfx::SurfaceFormat::B8G8R8A8)); |
134 | 0 | } |
135 | 0 | return ImageDataSerializer::ComputeRGBStride(format, GetSize().width); |
136 | 0 | } |
137 | | |
138 | | uint32_t |
139 | | WebRenderTextureHost::NumSubTextures() const |
140 | 0 | { |
141 | 0 | MOZ_ASSERT(mWrappedTextureHost); |
142 | 0 | return mWrappedTextureHost->NumSubTextures(); |
143 | 0 | } |
144 | | |
145 | | void |
146 | | WebRenderTextureHost::PushResourceUpdates(wr::TransactionBuilder& aResources, |
147 | | ResourceUpdateOp aOp, |
148 | | const Range<wr::ImageKey>& aImageKeys, |
149 | | const wr::ExternalImageId& aExtID) |
150 | 0 | { |
151 | 0 | MOZ_ASSERT(mWrappedTextureHost); |
152 | 0 | MOZ_ASSERT(mExternalImageId == aExtID || SupportsWrNativeTexture()); |
153 | 0 |
|
154 | 0 | mWrappedTextureHost->PushResourceUpdates(aResources, aOp, aImageKeys, aExtID); |
155 | 0 | } |
156 | | |
157 | | void |
158 | | WebRenderTextureHost::PushDisplayItems(wr::DisplayListBuilder& aBuilder, |
159 | | const wr::LayoutRect& aBounds, |
160 | | const wr::LayoutRect& aClip, |
161 | | wr::ImageRendering aFilter, |
162 | | const Range<wr::ImageKey>& aImageKeys) |
163 | 0 | { |
164 | 0 | MOZ_ASSERT(mWrappedTextureHost); |
165 | 0 | MOZ_ASSERT(aImageKeys.length() > 0); |
166 | 0 |
|
167 | 0 | mWrappedTextureHost->PushDisplayItems(aBuilder, |
168 | 0 | aBounds, |
169 | 0 | aClip, |
170 | 0 | aFilter, |
171 | 0 | aImageKeys); |
172 | 0 | } |
173 | | |
174 | | bool |
175 | | WebRenderTextureHost::SupportsWrNativeTexture() |
176 | 0 | { |
177 | 0 | return mWrappedTextureHost->SupportsWrNativeTexture(); |
178 | 0 | } |
179 | | |
180 | | } // namespace layers |
181 | | } // namespace mozilla |