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_GFX_SOURCESURFACERAWDATA_H_
8 #define MOZILLA_GFX_SOURCESURFACERAWDATA_H_
12 #include "mozilla/Atomics.h"
17 class SourceSurfaceMappedData final
: public DataSourceSurface
{
19 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceMappedData
, final
)
21 SourceSurfaceMappedData(ScopedMap
&& aMap
, const IntSize
& aSize
,
22 SurfaceFormat aFormat
)
23 : mMap(std::move(aMap
)), mSize(aSize
), mFormat(aFormat
) {}
25 ~SourceSurfaceMappedData() final
= default;
27 uint8_t* GetData() final
{ return mMap
.GetData(); }
28 int32_t Stride() final
{ return mMap
.GetStride(); }
30 SurfaceType
GetType() const final
{ return SurfaceType::DATA_MAPPED
; }
31 IntSize
GetSize() const final
{ return mSize
; }
32 SurfaceFormat
GetFormat() const final
{ return mFormat
; }
34 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
,
35 SizeOfInfo
& aInfo
) const override
{
36 aInfo
.AddType(SurfaceType::DATA_MAPPED
);
37 mMap
.GetSurface()->SizeOfExcludingThis(aMallocSizeOf
, aInfo
);
40 const DataSourceSurface
* GetScopedSurface() const {
41 return mMap
.GetSurface();
47 SurfaceFormat mFormat
;
50 class SourceSurfaceRawData
: public DataSourceSurface
{
52 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceRawData
, override
)
54 SourceSurfaceRawData()
57 mFormat(SurfaceFormat::UNKNOWN
),
58 mDeallocator(nullptr),
61 virtual ~SourceSurfaceRawData() {
63 mDeallocator(mClosure
);
67 virtual uint8_t* GetData() override
{ return mRawData
; }
68 virtual int32_t Stride() override
{ return mStride
; }
70 virtual SurfaceType
GetType() const override
{ return SurfaceType::DATA
; }
71 virtual IntSize
GetSize() const override
{ return mSize
; }
72 virtual SurfaceFormat
GetFormat() const override
{ return mFormat
; }
74 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
,
75 SizeOfInfo
& aInfo
) const override
;
80 // If we have a custom deallocator, the |aData| will be released using the
81 // custom deallocator and |aClosure| in dtor. The assumption is that the
82 // caller will check for valid size and stride before making this call.
83 void InitWrappingData(unsigned char* aData
, const IntSize
& aSize
,
84 int32_t aStride
, SurfaceFormat aFormat
,
85 Factory::SourceSurfaceDeallocator aDeallocator
,
90 SurfaceFormat mFormat
;
93 Factory::SourceSurfaceDeallocator mDeallocator
;
97 class SourceSurfaceAlignedRawData
: public DataSourceSurface
{
99 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceAlignedRawData
,
101 SourceSurfaceAlignedRawData() : mStride(0), mFormat(SurfaceFormat::UNKNOWN
) {}
102 ~SourceSurfaceAlignedRawData() override
= default;
104 bool Init(const IntSize
& aSize
, SurfaceFormat aFormat
, bool aClearMem
,
105 uint8_t aClearValue
, int32_t aStride
= 0);
107 uint8_t* GetData() override
{ return mArray
; }
108 int32_t Stride() override
{ return mStride
; }
110 SurfaceType
GetType() const override
{ return SurfaceType::DATA_ALIGNED
; }
111 IntSize
GetSize() const override
{ return mSize
; }
112 SurfaceFormat
GetFormat() const override
{ return mFormat
; }
114 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
,
115 SizeOfInfo
& aInfo
) const override
;
118 friend class Factory
;
120 AlignedArray
<uint8_t> mArray
;
122 SurfaceFormat mFormat
;
127 } // namespace mozilla
129 #endif /* MOZILLA_GFX_SOURCESURFACERAWDATA_H_ */