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

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: 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') | no next file with comments »
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 result *= target_size_.width();
56 result *= target_size_.height(); 65 result *= target_size_.height();
57 return result.ValueOrDefault(std::numeric_limits<size_t>::max()); 66 return result.ValueOrDefault(std::numeric_limits<size_t>::max());
58 } 67 }
59 68
60 std::string ToString() const; 69 std::string ToString() const;
61 70
62 private: 71 private:
63 ImageDecodeControllerKey(uint32_t image_id, 72 ImageDecodeControllerKey(uint32_t image_id,
64 const gfx::Rect& src_rect, 73 const gfx::Rect& src_rect,
65 const gfx::Size& size, 74 const gfx::Size& size,
66 SkFilterQuality filter_quality); 75 SkFilterQuality filter_quality,
76 bool can_use_original_decode);
67 77
68 uint32_t image_id_; 78 uint32_t image_id_;
69 gfx::Rect src_rect_; 79 gfx::Rect src_rect_;
70 gfx::Size target_size_; 80 gfx::Size target_size_;
71 SkFilterQuality filter_quality_; 81 SkFilterQuality filter_quality_;
82 bool can_use_original_decode_;
83 size_t hash_;
72 }; 84 };
73 85
74 // Hash function for the above ImageDecodeControllerKey. 86 // Hash function for the above ImageDecodeControllerKey.
75 struct ImageDecodeControllerKeyHash { 87 struct ImageDecodeControllerKeyHash {
76 size_t operator()(const ImageDecodeControllerKey& key) const { 88 size_t operator()(const ImageDecodeControllerKey& key) const {
77 // TODO(vmpstr): This is a mess. Maybe it's faster to just search the vector 89 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 } 90 }
91 }; 91 };
92 92
93 // ImageDecodeController is responsible for generating decode tasks, decoding 93 // ImageDecodeController is responsible for generating decode tasks, decoding
94 // images, storing images in cache, and being able to return the decoded images 94 // images, storing images in cache, and being able to return the decoded images
95 // when requested. 95 // when requested.
96 96
97 // ImageDecodeController is responsible for the following things: 97 // ImageDecodeController is responsible for the following things:
98 // 1. Given a DrawImage, it can return an ImageDecodeTask which when run will 98 // 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 99 // 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 211
212 // Looks for the key in the cache and returns true if it was found and was 212 // 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 213 // 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. 214 // function returns true, then a ref count is increased for the image.
215 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); 215 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key);
216 216
217 // Actually decode the image. Note that this function can (and should) be 217 // 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 218 // 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. 219 // can also return nullptr to indicate the decode failed.
220 scoped_refptr<DecodedImage> DecodeImageInternal(const ImageKey& key, 220 scoped_refptr<DecodedImage> DecodeImageInternal(const ImageKey& key,
221 const SkImage* image); 221 const DrawImage& draw_image);
222
223 // Get the decoded draw image for the given key and draw_image. Note that this
224 // function has to be called with no lock acquired, since it will acquire its
225 // own locks and might call DecodeImageInternal above. Also note that this
226 // function will use the provided key, even if
227 // ImageKey::FromDrawImage(draw_image) would return a different key.
228 // Note that when used internally, we still require that
229 // DrawWithImageFinished() is called afterwards.
230 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key,
231 const DrawImage& draw_image);
232
222 void SanityCheckState(int line, bool lock_acquired); 233 void SanityCheckState(int line, bool lock_acquired);
223 void RefImage(const ImageKey& key); 234 void RefImage(const ImageKey& key);
224 void RefAtRasterImage(const ImageKey& key); 235 void RefAtRasterImage(const ImageKey& key);
225 void UnrefAtRasterImage(const ImageKey& key); 236 void UnrefAtRasterImage(const ImageKey& key);
226 237
227 // These functions indicate whether the images can be handled and cached by 238 // These functions indicate whether the images can be handled and cached by
228 // ImageDecodeController or whether they will fall through to Skia (with 239 // ImageDecodeController or whether they will fall through to Skia (with
229 // exception of possibly prerolling them). Over time these should return 240 // exception of possibly prerolling them). Over time these should return
230 // "false" in less cases, as the ImageDecodeController should start handling 241 // "false" in less cases, as the ImageDecodeController should start handling
231 // more of them. 242 // more of them.
(...skipping 18 matching lines...) Expand all
250 261
251 // Note that this is used for cases where the only thing we do is preroll the 262 // 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 263 // 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. 264 // should over time change as the compositor starts to handle more cases.
254 std::unordered_set<uint32_t> prerolled_images_; 265 std::unordered_set<uint32_t> prerolled_images_;
255 }; 266 };
256 267
257 } // namespace cc 268 } // namespace cc
258 269
259 #endif // CC_TILES_IMAGE_DECODE_CONTROLLER_H_ 270 #endif // CC_TILES_IMAGE_DECODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/tiles/image_decode_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698