gfx/2d/ImageScaling.h

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 #ifndef _MOZILLA_GFX_IMAGESCALING_H
michael@0 7 #define _MOZILLA_GFX_IMAGESCALING_H
michael@0 8
michael@0 9 #include "Types.h"
michael@0 10
michael@0 11 #include <vector>
michael@0 12 #include "Point.h"
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15 namespace gfx {
michael@0 16
michael@0 17 class ImageHalfScaler
michael@0 18 {
michael@0 19 public:
michael@0 20 ImageHalfScaler(uint8_t *aData, int32_t aStride, const IntSize &aSize)
michael@0 21 : mOrigData(aData), mOrigStride(aStride), mOrigSize(aSize)
michael@0 22 , mDataStorage(nullptr)
michael@0 23 {
michael@0 24 }
michael@0 25
michael@0 26 ~ImageHalfScaler()
michael@0 27 {
michael@0 28 delete [] mDataStorage;
michael@0 29 }
michael@0 30
michael@0 31 void ScaleForSize(const IntSize &aSize);
michael@0 32
michael@0 33 uint8_t *GetScaledData() const { return mData; }
michael@0 34 IntSize GetSize() const { return mSize; }
michael@0 35 uint32_t GetStride() const { return mStride; }
michael@0 36
michael@0 37 private:
michael@0 38 void HalfImage2D(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 39 uint8_t *aDest, uint32_t aDestStride);
michael@0 40 void HalfImageVertical(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 41 uint8_t *aDest, uint32_t aDestStride);
michael@0 42 void HalfImageHorizontal(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 43 uint8_t *aDest, uint32_t aDestStride);
michael@0 44
michael@0 45 // This is our SSE2 scaling function. Our destination must always be 16-byte
michael@0 46 // aligned and use a 16-byte aligned stride.
michael@0 47 void HalfImage2D_SSE2(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 48 uint8_t *aDest, uint32_t aDestStride);
michael@0 49 void HalfImageVertical_SSE2(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 50 uint8_t *aDest, uint32_t aDestStride);
michael@0 51 void HalfImageHorizontal_SSE2(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 52 uint8_t *aDest, uint32_t aDestStride);
michael@0 53
michael@0 54 void HalfImage2D_C(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 55 uint8_t *aDest, uint32_t aDestStride);
michael@0 56 void HalfImageVertical_C(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 57 uint8_t *aDest, uint32_t aDestStride);
michael@0 58 void HalfImageHorizontal_C(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
michael@0 59 uint8_t *aDest, uint32_t aDestStride);
michael@0 60
michael@0 61 uint8_t *mOrigData;
michael@0 62 int32_t mOrigStride;
michael@0 63 IntSize mOrigSize;
michael@0 64
michael@0 65 uint8_t *mDataStorage;
michael@0 66 // Guaranteed 16-byte aligned
michael@0 67 uint8_t *mData;
michael@0 68 IntSize mSize;
michael@0 69 // Guaranteed 16-byte aligned
michael@0 70 uint32_t mStride;
michael@0 71 };
michael@0 72
michael@0 73 }
michael@0 74 }
michael@0 75
michael@0 76 #endif

mercurial