picture_layer.cc 1.6 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 "lib/fxl/logging.h"
8

A
Adam Barth 已提交
9
namespace flow {
10

11
PictureLayer::PictureLayer() = default;
12

13
PictureLayer::~PictureLayer() = default;
14

15
void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
16 17
  SkPicture* sk_picture = picture();

18
  if (auto cache = context->raster_cache) {
19
    raster_cache_result_ = cache->GetPrerolledImage(
20
        context->gr_context, sk_picture, matrix, context->dst_color_space,
21
        is_complex_, will_change_);
22 23
  }

24
  SkRect bounds = sk_picture->cullRect().makeOffset(offset_.x(), offset_.y());
25
  set_paint_bounds(bounds);
A
Adam Barth 已提交
26
}
27

28
void PictureLayer::Paint(PaintContext& context) const {
29
  TRACE_EVENT0("flutter", "PictureLayer::Paint");
30
  FXL_DCHECK(picture_.get());
31
  FXL_DCHECK(needs_painting());
32 33 34 35

  SkAutoCanvasRestore save(&context.canvas, true);
  context.canvas.translate(offset_.x(), offset_.y());

36
  if (raster_cache_result_.is_valid()) {
37 38
    SkPaint paint;
    paint.setFilterQuality(kLow_SkFilterQuality);
39 40 41 42
    context.canvas.drawImageRect(
        raster_cache_result_.image(),             // image
        raster_cache_result_.source_rect(),       // source
        raster_cache_result_.destination_rect(),  // destination
43
        &paint,                                   // paint
44
        SkCanvas::kStrict_SrcRectConstraint       // source constraint
45
    );
46
  } else {
47
    context.canvas.drawPicture(picture());
48
  }
49 50
}

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