Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: cc/tiles/image_decode_controller.h

Issue 1682803003: cc: ImageDecodes: handle low quality filters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove old code Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/tiles/image_decode_controller.cc » ('j') | cc/tiles/image_decode_controller.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_TILES_IMAGE_DECODE_CONTROLLER_H_ 5 #ifndef CC_TILES_IMAGE_DECODE_CONTROLLER_H_
6 #define CC_TILES_IMAGE_DECODE_CONTROLLER_H_ 6 #define CC_TILES_IMAGE_DECODE_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <unordered_map> 10 #include <unordered_map>
(...skipping 15 matching lines...) Expand all
26 26
27 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw 27 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw
28 // image. That is, this key uniquely identifies an image in the cache. Note that 28 // image. That is, this key uniquely identifies an image in the cache. Note that
29 // it's insufficient to use SkImage's unique id, since the same image can appear 29 // it's insufficient to use SkImage's unique id, since the same image can appear
30 // in the cache multiple times at different scales and filter qualities. 30 // in the cache multiple times at different scales and filter qualities.
31 class CC_EXPORT ImageDecodeControllerKey { 31 class CC_EXPORT ImageDecodeControllerKey {
32 public: 32 public:
33 static ImageDecodeControllerKey FromDrawImage(const DrawImage& image); 33 static ImageDecodeControllerKey FromDrawImage(const DrawImage& image);
34 34
35 bool operator==(const ImageDecodeControllerKey& other) const { 35 bool operator==(const ImageDecodeControllerKey& other) const {
36 return image_id_ == other.image_id_ && src_rect_ == other.src_rect_ && 36 // The image_id always has to be the same. However, after that all original
37 target_size_ == other.target_size_ && 37 // decodes are the same, so if we can use the original decode, return true.
38 filter_quality_ == other.filter_quality_; 38 // If not, then we have to compare every field.
39 return image_id_ == other.image_id_ &&
40 can_use_original_decode_ == other.can_use_original_decode_ &&
41 (can_use_original_decode_ ||
42 (src_rect_ == other.src_rect_ &&
43 target_size_ == other.target_size_ &&
44 filter_quality_ == other.filter_quality_));
39 } 45 }
40 46
41 bool operator!=(const ImageDecodeControllerKey& other) const { 47 bool operator!=(const ImageDecodeControllerKey& other) const {
42 return !(*this == other); 48 return !(*this == other);
43 } 49 }
44 50
45 uint32_t image_id() const { return image_id_; } 51 uint32_t image_id() const { return image_id_; }
46 SkFilterQuality filter_quality() const { return filter_quality_; } 52 SkFilterQuality filter_quality() const { return filter_quality_; }
47 gfx::Rect src_rect() const { return src_rect_; } 53 gfx::Rect src_rect() const { return src_rect_; }
48 gfx::Size target_size() const { return target_size_; } 54 gfx::Size target_size() const { return target_size_; }
49 55
50 // Helper to figure out how much memory this decoded and scaled image would 56 bool can_use_original_decode() const { return can_use_original_decode_; }
51 // take. 57 size_t get_hash() const { return hash_; }
52 size_t target_bytes() const { 58
59 // Helper to figure out how much memory the locked image represented by this
60 // key would take.
61 size_t locked_bytes() const {
53 // TODO(vmpstr): Handle formats other than RGBA. 62 // TODO(vmpstr): Handle formats other than RGBA.
54 base::CheckedNumeric<size_t> result = 4; 63 base::CheckedNumeric<size_t> result = 4;
55 result *= target_size_.width(); 64 if (can_use_original_decode()) {
56 result *= target_size_.height(); 65 result *= original_size_.width();
66 result *= original_size_.height();
67 } else {
68 result *= target_size_.width();
69 result *= target_size_.height();
70 }
57 return result.ValueOrDefault(std::numeric_limits<size_t>::max()); 71 return result.ValueOrDefault(std::numeric_limits<size_t>::max());
58 } 72 }
59 73
60 std::string ToString() const; 74 std::string ToString() const;
61 75
62 private: 76 private:
63 ImageDecodeControllerKey(uint32_t image_id, 77 ImageDecodeControllerKey(uint32_t image_id,
64 const gfx::Rect& src_rect, 78 const gfx::Rect& src_rect,
65 const gfx::Size& size, 79 const gfx::Size& size,
66 SkFilterQuality filter_quality); 80 SkFilterQuality filter_quality,
81 bool can_use_original_decode,
82 const gfx::Size& original_size);
67 83
68 uint32_t image_id_; 84 uint32_t image_id_;
69 gfx::Rect src_rect_; 85 gfx::Rect src_rect_;
70 gfx::Size target_size_; 86 gfx::Size target_size_;
71 SkFilterQuality filter_quality_; 87 SkFilterQuality filter_quality_;
88 bool can_use_original_decode_;
89 gfx::Size original_size_;
enne (OOO) 2016/02/11 00:06:06 I'm not sure I follow why you need two sizes here?
vmpstr 2016/02/11 00:23:46 Hmm.. I'm going to confirm, but yeah I think I can
90 size_t hash_;
72 }; 91 };
73 92
74 // Hash function for the above ImageDecodeControllerKey. 93 // Hash function for the above ImageDecodeControllerKey.
75 struct ImageDecodeControllerKeyHash { 94 struct ImageDecodeControllerKeyHash {
76 size_t operator()(const ImageDecodeControllerKey& key) const { 95 size_t operator()(const ImageDecodeControllerKey& key) const {
77 // TODO(vmpstr): This is a mess. Maybe it's faster to just search the vector 96 return key.get_hash();
78 // always (forwards or backwards to account for LRU).
79 uint64_t src_rect_hash =
80 base::HashInts(static_cast<uint64_t>(base::HashInts(
81 key.src_rect().x(), key.src_rect().y())),
82 static_cast<uint64_t>(base::HashInts(
83 key.src_rect().width(), key.src_rect().height())));
84
85 uint64_t target_size_hash =
86 base::HashInts(key.target_size().width(), key.target_size().height());
87
88 return base::HashInts(base::HashInts(src_rect_hash, target_size_hash),
89 base::HashInts(key.image_id(), key.filter_quality()));
90 } 97 }
91 }; 98 };
92 99
93 // ImageDecodeController is responsible for generating decode tasks, decoding 100 // ImageDecodeController is responsible for generating decode tasks, decoding
94 // images, storing images in cache, and being able to return the decoded images 101 // images, storing images in cache, and being able to return the decoded images
95 // when requested. 102 // when requested.
96 103
97 // ImageDecodeController is responsible for the following things: 104 // ImageDecodeController is responsible for the following things:
98 // 1. Given a DrawImage, it can return an ImageDecodeTask which when run will 105 // 1. Given a DrawImage, it can return an ImageDecodeTask which when run will
99 // decode and cache the resulting image. If the image does not need a task to 106 // decode and cache the resulting image. If the image does not need a task to
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 218
212 // Looks for the key in the cache and returns true if it was found and was 219 // Looks for the key in the cache and returns true if it was found and was
213 // successfully locked (or if it was already locked). Note that if this 220 // successfully locked (or if it was already locked). Note that if this
214 // function returns true, then a ref count is increased for the image. 221 // function returns true, then a ref count is increased for the image.
215 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); 222 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key);
216 223
217 // Actually decode the image. Note that this function can (and should) be 224 // Actually decode the image. Note that this function can (and should) be
218 // called with no lock acquired, since it can do a lot of work. Note that it 225 // called with no lock acquired, since it can do a lot of work. Note that it
219 // can also return nullptr to indicate the decode failed. 226 // can also return nullptr to indicate the decode failed.
220 scoped_refptr<DecodedImage> DecodeImageInternal(const ImageKey& key, 227 scoped_refptr<DecodedImage> DecodeImageInternal(const ImageKey& key,
221 const SkImage* image); 228 const DrawImage& draw_image);
229
230 // Get the decoded draw image for the given key and draw_image. Note that this
231 // function has to be called with no lock acquired, since it will acquire its
232 // own locks and might call DecodeImageInternal above. Also note that this
233 // function will use the provided key, even if
234 // ImageKey::FromDrawImage(draw_image) would return a different key.
235 // Note that when used internally, we still require that
236 // DrawWithImageFinished() is called afterwards.
237 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key,
238 const DrawImage& draw_image);
239
222 void SanityCheckState(int line, bool lock_acquired); 240 void SanityCheckState(int line, bool lock_acquired);
223 void RefImage(const ImageKey& key); 241 void RefImage(const ImageKey& key);
224 void RefAtRasterImage(const ImageKey& key); 242 void RefAtRasterImage(const ImageKey& key);
225 void UnrefAtRasterImage(const ImageKey& key); 243 void UnrefAtRasterImage(const ImageKey& key);
226 244
227 // These functions indicate whether the images can be handled and cached by 245 // These functions indicate whether the images can be handled and cached by
228 // ImageDecodeController or whether they will fall through to Skia (with 246 // ImageDecodeController or whether they will fall through to Skia (with
229 // exception of possibly prerolling them). Over time these should return 247 // exception of possibly prerolling them). Over time these should return
230 // "false" in less cases, as the ImageDecodeController should start handling 248 // "false" in less cases, as the ImageDecodeController should start handling
231 // more of them. 249 // more of them.
(...skipping 18 matching lines...) Expand all
250 268
251 // Note that this is used for cases where the only thing we do is preroll the 269 // Note that this is used for cases where the only thing we do is preroll the
252 // image the first time we see it. This mimics the previous behavior and 270 // image the first time we see it. This mimics the previous behavior and
253 // should over time change as the compositor starts to handle more cases. 271 // should over time change as the compositor starts to handle more cases.
254 std::unordered_set<uint32_t> prerolled_images_; 272 std::unordered_set<uint32_t> prerolled_images_;
255 }; 273 };
256 274
257 } // namespace cc 275 } // namespace cc
258 276
259 #endif // CC_TILES_IMAGE_DECODE_CONTROLLER_H_ 277 #endif // CC_TILES_IMAGE_DECODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/tiles/image_decode_controller.cc » ('j') | cc/tiles/image_decode_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698