1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_LAYERS_LAYER_LIST_ITERATOR_H_
#define CC_LAYERS_LAYER_LIST_ITERATOR_H_
#include <stdlib.h>
#include <vector>
#include "base/memory/stack_allocated.h"
#include "cc/cc_export.h"
namespace cc {
class Layer;
// This visits a tree of layers in drawing order.
class CC_EXPORT LayerListIterator {
STACK_ALLOCATED();
public:
explicit LayerListIterator(Layer* root_layer);
LayerListIterator(const LayerListIterator& other);
~LayerListIterator();
bool operator==(const LayerListIterator& other) const {
return current_layer_ == other.current_layer_;
}
bool operator!=(const LayerListIterator& other) const {
return !(*this == other);
}
// We will only support prefix increment.
LayerListIterator& operator++();
Layer* operator->() const { return current_layer_; }
Layer* operator*() const { return current_layer_; }
private:
// The implementation of this iterator is currently tied tightly to the layer
// tree, but it should be straightforward to reimplement in terms of a list
// when it's ready.
Layer* current_layer_ = nullptr;
std::vector<size_t> list_indices_;
};
class CC_EXPORT LayerListConstIterator {
STACK_ALLOCATED();
public:
explicit LayerListConstIterator(const Layer* root_layer);
LayerListConstIterator(const LayerListConstIterator& other);
~LayerListConstIterator();
bool operator==(const LayerListConstIterator& other) const {
return current_layer_ == other.current_layer_;
}
bool operator!=(const LayerListConstIterator& other) const {
return !(*this == other);
}
// We will only support prefix increment.
LayerListConstIterator& operator++();
const Layer* operator->() const { return current_layer_; }
const Layer* operator*() const { return current_layer_; }
private:
const Layer* current_layer_;
std::vector<size_t> list_indices_;
};
class CC_EXPORT LayerListReverseIterator {
STACK_ALLOCATED();
public:
explicit LayerListReverseIterator(Layer* root_layer);
LayerListReverseIterator(const LayerListReverseIterator& other);
~LayerListReverseIterator();
bool operator==(const LayerListReverseIterator& other) const {
return current_layer_ == other.current_layer_;
}
bool operator!=(const LayerListReverseIterator& other) const {
return !(*this == other);
}
// We will only support prefix increment.
LayerListReverseIterator& operator++();
Layer* operator->() const { return current_layer_; }
Layer* operator*() const { return current_layer_; }
private:
void DescendToRightmostInSubtree();
Layer* current_layer_ = nullptr;
std::vector<size_t> list_indices_;
};
class CC_EXPORT LayerListReverseConstIterator {
STACK_ALLOCATED();
public:
explicit LayerListReverseConstIterator(const Layer* root_layer);
LayerListReverseConstIterator(const LayerListReverseConstIterator& other);
~LayerListReverseConstIterator();
bool operator==(const LayerListReverseConstIterator& other) const {
return current_layer_ == other.current_layer_;
}
bool operator!=(const LayerListReverseConstIterator& other) const {
return !(*this == other);
}
// We will only support prefix increment.
LayerListReverseConstIterator& operator++();
const Layer* operator->() const { return current_layer_; }
const Layer* operator*() const { return current_layer_; }
private:
void DescendToRightmostInSubtree();
const Layer* current_layer_ = nullptr;
std::vector<size_t> list_indices_;
};
} // namespace cc
#endif // CC_LAYERS_LAYER_LIST_ITERATOR_H_
|