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 | // Copyright (c) 2006-2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // |
michael@0 | 3 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 4 | // modification, are permitted provided that the following conditions |
michael@0 | 5 | // are met: |
michael@0 | 6 | // * Redistributions of source code must retain the above copyright |
michael@0 | 7 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 8 | // * Redistributions in binary form must reproduce the above copyright |
michael@0 | 9 | // notice, this list of conditions and the following disclaimer in |
michael@0 | 10 | // the documentation and/or other materials provided with the |
michael@0 | 11 | // distribution. |
michael@0 | 12 | // * Neither the name of Google, Inc. nor the names of its contributors |
michael@0 | 13 | // may be used to endorse or promote products derived from this |
michael@0 | 14 | // software without specific prior written permission. |
michael@0 | 15 | // |
michael@0 | 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
michael@0 | 19 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
michael@0 | 20 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
michael@0 | 21 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
michael@0 | 22 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
michael@0 | 23 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
michael@0 | 24 | // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@0 | 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@0 | 26 | // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@0 | 27 | // SUCH DAMAGE. |
michael@0 | 28 | |
michael@0 | 29 | #ifndef SKIA_EXT_IMAGE_OPERATIONS_H_ |
michael@0 | 30 | #define SKIA_EXT_IMAGE_OPERATIONS_H_ |
michael@0 | 31 | |
michael@0 | 32 | #include "skia/SkTypes.h" |
michael@0 | 33 | #include "Types.h" |
michael@0 | 34 | |
michael@0 | 35 | class SkBitmap; |
michael@0 | 36 | struct SkIRect; |
michael@0 | 37 | |
michael@0 | 38 | namespace skia { |
michael@0 | 39 | |
michael@0 | 40 | class ImageOperations { |
michael@0 | 41 | public: |
michael@0 | 42 | enum ResizeMethod { |
michael@0 | 43 | // |
michael@0 | 44 | // Quality Methods |
michael@0 | 45 | // |
michael@0 | 46 | // Those enumeration values express a desired quality/speed tradeoff. |
michael@0 | 47 | // They are translated into an algorithm-specific method that depends |
michael@0 | 48 | // on the capabilities (CPU, GPU) of the underlying platform. |
michael@0 | 49 | // It is possible for all three methods to be mapped to the same |
michael@0 | 50 | // algorithm on a given platform. |
michael@0 | 51 | |
michael@0 | 52 | // Good quality resizing. Fastest resizing with acceptable visual quality. |
michael@0 | 53 | // This is typically intended for use during interactive layouts |
michael@0 | 54 | // where slower platforms may want to trade image quality for large |
michael@0 | 55 | // increase in resizing performance. |
michael@0 | 56 | // |
michael@0 | 57 | // For example the resizing implementation may devolve to linear |
michael@0 | 58 | // filtering if this enables GPU acceleration to be used. |
michael@0 | 59 | // |
michael@0 | 60 | // Note that the underlying resizing method may be determined |
michael@0 | 61 | // on the fly based on the parameters for a given resize call. |
michael@0 | 62 | // For example an implementation using a GPU-based linear filter |
michael@0 | 63 | // in the common case may still use a higher-quality software-based |
michael@0 | 64 | // filter in cases where using the GPU would actually be slower - due |
michael@0 | 65 | // to too much latency - or impossible - due to image format or size |
michael@0 | 66 | // constraints. |
michael@0 | 67 | RESIZE_GOOD, |
michael@0 | 68 | |
michael@0 | 69 | // Medium quality resizing. Close to high quality resizing (better |
michael@0 | 70 | // than linear interpolation) with potentially some quality being |
michael@0 | 71 | // traded-off for additional speed compared to RESIZE_BEST. |
michael@0 | 72 | // |
michael@0 | 73 | // This is intended, for example, for generation of large thumbnails |
michael@0 | 74 | // (hundreds of pixels in each dimension) from large sources, where |
michael@0 | 75 | // a linear filter would produce too many artifacts but where |
michael@0 | 76 | // a RESIZE_HIGH might be too costly time-wise. |
michael@0 | 77 | RESIZE_BETTER, |
michael@0 | 78 | |
michael@0 | 79 | // High quality resizing. The algorithm is picked to favor image quality. |
michael@0 | 80 | RESIZE_BEST, |
michael@0 | 81 | |
michael@0 | 82 | // |
michael@0 | 83 | // Algorithm-specific enumerations |
michael@0 | 84 | // |
michael@0 | 85 | |
michael@0 | 86 | // Box filter. This is a weighted average of all of the pixels touching |
michael@0 | 87 | // the destination pixel. For enlargement, this is nearest neighbor. |
michael@0 | 88 | // |
michael@0 | 89 | // You probably don't want this, it is here for testing since it is easy to |
michael@0 | 90 | // compute. Use RESIZE_LANCZOS3 instead. |
michael@0 | 91 | RESIZE_BOX, |
michael@0 | 92 | |
michael@0 | 93 | // 1-cycle Hamming filter. This is tall is the middle and falls off towards |
michael@0 | 94 | // the window edges but without going to 0. This is about 40% faster than |
michael@0 | 95 | // a 2-cycle Lanczos. |
michael@0 | 96 | RESIZE_HAMMING1, |
michael@0 | 97 | |
michael@0 | 98 | // 2-cycle Lanczos filter. This is tall in the middle, goes negative on |
michael@0 | 99 | // each side, then returns to zero. Does not provide as good a frequency |
michael@0 | 100 | // response as a 3-cycle Lanczos but is roughly 30% faster. |
michael@0 | 101 | RESIZE_LANCZOS2, |
michael@0 | 102 | |
michael@0 | 103 | // 3-cycle Lanczos filter. This is tall in the middle, goes negative on |
michael@0 | 104 | // each side, then oscillates 2 more times. It gives nice sharp edges. |
michael@0 | 105 | RESIZE_LANCZOS3, |
michael@0 | 106 | |
michael@0 | 107 | // Lanczos filter + subpixel interpolation. If subpixel rendering is not |
michael@0 | 108 | // appropriate we automatically fall back to Lanczos. |
michael@0 | 109 | RESIZE_SUBPIXEL, |
michael@0 | 110 | |
michael@0 | 111 | // enum aliases for first and last methods by algorithm or by quality. |
michael@0 | 112 | RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD, |
michael@0 | 113 | RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST, |
michael@0 | 114 | RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX, |
michael@0 | 115 | RESIZE_LAST_ALGORITHM_METHOD = RESIZE_SUBPIXEL, |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | // Resizes the given source bitmap using the specified resize method, so that |
michael@0 | 119 | // the entire image is (dest_size) big. The dest_subset is the rectangle in |
michael@0 | 120 | // this destination image that should actually be returned. |
michael@0 | 121 | // |
michael@0 | 122 | // The output image will be (dest_subset.width(), dest_subset.height()). This |
michael@0 | 123 | // will save work if you do not need the entire bitmap. |
michael@0 | 124 | // |
michael@0 | 125 | // The destination subset must be smaller than the destination image. |
michael@0 | 126 | static SkBitmap Resize(const SkBitmap& source, |
michael@0 | 127 | ResizeMethod method, |
michael@0 | 128 | int dest_width, int dest_height, |
michael@0 | 129 | const SkIRect& dest_subset, |
michael@0 | 130 | void* dest_pixels = nullptr); |
michael@0 | 131 | |
michael@0 | 132 | // Alternate version for resizing and returning the entire bitmap rather than |
michael@0 | 133 | // a subset. |
michael@0 | 134 | static SkBitmap Resize(const SkBitmap& source, |
michael@0 | 135 | ResizeMethod method, |
michael@0 | 136 | int dest_width, int dest_height, |
michael@0 | 137 | void* dest_pixels = nullptr); |
michael@0 | 138 | |
michael@0 | 139 | private: |
michael@0 | 140 | ImageOperations(); // Class for scoping only. |
michael@0 | 141 | |
michael@0 | 142 | // Supports all methods except RESIZE_SUBPIXEL. |
michael@0 | 143 | static SkBitmap ResizeBasic(const SkBitmap& source, |
michael@0 | 144 | ResizeMethod method, |
michael@0 | 145 | int dest_width, int dest_height, |
michael@0 | 146 | const SkIRect& dest_subset, |
michael@0 | 147 | void* dest_pixels = nullptr); |
michael@0 | 148 | |
michael@0 | 149 | // Subpixel renderer. |
michael@0 | 150 | static SkBitmap ResizeSubpixel(const SkBitmap& source, |
michael@0 | 151 | int dest_width, int dest_height, |
michael@0 | 152 | const SkIRect& dest_subset); |
michael@0 | 153 | }; |
michael@0 | 154 | |
michael@0 | 155 | } // namespace skia |
michael@0 | 156 | |
michael@0 | 157 | #endif // SKIA_EXT_IMAGE_OPERATIONS_H_ |