Chromium Code Reviews| 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_cache.h" | 5 #include "cc/tiles/gpu_image_decode_cache.h" |
| 6 | 6 |
| 7 #include "cc/paint/draw_image.h" | 7 #include "cc/paint/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 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1707 TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); | 1707 TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); |
| 1708 TestTileTaskRunner::ProcessTask(first_task.get()); | 1708 TestTileTaskRunner::ProcessTask(first_task.get()); |
| 1709 TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); | 1709 TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); |
| 1710 TestTileTaskRunner::ProcessTask(second_task.get()); | 1710 TestTileTaskRunner::ProcessTask(second_task.get()); |
| 1711 | 1711 |
| 1712 cache.UnrefImage(first_draw_image); | 1712 cache.UnrefImage(first_draw_image); |
| 1713 cache.UnrefImage(second_draw_image); | 1713 cache.UnrefImage(second_draw_image); |
| 1714 cache.UnrefImage(third_draw_image); | 1714 cache.UnrefImage(third_draw_image); |
| 1715 } | 1715 } |
| 1716 | 1716 |
| 1717 TEST(GpuImageDecodeCacheTest, RemoveUnusedImage) { | |
|
ericrk
2017/06/19 17:09:30
Not needed right now, but I wonder if we should mo
sohan
2017/06/20 13:31:39
If we remove this test for future, we are essentia
ericrk
2017/06/20 16:06:05
SGTM, thanks
| |
| 1718 auto context_provider = TestContextProvider::Create(); | |
| 1719 context_provider->BindToCurrentThread(); | |
| 1720 TestGpuImageDecodeCache cache(context_provider.get()); | |
| 1721 bool is_decomposable = true; | |
| 1722 SkFilterQuality quality = kHigh_SkFilterQuality; | |
| 1723 std::vector<uint32_t> unique_ids(10); | |
| 1724 | |
| 1725 for (int i = 0; i < 10; ++i) { | |
| 1726 sk_sp<SkImage> image = CreateImage(100, 100); | |
| 1727 unique_ids[i] = image->uniqueID(); | |
| 1728 DrawImage draw_image( | |
| 1729 CreatePaintImage(image), | |
| 1730 SkIRect::MakeWH(image->width(), image->height()), quality, | |
| 1731 CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), | |
| 1732 DefaultColorSpace()); | |
| 1733 scoped_refptr<TileTask> task; | |
| 1734 bool need_unref = cache.GetTaskForImageAndRef( | |
| 1735 draw_image, ImageDecodeCache::TracingInfo(), &task); | |
| 1736 EXPECT_TRUE(need_unref); | |
| 1737 EXPECT_TRUE(task); | |
| 1738 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); | |
| 1739 TestTileTaskRunner::ProcessTask(task.get()); | |
| 1740 cache.UnrefImage(draw_image); | |
| 1741 } | |
| 1742 | |
| 1743 // We should now have data image in our cache. | |
| 1744 EXPECT_GT(cache.GetBytesUsedForTesting(), 0u); | |
| 1745 EXPECT_EQ(cache.GetNumCacheEntriesForTesting(), 10u); | |
| 1746 | |
| 1747 // Remove unused ids. | |
| 1748 for (uint32_t i = 0; i < 10; ++i) { | |
| 1749 cache.NotifyImageUnused(unique_ids[i]); | |
| 1750 EXPECT_EQ(cache.GetNumCacheEntriesForTesting(), (10 - i - 1)); | |
| 1751 } | |
| 1752 } | |
| 1753 | |
| 1717 } // namespace | 1754 } // namespace |
| 1718 } // namespace cc | 1755 } // namespace cc |
| OLD | NEW |