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.

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 19 20 21
}

PictureLayer::~PictureLayer() {
}

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

A
Adam Barth 已提交
29 30 31 32 33
void PictureLayer::Paint(PaintContext::ScopedFrame& frame) {
  DCHECK(picture_);

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

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