Index: cc/tiles/software_image_decode_cache.cc |
diff --git a/cc/tiles/software_image_decode_cache.cc b/cc/tiles/software_image_decode_cache.cc |
index bb2a8d0c1370947ee6b97e866181a5b2ae6a76f2..482d6f5513a51fdb8b70fa7b9a763ed80eda85e6 100644 |
--- a/cc/tiles/software_image_decode_cache.cc |
+++ b/cc/tiles/software_image_decode_cache.cc |
@@ -94,11 +94,13 @@ class ImageDecodeTaskImpl : public TileTask { |
ImageDecodeTaskImpl(SoftwareImageDecodeCache* cache, |
const SoftwareImageDecodeCache::ImageKey& image_key, |
const DrawImage& image, |
+ const SoftwareImageDecodeCache::DecodeTaskType task_type, |
const ImageDecodeCache::TracingInfo& tracing_info) |
: TileTask(true), |
cache_(cache), |
image_key_(image_key), |
image_(image), |
+ task_type_(task_type), |
tracing_info_(tracing_info) {} |
// Overridden from Task: |
@@ -109,11 +111,13 @@ class ImageDecodeTaskImpl : public TileTask { |
devtools_instrumentation::ScopedImageDecodeTask image_decode_task( |
image_.image().get(), |
devtools_instrumentation::ScopedImageDecodeTask::SOFTWARE); |
- cache_->DecodeImage(image_key_, image_); |
+ cache_->DecodeImage(image_key_, image_, task_type_); |
} |
// Overridden from TileTask: |
- void OnTaskCompleted() override { cache_->RemovePendingTask(image_key_); } |
+ void OnTaskCompleted() override { |
+ cache_->RemovePendingTask(image_key_, task_type_); |
+ } |
protected: |
~ImageDecodeTaskImpl() override {} |
@@ -122,6 +126,7 @@ class ImageDecodeTaskImpl : public TileTask { |
SoftwareImageDecodeCache* cache_; |
SoftwareImageDecodeCache::ImageKey image_key_; |
DrawImage image_; |
+ SoftwareImageDecodeCache::DecodeTaskType task_type_; |
const ImageDecodeCache::TracingInfo tracing_info_; |
DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
@@ -207,6 +212,22 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRef( |
const DrawImage& image, |
const TracingInfo& tracing_info, |
scoped_refptr<TileTask>* task) { |
+ return GetTaskForImageAndRefInternal(image, tracing_info, USE_IN_RASTER_TASKS, |
+ task); |
+} |
+ |
+bool SoftwareImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef( |
+ const DrawImage& image, |
+ scoped_refptr<TileTask>* task) { |
+ return GetTaskForImageAndRefInternal(image, TracingInfo(), |
+ USE_OUT_OF_RASTER_TASKS, task); |
+} |
+ |
+bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( |
+ const DrawImage& image, |
+ const TracingInfo& tracing_info, |
+ DecodeTaskType task_type, |
+ scoped_refptr<TileTask>* task) { |
// If the image already exists or if we're going to create a task for it, then |
// we'll likely need to ref this image (the exception is if we're prerolling |
// the image only). That means the image is or will be in the cache. When the |
@@ -257,8 +278,15 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRef( |
} |
} |
- // If the task exists, return it. |
- scoped_refptr<TileTask>& existing_task = pending_image_tasks_[key]; |
+ DCHECK(task_type == USE_IN_RASTER_TASKS || |
+ task_type == USE_OUT_OF_RASTER_TASKS); |
+ // If the task exists, return it. Note that if we always need to create a new |
+ // task, then just set |existing_task| to reference the passed in task (which |
+ // is set to nullptr above). |
+ scoped_refptr<TileTask>& existing_task = |
+ (task_type == USE_IN_RASTER_TASKS) |
+ ? pending_in_raster_image_tasks_[key] |
+ : pending_out_of_raster_image_tasks_[key]; |
if (existing_task) { |
RefImage(key); |
*task = existing_task; |
@@ -282,7 +310,7 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRef( |
// ref. |
RefImage(key); |
existing_task = make_scoped_refptr( |
- new ImageDecodeTaskImpl(this, key, image, tracing_info)); |
+ new ImageDecodeTaskImpl(this, key, image, task_type, tracing_info)); |
*task = existing_task; |
SanityCheckState(__LINE__, true); |
return true; |
@@ -333,11 +361,15 @@ void SoftwareImageDecodeCache::UnrefImage(const DrawImage& image) { |
} |
void SoftwareImageDecodeCache::DecodeImage(const ImageKey& key, |
- const DrawImage& image) { |
+ const DrawImage& image, |
+ DecodeTaskType task_type) { |
TRACE_EVENT1("cc", "SoftwareImageDecodeCache::DecodeImage", "key", |
key.ToString()); |
base::AutoLock lock(lock_); |
- AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); |
+ AutoRemoveKeyFromTaskMap remove_key_from_task_map( |
+ (task_type == USE_IN_RASTER_TASKS) ? &pending_in_raster_image_tasks_ |
+ : &pending_out_of_raster_image_tasks_, |
+ key); |
// We could have finished all of the raster tasks (cancelled) while the task |
// was just starting to run. Since this task already started running, it |
@@ -767,9 +799,17 @@ void SoftwareImageDecodeCache::ReduceCacheUsage() { |
} |
} |
-void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key) { |
+void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key, |
+ DecodeTaskType task_type) { |
base::AutoLock lock(lock_); |
- pending_image_tasks_.erase(key); |
+ switch (task_type) { |
+ case USE_IN_RASTER_TASKS: |
+ pending_in_raster_image_tasks_.erase(key); |
+ break; |
+ case USE_OUT_OF_RASTER_TASKS: |
+ pending_out_of_raster_image_tasks_.erase(key); |
+ break; |
+ } |
} |
bool SoftwareImageDecodeCache::OnMemoryDump( |
@@ -836,7 +876,10 @@ void SoftwareImageDecodeCache::SanityCheckState(int line, bool lock_acquired) { |
DCHECK(ref_it != decoded_images_ref_counts_.end()) << line; |
} else { |
DCHECK(ref_it == decoded_images_ref_counts_.end() || |
- pending_image_tasks_.find(key) != pending_image_tasks_.end()) |
+ pending_in_raster_image_tasks_.find(key) != |
+ pending_in_raster_image_tasks_.end() || |
+ pending_out_of_raster_image_tasks_.find(key) != |
+ pending_out_of_raster_image_tasks_.end()) |
<< line; |
} |
} |