| 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/test/test_context_provider.h" | 8 #include "cc/test/test_context_provider.h" |
| 9 #include "cc/test/test_tile_task_runner.h" | 9 #include "cc/test/test_tile_task_runner.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); | 630 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); |
| 631 } | 631 } |
| 632 | 632 |
| 633 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDrawAtRasterDecode) { | 633 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDrawAtRasterDecode) { |
| 634 auto context_provider = TestContextProvider::Create(); | 634 auto context_provider = TestContextProvider::Create(); |
| 635 context_provider->BindToCurrentThread(); | 635 context_provider->BindToCurrentThread(); |
| 636 TestGpuImageDecodeController controller(context_provider.get()); | 636 TestGpuImageDecodeController controller(context_provider.get()); |
| 637 bool is_decomposable = true; | 637 bool is_decomposable = true; |
| 638 SkFilterQuality quality = kHigh_SkFilterQuality; | 638 SkFilterQuality quality = kHigh_SkFilterQuality; |
| 639 | 639 |
| 640 controller.SetCachedItemLimitForTesting(0); | |
| 641 controller.SetCachedBytesLimitForTesting(0); | 640 controller.SetCachedBytesLimitForTesting(0); |
| 642 | 641 |
| 643 sk_sp<SkImage> image = CreateImage(100, 100); | 642 sk_sp<SkImage> image = CreateImage(100, 100); |
| 644 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 643 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 645 quality, | 644 quality, |
| 646 CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable)); | 645 CreateMatrix(SkSize::Make(1.0f, 1.0f), 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); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); | 853 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); |
| 855 } | 854 } |
| 856 | 855 |
| 857 TEST(GpuImageDecodeControllerTest, AtRasterUsedDirectlyIfSpaceAllows) { | 856 TEST(GpuImageDecodeControllerTest, AtRasterUsedDirectlyIfSpaceAllows) { |
| 858 auto context_provider = TestContextProvider::Create(); | 857 auto context_provider = TestContextProvider::Create(); |
| 859 context_provider->BindToCurrentThread(); | 858 context_provider->BindToCurrentThread(); |
| 860 TestGpuImageDecodeController controller(context_provider.get()); | 859 TestGpuImageDecodeController controller(context_provider.get()); |
| 861 bool is_decomposable = true; | 860 bool is_decomposable = true; |
| 862 SkFilterQuality quality = kHigh_SkFilterQuality; | 861 SkFilterQuality quality = kHigh_SkFilterQuality; |
| 863 | 862 |
| 864 controller.SetCachedItemLimitForTesting(0); | |
| 865 controller.SetCachedBytesLimitForTesting(0); | 863 controller.SetCachedBytesLimitForTesting(0); |
| 866 | 864 |
| 867 sk_sp<SkImage> image = CreateImage(100, 100); | 865 sk_sp<SkImage> image = CreateImage(100, 100); |
| 868 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 866 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 869 quality, | 867 quality, |
| 870 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 868 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
| 871 | 869 |
| 872 scoped_refptr<TileTask> task; | 870 scoped_refptr<TileTask> task; |
| 873 bool need_unref = controller.GetTaskForImageAndRef( | 871 bool need_unref = controller.GetTaskForImageAndRef( |
| 874 draw_image, ImageDecodeController::TracingInfo(), &task); | 872 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 875 EXPECT_FALSE(need_unref); | 873 EXPECT_FALSE(need_unref); |
| 876 EXPECT_FALSE(task); | 874 EXPECT_FALSE(task); |
| 877 | 875 |
| 878 // Must hold context lock before calling GetDecodedImageForDraw / | 876 // Must hold context lock before calling GetDecodedImageForDraw / |
| 879 // DrawWithImageFinished. | 877 // DrawWithImageFinished. |
| 880 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 878 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
| 881 DecodedDrawImage decoded_draw_image = | 879 DecodedDrawImage decoded_draw_image = |
| 882 controller.GetDecodedImageForDraw(draw_image); | 880 controller.GetDecodedImageForDraw(draw_image); |
| 883 EXPECT_TRUE(decoded_draw_image.image()); | 881 EXPECT_TRUE(decoded_draw_image.image()); |
| 884 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); | 882 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); |
| 885 EXPECT_TRUE(decoded_draw_image.is_at_raster_decode()); | 883 EXPECT_TRUE(decoded_draw_image.is_at_raster_decode()); |
| 886 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); | 884 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); |
| 887 | 885 |
| 888 controller.SetCachedItemLimitForTesting(1000); | |
| 889 controller.SetCachedBytesLimitForTesting(96 * 1024 * 1024); | 886 controller.SetCachedBytesLimitForTesting(96 * 1024 * 1024); |
| 890 | 887 |
| 891 // Finish our draw after increasing the memory limit, image should be added to | 888 // Finish our draw after increasing the memory limit, image should be added to |
| 892 // cache. | 889 // cache. |
| 893 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 890 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
| 894 | 891 |
| 895 scoped_refptr<TileTask> another_task; | 892 scoped_refptr<TileTask> another_task; |
| 896 bool another_task_needs_unref = controller.GetTaskForImageAndRef( | 893 bool another_task_needs_unref = controller.GetTaskForImageAndRef( |
| 897 draw_image, ImageDecodeController::TracingInfo(), &task); | 894 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 898 EXPECT_TRUE(another_task_needs_unref); | 895 EXPECT_TRUE(another_task_needs_unref); |
| 899 EXPECT_FALSE(another_task); | 896 EXPECT_FALSE(another_task); |
| 900 controller.UnrefImage(draw_image); | 897 controller.UnrefImage(draw_image); |
| 901 } | 898 } |
| 902 | 899 |
| 903 TEST(GpuImageDecodeControllerTest, | 900 TEST(GpuImageDecodeControllerTest, |
| 904 GetDecodedImageForDrawAtRasterDecodeMultipleTimes) { | 901 GetDecodedImageForDrawAtRasterDecodeMultipleTimes) { |
| 905 auto context_provider = TestContextProvider::Create(); | 902 auto context_provider = TestContextProvider::Create(); |
| 906 context_provider->BindToCurrentThread(); | 903 context_provider->BindToCurrentThread(); |
| 907 TestGpuImageDecodeController controller(context_provider.get()); | 904 TestGpuImageDecodeController controller(context_provider.get()); |
| 908 bool is_decomposable = true; | 905 bool is_decomposable = true; |
| 909 SkFilterQuality quality = kHigh_SkFilterQuality; | 906 SkFilterQuality quality = kHigh_SkFilterQuality; |
| 910 | 907 |
| 911 controller.SetCachedItemLimitForTesting(0); | |
| 912 controller.SetCachedBytesLimitForTesting(0); | 908 controller.SetCachedBytesLimitForTesting(0); |
| 913 | 909 |
| 914 sk_sp<SkImage> image = CreateImage(100, 100); | 910 sk_sp<SkImage> image = CreateImage(100, 100); |
| 915 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 911 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 916 quality, | 912 quality, |
| 917 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 913 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
| 918 | 914 |
| 919 // Must hold context lock before calling GetDecodedImageForDraw / | 915 // Must hold context lock before calling GetDecodedImageForDraw / |
| 920 // DrawWithImageFinished. | 916 // DrawWithImageFinished. |
| 921 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 917 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 | 1296 |
| 1301 // Do an at-raster decode of the above image that *does* require mips. | 1297 // Do an at-raster decode of the above image that *does* require mips. |
| 1302 DrawImage draw_image_mips( | 1298 DrawImage draw_image_mips( |
| 1303 image, SkIRect::MakeWH(image->width(), image->height()), quality, | 1299 image, SkIRect::MakeWH(image->width(), image->height()), quality, |
| 1304 CreateMatrix(SkSize::Make(0.6f, 0.6f), is_decomposable)); | 1300 CreateMatrix(SkSize::Make(0.6f, 0.6f), is_decomposable)); |
| 1305 DecodedDrawImage decoded_draw_image = | 1301 DecodedDrawImage decoded_draw_image = |
| 1306 controller.GetDecodedImageForDraw(draw_image_mips); | 1302 controller.GetDecodedImageForDraw(draw_image_mips); |
| 1307 controller.DrawWithImageFinished(draw_image_mips, decoded_draw_image); | 1303 controller.DrawWithImageFinished(draw_image_mips, decoded_draw_image); |
| 1308 } | 1304 } |
| 1309 | 1305 |
| 1306 TEST(GpuImageDecodeControllerTest, MemoryStateSuspended) { |
| 1307 auto context_provider = TestContextProvider::Create(); |
| 1308 context_provider->BindToCurrentThread(); |
| 1309 TestGpuImageDecodeController controller(context_provider.get()); |
| 1310 |
| 1311 // First Insert an image into our cache. |
| 1312 sk_sp<SkImage> image = CreateImage(1, 1); |
| 1313 bool is_decomposable = true; |
| 1314 SkMatrix matrix = CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable); |
| 1315 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
| 1316 kLow_SkFilterQuality, matrix); |
| 1317 scoped_refptr<TileTask> task; |
| 1318 bool need_unref = controller.GetTaskForImageAndRef( |
| 1319 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 1320 EXPECT_TRUE(need_unref); |
| 1321 EXPECT_TRUE(task); |
| 1322 |
| 1323 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
| 1324 TestTileTaskRunner::ProcessTask(task.get()); |
| 1325 controller.UnrefImage(draw_image); |
| 1326 |
| 1327 // The image should be cached. |
| 1328 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
| 1329 DCHECK_EQ(controller.GetNumCacheEntriesForTesting(), 1u); |
| 1330 |
| 1331 // Set us to the not visible state (prerequisite for SUSPENDED). |
| 1332 controller.SetShouldAggressivelyFreeResources(true); |
| 1333 |
| 1334 // Image should be cached, but not using memory budget. |
| 1335 DCHECK_EQ(controller.GetBytesUsedForTesting(), 0u); |
| 1336 DCHECK_EQ(controller.GetNumCacheEntriesForTesting(), 1u); |
| 1337 |
| 1338 // Set us to the SUSPENDED state. |
| 1339 controller.OnMemoryStateChange(base::MemoryState::SUSPENDED); |
| 1340 |
| 1341 // Nothing should be cached. |
| 1342 DCHECK_EQ(controller.GetBytesUsedForTesting(), 0u); |
| 1343 DCHECK_EQ(controller.GetNumCacheEntriesForTesting(), 0u); |
| 1344 |
| 1345 // Attempts to get a task for the image should fail, as we have no space (at |
| 1346 // raster only). |
| 1347 need_unref = controller.GetTaskForImageAndRef( |
| 1348 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 1349 EXPECT_FALSE(need_unref); |
| 1350 EXPECT_FALSE(task); |
| 1351 |
| 1352 // Restore us to visible and NORMAL memory state. |
| 1353 controller.OnMemoryStateChange(base::MemoryState::NORMAL); |
| 1354 controller.SetShouldAggressivelyFreeResources(false); |
| 1355 |
| 1356 // We should now be able to create a task again (space available). |
| 1357 need_unref = controller.GetTaskForImageAndRef( |
| 1358 draw_image, ImageDecodeController::TracingInfo(), &task); |
| 1359 EXPECT_TRUE(need_unref); |
| 1360 EXPECT_TRUE(task); |
| 1361 |
| 1362 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
| 1363 TestTileTaskRunner::ProcessTask(task.get()); |
| 1364 controller.UnrefImage(draw_image); |
| 1365 } |
| 1366 |
| 1310 } // namespace | 1367 } // namespace |
| 1311 } // namespace cc | 1368 } // namespace cc |
| OLD | NEW |