gfx/2d/SourceSurfaceRawData.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:660dc7d4cc01
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "SourceSurfaceRawData.h"
7
8 #include "DataSurfaceHelpers.h"
9 #include "Logging.h"
10 #include "mozilla/Types.h" // for decltype
11
12 namespace mozilla {
13 namespace gfx {
14
15 bool
16 SourceSurfaceRawData::InitWrappingData(uint8_t *aData,
17 const IntSize &aSize,
18 int32_t aStride,
19 SurfaceFormat aFormat,
20 bool aOwnData)
21 {
22 mRawData = aData;
23 mSize = aSize;
24 mStride = aStride;
25 mFormat = aFormat;
26 mOwnData = aOwnData;
27
28 return true;
29 }
30
31 bool
32 SourceSurfaceAlignedRawData::Init(const IntSize &aSize,
33 SurfaceFormat aFormat)
34 {
35 mFormat = aFormat;
36 mStride = GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat));
37
38 size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
39 if (bufLen > 0) {
40 static_assert(sizeof(decltype(mArray[0])) == 1,
41 "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen");
42 mArray.Realloc(/* actually an object count */ bufLen);
43 mSize = aSize;
44 } else {
45 mArray.Dealloc();
46 mSize.SizeTo(0, 0);
47 }
48
49 return mArray != nullptr;
50 }
51
52 bool
53 SourceSurfaceAlignedRawData::InitWithStride(const IntSize &aSize,
54 SurfaceFormat aFormat,
55 int32_t aStride)
56 {
57 mFormat = aFormat;
58 mStride = aStride;
59
60 size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
61 if (bufLen > 0) {
62 static_assert(sizeof(decltype(mArray[0])) == 1,
63 "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen");
64 mArray.Realloc(/* actually an object count */ bufLen);
65 mSize = aSize;
66 } else {
67 mArray.Dealloc();
68 mSize.SizeTo(0, 0);
69 }
70
71 return mArray != nullptr;
72 }
73
74 }
75 }

mercurial