gfx/2d/Scale.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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "Scale.h"
     7 #ifdef USE_SKIA
     8 #include "HelpersSkia.h"
     9 #include "skia/SkBitmap.h"
    10 #include "image_operations.h"
    11 #endif
    13 namespace mozilla {
    14 namespace gfx {
    16 bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride,
    17            uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride,
    18            SurfaceFormat format)
    19 {
    20 #ifdef USE_SKIA
    21   SkAlphaType alphaType;
    22   if (format == SurfaceFormat::B8G8R8A8) {
    23     alphaType = kPremul_SkAlphaType;
    24   } else {
    25     alphaType = kOpaque_SkAlphaType;
    26   }
    28   SkBitmap::Config config = GfxFormatToSkiaConfig(format);
    30   SkBitmap imgSrc;
    31   imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType);
    32   imgSrc.setPixels(srcData);
    34   // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed.
    35   if (config != SkBitmap::kARGB_8888_Config) {
    36     imgSrc.copyTo(&imgSrc, kRGBA_8888_SkColorType);
    37   }
    39   // This returns an SkBitmap backed by dstData; since it also wrote to dstData,
    40   // we don't need to look at that SkBitmap.
    41   SkBitmap result = skia::ImageOperations::Resize(imgSrc,
    42                                                   skia::ImageOperations::RESIZE_BEST,
    43                                                   dstWidth, dstHeight,
    44                                                   dstData);
    46   return !result.isNull();
    47 #else
    48   return false;
    49 #endif
    50 }
    52 }
    53 }

mercurial