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/. */
7 #include "RenderTextureHostWrapper.h"
9 #include "mozilla/gfx/Logging.h"
10 #include "mozilla/layers/RemoteTextureMap.h"
11 #include "mozilla/webrender/RenderThread.h"
16 RenderTextureHostWrapper::RenderTextureHostWrapper(
17 ExternalImageId aExternalImageId
)
18 : mExternalImageId(aExternalImageId
) {
19 MOZ_COUNT_CTOR_INHERITED(RenderTextureHostWrapper
, RenderTextureHost
);
23 RenderTextureHostWrapper::RenderTextureHostWrapper(
24 const layers::RemoteTextureId aTextureId
,
25 const layers::RemoteTextureOwnerId aOwnerId
, const base::ProcessId aForPid
)
26 : mExternalImageId({}),
27 mTextureId(Some(aTextureId
)),
28 mOwnerId(Some(aOwnerId
)),
29 mForPid(Some(aForPid
)) {
30 MOZ_COUNT_CTOR_INHERITED(RenderTextureHostWrapper
, RenderTextureHost
);
33 RenderTextureHostWrapper::~RenderTextureHostWrapper() {
34 MOZ_COUNT_DTOR_INHERITED(RenderTextureHostWrapper
, RenderTextureHost
);
37 void RenderTextureHostWrapper::EnsureTextureHost() const {
38 MOZ_ASSERT(mTextureId
.isNothing());
44 mTextureHost
= RenderThread::Get()->GetRenderTexture(mExternalImageId
);
45 MOZ_ASSERT(mTextureHost
);
47 gfxCriticalNoteOnce
<< "Failed to get RenderTextureHost for extId:"
48 << AsUint64(mExternalImageId
);
52 void RenderTextureHostWrapper::EnsureRemoteTexture() const {
53 MOZ_ASSERT(mTextureId
.isSome());
59 auto externalImageId
=
60 layers::RemoteTextureMap::Get()->GetExternalImageIdOfRemoteTexture(
61 *mTextureId
, *mOwnerId
, *mForPid
);
62 if (externalImageId
.isNothing()) {
63 // This could happen with IPC abnormal shutdown
67 mTextureHost
= RenderThread::Get()->GetRenderTexture(*externalImageId
);
68 MOZ_ASSERT(mTextureHost
);
70 gfxCriticalNoteOnce
<< "Failed to get RenderTextureHost for extId:"
71 << AsUint64(*externalImageId
);
75 wr::WrExternalImage
RenderTextureHostWrapper::Lock(uint8_t aChannelIndex
,
77 if (mTextureId
.isSome()) {
78 EnsureRemoteTexture();
82 return InvalidToWrExternalImage();
85 return mTextureHost
->Lock(aChannelIndex
, aGL
);
88 void RenderTextureHostWrapper::Unlock() {
90 mTextureHost
->Unlock();
94 std::pair
<gfx::Point
, gfx::Point
> RenderTextureHostWrapper::GetUvCoords(
95 gfx::IntSize aTextureSize
) const {
97 return mTextureHost
->GetUvCoords(aTextureSize
);
99 return RenderTextureHost::GetUvCoords(aTextureSize
);
102 void RenderTextureHostWrapper::ClearCachedResources() {
104 mTextureHost
->ClearCachedResources();
108 void RenderTextureHostWrapper::PrepareForUse() {
112 mTextureHost
->PrepareForUse();
115 void RenderTextureHostWrapper::NotifyForUse() {
119 mTextureHost
->NotifyForUse();
122 void RenderTextureHostWrapper::NotifyNotUsed() {
126 mTextureHost
->NotifyNotUsed();
129 bool RenderTextureHostWrapper::SyncObjectNeeded() { return false; }
131 RenderMacIOSurfaceTextureHost
*
132 RenderTextureHostWrapper::AsRenderMacIOSurfaceTextureHost() {
133 if (mTextureId
.isSome()) {
134 EnsureRemoteTexture();
139 return mTextureHost
->AsRenderMacIOSurfaceTextureHost();
142 RenderDXGITextureHost
* RenderTextureHostWrapper::AsRenderDXGITextureHost() {
143 if (mTextureId
.isSome()) {
144 EnsureRemoteTexture();
149 return mTextureHost
->AsRenderDXGITextureHost();
152 RenderDXGIYCbCrTextureHost
*
153 RenderTextureHostWrapper::AsRenderDXGIYCbCrTextureHost() {
154 if (mTextureId
.isSome()) {
155 EnsureRemoteTexture();
160 return mTextureHost
->AsRenderDXGIYCbCrTextureHost();
163 RenderDcompSurfaceTextureHost
*
164 RenderTextureHostWrapper::AsRenderDcompSurfaceTextureHost() {
168 return mTextureHost
->AsRenderDcompSurfaceTextureHost();
171 RenderTextureHostSWGL
* RenderTextureHostWrapper::AsRenderTextureHostSWGL() {
172 if (mTextureId
.isSome()) {
173 EnsureRemoteTexture();
178 return mTextureHost
->AsRenderTextureHostSWGL();
181 RenderAndroidHardwareBufferTextureHost
*
182 RenderTextureHostWrapper::AsRenderAndroidHardwareBufferTextureHost() {
183 if (mTextureId
.isSome()) {
184 EnsureRemoteTexture();
189 return mTextureHost
->AsRenderAndroidHardwareBufferTextureHost();
192 RenderAndroidSurfaceTextureHost
*
193 RenderTextureHostWrapper::AsRenderAndroidSurfaceTextureHost() {
194 if (mTextureId
.isSome()) {
195 EnsureRemoteTexture();
200 return mTextureHost
->AsRenderAndroidSurfaceTextureHost();
203 RenderTextureHostSWGL
* RenderTextureHostWrapper::EnsureRenderTextureHostSWGL()
205 if (mTextureId
.isSome()) {
206 EnsureRemoteTexture();
211 return mTextureHost
->AsRenderTextureHostSWGL();
214 bool RenderTextureHostWrapper::IsWrappingAsyncRemoteTexture() {
215 return mTextureId
.isSome();
218 size_t RenderTextureHostWrapper::GetPlaneCount() const {
219 if (RenderTextureHostSWGL
* swglHost
= EnsureRenderTextureHostSWGL()) {
220 return swglHost
->GetPlaneCount();
225 gfx::SurfaceFormat
RenderTextureHostWrapper::GetFormat() const {
226 if (RenderTextureHostSWGL
* swglHost
= EnsureRenderTextureHostSWGL()) {
227 return swglHost
->GetFormat();
229 return gfx::SurfaceFormat::UNKNOWN
;
232 gfx::ColorDepth
RenderTextureHostWrapper::GetColorDepth() const {
233 if (RenderTextureHostSWGL
* swglHost
= EnsureRenderTextureHostSWGL()) {
234 return swglHost
->GetColorDepth();
236 return gfx::ColorDepth::COLOR_8
;
239 gfx::YUVRangedColorSpace
RenderTextureHostWrapper::GetYUVColorSpace() const {
240 if (RenderTextureHostSWGL
* swglHost
= EnsureRenderTextureHostSWGL()) {
241 return swglHost
->GetYUVColorSpace();
243 return gfx::YUVRangedColorSpace::Default
;
246 bool RenderTextureHostWrapper::MapPlane(RenderCompositor
* aCompositor
,
247 uint8_t aChannelIndex
,
248 PlaneInfo
& aPlaneInfo
) {
249 if (RenderTextureHostSWGL
* swglHost
= EnsureRenderTextureHostSWGL()) {
250 return swglHost
->MapPlane(aCompositor
, aChannelIndex
, aPlaneInfo
);
255 void RenderTextureHostWrapper::UnmapPlanes() {
256 if (RenderTextureHostSWGL
* swglHost
= EnsureRenderTextureHostSWGL()) {
257 swglHost
->UnmapPlanes();
262 } // namespace mozilla