Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / SourceSurfaceVolatileData.cpp
blobe555b53deb4d3a60f842a156aa74e2512bc4ea5a
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
13 namespace mozilla {
14 namespace gfx {
16 bool SourceSurfaceVolatileData::Init(const IntSize& aSize, int32_t aStride,
17 SurfaceFormat aFormat) {
18 mSize = aSize;
19 mStride = aStride;
20 mFormat = aFormat;
22 size_t alignment = size_t(1) << gfxAlphaRecovery::GoodAlignmentLog2();
23 mVBuf = new VolatileBuffer();
24 if (MOZ_UNLIKELY(!mVBuf->Init(aStride * aSize.height, alignment))) {
25 mVBuf = nullptr;
26 return false;
29 return true;
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);
39 if (mVBuf) {
40 aInfo.mHeapBytes = mVBuf->HeapSizeOfExcludingThis(aMallocSizeOf);
41 aInfo.mNonHeapBytes = mVBuf->NonHeapSizeOfExcludingThis();
42 #ifdef ANDROID
43 if (!mVBuf->OnHeap()) {
44 // Volatile buffers keep a file handle open on Android.
45 aInfo.mExternalHandles = 1;
47 #endif
51 } // namespace gfx
52 } // namespace mozilla