Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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/. */
6 #include "SourceSurfaceRawData.h"
8 #include "DataSurfaceHelpers.h"
9 #include "Logging.h"
10 #include "mozilla/Types.h" // for decltype
12 namespace mozilla {
13 namespace gfx {
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;
28 return true;
29 }
31 bool
32 SourceSurfaceAlignedRawData::Init(const IntSize &aSize,
33 SurfaceFormat aFormat)
34 {
35 mFormat = aFormat;
36 mStride = GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat));
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 }
49 return mArray != nullptr;
50 }
52 bool
53 SourceSurfaceAlignedRawData::InitWithStride(const IntSize &aSize,
54 SurfaceFormat aFormat,
55 int32_t aStride)
56 {
57 mFormat = aFormat;
58 mStride = aStride;
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 }
71 return mArray != nullptr;
72 }
74 }
75 }