Flutter Engine
The Flutter Engine
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/layer.h"
6
7#include "flutter/flow/paint_utils.h"
8
9namespace flutter {
10
12 : paint_bounds_(SkRect::MakeEmpty()),
13 unique_id_(NextUniqueID()),
14 original_layer_id_(unique_id_) {}
15
16Layer::~Layer() = default;
17
18uint64_t Layer::NextUniqueID() {
19 static std::atomic<uint64_t> next_id(1);
20 uint64_t id;
21 do {
22 id = next_id.fetch_add(1);
23 } while (id == 0); // 0 is reserved for an invalid id.
24 return id;
25}
26
27Layer::AutoPrerollSaveLayerState::AutoPrerollSaveLayerState(
28 PrerollContext* preroll_context,
29 bool save_layer_is_active,
30 bool layer_itself_performs_readback)
31 : preroll_context_(preroll_context),
32 save_layer_is_active_(save_layer_is_active),
33 layer_itself_performs_readback_(layer_itself_performs_readback) {
34 if (save_layer_is_active_) {
35 prev_surface_needs_readback_ = preroll_context_->surface_needs_readback;
36 preroll_context_->surface_needs_readback = false;
37 }
38}
39
41 PrerollContext* preroll_context,
42 bool save_layer_is_active,
43 bool layer_itself_performs_readback) {
44 return Layer::AutoPrerollSaveLayerState(preroll_context, save_layer_is_active,
45 layer_itself_performs_readback);
46}
47
49 if (save_layer_is_active_) {
50 preroll_context_->surface_needs_readback =
51 (prev_surface_needs_readback_ || layer_itself_performs_readback_);
52 }
53}
54
55} // namespace flutter
static uint32_t next_id()
Definition: SkTextBlob.cpp:146
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:40
virtual ~Layer()
const uintptr_t id