• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/layer.h"
6 
7 #include "flutter/flow/paint_utils.h"
8 #include "third_party/skia/include/core/SkColorFilter.h"
9 
10 namespace flutter {
11 
Layer()12 Layer::Layer()
13     : parent_(nullptr),
14       needs_system_composite_(false),
15       paint_bounds_(SkRect::MakeEmpty()),
16       unique_id_(NextUniqueID()) {}
17 
18 Layer::~Layer() = default;
19 
NextUniqueID()20 uint64_t Layer::NextUniqueID() {
21   static std::atomic<uint64_t> nextID(1);
22   uint64_t id;
23   do {
24     id = nextID.fetch_add(1);
25   } while (id == 0);  // 0 is reserved for an invalid id.
26   return id;
27 }
28 
Preroll(PrerollContext * context,const SkMatrix & matrix)29 void Layer::Preroll(PrerollContext* context, const SkMatrix& matrix) {}
30 
31 #if defined(OS_FUCHSIA)
UpdateScene(SceneUpdateContext & context)32 void Layer::UpdateScene(SceneUpdateContext& context) {}
33 #endif  // defined(OS_FUCHSIA)
34 
AutoSaveLayer(const PaintContext & paint_context,const SkRect & bounds,const SkPaint * paint)35 Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
36                                     const SkRect& bounds,
37                                     const SkPaint* paint)
38     : paint_context_(paint_context), bounds_(bounds) {
39   paint_context_.internal_nodes_canvas->saveLayer(bounds_, paint);
40 }
41 
AutoSaveLayer(const PaintContext & paint_context,const SkCanvas::SaveLayerRec & layer_rec)42 Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
43                                     const SkCanvas::SaveLayerRec& layer_rec)
44     : paint_context_(paint_context), bounds_(*layer_rec.fBounds) {
45   paint_context_.internal_nodes_canvas->saveLayer(layer_rec);
46 }
47 
Create(const PaintContext & paint_context,const SkRect & bounds,const SkPaint * paint)48 Layer::AutoSaveLayer Layer::AutoSaveLayer::Create(
49     const PaintContext& paint_context,
50     const SkRect& bounds,
51     const SkPaint* paint) {
52   return Layer::AutoSaveLayer(paint_context, bounds, paint);
53 }
54 
Create(const PaintContext & paint_context,const SkCanvas::SaveLayerRec & layer_rec)55 Layer::AutoSaveLayer Layer::AutoSaveLayer::Create(
56     const PaintContext& paint_context,
57     const SkCanvas::SaveLayerRec& layer_rec) {
58   return Layer::AutoSaveLayer(paint_context, layer_rec);
59 }
60 
~AutoSaveLayer()61 Layer::AutoSaveLayer::~AutoSaveLayer() {
62   if (paint_context_.checkerboard_offscreen_layers) {
63     DrawCheckerboard(paint_context_.internal_nodes_canvas, bounds_);
64   }
65   paint_context_.internal_nodes_canvas->restore();
66 }
67 
68 }  // namespace flutter
69