tor-browser

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

BufferTexture.h (4695B)


      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_LAYERS_BUFFERETEXTURE
      8 #define MOZILLA_LAYERS_BUFFERETEXTURE
      9 
     10 #include "mozilla/gfx/2D.h"
     11 #include "mozilla/gfx/Types.h"
     12 #include "mozilla/layers/TextureClient.h"
     13 
     14 namespace mozilla {
     15 namespace layers {
     16 
     17 class BufferTextureData : public TextureData {
     18 public:
     19  // ShmemAllocator needs to implement IShmemAllocator and IsSameProcess,
     20  // as done in LayersIPCChannel and ISurfaceAllocator.
     21  template <typename ShmemAllocator>
     22  static BufferTextureData* Create(gfx::IntSize aSize,
     23                                   gfx::SurfaceFormat aFormat,
     24                                   gfx::BackendType aMoz2DBackend,
     25                                   LayersBackend aLayersBackend,
     26                                   TextureFlags aFlags,
     27                                   TextureAllocationFlags aAllocFlags,
     28                                   ShmemAllocator aAllocator);
     29 
     30  static BufferTextureData* CreateForYCbCr(
     31      KnowsCompositor* aAllocator, const gfx::IntRect& aDisplay,
     32      const gfx::IntSize& aYSize, uint32_t aYStride,
     33      const gfx::IntSize& aCbCrSize, uint32_t aCbCrStride,
     34      StereoMode aStereoMode, gfx::ColorDepth aColorDepth,
     35      gfx::YUVColorSpace aYUVColorSpace, gfx::ColorRange aColorRange,
     36      gfx::ChromaSubsampling aSubsampling, TextureFlags aTextureFlags);
     37 
     38  bool Lock(OpenMode aMode) override { return true; }
     39 
     40  void Unlock() override { mIsClear = false; }
     41 
     42  void FillInfo(TextureData::Info& aInfo) const override;
     43 
     44  already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;
     45 
     46  bool BorrowMappedData(MappedTextureData& aMap) override;
     47 
     48  bool BorrowMappedYCbCrData(MappedYCbCrTextureData& aMap) override;
     49 
     50  // use TextureClient's default implementation
     51  bool UpdateFromSurface(gfx::SourceSurface* aSurface) override;
     52 
     53  BufferTextureData* AsBufferTextureData() override { return this; }
     54 
     55  Maybe<gfx::IntSize> GetYSize() const;
     56 
     57  Maybe<gfx::IntSize> GetCbCrSize() const;
     58 
     59  Maybe<int32_t> GetYStride() const;
     60 
     61  Maybe<int32_t> GetCbCrStride() const;
     62 
     63  Maybe<gfx::YUVColorSpace> GetYUVColorSpace() const;
     64 
     65  Maybe<gfx::ColorDepth> GetColorDepth() const;
     66 
     67  Maybe<StereoMode> GetStereoMode() const;
     68 
     69  Maybe<gfx::ChromaSubsampling> GetChromaSubsampling() const;
     70 
     71  gfx::IntRect GetPictureRect() const;
     72 
     73  gfx::IntSize GetSize() const;
     74 
     75  gfx::SurfaceFormat GetFormat() const;
     76 
     77  virtual size_t GetBufferSize() = 0;
     78 
     79 protected:
     80  static BufferTextureData* Create(
     81      gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
     82      gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
     83      TextureFlags aFlags, TextureAllocationFlags aAllocFlags,
     84      mozilla::ipc::IShmemAllocator* aAllocator, bool aIsSameProcess);
     85 
     86  static BufferTextureData* CreateInternal(LayersIPCChannel* aAllocator,
     87                                           const BufferDescriptor& aDesc,
     88                                           gfx::BackendType aMoz2DBackend,
     89                                           int32_t aBufferSize,
     90                                           TextureFlags aTextureFlags);
     91 
     92  virtual uint8_t* GetBuffer() = 0;
     93 
     94  BufferTextureData(const BufferDescriptor& aDescriptor,
     95                    gfx::BackendType aMoz2DBackend, bool aIsClear = false)
     96      : mDescriptor(aDescriptor),
     97        mMoz2DBackend(aMoz2DBackend),
     98        mIsClear(aIsClear) {}
     99 
    100  ~BufferTextureData() override = default;
    101 
    102  BufferDescriptor mDescriptor;
    103  gfx::BackendType mMoz2DBackend;
    104  bool mIsClear = false;
    105 };
    106 
    107 template <typename ShmemAllocator>
    108 inline BufferTextureData* BufferTextureData::Create(
    109    gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
    110    gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
    111    TextureFlags aFlags, TextureAllocationFlags aAllocFlags,
    112    ShmemAllocator aAllocator) {
    113  return Create(aSize, aFormat, aMoz2DBackend, aLayersBackend, aFlags,
    114                aAllocFlags, aAllocator, aAllocator->IsSameProcess());
    115 }
    116 
    117 // nullptr allocator specialization
    118 template <>
    119 inline BufferTextureData* BufferTextureData::Create(
    120    gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
    121    gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
    122    TextureFlags aFlags, TextureAllocationFlags aAllocFlags, std::nullptr_t) {
    123  return Create(aSize, aFormat, aMoz2DBackend, aLayersBackend, aFlags,
    124                aAllocFlags, nullptr, true);
    125 }
    126 
    127 }  // namespace layers
    128 }  // namespace mozilla
    129 
    130 #endif