summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/cc_tests.gyp3
-rw-r--r--cc/output/context_provider.h3
-rw-r--r--cc/output/delegating_renderer.cc17
-rw-r--r--cc/output/delegating_renderer.h5
-rw-r--r--cc/output/gl_renderer.cc12
-rw-r--r--cc/output/gl_renderer.h5
-rw-r--r--cc/output/gl_renderer_unittest.cc19
-rw-r--r--cc/output/renderer.cc8
-rw-r--r--cc/output/renderer.h8
-rw-r--r--cc/output/renderer_unittest.cc93
-rw-r--r--cc/output/software_renderer.cc9
-rw-r--r--cc/output/software_renderer.h4
-rw-r--r--cc/resources/raster_worker_pool_perftest.cc1
-rw-r--r--cc/test/fake_renderer_client.cc17
-rw-r--r--cc/test/fake_renderer_client.h30
-rw-r--r--cc/test/test_context_provider.cc3
-rw-r--r--cc/test/test_context_provider.h1
-rw-r--r--cc/test/test_in_process_context_provider.cc5
-rw-r--r--cc/test/test_in_process_context_provider.h1
-rw-r--r--content/common/gpu/client/context_provider_command_buffer.cc13
-rw-r--r--content/common/gpu/client/context_provider_command_buffer.h1
-rw-r--r--mojo/examples/compositor_app/mojo_context_provider.h1
-rw-r--r--webkit/common/gpu/context_provider_in_process.cc7
-rw-r--r--webkit/common/gpu/context_provider_in_process.h1
-rw-r--r--webkit/common/gpu/grcontext_for_webgraphicscontext3d.cc32
-rw-r--r--webkit/common/gpu/grcontext_for_webgraphicscontext3d.h2
26 files changed, 221 insertions, 80 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp
index f9688b5..af73286 100644
--- a/cc/cc_tests.gyp
+++ b/cc/cc_tests.gyp
@@ -60,6 +60,7 @@
'output/output_surface_unittest.cc',
'output/overlay_unittest.cc',
'output/renderer_pixeltest.cc',
+ 'output/renderer_unittest.cc',
'output/shader_unittest.cc',
'output/software_renderer_unittest.cc',
'quads/draw_quad_unittest.cc',
@@ -154,6 +155,8 @@
'test/fake_picture_pile_impl.h',
'test/fake_proxy.cc',
'test/fake_proxy.h',
+ 'test/fake_renderer_client.cc',
+ 'test/fake_renderer_client.h',
'test/fake_rendering_stats_instrumentation.h',
'test/fake_scoped_ui_resource.cc',
'test/fake_scoped_ui_resource.h',
diff --git a/cc/output/context_provider.h b/cc/output/context_provider.h
index 934118e..7362e8b 100644
--- a/cc/output/context_provider.h
+++ b/cc/output/context_provider.h
@@ -50,6 +50,9 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
// one.
virtual void VerifyContexts() = 0;
+ // Delete all cached gpu resources.
+ virtual void DeleteCachedResources() = 0;
+
// A method to be called from the main thread that should return true if
// the context inside the provider is no longer valid.
virtual bool DestroyedOnMainThread() = 0;
diff --git a/cc/output/delegating_renderer.cc b/cc/output/delegating_renderer.cc
index 63c975a..1451a65 100644
--- a/cc/output/delegating_renderer.cc
+++ b/cc/output/delegating_renderer.cc
@@ -45,8 +45,7 @@ DelegatingRenderer::DelegatingRenderer(RendererClient* client,
ResourceProvider* resource_provider)
: Renderer(client, settings),
output_surface_(output_surface),
- resource_provider_(resource_provider),
- visible_(true) {
+ resource_provider_(resource_provider) {
DCHECK(resource_provider_);
capabilities_.using_partial_swap = false;
@@ -137,23 +136,21 @@ bool DelegatingRenderer::IsContextLost() {
return context_provider->IsContextLost();
}
-void DelegatingRenderer::SetVisible(bool visible) {
- if (visible == visible_)
- return;
-
- visible_ = visible;
+void DelegatingRenderer::DidChangeVisibility() {
ContextProvider* context_provider = output_surface_->context_provider();
- if (!visible_) {
+ if (!visible()) {
TRACE_EVENT0("cc", "DelegatingRenderer::SetVisible dropping resources");
resource_provider_->ReleaseCachedData();
- if (context_provider)
+ if (context_provider) {
+ context_provider->DeleteCachedResources();
context_provider->ContextGL()->Flush();
+ }
}
// We loop visibility to the GPU process, since that's what manages memory.
// That will allow it to feed us with memory allocations that we can act
// upon.
if (context_provider)
- context_provider->ContextSupport()->SetSurfaceVisible(visible);
+ context_provider->ContextSupport()->SetSurfaceVisible(visible());
}
void DelegatingRenderer::SendManagedMemoryStats(size_t bytes_visible,
diff --git a/cc/output/delegating_renderer.h b/cc/output/delegating_renderer.h
index eec399a..991ae00 100644
--- a/cc/output/delegating_renderer.h
+++ b/cc/output/delegating_renderer.h
@@ -44,8 +44,6 @@ class CC_EXPORT DelegatingRenderer : public Renderer {
virtual bool IsContextLost() OVERRIDE;
- virtual void SetVisible(bool visible) OVERRIDE;
-
virtual void SendManagedMemoryStats(size_t bytes_visible,
size_t bytes_visible_and_nearby,
size_t bytes_allocated) OVERRIDE;
@@ -56,11 +54,12 @@ class CC_EXPORT DelegatingRenderer : public Renderer {
OutputSurface* output_surface,
ResourceProvider* resource_provider);
+ virtual void DidChangeVisibility() OVERRIDE;
+
OutputSurface* output_surface_;
ResourceProvider* resource_provider_;
RendererCapabilitiesImpl capabilities_;
scoped_ptr<DelegatedFrameData> delegated_frame_data_;
- bool visible_;
DISALLOW_COPY_AND_ASSIGN(DelegatingRenderer);
};
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index b980d21..43c60337 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -302,7 +302,6 @@ GLRenderer::GLRenderer(RendererClient* client,
context_support_(output_surface->context_provider()->ContextSupport()),
texture_mailbox_deleter_(texture_mailbox_deleter),
is_backbuffer_discarded_(false),
- visible_(true),
is_scissor_enabled_(false),
scissor_rect_needs_reset_(true),
stencil_shadow_(false),
@@ -374,14 +373,10 @@ void GLRenderer::DebugGLCall(GLES2Interface* gl,
<< static_cast<int>(error) << "\n";
}
-void GLRenderer::SetVisible(bool visible) {
- if (visible_ == visible)
- return;
- visible_ = visible;
-
+void GLRenderer::DidChangeVisibility() {
EnforceMemoryPolicy();
- context_support_->SetSurfaceVisible(visible);
+ context_support_->SetSurfaceVisible(visible());
}
void GLRenderer::SendManagedMemoryStats(size_t bytes_visible,
@@ -2289,11 +2284,12 @@ void GLRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) {
}
void GLRenderer::EnforceMemoryPolicy() {
- if (!visible_) {
+ if (!visible()) {
TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources");
ReleaseRenderPassTextures();
DiscardBackbuffer();
resource_provider_->ReleaseCachedData();
+ output_surface_->context_provider()->DeleteCachedResources();
GLC(gl_, gl_->Flush());
}
}
diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h
index 48a9931..a6a9b2e 100644
--- a/cc/output/gl_renderer.h
+++ b/cc/output/gl_renderer.h
@@ -70,8 +70,6 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
virtual bool IsContextLost() OVERRIDE;
- virtual void SetVisible(bool visible) OVERRIDE;
-
virtual void SendManagedMemoryStats(size_t bytes_visible,
size_t bytes_visible_and_nearby,
size_t bytes_allocated) OVERRIDE;
@@ -89,6 +87,8 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
TextureMailboxDeleter* texture_mailbox_deleter,
int highp_threshold_min);
+ virtual void DidChangeVisibility() OVERRIDE;
+
bool IsBackbufferDiscarded() const { return is_backbuffer_discarded_; }
void InitializeGrContext();
@@ -421,7 +421,6 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
gfx::Rect viewport_;
bool is_backbuffer_discarded_;
bool is_using_bind_uniform_;
- bool visible_;
bool is_scissor_enabled_;
bool scissor_rect_needs_reset_;
bool stencil_shadow_;
diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc
index 0723e3a..f82c06a 100644
--- a/cc/output/gl_renderer_unittest.cc
+++ b/cc/output/gl_renderer_unittest.cc
@@ -14,6 +14,7 @@
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_output_surface_client.h"
+#include "cc/test/fake_renderer_client.h"
#include "cc/test/mock_quad_culler.h"
#include "cc/test/pixel_test.h"
#include "cc/test/render_pass_test_common.h"
@@ -124,24 +125,6 @@ namespace {
TEST_F(GLRendererShaderPixelTest, AllShadersCompile) { TestShaders(); }
#endif
-class FakeRendererClient : public RendererClient {
- public:
- FakeRendererClient() : set_full_root_layer_damage_count_(0) {}
-
- // RendererClient methods.
- virtual void SetFullRootLayerDamage() OVERRIDE {
- set_full_root_layer_damage_count_++;
- }
-
- // Methods added for test.
- int set_full_root_layer_damage_count() const {
- return set_full_root_layer_damage_count_;
- }
-
- private:
- int set_full_root_layer_damage_count_;
-};
-
class FakeRendererGL : public GLRenderer {
public:
FakeRendererGL(RendererClient* client,
diff --git a/cc/output/renderer.cc b/cc/output/renderer.cc
index e12d69e..e177149 100644
--- a/cc/output/renderer.cc
+++ b/cc/output/renderer.cc
@@ -14,6 +14,14 @@ bool Renderer::IsContextLost() {
return false;
}
+void Renderer::SetVisible(bool visible) {
+ if (visible_ == visible)
+ return;
+
+ visible_ = visible;
+ DidChangeVisibility();
+}
+
RendererCapabilitiesImpl::RendererCapabilitiesImpl()
: best_texture_format(RGBA_8888),
allow_partial_texture_updates(false),
diff --git a/cc/output/renderer.h b/cc/output/renderer.h
index d9f3310..99cc628 100644
--- a/cc/output/renderer.h
+++ b/cc/output/renderer.h
@@ -78,7 +78,8 @@ class CC_EXPORT Renderer {
virtual bool IsContextLost();
- virtual void SetVisible(bool visible) = 0;
+ bool visible() const { return visible_; }
+ void SetVisible(bool visible);
virtual void SendManagedMemoryStats(size_t bytes_visible,
size_t bytes_visible_and_nearby,
@@ -86,10 +87,13 @@ class CC_EXPORT Renderer {
protected:
explicit Renderer(RendererClient* client, const LayerTreeSettings* settings)
- : client_(client), settings_(settings) {}
+ : client_(client), settings_(settings), visible_(true) {}
+
+ virtual void DidChangeVisibility() = 0;
RendererClient* client_;
const LayerTreeSettings* settings_;
+ bool visible_;
private:
DISALLOW_COPY_AND_ASSIGN(Renderer);
diff --git a/cc/output/renderer_unittest.cc b/cc/output/renderer_unittest.cc
new file mode 100644
index 0000000..c6185ec
--- /dev/null
+++ b/cc/output/renderer_unittest.cc
@@ -0,0 +1,93 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/output/delegating_renderer.h"
+#include "cc/output/gl_renderer.h"
+#include "cc/output/output_surface.h"
+#include "cc/test/fake_output_surface_client.h"
+#include "cc/test/fake_renderer_client.h"
+#include "cc/test/test_context_provider.h"
+#include "cc/test/test_web_graphics_context_3d.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+namespace {
+
+class MockContextProvider : public TestContextProvider {
+ public:
+ explicit MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context)
+ : TestContextProvider(context.Pass()) {}
+ MOCK_METHOD0(DeleteCachedResources, void());
+
+ protected:
+ ~MockContextProvider() {}
+};
+
+template <class T>
+scoped_ptr<Renderer> CreateRenderer(RendererClient* client,
+ const LayerTreeSettings* settings,
+ OutputSurface* output_surface,
+ ResourceProvider* resource_provider);
+
+template <>
+scoped_ptr<Renderer> CreateRenderer<DelegatingRenderer>(
+ RendererClient* client,
+ const LayerTreeSettings* settings,
+ OutputSurface* output_surface,
+ ResourceProvider* resource_provider) {
+ return DelegatingRenderer::Create(
+ client, settings, output_surface, resource_provider)
+ .PassAs<Renderer>();
+}
+
+template <>
+scoped_ptr<Renderer> CreateRenderer<GLRenderer>(
+ RendererClient* client,
+ const LayerTreeSettings* settings,
+ OutputSurface* output_surface,
+ ResourceProvider* resource_provider) {
+ return GLRenderer::Create(
+ client, settings, output_surface, resource_provider, NULL, 0)
+ .PassAs<Renderer>();
+}
+
+template <typename T>
+class RendererTest : public ::testing::Test {
+ protected:
+ virtual void SetUp() {
+ context_provider_ =
+ new MockContextProvider(TestWebGraphicsContext3D::Create());
+ output_surface_.reset(new OutputSurface(context_provider_));
+ output_surface_->BindToClient(&output_surface_client_);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1);
+ renderer_ = CreateRenderer<T>(&renderer_client_,
+ &tree_settings_,
+ output_surface_.get(),
+ resource_provider_.get());
+ }
+
+ FakeRendererClient renderer_client_;
+ LayerTreeSettings tree_settings_;
+ FakeOutputSurfaceClient output_surface_client_;
+ scoped_refptr<MockContextProvider> context_provider_;
+ scoped_ptr<OutputSurface> output_surface_;
+ scoped_ptr<ResourceProvider> resource_provider_;
+ scoped_ptr<Renderer> renderer_;
+};
+
+typedef ::testing::Types<DelegatingRenderer, GLRenderer> RendererTypes;
+TYPED_TEST_CASE(RendererTest, RendererTypes);
+
+TYPED_TEST(RendererTest, ContextPurgedWhenRendererBecomesInvisible) {
+ EXPECT_CALL(*(this->context_provider_), DeleteCachedResources()).Times(1);
+
+ EXPECT_TRUE(this->renderer_->visible());
+ this->renderer_->SetVisible(false);
+ EXPECT_FALSE(this->renderer_->visible());
+}
+
+} // namespace
+} // namespace cc
diff --git a/cc/output/software_renderer.cc b/cc/output/software_renderer.cc
index fb24e44..dc117ef 100644
--- a/cc/output/software_renderer.cc
+++ b/cc/output/software_renderer.cc
@@ -115,7 +115,6 @@ SoftwareRenderer::SoftwareRenderer(RendererClient* client,
OutputSurface* output_surface,
ResourceProvider* resource_provider)
: DirectRenderer(client, settings, output_surface, resource_provider),
- visible_(true),
is_scissor_enabled_(false),
is_backbuffer_discarded_(false),
output_device_(output_surface->software_device()),
@@ -655,12 +654,8 @@ void SoftwareRenderer::GetFramebufferPixels(void* pixels,
output_device_->CopyToPixels(frame_rect, pixels);
}
-void SoftwareRenderer::SetVisible(bool visible) {
- if (visible_ == visible)
- return;
- visible_ = visible;
-
- if (visible_)
+void SoftwareRenderer::DidChangeVisibility() {
+ if (visible())
EnsureBackbuffer();
else
DiscardBackbuffer();
diff --git a/cc/output/software_renderer.h b/cc/output/software_renderer.h
index 3419342..7583bd8 100644
--- a/cc/output/software_renderer.h
+++ b/cc/output/software_renderer.h
@@ -39,7 +39,6 @@ class CC_EXPORT SoftwareRenderer : public DirectRenderer {
virtual void SwapBuffers(const CompositorFrameMetadata& metadata) OVERRIDE;
virtual void GetFramebufferPixels(void* pixels,
const gfx::Rect& rect) OVERRIDE;
- virtual void SetVisible(bool visible) OVERRIDE;
virtual void SendManagedMemoryStats(
size_t bytes_visible,
size_t bytes_visible_and_nearby,
@@ -76,6 +75,8 @@ class CC_EXPORT SoftwareRenderer : public DirectRenderer {
OutputSurface* output_surface,
ResourceProvider* resource_provider);
+ virtual void DidChangeVisibility() OVERRIDE;
+
private:
void ClearCanvas(SkColor color);
void SetClipRect(const gfx::Rect& rect);
@@ -99,7 +100,6 @@ class CC_EXPORT SoftwareRenderer : public DirectRenderer {
const DrawQuad* quad);
RendererCapabilitiesImpl capabilities_;
- bool visible_;
bool is_scissor_enabled_;
bool is_backbuffer_discarded_;
gfx::Rect scissor_rect_;
diff --git a/cc/resources/raster_worker_pool_perftest.cc b/cc/resources/raster_worker_pool_perftest.cc
index 8c33d17..69ecca5 100644
--- a/cc/resources/raster_worker_pool_perftest.cc
+++ b/cc/resources/raster_worker_pool_perftest.cc
@@ -59,6 +59,7 @@ class PerfContextProvider : public ContextProvider {
virtual class GrContext* GrContext() OVERRIDE { return NULL; }
virtual bool IsContextLost() OVERRIDE { return false; }
virtual void VerifyContexts() OVERRIDE {}
+ virtual void DeleteCachedResources() OVERRIDE {}
virtual bool DestroyedOnMainThread() OVERRIDE { return false; }
virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE {}
virtual void SetMemoryPolicyChangedCallback(
diff --git a/cc/test/fake_renderer_client.cc b/cc/test/fake_renderer_client.cc
new file mode 100644
index 0000000..f45831d
--- /dev/null
+++ b/cc/test/fake_renderer_client.cc
@@ -0,0 +1,17 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/test/fake_renderer_client.h"
+
+namespace cc {
+
+FakeRendererClient::FakeRendererClient()
+ : set_full_root_layer_damage_count_(0) {
+}
+
+void FakeRendererClient::SetFullRootLayerDamage() {
+ ++set_full_root_layer_damage_count_;
+}
+
+} // namespace cc
diff --git a/cc/test/fake_renderer_client.h b/cc/test/fake_renderer_client.h
new file mode 100644
index 0000000..9854b01
--- /dev/null
+++ b/cc/test/fake_renderer_client.h
@@ -0,0 +1,30 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_TEST_FAKE_RENDERER_CLIENT_H_
+#define CC_TEST_FAKE_RENDERER_CLIENT_H_
+
+#include "cc/output/renderer.h"
+
+namespace cc {
+
+class FakeRendererClient : public RendererClient {
+ public:
+ FakeRendererClient();
+
+ // RendererClient methods.
+ virtual void SetFullRootLayerDamage() OVERRIDE;
+
+ // Methods added for test.
+ int set_full_root_layer_damage_count() const {
+ return set_full_root_layer_damage_count_;
+ }
+
+ private:
+ int set_full_root_layer_damage_count_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_FAKE_RENDERER_CLIENT_H_
diff --git a/cc/test/test_context_provider.cc b/cc/test/test_context_provider.cc
index 887317a..e7697f1 100644
--- a/cc/test/test_context_provider.cc
+++ b/cc/test/test_context_provider.cc
@@ -111,6 +111,9 @@ void TestContextProvider::VerifyContexts() {
}
}
+void TestContextProvider::DeleteCachedResources() {
+}
+
bool TestContextProvider::DestroyedOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
diff --git a/cc/test/test_context_provider.h b/cc/test/test_context_provider.h
index 68f7382..a57fb58 100644
--- a/cc/test/test_context_provider.h
+++ b/cc/test/test_context_provider.h
@@ -34,6 +34,7 @@ class TestContextProvider : public ContextProvider {
virtual class GrContext* GrContext() OVERRIDE;
virtual bool IsContextLost() OVERRIDE;
virtual void VerifyContexts() OVERRIDE;
+ virtual void DeleteCachedResources() OVERRIDE;
virtual bool DestroyedOnMainThread() OVERRIDE;
virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE;
virtual void SetMemoryPolicyChangedCallback(
diff --git a/cc/test/test_in_process_context_provider.cc b/cc/test/test_in_process_context_provider.cc
index fbd3335..5005c06 100644
--- a/cc/test/test_in_process_context_provider.cc
+++ b/cc/test/test_in_process_context_provider.cc
@@ -115,6 +115,11 @@ bool TestInProcessContextProvider::IsContextLost() { return false; }
void TestInProcessContextProvider::VerifyContexts() {}
+void TestInProcessContextProvider::DeleteCachedResources() {
+ if (gr_context_)
+ gr_context_->freeGpuResources();
+}
+
bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; }
void TestInProcessContextProvider::SetLostContextCallback(
diff --git a/cc/test/test_in_process_context_provider.h b/cc/test/test_in_process_context_provider.h
index 9dfd7e9..721caba 100644
--- a/cc/test/test_in_process_context_provider.h
+++ b/cc/test/test_in_process_context_provider.h
@@ -29,6 +29,7 @@ class TestInProcessContextProvider : public ContextProvider {
virtual Capabilities ContextCapabilities() OVERRIDE;
virtual bool IsContextLost() OVERRIDE;
virtual void VerifyContexts() OVERRIDE;
+ virtual void DeleteCachedResources() OVERRIDE;
virtual bool DestroyedOnMainThread() OVERRIDE;
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) OVERRIDE;
diff --git a/content/common/gpu/client/context_provider_command_buffer.cc b/content/common/gpu/client/context_provider_command_buffer.cc
index 86331cc..f23283e 100644
--- a/content/common/gpu/client/context_provider_command_buffer.cc
+++ b/content/common/gpu/client/context_provider_command_buffer.cc
@@ -154,6 +154,13 @@ void ContextProviderCommandBuffer::VerifyContexts() {
OnLostContext();
}
+void ContextProviderCommandBuffer::DeleteCachedResources() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ if (gr_context_)
+ gr_context_->FreeGpuResources();
+}
+
void ContextProviderCommandBuffer::OnLostContext() {
DCHECK(context_thread_checker_.CalledOnValidThread());
{
@@ -172,11 +179,6 @@ void ContextProviderCommandBuffer::OnMemoryAllocationChanged(
const gpu::MemoryAllocation& allocation) {
DCHECK(context_thread_checker_.CalledOnValidThread());
- if (gr_context_) {
- bool nonzero_allocation = !!allocation.bytes_limit_when_visible;
- gr_context_->SetMemoryLimit(nonzero_allocation);
- }
-
if (memory_policy_changed_callback_.is_null())
return;
@@ -195,7 +197,6 @@ void ContextProviderCommandBuffer::InitializeCapabilities() {
capabilities_ = caps;
}
-
bool ContextProviderCommandBuffer::DestroyedOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
diff --git a/content/common/gpu/client/context_provider_command_buffer.h b/content/common/gpu/client/context_provider_command_buffer.h
index 3446f07..aa8613a 100644
--- a/content/common/gpu/client/context_provider_command_buffer.h
+++ b/content/common/gpu/client/context_provider_command_buffer.h
@@ -44,6 +44,7 @@ class CONTENT_EXPORT ContextProviderCommandBuffer
virtual Capabilities ContextCapabilities() OVERRIDE;
virtual bool IsContextLost() OVERRIDE;
virtual void VerifyContexts() OVERRIDE;
+ virtual void DeleteCachedResources() OVERRIDE;
virtual bool DestroyedOnMainThread() OVERRIDE;
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) OVERRIDE;
diff --git a/mojo/examples/compositor_app/mojo_context_provider.h b/mojo/examples/compositor_app/mojo_context_provider.h
index 04abe80..bcee248 100644
--- a/mojo/examples/compositor_app/mojo_context_provider.h
+++ b/mojo/examples/compositor_app/mojo_context_provider.h
@@ -21,6 +21,7 @@ class MojoContextProvider : public cc::ContextProvider {
virtual Capabilities ContextCapabilities() OVERRIDE;
virtual bool IsContextLost() OVERRIDE;
virtual void VerifyContexts() OVERRIDE {}
+ virtual void DeleteCachedResources() OVERRIDE {}
virtual bool DestroyedOnMainThread() OVERRIDE;
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) OVERRIDE {}
diff --git a/webkit/common/gpu/context_provider_in_process.cc b/webkit/common/gpu/context_provider_in_process.cc
index d71d6fa..3785d38a 100644
--- a/webkit/common/gpu/context_provider_in_process.cc
+++ b/webkit/common/gpu/context_provider_in_process.cc
@@ -164,6 +164,13 @@ void ContextProviderInProcess::VerifyContexts() {
OnLostContext();
}
+void ContextProviderInProcess::DeleteCachedResources() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ if (gr_context_)
+ gr_context_->FreeGpuResources();
+}
+
void ContextProviderInProcess::OnLostContext() {
DCHECK(context_thread_checker_.CalledOnValidThread());
{
diff --git a/webkit/common/gpu/context_provider_in_process.h b/webkit/common/gpu/context_provider_in_process.h
index c42585f..3df327b 100644
--- a/webkit/common/gpu/context_provider_in_process.h
+++ b/webkit/common/gpu/context_provider_in_process.h
@@ -39,6 +39,7 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess
virtual class GrContext* GrContext() OVERRIDE;
virtual bool IsContextLost() OVERRIDE;
virtual void VerifyContexts() OVERRIDE;
+ virtual void DeleteCachedResources() OVERRIDE;
virtual bool DestroyedOnMainThread() OVERRIDE;
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) OVERRIDE;
diff --git a/webkit/common/gpu/grcontext_for_webgraphicscontext3d.cc b/webkit/common/gpu/grcontext_for_webgraphicscontext3d.cc
index f612a14..5c7bc39 100644
--- a/webkit/common/gpu/grcontext_for_webgraphicscontext3d.cc
+++ b/webkit/common/gpu/grcontext_for_webgraphicscontext3d.cc
@@ -35,11 +35,17 @@ GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D(
gr_context_ = skia::AdoptRef(GrContext::Create(
kOpenGL_GrBackend,
reinterpret_cast<GrBackendContext>(interface.get())));
- if (!gr_context_)
- return;
+ if (gr_context_) {
+ // The limit of the number of textures we hold in the GrContext's
+ // bitmap->texture cache.
+ static const int kMaxGaneshTextureCacheCount = 2048;
+ // The limit of the bytes allocated toward textures in the GrContext's
+ // bitmap->texture cache.
+ static const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024;
- bool nonzero_allocation = true;
- SetMemoryLimit(nonzero_allocation);
+ gr_context_->setTextureCacheLimits(kMaxGaneshTextureCacheCount,
+ kMaxGaneshTextureCacheBytes);
+ }
}
GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() {
@@ -50,25 +56,11 @@ void GrContextForWebGraphicsContext3D::OnLostContext() {
gr_context_->contextDestroyed();
}
-void GrContextForWebGraphicsContext3D::SetMemoryLimit(bool nonzero_allocation) {
- if (!gr_context_)
- return;
-
- if (nonzero_allocation) {
- // The limit of the number of textures we hold in the GrContext's
- // bitmap->texture cache.
- static const int kMaxGaneshTextureCacheCount = 2048;
- // The limit of the bytes allocated toward textures in the GrContext's
- // bitmap->texture cache.
- static const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024;
-
- gr_context_->setTextureCacheLimits(
- kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
- } else {
+void GrContextForWebGraphicsContext3D::FreeGpuResources() {
+ if (gr_context_) {
TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", \
TRACE_EVENT_SCOPE_THREAD);
gr_context_->freeGpuResources();
- gr_context_->setTextureCacheLimits(0, 0);
}
}
diff --git a/webkit/common/gpu/grcontext_for_webgraphicscontext3d.h b/webkit/common/gpu/grcontext_for_webgraphicscontext3d.h
index d018833..5c983aa 100644
--- a/webkit/common/gpu/grcontext_for_webgraphicscontext3d.h
+++ b/webkit/common/gpu/grcontext_for_webgraphicscontext3d.h
@@ -27,7 +27,7 @@ class WEBKIT_GPU_EXPORT GrContextForWebGraphicsContext3D {
GrContext* get() { return gr_context_.get(); }
void OnLostContext();
- void SetMemoryLimit(bool nonzero_allocation);
+ void FreeGpuResources();
private:
skia::RefPtr<class GrContext> gr_context_;