tor-browser

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

RenderTextureHost.h (6131B)


      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_RENDERTEXTUREHOST_H
      8 #define MOZILLA_GFX_RENDERTEXTUREHOST_H
      9 
     10 #include "GLConsts.h"
     11 #include "GLTypes.h"
     12 #include "nsISupportsImpl.h"
     13 #include "mozilla/Atomics.h"
     14 #include "mozilla/gfx/2D.h"
     15 #include "mozilla/layers/LayersSurfaces.h"
     16 #include "mozilla/layers/OverlayInfo.h"
     17 #include "mozilla/RefPtr.h"
     18 #include "mozilla/webrender/webrender_ffi.h"
     19 #include "mozilla/webrender/WebRenderTypes.h"
     20 
     21 namespace mozilla {
     22 
     23 namespace gl {
     24 class GLContext;
     25 }
     26 namespace layers {
     27 class TextureSource;
     28 class TextureSourceProvider;
     29 }  // namespace layers
     30 
     31 namespace wr {
     32 
     33 class RenderEGLImageTextureHost;
     34 class RenderAndroidHardwareBufferTextureHost;
     35 class RenderAndroidSurfaceTextureHost;
     36 class RenderCompositor;
     37 class RenderDXGITextureHost;
     38 class RenderDXGIYCbCrTextureHost;
     39 class RenderDcompSurfaceTextureHost;
     40 class RenderMacIOSurfaceTextureHost;
     41 class RenderBufferTextureHost;
     42 class RenderTextureHostSWGL;
     43 class RenderTextureHostWrapper;
     44 class RenderDMABUFTextureHost;
     45 
     46 void ActivateBindAndTexParameteri(gl::GLContext* aGL, GLenum aActiveTexture,
     47                                  GLenum aBindTarget, GLuint aBindTexture);
     48 
     49 // RenderTextureHostUsageInfo holds information about how the RenderTextureHost
     50 // is used. It is used by AsyncImagePipelineManager to determine how to render
     51 // TextureHost.
     52 class RenderTextureHostUsageInfo final {
     53 public:
     54  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHostUsageInfo)
     55 
     56  RenderTextureHostUsageInfo() : mCreationTimeStamp(TimeStamp::Now()) {}
     57 
     58  bool VideoOverlayDisabled() { return mVideoOverlayDisabled; }
     59  void DisableVideoOverlay() { mVideoOverlayDisabled = true; }
     60 
     61  void OnVideoPresent(int aFrameId, uint32_t aDurationMs);
     62  void OnCompositorEndFrame(int aFrameId, uint32_t aDurationMs);
     63 
     64  const TimeStamp mCreationTimeStamp;
     65 
     66 protected:
     67  ~RenderTextureHostUsageInfo() = default;
     68 
     69  // RenderTextureHost prefers to disable video overlay.
     70  Atomic<bool> mVideoOverlayDisabled{false};
     71 
     72  int mVideoPresentFrameId = 0;
     73  int mSlowPresentCount = 0;
     74  int mSlowCommitCount = 0;
     75 };
     76 
     77 class RenderTextureHost {
     78  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHost)
     79 
     80 public:
     81  RenderTextureHost();
     82 
     83  virtual gfx::SurfaceFormat GetFormat() const {
     84    return gfx::SurfaceFormat::UNKNOWN;
     85  }
     86 
     87  virtual gfx::YUVRangedColorSpace GetYUVColorSpace() const {
     88    return gfx::YUVRangedColorSpace::Default;
     89  }
     90 
     91  virtual wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL);
     92 
     93  virtual void Unlock() {}
     94 
     95  virtual wr::WrExternalImage LockSWGL(uint8_t aChannelIndex, void* aContext,
     96                                       RenderCompositor* aCompositor);
     97 
     98  virtual void UnlockSWGL() {}
     99 
    100  virtual RefPtr<layers::TextureSource> CreateTextureSource(
    101      layers::TextureSourceProvider* aProvider);
    102 
    103  virtual void ClearCachedResources() {}
    104 
    105  // Called asynchronouly when corresponding TextureHost's mCompositableCount
    106  // becomes from 0 to 1. For now, it is used only for
    107  // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
    108  virtual void PrepareForUse() {}
    109  // Called asynchronouly when corresponding TextureHost's is actually going to
    110  // be used by WebRender. For now, it is used only for
    111  // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
    112  virtual void NotifyForUse() {}
    113  // Called asynchronouly when corresponding TextureHost's mCompositableCount
    114  // becomes 0. For now, it is used only for
    115  // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
    116  virtual void NotifyNotUsed() {}
    117  // Returns true when RenderTextureHost needs SyncObjectHost::Synchronize()
    118  // call, before its usage.
    119  virtual bool SyncObjectNeeded() { return false; }
    120  // Returns true when this texture was generated from a DRM-protected source.
    121  bool IsFromDRMSource() { return mIsFromDRMSource; }
    122  void SetIsFromDRMSource(bool aIsFromDRMSource) {
    123    mIsFromDRMSource = aIsFromDRMSource;
    124  }
    125 
    126  virtual size_t Bytes() = 0;
    127 
    128  virtual RenderDXGITextureHost* AsRenderDXGITextureHost() { return nullptr; }
    129  virtual RenderDXGIYCbCrTextureHost* AsRenderDXGIYCbCrTextureHost() {
    130    return nullptr;
    131  }
    132 
    133  virtual RenderMacIOSurfaceTextureHost* AsRenderMacIOSurfaceTextureHost() {
    134    return nullptr;
    135  }
    136 
    137  virtual RenderEGLImageTextureHost* AsRenderEGLImageTextureHost() {
    138    return nullptr;
    139  }
    140 
    141  virtual RenderAndroidHardwareBufferTextureHost*
    142  AsRenderAndroidHardwareBufferTextureHost() {
    143    return nullptr;
    144  }
    145 
    146  virtual RenderAndroidSurfaceTextureHost* AsRenderAndroidSurfaceTextureHost() {
    147    return nullptr;
    148  }
    149 
    150  virtual RenderTextureHostSWGL* AsRenderTextureHostSWGL() { return nullptr; }
    151 
    152  virtual RenderDcompSurfaceTextureHost* AsRenderDcompSurfaceTextureHost() {
    153    return nullptr;
    154  }
    155 
    156  virtual RenderDMABUFTextureHost* AsRenderDMABUFTextureHost() {
    157    return nullptr;
    158  }
    159 
    160  virtual void Destroy();
    161 
    162  virtual void SetIsSoftwareDecodedVideo() {
    163    MOZ_ASSERT_UNREACHABLE("unexpected to be called");
    164  }
    165  virtual bool IsSoftwareDecodedVideo() {
    166    MOZ_ASSERT_UNREACHABLE("unexpected to be called");
    167    return false;
    168  }
    169 
    170  // Get RenderTextureHostUsageInfo of the RenderTextureHost.
    171  // If mRenderTextureHostUsageInfo and aUsageInfo are different, merge them to
    172  // one RenderTextureHostUsageInfo.
    173  virtual RefPtr<RenderTextureHostUsageInfo> GetOrMergeUsageInfo(
    174      const MutexAutoLock& aProofOfMapLock,
    175      RefPtr<RenderTextureHostUsageInfo> aUsageInfo);
    176 
    177  virtual RefPtr<RenderTextureHostUsageInfo> GetTextureHostUsageInfo(
    178      const MutexAutoLock& aProofOfMapLock);
    179 
    180 protected:
    181  virtual ~RenderTextureHost();
    182 
    183  bool mIsFromDRMSource;
    184 
    185  // protected by RenderThread::mRenderTextureMapLock
    186  RefPtr<RenderTextureHostUsageInfo> mRenderTextureHostUsageInfo;
    187 
    188  friend class RenderTextureHostWrapper;
    189 };
    190 
    191 }  // namespace wr
    192 }  // namespace mozilla
    193 
    194 #endif  // MOZILLA_GFX_RENDERTEXTUREHOST_H