Flutter Engine
picture_layer.cc
Go to the documentation of this file.
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,
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
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());
49 
50  SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);
51  context.leaf_nodes_canvas->translate(offset_.x(), offset_.y());
52 #ifndef SUPPORT_FRACTIONAL_TRANSLATION
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
GrDirectContext * gr_context
Definition: layer.h:45
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_DCHECK(condition)
Definition: logging.h:86
void Preroll(PrerollContext *frame, const SkMatrix &matrix) override
#define TRACE_EVENT_INSTANT0(category_group, name)
Definition: trace_event.h:104
sk_sp< SkiaObjectType > get() const
Definition: ref_ptr.h:252
void Paint(PaintContext &context) const override
const RasterCache * raster_cache
Definition: layer.h:122
bool needs_painting() const
Definition: layer.h:174
SkColorSpace * dst_color_space
Definition: layer.h:48
bool Draw(const SkPicture &picture, SkCanvas &canvas) const
SkCanvas * leaf_nodes_canvas
Definition: layer.h:116
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:170
RasterCache * raster_cache
Definition: layer.h:44
PictureLayer(const SkPoint &offset, SkiaGPUObject< SkPicture > picture, bool is_complex, bool will_change)
static SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
Definition: raster_cache.h:115
SkPicture * picture() const
Definition: picture_layer.h:23