1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #include "flutter/flow/layers/picture_layer.h" |
6 | |
7 | #include "flutter/fml/logging.h" |
8 | |
9 | namespace flutter { |
10 | |
11 | PictureLayer::PictureLayer(const SkPoint& offset, |
12 | SkiaGPUObject<SkPicture> picture, |
13 | bool is_complex, |
14 | bool will_change) |
15 | : offset_(offset), |
16 | picture_(std::move(picture)), |
17 | is_complex_(is_complex), |
18 | will_change_(will_change) {} |
19 | |
20 | void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { |
21 | TRACE_EVENT0("flutter" , "PictureLayer::Preroll" ); |
22 | |
23 | #if defined(LEGACY_FUCHSIA_EMBEDDER) |
24 | CheckForChildLayerBelow(context); |
25 | #endif |
26 | |
27 | SkPicture* sk_picture = picture(); |
28 | |
29 | if (auto* cache = context->raster_cache) { |
30 | TRACE_EVENT0("flutter" , "PictureLayer::RasterCache (Preroll)" ); |
31 | |
32 | SkMatrix ctm = matrix; |
33 | ctm.postTranslate(offset_.x(), offset_.y()); |
34 | #ifndef SUPPORT_FRACTIONAL_TRANSLATION |
35 | ctm = RasterCache::GetIntegralTransCTM(ctm); |
36 | #endif |
37 | cache->Prepare(context->gr_context, sk_picture, ctm, |
38 | context->dst_color_space, is_complex_, will_change_); |
39 | } |
40 | |
41 | SkRect bounds = sk_picture->cullRect().makeOffset(offset_.x(), offset_.y()); |
42 | set_paint_bounds(bounds); |
43 | } |
44 | |
45 | void PictureLayer::Paint(PaintContext& context) const { |
46 | TRACE_EVENT0("flutter" , "PictureLayer::Paint" ); |
47 | FML_DCHECK(picture_.get()); |
48 | FML_DCHECK(needs_painting()); |
49 | |
50 | SkAutoCanvasRestore save(context.leaf_nodes_canvas, true); |
51 | context.leaf_nodes_canvas->translate(offset_.x(), offset_.y()); |
52 | #ifndef SUPPORT_FRACTIONAL_TRANSLATION |
53 | context.leaf_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM( |
54 | context.leaf_nodes_canvas->getTotalMatrix())); |
55 | #endif |
56 | |
57 | if (context.raster_cache && |
58 | context.raster_cache->Draw(*picture(), *context.leaf_nodes_canvas)) { |
59 | TRACE_EVENT_INSTANT0("flutter" , "raster cache hit" ); |
60 | return; |
61 | } |
62 | picture()->playback(context.leaf_nodes_canvas); |
63 | } |
64 | |
65 | } // namespace flutter |
66 | |