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/. */
7 #ifndef GFX_MACIOSURFACEIMAGE_H
8 #define GFX_MACIOSURFACEIMAGE_H
10 #include "ImageContainer.h"
11 #include "mozilla/gfx/MacIOSurface.h"
12 #include "mozilla/gfx/Point.h"
13 #include "mozilla/layers/TextureClient.h"
19 class MacIOSurfaceImage
: public Image
{
21 explicit MacIOSurfaceImage(MacIOSurface
* aSurface
)
22 : Image(nullptr, ImageFormat::MAC_IOSURFACE
), mSurface(aSurface
) {
24 mPictureRect
= gfx::IntRect(
25 gfx::IntPoint
{}, gfx::IntSize(aSurface
->GetDevicePixelWidth(0),
26 aSurface
->GetDevicePixelHeight(0)));
30 bool SetData(ImageContainer
* aContainer
, const PlanarYCbCrData
& aData
);
32 MacIOSurface
* GetSurface() { return mSurface
; }
34 gfx::IntSize
GetSize() const override
{
35 return gfx::IntSize::Truncate(mSurface
->GetDevicePixelWidth(),
36 mSurface
->GetDevicePixelHeight());
39 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
;
41 nsresult
BuildSurfaceDescriptorBuffer(
42 SurfaceDescriptorBuffer
& aSdBuffer
, BuildSdbFlags aFlags
,
43 const std::function
<MemoryOrShmem(uint32_t)>& aAllocate
) override
;
45 TextureClient
* GetTextureClient(KnowsCompositor
* aKnowsCompositor
) override
;
47 MacIOSurfaceImage
* AsMacIOSurfaceImage() override
{ return this; }
49 gfx::IntRect
GetPictureRect() const override
{ return mPictureRect
; }
51 gfx::ColorDepth
GetColorDepth() const override
;
54 RefPtr
<MacIOSurface
> mSurface
;
55 RefPtr
<TextureClient
> mTextureClient
;
56 gfx::IntRect mPictureRect
;
59 class MacIOSurfaceRecycleAllocator
{
61 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MacIOSurfaceRecycleAllocator
)
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
);
71 ~MacIOSurfaceRecycleAllocator() = default;
73 nsTArray
<CFTypeRefPtr
<IOSurfaceRef
>> mSurfaces
;
75 // Cached parameters used for allocations stored in mSurfaces.
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
;
86 } // namespace mozilla
88 #endif // GFX_SHAREDTEXTUREIMAGE_H