From b9ff394182d31f6581471729ed87fd8303df1043 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 21 Apr 2016 23:05:41 -0700 Subject: [PATCH] Break dependency from Layer to PaintContext (#2609) Instead, make Layer::Paint take a new PaintContext that has just exactly the state that it needs, mirroring PrerollContext. Also, rename PaintContext to CompositorContext because it holds the context for the whole compositor. --- flow/BUILD.gn | 4 +- flow/compositor_context.cc | 58 +++++++++++++++++++ .../{paint_context.h => compositor_context.h} | 26 ++++----- flow/layers/backdrop_filter_layer.cc | 11 ++-- flow/layers/backdrop_filter_layer.h | 2 +- flow/layers/child_scene_layer.cc | 2 +- flow/layers/child_scene_layer.h | 2 +- flow/layers/clip_path_layer.cc | 11 ++-- flow/layers/clip_path_layer.h | 2 +- flow/layers/clip_rect_layer.cc | 9 ++- flow/layers/clip_rect_layer.h | 2 +- flow/layers/clip_rrect_layer.cc | 11 ++-- flow/layers/clip_rrect_layer.h | 2 +- flow/layers/color_filter_layer.cc | 9 ++- flow/layers/color_filter_layer.h | 2 +- flow/layers/container_layer.cc | 4 +- flow/layers/container_layer.h | 2 +- flow/layers/layer.h | 12 +++- flow/layers/layer_tree.cc | 9 ++- flow/layers/layer_tree.h | 3 +- flow/layers/opacity_layer.cc | 9 ++- flow/layers/opacity_layer.h | 2 +- flow/layers/performance_overlay_layer.cc | 8 +-- flow/layers/performance_overlay_layer.h | 2 +- flow/layers/picture_layer.cc | 17 +++--- flow/layers/picture_layer.h | 2 +- flow/layers/shader_mask_layer.cc | 14 ++--- flow/layers/shader_mask_layer.h | 2 +- flow/layers/transform_layer.cc | 9 ++- flow/layers/transform_layer.h | 2 +- flow/paint_context.cc | 56 ------------------ flow/raster_cache.cc | 2 +- sky/shell/diagnostic/diagnostic_server.cc | 6 +- sky/shell/gpu/direct/rasterizer_direct.cc | 12 ++-- sky/shell/gpu/direct/rasterizer_direct.h | 4 +- sky/shell/gpu/mojo/rasterizer_mojo.cc | 6 +- sky/shell/gpu/mojo/rasterizer_mojo.h | 4 +- 37 files changed, 176 insertions(+), 164 deletions(-) create mode 100644 flow/compositor_context.cc rename flow/{paint_context.h => compositor_context.h} (73%) delete mode 100644 flow/paint_context.cc diff --git a/flow/BUILD.gn b/flow/BUILD.gn index bd2b485b8..00370e650 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -6,6 +6,8 @@ source_set("flow") { sources = [ "checkerboard.cc", "checkerboard.h", + "compositor_context.cc", + "compositor_context.h", "instrumentation.cc", "instrumentation.h", "layers/backdrop_filter_layer.cc", @@ -36,8 +38,6 @@ source_set("flow") { "layers/shader_mask_layer.h", "layers/transform_layer.cc", "layers/transform_layer.h", - "paint_context.cc", - "paint_context.h", "raster_cache.cc", "raster_cache.h", ] diff --git a/flow/compositor_context.cc b/flow/compositor_context.cc new file mode 100644 index 000000000..5dbc25f79 --- /dev/null +++ b/flow/compositor_context.cc @@ -0,0 +1,58 @@ +// Copyright 2015 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 "flow/compositor_context.h" + +#include "base/logging.h" +#include "third_party/skia/include/core/SkCanvas.h" + +namespace flow { + +CompositorContext::CompositorContext() { +} + +CompositorContext::~CompositorContext() { +} + +void CompositorContext::BeginFrame(ScopedFrame& frame, + bool enable_instrumentation) { + if (enable_instrumentation) { + frame_count_.Increment(); + frame_time_.Start(); + } +} + +void CompositorContext::EndFrame(ScopedFrame& frame, + bool enable_instrumentation) { + raster_cache_.SweepAfterFrame(); + if (enable_instrumentation) { + frame_time_.Stop(); + } +} + +CompositorContext::ScopedFrame CompositorContext::AcquireFrame( + GrContext* gr_context, SkCanvas& canvas, bool instrumentation_enabled) { + return ScopedFrame(*this, gr_context, canvas, instrumentation_enabled); +} + +CompositorContext::ScopedFrame::ScopedFrame(CompositorContext& context, + GrContext* gr_context, + SkCanvas& canvas, + bool instrumentation_enabled) + : context_(context), gr_context_(gr_context), canvas_(&canvas), + instrumentation_enabled_(instrumentation_enabled) { + context_.BeginFrame(*this, instrumentation_enabled_); +} + +CompositorContext::ScopedFrame::ScopedFrame(ScopedFrame&& frame) = default; + +CompositorContext::ScopedFrame::~ScopedFrame() { + context_.EndFrame(*this, instrumentation_enabled_); +} + +void CompositorContext::OnGrContextDestroyed() { + raster_cache_.Clear(); +} + +} // namespace flow diff --git a/flow/paint_context.h b/flow/compositor_context.h similarity index 73% rename from flow/paint_context.h rename to flow/compositor_context.h index 0f3f8cfc3..4ac7d5174 100644 --- a/flow/paint_context.h +++ b/flow/compositor_context.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLOW_PAINT_CONTEXT_H_ -#define FLOW_PAINT_CONTEXT_H_ +#ifndef FLOW_COMPOSITOR_CONTEXT_H_ +#define FLOW_COMPOSITOR_CONTEXT_H_ #include #include @@ -17,35 +17,35 @@ namespace flow { -class PaintContext { +class CompositorContext { public: class ScopedFrame { public: SkCanvas& canvas() { return *canvas_; } - PaintContext& context() const { return context_; } + CompositorContext& context() const { return context_; } GrContext* gr_context() const { return gr_context_; } ScopedFrame(ScopedFrame&& frame); ~ScopedFrame(); private: - PaintContext& context_; + CompositorContext& context_; GrContext* gr_context_; SkCanvas* canvas_; const bool instrumentation_enabled_; - ScopedFrame(PaintContext& context, + ScopedFrame(CompositorContext& context, GrContext* gr_context, SkCanvas& canvas, bool instrumentation_enabled); - friend class PaintContext; + friend class CompositorContext; DISALLOW_COPY_AND_ASSIGN(ScopedFrame); }; - PaintContext(); - ~PaintContext(); + CompositorContext(); + ~CompositorContext(); ScopedFrame AcquireFrame(GrContext* gr_context, SkCanvas& canvas, @@ -65,12 +65,12 @@ class PaintContext { Stopwatch frame_time_; Stopwatch engine_time_; - void BeginFrame(ScopedFrame& frame, bool enableInstrumentation); - void EndFrame(ScopedFrame& frame, bool enableInstrumentation); + void BeginFrame(ScopedFrame& frame, bool enable_instrumentation); + void EndFrame(ScopedFrame& frame, bool enable_instrumentation); - DISALLOW_COPY_AND_ASSIGN(PaintContext); + DISALLOW_COPY_AND_ASSIGN(CompositorContext); }; } // namespace flow -#endif // FLOW_PAINT_CONTEXT_H_ +#endif // FLOW_COMPOSITOR_CONTEXT_H_ diff --git a/flow/layers/backdrop_filter_layer.cc b/flow/layers/backdrop_filter_layer.cc index 6f328263a..38d7640dc 100644 --- a/flow/layers/backdrop_filter_layer.cc +++ b/flow/layers/backdrop_filter_layer.cc @@ -4,6 +4,8 @@ #include "flow/layers/backdrop_filter_layer.h" +#include "third_party/skia/include/core/SkImageFilter.h" + namespace flow { BackdropFilterLayer::BackdropFilterLayer() { @@ -12,12 +14,11 @@ BackdropFilterLayer::BackdropFilterLayer() { BackdropFilterLayer::~BackdropFilterLayer() { } -void BackdropFilterLayer::Paint(PaintContext::ScopedFrame& frame) { - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, false); - canvas.saveLayer(SkCanvas::SaveLayerRec{ +void BackdropFilterLayer::Paint(PaintContext& context) { + SkAutoCanvasRestore save(&context.canvas, false); + context.canvas.saveLayer(SkCanvas::SaveLayerRec{ &paint_bounds(), nullptr, filter_.get(), 0}); - PaintChildren(frame); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/backdrop_filter_layer.h b/flow/layers/backdrop_filter_layer.h index 3d4be1a0a..6c7362b96 100644 --- a/flow/layers/backdrop_filter_layer.h +++ b/flow/layers/backdrop_filter_layer.h @@ -17,7 +17,7 @@ class BackdropFilterLayer : public ContainerLayer { void set_filter(SkImageFilter* filter) { filter_ = skia::SharePtr(filter); } protected: - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: skia::RefPtr filter_; diff --git a/flow/layers/child_scene_layer.cc b/flow/layers/child_scene_layer.cc index a033d0534..59379c8d0 100644 --- a/flow/layers/child_scene_layer.cc +++ b/flow/layers/child_scene_layer.cc @@ -24,7 +24,7 @@ void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { transform_.preScale(inverse_device_pixel_ratio, inverse_device_pixel_ratio); } -void ChildSceneLayer::Paint(PaintContext::ScopedFrame& frame) { +void ChildSceneLayer::Paint(PaintContext& context) { } void ChildSceneLayer::UpdateScene(mojo::gfx::composition::SceneUpdate* update, diff --git a/flow/layers/child_scene_layer.h b/flow/layers/child_scene_layer.h index e777b33b9..7a573728c 100644 --- a/flow/layers/child_scene_layer.h +++ b/flow/layers/child_scene_layer.h @@ -30,7 +30,7 @@ class ChildSceneLayer : public Layer { } void Preroll(PrerollContext* context, const SkMatrix& matrix) override; - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; void UpdateScene(mojo::gfx::composition::SceneUpdate* update, mojo::gfx::composition::Node* container) override; diff --git a/flow/layers/clip_path_layer.cc b/flow/layers/clip_path_layer.cc index 277d8fbe2..b11190d02 100644 --- a/flow/layers/clip_path_layer.cc +++ b/flow/layers/clip_path_layer.cc @@ -19,12 +19,11 @@ void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { set_paint_bounds(context->child_paint_bounds); } -void ClipPathLayer::Paint(PaintContext::ScopedFrame& frame) { - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, false); - canvas.saveLayer(&paint_bounds(), nullptr); - canvas.clipPath(clip_path_); - PaintChildren(frame); +void ClipPathLayer::Paint(PaintContext& context) { + SkAutoCanvasRestore save(&context.canvas, false); + context.canvas.saveLayer(&paint_bounds(), nullptr); + context.canvas.clipPath(clip_path_); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/clip_path_layer.h b/flow/layers/clip_path_layer.h index ad1bf166a..70cd6e589 100644 --- a/flow/layers/clip_path_layer.h +++ b/flow/layers/clip_path_layer.h @@ -18,7 +18,7 @@ class ClipPathLayer : public ContainerLayer { protected: void Preroll(PrerollContext* context, const SkMatrix& matrix) override; - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: SkPath clip_path_; diff --git a/flow/layers/clip_rect_layer.cc b/flow/layers/clip_rect_layer.cc index de02d8376..436c6c1b9 100644 --- a/flow/layers/clip_rect_layer.cc +++ b/flow/layers/clip_rect_layer.cc @@ -19,11 +19,10 @@ void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { set_paint_bounds(context->child_paint_bounds); } -void ClipRectLayer::Paint(PaintContext::ScopedFrame& frame) { - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, true); - canvas.clipRect(paint_bounds()); - PaintChildren(frame); +void ClipRectLayer::Paint(PaintContext& context) { + SkAutoCanvasRestore save(&context.canvas, true); + context.canvas.clipRect(paint_bounds()); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/clip_rect_layer.h b/flow/layers/clip_rect_layer.h index 8abc2187c..6804a657c 100644 --- a/flow/layers/clip_rect_layer.h +++ b/flow/layers/clip_rect_layer.h @@ -18,7 +18,7 @@ class ClipRectLayer : public ContainerLayer { protected: void Preroll(PrerollContext* context, const SkMatrix& matrix) override; - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: SkRect clip_rect_; diff --git a/flow/layers/clip_rrect_layer.cc b/flow/layers/clip_rrect_layer.cc index ca6b3e0ab..248bbb8e5 100644 --- a/flow/layers/clip_rrect_layer.cc +++ b/flow/layers/clip_rrect_layer.cc @@ -19,12 +19,11 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { set_paint_bounds(context->child_paint_bounds); } -void ClipRRectLayer::Paint(PaintContext::ScopedFrame& frame) { - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, false); - canvas.saveLayer(&paint_bounds(), nullptr); - canvas.clipRRect(clip_rrect_); - PaintChildren(frame); +void ClipRRectLayer::Paint(PaintContext& context) { + SkAutoCanvasRestore save(&context.canvas, false); + context.canvas.saveLayer(&paint_bounds(), nullptr); + context.canvas.clipRRect(clip_rrect_); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/clip_rrect_layer.h b/flow/layers/clip_rrect_layer.h index bec9f51dc..336c44178 100644 --- a/flow/layers/clip_rrect_layer.h +++ b/flow/layers/clip_rrect_layer.h @@ -18,7 +18,7 @@ class ClipRRectLayer : public ContainerLayer { protected: void Preroll(PrerollContext* context, const SkMatrix& matrix) override; - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: SkRRect clip_rrect_; diff --git a/flow/layers/color_filter_layer.cc b/flow/layers/color_filter_layer.cc index 85352e586..d485a3b44 100644 --- a/flow/layers/color_filter_layer.cc +++ b/flow/layers/color_filter_layer.cc @@ -12,16 +12,15 @@ ColorFilterLayer::ColorFilterLayer() { ColorFilterLayer::~ColorFilterLayer() { } -void ColorFilterLayer::Paint(PaintContext::ScopedFrame& frame) { +void ColorFilterLayer::Paint(PaintContext& context) { skia::RefPtr color_filter = skia::AdoptRef(SkColorFilter::CreateModeFilter(color_, transfer_mode_)); SkPaint paint; paint.setColorFilter(color_filter.get()); - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, false); - canvas.saveLayer(&paint_bounds(), &paint); - PaintChildren(frame); + SkAutoCanvasRestore save(&context.canvas, false); + context.canvas.saveLayer(&paint_bounds(), &paint); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/color_filter_layer.h b/flow/layers/color_filter_layer.h index 901020a2d..4dbdf7d84 100644 --- a/flow/layers/color_filter_layer.h +++ b/flow/layers/color_filter_layer.h @@ -21,7 +21,7 @@ class ColorFilterLayer : public ContainerLayer { } protected: - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: SkColor color_; diff --git a/flow/layers/container_layer.cc b/flow/layers/container_layer.cc index 25c92ac2f..d68b98ba4 100644 --- a/flow/layers/container_layer.cc +++ b/flow/layers/container_layer.cc @@ -33,9 +33,9 @@ void ContainerLayer::PrerollChildren(PrerollContext* context, context->child_paint_bounds = child_paint_bounds; } -void ContainerLayer::PaintChildren(PaintContext::ScopedFrame& frame) const { +void ContainerLayer::PaintChildren(PaintContext& context) const { for (auto& layer : layers_) - layer->Paint(frame); + layer->Paint(context); } void ContainerLayer::UpdateScene(mojo::gfx::composition::SceneUpdate* update, diff --git a/flow/layers/container_layer.h b/flow/layers/container_layer.h index 12a6412ce..09fc66342 100644 --- a/flow/layers/container_layer.h +++ b/flow/layers/container_layer.h @@ -20,7 +20,7 @@ class ContainerLayer : public Layer { void Preroll(PrerollContext* context, const SkMatrix& matrix) override; void PrerollChildren(PrerollContext* context, const SkMatrix& matrix); - void PaintChildren(PaintContext::ScopedFrame& frame) const; + void PaintChildren(PaintContext& context) const; void UpdateScene(mojo::gfx::composition::SceneUpdate* update, mojo::gfx::composition::Node* container) override; diff --git a/flow/layers/layer.h b/flow/layers/layer.h index 9e2731c3f..e3e723183 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -10,7 +10,8 @@ #include "base/logging.h" #include "base/macros.h" -#include "flow/paint_context.h" +#include "flow/instrumentation.h" +#include "flow/raster_cache.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" @@ -46,7 +47,14 @@ class Layer { }; virtual void Preroll(PrerollContext* context, const SkMatrix& matrix); - virtual void Paint(PaintContext::ScopedFrame& frame) = 0; + + struct PaintContext { + SkCanvas& canvas; + const Stopwatch& frame_time; + const Stopwatch& engine_time; + }; + + virtual void Paint(PaintContext& context) = 0; virtual void UpdateScene(mojo::gfx::composition::SceneUpdate* update, mojo::gfx::composition::Node* container); diff --git a/flow/layers/layer_tree.cc b/flow/layers/layer_tree.cc index d1e7f55ba..0d4e58b97 100644 --- a/flow/layers/layer_tree.cc +++ b/flow/layers/layer_tree.cc @@ -15,7 +15,7 @@ LayerTree::LayerTree() : scene_version_(0), rasterizer_tracing_threshold_(0) { LayerTree::~LayerTree() { } -void LayerTree::Raster(PaintContext::ScopedFrame& frame) { +void LayerTree::Raster(CompositorContext::ScopedFrame& frame) { { TRACE_EVENT0("flutter", "LayerTree::Preroll"); Layer::PrerollContext context = { @@ -27,8 +27,13 @@ void LayerTree::Raster(PaintContext::ScopedFrame& frame) { } { + Layer::PaintContext context = { + frame.canvas(), + frame.context().frame_time(), + frame.context().engine_time(), + }; TRACE_EVENT0("flutter", "LayerTree::Paint"); - root_layer_->Paint(frame); + root_layer_->Paint(context); } } diff --git a/flow/layers/layer_tree.h b/flow/layers/layer_tree.h index 4e15e3ced..ef83ce6ab 100644 --- a/flow/layers/layer_tree.h +++ b/flow/layers/layer_tree.h @@ -10,6 +10,7 @@ #include "base/macros.h" #include "base/time/time.h" +#include "flow/compositor_context.h" #include "flow/layers/layer.h" #include "third_party/skia/include/core/SkSize.h" @@ -20,7 +21,7 @@ class LayerTree { LayerTree(); ~LayerTree(); - void Raster(PaintContext::ScopedFrame& frame); + void Raster(CompositorContext::ScopedFrame& frame); // TODO(abarth): Integrate scene updates with the rasterization pass so that // we can draw on top of child scenes (and so that we can apply clips and diff --git a/flow/layers/opacity_layer.cc b/flow/layers/opacity_layer.cc index 4fae92bc3..f9158a49c 100644 --- a/flow/layers/opacity_layer.cc +++ b/flow/layers/opacity_layer.cc @@ -12,14 +12,13 @@ OpacityLayer::OpacityLayer() { OpacityLayer::~OpacityLayer() { } -void OpacityLayer::Paint(PaintContext::ScopedFrame& frame) { +void OpacityLayer::Paint(PaintContext& context) { SkPaint paint; paint.setAlpha(alpha_); - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, false); - canvas.saveLayer(&paint_bounds(), &paint); - PaintChildren(frame); + SkAutoCanvasRestore save(&context.canvas, false); + context.canvas.saveLayer(&paint_bounds(), &paint); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/opacity_layer.h b/flow/layers/opacity_layer.h index 240cd2dbc..70a846081 100644 --- a/flow/layers/opacity_layer.h +++ b/flow/layers/opacity_layer.h @@ -17,7 +17,7 @@ class OpacityLayer : public ContainerLayer { void set_alpha(int alpha) { alpha_ = alpha; } protected: - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: int alpha_; diff --git a/flow/layers/performance_overlay_layer.cc b/flow/layers/performance_overlay_layer.cc index 5869b9ee0..367769312 100644 --- a/flow/layers/performance_overlay_layer.cc +++ b/flow/layers/performance_overlay_layer.cc @@ -64,7 +64,7 @@ PerformanceOverlayLayer::PerformanceOverlayLayer(uint64_t options) } -void PerformanceOverlayLayer::Paint(PaintContext::ScopedFrame& frame) { +void PerformanceOverlayLayer::Paint(PaintContext& context) { if (!options_) return; @@ -72,15 +72,15 @@ void PerformanceOverlayLayer::Paint(PaintContext::ScopedFrame& frame) { SkScalar y = paint_bounds().y(); SkScalar width = paint_bounds().width(); SkScalar height = paint_bounds().height() / 2; - SkAutoCanvasRestore save(&frame.canvas(), true); + SkAutoCanvasRestore save(&context.canvas, true); - VisualizeStopWatch(frame.canvas(), frame.context().frame_time(), + VisualizeStopWatch(context.canvas, context.frame_time, x, y, width, height, options_ & kVisualizeRasterizerStatistics, options_ & kDisplayRasterizerStatistics, "Rasterizer"); - VisualizeStopWatch(frame.canvas(), frame.context().engine_time(), + VisualizeStopWatch(context.canvas, context.engine_time, x, y + height, width, height, options_ & kVisualizeEngineStatistics, options_ & kDisplayEngineStatistics, diff --git a/flow/layers/performance_overlay_layer.h b/flow/layers/performance_overlay_layer.h index 302b1e074..ac5d6735a 100644 --- a/flow/layers/performance_overlay_layer.h +++ b/flow/layers/performance_overlay_layer.h @@ -19,7 +19,7 @@ class PerformanceOverlayLayer : public Layer { public: explicit PerformanceOverlayLayer(uint64_t options); - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: int options_; diff --git a/flow/layers/picture_layer.cc b/flow/layers/picture_layer.cc index 242d9491a..65bed63a1 100644 --- a/flow/layers/picture_layer.cc +++ b/flow/layers/picture_layer.cc @@ -23,22 +23,23 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { image_ = context->raster_cache.GetPrerolledImage( context->gr_context, picture_.get(), matrix); - context->child_paint_bounds = picture_->cullRect().makeOffset(offset_.x(), offset_.y()); + context->child_paint_bounds = + picture_->cullRect().makeOffset(offset_.x(), offset_.y()); } -void PictureLayer::Paint(PaintContext::ScopedFrame& frame) { +void PictureLayer::Paint(PaintContext& context) { DCHECK(picture_); - SkCanvas& canvas = frame.canvas(); if (image_) { SkRect rect = picture_->cullRect().makeOffset(offset_.x(), offset_.y()); - canvas.drawImageRect(image_.get(), rect, nullptr, SkCanvas::kFast_SrcRectConstraint); + context.canvas.drawImageRect(image_.get(), rect, nullptr, + SkCanvas::kFast_SrcRectConstraint); if (kDebugCheckerboardRasterizedLayers) - DrawCheckerboard(&canvas, rect); + DrawCheckerboard(&context.canvas, rect); } else { - SkAutoCanvasRestore save(&canvas, true); - canvas.translate(offset_.x(), offset_.y()); - canvas.drawPicture(picture_.get()); + SkAutoCanvasRestore save(&context.canvas, true); + context.canvas.translate(offset_.x(), offset_.y()); + context.canvas.drawPicture(picture_.get()); } } diff --git a/flow/layers/picture_layer.h b/flow/layers/picture_layer.h index 1b131b5a6..d5cd9e51c 100644 --- a/flow/layers/picture_layer.h +++ b/flow/layers/picture_layer.h @@ -21,7 +21,7 @@ class PictureLayer : public Layer { SkPicture* picture() const { return picture_.get(); } void Preroll(PrerollContext* frame, const SkMatrix& matrix) override; - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: SkPoint offset_; diff --git a/flow/layers/shader_mask_layer.cc b/flow/layers/shader_mask_layer.cc index 043b36b55..c556d7c72 100644 --- a/flow/layers/shader_mask_layer.cc +++ b/flow/layers/shader_mask_layer.cc @@ -12,17 +12,17 @@ ShaderMaskLayer::ShaderMaskLayer() { ShaderMaskLayer::~ShaderMaskLayer() { } -void ShaderMaskLayer::Paint(PaintContext::ScopedFrame& frame) { - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, false); - canvas.saveLayer(&paint_bounds(), nullptr); - PaintChildren(frame); +void ShaderMaskLayer::Paint(PaintContext& context) { + SkAutoCanvasRestore save(&context.canvas, false); + context.canvas.saveLayer(&paint_bounds(), nullptr); + PaintChildren(context); SkPaint paint; paint.setXfermodeMode(transfer_mode_); paint.setShader(shader_); - canvas.translate(mask_rect_.left(), mask_rect_.top()); - canvas.drawRect(SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()), paint); + context.canvas.translate(mask_rect_.left(), mask_rect_.top()); + context.canvas.drawRect( + SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()), paint); } } // namespace flow diff --git a/flow/layers/shader_mask_layer.h b/flow/layers/shader_mask_layer.h index a4002aeb7..52d395bc3 100644 --- a/flow/layers/shader_mask_layer.h +++ b/flow/layers/shader_mask_layer.h @@ -27,7 +27,7 @@ class ShaderMaskLayer : public ContainerLayer { } protected: - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: sk_sp shader_; diff --git a/flow/layers/transform_layer.cc b/flow/layers/transform_layer.cc index d2dfbb4c4..0eb3e1854 100644 --- a/flow/layers/transform_layer.cc +++ b/flow/layers/transform_layer.cc @@ -19,11 +19,10 @@ void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { transform_.mapRect(&context->child_paint_bounds); } -void TransformLayer::Paint(PaintContext::ScopedFrame& frame) { - SkCanvas& canvas = frame.canvas(); - SkAutoCanvasRestore save(&canvas, true); - canvas.concat(transform_); - PaintChildren(frame); +void TransformLayer::Paint(PaintContext& context) { + SkAutoCanvasRestore save(&context.canvas, true); + context.canvas.concat(transform_); + PaintChildren(context); } } // namespace flow diff --git a/flow/layers/transform_layer.h b/flow/layers/transform_layer.h index 84ad6135e..c90da8230 100644 --- a/flow/layers/transform_layer.h +++ b/flow/layers/transform_layer.h @@ -17,7 +17,7 @@ class TransformLayer : public ContainerLayer { void set_transform(const SkMatrix& transform) { transform_ = transform; } void Preroll(PrerollContext* context, const SkMatrix& matrix) override; - void Paint(PaintContext::ScopedFrame& frame) override; + void Paint(PaintContext& context) override; private: SkMatrix transform_; diff --git a/flow/paint_context.cc b/flow/paint_context.cc deleted file mode 100644 index f3a908820..000000000 --- a/flow/paint_context.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 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 "flow/paint_context.h" - -#include "base/logging.h" -#include "third_party/skia/include/core/SkCanvas.h" - -namespace flow { - -PaintContext::PaintContext() { -} - -void PaintContext::BeginFrame(ScopedFrame& frame, bool enableInstrumentation) { - if (enableInstrumentation) { - frame_count_.Increment(); - frame_time_.Start(); - } -} - -void PaintContext::EndFrame(ScopedFrame& frame, bool enableInstrumentation) { - raster_cache_.SweepAfterFrame(); - if (enableInstrumentation) { - frame_time_.Stop(); - } -} - -PaintContext::ScopedFrame PaintContext::AcquireFrame( - GrContext* gr_context, SkCanvas& canvas, bool instrumentation_enabled) { - return ScopedFrame(*this, gr_context, canvas, instrumentation_enabled); -} - -PaintContext::ScopedFrame::ScopedFrame(PaintContext& context, - GrContext* gr_context, - SkCanvas& canvas, - bool instrumentation_enabled) - : context_(context), gr_context_(gr_context), canvas_(&canvas), - instrumentation_enabled_(instrumentation_enabled) { - context_.BeginFrame(*this, instrumentation_enabled_); -} - -PaintContext::ScopedFrame::ScopedFrame(ScopedFrame&& frame) = default; - -PaintContext::ScopedFrame::~ScopedFrame() { - context_.EndFrame(*this, instrumentation_enabled_); -} - -PaintContext::~PaintContext() { -} - -void PaintContext::OnGrContextDestroyed() { - raster_cache_.Clear(); -} - -} // namespace flow diff --git a/flow/raster_cache.cc b/flow/raster_cache.cc index 61018b7a8..8a95311b2 100644 --- a/flow/raster_cache.cc +++ b/flow/raster_cache.cc @@ -6,9 +6,9 @@ #include "base/logging.h" #include "base/trace_event/trace_event.h" -#include "flow/paint_context.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkImage.h" +#include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkSurface.h" #define ENABLE_RASTER_CACHE 1 diff --git a/sky/shell/diagnostic/diagnostic_server.cc b/sky/shell/diagnostic/diagnostic_server.cc index 8dd4ab51f..f6e23e84d 100644 --- a/sky/shell/diagnostic/diagnostic_server.cc +++ b/sky/shell/diagnostic/diagnostic_server.cc @@ -9,7 +9,7 @@ #include "base/logging.h" #include "dart/runtime/include/dart_api.h" #include "dart/runtime/include/dart_native_api.h" -#include "flow/paint_context.h" +#include "flow/compositor_context.h" #include "sky/engine/core/script/embedder_resources.h" #include "sky/engine/tonic/dart_binding_macros.h" #include "sky/engine/tonic/dart_invoke.h" @@ -128,8 +128,8 @@ void DiagnosticServer::SkiaPictureTask(Dart_Port port_id) { recorder.beginRecording(SkRect::MakeWH(layer_tree->frame_size().width(), layer_tree->frame_size().height())); - flow::PaintContext paint_context; - flow::PaintContext::ScopedFrame frame = paint_context.AcquireFrame( + flow::CompositorContext compositor_context; + flow::CompositorContext::ScopedFrame frame = compositor_context.AcquireFrame( nullptr, *recorder.getRecordingCanvas(), false); layer_tree->Raster(frame); diff --git a/sky/shell/gpu/direct/rasterizer_direct.cc b/sky/shell/gpu/direct/rasterizer_direct.cc index 29793a17e..871934012 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.cc +++ b/sky/shell/gpu/direct/rasterizer_direct.cc @@ -85,15 +85,15 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, // There is no way for the compositor to know how long the layer tree // construction took. Fortunately, the layer tree does. Grab that time // for instrumentation. - paint_context_.engine_time().SetLapTime(layer_tree->construction_time()); + compositor_context_.engine_time().SetLapTime(layer_tree->construction_time()); { EnsureGLContext(); CHECK(context_->MakeCurrent(surface_.get())); SkCanvas* canvas = ganesh_canvas_.GetCanvas( surface_->GetBackingFrameBufferObject(), layer_tree->frame_size()); - flow::PaintContext::ScopedFrame frame = - paint_context_.AcquireFrame(ganesh_canvas_.gr_context(), *canvas); + flow::CompositorContext::ScopedFrame frame = + compositor_context_.AcquireFrame(ganesh_canvas_.gr_context(), *canvas); canvas->clear(SK_ColorBLACK); layer_tree->Raster(frame); canvas->flush(); @@ -104,7 +104,7 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, bool frameExceededThreshold = false; uint32_t thresholdInterval = layer_tree->rasterizer_tracing_threshold(); if (thresholdInterval != 0 && - paint_context_.frame_time().LastLap().InMillisecondsF() > + compositor_context_.frame_time().LastLap().InMillisecondsF() > thresholdInterval * kOneFrameDuration) { // While rendering the last frame, if we exceeded the tracing threshold // specified in the layer tree, we force a trace to disk. @@ -120,7 +120,7 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, recoder.beginRecording(SkRect::MakeWH(size.width(), size.height())); { - auto frame = paint_context_.AcquireFrame( + auto frame = compositor_context_.AcquireFrame( nullptr, *recoder.getRecordingCanvas(), false); layer_tree->Raster(frame); } @@ -137,7 +137,7 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, void RasterizerDirect::OnOutputSurfaceDestroyed() { if (context_) { CHECK(context_->MakeCurrent(surface_.get())); - paint_context_.OnGrContextDestroyed(); + compositor_context_.OnGrContextDestroyed(); ganesh_canvas_.SetGrGLInterface(nullptr); context_ = nullptr; } diff --git a/sky/shell/gpu/direct/rasterizer_direct.h b/sky/shell/gpu/direct/rasterizer_direct.h index fc6171912..07e766b7c 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.h +++ b/sky/shell/gpu/direct/rasterizer_direct.h @@ -6,7 +6,7 @@ #define SKY_SHELL_GPU_DIRECT_RASTERIZER_H_ #include "base/memory/weak_ptr.h" -#include "flow/paint_context.h" +#include "flow/compositor_context.h" #include "skia/ext/refptr.h" #include "sky/shell/gpu/direct/ganesh_canvas.h" #include "sky/shell/rasterizer.h" @@ -52,7 +52,7 @@ class RasterizerDirect : public Rasterizer { skia::RefPtr gr_gl_interface_; GaneshCanvas ganesh_canvas_; - flow::PaintContext paint_context_; + flow::CompositorContext compositor_context_; mojo::Binding binding_; diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.cc b/sky/shell/gpu/mojo/rasterizer_mojo.cc index f1131c910..7da78020e 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.cc +++ b/sky/shell/gpu/mojo/rasterizer_mojo.cc @@ -82,7 +82,7 @@ void RasterizerMojo::Draw(uint64_t layer_tree_ptr, return; } - paint_context_.engine_time().SetLapTime(layer_tree->construction_time()); + compositor_context_.engine_time().SetLapTime(layer_tree->construction_time()); std::unique_ptr texture = gl_state_->gl_texture_recycler.GetTexture(size); @@ -93,8 +93,8 @@ void RasterizerMojo::Draw(uint64_t layer_tree_ptr, mojo::skia::GaneshTextureSurface texture_surface(scope, std::move(texture)); SkCanvas* canvas = texture_surface.canvas(); - flow::PaintContext::ScopedFrame frame = - paint_context_.AcquireFrame(scope.gr_context().get(), *canvas); + flow::CompositorContext::ScopedFrame frame = + compositor_context_.AcquireFrame(scope.gr_context().get(), *canvas); canvas->clear(SK_ColorBLACK); layer_tree->Raster(frame); diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.h b/sky/shell/gpu/mojo/rasterizer_mojo.h index d980f72a2..a27e710fe 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.h +++ b/sky/shell/gpu/mojo/rasterizer_mojo.h @@ -6,7 +6,7 @@ #define SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_H_ #include "base/memory/weak_ptr.h" -#include "flow/paint_context.h" +#include "flow/compositor_context.h" #include "mojo/gpu/gl_context.h" #include "mojo/public/interfaces/application/application_connector.mojom.h" #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" @@ -49,7 +49,7 @@ class RasterizerMojo : public Rasterizer { mojo::Binding binding_; mojo::gfx::composition::ScenePtr scene_; std::unique_ptr gl_state_; - flow::PaintContext paint_context_; + flow::CompositorContext compositor_context_; std::unique_ptr last_layer_tree_; base::WeakPtrFactory weak_factory_; -- GitLab