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 InUseCacheKeyHash; |
| 271 struct InUseCacheKey { |
| 272 static InUseCacheKey FromDrawImage(const DrawImage& draw_image); |
| 273 bool operator==(const InUseCacheKey& other) const; |
| 274 |
| 275 private: |
| 276 friend struct GpuImageDecodeCache::InUseCacheKeyHash; |
| 277 explicit InUseCacheKey(const DrawImage& draw_image); |
| 278 |
| 279 uint32_t image_id; |
| 280 int mip_level; |
| 281 SkFilterQuality filter_quality; |
| 282 gfx::ColorSpace target_color_space; |
| 283 }; |
| 284 struct InUseCacheKeyHash { |
| 285 size_t operator()(const InUseCacheKey&) const; |
| 286 }; |
| 287 InUseCacheKey FromDrawImage(const DrawImage& draw_image); |
269 | 288 |
270 // All private functions should only be called while holding |lock_|. Some | 289 // All private functions should only be called while holding |lock_|. Some |
271 // functions also require the |context_| lock. These are indicated by | 290 // functions also require the |context_| lock. These are indicated by |
272 // additional comments. | 291 // additional comments. |
273 | 292 |
274 // Similar to GetTaskForImageAndRef, but gets the dependent decode task | 293 // Similar to GetTaskForImageAndRef, but gets the dependent decode task |
275 // rather than the upload task, if necessary. | 294 // rather than the upload task, if necessary. |
276 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( | 295 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( |
277 const DrawImage& image, | 296 const DrawImage& image, |
278 const TracingInfo& tracing_info, | 297 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_|. | 349 // All members below this point must only be accessed while holding |lock_|. |
331 base::Lock lock_; | 350 base::Lock lock_; |
332 | 351 |
333 // |persistent_cache_| represents the long-lived cache, keeping a certain | 352 // |persistent_cache_| represents the long-lived cache, keeping a certain |
334 // budget of ImageDatas alive even when their ref count reaches zero. | 353 // budget of ImageDatas alive even when their ref count reaches zero. |
335 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; | 354 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; |
336 PersistentCache persistent_cache_; | 355 PersistentCache persistent_cache_; |
337 | 356 |
338 // |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 |
339 // cleaned up as soon as their ref count reaches zero. | 358 // cleaned up as soon as their ref count reaches zero. |
340 using InUseCache = std::unordered_map<InUseCacheKey, InUseCacheEntry>; | 359 using InUseCache = |
| 360 std::unordered_map<InUseCacheKey, InUseCacheEntry, InUseCacheKeyHash>; |
341 InUseCache in_use_cache_; | 361 InUseCache in_use_cache_; |
342 | 362 |
343 size_t max_working_set_bytes_; | 363 size_t max_working_set_bytes_; |
344 const size_t normal_max_cache_bytes_; | 364 const size_t normal_max_cache_bytes_; |
345 size_t cached_bytes_limit_ = normal_max_cache_bytes_; | 365 size_t cached_bytes_limit_ = normal_max_cache_bytes_; |
346 size_t bytes_used_ = 0; | 366 size_t bytes_used_ = 0; |
347 base::MemoryState memory_state_ = base::MemoryState::NORMAL; | 367 base::MemoryState memory_state_ = base::MemoryState::NORMAL; |
348 | 368 |
349 // 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, |
350 // 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 |
351 // is held. | 371 // is held. |
352 std::vector<sk_sp<SkImage>> images_pending_deletion_; | 372 std::vector<sk_sp<SkImage>> images_pending_deletion_; |
353 }; | 373 }; |
354 | 374 |
355 } // namespace cc | 375 } // namespace cc |
356 | 376 |
357 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 377 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |