picture_layer.cc 1.7 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/common/threads.h"
A
Adam Barth 已提交
8
#include "lib/ftl/logging.h"
9

A
Adam Barth 已提交
10
namespace flow {
11

12
PictureLayer::PictureLayer() {}
13

14 15 16 17
PictureLayer::~PictureLayer() {
  // The picture may contain references to textures that are associated
  // with the IO thread's context.
  SkPicture* picture = picture_.release();
18 19 20
  if (picture) {
    blink::Threads::IO()->PostTask([picture]() { picture->unref(); });
  }
21
}
22

23
void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
24
  if (auto cache = context->raster_cache) {
25
    raster_cache_result_ = cache->GetPrerolledImage(
26 27
        context->gr_context, picture_.get(), matrix, context->dst_color_space,
        is_complex_, will_change_);
28 29
  }

30 31 32
  SkRect bounds = picture_->cullRect().makeOffset(offset_.x(), offset_.y());
  set_paint_bounds(bounds);
  context->child_paint_bounds = bounds;
A
Adam Barth 已提交
33
}
34

35
void PictureLayer::Paint(PaintContext& context) {
A
Adam Barth 已提交
36
  FTL_DCHECK(picture_);
A
Adam Barth 已提交
37

38
  TRACE_EVENT0("flutter", "PictureLayer::Paint");
39 40 41 42

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

43 44 45 46 47 48 49 50
  if (raster_cache_result_.is_valid()) {
    context.canvas.drawImageRect(
        raster_cache_result_.image(),             // image
        raster_cache_result_.source_rect(),       // source
        raster_cache_result_.destination_rect(),  // destination
        nullptr,                                  // paint
        SkCanvas::kStrict_SrcRectConstraint       // source constraint
        );
51
  } else {
52
    context.canvas.drawPicture(picture_.get());
53
  }
54 55
}

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