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

Side by Side Diff: cc/tiles/gpu_image_decode_cache_unittest.cc

Issue 2945813002: cc: Interface to evict images from cc image decode cache. (Closed)
Patch Set: update Created 3 years, 6 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_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 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); 1745 TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
1746 TestTileTaskRunner::ProcessTask(first_task.get()); 1746 TestTileTaskRunner::ProcessTask(first_task.get());
1747 TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); 1747 TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
1748 TestTileTaskRunner::ProcessTask(second_task.get()); 1748 TestTileTaskRunner::ProcessTask(second_task.get());
1749 1749
1750 cache.UnrefImage(first_draw_image); 1750 cache.UnrefImage(first_draw_image);
1751 cache.UnrefImage(second_draw_image); 1751 cache.UnrefImage(second_draw_image);
1752 cache.UnrefImage(third_draw_image); 1752 cache.UnrefImage(third_draw_image);
1753 } 1753 }
1754 1754
1755 TEST(GpuImageDecodeCacheTest, RemoveUnusedImage) {
1756 auto context_provider = TestContextProvider::Create();
1757 context_provider->BindToCurrentThread();
1758 TestGpuImageDecodeCache cache(context_provider.get());
1759 bool is_decomposable = true;
1760 SkFilterQuality quality = kHigh_SkFilterQuality;
1761 std::vector<uint32_t> unique_ids(10);
1762
1763 for (int i = 0; i < 10; ++i) {
1764 sk_sp<SkImage> image = CreateImage(100, 100);
1765 unique_ids[i] = image->uniqueID();
1766 DrawImage draw_image(
1767 CreatePaintImage(image),
1768 SkIRect::MakeWH(image->width(), image->height()), quality,
1769 CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
1770 DefaultColorSpace());
1771 scoped_refptr<TileTask> task;
1772 bool need_unref = cache.GetTaskForImageAndRef(
1773 draw_image, ImageDecodeCache::TracingInfo(), &task);
1774 EXPECT_TRUE(need_unref);
1775 EXPECT_TRUE(task);
1776 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
1777 TestTileTaskRunner::ProcessTask(task.get());
1778 cache.UnrefImage(draw_image);
1779 }
1780
1781 // We should now have data image in our cache.
1782 EXPECT_GT(cache.GetBytesUsedForTesting(), 0u);
1783 EXPECT_EQ(cache.GetNumCacheEntriesForTesting(), 10u);
1784
1785 // Remove unused ids.
1786 for (uint32_t i = 0; i < 10; ++i) {
1787 cache.NotifyImageUnused(unique_ids[i]);
1788 EXPECT_EQ(cache.GetNumCacheEntriesForTesting(), (10 - i - 1));
1789 }
1790 }
1791
1755 } // namespace 1792 } // namespace
1756 } // namespace cc 1793 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698