OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 #include <unordered_set> | 12 #include <unordered_set> |
13 | 13 |
14 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
15 #include "base/containers/mru_cache.h" | 15 #include "base/containers/mru_cache.h" |
16 #include "base/hash.h" | 16 #include "base/hash.h" |
17 #include "base/memory/discardable_memory_allocator.h" | 17 #include "base/memory/discardable_memory_allocator.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/numerics/safe_math.h" | 19 #include "base/numerics/safe_math.h" |
20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
21 #include "base/trace_event/memory_dump_provider.h" | 21 #include "base/trace_event/memory_dump_provider.h" |
22 #include "cc/base/cc_export.h" | 22 #include "cc/base/cc_export.h" |
23 #include "cc/playback/decoded_draw_image.h" | 23 #include "cc/playback/decoded_draw_image.h" |
24 #include "cc/playback/draw_image.h" | 24 #include "cc/playback/draw_image.h" |
25 #include "cc/resources/resource_format.h" | 25 #include "cc/resources/resource_format.h" |
26 #include "cc/tiles/image_decode_controller.h" | 26 #include "cc/tiles/image_decode_controller.h" |
27 #include "skia/ext/refptr.h" | 27 #include "third_party/skia/include/core/SkRefCnt.h" |
28 | 28 |
29 namespace cc { | 29 namespace cc { |
30 | 30 |
31 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw | 31 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw |
32 // image. That is, this key uniquely identifies an image in the cache. Note that | 32 // image. That is, this key uniquely identifies an image in the cache. Note that |
33 // it's insufficient to use SkImage's unique id, since the same image can appear | 33 // it's insufficient to use SkImage's unique id, since the same image can appear |
34 // in the cache multiple times at different scales and filter qualities. | 34 // in the cache multiple times at different scales and filter qualities. |
35 class CC_EXPORT ImageDecodeControllerKey { | 35 class CC_EXPORT ImageDecodeControllerKey { |
36 public: | 36 public: |
37 static ImageDecodeControllerKey FromDrawImage(const DrawImage& image); | 37 static ImageDecodeControllerKey FromDrawImage(const DrawImage& image); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // DecodedImage is a convenience storage for discardable memory. It can also | 134 // DecodedImage is a convenience storage for discardable memory. It can also |
135 // construct an image out of SkImageInfo and stored discardable memory. | 135 // construct an image out of SkImageInfo and stored discardable memory. |
136 class DecodedImage { | 136 class DecodedImage { |
137 public: | 137 public: |
138 DecodedImage(const SkImageInfo& info, | 138 DecodedImage(const SkImageInfo& info, |
139 std::unique_ptr<base::DiscardableMemory> memory, | 139 std::unique_ptr<base::DiscardableMemory> memory, |
140 const SkSize& src_rect_offset, | 140 const SkSize& src_rect_offset, |
141 uint64_t tracing_id); | 141 uint64_t tracing_id); |
142 ~DecodedImage(); | 142 ~DecodedImage(); |
143 | 143 |
144 SkImage* image() const { | 144 const sk_sp<SkImage>& image() const { |
145 DCHECK(locked_); | 145 DCHECK(locked_); |
146 return image_.get(); | 146 return image_; |
147 } | 147 } |
148 | 148 |
149 const SkSize& src_rect_offset() const { return src_rect_offset_; } | 149 const SkSize& src_rect_offset() const { return src_rect_offset_; } |
150 | 150 |
151 bool is_locked() const { return locked_; } | 151 bool is_locked() const { return locked_; } |
152 bool Lock(); | 152 bool Lock(); |
153 void Unlock(); | 153 void Unlock(); |
154 | 154 |
155 const base::DiscardableMemory* memory() const { return memory_.get(); } | 155 const base::DiscardableMemory* memory() const { return memory_.get(); } |
156 | 156 |
157 // An ID which uniquely identifies this DecodedImage within the image decode | 157 // An ID which uniquely identifies this DecodedImage within the image decode |
158 // controller. Used in memory tracing. | 158 // controller. Used in memory tracing. |
159 uint64_t tracing_id() const { return tracing_id_; } | 159 uint64_t tracing_id() const { return tracing_id_; } |
160 | 160 |
161 private: | 161 private: |
162 bool locked_; | 162 bool locked_; |
163 SkImageInfo image_info_; | 163 SkImageInfo image_info_; |
164 std::unique_ptr<base::DiscardableMemory> memory_; | 164 std::unique_ptr<base::DiscardableMemory> memory_; |
165 skia::RefPtr<SkImage> image_; | 165 sk_sp<SkImage> image_; |
166 SkSize src_rect_offset_; | 166 SkSize src_rect_offset_; |
167 uint64_t tracing_id_; | 167 uint64_t tracing_id_; |
168 }; | 168 }; |
169 | 169 |
170 // MemoryBudget is a convenience class for memory bookkeeping and ensuring | 170 // MemoryBudget is a convenience class for memory bookkeeping and ensuring |
171 // that we don't go over the limit when pre-decoding. | 171 // that we don't go over the limit when pre-decoding. |
172 class MemoryBudget { | 172 class MemoryBudget { |
173 public: | 173 public: |
174 explicit MemoryBudget(size_t limit_bytes); | 174 explicit MemoryBudget(size_t limit_bytes); |
175 | 175 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 // function will use the provided key, even if | 207 // function will use the provided key, even if |
208 // ImageKey::FromDrawImage(draw_image) would return a different key. | 208 // ImageKey::FromDrawImage(draw_image) would return a different key. |
209 // Note that when used internally, we still require that | 209 // Note that when used internally, we still require that |
210 // DrawWithImageFinished() is called afterwards. | 210 // DrawWithImageFinished() is called afterwards. |
211 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, | 211 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, |
212 const DrawImage& draw_image); | 212 const DrawImage& draw_image); |
213 | 213 |
214 // GetOriginalImageDecode is called by DecodeImageInternal when the quality | 214 // GetOriginalImageDecode is called by DecodeImageInternal when the quality |
215 // does not scale the image. Like DecodeImageInternal, it should be called | 215 // does not scale the image. Like DecodeImageInternal, it should be called |
216 // with no lock acquired and it returns nullptr if the decoding failed. | 216 // with no lock acquired and it returns nullptr if the decoding failed. |
217 std::unique_ptr<DecodedImage> GetOriginalImageDecode(const ImageKey& key, | 217 std::unique_ptr<DecodedImage> GetOriginalImageDecode( |
218 const SkImage& image); | 218 const ImageKey& key, |
219 sk_sp<const SkImage> image); | |
danakj
2016/04/22 20:36:04
I think florin was against saying const for these?
| |
219 | 220 |
220 // GetScaledImageDecode is called by DecodeImageInternal when the quality | 221 // GetScaledImageDecode is called by DecodeImageInternal when the quality |
221 // requires the image be scaled. Like DecodeImageInternal, it should be | 222 // requires the image be scaled. Like DecodeImageInternal, it should be |
222 // called with no lock acquired and it returns nullptr if the decoding or | 223 // called with no lock acquired and it returns nullptr if the decoding or |
223 // scaling failed. | 224 // scaling failed. |
224 std::unique_ptr<DecodedImage> GetScaledImageDecode(const ImageKey& key, | 225 std::unique_ptr<DecodedImage> GetScaledImageDecode( |
225 const SkImage& image); | 226 const ImageKey& key, |
227 sk_sp<const SkImage> image); | |
226 | 228 |
227 void SanityCheckState(int line, bool lock_acquired); | 229 void SanityCheckState(int line, bool lock_acquired); |
228 void RefImage(const ImageKey& key); | 230 void RefImage(const ImageKey& key); |
229 void RefAtRasterImage(const ImageKey& key); | 231 void RefAtRasterImage(const ImageKey& key); |
230 void UnrefAtRasterImage(const ImageKey& key); | 232 void UnrefAtRasterImage(const ImageKey& key); |
231 | 233 |
232 // These functions indicate whether the images can be handled and cached by | 234 // These functions indicate whether the images can be handled and cached by |
233 // ImageDecodeController or whether they will fall through to Skia (with | 235 // ImageDecodeController or whether they will fall through to Skia (with |
234 // exception of possibly prerolling them). Over time these should return | 236 // exception of possibly prerolling them). Over time these should return |
235 // "false" in less cases, as the ImageDecodeController should start handling | 237 // "false" in less cases, as the ImageDecodeController should start handling |
(...skipping 30 matching lines...) Expand all Loading... | |
266 | 268 |
267 ResourceFormat format_; | 269 ResourceFormat format_; |
268 | 270 |
269 // Used to uniquely identify DecodedImages for memory traces. | 271 // Used to uniquely identify DecodedImages for memory traces. |
270 base::AtomicSequenceNumber next_tracing_id_; | 272 base::AtomicSequenceNumber next_tracing_id_; |
271 }; | 273 }; |
272 | 274 |
273 } // namespace cc | 275 } // namespace cc |
274 | 276 |
275 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 277 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
OLD | NEW |