From 9d711ccf9b3ad0e4140ebb0dbd282587e8c01624 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Wed, 22 Nov 2017 14:39:03 +0100 Subject: [PATCH] Move texture registry to platform view (#4388) * Move texture registry ownership to platform view This enables the texture registry to survive activity pause on Android. * Remove debug info * Formatted * Set texture registry on initial rasterizer * Remove unneccessary std::move --- flow/compositor_context.cc | 4 ++-- flow/compositor_context.h | 8 ++++++-- shell/common/null_rasterizer.cc | 7 ++++++- shell/common/null_rasterizer.h | 4 +++- shell/common/platform_view.cc | 2 ++ shell/common/platform_view.h | 1 + shell/common/rasterizer.h | 2 ++ shell/gpu/gpu_rasterizer.cc | 4 ++++ shell/gpu/gpu_rasterizer.h | 2 ++ 9 files changed, 28 insertions(+), 6 deletions(-) diff --git a/flow/compositor_context.cc b/flow/compositor_context.cc index 9f87eed8d..e0d17229e 100644 --- a/flow/compositor_context.cc +++ b/flow/compositor_context.cc @@ -58,11 +58,11 @@ CompositorContext::ScopedFrame::~ScopedFrame() { } void CompositorContext::OnGrContextCreated() { - texture_registry_.OnGrContextCreated(); + texture_registry_->OnGrContextCreated(); } void CompositorContext::OnGrContextDestroyed() { - texture_registry_.OnGrContextDestroyed(); + texture_registry_->OnGrContextDestroyed(); raster_cache_.Clear(); } diff --git a/flow/compositor_context.h b/flow/compositor_context.h index 0b40bb5ed..2d3104227 100644 --- a/flow/compositor_context.h +++ b/flow/compositor_context.h @@ -62,7 +62,7 @@ class CompositorContext { RasterCache& raster_cache() { return raster_cache_; } - TextureRegistry& texture_registry() { return texture_registry_; } + TextureRegistry& texture_registry() { return *texture_registry_; } const Counter& frame_count() const { return frame_count_; } @@ -72,9 +72,13 @@ class CompositorContext { const CounterValues& memory_usage() const { return memory_usage_; } + void SetTextureRegistry(TextureRegistry* textureRegistry) { + texture_registry_ = textureRegistry; + } + private: RasterCache raster_cache_; - TextureRegistry texture_registry_; + TextureRegistry* texture_registry_; std::unique_ptr process_info_; Counter frame_count_; Stopwatch frame_time_; diff --git a/shell/common/null_rasterizer.cc b/shell/common/null_rasterizer.cc index adcb3bbac..81efdd11d 100644 --- a/shell/common/null_rasterizer.cc +++ b/shell/common/null_rasterizer.cc @@ -38,7 +38,7 @@ void NullRasterizer::DrawLastLayerTree() { } flow::TextureRegistry& NullRasterizer::GetTextureRegistry() { - return texture_registry_; + return *texture_registry_; } void NullRasterizer::Clear(SkColor color, const SkISize& size) { @@ -59,4 +59,9 @@ void NullRasterizer::AddNextFrameCallback(fxl::Closure nextFrameCallback) { // Null rasterizer. Nothing to do. } +void NullRasterizer::SetTextureRegistry( + flow::TextureRegistry* textureRegistry) { + texture_registry_ = textureRegistry; +} + } // namespace shell diff --git a/shell/common/null_rasterizer.h b/shell/common/null_rasterizer.h index d629f167d..8558a3c3a 100644 --- a/shell/common/null_rasterizer.h +++ b/shell/common/null_rasterizer.h @@ -36,10 +36,12 @@ class NullRasterizer : public Rasterizer { void AddNextFrameCallback(fxl::Closure nextFrameCallback) override; + void SetTextureRegistry(flow::TextureRegistry* textureRegistry) override; + private: std::unique_ptr surface_; fml::WeakPtrFactory weak_factory_; - flow::TextureRegistry texture_registry_; + flow::TextureRegistry* texture_registry_; FXL_DISALLOW_COPY_AND_ASSIGN(NullRasterizer); }; diff --git a/shell/common/platform_view.cc b/shell/common/platform_view.cc index 6d3d3f61e..5479a96b2 100644 --- a/shell/common/platform_view.cc +++ b/shell/common/platform_view.cc @@ -18,6 +18,7 @@ namespace shell { PlatformView::PlatformView(std::unique_ptr rasterizer) : rasterizer_(std::move(rasterizer)), size_(SkISize::Make(0, 0)) { + rasterizer_->SetTextureRegistry(&texture_registry_); Shell::Shared().AddPlatformView(this); } @@ -35,6 +36,7 @@ void PlatformView::SetRasterizer(std::unique_ptr rasterizer) { Rasterizer* r = rasterizer_.release(); blink::Threads::Gpu()->PostTask([r]() { delete r; }); rasterizer_ = std::move(rasterizer); + rasterizer_->SetTextureRegistry(&texture_registry_); engine_->set_rasterizer(rasterizer_->GetWeakRasterizerPtr()); } diff --git a/shell/common/platform_view.h b/shell/common/platform_view.h index 29970ec3e..a377f721e 100644 --- a/shell/common/platform_view.h +++ b/shell/common/platform_view.h @@ -90,6 +90,7 @@ class PlatformView : public std::enable_shared_from_this { SurfaceConfig surface_config_; std::unique_ptr rasterizer_; + flow::TextureRegistry texture_registry_; std::unique_ptr engine_; std::unique_ptr vsync_waiter_; SkISize size_; diff --git a/shell/common/rasterizer.h b/shell/common/rasterizer.h index fdecdec7c..6f45f49d8 100644 --- a/shell/common/rasterizer.h +++ b/shell/common/rasterizer.h @@ -42,6 +42,8 @@ class Rasterizer { // Set a callback to be called once when the next frame is drawn. virtual void AddNextFrameCallback(fxl::Closure nextFrameCallback) = 0; + + virtual void SetTextureRegistry(flow::TextureRegistry* textureRegistry) = 0; }; } // namespace shell diff --git a/shell/gpu/gpu_rasterizer.cc b/shell/gpu/gpu_rasterizer.cc index fe60f6248..3424f989b 100644 --- a/shell/gpu/gpu_rasterizer.cc +++ b/shell/gpu/gpu_rasterizer.cc @@ -161,4 +161,8 @@ void GPURasterizer::NotifyNextFrameOnce() { } } +void GPURasterizer::SetTextureRegistry(flow::TextureRegistry* textureRegistry) { + compositor_context_.SetTextureRegistry(textureRegistry); +} + } // namespace shell diff --git a/shell/gpu/gpu_rasterizer.h b/shell/gpu/gpu_rasterizer.h index d92fe6312..ad16ee2c4 100644 --- a/shell/gpu/gpu_rasterizer.h +++ b/shell/gpu/gpu_rasterizer.h @@ -42,6 +42,8 @@ class GPURasterizer : public Rasterizer { // Set a callback to be called once when the next frame is drawn. void AddNextFrameCallback(fxl::Closure nextFrameCallback) override; + void SetTextureRegistry(flow::TextureRegistry* textureRegistry) override; + private: std::unique_ptr surface_; flow::CompositorContext compositor_context_; -- GitLab