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

Side by Side 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 unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 25
26 if (!is_decomposable) { 26 if (!is_decomposable) {
27 // Perspective is not decomposable, add it. 27 // Perspective is not decomposable, add it.
28 matrix[SkMatrix::kMPersp0] = 0.1f; 28 matrix[SkMatrix::kMPersp0] = 0.1f;
29 } 29 }
30 30
31 return matrix; 31 return matrix;
32 } 32 }
33 33
34 void ScheduleTask(TileTask* task) { 34 void ScheduleTask(TileTask* task) {
35 task->WillSchedule(); 35 task->state().DidSchedule();
36 task->ScheduleOnOriginThread(nullptr);
37 task->DidSchedule();
38 } 36 }
39 37
38 // Before running the task it must be scheduled. Call ScheduleTask() before
39 // calling this function.
40 void RunTask(TileTask* task) { 40 void RunTask(TileTask* task) {
41 // TODO(prashant.n): Once ScheduleOnOriginThread() and
42 // CompleteOnOriginThread() functions are removed, modify this function
43 // accordingly. (crbug.com/599863)
44 task->state().DidSchedule();
45 task->state().DidStart(); 41 task->state().DidStart();
46 task->RunOnWorkerThread(); 42 task->RunOnWorkerThread();
47 task->state().DidFinish(); 43 task->state().DidFinish();
48 } 44 }
49 45
50 void CompleteTask(TileTask* task) { 46 void CompleteTask(TileTask* task) {
51 task->WillComplete(); 47 DCHECK(task->state().IsFinished() || task->state().IsCanceled());
52 task->CompleteOnOriginThread(nullptr); 48 task->OnTaskCompleted();
53 task->DidComplete(); 49 }
50
51 void CancelTask(TileTask* task) {
52 task->state().DidCancel();
54 } 53 }
55 54
56 void ProcessTask(TileTask* task) { 55 void ProcessTask(TileTask* task) {
57 ScheduleTask(task); 56 ScheduleTask(task);
58 RunTask(task); 57 RunTask(task);
59 CompleteTask(task); 58 CompleteTask(task);
60 } 59 }
61 60
62 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { 61 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) {
63 auto context_provider = TestContextProvider::Create(); 62 auto context_provider = TestContextProvider::Create();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 EXPECT_TRUE(need_unref); 149 EXPECT_TRUE(need_unref);
151 EXPECT_TRUE(task); 150 EXPECT_TRUE(task);
152 EXPECT_EQ(task->dependencies().size(), 1u); 151 EXPECT_EQ(task->dependencies().size(), 1u);
153 EXPECT_TRUE(task->dependencies()[0]); 152 EXPECT_TRUE(task->dependencies()[0]);
154 153
155 // Run the decode but don't complete it (this will keep the decode locked). 154 // Run the decode but don't complete it (this will keep the decode locked).
156 ScheduleTask(task->dependencies()[0].get()); 155 ScheduleTask(task->dependencies()[0].get());
157 RunTask(task->dependencies()[0].get()); 156 RunTask(task->dependencies()[0].get());
158 157
159 // Cancel the upload. 158 // Cancel the upload.
160 ScheduleTask(task.get()); 159 CancelTask(task.get());
161 CompleteTask(task.get()); 160 CompleteTask(task.get());
162 161
163 // Get the image again - we should have an upload task, but no dependent 162 // Get the image again - we should have an upload task, but no dependent
164 // decode task, as the decode was already locked. 163 // decode task, as the decode was already locked.
165 scoped_refptr<TileTask> another_task; 164 scoped_refptr<TileTask> another_task;
166 need_unref = controller.GetTaskForImageAndRef( 165 need_unref = controller.GetTaskForImageAndRef(
167 draw_image, ImageDecodeController::TracingInfo(), &another_task); 166 draw_image, ImageDecodeController::TracingInfo(), &another_task);
168 EXPECT_TRUE(need_unref); 167 EXPECT_TRUE(need_unref);
169 EXPECT_TRUE(another_task); 168 EXPECT_TRUE(another_task);
170 EXPECT_EQ(another_task->dependencies().size(), 0u); 169 EXPECT_EQ(another_task->dependencies().size(), 0u);
(...skipping 24 matching lines...) Expand all
195 draw_image, ImageDecodeController::TracingInfo(), &task); 194 draw_image, ImageDecodeController::TracingInfo(), &task);
196 EXPECT_TRUE(need_unref); 195 EXPECT_TRUE(need_unref);
197 EXPECT_TRUE(task); 196 EXPECT_TRUE(task);
198 EXPECT_EQ(task->dependencies().size(), 1u); 197 EXPECT_EQ(task->dependencies().size(), 1u);
199 EXPECT_TRUE(task->dependencies()[0]); 198 EXPECT_TRUE(task->dependencies()[0]);
200 199
201 // Run the decode. 200 // Run the decode.
202 ProcessTask(task->dependencies()[0].get()); 201 ProcessTask(task->dependencies()[0].get());
203 202
204 // Cancel the upload. 203 // Cancel the upload.
205 ScheduleTask(task.get()); 204 CancelTask(task.get());
206 CompleteTask(task.get()); 205 CompleteTask(task.get());
207 206
208 // Unref the image. 207 // Unref the image.
209 controller.UnrefImage(draw_image); 208 controller.UnrefImage(draw_image);
210 209
211 // Get the image again - we should have an upload task and a dependent decode 210 // Get the image again - we should have an upload task and a dependent decode
212 // task - this dependent task will typically just re-lock the image. 211 // task - this dependent task will typically just re-lock the image.
213 scoped_refptr<TileTask> another_task; 212 scoped_refptr<TileTask> another_task;
214 need_unref = controller.GetTaskForImageAndRef( 213 need_unref = controller.GetTaskForImageAndRef(
215 draw_image, ImageDecodeController::TracingInfo(), &another_task); 214 draw_image, ImageDecodeController::TracingInfo(), &another_task);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), 271 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()),
273 quality, 272 quality,
274 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); 273 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable));
275 scoped_refptr<TileTask> task; 274 scoped_refptr<TileTask> task;
276 bool need_unref = controller.GetTaskForImageAndRef( 275 bool need_unref = controller.GetTaskForImageAndRef(
277 draw_image, ImageDecodeController::TracingInfo(), &task); 276 draw_image, ImageDecodeController::TracingInfo(), &task);
278 EXPECT_TRUE(need_unref); 277 EXPECT_TRUE(need_unref);
279 EXPECT_TRUE(task); 278 EXPECT_TRUE(task);
280 279
281 ProcessTask(task->dependencies()[0].get()); 280 ProcessTask(task->dependencies()[0].get());
282 ScheduleTask(task.get());
283 281
284 scoped_refptr<TileTask> another_task; 282 scoped_refptr<TileTask> another_task;
285 need_unref = controller.GetTaskForImageAndRef( 283 need_unref = controller.GetTaskForImageAndRef(
286 draw_image, ImageDecodeController::TracingInfo(), &another_task); 284 draw_image, ImageDecodeController::TracingInfo(), &another_task);
287 EXPECT_TRUE(need_unref); 285 EXPECT_TRUE(need_unref);
288 EXPECT_TRUE(another_task.get() == task.get()); 286 EXPECT_TRUE(another_task.get() == task.get());
289 287
290 // Didn't run the task, complete it (it was canceled). 288 // Didn't run the task, so cancel it.
289 CancelTask(task.get());
291 CompleteTask(task.get()); 290 CompleteTask(task.get());
292 291
293 // Fully cancel everything (so the raster would unref things). 292 // Fully cancel everything (so the raster would unref things).
294 controller.UnrefImage(draw_image); 293 controller.UnrefImage(draw_image);
295 controller.UnrefImage(draw_image); 294 controller.UnrefImage(draw_image);
296 295
297 // Here a new task is created. 296 // Here a new task is created.
298 scoped_refptr<TileTask> third_task; 297 scoped_refptr<TileTask> third_task;
299 need_unref = controller.GetTaskForImageAndRef( 298 need_unref = controller.GetTaskForImageAndRef(
300 draw_image, ImageDecodeController::TracingInfo(), &third_task); 299 draw_image, ImageDecodeController::TracingInfo(), &third_task);
(...skipping 20 matching lines...) Expand all
321 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), 320 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()),
322 quality, 321 quality,
323 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); 322 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable));
324 scoped_refptr<TileTask> task; 323 scoped_refptr<TileTask> task;
325 bool need_unref = controller.GetTaskForImageAndRef( 324 bool need_unref = controller.GetTaskForImageAndRef(
326 draw_image, ImageDecodeController::TracingInfo(), &task); 325 draw_image, ImageDecodeController::TracingInfo(), &task);
327 EXPECT_TRUE(need_unref); 326 EXPECT_TRUE(need_unref);
328 EXPECT_TRUE(task); 327 EXPECT_TRUE(task);
329 328
330 ProcessTask(task->dependencies()[0].get()); 329 ProcessTask(task->dependencies()[0].get());
331 ScheduleTask(task.get());
332 330
333 scoped_refptr<TileTask> another_task; 331 scoped_refptr<TileTask> another_task;
334 need_unref = controller.GetTaskForImageAndRef( 332 need_unref = controller.GetTaskForImageAndRef(
335 draw_image, ImageDecodeController::TracingInfo(), &another_task); 333 draw_image, ImageDecodeController::TracingInfo(), &another_task);
336 EXPECT_TRUE(need_unref); 334 EXPECT_TRUE(need_unref);
337 EXPECT_TRUE(another_task.get() == task.get()); 335 EXPECT_TRUE(another_task.get() == task.get());
338 336
339 // Didn't run the task, complete it (it was canceled). 337 // Didn't run the task, so cancel it.
338 CancelTask(task.get());
340 CompleteTask(task.get()); 339 CompleteTask(task.get());
341 340
342 // Note that here, everything is reffed, but a new task is created. This is 341 // Note that here, everything is reffed, but a new task is created. This is
343 // possible with repeated schedule/cancel operations. 342 // possible with repeated schedule/cancel operations.
344 scoped_refptr<TileTask> third_task; 343 scoped_refptr<TileTask> third_task;
345 need_unref = controller.GetTaskForImageAndRef( 344 need_unref = controller.GetTaskForImageAndRef(
346 draw_image, ImageDecodeController::TracingInfo(), &third_task); 345 draw_image, ImageDecodeController::TracingInfo(), &third_task);
347 EXPECT_TRUE(need_unref); 346 EXPECT_TRUE(need_unref);
348 EXPECT_TRUE(third_task); 347 EXPECT_TRUE(third_task);
349 EXPECT_FALSE(third_task.get() == task.get()); 348 EXPECT_FALSE(third_task.get() == task.get());
(...skipping 19 matching lines...) Expand all
369 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), 368 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()),
370 quality, 369 quality,
371 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); 370 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable));
372 scoped_refptr<TileTask> task; 371 scoped_refptr<TileTask> task;
373 bool need_unref = controller.GetTaskForImageAndRef( 372 bool need_unref = controller.GetTaskForImageAndRef(
374 draw_image, ImageDecodeController::TracingInfo(), &task); 373 draw_image, ImageDecodeController::TracingInfo(), &task);
375 EXPECT_TRUE(need_unref); 374 EXPECT_TRUE(need_unref);
376 EXPECT_TRUE(task); 375 EXPECT_TRUE(task);
377 376
378 ProcessTask(task->dependencies()[0].get()); 377 ProcessTask(task->dependencies()[0].get());
379 ScheduleTask(task.get()); 378 // Didn't run the task, so cancel it.
380 // Didn't run the task, complete it (it was canceled). 379 CancelTask(task.get());
381 CompleteTask(task.get()); 380 CompleteTask(task.get());
382 381
383 controller.SetImageDecodingFailedForTesting(draw_image); 382 controller.SetImageDecodingFailedForTesting(draw_image);
384 383
385 scoped_refptr<TileTask> another_task; 384 scoped_refptr<TileTask> another_task;
386 need_unref = controller.GetTaskForImageAndRef( 385 need_unref = controller.GetTaskForImageAndRef(
387 draw_image, ImageDecodeController::TracingInfo(), &another_task); 386 draw_image, ImageDecodeController::TracingInfo(), &another_task);
388 EXPECT_FALSE(need_unref); 387 EXPECT_FALSE(need_unref);
389 EXPECT_EQ(another_task.get(), nullptr); 388 EXPECT_EQ(another_task.get(), nullptr);
390 389
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, 644 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality,
646 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); 645 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable));
647 646
648 scoped_refptr<TileTask> task; 647 scoped_refptr<TileTask> task;
649 bool need_unref = controller.GetTaskForImageAndRef( 648 bool need_unref = controller.GetTaskForImageAndRef(
650 draw_image, ImageDecodeController::TracingInfo(), &task); 649 draw_image, ImageDecodeController::TracingInfo(), &task);
651 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); 650 EXPECT_NE(0u, controller.GetBytesUsedForTesting());
652 EXPECT_TRUE(task); 651 EXPECT_TRUE(task);
653 EXPECT_TRUE(need_unref); 652 EXPECT_TRUE(need_unref);
654 653
655 ScheduleTask(task->dependencies()[0].get()); 654 CancelTask(task->dependencies()[0].get());
656 CompleteTask(task->dependencies()[0].get()); 655 CompleteTask(task->dependencies()[0].get());
657 ScheduleTask(task.get()); 656 CancelTask(task.get());
658 CompleteTask(task.get()); 657 CompleteTask(task.get());
659 658
660 controller.UnrefImage(draw_image); 659 controller.UnrefImage(draw_image);
661 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); 660 EXPECT_EQ(0u, controller.GetBytesUsedForTesting());
662 } 661 }
663 662
664 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { 663 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) {
665 auto context_provider = TestContextProvider::Create(); 664 auto context_provider = TestContextProvider::Create();
666 context_provider->BindToCurrentThread(); 665 context_provider->BindToCurrentThread();
667 GpuImageDecodeController controller(context_provider.get(), 666 GpuImageDecodeController controller(context_provider.get(),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 ProcessTask(task->dependencies()[0].get()); 713 ProcessTask(task->dependencies()[0].get());
715 ProcessTask(task.get()); 714 ProcessTask(task.get());
716 715
717 // The image should be in our cache after un-ref. 716 // The image should be in our cache after un-ref.
718 controller.UnrefImage(draw_image); 717 controller.UnrefImage(draw_image);
719 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); 718 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u);
720 } 719 }
721 720
722 } // namespace 721 } // namespace
723 } // namespace cc 722 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698