Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Move texture registry to platform view (#4388)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sigurdm authored Nov 22, 2017
1 parent 1e6ebb3 commit 9d711cc
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions flow/compositor_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
8 changes: 6 additions & 2 deletions flow/compositor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand All @@ -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<ProcessInfo> process_info_;
Counter frame_count_;
Stopwatch frame_time_;
Expand Down
7 changes: 6 additions & 1 deletion shell/common/null_rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
4 changes: 3 additions & 1 deletion shell/common/null_rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> surface_;
fml::WeakPtrFactory<NullRasterizer> weak_factory_;
flow::TextureRegistry texture_registry_;
flow::TextureRegistry* texture_registry_;

FXL_DISALLOW_COPY_AND_ASSIGN(NullRasterizer);
};
Expand Down
2 changes: 2 additions & 0 deletions shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace shell {

PlatformView::PlatformView(std::unique_ptr<Rasterizer> rasterizer)
: rasterizer_(std::move(rasterizer)), size_(SkISize::Make(0, 0)) {
rasterizer_->SetTextureRegistry(&texture_registry_);
Shell::Shared().AddPlatformView(this);
}

Expand All @@ -35,6 +36,7 @@ void PlatformView::SetRasterizer(std::unique_ptr<Rasterizer> 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());
}

Expand Down
1 change: 1 addition & 0 deletions shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class PlatformView : public std::enable_shared_from_this<PlatformView> {

SurfaceConfig surface_config_;
std::unique_ptr<Rasterizer> rasterizer_;
flow::TextureRegistry texture_registry_;
std::unique_ptr<Engine> engine_;
std::unique_ptr<VsyncWaiter> vsync_waiter_;
SkISize size_;
Expand Down
2 changes: 2 additions & 0 deletions shell/common/rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions shell/gpu/gpu_rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,8 @@ void GPURasterizer::NotifyNextFrameOnce() {
}
}

void GPURasterizer::SetTextureRegistry(flow::TextureRegistry* textureRegistry) {
compositor_context_.SetTextureRegistry(textureRegistry);
}

} // namespace shell
2 changes: 2 additions & 0 deletions shell/gpu/gpu_rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> surface_;
flow::CompositorContext compositor_context_;
Expand Down

0 comments on commit 9d711cc

Please sign in to comment.