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/. */ 6 7 #include "SourceSurfaceVolatileData.h" 8 9 #include "gfxAlphaRecovery.h" 10 #include "mozilla/Likely.h" 11 #include "mozilla/Types.h" // for decltype 12 13 namespace mozilla { 14 namespace gfx { 15 Init(const IntSize & aSize,int32_t aStride,SurfaceFormat aFormat)16bool SourceSurfaceVolatileData::Init(const IntSize& aSize, int32_t aStride, 17 SurfaceFormat aFormat) { 18 mSize = aSize; 19 mStride = aStride; 20 mFormat = aFormat; 21 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; 27 } 28 29 return true; 30 } 31 GuaranteePersistance()32void SourceSurfaceVolatileData::GuaranteePersistance() { 33 MOZ_ASSERT_UNREACHABLE("Should use SourceSurfaceRawData wrapper!"); 34 } 35 SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,SizeOfInfo & aInfo) const36void 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; 46 } 47 #endif 48 } 49 } 50 51 } // namespace gfx 52 } // namespace mozilla 53