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