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_GPU_IMAGE_DECODE_CACHE_H_ | 5 #ifndef CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
6 #define CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 6 #define CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 void ReportUsageStats() const; | 225 void ReportUsageStats() const; |
226 | 226 |
227 // May be null if image not yet uploaded / prepared. | 227 // May be null if image not yet uploaded / prepared. |
228 sk_sp<SkImage> image_; | 228 sk_sp<SkImage> image_; |
229 UsageStats usage_stats_; | 229 UsageStats usage_stats_; |
230 }; | 230 }; |
231 | 231 |
232 struct ImageData : public base::RefCounted<ImageData> { | 232 struct ImageData : public base::RefCounted<ImageData> { |
233 ImageData(DecodedDataMode mode, | 233 ImageData(DecodedDataMode mode, |
234 size_t size, | 234 size_t size, |
235 const gfx::ColorSpace& target_color_space, | |
235 const SkImage::DeferredTextureImageUsageParams& upload_params); | 236 const SkImage::DeferredTextureImageUsageParams& upload_params); |
236 | 237 |
237 const DecodedDataMode mode; | 238 const DecodedDataMode mode; |
238 const size_t size; | 239 const size_t size; |
240 gfx::ColorSpace target_color_space; | |
239 bool is_at_raster = false; | 241 bool is_at_raster = false; |
240 SkImage::DeferredTextureImageUsageParams upload_params; | 242 SkImage::DeferredTextureImageUsageParams upload_params; |
241 | 243 |
242 // If true, this image is no longer in our |persistent_cache_| and will be | 244 // If true, this image is no longer in our |persistent_cache_| and will be |
243 // deleted as soon as its ref count reaches zero. | 245 // deleted as soon as its ref count reaches zero. |
244 bool is_orphaned = false; | 246 bool is_orphaned = false; |
245 | 247 |
246 DecodedImageData decode; | 248 DecodedImageData decode; |
247 UploadedImageData upload; | 249 UploadedImageData upload; |
248 | 250 |
249 private: | 251 private: |
250 friend class base::RefCounted<ImageData>; | 252 friend class base::RefCounted<ImageData>; |
251 ~ImageData(); | 253 ~ImageData(); |
252 }; | 254 }; |
253 | 255 |
254 // A ref-count and ImageData, used to associate the ImageData with a specific | 256 // A ref-count and ImageData, used to associate the ImageData with a specific |
255 // DrawImage in the |in_use_cache_|. | 257 // DrawImage in the |in_use_cache_|. |
256 struct InUseCacheEntry { | 258 struct InUseCacheEntry { |
257 explicit InUseCacheEntry(scoped_refptr<ImageData> image_data); | 259 explicit InUseCacheEntry(scoped_refptr<ImageData> image_data); |
258 InUseCacheEntry(const InUseCacheEntry& other); | 260 InUseCacheEntry(const InUseCacheEntry& other); |
259 InUseCacheEntry(InUseCacheEntry&& other); | 261 InUseCacheEntry(InUseCacheEntry&& other); |
260 ~InUseCacheEntry(); | 262 ~InUseCacheEntry(); |
261 | 263 |
262 uint32_t ref_count = 0; | 264 uint32_t ref_count = 0; |
263 scoped_refptr<ImageData> image_data; | 265 scoped_refptr<ImageData> image_data; |
264 }; | 266 }; |
265 | 267 |
266 // Uniquely identifies (without collisions) a specific DrawImage for use in | 268 // Uniquely identifies (without collisions) a specific DrawImage for use in |
267 // the |in_use_cache_|. | 269 // the |in_use_cache_|. |
268 using InUseCacheKey = uint64_t; | 270 struct InUseCacheKey { |
ericrk
2017/04/04 02:38:04
I don't think we ever access the internals of this
ccameron
2017/04/04 06:41:10
Done.
| |
271 explicit InUseCacheKey(const DrawImage& draw_image); | |
vmpstr
2017/04/04 01:16:43
Can you use a similar pattern as in the software c
ccameron
2017/04/04 06:41:10
Done.
| |
272 bool operator==(const InUseCacheKey& other) const; | |
273 uint32_t image_id; | |
274 int mip_level; | |
275 SkFilterQuality filter_quality; | |
276 gfx::ColorSpace target_color_space; | |
ericrk
2017/04/04 02:38:04
This looks really big (close to 100 bytes) - I sor
ccameron
2017/04/04 06:41:10
I'm surprised that this is a performance-critical
ericrk
2017/04/04 16:28:40
I was actually more concerned about the memory cos
vmpstr
2017/04/04 17:30:08
I don't feel strongly about this. I think we do en
| |
277 }; | |
278 struct InUseCacheKeyHash { | |
279 size_t operator()(const InUseCacheKey&) const; | |
280 }; | |
269 | 281 |
270 // All private functions should only be called while holding |lock_|. Some | 282 // All private functions should only be called while holding |lock_|. Some |
271 // functions also require the |context_| lock. These are indicated by | 283 // functions also require the |context_| lock. These are indicated by |
272 // additional comments. | 284 // additional comments. |
273 | 285 |
274 // Similar to GetTaskForImageAndRef, but gets the dependent decode task | 286 // Similar to GetTaskForImageAndRef, but gets the dependent decode task |
275 // rather than the upload task, if necessary. | 287 // rather than the upload task, if necessary. |
276 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( | 288 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( |
277 const DrawImage& image, | 289 const DrawImage& image, |
278 const TracingInfo& tracing_info, | 290 const TracingInfo& tracing_info, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 // All members below this point must only be accessed while holding |lock_|. | 342 // All members below this point must only be accessed while holding |lock_|. |
331 base::Lock lock_; | 343 base::Lock lock_; |
332 | 344 |
333 // |persistent_cache_| represents the long-lived cache, keeping a certain | 345 // |persistent_cache_| represents the long-lived cache, keeping a certain |
334 // budget of ImageDatas alive even when their ref count reaches zero. | 346 // budget of ImageDatas alive even when their ref count reaches zero. |
335 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; | 347 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; |
336 PersistentCache persistent_cache_; | 348 PersistentCache persistent_cache_; |
337 | 349 |
338 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are | 350 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are |
339 // cleaned up as soon as their ref count reaches zero. | 351 // cleaned up as soon as their ref count reaches zero. |
340 using InUseCache = std::unordered_map<InUseCacheKey, InUseCacheEntry>; | 352 using InUseCache = |
353 std::unordered_map<InUseCacheKey, InUseCacheEntry, InUseCacheKeyHash>; | |
341 InUseCache in_use_cache_; | 354 InUseCache in_use_cache_; |
342 | 355 |
343 size_t max_working_set_bytes_; | 356 size_t max_working_set_bytes_; |
344 const size_t normal_max_cache_bytes_; | 357 const size_t normal_max_cache_bytes_; |
345 size_t cached_bytes_limit_ = normal_max_cache_bytes_; | 358 size_t cached_bytes_limit_ = normal_max_cache_bytes_; |
346 size_t bytes_used_ = 0; | 359 size_t bytes_used_ = 0; |
347 base::MemoryState memory_state_ = base::MemoryState::NORMAL; | 360 base::MemoryState memory_state_ = base::MemoryState::NORMAL; |
348 | 361 |
349 // We can't release GPU backed SkImages without holding the context lock, | 362 // We can't release GPU backed SkImages without holding the context lock, |
350 // so we add them to this list and defer deletion until the next time the lock | 363 // so we add them to this list and defer deletion until the next time the lock |
351 // is held. | 364 // is held. |
352 std::vector<sk_sp<SkImage>> images_pending_deletion_; | 365 std::vector<sk_sp<SkImage>> images_pending_deletion_; |
353 }; | 366 }; |
354 | 367 |
355 } // namespace cc | 368 } // namespace cc |
356 | 369 |
357 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 370 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |