Commit bcce1f33 authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Only purge unlocked Skia resources when CC goes idle

This avoids clearing some longer-lived Skia caches, hopefully avoiding
an UMA latency regression we experienced when the idle clearing was
initially added.

This re-land uses a more direct Skia API, hopefully avoiding the
flakiness seen in issue 805575.

Note for sheriffs: We expect a small regression in measured memory.
This is intentional, and comes with an improvement to input latency.
This regression shouldn't have a large impact on real-world scenarios,
as we are preventing the clearing of a cache that will be immediately
re-created on any page raster.

TBR=brettw@chromium.org for test-only DEPS change (already ran by bsalomon@ in previous patch, this is re-land+updates)

Bug: 664181, 805575
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Id4c9a091a543c31f928e0214558695de81a30e9d
Reviewed-on: https://chromium-review.googlesource.com/1123169
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572391}
parent a5115083
...@@ -26,6 +26,7 @@ specific_include_rules = { ...@@ -26,6 +26,7 @@ specific_include_rules = {
"+cc/test", "+cc/test",
"+gpu/ipc/gl_in_process_context.h", "+gpu/ipc/gl_in_process_context.h",
"+media/base", "+media/base",
"+third_party/skia/include/core",
"+ui/gl", "+ui/gl",
], ],
".*_benchmark\.cc": [ ".*_benchmark\.cc": [
......
...@@ -159,8 +159,11 @@ void ContextCacheController::OnIdle(uint32_t idle_generation) { ...@@ -159,8 +159,11 @@ void ContextCacheController::OnIdle(uint32_t idle_generation) {
return; return;
} }
if (gr_context_) if (gr_context_) {
gr_context_->freeGpuResources(); // Avoid the more complete GrContext::freeGpuResources, as that evicts
// harder to re-generate Skia caches.
gr_context_->purgeUnlockedResources(false /* scratchResourcesOnly */);
}
// Toggle SetAggressivelyFreeResources to drop command buffer data. // Toggle SetAggressivelyFreeResources to drop command buffer data.
context_support_->SetAggressivelyFreeResources(true); context_support_->SetAggressivelyFreeResources(true);
......
...@@ -5,9 +5,13 @@ ...@@ -5,9 +5,13 @@
#include "components/viz/common/gpu/context_cache_controller.h" #include "components/viz/common/gpu/context_cache_controller.h"
#include "base/test/test_mock_time_task_runner.h" #include "base/test/test_mock_time_task_runner.h"
#include "components/viz/test/test_context_provider.h"
#include "components/viz/test/test_context_support.h" #include "components/viz/test/test_context_support.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/gpu/GrContext.h"
using ::testing::Mock; using ::testing::Mock;
using ::testing::StrictMock; using ::testing::StrictMock;
...@@ -109,5 +113,51 @@ TEST(ContextCacheControllerTest, ScopedBusyMulitpleWhileVisible) { ...@@ -109,5 +113,51 @@ TEST(ContextCacheControllerTest, ScopedBusyMulitpleWhileVisible) {
cache_controller.ClientBecameNotVisible(std::move(visible)); cache_controller.ClientBecameNotVisible(std::move(visible));
} }
// Confirms that the Skia performDeferredCleanup API used by the cache
// controller behaves as expected.
TEST(ContextCacheControllerTest, CheckSkiaResourcePurgeAPI) {
StrictMock<MockContextSupport> context_support;
auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>();
ContextCacheController cache_controller(&context_support, task_runner);
auto context_provider = TestContextProvider::Create();
context_provider->BindToCurrentThread();
auto* gr_context = context_provider->GrContext();
cache_controller.SetGrContext(gr_context);
// Make us visible.
EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
auto visibility = cache_controller.ClientBecameVisible();
Mock::VerifyAndClearExpectations(&context_support);
// Now that we're visible, become busy, create and release a skia resource.
auto busy = cache_controller.ClientBecameBusy();
{
auto image_info = SkImageInfo::MakeN32Premul(200, 200);
std::vector<uint8_t> image_data(image_info.computeMinByteSize());
SkPixmap pixmap(image_info, image_data.data(), image_info.minRowBytes());
auto image = SkImage::MakeRasterCopy(pixmap);
auto image_gpu = image->makeTextureImage(gr_context, nullptr);
gr_context->flush();
}
// Ensure we see size taken up for the image (now released, but cached for
// re-use).
EXPECT_GT(gr_context->getResourceCachePurgeableBytes(), 0u);
// Make the client idle and wait for the idle callback to trigger.
cache_controller.ClientBecameNotBusy(std::move(busy));
EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5));
Mock::VerifyAndClearExpectations(&context_support);
// The Skia resource cache should now be empty.
EXPECT_EQ(gr_context->getResourceCachePurgeableBytes(), 0u);
// Set not-visible.
EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
cache_controller.ClientBecameNotVisible(std::move(visibility));
}
} // namespace } // namespace
} // namespace viz } // namespace viz
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment