gfx/2d/SourceSurfaceRawData.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/SourceSurfaceRawData.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "SourceSurfaceRawData.h"
    1.10 +
    1.11 +#include "DataSurfaceHelpers.h"
    1.12 +#include "Logging.h"
    1.13 +#include "mozilla/Types.h" // for decltype
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace gfx {
    1.17 +
    1.18 +bool
    1.19 +SourceSurfaceRawData::InitWrappingData(uint8_t *aData,
    1.20 +                                       const IntSize &aSize,
    1.21 +                                       int32_t aStride,
    1.22 +                                       SurfaceFormat aFormat,
    1.23 +                                       bool aOwnData)
    1.24 +{
    1.25 +  mRawData = aData;
    1.26 +  mSize = aSize;
    1.27 +  mStride = aStride;
    1.28 +  mFormat = aFormat;
    1.29 +  mOwnData = aOwnData;
    1.30 +
    1.31 +  return true;
    1.32 +}
    1.33 +
    1.34 +bool
    1.35 +SourceSurfaceAlignedRawData::Init(const IntSize &aSize,
    1.36 +                                  SurfaceFormat aFormat)
    1.37 +{
    1.38 +  mFormat = aFormat;
    1.39 +  mStride = GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat));
    1.40 +
    1.41 +  size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
    1.42 +  if (bufLen > 0) {
    1.43 +    static_assert(sizeof(decltype(mArray[0])) == 1,
    1.44 +                  "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen");
    1.45 +    mArray.Realloc(/* actually an object count */ bufLen);
    1.46 +    mSize = aSize;
    1.47 +  } else {
    1.48 +    mArray.Dealloc();
    1.49 +    mSize.SizeTo(0, 0);
    1.50 +  }
    1.51 +
    1.52 +  return mArray != nullptr;
    1.53 +}
    1.54 +
    1.55 +bool
    1.56 +SourceSurfaceAlignedRawData::InitWithStride(const IntSize &aSize,
    1.57 +                                            SurfaceFormat aFormat,
    1.58 +                                            int32_t aStride)
    1.59 +{
    1.60 +  mFormat = aFormat;
    1.61 +  mStride = aStride;
    1.62 +
    1.63 +  size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
    1.64 +  if (bufLen > 0) {
    1.65 +    static_assert(sizeof(decltype(mArray[0])) == 1,
    1.66 +                  "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen");
    1.67 +    mArray.Realloc(/* actually an object count */ bufLen);
    1.68 +    mSize = aSize;
    1.69 +  } else {
    1.70 +    mArray.Dealloc();
    1.71 +    mSize.SizeTo(0, 0);
    1.72 +  }
    1.73 +
    1.74 +  return mArray != nullptr;
    1.75 +}
    1.76 +
    1.77 +}
    1.78 +}

mercurial