Commit 29f4d37f authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Use new Skia resource purging API when we go idle

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

R=danakj
TBR=brettw@chromium.org for DEPS change relying on third_party/skia. Got review from third_party/skia owner, bsalomon@.

Bug: 664181
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I801f63b7b3ff6386303b582b7ae1f503425e1bb0
Reviewed-on: https://chromium-review.googlesource.com/741454Reviewed-by: default avatarBrian Salomon <bsalomon@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530949}
parent 6fe983b5
......@@ -14,6 +14,7 @@ specific_include_rules = {
"+components/viz/test",
"+gpu/ipc/gl_in_process_context.h",
"+media/base",
"+third_party/skia/include/core",
"+ui/gl",
],
".*_benchmark\.cc": [
......
......@@ -159,8 +159,11 @@ void ContextCacheController::OnIdle(uint32_t idle_generation) {
return;
}
if (gr_context_)
gr_context_->freeGpuResources();
if (gr_context_) {
// Avoid the more complete GrContext::freeGpuResources, as that evicts
// harder to re-generate Skia caches.
gr_context_->performDeferredCleanup(std::chrono::milliseconds(0));
}
// Toggle SetAggressivelyFreeResources to drop command buffer data.
context_support_->SetAggressivelyFreeResources(true);
......
......@@ -11,6 +11,9 @@
#include "cc/test/test_web_graphics_context_3d.h"
#include "testing/gmock/include/gmock/gmock.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::StrictMock;
......@@ -112,5 +115,51 @@ TEST(ContextCacheControllerTest, ScopedBusyMulitpleWhileVisible) {
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 = cc::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 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