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 "SourceSurfaceVolatileData.h"
9 #include "gfxAlphaRecovery.h"
10 #include "mozilla/Likely.h"
11 #include "mozilla/Types.h" // for decltype
16 bool SourceSurfaceVolatileData::Init(const IntSize
& aSize
, int32_t aStride
,
17 SurfaceFormat aFormat
) {
22 size_t alignment
= size_t(1) << gfxAlphaRecovery::GoodAlignmentLog2();
23 mVBuf
= new VolatileBuffer();
24 if (MOZ_UNLIKELY(!mVBuf
->Init(aStride
* aSize
.height
, alignment
))) {
32 void SourceSurfaceVolatileData::GuaranteePersistance() {
33 MOZ_ASSERT_UNREACHABLE("Should use SourceSurfaceRawData wrapper!");
36 void SourceSurfaceVolatileData::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
,
37 SizeOfInfo
& aInfo
) const {
38 aInfo
.AddType(SurfaceType::DATA
);
40 aInfo
.mHeapBytes
= mVBuf
->HeapSizeOfExcludingThis(aMallocSizeOf
);
41 aInfo
.mNonHeapBytes
= mVBuf
->NonHeapSizeOfExcludingThis();
43 if (!mVBuf
->OnHeap()) {
44 // Volatile buffers keep a file handle open on Android.
45 aInfo
.mExternalHandles
= 1;
52 } // namespace mozilla