提交 2e5d3c49 编写于 作者: A Adam Barth

Preroll rasterization

Prerolling the rasterization tasks reduces the number of render target
switches because we don't interrupt the main render target.
上级 f4fc4e24
......@@ -18,6 +18,17 @@ void ContainerLayer::Add(std::unique_ptr<Layer> layer) {
layers_.push_back(std::move(layer));
}
void ContainerLayer::Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) {
PrerollChildren(frame, matrix);
}
void ContainerLayer::PrerollChildren(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) {
for (auto& layer : layers_)
layer->Preroll(frame, matrix);
}
void ContainerLayer::PaintChildren(PaintContext::ScopedFrame& frame) const {
for (auto& layer : layers_)
layer->Paint(frame);
......
......@@ -18,6 +18,10 @@ class ContainerLayer : public Layer {
void Add(std::unique_ptr<Layer> layer);
void Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) override;
void PrerollChildren(PaintContext::ScopedFrame& frame, const SkMatrix& matrix);
void PaintChildren(PaintContext::ScopedFrame& frame) const;
const std::vector<std::unique_ptr<Layer>>& layers() const { return layers_; }
......
......@@ -18,5 +18,8 @@ Layer::Layer()
Layer::~Layer() {
}
void Layer::Preroll(PaintContext::ScopedFrame& frame, const SkMatrix& matrix) {
}
} // namespace compositor
} // namespace sky
......@@ -31,6 +31,8 @@ class Layer {
Layer();
virtual ~Layer();
virtual void Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix);
virtual void Paint(PaintContext::ScopedFrame& frame) = 0;
ContainerLayer* parent() const { return parent_; }
......
......@@ -15,5 +15,10 @@ LayerTree::LayerTree() : rasterizer_tracing_threashold_(0) {
LayerTree::~LayerTree() {
}
void LayerTree::Raster(PaintContext::ScopedFrame& frame) {
root_layer_->Preroll(frame, SkMatrix());
root_layer_->Paint(frame);
}
} // namespace compositor
} // namespace sky
......@@ -21,6 +21,8 @@ class LayerTree {
LayerTree();
~LayerTree();
void Raster(PaintContext::ScopedFrame& frame);
Layer* root_layer() const { return root_layer_.get(); }
void set_root_layer(std::unique_ptr<Layer> root_layer) {
......
......@@ -28,8 +28,9 @@ void PaintContext::endFrame(ScopedFrame& frame, bool enableInstrumentation) {
}
}
PaintContext::ScopedFrame PaintContext::AcquireFrame(SkCanvas& canvas) {
return ScopedFrame(*this, canvas);
PaintContext::ScopedFrame PaintContext::AcquireFrame(GrContext* gr_context,
SkCanvas& canvas) {
return ScopedFrame(*this, gr_context, canvas);
}
PaintContext::ScopedFrame PaintContext::AcquireFrame(
......@@ -38,8 +39,11 @@ PaintContext::ScopedFrame PaintContext::AcquireFrame(
return ScopedFrame(*this, trace_file_name, frame_size);
}
PaintContext::ScopedFrame::ScopedFrame(PaintContext& context, SkCanvas& canvas)
: context_(context), canvas_(&canvas), instrumentation_enabled_(true) {
PaintContext::ScopedFrame::ScopedFrame(PaintContext& context,
GrContext* gr_context,
SkCanvas& canvas)
: context_(context), gr_context_(gr_context), canvas_(&canvas),
instrumentation_enabled_(true) {
context_.beginFrame(*this, instrumentation_enabled_);
}
......
......@@ -26,6 +26,7 @@ class PaintContext {
SkCanvas& canvas() { return *canvas_; }
PaintContext& context() const { return context_; }
GrContext* gr_context() const { return gr_context_; }
ScopedFrame(ScopedFrame&& frame);
......@@ -33,12 +34,13 @@ class PaintContext {
private:
PaintContext& context_;
GrContext* gr_context_;
SkCanvas* canvas_;
std::string trace_file_name_;
std::unique_ptr<SkPictureRecorder> trace_recorder_;
const bool instrumentation_enabled_;
ScopedFrame(PaintContext& context, SkCanvas& canvas);
ScopedFrame(PaintContext& context, GrContext* gr_context, SkCanvas& canvas);
ScopedFrame(PaintContext& context,
const std::string& trace_file_name,
......@@ -52,7 +54,7 @@ class PaintContext {
PaintContext();
~PaintContext();
ScopedFrame AcquireFrame(SkCanvas& canvas);
ScopedFrame AcquireFrame(GrContext* gr_context, SkCanvas& canvas);
ScopedFrame AcquireFrame(const std::string& trace_file_name,
gfx::Size frame_size);
......
......@@ -22,24 +22,27 @@ PictureLayer::PictureLayer() {
PictureLayer::~PictureLayer() {
}
void PictureLayer::Paint(PaintContext::ScopedFrame& frame) {
DCHECK(picture_);
SkCanvas& canvas = frame.canvas();
void PictureLayer::Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) {
#if ENABLE_RASTER_CACHE
const SkMatrix& ctm = canvas.getTotalMatrix();
SkISize size = SkISize::Make(paint_bounds().width() * ctm.getScaleX(),
paint_bounds().height() * ctm.getScaleY());
SkISize size = SkISize::Make(paint_bounds().width() * matrix.getScaleX(),
paint_bounds().height() * matrix.getScaleY());
RasterCache& cache = frame.context().raster_cache();
RefPtr<SkImage> image = cache.GetImage(picture_.get(), size);
#else
RefPtr<SkImage> image;
image_ = cache.GetImage(picture_.get(), size);
if (image_) {
image_->preroll(frame.gr_context(), SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode, kMedium_SkFilterQuality);
}
#endif
}
if (image) {
canvas.drawImage(image.get(), offset_.x(), offset_.y());
void PictureLayer::Paint(PaintContext::ScopedFrame& frame) {
DCHECK(picture_);
SkCanvas& canvas = frame.canvas();
if (image_) {
canvas.drawImage(image_.get(), offset_.x(), offset_.y());
if (kDebugCheckerboardRasterizedLayers) {
SkRect rect = paint_bounds().makeOffset(offset_.x(), offset_.y());
DrawCheckerboard(&canvas, rect);
......
......@@ -21,12 +21,17 @@ class PictureLayer : public Layer {
SkPicture* picture() const { return picture_.get(); }
void Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) override;
void Paint(PaintContext::ScopedFrame& frame) override;
private:
SkPoint offset_;
RefPtr<SkPicture> picture_;
// If we rasterized the picture separately, image_ holds the pixels.
RefPtr<SkImage> image_;
DISALLOW_COPY_AND_ASSIGN(PictureLayer);
};
......
......@@ -13,6 +13,13 @@ TransformLayer::TransformLayer() {
TransformLayer::~TransformLayer() {
}
void TransformLayer::Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) {
SkMatrix childMatrix;
childMatrix.setConcat(matrix, transform_);
PrerollChildren(frame, childMatrix);
}
void TransformLayer::Paint(PaintContext::ScopedFrame& frame) {
SkCanvas& canvas = frame.canvas();
canvas.save();
......
......@@ -17,6 +17,8 @@ class TransformLayer : public ContainerLayer {
void set_transform(const SkMatrix& transform) { transform_ = transform; }
void Preroll(PaintContext::ScopedFrame& frame,
const SkMatrix& matrix) override;
void Paint(PaintContext::ScopedFrame& frame) override;
private:
......
......@@ -89,9 +89,9 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr,
SkCanvas* canvas = ganesh_canvas_.GetCanvas(
surface_->GetBackingFrameBufferObject(), layer_tree->frame_size());
sky::compositor::PaintContext::ScopedFrame frame =
paint_context_.AcquireFrame(*canvas);
paint_context_.AcquireFrame(ganesh_canvas_.gr_context(), *canvas);
canvas->clear(SK_ColorBLACK);
layer_tree->root_layer()->Paint(frame);
layer_tree->Raster(frame);
canvas->flush();
surface_->SwapBuffers();
}
......
......@@ -26,6 +26,8 @@ class GaneshCanvas {
bool IsValid();
GrContext* gr_context() { return gr_context_.get(); }
private:
skia::RefPtr<GrContext> gr_context_;
skia::RefPtr<SkSurface> sk_surface_;
......
......@@ -63,9 +63,9 @@ void RasterizerMojo::Draw(uint64_t layer_tree_ptr,
layer_tree->frame_size().height());
SkCanvas* canvas = ganesh_canvas_.GetCanvas(0, layer_tree->frame_size());
sky::compositor::PaintContext::ScopedFrame frame =
paint_context_.AcquireFrame(*canvas);
paint_context_.AcquireFrame(ganesh_canvas_.gr_context(), *canvas);
canvas->clear(SK_ColorBLACK);
layer_tree->root_layer()->Paint(frame);
layer_tree->Raster(frame);
canvas->flush();
MGLSwapBuffers();
callback.Run();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册