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_runner.h" | 8 #include "cc/raster/tile_task_runner.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" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 namespace { | 13 namespace { |
14 | 14 |
15 skia::RefPtr<SkImage> CreateImage(int width, int height) { | 15 sk_sp<SkImage> CreateImage(int width, int height) { |
16 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 16 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
17 SkBitmap bitmap; | 17 SkBitmap bitmap; |
18 bitmap.allocPixels(info); | 18 bitmap.allocPixels(info); |
19 return skia::AdoptRef(SkImage::NewFromBitmap(bitmap)); | 19 return SkImage::MakeFromBitmap(bitmap); |
20 } | 20 } |
21 | 21 |
22 SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) { | 22 SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) { |
23 SkMatrix matrix; | 23 SkMatrix matrix; |
24 matrix.setScale(scale.width(), scale.height()); | 24 matrix.setScale(scale.width(), scale.height()); |
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 } |
(...skipping 23 matching lines...) Expand all Loading... |
53 ScheduleTask(task); | 53 ScheduleTask(task); |
54 RunTask(task); | 54 RunTask(task); |
55 CompleteTask(task); | 55 CompleteTask(task); |
56 } | 56 } |
57 | 57 |
58 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { | 58 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { |
59 auto context_provider = TestContextProvider::Create(); | 59 auto context_provider = TestContextProvider::Create(); |
60 context_provider->BindToCurrentThread(); | 60 context_provider->BindToCurrentThread(); |
61 GpuImageDecodeController controller(context_provider.get(), | 61 GpuImageDecodeController controller(context_provider.get(), |
62 ResourceFormat::RGBA_8888); | 62 ResourceFormat::RGBA_8888); |
63 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 63 sk_sp<SkImage> image = CreateImage(100, 100); |
64 bool is_decomposable = true; | 64 bool is_decomposable = true; |
65 SkFilterQuality quality = kHigh_SkFilterQuality; | 65 SkFilterQuality quality = kHigh_SkFilterQuality; |
66 uint64_t prepare_tiles_id = 1; | 66 uint64_t prepare_tiles_id = 1; |
67 | 67 |
68 DrawImage draw_image( | 68 DrawImage draw_image( |
69 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 69 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
70 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 70 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
71 scoped_refptr<ImageDecodeTask> task; | 71 scoped_refptr<ImageDecodeTask> task; |
72 bool need_unref = | 72 bool need_unref = |
73 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 73 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
(...skipping 18 matching lines...) Expand all Loading... |
92 | 92 |
93 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { | 93 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { |
94 auto context_provider = TestContextProvider::Create(); | 94 auto context_provider = TestContextProvider::Create(); |
95 context_provider->BindToCurrentThread(); | 95 context_provider->BindToCurrentThread(); |
96 GpuImageDecodeController controller(context_provider.get(), | 96 GpuImageDecodeController controller(context_provider.get(), |
97 ResourceFormat::RGBA_8888); | 97 ResourceFormat::RGBA_8888); |
98 bool is_decomposable = true; | 98 bool is_decomposable = true; |
99 uint64_t prepare_tiles_id = 1; | 99 uint64_t prepare_tiles_id = 1; |
100 SkFilterQuality quality = kHigh_SkFilterQuality; | 100 SkFilterQuality quality = kHigh_SkFilterQuality; |
101 | 101 |
102 skia::RefPtr<SkImage> first_image = CreateImage(100, 100); | 102 sk_sp<SkImage> first_image = CreateImage(100, 100); |
103 DrawImage first_draw_image( | 103 DrawImage first_draw_image( |
104 first_image.get(), | 104 first_image.get(), |
105 SkIRect::MakeWH(first_image->width(), first_image->height()), quality, | 105 SkIRect::MakeWH(first_image->width(), first_image->height()), quality, |
106 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 106 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
107 scoped_refptr<ImageDecodeTask> first_task; | 107 scoped_refptr<ImageDecodeTask> first_task; |
108 bool need_unref = controller.GetTaskForImageAndRef( | 108 bool need_unref = controller.GetTaskForImageAndRef( |
109 first_draw_image, prepare_tiles_id, &first_task); | 109 first_draw_image, prepare_tiles_id, &first_task); |
110 EXPECT_TRUE(need_unref); | 110 EXPECT_TRUE(need_unref); |
111 EXPECT_TRUE(first_task); | 111 EXPECT_TRUE(first_task); |
112 | 112 |
113 skia::RefPtr<SkImage> second_image = CreateImage(100, 100); | 113 sk_sp<SkImage> second_image = CreateImage(100, 100); |
114 DrawImage second_draw_image( | 114 DrawImage second_draw_image( |
115 second_image.get(), | 115 second_image.get(), |
116 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, | 116 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, |
117 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); | 117 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); |
118 scoped_refptr<ImageDecodeTask> second_task; | 118 scoped_refptr<ImageDecodeTask> second_task; |
119 need_unref = controller.GetTaskForImageAndRef(second_draw_image, | 119 need_unref = controller.GetTaskForImageAndRef(second_draw_image, |
120 prepare_tiles_id, &second_task); | 120 prepare_tiles_id, &second_task); |
121 EXPECT_TRUE(need_unref); | 121 EXPECT_TRUE(need_unref); |
122 EXPECT_TRUE(second_task); | 122 EXPECT_TRUE(second_task); |
123 EXPECT_TRUE(first_task.get() != second_task.get()); | 123 EXPECT_TRUE(first_task.get() != second_task.get()); |
124 | 124 |
125 ProcessTask(first_task->dependency().get()); | 125 ProcessTask(first_task->dependency().get()); |
126 ProcessTask(first_task.get()); | 126 ProcessTask(first_task.get()); |
127 ProcessTask(second_task->dependency().get()); | 127 ProcessTask(second_task->dependency().get()); |
128 ProcessTask(second_task.get()); | 128 ProcessTask(second_task.get()); |
129 | 129 |
130 controller.UnrefImage(first_draw_image); | 130 controller.UnrefImage(first_draw_image); |
131 controller.UnrefImage(second_draw_image); | 131 controller.UnrefImage(second_draw_image); |
132 } | 132 } |
133 | 133 |
134 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecoded) { | 134 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecoded) { |
135 auto context_provider = TestContextProvider::Create(); | 135 auto context_provider = TestContextProvider::Create(); |
136 context_provider->BindToCurrentThread(); | 136 context_provider->BindToCurrentThread(); |
137 GpuImageDecodeController controller(context_provider.get(), | 137 GpuImageDecodeController controller(context_provider.get(), |
138 ResourceFormat::RGBA_8888); | 138 ResourceFormat::RGBA_8888); |
139 bool is_decomposable = true; | 139 bool is_decomposable = true; |
140 uint64_t prepare_tiles_id = 1; | 140 uint64_t prepare_tiles_id = 1; |
141 SkFilterQuality quality = kHigh_SkFilterQuality; | 141 SkFilterQuality quality = kHigh_SkFilterQuality; |
142 | 142 |
143 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 143 sk_sp<SkImage> image = CreateImage(100, 100); |
144 DrawImage draw_image( | 144 DrawImage draw_image( |
145 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 145 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
146 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 146 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
147 scoped_refptr<ImageDecodeTask> task; | 147 scoped_refptr<ImageDecodeTask> task; |
148 bool need_unref = | 148 bool need_unref = |
149 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 149 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
150 EXPECT_TRUE(need_unref); | 150 EXPECT_TRUE(need_unref); |
151 EXPECT_TRUE(task); | 151 EXPECT_TRUE(task); |
152 EXPECT_TRUE(task->dependency()); | 152 EXPECT_TRUE(task->dependency()); |
153 | 153 |
(...skipping 15 matching lines...) Expand all Loading... |
169 | 169 |
170 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { | 170 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { |
171 auto context_provider = TestContextProvider::Create(); | 171 auto context_provider = TestContextProvider::Create(); |
172 context_provider->BindToCurrentThread(); | 172 context_provider->BindToCurrentThread(); |
173 GpuImageDecodeController controller(context_provider.get(), | 173 GpuImageDecodeController controller(context_provider.get(), |
174 ResourceFormat::RGBA_8888); | 174 ResourceFormat::RGBA_8888); |
175 bool is_decomposable = true; | 175 bool is_decomposable = true; |
176 uint64_t prepare_tiles_id = 1; | 176 uint64_t prepare_tiles_id = 1; |
177 SkFilterQuality quality = kHigh_SkFilterQuality; | 177 SkFilterQuality quality = kHigh_SkFilterQuality; |
178 | 178 |
179 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 179 sk_sp<SkImage> image = CreateImage(100, 100); |
180 DrawImage draw_image( | 180 DrawImage draw_image( |
181 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 181 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
182 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 182 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
183 scoped_refptr<ImageDecodeTask> task; | 183 scoped_refptr<ImageDecodeTask> task; |
184 bool need_unref = | 184 bool need_unref = |
185 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 185 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
186 EXPECT_TRUE(need_unref); | 186 EXPECT_TRUE(need_unref); |
187 EXPECT_TRUE(task); | 187 EXPECT_TRUE(task); |
188 | 188 |
189 ProcessTask(task->dependency().get()); | 189 ProcessTask(task->dependency().get()); |
(...skipping 29 matching lines...) Expand all Loading... |
219 TEST(GpuImageDecodeControllerTest, | 219 TEST(GpuImageDecodeControllerTest, |
220 GetTaskForImageCanceledWhileReffedGetsNewTask) { | 220 GetTaskForImageCanceledWhileReffedGetsNewTask) { |
221 auto context_provider = TestContextProvider::Create(); | 221 auto context_provider = TestContextProvider::Create(); |
222 context_provider->BindToCurrentThread(); | 222 context_provider->BindToCurrentThread(); |
223 GpuImageDecodeController controller(context_provider.get(), | 223 GpuImageDecodeController controller(context_provider.get(), |
224 ResourceFormat::RGBA_8888); | 224 ResourceFormat::RGBA_8888); |
225 bool is_decomposable = true; | 225 bool is_decomposable = true; |
226 uint64_t prepare_tiles_id = 1; | 226 uint64_t prepare_tiles_id = 1; |
227 SkFilterQuality quality = kHigh_SkFilterQuality; | 227 SkFilterQuality quality = kHigh_SkFilterQuality; |
228 | 228 |
229 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 229 sk_sp<SkImage> image = CreateImage(100, 100); |
230 DrawImage draw_image( | 230 DrawImage draw_image( |
231 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 231 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
232 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 232 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
233 scoped_refptr<ImageDecodeTask> task; | 233 scoped_refptr<ImageDecodeTask> task; |
234 bool need_unref = | 234 bool need_unref = |
235 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 235 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
236 EXPECT_TRUE(need_unref); | 236 EXPECT_TRUE(need_unref); |
237 EXPECT_TRUE(task); | 237 EXPECT_TRUE(task); |
238 | 238 |
239 ProcessTask(task->dependency().get()); | 239 ProcessTask(task->dependency().get()); |
(...skipping 28 matching lines...) Expand all Loading... |
268 | 268 |
269 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { | 269 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { |
270 auto context_provider = TestContextProvider::Create(); | 270 auto context_provider = TestContextProvider::Create(); |
271 context_provider->BindToCurrentThread(); | 271 context_provider->BindToCurrentThread(); |
272 GpuImageDecodeController controller(context_provider.get(), | 272 GpuImageDecodeController controller(context_provider.get(), |
273 ResourceFormat::RGBA_8888); | 273 ResourceFormat::RGBA_8888); |
274 bool is_decomposable = true; | 274 bool is_decomposable = true; |
275 uint64_t prepare_tiles_id = 1; | 275 uint64_t prepare_tiles_id = 1; |
276 SkFilterQuality quality = kHigh_SkFilterQuality; | 276 SkFilterQuality quality = kHigh_SkFilterQuality; |
277 | 277 |
278 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 278 sk_sp<SkImage> image = CreateImage(100, 100); |
279 DrawImage draw_image( | 279 DrawImage draw_image( |
280 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 280 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
281 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 281 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
282 scoped_refptr<ImageDecodeTask> task; | 282 scoped_refptr<ImageDecodeTask> task; |
283 bool need_unref = | 283 bool need_unref = |
284 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 284 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
285 EXPECT_TRUE(need_unref); | 285 EXPECT_TRUE(need_unref); |
286 EXPECT_TRUE(task); | 286 EXPECT_TRUE(task); |
287 | 287 |
288 ProcessTask(task->dependency().get()); | 288 ProcessTask(task->dependency().get()); |
(...skipping 14 matching lines...) Expand all Loading... |
303 | 303 |
304 TEST(GpuImageDecodeControllerTest, GetLargeDecodedImageForDraw) { | 304 TEST(GpuImageDecodeControllerTest, GetLargeDecodedImageForDraw) { |
305 auto context_provider = TestContextProvider::Create(); | 305 auto context_provider = TestContextProvider::Create(); |
306 context_provider->BindToCurrentThread(); | 306 context_provider->BindToCurrentThread(); |
307 GpuImageDecodeController controller(context_provider.get(), | 307 GpuImageDecodeController controller(context_provider.get(), |
308 ResourceFormat::RGBA_8888); | 308 ResourceFormat::RGBA_8888); |
309 bool is_decomposable = true; | 309 bool is_decomposable = true; |
310 uint64_t prepare_tiles_id = 1; | 310 uint64_t prepare_tiles_id = 1; |
311 SkFilterQuality quality = kHigh_SkFilterQuality; | 311 SkFilterQuality quality = kHigh_SkFilterQuality; |
312 | 312 |
313 skia::RefPtr<SkImage> image = CreateImage(1, 24000); | 313 sk_sp<SkImage> image = CreateImage(1, 24000); |
314 DrawImage draw_image( | 314 DrawImage draw_image( |
315 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 315 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
316 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 316 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
317 scoped_refptr<ImageDecodeTask> task; | 317 scoped_refptr<ImageDecodeTask> task; |
318 bool need_unref = | 318 bool need_unref = |
319 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 319 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
320 EXPECT_TRUE(need_unref); | 320 EXPECT_TRUE(need_unref); |
321 EXPECT_TRUE(task); | 321 EXPECT_TRUE(task); |
322 | 322 |
323 ProcessTask(task->dependency().get()); | 323 ProcessTask(task->dependency().get()); |
(...skipping 17 matching lines...) Expand all Loading... |
341 context_provider->BindToCurrentThread(); | 341 context_provider->BindToCurrentThread(); |
342 GpuImageDecodeController controller(context_provider.get(), | 342 GpuImageDecodeController controller(context_provider.get(), |
343 ResourceFormat::RGBA_8888); | 343 ResourceFormat::RGBA_8888); |
344 bool is_decomposable = true; | 344 bool is_decomposable = true; |
345 uint64_t prepare_tiles_id = 1; | 345 uint64_t prepare_tiles_id = 1; |
346 SkFilterQuality quality = kHigh_SkFilterQuality; | 346 SkFilterQuality quality = kHigh_SkFilterQuality; |
347 | 347 |
348 controller.SetCachedItemLimitForTesting(0); | 348 controller.SetCachedItemLimitForTesting(0); |
349 controller.SetCachedBytesLimitForTesting(0); | 349 controller.SetCachedBytesLimitForTesting(0); |
350 | 350 |
351 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 351 sk_sp<SkImage> image = CreateImage(100, 100); |
352 DrawImage draw_image( | 352 DrawImage draw_image( |
353 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 353 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
354 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 354 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
355 | 355 |
356 scoped_refptr<ImageDecodeTask> task; | 356 scoped_refptr<ImageDecodeTask> task; |
357 bool need_unref = | 357 bool need_unref = |
358 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 358 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
359 EXPECT_FALSE(need_unref); | 359 EXPECT_FALSE(need_unref); |
360 EXPECT_FALSE(task); | 360 EXPECT_FALSE(task); |
361 | 361 |
(...skipping 14 matching lines...) Expand all Loading... |
376 context_provider->BindToCurrentThread(); | 376 context_provider->BindToCurrentThread(); |
377 GpuImageDecodeController controller(context_provider.get(), | 377 GpuImageDecodeController controller(context_provider.get(), |
378 ResourceFormat::RGBA_8888); | 378 ResourceFormat::RGBA_8888); |
379 bool is_decomposable = true; | 379 bool is_decomposable = true; |
380 uint64_t prepare_tiles_id = 1; | 380 uint64_t prepare_tiles_id = 1; |
381 SkFilterQuality quality = kHigh_SkFilterQuality; | 381 SkFilterQuality quality = kHigh_SkFilterQuality; |
382 | 382 |
383 controller.SetCachedItemLimitForTesting(0); | 383 controller.SetCachedItemLimitForTesting(0); |
384 controller.SetCachedBytesLimitForTesting(0); | 384 controller.SetCachedBytesLimitForTesting(0); |
385 | 385 |
386 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 386 sk_sp<SkImage> image = CreateImage(100, 100); |
387 DrawImage draw_image( | 387 DrawImage draw_image( |
388 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 388 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
389 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 389 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
390 | 390 |
391 scoped_refptr<ImageDecodeTask> task; | 391 scoped_refptr<ImageDecodeTask> task; |
392 bool need_unref = | 392 bool need_unref = |
393 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 393 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
394 EXPECT_FALSE(need_unref); | 394 EXPECT_FALSE(need_unref); |
395 EXPECT_FALSE(task); | 395 EXPECT_FALSE(task); |
396 | 396 |
(...skipping 26 matching lines...) Expand all Loading... |
423 auto context_provider = TestContextProvider::Create(); | 423 auto context_provider = TestContextProvider::Create(); |
424 context_provider->BindToCurrentThread(); | 424 context_provider->BindToCurrentThread(); |
425 GpuImageDecodeController controller(context_provider.get(), | 425 GpuImageDecodeController controller(context_provider.get(), |
426 ResourceFormat::RGBA_8888); | 426 ResourceFormat::RGBA_8888); |
427 bool is_decomposable = true; | 427 bool is_decomposable = true; |
428 SkFilterQuality quality = kHigh_SkFilterQuality; | 428 SkFilterQuality quality = kHigh_SkFilterQuality; |
429 | 429 |
430 controller.SetCachedItemLimitForTesting(0); | 430 controller.SetCachedItemLimitForTesting(0); |
431 controller.SetCachedBytesLimitForTesting(0); | 431 controller.SetCachedBytesLimitForTesting(0); |
432 | 432 |
433 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 433 sk_sp<SkImage> image = CreateImage(100, 100); |
434 DrawImage draw_image( | 434 DrawImage draw_image( |
435 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 435 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
436 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 436 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
437 | 437 |
438 // Must hold context lock before calling GetDecodedImageForDraw / | 438 // Must hold context lock before calling GetDecodedImageForDraw / |
439 // DrawWithImageFinished. | 439 // DrawWithImageFinished. |
440 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 440 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
441 DecodedDrawImage decoded_draw_image = | 441 DecodedDrawImage decoded_draw_image = |
442 controller.GetDecodedImageForDraw(draw_image); | 442 controller.GetDecodedImageForDraw(draw_image); |
443 EXPECT_TRUE(decoded_draw_image.image()); | 443 EXPECT_TRUE(decoded_draw_image.image()); |
(...skipping 11 matching lines...) Expand all Loading... |
455 | 455 |
456 TEST(GpuImageDecodeControllerTest, ZeroSizedImagesAreSkipped) { | 456 TEST(GpuImageDecodeControllerTest, ZeroSizedImagesAreSkipped) { |
457 auto context_provider = TestContextProvider::Create(); | 457 auto context_provider = TestContextProvider::Create(); |
458 context_provider->BindToCurrentThread(); | 458 context_provider->BindToCurrentThread(); |
459 GpuImageDecodeController controller(context_provider.get(), | 459 GpuImageDecodeController controller(context_provider.get(), |
460 ResourceFormat::RGBA_8888); | 460 ResourceFormat::RGBA_8888); |
461 bool is_decomposable = true; | 461 bool is_decomposable = true; |
462 uint64_t prepare_tiles_id = 1; | 462 uint64_t prepare_tiles_id = 1; |
463 SkFilterQuality quality = kHigh_SkFilterQuality; | 463 SkFilterQuality quality = kHigh_SkFilterQuality; |
464 | 464 |
465 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 465 sk_sp<SkImage> image = CreateImage(100, 100); |
466 DrawImage draw_image( | 466 DrawImage draw_image( |
467 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 467 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
468 CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable)); | 468 CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable)); |
469 | 469 |
470 scoped_refptr<ImageDecodeTask> task; | 470 scoped_refptr<ImageDecodeTask> task; |
471 bool need_unref = | 471 bool need_unref = |
472 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 472 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
473 EXPECT_FALSE(task); | 473 EXPECT_FALSE(task); |
474 EXPECT_FALSE(need_unref); | 474 EXPECT_FALSE(need_unref); |
475 | 475 |
476 // Must hold context lock before calling GetDecodedImageForDraw / | 476 // Must hold context lock before calling GetDecodedImageForDraw / |
477 // DrawWithImageFinished. | 477 // DrawWithImageFinished. |
478 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 478 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
479 DecodedDrawImage decoded_draw_image = | 479 DecodedDrawImage decoded_draw_image = |
480 controller.GetDecodedImageForDraw(draw_image); | 480 controller.GetDecodedImageForDraw(draw_image); |
481 EXPECT_FALSE(decoded_draw_image.image()); | 481 EXPECT_FALSE(decoded_draw_image.image()); |
482 | 482 |
483 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 483 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
484 } | 484 } |
485 | 485 |
486 TEST(GpuImageDecodeControllerTest, NonOverlappingSrcRectImagesAreSkipped) { | 486 TEST(GpuImageDecodeControllerTest, NonOverlappingSrcRectImagesAreSkipped) { |
487 auto context_provider = TestContextProvider::Create(); | 487 auto context_provider = TestContextProvider::Create(); |
488 context_provider->BindToCurrentThread(); | 488 context_provider->BindToCurrentThread(); |
489 GpuImageDecodeController controller(context_provider.get(), | 489 GpuImageDecodeController controller(context_provider.get(), |
490 ResourceFormat::RGBA_8888); | 490 ResourceFormat::RGBA_8888); |
491 bool is_decomposable = true; | 491 bool is_decomposable = true; |
492 uint64_t prepare_tiles_id = 1; | 492 uint64_t prepare_tiles_id = 1; |
493 SkFilterQuality quality = kHigh_SkFilterQuality; | 493 SkFilterQuality quality = kHigh_SkFilterQuality; |
494 | 494 |
495 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 495 sk_sp<SkImage> image = CreateImage(100, 100); |
496 DrawImage draw_image( | 496 DrawImage draw_image( |
497 image.get(), SkIRect::MakeXYWH(150, 150, image->width(), image->height()), | 497 image.get(), SkIRect::MakeXYWH(150, 150, image->width(), image->height()), |
498 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 498 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
499 | 499 |
500 scoped_refptr<ImageDecodeTask> task; | 500 scoped_refptr<ImageDecodeTask> task; |
501 bool need_unref = | 501 bool need_unref = |
502 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 502 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
503 EXPECT_FALSE(task); | 503 EXPECT_FALSE(task); |
504 EXPECT_FALSE(need_unref); | 504 EXPECT_FALSE(need_unref); |
505 | 505 |
506 // Must hold context lock before calling GetDecodedImageForDraw / | 506 // Must hold context lock before calling GetDecodedImageForDraw / |
507 // DrawWithImageFinished. | 507 // DrawWithImageFinished. |
508 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 508 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
509 DecodedDrawImage decoded_draw_image = | 509 DecodedDrawImage decoded_draw_image = |
510 controller.GetDecodedImageForDraw(draw_image); | 510 controller.GetDecodedImageForDraw(draw_image); |
511 EXPECT_FALSE(decoded_draw_image.image()); | 511 EXPECT_FALSE(decoded_draw_image.image()); |
512 | 512 |
513 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 513 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
514 } | 514 } |
515 | 515 |
516 TEST(GpuImageDecodeControllerTest, CanceledTasksDoNotCountAgainstBudget) { | 516 TEST(GpuImageDecodeControllerTest, CanceledTasksDoNotCountAgainstBudget) { |
517 auto context_provider = TestContextProvider::Create(); | 517 auto context_provider = TestContextProvider::Create(); |
518 context_provider->BindToCurrentThread(); | 518 context_provider->BindToCurrentThread(); |
519 GpuImageDecodeController controller(context_provider.get(), | 519 GpuImageDecodeController controller(context_provider.get(), |
520 ResourceFormat::RGBA_8888); | 520 ResourceFormat::RGBA_8888); |
521 bool is_decomposable = true; | 521 bool is_decomposable = true; |
522 uint64_t prepare_tiles_id = 1; | 522 uint64_t prepare_tiles_id = 1; |
523 SkFilterQuality quality = kHigh_SkFilterQuality; | 523 SkFilterQuality quality = kHigh_SkFilterQuality; |
524 | 524 |
525 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 525 sk_sp<SkImage> image = CreateImage(100, 100); |
526 DrawImage draw_image( | 526 DrawImage draw_image( |
527 image.get(), SkIRect::MakeXYWH(0, 0, image->width(), image->height()), | 527 image.get(), SkIRect::MakeXYWH(0, 0, image->width(), image->height()), |
528 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 528 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
529 | 529 |
530 scoped_refptr<ImageDecodeTask> task; | 530 scoped_refptr<ImageDecodeTask> task; |
531 bool need_unref = | 531 bool need_unref = |
532 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 532 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
533 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); | 533 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); |
534 EXPECT_TRUE(task); | 534 EXPECT_TRUE(task); |
535 EXPECT_TRUE(need_unref); | 535 EXPECT_TRUE(need_unref); |
536 | 536 |
537 ScheduleTask(task->dependency().get()); | 537 ScheduleTask(task->dependency().get()); |
538 CompleteTask(task->dependency().get()); | 538 CompleteTask(task->dependency().get()); |
539 ScheduleTask(task.get()); | 539 ScheduleTask(task.get()); |
540 CompleteTask(task.get()); | 540 CompleteTask(task.get()); |
541 | 541 |
542 controller.UnrefImage(draw_image); | 542 controller.UnrefImage(draw_image); |
543 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); | 543 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); |
544 } | 544 } |
545 | 545 |
546 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { | 546 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { |
547 auto context_provider = TestContextProvider::Create(); | 547 auto context_provider = TestContextProvider::Create(); |
548 context_provider->BindToCurrentThread(); | 548 context_provider->BindToCurrentThread(); |
549 GpuImageDecodeController controller(context_provider.get(), | 549 GpuImageDecodeController controller(context_provider.get(), |
550 ResourceFormat::RGBA_8888); | 550 ResourceFormat::RGBA_8888); |
551 bool is_decomposable = true; | 551 bool is_decomposable = true; |
552 uint64_t prepare_tiles_id = 1; | 552 uint64_t prepare_tiles_id = 1; |
553 SkFilterQuality quality = kHigh_SkFilterQuality; | 553 SkFilterQuality quality = kHigh_SkFilterQuality; |
554 | 554 |
555 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 555 sk_sp<SkImage> image = CreateImage(100, 100); |
556 DrawImage draw_image( | 556 DrawImage draw_image( |
557 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 557 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
558 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 558 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
559 scoped_refptr<ImageDecodeTask> task; | 559 scoped_refptr<ImageDecodeTask> task; |
560 { | 560 { |
561 bool need_unref = | 561 bool need_unref = |
562 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 562 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
563 EXPECT_TRUE(need_unref); | 563 EXPECT_TRUE(need_unref); |
564 EXPECT_TRUE(task); | 564 EXPECT_TRUE(task); |
565 } | 565 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 ProcessTask(task->dependency().get()); | 597 ProcessTask(task->dependency().get()); |
598 ProcessTask(task.get()); | 598 ProcessTask(task.get()); |
599 | 599 |
600 // The image should be in our cache after un-ref. | 600 // The image should be in our cache after un-ref. |
601 controller.UnrefImage(draw_image); | 601 controller.UnrefImage(draw_image); |
602 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 602 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
603 } | 603 } |
604 | 604 |
605 } // namespace | 605 } // namespace |
606 } // namespace cc | 606 } // namespace cc |
OLD | NEW |