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 | |
9 | namespace flutter { |
10 | |
11 | Layer::Layer() |
12 | : paint_bounds_(SkRect::MakeEmpty()), |
13 | unique_id_(NextUniqueID()), |
14 | original_layer_id_(unique_id_), |
15 | subtree_has_platform_view_(false) {} |
16 | |
17 | Layer::~Layer() = default; |
18 | |
19 | uint64_t Layer::NextUniqueID() { |
20 | static std::atomic<uint64_t> next_id(1); |
21 | uint64_t id; |
22 | do { |
23 | id = next_id.fetch_add(op: 1); |
24 | } while (id == 0); // 0 is reserved for an invalid id. |
25 | return id; |
26 | } |
27 | |
28 | Layer::AutoPrerollSaveLayerState::AutoPrerollSaveLayerState( |
29 | PrerollContext* preroll_context, |
30 | bool save_layer_is_active, |
31 | bool layer_itself_performs_readback) |
32 | : preroll_context_(preroll_context), |
33 | save_layer_is_active_(save_layer_is_active), |
34 | layer_itself_performs_readback_(layer_itself_performs_readback) { |
35 | if (save_layer_is_active_) { |
36 | prev_surface_needs_readback_ = preroll_context_->surface_needs_readback; |
37 | preroll_context_->surface_needs_readback = false; |
38 | } |
39 | } |
40 | |
41 | Layer::AutoPrerollSaveLayerState Layer::AutoPrerollSaveLayerState::Create( |
42 | PrerollContext* preroll_context, |
43 | bool save_layer_is_active, |
44 | bool layer_itself_performs_readback) { |
45 | return Layer::AutoPrerollSaveLayerState(preroll_context, save_layer_is_active, |
46 | layer_itself_performs_readback); |
47 | } |
48 | |
49 | Layer::AutoPrerollSaveLayerState::~AutoPrerollSaveLayerState() { |
50 | if (save_layer_is_active_) { |
51 | preroll_context_->surface_needs_readback = |
52 | (prev_surface_needs_readback_ || layer_itself_performs_readback_); |
53 | } |
54 | } |
55 | |
56 | } // namespace flutter |
57 | |