tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RenderAndroidSurfaceTextureHost.h (2835B)


      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_RENDERANDROIDSURFACETEXTUREHOST_H
      8 #define MOZILLA_GFX_RENDERANDROIDSURFACETEXTUREHOST_H
      9 
     10 #include "mozilla/java/GeckoSurfaceTextureWrappers.h"
     11 #include "mozilla/layers/TextureHostOGL.h"
     12 #include "RenderTextureHostSWGL.h"
     13 
     14 namespace mozilla {
     15 
     16 namespace gfx {
     17 class DataSourceSurface;
     18 }
     19 
     20 namespace wr {
     21 
     22 class RenderAndroidSurfaceTextureHost final : public RenderTextureHostSWGL {
     23 public:
     24  explicit RenderAndroidSurfaceTextureHost(
     25      const java::GeckoSurfaceTexture::GlobalRef& aSurfTex, gfx::IntSize aSize,
     26      gfx::SurfaceFormat aFormat, bool aContinuousUpdate,
     27      Maybe<gfx::Matrix4x4> aTransformOverride, bool aIsRemoteTexture);
     28 
     29  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
     30  void Unlock() override;
     31 
     32  size_t Bytes() override {
     33    return mSize.width * mSize.height * BytesPerPixel(mFormat);
     34  }
     35 
     36  void PrepareForUse() override;
     37  void NotifyForUse() override;
     38  void NotifyNotUsed() override;
     39 
     40  // RenderTextureHostSWGL
     41  gfx::SurfaceFormat GetFormat() const override;
     42  gfx::ColorDepth GetColorDepth() const override {
     43    return gfx::ColorDepth::COLOR_8;
     44  }
     45  size_t GetPlaneCount() const override { return 1; }
     46  bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
     47                PlaneInfo& aPlaneInfo) override;
     48  void UnmapPlanes() override;
     49 
     50  RefPtr<layers::TextureSource> CreateTextureSource(
     51      layers::TextureSourceProvider* aProvider) override;
     52 
     53  RenderAndroidSurfaceTextureHost* AsRenderAndroidSurfaceTextureHost()
     54      override {
     55    return this;
     56  }
     57 
     58  void UpdateTexImageIfNecessary();
     59 
     60  mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
     61  const gfx::IntSize mSize;
     62  const gfx::SurfaceFormat mFormat;
     63  // mContinuousUpdate was used for rendering video in the past.
     64  // It is not used on current gecko.
     65  const bool mContinuousUpdate;
     66  const Maybe<gfx::Matrix4x4> mTransformOverride;
     67 
     68 private:
     69  virtual ~RenderAndroidSurfaceTextureHost();
     70  bool EnsureAttachedToGLContext();
     71 
     72  gfx::Matrix4x4 GetTextureTransform() const;
     73 
     74  already_AddRefed<gfx::DataSourceSurface> ReadTexImage();
     75 
     76  enum PrepareStatus {
     77    STATUS_NONE,
     78    STATUS_MIGHT_BE_USED_BY_WR,
     79    STATUS_UPDATE_TEX_IMAGE_NEEDED,
     80    STATUS_PREPARED
     81  };
     82 
     83  PrepareStatus mPrepareStatus;
     84  bool mAttachedToGLContext;
     85 
     86  RefPtr<gl::GLContext> mGL;
     87 
     88  RefPtr<gfx::DataSourceSurface> mReadback;
     89 
     90  bool mIsRemoteTexture;
     91 };
     92 
     93 }  // namespace wr
     94 }  // namespace mozilla
     95 
     96 #endif  // MOZILLA_GFX_RENDERANDROIDSURFACETEXTUREHOST_H