Source code

Revision control

Other Tools

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