flutter_flutter/flow/picture_layer.cc
Adam Barth 0b629d419f Move //sky/compositor to //flow
Now that the compositor doesn't have any tricky deps, we can make it a
top-level project, which saves a bunch of typing.
2016-01-12 22:39:51 -08:00

46 lines
1.3 KiB
C++

// 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/picture_layer.h"
#include "base/logging.h"
#include "flow/checkerboard.h"
#include "flow/raster_cache.h"
namespace flow {
// TODO(abarth): Make this configurable by developers.
const bool kDebugCheckerboardRasterizedLayers = false;
PictureLayer::PictureLayer() {
}
PictureLayer::~PictureLayer() {
}
void PictureLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
image_ = context->frame.context().raster_cache().GetPrerolledImage(
context->frame.gr_context(), picture_.get(), matrix);
context->child_paint_bounds = picture_->cullRect().makeOffset(offset_.x(), offset_.y());
}
void PictureLayer::Paint(PaintContext::ScopedFrame& frame) {
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);
if (kDebugCheckerboardRasterizedLayers)
DrawCheckerboard(&canvas, rect);
} else {
SkAutoCanvasRestore save(&canvas, true);
canvas.translate(offset_.x(), offset_.y());
canvas.drawPicture(picture_.get());
}
}
} // namespace flow