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