mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
Move texture registry ownership to platform view (#4348)
* Move texture registry ownership to platform view This enables the texture registry to survive activity pause on Android.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ProcessInfo> process_info_;
|
||||
Counter frame_count_;
|
||||
Stopwatch frame_time_;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -35,6 +35,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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -161,4 +161,8 @@ void GPURasterizer::NotifyNextFrameOnce() {
|
||||
}
|
||||
}
|
||||
|
||||
void GPURasterizer::SetTextureRegistry(flow::TextureRegistry* textureRegistry) {
|
||||
compositor_context_.SetTextureRegistry(std::move(textureRegistry));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user