Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / 2d / SourceSurfaceRawData.cpp
blobd5590e329c73cf1aee27e2ca98ce200f17bb985e
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"
10 #include "Logging.h"
11 #include "mozilla/Types.h" // for decltype
13 namespace mozilla {
14 namespace gfx {
16 void SourceSurfaceRawData::InitWrappingData(
17 uint8_t* aData, const IntSize& aSize, int32_t aStride,
18 SurfaceFormat aFormat, Factory::SourceSurfaceDeallocator aDeallocator,
19 void* aClosure) {
20 mRawData = aData;
21 mSize = aSize;
22 mStride = aStride;
23 mFormat = aFormat;
24 mDeallocator = aDeallocator;
25 mClosure = aClosure;
28 void SourceSurfaceRawData::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
29 SizeOfInfo& aInfo) const {
30 aInfo.AddType(SurfaceType::DATA);
31 if (mDeallocator) {
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) {
39 mFormat = aFormat;
40 mStride = aStride ? aStride
41 : GetAlignedStride<16>(aSize.width, BytesPerPixel(aFormat));
43 size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
44 if (bufLen > 0) {
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);
52 mSize = aSize;
54 if (mArray && aClearMem && aClearValue) {
55 memset(mArray, aClearValue, mStride * aSize.height);
57 } else {
58 mArray.Dealloc();
59 mSize.SizeTo(0, 0);
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);
71 } // namespace gfx
72 } // namespace mozilla