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 #include "SourceSurfaceRawData.h"
9 #include "DataSurfaceHelpers.h"
11 #include "mozilla/Types.h" // for decltype
16 void SourceSurfaceRawData::InitWrappingData(
17 uint8_t* aData
, const IntSize
& aSize
, int32_t aStride
,
18 SurfaceFormat aFormat
, Factory::SourceSurfaceDeallocator aDeallocator
,
24 mDeallocator
= aDeallocator
;
28 void SourceSurfaceRawData::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
,
29 SizeOfInfo
& aInfo
) const {
30 aInfo
.AddType(SurfaceType::DATA
);
32 aInfo
.mUnknownBytes
= mStride
* mSize
.height
;
36 bool SourceSurfaceAlignedRawData::Init(const IntSize
& aSize
,
37 SurfaceFormat aFormat
, bool aClearMem
,
38 uint8_t aClearValue
, int32_t aStride
) {
40 mStride
= aStride
? aStride
41 : GetAlignedStride
<16>(aSize
.width
, BytesPerPixel(aFormat
));
43 size_t bufLen
= BufferSizeFromStrideAndHeight(mStride
, aSize
.height
);
45 bool zeroMem
= aClearMem
&& !aClearValue
;
46 static_assert(sizeof(decltype(mArray
[0])) == 1,
47 "mArray.Realloc() takes an object count, so its objects must "
48 "be 1-byte sized if we use bufLen");
50 // AlignedArray uses cmalloc to zero mem for a fast path.
51 mArray
.Realloc(/* actually an object count */ bufLen
, zeroMem
);
54 if (mArray
&& aClearMem
&& aClearValue
) {
55 memset(mArray
, aClearValue
, mStride
* aSize
.height
);
62 return mArray
!= nullptr;
65 void SourceSurfaceAlignedRawData::SizeOfExcludingThis(
66 MallocSizeOf aMallocSizeOf
, SizeOfInfo
& aInfo
) const {
67 aInfo
.AddType(SurfaceType::DATA_ALIGNED
);
68 aInfo
.mHeapBytes
= mArray
.HeapSizeOfExcludingThis(aMallocSizeOf
);
72 } // namespace mozilla