| // Copyright 2013 The Flutter Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef FLUTTER_FLOW_LAYER_SNAPSHOT_STORE_H_ |
| #define FLUTTER_FLOW_LAYER_SNAPSHOT_STORE_H_ |
| |
| #include <vector> |
| |
| #include "flutter/fml/logging.h" |
| #include "flutter/fml/time/time_delta.h" |
| |
| #include "third_party/skia/include/core/SkImageEncoder.h" |
| #include "third_party/skia/include/core/SkPictureRecorder.h" |
| #include "third_party/skia/include/core/SkSerialProcs.h" |
| #include "third_party/skia/include/core/SkSurface.h" |
| #include "third_party/skia/include/core/SkSurfaceCharacterization.h" |
| #include "third_party/skia/include/utils/SkBase64.h" |
| |
| namespace flutter { |
| |
| /// Container for snapshot data pertaining to a given layer. A layer is |
| /// identified by it's unique id. |
| class LayerSnapshotData { |
| public: |
| LayerSnapshotData(int64_t layer_unique_id, |
| fml::TimeDelta duration, |
| sk_sp<SkData> snapshot); |
| |
| ~LayerSnapshotData() = default; |
| |
| int64_t GetLayerUniqueId() const { return layer_unique_id_; } |
| |
| fml::TimeDelta GetDuration() const { return duration_; } |
| |
| sk_sp<SkData> GetSnapshot() const { return snapshot_; } |
| |
| private: |
| const int64_t layer_unique_id_; |
| const fml::TimeDelta duration_; |
| const sk_sp<SkData> snapshot_; |
| }; |
| |
| /// Collects snapshots of layers during frame rasterization. |
| class LayerSnapshotStore { |
| public: |
| typedef std::vector<LayerSnapshotData> Snapshots; |
| |
| LayerSnapshotStore() = default; |
| |
| ~LayerSnapshotStore() = default; |
| |
| /// Clears all the stored snapshots. |
| void Clear(); |
| |
| /// Adds snapshots for a given layer. `duration` marks the time taken to |
| /// rasterize this one layer. |
| void Add(int64_t layer_unique_id, |
| fml::TimeDelta duration, |
| sk_sp<SkData> base64_png_snapshot); |
| |
| // Returns the number of snapshots collected. |
| size_t Size() const { return layer_snapshots_.size(); } |
| |
| // make this class iterable |
| Snapshots::iterator begin() { return layer_snapshots_.begin(); } |
| Snapshots::iterator end() { return layer_snapshots_.end(); } |
| |
| private: |
| Snapshots layer_snapshots_; |
| |
| FML_DISALLOW_COPY_AND_ASSIGN(LayerSnapshotStore); |
| }; |
| |
| } // namespace flutter |
| |
| #endif // FLUTTER_FLOW_LAYER_SNAPSHOT_STORE_H_ |