RenderExternalTextureHost.h (2516B)
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 #ifndef MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H 8 #define MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H 9 10 #include "mozilla/layers/TextureHostOGL.h" 11 #include "RenderTextureHostSWGL.h" 12 13 namespace mozilla { 14 namespace wr { 15 16 /** 17 * RenderExternalTextureHost manages external textures used by WebRender on Mac. 18 * The motivation for this is to be able to use Apple Client Storage OpenGL 19 * extension, which makes it possible to avoid some copies during texture 20 * upload. This is especially helpful for high resolution video. 21 */ 22 class RenderExternalTextureHost final : public RenderTextureHostSWGL { 23 public: 24 RenderExternalTextureHost(uint8_t* aBuffer, 25 const layers::BufferDescriptor& aDescriptor); 26 27 wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override; 28 void Unlock() override; 29 void PrepareForUse() override; 30 size_t Bytes() override { 31 return mSize.width * mSize.height * BytesPerPixel(mFormat); 32 } 33 34 // RenderTextureHostSWGL 35 size_t GetPlaneCount() const override; 36 37 gfx::SurfaceFormat GetFormat() const override; 38 39 gfx::ColorDepth GetColorDepth() const override; 40 41 gfx::YUVRangedColorSpace GetYUVColorSpace() const override; 42 43 bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex, 44 PlaneInfo& aPlaneInfo) override; 45 46 void UnmapPlanes() override; 47 48 private: 49 ~RenderExternalTextureHost(); 50 51 bool CreateSurfaces(); 52 void DeleteSurfaces(); 53 void DeleteTextures(); 54 55 uint8_t* GetBuffer() const { return mBuffer; } 56 bool InitializeIfNeeded(); 57 bool IsReadyForDeletion(); 58 bool IsYUV() const { return mFormat == gfx::SurfaceFormat::YUV420; } 59 size_t PlaneCount() const { return IsYUV() ? 3 : 1; } 60 void UpdateTexture(size_t aIndex); 61 void UpdateTextures(); 62 63 uint8_t* mBuffer; 64 layers::BufferDescriptor mDescriptor; 65 66 bool mInitialized; 67 bool mTextureUpdateNeeded; 68 69 gfx::IntSize mSize; 70 gfx::SurfaceFormat mFormat; 71 72 RefPtr<gl::GLContext> mGL; 73 RefPtr<gfx::DataSourceSurface> mSurfaces[3]; 74 RefPtr<layers::DirectMapTextureSource> mTextureSources[3]; 75 wr::WrExternalImage mImages[3]; 76 }; 77 78 } // namespace wr 79 } // namespace mozilla 80 81 #endif // MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H