picture_layer.cc 1.7 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4
// 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/fml/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 20 21 22 23
    SkMatrix ctm = matrix;
    ctm.postTranslate(offset_.x(), offset_.y());
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
    ctm = RasterCache::GetIntegralTransCTM(ctm);
#endif
24 25
    cache->Prepare(context->gr_context, sk_picture, ctm,
                   context->dst_color_space, is_complex_, will_change_);
26 27
  }

28
  SkRect bounds = sk_picture->cullRect().makeOffset(offset_.x(), offset_.y());
29
  set_paint_bounds(bounds);
A
Adam Barth 已提交
30
}
31

32
void PictureLayer::Paint(PaintContext& context) const {
33
  TRACE_EVENT0("flutter", "PictureLayer::Paint");
34 35
  FML_DCHECK(picture_.get());
  FML_DCHECK(needs_painting());
36

37 38
  SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);
  context.leaf_nodes_canvas->translate(offset_.x(), offset_.y());
39
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
40 41
  context.leaf_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM(
      context.leaf_nodes_canvas->getTotalMatrix()));
42
#endif
43

44
  if (context.raster_cache) {
45
    const SkMatrix& ctm = context.leaf_nodes_canvas->getTotalMatrix();
46 47
    RasterCacheResult result = context.raster_cache->Get(*picture(), ctm);
    if (result.is_valid()) {
48
      result.draw(*context.leaf_nodes_canvas);
49 50
      return;
    }
51
  }
52
  context.leaf_nodes_canvas->drawPicture(picture());
53 54
}

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