diff options
Diffstat (limited to 'cc/output')
-rw-r--r-- | cc/output/context_provider.h | 3 | ||||
-rw-r--r-- | cc/output/delegating_renderer.cc | 17 | ||||
-rw-r--r-- | cc/output/delegating_renderer.h | 5 | ||||
-rw-r--r-- | cc/output/gl_renderer.cc | 12 | ||||
-rw-r--r-- | cc/output/gl_renderer.h | 5 | ||||
-rw-r--r-- | cc/output/gl_renderer_unittest.cc | 19 | ||||
-rw-r--r-- | cc/output/renderer.cc | 8 | ||||
-rw-r--r-- | cc/output/renderer.h | 8 | ||||
-rw-r--r-- | cc/output/renderer_unittest.cc | 93 | ||||
-rw-r--r-- | cc/output/software_renderer.cc | 9 | ||||
-rw-r--r-- | cc/output/software_renderer.h | 4 |
11 files changed, 130 insertions, 53 deletions
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_; |