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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 void ReportUsageStats() const; | 226 void ReportUsageStats() const; |
227 | 227 |
228 // May be null if image not yet uploaded / prepared. | 228 // May be null if image not yet uploaded / prepared. |
229 sk_sp<SkImage> image_; | 229 sk_sp<SkImage> image_; |
230 UsageStats usage_stats_; | 230 UsageStats usage_stats_; |
231 }; | 231 }; |
232 | 232 |
233 struct ImageData : public base::RefCounted<ImageData> { | 233 struct ImageData : public base::RefCounted<ImageData> { |
234 ImageData(DecodedDataMode mode, | 234 ImageData(DecodedDataMode mode, |
235 size_t size, | 235 size_t size, |
| 236 const gfx::ColorSpace& target_color_space, |
236 const SkImage::DeferredTextureImageUsageParams& upload_params); | 237 const SkImage::DeferredTextureImageUsageParams& upload_params); |
237 | 238 |
238 const DecodedDataMode mode; | 239 const DecodedDataMode mode; |
239 const size_t size; | 240 const size_t size; |
| 241 gfx::ColorSpace target_color_space; |
240 bool is_at_raster = false; | 242 bool is_at_raster = false; |
241 SkImage::DeferredTextureImageUsageParams upload_params; | 243 SkImage::DeferredTextureImageUsageParams upload_params; |
242 | 244 |
243 // If true, this image is no longer in our |persistent_cache_| and will be | 245 // If true, this image is no longer in our |persistent_cache_| and will be |
244 // deleted as soon as its ref count reaches zero. | 246 // deleted as soon as its ref count reaches zero. |
245 bool is_orphaned = false; | 247 bool is_orphaned = false; |
246 | 248 |
247 DecodedImageData decode; | 249 DecodedImageData decode; |
248 UploadedImageData upload; | 250 UploadedImageData upload; |
249 | 251 |
250 private: | 252 private: |
251 friend class base::RefCounted<ImageData>; | 253 friend class base::RefCounted<ImageData>; |
252 ~ImageData(); | 254 ~ImageData(); |
253 }; | 255 }; |
254 | 256 |
255 // A ref-count and ImageData, used to associate the ImageData with a specific | 257 // A ref-count and ImageData, used to associate the ImageData with a specific |
256 // DrawImage in the |in_use_cache_|. | 258 // DrawImage in the |in_use_cache_|. |
257 struct InUseCacheEntry { | 259 struct InUseCacheEntry { |
258 explicit InUseCacheEntry(scoped_refptr<ImageData> image_data); | 260 explicit InUseCacheEntry(scoped_refptr<ImageData> image_data); |
259 InUseCacheEntry(const InUseCacheEntry& other); | 261 InUseCacheEntry(const InUseCacheEntry& other); |
260 InUseCacheEntry(InUseCacheEntry&& other); | 262 InUseCacheEntry(InUseCacheEntry&& other); |
261 ~InUseCacheEntry(); | 263 ~InUseCacheEntry(); |
262 | 264 |
263 uint32_t ref_count = 0; | 265 uint32_t ref_count = 0; |
264 scoped_refptr<ImageData> image_data; | 266 scoped_refptr<ImageData> image_data; |
265 }; | 267 }; |
266 | 268 |
267 // Uniquely identifies (without collisions) a specific DrawImage for use in | 269 // Uniquely identifies (without collisions) a specific DrawImage for use in |
268 // the |in_use_cache_|. | 270 // the |in_use_cache_|. |
269 using InUseCacheKey = uint64_t; | 271 struct InUseCacheKeyHash; |
| 272 struct InUseCacheKey { |
| 273 static InUseCacheKey FromDrawImage(const DrawImage& draw_image); |
| 274 bool operator==(const InUseCacheKey& other) const; |
| 275 |
| 276 private: |
| 277 friend struct GpuImageDecodeCache::InUseCacheKeyHash; |
| 278 explicit InUseCacheKey(const DrawImage& draw_image); |
| 279 |
| 280 uint32_t image_id; |
| 281 int mip_level; |
| 282 SkFilterQuality filter_quality; |
| 283 gfx::ColorSpace target_color_space; |
| 284 }; |
| 285 struct InUseCacheKeyHash { |
| 286 size_t operator()(const InUseCacheKey&) const; |
| 287 }; |
270 | 288 |
271 // All private functions should only be called while holding |lock_|. Some | 289 // All private functions should only be called while holding |lock_|. Some |
272 // functions also require the |context_| lock. These are indicated by | 290 // functions also require the |context_| lock. These are indicated by |
273 // additional comments. | 291 // additional comments. |
274 | 292 |
275 // Similar to GetTaskForImageAndRef, but gets the dependent decode task | 293 // Similar to GetTaskForImageAndRef, but gets the dependent decode task |
276 // rather than the upload task, if necessary. | 294 // rather than the upload task, if necessary. |
277 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( | 295 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( |
278 const DrawImage& image, | 296 const DrawImage& image, |
279 const TracingInfo& tracing_info, | 297 const TracingInfo& tracing_info, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // All members below this point must only be accessed while holding |lock_|. | 349 // All members below this point must only be accessed while holding |lock_|. |
332 base::Lock lock_; | 350 base::Lock lock_; |
333 | 351 |
334 // |persistent_cache_| represents the long-lived cache, keeping a certain | 352 // |persistent_cache_| represents the long-lived cache, keeping a certain |
335 // budget of ImageDatas alive even when their ref count reaches zero. | 353 // budget of ImageDatas alive even when their ref count reaches zero. |
336 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; | 354 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; |
337 PersistentCache persistent_cache_; | 355 PersistentCache persistent_cache_; |
338 | 356 |
339 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are | 357 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are |
340 // cleaned up as soon as their ref count reaches zero. | 358 // cleaned up as soon as their ref count reaches zero. |
341 using InUseCache = std::unordered_map<InUseCacheKey, InUseCacheEntry>; | 359 using InUseCache = |
| 360 std::unordered_map<InUseCacheKey, InUseCacheEntry, InUseCacheKeyHash>; |
342 InUseCache in_use_cache_; | 361 InUseCache in_use_cache_; |
343 | 362 |
344 size_t max_working_set_bytes_; | 363 size_t max_working_set_bytes_; |
345 const size_t normal_max_cache_bytes_; | 364 const size_t normal_max_cache_bytes_; |
346 size_t cached_bytes_limit_ = normal_max_cache_bytes_; | 365 size_t cached_bytes_limit_ = normal_max_cache_bytes_; |
347 size_t bytes_used_ = 0; | 366 size_t bytes_used_ = 0; |
348 base::MemoryState memory_state_ = base::MemoryState::NORMAL; | 367 base::MemoryState memory_state_ = base::MemoryState::NORMAL; |
349 | 368 |
350 // We can't release GPU backed SkImages without holding the context lock, | 369 // We can't release GPU backed SkImages without holding the context lock, |
351 // so we add them to this list and defer deletion until the next time the lock | 370 // so we add them to this list and defer deletion until the next time the lock |
352 // is held. | 371 // is held. |
353 std::vector<sk_sp<SkImage>> images_pending_deletion_; | 372 std::vector<sk_sp<SkImage>> images_pending_deletion_; |
354 }; | 373 }; |
355 | 374 |
356 } // namespace cc | 375 } // namespace cc |
357 | 376 |
358 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 377 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |