tor-browser

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

MacIOSurfaceImage.h (2979B)


      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 GFX_MACIOSURFACEIMAGE_H
      8 #define GFX_MACIOSURFACEIMAGE_H
      9 
     10 #include "ImageContainer.h"
     11 #include "mozilla/gfx/MacIOSurface.h"
     12 #include "mozilla/gfx/Point.h"
     13 #include "mozilla/layers/TextureClient.h"
     14 
     15 namespace mozilla {
     16 
     17 namespace layers {
     18 
     19 class MacIOSurfaceImage : public Image {
     20 public:
     21  explicit MacIOSurfaceImage(MacIOSurface* aSurface)
     22      : Image(nullptr, ImageFormat::MAC_IOSURFACE), mSurface(aSurface) {
     23    if (aSurface) {
     24      mPictureRect = gfx::IntRect(
     25          gfx::IntPoint{}, gfx::IntSize(aSurface->GetDevicePixelWidth(0),
     26                                        aSurface->GetDevicePixelHeight(0)));
     27    }
     28  }
     29 
     30  bool SetData(ImageContainer* aContainer, const PlanarYCbCrData& aData);
     31 
     32  MacIOSurface* GetSurface() { return mSurface; }
     33 
     34  gfx::IntSize GetSize() const override {
     35    return gfx::IntSize::Truncate(mSurface->GetDevicePixelWidth(),
     36                                  mSurface->GetDevicePixelHeight());
     37  }
     38 
     39  already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
     40 
     41  nsresult BuildSurfaceDescriptorBuffer(
     42      SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
     43      const std::function<MemoryOrShmem(uint32_t)>& aAllocate) override;
     44 
     45  TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
     46 
     47  MacIOSurfaceImage* AsMacIOSurfaceImage() override { return this; }
     48 
     49  gfx::IntRect GetPictureRect() const override { return mPictureRect; }
     50 
     51  gfx::ColorDepth GetColorDepth() const override;
     52 
     53 private:
     54  RefPtr<MacIOSurface> mSurface;
     55  RefPtr<TextureClient> mTextureClient;
     56  gfx::IntRect mPictureRect;
     57 };
     58 
     59 class MacIOSurfaceRecycleAllocator {
     60 public:
     61  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MacIOSurfaceRecycleAllocator)
     62 
     63  already_AddRefed<MacIOSurface> Allocate(
     64      const gfx::IntSize aYSize, const gfx::IntSize& aCbCrSize,
     65      gfx::ChromaSubsampling aChromaSubsampling,
     66      gfx::YUVColorSpace aYUVColorSpace,
     67      gfx::TransferFunction aTransferFunction, gfx::ColorRange aColorRange,
     68      gfx::ColorDepth aColorDepth);
     69 
     70 private:
     71  ~MacIOSurfaceRecycleAllocator() = default;
     72 
     73  nsTArray<CFTypeRefPtr<IOSurfaceRef>> mSurfaces;
     74 
     75  // Cached parameters used for allocations stored in mSurfaces.
     76  gfx::IntSize mYSize;
     77  gfx::IntSize mCbCrSize;
     78  gfx::ChromaSubsampling mChromaSubsampling = gfx::ChromaSubsampling::FULL;
     79  gfx::YUVColorSpace mYUVColorSpace = gfx::YUVColorSpace::BT709;
     80  gfx::TransferFunction mTransferFunction = gfx::TransferFunction::BT709;
     81  gfx::ColorRange mColorRange = gfx::ColorRange::FULL;
     82  gfx::ColorDepth mColorDepth = gfx::ColorDepth::COLOR_8;
     83 };
     84 
     85 }  // namespace layers
     86 }  // namespace mozilla
     87 
     88 #endif  // GFX_SHAREDTEXTUREIMAGE_H