picture_layer.cc 1.3 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.

5
#include "flutter/flow/layers/picture_layer.h"
6

7
#include "flutter/flow/raster_cache.h"
A
Adam Barth 已提交
8
#include "lib/ftl/logging.h"
9

A
Adam Barth 已提交
10
namespace flow {
11

12
PictureLayer::PictureLayer() {}
13

14
PictureLayer::~PictureLayer() {}
15

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

23
void PictureLayer::Paint(PaintContext& context) {
A
Adam Barth 已提交
24
  FTL_DCHECK(picture_);
A
Adam Barth 已提交
25 26

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

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