gfx/2d/SourceSurfaceRawData.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

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

mercurial