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