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

Unified Diff: cc/tiles/gpu_image_decode_controller_unittest.cc

Issue 1866043006: cc: Remove ScheduleOnOriginThread() and CompleteOnOriginThread(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 7 months 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_controller_unittest.cc
diff --git a/cc/tiles/gpu_image_decode_controller_unittest.cc b/cc/tiles/gpu_image_decode_controller_unittest.cc
index 1891f2e55710e4e4ec3ac055a2327a02038063d0..c66cad5d598f737a0efbf8f93a58881c55aeed89 100644
--- a/cc/tiles/gpu_image_decode_controller_unittest.cc
+++ b/cc/tiles/gpu_image_decode_controller_unittest.cc
@@ -32,31 +32,40 @@ SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) {
}
void ScheduleTask(TileTask* task) {
- task->WillSchedule();
- task->ScheduleOnOriginThread(nullptr);
- task->DidSchedule();
+ task->state().DidSchedule();
}
+// Before running the task it must be scheduled. Call ScheduleTask() before
+// calling this function.
void RunTask(TileTask* task) {
- // TODO(prashant.n): Once ScheduleOnOriginThread() and
- // CompleteOnOriginThread() functions are removed, modify this function
- // accordingly. (crbug.com/599863)
- task->state().DidSchedule();
task->state().DidStart();
task->RunOnWorkerThread();
task->state().DidFinish();
}
-void CompleteTask(TileTask* task) {
- task->WillComplete();
- task->CompleteOnOriginThread(nullptr);
- task->DidComplete();
+void CompleteTask(GpuImageDecodeController* controller, TileTask* task) {
+ switch (task->type()) {
+ case TileTask::Type::IMAGE_DECODE:
+ controller->OnImageDecodeTaskCompleted(task);
+ break;
+ case TileTask::Type::IMAGE_UPLOAD:
+ controller->OnImageUploadTaskCompleted(task);
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ task->state().DidComplete();
}
-void ProcessTask(TileTask* task) {
+void CancelTask(TileTask* task) {
+ task->state().DidCancel();
+}
+
+void ProcessTask(GpuImageDecodeController* controller, TileTask* task) {
ScheduleTask(task);
RunTask(task);
- CompleteTask(task);
+ CompleteTask(controller, task);
}
TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) {
@@ -86,8 +95,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task.get() == another_task.get());
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
+ ProcessTask(&controller, task.get());
controller.UnrefImage(draw_image);
controller.UnrefImage(draw_image);
@@ -123,10 +132,10 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) {
EXPECT_TRUE(second_task);
EXPECT_TRUE(first_task.get() != second_task.get());
- ProcessTask(first_task->dependencies()[0].get());
- ProcessTask(first_task.get());
- ProcessTask(second_task->dependencies()[0].get());
- ProcessTask(second_task.get());
+ ProcessTask(&controller, first_task->dependencies()[0].get());
+ ProcessTask(&controller, first_task.get());
+ ProcessTask(&controller, second_task->dependencies()[0].get());
+ ProcessTask(&controller, second_task.get());
controller.UnrefImage(first_draw_image);
controller.UnrefImage(second_draw_image);
@@ -157,8 +166,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) {
RunTask(task->dependencies()[0].get());
// Cancel the upload.
- ScheduleTask(task.get());
- CompleteTask(task.get());
+ CancelTask(task.get());
+ CompleteTask(&controller, task.get());
// Get the image again - we should have an upload task, but no dependent
// decode task, as the decode was already locked.
@@ -169,10 +178,10 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) {
EXPECT_TRUE(another_task);
EXPECT_EQ(another_task->dependencies().size(), 0u);
- ProcessTask(another_task.get());
+ ProcessTask(&controller, another_task.get());
// Finally, complete the original decode task.
- CompleteTask(task->dependencies()[0].get());
+ CompleteTask(&controller, task->dependencies()[0].get());
controller.UnrefImage(draw_image);
controller.UnrefImage(draw_image);
@@ -199,11 +208,11 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) {
EXPECT_TRUE(task->dependencies()[0]);
// Run the decode.
- ProcessTask(task->dependencies()[0].get());
+ ProcessTask(&controller, task->dependencies()[0].get());
// Cancel the upload.
- ScheduleTask(task.get());
- CompleteTask(task.get());
+ CancelTask(task.get());
+ CompleteTask(&controller, task.get());
// Unref the image.
controller.UnrefImage(draw_image);
@@ -218,8 +227,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) {
EXPECT_EQ(another_task->dependencies().size(), 1u);
EXPECT_TRUE(task->dependencies()[0]);
- ProcessTask(another_task->dependencies()[0].get());
- ProcessTask(another_task.get());
+ ProcessTask(&controller, another_task->dependencies()[0].get());
+ ProcessTask(&controller, another_task.get());
controller.UnrefImage(draw_image);
}
@@ -244,7 +253,7 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) {
EXPECT_EQ(task->dependencies().size(), 1u);
EXPECT_TRUE(task->dependencies()[0]);
- ProcessTask(task->dependencies()[0].get());
+ ProcessTask(&controller, task->dependencies()[0].get());
ScheduleTask(task.get());
RunTask(task.get());
@@ -254,7 +263,7 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) {
EXPECT_TRUE(need_unref);
EXPECT_FALSE(another_task);
- CompleteTask(task.get());
+ CompleteTask(&controller, task.get());
controller.UnrefImage(draw_image);
controller.UnrefImage(draw_image);
@@ -278,8 +287,7 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ScheduleTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
scoped_refptr<TileTask> another_task;
need_unref = controller.GetTaskForImageAndRef(
@@ -287,8 +295,9 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(another_task.get() == task.get());
- // Didn't run the task, complete it (it was canceled).
- CompleteTask(task.get());
+ // Didn't run the task, so cancel it.
+ CancelTask(task.get());
+ CompleteTask(&controller, task.get());
// Fully cancel everything (so the raster would unref things).
controller.UnrefImage(draw_image);
@@ -302,8 +311,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) {
EXPECT_TRUE(third_task);
EXPECT_FALSE(third_task.get() == task.get());
- ProcessTask(third_task->dependencies()[0].get());
- ProcessTask(third_task.get());
+ ProcessTask(&controller, third_task->dependencies()[0].get());
+ ProcessTask(&controller, third_task.get());
controller.UnrefImage(draw_image);
}
@@ -327,8 +336,7 @@ TEST(GpuImageDecodeControllerTest,
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ScheduleTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
scoped_refptr<TileTask> another_task;
need_unref = controller.GetTaskForImageAndRef(
@@ -336,8 +344,9 @@ TEST(GpuImageDecodeControllerTest,
EXPECT_TRUE(need_unref);
EXPECT_TRUE(another_task.get() == task.get());
- // Didn't run the task, complete it (it was canceled).
- CompleteTask(task.get());
+ // Didn't run the task, so cancel it.
+ CancelTask(task.get());
+ CompleteTask(&controller, task.get());
// Note that here, everything is reffed, but a new task is created. This is
// possible with repeated schedule/cancel operations.
@@ -348,8 +357,8 @@ TEST(GpuImageDecodeControllerTest,
EXPECT_TRUE(third_task);
EXPECT_FALSE(third_task.get() == task.get());
- ProcessTask(third_task->dependencies()[0].get());
- ProcessTask(third_task.get());
+ ProcessTask(&controller, third_task->dependencies()[0].get());
+ ProcessTask(&controller, third_task.get());
// 3 Unrefs!
controller.UnrefImage(draw_image);
@@ -375,10 +384,10 @@ TEST(GpuImageDecodeControllerTest, NoTaskForImageAlreadyFailedDecoding) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ScheduleTask(task.get());
- // Didn't run the task, complete it (it was canceled).
- CompleteTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
+ // Didn't run the task, so cancel it.
+ CancelTask(task.get());
+ CompleteTask(&controller, task.get());
controller.SetImageDecodingFailedForTesting(draw_image);
@@ -409,8 +418,8 @@ TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
+ ProcessTask(&controller, task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -443,8 +452,8 @@ TEST(GpuImageDecodeControllerTest, GetLargeDecodedImageForDraw) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
+ ProcessTask(&controller, task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -652,10 +661,10 @@ TEST(GpuImageDecodeControllerTest, CanceledTasksDoNotCountAgainstBudget) {
EXPECT_TRUE(task);
EXPECT_TRUE(need_unref);
- ScheduleTask(task->dependencies()[0].get());
- CompleteTask(task->dependencies()[0].get());
- ScheduleTask(task.get());
- CompleteTask(task.get());
+ CancelTask(task->dependencies()[0].get());
+ CompleteTask(&controller, task->dependencies()[0].get());
+ CancelTask(task.get());
+ CompleteTask(&controller, task.get());
controller.UnrefImage(draw_image);
EXPECT_EQ(0u, controller.GetBytesUsedForTesting());
@@ -681,8 +690,8 @@ TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) {
EXPECT_TRUE(task);
}
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
+ ProcessTask(&controller, task.get());
controller.UnrefImage(draw_image);
@@ -711,8 +720,8 @@ TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) {
EXPECT_TRUE(task);
}
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ ProcessTask(&controller, task->dependencies()[0].get());
+ ProcessTask(&controller, task.get());
// The image should be in our cache after un-ref.
controller.UnrefImage(draw_image);

Powered by Google App Engine
This is Rietveld 408576698