tor-browser

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

DcompSurfaceImage.h (4437B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef GFX_LAYER_DCOMP_SURFACE_IMAGE_H
      7 #define GFX_LAYER_DCOMP_SURFACE_IMAGE_H
      8 
      9 #include "ImageContainer.h"
     10 #include "mozilla/layers/TextureClient.h"
     11 #include "mozilla/layers/TextureHost.h"
     12 
     13 namespace mozilla::wr {
     14 class DisplayListBuilder;
     15 class TransactionBuilder;
     16 }  // namespace mozilla::wr
     17 
     18 namespace mozilla::layers {
     19 
     20 already_AddRefed<TextureHost> CreateTextureHostDcompSurface(
     21    const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator,
     22    LayersBackend aBackend, TextureFlags aFlags);
     23 
     24 /**
     25 * A texture data wrapping a dcomp surface handle, which is provided by the
     26 * media foundation media engine. We won't be able to control real texture data
     27 * because that is protected by the media engine.
     28 */
     29 class DcompSurfaceTexture final : public TextureData {
     30 public:
     31  static already_AddRefed<TextureClient> CreateTextureClient(
     32      HANDLE aHandle, gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
     33      KnowsCompositor* aKnowsCompositor);
     34 
     35  ~DcompSurfaceTexture();
     36 
     37  bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
     38  void GetSubDescriptor(RemoteDecoderVideoSubDescriptor* aOutDesc) override;
     39  void FillInfo(TextureData::Info& aInfo) const {
     40    aInfo.size = mSize;
     41    aInfo.supportsMoz2D = false;
     42    aInfo.canExposeMappedData = false;
     43    aInfo.hasSynchronization = false;
     44  }
     45  bool Lock(OpenMode) override { return true; }
     46  void Unlock() override {}
     47  void Deallocate(LayersIPCChannel* aAllocator) override {}
     48 
     49 private:
     50  DcompSurfaceTexture(HANDLE aHandle, gfx::IntSize aSize,
     51                      gfx::SurfaceFormat aFormat)
     52      : mHandle(aHandle), mSize(aSize), mFormat(aFormat) {}
     53 
     54  const HANDLE mHandle;
     55  const gfx::IntSize mSize;
     56  const gfx::SurfaceFormat mFormat;
     57 };
     58 
     59 /**
     60 * A image data which holds a dcomp texture which is provided by the media
     61 * foundation media engine. As the real texture is protected, it does not
     62 * support being accessed as a source surface.
     63 */
     64 class DcompSurfaceImage : public Image {
     65 public:
     66  DcompSurfaceImage(HANDLE aHandle, gfx::IntSize aSize,
     67                    gfx::SurfaceFormat aFormat,
     68                    KnowsCompositor* aKnowsCompositor);
     69  virtual ~DcompSurfaceImage() = default;
     70 
     71  already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
     72    return nullptr;
     73  }
     74 
     75  gfx::IntSize GetSize() const { return mTextureClient->GetSize(); };
     76 
     77  TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
     78 
     79 private:
     80  RefPtr<TextureClient> mTextureClient;
     81 };
     82 
     83 /**
     84 * A Texture host living in GPU process which owns a dcomp surface handle which
     85 * is provided by the media foundation media engine.
     86 */
     87 class DcompSurfaceHandleHost : public TextureHost {
     88 public:
     89  DcompSurfaceHandleHost(TextureFlags aFlags,
     90                         const SurfaceDescriptorDcompSurface& aDescriptor);
     91 
     92  gfx::SurfaceFormat GetFormat() const override { return mFormat; }
     93 
     94  gfx::IntSize GetSize() const override { return mSize; }
     95 
     96  const char* Name() override { return "DcompSurfaceHandleHost"; }
     97 
     98  already_AddRefed<gfx::DataSourceSurface> GetAsSurface(
     99      gfx::DataSourceSurface* aSurface) override {
    100    return nullptr;
    101  }
    102 
    103  void CreateRenderTexture(
    104      const wr::ExternalImageId& aExternalImageId) override;
    105 
    106  void PushResourceUpdates(
    107      wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
    108      const Range<wr::ImageKey>& aImageKeys,
    109      const wr::ExternalImageId& aExternalImageId) override;
    110 
    111  void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
    112                        const wr::LayoutRect& aBounds,
    113                        const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
    114                        const Range<wr::ImageKey>& aImageKeys,
    115                        PushDisplayItemFlagSet aFlags) override;
    116 
    117  bool SupportsExternalCompositing(WebRenderBackend aBackend) override {
    118    return true;
    119  }
    120 
    121 protected:
    122  ~DcompSurfaceHandleHost();
    123 
    124  // Handle will be closed automatically when `UniqueFileHandle` gets destroyed.
    125  const mozilla::UniqueFileHandle mHandle;
    126  const gfx::IntSize mSize;
    127  const gfx::SurfaceFormat mFormat;
    128 };
    129 
    130 }  // namespace mozilla::layers
    131 
    132 #endif  // GFX_LAYER_DCOMP_SURFACE_IMAGE_H