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.

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

mercurial