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 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
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 "gfx2DGlue.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "YCbCrUtils.h" |
michael@0 | 9 | #include "yuv_convert.h" |
michael@0 | 10 | #include "ycbcr_to_rgb565.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | namespace gfx { |
michael@0 | 14 | |
michael@0 | 15 | void |
michael@0 | 16 | GetYCbCrToRGBDestFormatAndSize(const layers::PlanarYCbCrData& aData, |
michael@0 | 17 | SurfaceFormat& aSuggestedFormat, |
michael@0 | 18 | IntSize& aSuggestedSize) |
michael@0 | 19 | { |
michael@0 | 20 | YUVType yuvtype = |
michael@0 | 21 | TypeFromSize(aData.mYSize.width, |
michael@0 | 22 | aData.mYSize.height, |
michael@0 | 23 | aData.mCbCrSize.width, |
michael@0 | 24 | aData.mCbCrSize.height); |
michael@0 | 25 | |
michael@0 | 26 | // 'prescale' is true if the scaling is to be done as part of the |
michael@0 | 27 | // YCbCr to RGB conversion rather than on the RGB data when rendered. |
michael@0 | 28 | bool prescale = aSuggestedSize.width > 0 && aSuggestedSize.height > 0 && |
michael@0 | 29 | aSuggestedSize != aData.mPicSize; |
michael@0 | 30 | |
michael@0 | 31 | if (aSuggestedFormat == SurfaceFormat::R5G6B5) { |
michael@0 | 32 | #if defined(HAVE_YCBCR_TO_RGB565) |
michael@0 | 33 | if (prescale && |
michael@0 | 34 | !IsScaleYCbCrToRGB565Fast(aData.mPicX, |
michael@0 | 35 | aData.mPicY, |
michael@0 | 36 | aData.mPicSize.width, |
michael@0 | 37 | aData.mPicSize.height, |
michael@0 | 38 | aSuggestedSize.width, |
michael@0 | 39 | aSuggestedSize.height, |
michael@0 | 40 | yuvtype, |
michael@0 | 41 | FILTER_BILINEAR) && |
michael@0 | 42 | IsConvertYCbCrToRGB565Fast(aData.mPicX, |
michael@0 | 43 | aData.mPicY, |
michael@0 | 44 | aData.mPicSize.width, |
michael@0 | 45 | aData.mPicSize.height, |
michael@0 | 46 | yuvtype)) { |
michael@0 | 47 | prescale = false; |
michael@0 | 48 | } |
michael@0 | 49 | #else |
michael@0 | 50 | // yuv2rgb16 function not available |
michael@0 | 51 | aSuggestedFormat = SurfaceFormat::B8G8R8X8; |
michael@0 | 52 | #endif |
michael@0 | 53 | } |
michael@0 | 54 | else if (aSuggestedFormat != SurfaceFormat::B8G8R8X8) { |
michael@0 | 55 | // No other formats are currently supported. |
michael@0 | 56 | aSuggestedFormat = SurfaceFormat::B8G8R8X8; |
michael@0 | 57 | } |
michael@0 | 58 | if (aSuggestedFormat == SurfaceFormat::B8G8R8X8) { |
michael@0 | 59 | /* ScaleYCbCrToRGB32 does not support a picture offset, nor 4:4:4 data. |
michael@0 | 60 | See bugs 639415 and 640073. */ |
michael@0 | 61 | if (aData.mPicX != 0 || aData.mPicY != 0 || yuvtype == YV24) |
michael@0 | 62 | prescale = false; |
michael@0 | 63 | } |
michael@0 | 64 | if (!prescale) { |
michael@0 | 65 | aSuggestedSize = aData.mPicSize; |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | void |
michael@0 | 70 | ConvertYCbCrToRGB(const layers::PlanarYCbCrData& aData, |
michael@0 | 71 | const SurfaceFormat& aDestFormat, |
michael@0 | 72 | const IntSize& aDestSize, |
michael@0 | 73 | unsigned char* aDestBuffer, |
michael@0 | 74 | int32_t aStride) |
michael@0 | 75 | { |
michael@0 | 76 | // ConvertYCbCrToRGB et al. assume the chroma planes are rounded up if the |
michael@0 | 77 | // luma plane is odd sized. |
michael@0 | 78 | MOZ_ASSERT((aData.mCbCrSize.width == aData.mYSize.width || |
michael@0 | 79 | aData.mCbCrSize.width == (aData.mYSize.width + 1) >> 1) && |
michael@0 | 80 | (aData.mCbCrSize.height == aData.mYSize.height || |
michael@0 | 81 | aData.mCbCrSize.height == (aData.mYSize.height + 1) >> 1)); |
michael@0 | 82 | YUVType yuvtype = |
michael@0 | 83 | TypeFromSize(aData.mYSize.width, |
michael@0 | 84 | aData.mYSize.height, |
michael@0 | 85 | aData.mCbCrSize.width, |
michael@0 | 86 | aData.mCbCrSize.height); |
michael@0 | 87 | |
michael@0 | 88 | // Convert from YCbCr to RGB now, scaling the image if needed. |
michael@0 | 89 | if (aDestSize != aData.mPicSize) { |
michael@0 | 90 | #if defined(HAVE_YCBCR_TO_RGB565) |
michael@0 | 91 | if (aDestFormat == SurfaceFormat::R5G6B5) { |
michael@0 | 92 | ScaleYCbCrToRGB565(aData.mYChannel, |
michael@0 | 93 | aData.mCbChannel, |
michael@0 | 94 | aData.mCrChannel, |
michael@0 | 95 | aDestBuffer, |
michael@0 | 96 | aData.mPicX, |
michael@0 | 97 | aData.mPicY, |
michael@0 | 98 | aData.mPicSize.width, |
michael@0 | 99 | aData.mPicSize.height, |
michael@0 | 100 | aDestSize.width, |
michael@0 | 101 | aDestSize.height, |
michael@0 | 102 | aData.mYStride, |
michael@0 | 103 | aData.mCbCrStride, |
michael@0 | 104 | aStride, |
michael@0 | 105 | yuvtype, |
michael@0 | 106 | FILTER_BILINEAR); |
michael@0 | 107 | } else |
michael@0 | 108 | #endif |
michael@0 | 109 | ScaleYCbCrToRGB32(aData.mYChannel, // |
michael@0 | 110 | aData.mCbChannel, |
michael@0 | 111 | aData.mCrChannel, |
michael@0 | 112 | aDestBuffer, |
michael@0 | 113 | aData.mPicSize.width, |
michael@0 | 114 | aData.mPicSize.height, |
michael@0 | 115 | aDestSize.width, |
michael@0 | 116 | aDestSize.height, |
michael@0 | 117 | aData.mYStride, |
michael@0 | 118 | aData.mCbCrStride, |
michael@0 | 119 | aStride, |
michael@0 | 120 | yuvtype, |
michael@0 | 121 | ROTATE_0, |
michael@0 | 122 | FILTER_BILINEAR); |
michael@0 | 123 | } else { // no prescale |
michael@0 | 124 | #if defined(HAVE_YCBCR_TO_RGB565) |
michael@0 | 125 | if (aDestFormat == SurfaceFormat::R5G6B5) { |
michael@0 | 126 | ConvertYCbCrToRGB565(aData.mYChannel, |
michael@0 | 127 | aData.mCbChannel, |
michael@0 | 128 | aData.mCrChannel, |
michael@0 | 129 | aDestBuffer, |
michael@0 | 130 | aData.mPicX, |
michael@0 | 131 | aData.mPicY, |
michael@0 | 132 | aData.mPicSize.width, |
michael@0 | 133 | aData.mPicSize.height, |
michael@0 | 134 | aData.mYStride, |
michael@0 | 135 | aData.mCbCrStride, |
michael@0 | 136 | aStride, |
michael@0 | 137 | yuvtype); |
michael@0 | 138 | } else // aDestFormat != gfxImageFormat::RGB16_565 |
michael@0 | 139 | #endif |
michael@0 | 140 | ConvertYCbCrToRGB32(aData.mYChannel, // |
michael@0 | 141 | aData.mCbChannel, |
michael@0 | 142 | aData.mCrChannel, |
michael@0 | 143 | aDestBuffer, |
michael@0 | 144 | aData.mPicX, |
michael@0 | 145 | aData.mPicY, |
michael@0 | 146 | aData.mPicSize.width, |
michael@0 | 147 | aData.mPicSize.height, |
michael@0 | 148 | aData.mYStride, |
michael@0 | 149 | aData.mCbCrStride, |
michael@0 | 150 | aStride, |
michael@0 | 151 | yuvtype); |
michael@0 | 152 | } |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | } |
michael@0 | 156 | } |