RenderTextureHostWrapper.cpp (6639B)
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 "RenderTextureHostWrapper.h" 8 9 #include "mozilla/gfx/Logging.h" 10 #include "mozilla/layers/RemoteTextureMap.h" 11 #include "mozilla/webrender/RenderThread.h" 12 13 namespace mozilla { 14 namespace wr { 15 16 RenderTextureHostWrapper::RenderTextureHostWrapper( 17 ExternalImageId aExternalImageId) 18 : mExternalImageId(aExternalImageId) { 19 MOZ_COUNT_CTOR_INHERITED(RenderTextureHostWrapper, RenderTextureHost); 20 EnsureTextureHost(); 21 } 22 23 RenderTextureHostWrapper::~RenderTextureHostWrapper() { 24 MOZ_COUNT_DTOR_INHERITED(RenderTextureHostWrapper, RenderTextureHost); 25 } 26 27 void RenderTextureHostWrapper::EnsureTextureHost() const { 28 if (mTextureHost) { 29 return; 30 } 31 32 mTextureHost = RenderThread::Get()->GetRenderTexture(mExternalImageId); 33 MOZ_ASSERT(mTextureHost); 34 if (!mTextureHost) { 35 gfxCriticalNoteOnce << "Failed to get RenderTextureHost for extId:" 36 << AsUint64(mExternalImageId); 37 } 38 } 39 40 wr::WrExternalImage RenderTextureHostWrapper::Lock(uint8_t aChannelIndex, 41 gl::GLContext* aGL) { 42 if (!mTextureHost) { 43 return InvalidToWrExternalImage(); 44 } 45 46 return mTextureHost->Lock(aChannelIndex, aGL); 47 } 48 49 void RenderTextureHostWrapper::Unlock() { 50 if (mTextureHost) { 51 mTextureHost->Unlock(); 52 } 53 } 54 55 void RenderTextureHostWrapper::ClearCachedResources() { 56 if (mTextureHost) { 57 mTextureHost->ClearCachedResources(); 58 } 59 } 60 61 void RenderTextureHostWrapper::PrepareForUse() { 62 if (!mTextureHost) { 63 return; 64 } 65 mTextureHost->PrepareForUse(); 66 } 67 68 void RenderTextureHostWrapper::NotifyForUse() { 69 if (!mTextureHost) { 70 return; 71 } 72 mTextureHost->NotifyForUse(); 73 } 74 75 void RenderTextureHostWrapper::NotifyNotUsed() { 76 if (!mTextureHost) { 77 return; 78 } 79 mTextureHost->NotifyNotUsed(); 80 } 81 82 bool RenderTextureHostWrapper::SyncObjectNeeded() { return false; } 83 84 RefPtr<layers::TextureSource> RenderTextureHostWrapper::CreateTextureSource( 85 layers::TextureSourceProvider* aProvider) { 86 if (!mTextureHost) { 87 return nullptr; 88 } 89 return mTextureHost->CreateTextureSource(aProvider); 90 } 91 92 RenderMacIOSurfaceTextureHost* 93 RenderTextureHostWrapper::AsRenderMacIOSurfaceTextureHost() { 94 if (!mTextureHost) { 95 return nullptr; 96 } 97 return mTextureHost->AsRenderMacIOSurfaceTextureHost(); 98 } 99 100 RenderDXGITextureHost* RenderTextureHostWrapper::AsRenderDXGITextureHost() { 101 if (!mTextureHost) { 102 return nullptr; 103 } 104 return mTextureHost->AsRenderDXGITextureHost(); 105 } 106 107 RenderDXGIYCbCrTextureHost* 108 RenderTextureHostWrapper::AsRenderDXGIYCbCrTextureHost() { 109 if (!mTextureHost) { 110 return nullptr; 111 } 112 return mTextureHost->AsRenderDXGIYCbCrTextureHost(); 113 } 114 115 RenderDcompSurfaceTextureHost* 116 RenderTextureHostWrapper::AsRenderDcompSurfaceTextureHost() { 117 if (!mTextureHost) { 118 return nullptr; 119 } 120 return mTextureHost->AsRenderDcompSurfaceTextureHost(); 121 } 122 123 RenderTextureHostSWGL* RenderTextureHostWrapper::AsRenderTextureHostSWGL() { 124 if (!mTextureHost) { 125 return nullptr; 126 } 127 return mTextureHost->AsRenderTextureHostSWGL(); 128 } 129 130 RenderDMABUFTextureHost* RenderTextureHostWrapper::AsRenderDMABUFTextureHost() { 131 if (!mTextureHost) { 132 return nullptr; 133 } 134 return mTextureHost->AsRenderDMABUFTextureHost(); 135 } 136 137 RenderAndroidHardwareBufferTextureHost* 138 RenderTextureHostWrapper::AsRenderAndroidHardwareBufferTextureHost() { 139 if (!mTextureHost) { 140 return nullptr; 141 } 142 return mTextureHost->AsRenderAndroidHardwareBufferTextureHost(); 143 } 144 145 RenderAndroidSurfaceTextureHost* 146 RenderTextureHostWrapper::AsRenderAndroidSurfaceTextureHost() { 147 if (!mTextureHost) { 148 return nullptr; 149 } 150 return mTextureHost->AsRenderAndroidSurfaceTextureHost(); 151 } 152 153 RenderEGLImageTextureHost* 154 RenderTextureHostWrapper::AsRenderEGLImageTextureHost() { 155 if (!mTextureHost) { 156 return nullptr; 157 } 158 return mTextureHost->AsRenderEGLImageTextureHost(); 159 } 160 161 RenderTextureHostSWGL* RenderTextureHostWrapper::EnsureRenderTextureHostSWGL() 162 const { 163 if (!mTextureHost) { 164 return nullptr; 165 } 166 return mTextureHost->AsRenderTextureHostSWGL(); 167 } 168 169 void RenderTextureHostWrapper::SetIsSoftwareDecodedVideo() { 170 if (!mTextureHost) { 171 return; 172 } 173 return mTextureHost->SetIsSoftwareDecodedVideo(); 174 } 175 176 bool RenderTextureHostWrapper::IsSoftwareDecodedVideo() { 177 if (!mTextureHost) { 178 return false; 179 } 180 return mTextureHost->IsSoftwareDecodedVideo(); 181 } 182 183 RefPtr<RenderTextureHostUsageInfo> 184 RenderTextureHostWrapper::GetOrMergeUsageInfo( 185 const MutexAutoLock& aProofOfMapLock, 186 RefPtr<RenderTextureHostUsageInfo> aUsageInfo) { 187 if (!mTextureHost) { 188 return nullptr; 189 } 190 return mTextureHost->GetOrMergeUsageInfo(aProofOfMapLock, aUsageInfo); 191 } 192 193 RefPtr<RenderTextureHostUsageInfo> 194 RenderTextureHostWrapper::GetTextureHostUsageInfo( 195 const MutexAutoLock& aProofOfMapLock) { 196 if (!mTextureHost) { 197 return nullptr; 198 } 199 return mTextureHost->GetTextureHostUsageInfo(aProofOfMapLock); 200 } 201 202 size_t RenderTextureHostWrapper::GetPlaneCount() const { 203 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) { 204 return swglHost->GetPlaneCount(); 205 } 206 return 0; 207 } 208 209 gfx::SurfaceFormat RenderTextureHostWrapper::GetFormat() const { 210 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) { 211 return swglHost->GetFormat(); 212 } 213 return gfx::SurfaceFormat::UNKNOWN; 214 } 215 216 gfx::ColorDepth RenderTextureHostWrapper::GetColorDepth() const { 217 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) { 218 return swglHost->GetColorDepth(); 219 } 220 return gfx::ColorDepth::COLOR_8; 221 } 222 223 gfx::YUVRangedColorSpace RenderTextureHostWrapper::GetYUVColorSpace() const { 224 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) { 225 return swglHost->GetYUVColorSpace(); 226 } 227 return gfx::YUVRangedColorSpace::Default; 228 } 229 230 bool RenderTextureHostWrapper::MapPlane(RenderCompositor* aCompositor, 231 uint8_t aChannelIndex, 232 PlaneInfo& aPlaneInfo) { 233 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) { 234 return swglHost->MapPlane(aCompositor, aChannelIndex, aPlaneInfo); 235 } 236 return false; 237 } 238 239 void RenderTextureHostWrapper::UnmapPlanes() { 240 if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) { 241 swglHost->UnmapPlanes(); 242 } 243 } 244 245 } // namespace wr 246 } // namespace mozilla