mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL teaches the Sky compositor to record an SkPicture instead of just drawing in immediate mode. Using an SkPicture will let us experiment with various optimizations in Skia that preprocess the SkPicture before translating the Skia commands to GL commands. This CL also refactors the "display delegate" system now that we can hand off an SkPicture to a rasterization backend. The new design requires fewer backpointers and removes the static display delegate factory. R=eseidel@google.com Review URL: https://codereview.chromium.org/854303002
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
// Copyright 2014 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 "sky/compositor/layer.h"
|
|
|
|
#include "base/debug/trace_event.h"
|
|
#include "sky/compositor/layer_host.h"
|
|
#include "sky/compositor/rasterizer.h"
|
|
#include "third_party/skia/include/core/SkCanvas.h"
|
|
#include "third_party/skia/include/core/SkPictureRecorder.h"
|
|
|
|
namespace sky {
|
|
|
|
Layer::Layer(LayerClient* client) : client_(client) {
|
|
}
|
|
|
|
Layer::~Layer() {
|
|
}
|
|
|
|
void Layer::SetSize(const gfx::Size& size) {
|
|
size_ = size;
|
|
}
|
|
|
|
void Layer::Display() {
|
|
TRACE_EVENT0("sky", "Layer::Display");
|
|
DCHECK(rasterizer_);
|
|
auto picture = RecordPicture();
|
|
texture_ = rasterizer_->Rasterize(picture.get());
|
|
}
|
|
|
|
skia::RefPtr<SkPicture> Layer::RecordPicture() {
|
|
TRACE_EVENT0("sky", "Layer::RecordPicture");
|
|
|
|
SkRTreeFactory factory;
|
|
SkPictureRecorder recorder;
|
|
|
|
auto canvas = skia::SharePtr(recorder.beginRecording(
|
|
size_.width(), size_.height(), &factory,
|
|
SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
|
|
|
|
client_->PaintContents(canvas.get(), gfx::Rect(size_));
|
|
return skia::AdoptRef(recorder.endRecordingAsPicture());
|
|
}
|
|
|
|
scoped_ptr<mojo::GLTexture> Layer::GetTexture() {
|
|
return texture_.Pass();
|
|
}
|
|
|
|
} // namespace sky
|