picture_layer.cc 1.5 KB
Newer Older
1 2 3 4
// 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.

A
Adam Barth 已提交
5
#include "flow/layers/picture_layer.h"
6

7
#include "base/logging.h"
A
Adam Barth 已提交
8 9
#include "flow/checkerboard.h"
#include "flow/raster_cache.h"
10

A
Adam Barth 已提交
11
namespace flow {
12

13 14 15
// TODO(abarth): Make this configurable by developers.
const bool kDebugCheckerboardRasterizedLayers = false;

16
PictureLayer::PictureLayer() {}
17

18
PictureLayer::~PictureLayer() {}
19

20
void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
21
  image_ = context->raster_cache.GetPrerolledImage(
22
      context->gr_context, picture_.get(), matrix, is_complex_, will_change_);
23 24
  context->child_paint_bounds =
      picture_->cullRect().makeOffset(offset_.x(), offset_.y());
A
Adam Barth 已提交
25
}
26

27
void PictureLayer::Paint(PaintContext& context) {
A
Adam Barth 已提交
28 29 30
  DCHECK(picture_);

  if (image_) {
31
    TRACE_EVENT1("flutter", "PictureLayer::Paint", "image", "prerolled");
A
Adam Barth 已提交
32
    SkRect rect = picture_->cullRect().makeOffset(offset_.x(), offset_.y());
33 34
    context.canvas.drawImageRect(image_.get(), rect, nullptr,
                                 SkCanvas::kFast_SrcRectConstraint);
35
    if (kDebugCheckerboardRasterizedLayers)
36
      DrawCheckerboard(&context.canvas, rect);
37
  } else {
38
    TRACE_EVENT1("flutter", "PictureLayer::Paint", "image", "normal");
39 40 41
    SkAutoCanvasRestore save(&context.canvas, true);
    context.canvas.translate(offset_.x(), offset_.y());
    context.canvas.drawPicture(picture_.get());
42
  }
43 44
}

A
Adam Barth 已提交
45
}  // namespace flow