Commit b8447828 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Purge more cache data in RenderThreadImpl::ClearMemory

RenderThreadImpl::ClearMemory has been purging only font cache in Skia.
But, it would be good if we purge more cache data in RenderThreadImpl::ClearMemory,
because it has mainly called under out of memory. I found SkGraphics::PurgeAllCaches
purges more cache data, so this CL calls it instead of calling SkGraphics::SetFontCacheLimit.

    void SkGraphics::PurgeAllCaches() {
        SkGraphics::PurgeFontCache();
        SkGraphics::PurgeResourceCache();
        SkImageFilter::PurgeCache();
    }

Although I add a new test to measure if RenderThreadImpl::ClearMemory purges memory,
it's not completed yet. But, this CL can be covered by tests for MemoryPressureListener.
(i.e, RenderWidgetHostViewAuraTest.DiscardDelegatedFramesWithMemoryPressure.)

Bug: None
Change-Id: I6d702e02c84a04c98489bc3f20b52f55beed1452
Reviewed-on: https://chromium-review.googlesource.com/910732Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung.kim@lge.com>
Cr-Commit-Position: refs/heads/master@{#539452}
parent 4fe42077
......@@ -2481,10 +2481,8 @@ void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) {
void RenderThreadImpl::ClearMemory() {
// Do not call into blink if it is not initialized.
if (blink_platform_impl_) {
// Purge Skia font cache, by setting it to 0 and then again to the
// previous limit.
size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
SkGraphics::SetFontCacheLimit(font_cache_limit);
// Purge Skia font cache, resource cache, and image filter.
SkGraphics::PurgeAllCaches();
}
}
......
......@@ -20,6 +20,7 @@
#include "base/test/scoped_feature_list.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "content/app/mojo/mojo_init.h"
#include "content/common/in_process_child_thread_params.h"
#include "content/common/service_manager/child_connection.h"
......@@ -36,8 +37,10 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_content_client_initializer.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_service_manager_context.h"
#include "content/renderer/render_process_impl.h"
#include "content/shell/browser/shell.h"
#include "content/test/mock_render_process.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
......@@ -47,9 +50,11 @@
#include "ipc/ipc_channel_mojo.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/skia/include/core/SkGraphics.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/buffer_format_util.h"
......@@ -414,5 +419,37 @@ INSTANTIATE_TEST_CASE_P(
gfx::BufferFormat::BGRA_8888,
gfx::BufferFormat::YVU_420)));
class RenderThreadImplClearMemoryBrowserTest : public ContentBrowserTest {
protected:
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->Start());
}
};
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(IS_CHROMECAST)
#define MAYBE_ClearMemory DISABLED_ClearMemory
#else
#define MAYBE_ClearMemory ClearMemory
#endif
IN_PROC_BROWSER_TEST_F(RenderThreadImplClearMemoryBrowserTest,
MAYBE_ClearMemory) {
TestNavigationObserver observer(shell()->web_contents());
GURL url(embedded_test_server()->GetURL("/simple_page.html"));
NavigateToURL(shell(), url);
EXPECT_GT(static_cast<int>(SkGraphics::GetFontCacheUsed()), 0);
EXPECT_GT(SkGraphics::GetFontCacheCountUsed(), 0);
// TODO(gyuyoung): How to call RenderThreadImpl::ClearMemory() from here?
// Instead we call same function that RenderThreadImpl::ClearMemory() calls at
// the moment.
SkGraphics::PurgeAllCaches();
EXPECT_EQ(static_cast<int>(SkGraphics::GetFontCacheUsed()), 0);
EXPECT_EQ(SkGraphics::GetFontCacheCountUsed(), 0);
}
} // namespace
} // namespace content
......@@ -847,6 +847,10 @@ test("content_browsertests") {
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
if (is_chromecast) {
defines += [ "IS_CHROMECAST" ]
}
configs += [
"//build/config:precompiled_headers",
"//build/config/compiler:no_size_t_to_int_warning",
......
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