| 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 | #ifndef FLUTTER_FLOW_PAINT_REGION_H_ |
| 6 | #define FLUTTER_FLOW_PAINT_REGION_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | #include "flutter/fml/logging.h" |
| 10 | #include "third_party/skia/include/core/SkRect.h" |
| 11 | |
| 12 | namespace flutter { |
| 13 | |
| 14 | // Corresponds to area on the screen where the layer subtree has painted to. |
| 15 | // |
| 16 | // The area is used when adding damage of removed or dirty layer to overall |
| 17 | // damage. |
| 18 | // |
| 19 | // Because there is a PaintRegion for each layer, it must be able to represent |
| 20 | // the area with minimal overhead. This is accomplished by having one |
| 21 | // vector<SkRect> shared between all paint regions, and each paint region |
| 22 | // keeping begin and end index of rects relevant to particular subtree. |
| 23 | // |
| 24 | // All rects are in screen coordinates. |
| 25 | class PaintRegion { |
| 26 | public: |
| 27 | PaintRegion() = default; |
| 28 | PaintRegion(std::shared_ptr<std::vector<SkRect>> rects, |
| 29 | size_t from, |
| 30 | size_t to, |
| 31 | bool has_readback, |
| 32 | bool has_texture) |
| 33 | : rects_(rects), |
| 34 | from_(from), |
| 35 | to_(to), |
| 36 | has_readback_(has_readback), |
| 37 | has_texture_(has_texture) {} |
| 38 | |
| 39 | std::vector<SkRect>::const_iterator begin() const { |
| 40 | FML_DCHECK(is_valid()); |
| 41 | return rects_->begin() + from_; |
| 42 | } |
| 43 | |
| 44 | std::vector<SkRect>::const_iterator end() const { |
| 45 | FML_DCHECK(is_valid()); |
| 46 | return rects_->begin() + to_; |
| 47 | } |
| 48 | |
| 49 | // Compute bounds for this region |
| 50 | SkRect ComputeBounds() const; |
| 51 | |
| 52 | bool is_valid() const { return rects_ != nullptr; } |
| 53 | |
| 54 | // Returns true if there is a layer in subtree represented by this region |
| 55 | // that performs readback |
| 56 | bool has_readback() const { return has_readback_; } |
| 57 | |
| 58 | // Returns whether there is a TextureLayer in subtree represented by this |
| 59 | // region. |
| 60 | bool has_texture() const { return has_texture_; } |
| 61 | |
| 62 | private: |
| 63 | std::shared_ptr<std::vector<SkRect>> rects_; |
| 64 | size_t from_ = 0; |
| 65 | size_t to_ = 0; |
| 66 | bool has_readback_ = false; |
| 67 | bool has_texture_ = false; |
| 68 | }; |
| 69 | |
| 70 | } // namespace flutter |
| 71 | |
| 72 | #endif // FLUTTER_FLOW_PAINT_REGION_H_ |
| 73 | |