chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <layerproto/LayerProtoHeader.h> |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 18 | #include <renderengine/ExternalTexture.h> |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 19 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 20 | #include <Layer.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 21 | #include <gui/WindowInfo.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 22 | #include <math/vec4.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 23 | #include <ui/BlurRegion.h> |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 24 | #include <ui/GraphicBuffer.h> |
| 25 | #include <ui/Rect.h> |
| 26 | #include <ui/Region.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 27 | #include <ui/Transform.h> |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 28 | #include <cstdint> |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 29 | |
| 30 | #include "FrontEnd/DisplayInfo.h" |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 31 | #include "FrontEnd/LayerHierarchy.h" |
| 32 | #include "FrontEnd/LayerSnapshot.h" |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | namespace surfaceflinger { |
| 36 | class LayerProtoHelper { |
| 37 | public: |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 38 | static void writePositionToProto( |
| 39 | const float x, const float y, |
| 40 | std::function<perfetto::protos::PositionProto*()> getPositionProto); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 41 | static void writeSizeToProto(const uint32_t w, const uint32_t h, |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 42 | std::function<perfetto::protos::SizeProto*()> getSizeProto); |
| 43 | static void writeToProto(const Rect& rect, |
| 44 | std::function<perfetto::protos::RectProto*()> getRectProto); |
| 45 | static void writeToProto(const Rect& rect, perfetto::protos::RectProto* rectProto); |
| 46 | static void readFromProto(const perfetto::protos::RectProto& proto, Rect& outRect); |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame] | 47 | static void readFromProto(const perfetto::protos::RectProto& proto, FloatRect& outRect); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 48 | static void writeToProto(const FloatRect& rect, |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 49 | std::function<perfetto::protos::FloatRectProto*()> getFloatRectProto); |
| 50 | static void writeToProto(const Region& region, |
| 51 | std::function<perfetto::protos::RegionProto*()> getRegionProto); |
| 52 | static void writeToProto(const Region& region, perfetto::protos::RegionProto* regionProto); |
| 53 | static void readFromProto(const perfetto::protos::RegionProto& regionProto, Region& outRegion); |
| 54 | static void writeToProto(const half4 color, |
| 55 | std::function<perfetto::protos::ColorProto*()> getColorProto); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 56 | // This writeToProto for transform is incorrect, but due to backwards compatibility, we can't |
| 57 | // update Layers to use it. Use writeTransformToProto for any new transform proto data. |
| 58 | static void writeToProtoDeprecated(const ui::Transform& transform, |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 59 | perfetto::protos::TransformProto* transformProto); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 60 | static void writeTransformToProto(const ui::Transform& transform, |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 61 | perfetto::protos::TransformProto* transformProto); |
| 62 | static void writeToProto( |
| 63 | const renderengine::ExternalTexture& buffer, |
| 64 | std::function<perfetto::protos::ActiveBufferProto*()> getActiveBufferProto); |
| 65 | static void writeToProto( |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 66 | const gui::WindowInfo& inputInfo, |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 67 | std::function<perfetto::protos::InputWindowInfoProto*()> getInputWindowInfoProto); |
| 68 | static void writeToProto(const mat4 matrix, |
| 69 | perfetto::protos::ColorTransformProto* colorTransformProto); |
| 70 | static void readFromProto(const perfetto::protos::ColorTransformProto& colorTransformProto, |
| 71 | mat4& matrix); |
| 72 | static void writeToProto(const android::BlurRegion region, perfetto::protos::BlurRegion*); |
| 73 | static void readFromProto(const perfetto::protos::BlurRegion& proto, |
| 74 | android::BlurRegion& outRegion); |
| 75 | static void writeSnapshotToProto(perfetto::protos::LayerProto* outProto, |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 76 | const frontend::RequestedLayerState& requestedState, |
| 77 | const frontend::LayerSnapshot& snapshot, uint32_t traceFlags); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 78 | static google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 79 | writeDisplayInfoToProto(const frontend::DisplayInfos&); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 82 | class LayerProtoFromSnapshotGenerator { |
| 83 | public: |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 84 | LayerProtoFromSnapshotGenerator(const frontend::LayerSnapshotBuilder& snapshotBuilder, |
| 85 | const frontend::DisplayInfos& displayInfos, |
| 86 | const std::unordered_map<uint32_t, sp<Layer>>& legacyLayers, |
| 87 | uint32_t traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 88 | : mSnapshotBuilder(snapshotBuilder), |
| 89 | mLegacyLayers(legacyLayers), |
| 90 | mDisplayInfos(displayInfos), |
| 91 | mTraceFlags(traceFlags) {} |
Vishnu Nair | b46e37c | 2024-08-16 14:30:28 +0000 | [diff] [blame] | 92 | LayerProtoFromSnapshotGenerator& with(const frontend::LayerHierarchy& root); |
| 93 | // Creates a fake root and adds all offscreen layers from the passed in hierarchy to the fake |
| 94 | // root |
| 95 | LayerProtoFromSnapshotGenerator& withOffscreenLayers( |
| 96 | const frontend::LayerHierarchy& offscreenRoot); |
| 97 | perfetto::protos::LayersProto generate() { return mLayersProto; }; |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 98 | |
| 99 | private: |
| 100 | void writeHierarchyToProto(const frontend::LayerHierarchy& root, |
| 101 | frontend::LayerHierarchy::TraversalPath& path); |
| 102 | frontend::LayerSnapshot* getSnapshot(frontend::LayerHierarchy::TraversalPath& path, |
| 103 | const frontend::RequestedLayerState& layer); |
| 104 | |
| 105 | const frontend::LayerSnapshotBuilder& mSnapshotBuilder; |
| 106 | const std::unordered_map<uint32_t, sp<Layer>>& mLegacyLayers; |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 107 | const frontend::DisplayInfos& mDisplayInfos; |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 108 | uint32_t mTraceFlags; |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 109 | perfetto::protos::LayersProto mLayersProto; |
Vishnu Nair | 516228f | 2024-07-11 23:03:02 +0000 | [diff] [blame] | 110 | std::unordered_set<uint32_t> mVisitedLayers; |
| 111 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 112 | // winscope expects all the layers, so provide a snapshot even if it not currently drawing |
| 113 | std::unordered_map<frontend::LayerHierarchy::TraversalPath, frontend::LayerSnapshot, |
| 114 | frontend::LayerHierarchy::TraversalPathHash> |
| 115 | mDefaultSnapshots; |
| 116 | std::unordered_map<uint32_t /* child unique seq*/, uint32_t /* relative parent unique seq*/> |
| 117 | mChildToRelativeParent; |
| 118 | std::unordered_map<uint32_t /* child unique seq*/, uint32_t /* parent unique seq*/> |
| 119 | mChildToParent; |
| 120 | }; |
| 121 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 122 | } // namespace surfaceflinger |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 123 | } // namespace android |