michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "SourceSurfaceRawData.h" michael@0: michael@0: #include "DataSurfaceHelpers.h" michael@0: #include "Logging.h" michael@0: #include "mozilla/Types.h" // for decltype michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: bool michael@0: SourceSurfaceRawData::InitWrappingData(uint8_t *aData, michael@0: const IntSize &aSize, michael@0: int32_t aStride, michael@0: SurfaceFormat aFormat, michael@0: bool aOwnData) michael@0: { michael@0: mRawData = aData; michael@0: mSize = aSize; michael@0: mStride = aStride; michael@0: mFormat = aFormat; michael@0: mOwnData = aOwnData; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SourceSurfaceAlignedRawData::Init(const IntSize &aSize, michael@0: SurfaceFormat aFormat) michael@0: { michael@0: mFormat = aFormat; michael@0: mStride = GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat)); michael@0: michael@0: size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height); michael@0: if (bufLen > 0) { michael@0: static_assert(sizeof(decltype(mArray[0])) == 1, michael@0: "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen"); michael@0: mArray.Realloc(/* actually an object count */ bufLen); michael@0: mSize = aSize; michael@0: } else { michael@0: mArray.Dealloc(); michael@0: mSize.SizeTo(0, 0); michael@0: } michael@0: michael@0: return mArray != nullptr; michael@0: } michael@0: michael@0: bool michael@0: SourceSurfaceAlignedRawData::InitWithStride(const IntSize &aSize, michael@0: SurfaceFormat aFormat, michael@0: int32_t aStride) michael@0: { michael@0: mFormat = aFormat; michael@0: mStride = aStride; michael@0: michael@0: size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height); michael@0: if (bufLen > 0) { michael@0: static_assert(sizeof(decltype(mArray[0])) == 1, michael@0: "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen"); michael@0: mArray.Realloc(/* actually an object count */ bufLen); michael@0: mSize = aSize; michael@0: } else { michael@0: mArray.Dealloc(); michael@0: mSize.SizeTo(0, 0); michael@0: } michael@0: michael@0: return mArray != nullptr; michael@0: } michael@0: michael@0: } michael@0: }