RenderEGLImageTextureHost.h (2167B)
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_RENDEREGLIMAGETEXTUREHOST_H 8 #define MOZILLA_GFX_RENDEREGLIMAGETEXTUREHOST_H 9 10 #include "mozilla/layers/TextureHostOGL.h" 11 #include "RenderTextureHostSWGL.h" 12 13 namespace mozilla { 14 15 namespace wr { 16 17 // RenderEGLImageTextureHost is created only for SharedSurface_EGLImage that is 18 // created in parent process. 19 class RenderEGLImageTextureHost final : public RenderTextureHostSWGL { 20 public: 21 RenderEGLImageTextureHost(EGLImage aImage, EGLSync aSync, gfx::IntSize aSize, 22 gfx::SurfaceFormat aFormat); 23 24 wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override; 25 void Unlock() override; 26 size_t Bytes() override { 27 return mSize.width * mSize.height * BytesPerPixel(mFormat); 28 } 29 30 RenderEGLImageTextureHost* AsRenderEGLImageTextureHost() override { 31 return this; 32 } 33 34 RefPtr<layers::TextureSource> CreateTextureSource( 35 layers::TextureSourceProvider* aProvider) override; 36 37 // RenderTextureHostSWGL 38 gfx::SurfaceFormat GetFormat() const override; 39 gfx::ColorDepth GetColorDepth() const override { 40 return gfx::ColorDepth::COLOR_8; 41 } 42 size_t GetPlaneCount() const override { return 1; }; 43 bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex, 44 PlaneInfo& aPlaneInfo) override; 45 void UnmapPlanes() override; 46 47 private: 48 virtual ~RenderEGLImageTextureHost(); 49 bool CreateTextureHandle(); 50 void DeleteTextureHandle(); 51 bool WaitSync(); 52 already_AddRefed<gfx::DataSourceSurface> ReadTexImage(); 53 54 const EGLImage mImage; 55 EGLSync mSync; 56 const gfx::IntSize mSize; 57 const gfx::SurfaceFormat mFormat; 58 59 RefPtr<gl::GLContext> mGL; 60 GLenum mTextureTarget; 61 GLuint mTextureHandle; 62 RefPtr<gfx::DataSourceSurface> mReadback; 63 }; 64 65 } // namespace wr 66 } // namespace mozilla 67 68 #endif // MOZILLA_GFX_RENDEREGLIMAGETEXTUREHOST_H