Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4880)

Unified Diff: cc/tiles/gpu_image_decode_cache.cc

Issue 2537683002: cc: Add image decode queue functionality to image manager. (Closed)
Patch Set: image-queue: update Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/tiles/gpu_image_decode_cache.cc
diff --git a/cc/tiles/gpu_image_decode_cache.cc b/cc/tiles/gpu_image_decode_cache.cc
index b06da1f9b216464efc1f94a1ac4482996b683775..c9d2b4c1ff3be542d2c49560428ab0c4ea50e829 100644
--- a/cc/tiles/gpu_image_decode_cache.cc
+++ b/cc/tiles/gpu_image_decode_cache.cc
@@ -149,11 +149,13 @@ class ImageDecodeTaskImpl : public TileTask {
public:
ImageDecodeTaskImpl(GpuImageDecodeCache* cache,
const DrawImage& draw_image,
- const ImageDecodeCache::TracingInfo& tracing_info)
+ const ImageDecodeCache::TracingInfo& tracing_info,
+ GpuImageDecodeCache::DecodeTaskType task_type)
: TileTask(true),
cache_(cache),
image_(draw_image),
- tracing_info_(tracing_info) {
+ tracing_info_(tracing_info),
+ task_type_(task_type) {
DCHECK(!SkipImage(draw_image));
}
@@ -169,7 +171,7 @@ class ImageDecodeTaskImpl : public TileTask {
// Overridden from TileTask:
void OnTaskCompleted() override {
- cache_->OnImageDecodeTaskCompleted(image_);
+ cache_->OnImageDecodeTaskCompleted(image_, task_type_);
}
protected:
@@ -179,6 +181,7 @@ class ImageDecodeTaskImpl : public TileTask {
GpuImageDecodeCache* cache_;
DrawImage image_;
const ImageDecodeCache::TracingInfo tracing_info_;
+ GpuImageDecodeCache::DecodeTaskType task_type_;
ericrk 2016/12/06 23:22:52 nit: const
DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl);
};
@@ -377,6 +380,22 @@ GpuImageDecodeCache::~GpuImageDecodeCache() {
bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image,
const TracingInfo& tracing_info,
scoped_refptr<TileTask>* task) {
+ return GetTaskForImageAndRefInternal(draw_image, tracing_info,
+ PART_OF_UPLOAD_TASK, task);
+}
+
+bool GpuImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& draw_image,
+ scoped_refptr<TileTask>* task) {
+ return GetTaskForImageAndRefInternal(draw_image, TracingInfo(),
+ STAND_ALONE_DECODE_TASK, task);
+}
+
+bool GpuImageDecodeCache::GetTaskForImageAndRefInternal(
+ const DrawImage& draw_image,
+ const TracingInfo& tracing_info,
+ DecodeTaskType task_type,
+ scoped_refptr<TileTask>* task) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
"GpuImageDecodeCache::GetTaskForImageAndRef");
if (SkipImage(draw_image)) {
@@ -405,11 +424,17 @@ bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image,
RefImage(draw_image);
*task = nullptr;
return true;
- } else if (image_data->upload.task) {
+ } else if (task_type == PART_OF_UPLOAD_TASK && image_data->upload.task) {
// We had an existing upload task, ref the image and return the task.
RefImage(draw_image);
*task = image_data->upload.task;
return true;
+ } else if (task_type == STAND_ALONE_DECODE_TASK &&
+ image_data->decode.stand_alone_task) {
+ // We had an existing out of raster task, ref the image and return the task.
+ RefImage(draw_image);
+ *task = image_data->decode.stand_alone_task;
+ return true;
}
// Ensure that the image we're about to decode/upload will fit in memory.
@@ -424,13 +449,18 @@ bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image,
if (new_data)
persistent_cache_.Put(image_id, std::move(new_data));
- // Ref image and create a upload and decode tasks. We will release this ref
- // in UploadTaskCompleted.
- RefImage(draw_image);
- *task = make_scoped_refptr(new ImageUploadTaskImpl(
- this, draw_image, GetImageDecodeTaskAndRef(draw_image, tracing_info),
- tracing_info));
- image_data->upload.task = *task;
+ if (task_type == PART_OF_UPLOAD_TASK) {
+ // Ref image and create a upload and decode tasks. We will release this ref
+ // in UploadTaskCompleted.
+ RefImage(draw_image);
+ *task = make_scoped_refptr(new ImageUploadTaskImpl(
+ this, draw_image,
+ GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type),
+ tracing_info));
+ image_data->upload.task = *task;
+ } else {
+ *task = GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type);
+ }
// Ref the image again - this ref is owned by the caller, and it is their
// responsibility to release it by calling UnrefImage.
@@ -644,15 +674,22 @@ void GpuImageDecodeCache::UploadImage(const DrawImage& draw_image) {
}
void GpuImageDecodeCache::OnImageDecodeTaskCompleted(
- const DrawImage& draw_image) {
+ const DrawImage& draw_image,
+ DecodeTaskType task_type) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
"GpuImageDecodeCache::OnImageDecodeTaskCompleted");
base::AutoLock lock(lock_);
// Decode task is complete, remove our reference to it.
ImageData* image_data = GetImageDataForDrawImage(draw_image);
DCHECK(image_data);
- DCHECK(image_data->decode.task);
- image_data->decode.task = nullptr;
+ if (task_type == PART_OF_UPLOAD_TASK) {
+ DCHECK(image_data->decode.task);
+ image_data->decode.task = nullptr;
+ } else {
+ DCHECK(task_type == STAND_ALONE_DECODE_TASK);
+ DCHECK(image_data->decode.stand_alone_task);
+ image_data->decode.stand_alone_task = nullptr;
+ }
// While the decode task is active, we keep a ref on the decoded data.
// Release that ref now.
@@ -681,14 +718,16 @@ void GpuImageDecodeCache::OnImageUploadTaskCompleted(
// the requested decode.
scoped_refptr<TileTask> GpuImageDecodeCache::GetImageDecodeTaskAndRef(
const DrawImage& draw_image,
- const TracingInfo& tracing_info) {
+ const TracingInfo& tracing_info,
+ DecodeTaskType task_type) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
"GpuImageDecodeCache::GetImageDecodeTaskAndRef");
lock_.AssertAcquired();
// This ref is kept alive while an upload task may need this decode. We
// release this ref in UploadTaskCompleted.
- RefImageDecode(draw_image);
+ if (task_type == PART_OF_UPLOAD_TASK)
+ RefImageDecode(draw_image);
ericrk 2016/12/06 23:22:52 Should we just move this out of this function, to
ImageData* image_data = GetImageDataForDrawImage(draw_image);
DCHECK(image_data);
@@ -701,13 +740,15 @@ scoped_refptr<TileTask> GpuImageDecodeCache::GetImageDecodeTaskAndRef(
}
// We didn't have an existing locked image, create a task to lock or decode.
- scoped_refptr<TileTask>& existing_task = image_data->decode.task;
+ scoped_refptr<TileTask>& existing_task =
+ (task_type == PART_OF_UPLOAD_TASK) ? image_data->decode.task
+ : image_data->decode.stand_alone_task;
if (!existing_task) {
// Ref image decode and create a decode task. This ref will be released in
// DecodeTaskCompleted.
RefImageDecode(draw_image);
existing_task = make_scoped_refptr(
- new ImageDecodeTaskImpl(this, draw_image, tracing_info));
+ new ImageDecodeTaskImpl(this, draw_image, tracing_info, task_type));
}
return existing_task;
}
@@ -854,10 +895,11 @@ void GpuImageDecodeCache::OwnershipChanged(const DrawImage& draw_image,
// We should unlock the discardable memory for the image in two cases:
// 1) The image is no longer being used (no decode or upload refs).
// 2) This is a GPU backed image that has already been uploaded (no decode
- // refs).
+ // refs, and we actually already have an image).
bool should_unlock_discardable =
- !has_any_refs || (image_data->mode == DecodedDataMode::GPU &&
- !image_data->decode.ref_count);
+ !has_any_refs ||
+ (image_data->mode == DecodedDataMode::GPU &&
+ !image_data->decode.ref_count && image_data->upload.image());
if (should_unlock_discardable && image_data->decode.is_locked()) {
DCHECK(image_data->decode.data());

Powered by Google App Engine
This is Rietveld 408576698