Bug 1719855 - Clean up code whether to fire a pointercancel event. r=botond
[gecko.git] / gfx / webrender_bindings / RenderTextureHostWrapper.cpp
blob7cc03fb97840458292366cb645886e640a81ed0d
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"
13 namespace mozilla {
14 namespace wr {
16 RenderTextureHostWrapper::RenderTextureHostWrapper(
17 ExternalImageId aExternalImageId)
18 : mExternalImageId(aExternalImageId) {
19 MOZ_COUNT_CTOR_INHERITED(RenderTextureHostWrapper, RenderTextureHost);
20 EnsureTextureHost();
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());
40 if (mTextureHost) {
41 return;
44 mTextureHost = RenderThread::Get()->GetRenderTexture(mExternalImageId);
45 MOZ_ASSERT(mTextureHost);
46 if (!mTextureHost) {
47 gfxCriticalNoteOnce << "Failed to get RenderTextureHost for extId:"
48 << AsUint64(mExternalImageId);
52 void RenderTextureHostWrapper::EnsureRemoteTexture() const {
53 MOZ_ASSERT(mTextureId.isSome());
55 if (mTextureHost) {
56 return;
59 auto externalImageId =
60 layers::RemoteTextureMap::Get()->GetExternalImageIdOfRemoteTexture(
61 *mTextureId, *mOwnerId, *mForPid);
62 if (externalImageId.isNothing()) {
63 // This could happen with IPC abnormal shutdown
64 return;
67 mTextureHost = RenderThread::Get()->GetRenderTexture(*externalImageId);
68 MOZ_ASSERT(mTextureHost);
69 if (!mTextureHost) {
70 gfxCriticalNoteOnce << "Failed to get RenderTextureHost for extId:"
71 << AsUint64(*externalImageId);
75 wr::WrExternalImage RenderTextureHostWrapper::Lock(uint8_t aChannelIndex,
76 gl::GLContext* aGL) {
77 if (mTextureId.isSome()) {
78 EnsureRemoteTexture();
81 if (!mTextureHost) {
82 return InvalidToWrExternalImage();
85 return mTextureHost->Lock(aChannelIndex, aGL);
88 void RenderTextureHostWrapper::Unlock() {
89 if (mTextureHost) {
90 mTextureHost->Unlock();
94 std::pair<gfx::Point, gfx::Point> RenderTextureHostWrapper::GetUvCoords(
95 gfx::IntSize aTextureSize) const {
96 if (mTextureHost) {
97 return mTextureHost->GetUvCoords(aTextureSize);
99 return RenderTextureHost::GetUvCoords(aTextureSize);
102 void RenderTextureHostWrapper::ClearCachedResources() {
103 if (mTextureHost) {
104 mTextureHost->ClearCachedResources();
108 void RenderTextureHostWrapper::PrepareForUse() {
109 if (!mTextureHost) {
110 return;
112 mTextureHost->PrepareForUse();
115 void RenderTextureHostWrapper::NotifyForUse() {
116 if (!mTextureHost) {
117 return;
119 mTextureHost->NotifyForUse();
122 void RenderTextureHostWrapper::NotifyNotUsed() {
123 if (!mTextureHost) {
124 return;
126 mTextureHost->NotifyNotUsed();
129 bool RenderTextureHostWrapper::SyncObjectNeeded() { return false; }
131 RenderMacIOSurfaceTextureHost*
132 RenderTextureHostWrapper::AsRenderMacIOSurfaceTextureHost() {
133 if (mTextureId.isSome()) {
134 EnsureRemoteTexture();
136 if (!mTextureHost) {
137 return nullptr;
139 return mTextureHost->AsRenderMacIOSurfaceTextureHost();
142 RenderDXGITextureHost* RenderTextureHostWrapper::AsRenderDXGITextureHost() {
143 if (mTextureId.isSome()) {
144 EnsureRemoteTexture();
146 if (!mTextureHost) {
147 return nullptr;
149 return mTextureHost->AsRenderDXGITextureHost();
152 RenderDXGIYCbCrTextureHost*
153 RenderTextureHostWrapper::AsRenderDXGIYCbCrTextureHost() {
154 if (mTextureId.isSome()) {
155 EnsureRemoteTexture();
157 if (!mTextureHost) {
158 return nullptr;
160 return mTextureHost->AsRenderDXGIYCbCrTextureHost();
163 RenderDcompSurfaceTextureHost*
164 RenderTextureHostWrapper::AsRenderDcompSurfaceTextureHost() {
165 if (!mTextureHost) {
166 return nullptr;
168 return mTextureHost->AsRenderDcompSurfaceTextureHost();
171 RenderTextureHostSWGL* RenderTextureHostWrapper::AsRenderTextureHostSWGL() {
172 if (mTextureId.isSome()) {
173 EnsureRemoteTexture();
175 if (!mTextureHost) {
176 return nullptr;
178 return mTextureHost->AsRenderTextureHostSWGL();
181 RenderAndroidHardwareBufferTextureHost*
182 RenderTextureHostWrapper::AsRenderAndroidHardwareBufferTextureHost() {
183 if (mTextureId.isSome()) {
184 EnsureRemoteTexture();
186 if (!mTextureHost) {
187 return nullptr;
189 return mTextureHost->AsRenderAndroidHardwareBufferTextureHost();
192 RenderAndroidSurfaceTextureHost*
193 RenderTextureHostWrapper::AsRenderAndroidSurfaceTextureHost() {
194 if (mTextureId.isSome()) {
195 EnsureRemoteTexture();
197 if (!mTextureHost) {
198 return nullptr;
200 return mTextureHost->AsRenderAndroidSurfaceTextureHost();
203 RenderTextureHostSWGL* RenderTextureHostWrapper::EnsureRenderTextureHostSWGL()
204 const {
205 if (mTextureId.isSome()) {
206 EnsureRemoteTexture();
208 if (!mTextureHost) {
209 return nullptr;
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();
222 return 0;
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);
252 return false;
255 void RenderTextureHostWrapper::UnmapPlanes() {
256 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
257 swglHost->UnmapPlanes();
261 } // namespace wr
262 } // namespace mozilla