| 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 #include "cc/tiles/gpu_image_decode_controller.h" | 5 #include "cc/tiles/gpu_image_decode_controller.h" |
| 6 | 6 |
| 7 #include "cc/playback/draw_image.h" | 7 #include "cc/playback/draw_image.h" |
| 8 #include "cc/raster/tile_task.h" | 8 #include "cc/raster/tile_task.h" |
| 9 #include "cc/test/test_context_provider.h" | 9 #include "cc/test/test_context_provider.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 if (!is_decomposable) { | 35 if (!is_decomposable) { |
| 36 // Perspective is not decomposable, add it. | 36 // Perspective is not decomposable, add it. |
| 37 matrix[SkMatrix::kMPersp0] = 0.1f; | 37 matrix[SkMatrix::kMPersp0] = 0.1f; |
| 38 } | 38 } |
| 39 | 39 |
| 40 return matrix; | 40 return matrix; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ScheduleTask(TileTask* task) { | 43 void ScheduleTask(TileTask* task) { |
| 44 task->WillSchedule(); | 44 task->state().DidSchedule(); |
| 45 task->ScheduleOnOriginThread(nullptr); | |
| 46 task->DidSchedule(); | |
| 47 } | 45 } |
| 48 | 46 |
| 47 // Before running the task it must be scheduled. Call ScheduleTask() before |
| 48 // calling this function. |
| 49 void RunTask(TileTask* task) { | 49 void RunTask(TileTask* task) { |
| 50 // TODO(prashant.n): Once ScheduleOnOriginThread() and | |
| 51 // CompleteOnOriginThread() functions are removed, modify this function | |
| 52 // accordingly. (crbug.com/599863) | |
| 53 task->state().DidSchedule(); | |
| 54 task->state().DidStart(); | 50 task->state().DidStart(); |
| 55 task->RunOnWorkerThread(); | 51 task->RunOnWorkerThread(); |
| 56 task->state().DidFinish(); | 52 task->state().DidFinish(); |
| 57 } | 53 } |
| 58 | 54 |
| 59 void CompleteTask(TileTask* task) { | 55 void CompleteTask(TileTask* task) { |
| 60 task->WillComplete(); | 56 DCHECK(task->state().IsFinished() || task->state().IsCanceled()); |
| 61 task->CompleteOnOriginThread(nullptr); | 57 task->OnTaskCompleted(); |
| 62 task->DidComplete(); | 58 } |
| 59 |
| 60 void CancelTask(TileTask* task) { |
| 61 task->state().DidCancel(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 void ProcessTask(TileTask* task) { | 64 void ProcessTask(TileTask* task) { |
| 66 ScheduleTask(task); | 65 ScheduleTask(task); |
| 67 RunTask(task); | 66 RunTask(task); |
| 68 CompleteTask(task); | 67 CompleteTask(task); |
| 69 } | 68 } |
| 70 | 69 |
| 71 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { | 70 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { |
| 72 auto context_provider = TestContextProvider::Create(); | 71 auto context_provider = TestContextProvider::Create(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 EXPECT_TRUE(need_unref); | 155 EXPECT_TRUE(need_unref); |
| 157 EXPECT_TRUE(task); | 156 EXPECT_TRUE(task); |
| 158 EXPECT_EQ(task->dependencies().size(), 1u); | 157 EXPECT_EQ(task->dependencies().size(), 1u); |
| 159 EXPECT_TRUE(task->dependencies()[0]); | 158 EXPECT_TRUE(task->dependencies()[0]); |
| 160 | 159 |
| 161 // Run the decode but don't complete it (this will keep the decode locked). | 160 // Run the decode but don't complete it (this will keep the decode locked). |
| 162 ScheduleTask(task->dependencies()[0].get()); | 161 ScheduleTask(task->dependencies()[0].get()); |
| 163 RunTask(task->dependencies()[0].get()); | 162 RunTask(task->dependencies()[0].get()); |
| 164 | 163 |
| 165 // Cancel the upload. | 164 // Cancel the upload. |
| 166 ScheduleTask(task.get()); | 165 CancelTask(task.get()); |
| 167 CompleteTask(task.get()); | 166 CompleteTask(task.get()); |
| 168 | 167 |
| 169 // Get the image again - we should have an upload task, but no dependent | 168 // Get the image again - we should have an upload task, but no dependent |
| 170 // decode task, as the decode was already locked. | 169 // decode task, as the decode was already locked. |
| 171 scoped_refptr<TileTask> another_task; | 170 scoped_refptr<TileTask> another_task; |
| 172 need_unref = controller.GetTaskForImageAndRef( | 171 need_unref = controller.GetTaskForImageAndRef( |
| 173 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 172 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
| 174 EXPECT_TRUE(need_unref); | 173 EXPECT_TRUE(need_unref); |
| 175 EXPECT_TRUE(another_task); | 174 EXPECT_TRUE(another_task); |
| 176 EXPECT_EQ(another_task->dependencies().size(), 0u); | 175 EXPECT_EQ(another_task->dependencies().size(), 0u); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 200 draw_image, ImageDecodeController::TracingInfo(), &task); | 199 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 201 EXPECT_TRUE(need_unref); | 200 EXPECT_TRUE(need_unref); |
| 202 EXPECT_TRUE(task); | 201 EXPECT_TRUE(task); |
| 203 EXPECT_EQ(task->dependencies().size(), 1u); | 202 EXPECT_EQ(task->dependencies().size(), 1u); |
| 204 EXPECT_TRUE(task->dependencies()[0]); | 203 EXPECT_TRUE(task->dependencies()[0]); |
| 205 | 204 |
| 206 // Run the decode. | 205 // Run the decode. |
| 207 ProcessTask(task->dependencies()[0].get()); | 206 ProcessTask(task->dependencies()[0].get()); |
| 208 | 207 |
| 209 // Cancel the upload. | 208 // Cancel the upload. |
| 210 ScheduleTask(task.get()); | 209 CancelTask(task.get()); |
| 211 CompleteTask(task.get()); | 210 CompleteTask(task.get()); |
| 212 | 211 |
| 213 // Unref the image. | 212 // Unref the image. |
| 214 controller.UnrefImage(draw_image); | 213 controller.UnrefImage(draw_image); |
| 215 | 214 |
| 216 // Get the image again - we should have an upload task and a dependent decode | 215 // Get the image again - we should have an upload task and a dependent decode |
| 217 // task - this dependent task will typically just re-lock the image. | 216 // task - this dependent task will typically just re-lock the image. |
| 218 scoped_refptr<TileTask> another_task; | 217 scoped_refptr<TileTask> another_task; |
| 219 need_unref = controller.GetTaskForImageAndRef( | 218 need_unref = controller.GetTaskForImageAndRef( |
| 220 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 219 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 274 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 276 quality, | 275 quality, |
| 277 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 276 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
| 278 scoped_refptr<TileTask> task; | 277 scoped_refptr<TileTask> task; |
| 279 bool need_unref = controller.GetTaskForImageAndRef( | 278 bool need_unref = controller.GetTaskForImageAndRef( |
| 280 draw_image, ImageDecodeController::TracingInfo(), &task); | 279 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 281 EXPECT_TRUE(need_unref); | 280 EXPECT_TRUE(need_unref); |
| 282 EXPECT_TRUE(task); | 281 EXPECT_TRUE(task); |
| 283 | 282 |
| 284 ProcessTask(task->dependencies()[0].get()); | 283 ProcessTask(task->dependencies()[0].get()); |
| 285 ScheduleTask(task.get()); | |
| 286 | 284 |
| 287 scoped_refptr<TileTask> another_task; | 285 scoped_refptr<TileTask> another_task; |
| 288 need_unref = controller.GetTaskForImageAndRef( | 286 need_unref = controller.GetTaskForImageAndRef( |
| 289 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 287 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
| 290 EXPECT_TRUE(need_unref); | 288 EXPECT_TRUE(need_unref); |
| 291 EXPECT_TRUE(another_task.get() == task.get()); | 289 EXPECT_TRUE(another_task.get() == task.get()); |
| 292 | 290 |
| 293 // Didn't run the task, complete it (it was canceled). | 291 // Didn't run the task, so cancel it. |
| 292 CancelTask(task.get()); |
| 294 CompleteTask(task.get()); | 293 CompleteTask(task.get()); |
| 295 | 294 |
| 296 // Fully cancel everything (so the raster would unref things). | 295 // Fully cancel everything (so the raster would unref things). |
| 297 controller.UnrefImage(draw_image); | 296 controller.UnrefImage(draw_image); |
| 298 controller.UnrefImage(draw_image); | 297 controller.UnrefImage(draw_image); |
| 299 | 298 |
| 300 // Here a new task is created. | 299 // Here a new task is created. |
| 301 scoped_refptr<TileTask> third_task; | 300 scoped_refptr<TileTask> third_task; |
| 302 need_unref = controller.GetTaskForImageAndRef( | 301 need_unref = controller.GetTaskForImageAndRef( |
| 303 draw_image, ImageDecodeController::TracingInfo(), &third_task); | 302 draw_image, ImageDecodeController::TracingInfo(), &third_task); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 322 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 324 quality, | 323 quality, |
| 325 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 324 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
| 326 scoped_refptr<TileTask> task; | 325 scoped_refptr<TileTask> task; |
| 327 bool need_unref = controller.GetTaskForImageAndRef( | 326 bool need_unref = controller.GetTaskForImageAndRef( |
| 328 draw_image, ImageDecodeController::TracingInfo(), &task); | 327 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 329 EXPECT_TRUE(need_unref); | 328 EXPECT_TRUE(need_unref); |
| 330 EXPECT_TRUE(task); | 329 EXPECT_TRUE(task); |
| 331 | 330 |
| 332 ProcessTask(task->dependencies()[0].get()); | 331 ProcessTask(task->dependencies()[0].get()); |
| 333 ScheduleTask(task.get()); | |
| 334 | 332 |
| 335 scoped_refptr<TileTask> another_task; | 333 scoped_refptr<TileTask> another_task; |
| 336 need_unref = controller.GetTaskForImageAndRef( | 334 need_unref = controller.GetTaskForImageAndRef( |
| 337 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 335 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
| 338 EXPECT_TRUE(need_unref); | 336 EXPECT_TRUE(need_unref); |
| 339 EXPECT_TRUE(another_task.get() == task.get()); | 337 EXPECT_TRUE(another_task.get() == task.get()); |
| 340 | 338 |
| 341 // Didn't run the task, complete it (it was canceled). | 339 // Didn't run the task, so cancel it. |
| 340 CancelTask(task.get()); |
| 342 CompleteTask(task.get()); | 341 CompleteTask(task.get()); |
| 343 | 342 |
| 344 // Note that here, everything is reffed, but a new task is created. This is | 343 // Note that here, everything is reffed, but a new task is created. This is |
| 345 // possible with repeated schedule/cancel operations. | 344 // possible with repeated schedule/cancel operations. |
| 346 scoped_refptr<TileTask> third_task; | 345 scoped_refptr<TileTask> third_task; |
| 347 need_unref = controller.GetTaskForImageAndRef( | 346 need_unref = controller.GetTaskForImageAndRef( |
| 348 draw_image, ImageDecodeController::TracingInfo(), &third_task); | 347 draw_image, ImageDecodeController::TracingInfo(), &third_task); |
| 349 EXPECT_TRUE(need_unref); | 348 EXPECT_TRUE(need_unref); |
| 350 EXPECT_TRUE(third_task); | 349 EXPECT_TRUE(third_task); |
| 351 EXPECT_FALSE(third_task.get() == task.get()); | 350 EXPECT_FALSE(third_task.get() == task.get()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 370 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 369 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 371 quality, | 370 quality, |
| 372 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 371 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
| 373 scoped_refptr<TileTask> task; | 372 scoped_refptr<TileTask> task; |
| 374 bool need_unref = controller.GetTaskForImageAndRef( | 373 bool need_unref = controller.GetTaskForImageAndRef( |
| 375 draw_image, ImageDecodeController::TracingInfo(), &task); | 374 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 376 EXPECT_TRUE(need_unref); | 375 EXPECT_TRUE(need_unref); |
| 377 EXPECT_TRUE(task); | 376 EXPECT_TRUE(task); |
| 378 | 377 |
| 379 ProcessTask(task->dependencies()[0].get()); | 378 ProcessTask(task->dependencies()[0].get()); |
| 380 ScheduleTask(task.get()); | 379 // Didn't run the task, so cancel it. |
| 381 // Didn't run the task, complete it (it was canceled). | 380 CancelTask(task.get()); |
| 382 CompleteTask(task.get()); | 381 CompleteTask(task.get()); |
| 383 | 382 |
| 384 controller.SetImageDecodingFailedForTesting(draw_image); | 383 controller.SetImageDecodingFailedForTesting(draw_image); |
| 385 | 384 |
| 386 scoped_refptr<TileTask> another_task; | 385 scoped_refptr<TileTask> another_task; |
| 387 need_unref = controller.GetTaskForImageAndRef( | 386 need_unref = controller.GetTaskForImageAndRef( |
| 388 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 387 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
| 389 EXPECT_FALSE(need_unref); | 388 EXPECT_FALSE(need_unref); |
| 390 EXPECT_EQ(another_task.get(), nullptr); | 389 EXPECT_EQ(another_task.get(), nullptr); |
| 391 | 390 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, | 680 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, |
| 682 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 681 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
| 683 | 682 |
| 684 scoped_refptr<TileTask> task; | 683 scoped_refptr<TileTask> task; |
| 685 bool need_unref = controller.GetTaskForImageAndRef( | 684 bool need_unref = controller.GetTaskForImageAndRef( |
| 686 draw_image, ImageDecodeController::TracingInfo(), &task); | 685 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 687 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); | 686 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); |
| 688 EXPECT_TRUE(task); | 687 EXPECT_TRUE(task); |
| 689 EXPECT_TRUE(need_unref); | 688 EXPECT_TRUE(need_unref); |
| 690 | 689 |
| 691 ScheduleTask(task->dependencies()[0].get()); | 690 CancelTask(task->dependencies()[0].get()); |
| 692 CompleteTask(task->dependencies()[0].get()); | 691 CompleteTask(task->dependencies()[0].get()); |
| 693 ScheduleTask(task.get()); | 692 CancelTask(task.get()); |
| 694 CompleteTask(task.get()); | 693 CompleteTask(task.get()); |
| 695 | 694 |
| 696 controller.UnrefImage(draw_image); | 695 controller.UnrefImage(draw_image); |
| 697 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); | 696 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); |
| 698 } | 697 } |
| 699 | 698 |
| 700 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { | 699 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { |
| 701 auto context_provider = TestContextProvider::Create(); | 700 auto context_provider = TestContextProvider::Create(); |
| 702 context_provider->BindToCurrentThread(); | 701 context_provider->BindToCurrentThread(); |
| 703 TestGpuImageDecodeController controller(context_provider.get()); | 702 TestGpuImageDecodeController controller(context_provider.get()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 ProcessTask(task->dependencies()[0].get()); | 748 ProcessTask(task->dependencies()[0].get()); |
| 750 ProcessTask(task.get()); | 749 ProcessTask(task.get()); |
| 751 | 750 |
| 752 // The image should be in our cache after un-ref. | 751 // The image should be in our cache after un-ref. |
| 753 controller.UnrefImage(draw_image); | 752 controller.UnrefImage(draw_image); |
| 754 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 753 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
| 755 } | 754 } |
| 756 | 755 |
| 757 } // namespace | 756 } // namespace |
| 758 } // namespace cc | 757 } // namespace cc |
| OLD | NEW |