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 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 EXPECT_EQ(task->dependencies().size(), 1u); | 1545 EXPECT_EQ(task->dependencies().size(), 1u); |
1546 EXPECT_TRUE(task->dependencies()[0]); | 1546 EXPECT_TRUE(task->dependencies()[0]); |
1547 | 1547 |
1548 // Run the task and unref the image. | 1548 // Run the task and unref the image. |
1549 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); | 1549 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
1550 TestTileTaskRunner::ProcessTask(task.get()); | 1550 TestTileTaskRunner::ProcessTask(task.get()); |
1551 cache.UnrefImage(draw_image); | 1551 cache.UnrefImage(draw_image); |
1552 } | 1552 } |
1553 } | 1553 } |
1554 | 1554 |
| 1555 TEST(GpuImageDecodeCacheTest, ClearCache) { |
| 1556 auto context_provider = TestContextProvider::Create(); |
| 1557 context_provider->BindToCurrentThread(); |
| 1558 TestGpuImageDecodeCache cache(context_provider.get()); |
| 1559 bool is_decomposable = true; |
| 1560 SkFilterQuality quality = kHigh_SkFilterQuality; |
| 1561 |
| 1562 for (int i = 0; i < 10; ++i) { |
| 1563 sk_sp<SkImage> image = CreateImage(100, 100); |
| 1564 DrawImage draw_image( |
| 1565 image, SkIRect::MakeWH(image->width(), image->height()), quality, |
| 1566 CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable)); |
| 1567 scoped_refptr<TileTask> task; |
| 1568 bool need_unref = cache.GetTaskForImageAndRef( |
| 1569 draw_image, ImageDecodeCache::TracingInfo(), &task); |
| 1570 EXPECT_TRUE(need_unref); |
| 1571 EXPECT_TRUE(task); |
| 1572 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
| 1573 TestTileTaskRunner::ProcessTask(task.get()); |
| 1574 cache.UnrefImage(draw_image); |
| 1575 } |
| 1576 |
| 1577 // We should now have data image in our cache. |
| 1578 EXPECT_GT(cache.GetBytesUsedForTesting(), 0u); |
| 1579 EXPECT_EQ(cache.GetNumCacheEntriesForTesting(), 10u); |
| 1580 |
| 1581 // Tell our cache to clear resources. |
| 1582 cache.ClearCache(); |
| 1583 |
| 1584 // We should now have nothing in our cache. |
| 1585 EXPECT_EQ(cache.GetBytesUsedForTesting(), 0u); |
| 1586 EXPECT_EQ(cache.GetNumCacheEntriesForTesting(), 0u); |
| 1587 } |
| 1588 |
1555 } // namespace | 1589 } // namespace |
1556 } // namespace cc | 1590 } // namespace cc |
OLD | NEW |