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> |
| 29 | #include "FrontEnd/LayerHierarchy.h" |
| 30 | #include "FrontEnd/LayerSnapshot.h" |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | namespace surfaceflinger { |
| 34 | class LayerProtoHelper { |
| 35 | public: |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 36 | static void writePositionToProto(const float x, const float y, |
| 37 | std::function<PositionProto*()> getPositionProto); |
| 38 | static void writeSizeToProto(const uint32_t w, const uint32_t h, |
| 39 | std::function<SizeProto*()> getSizeProto); |
| 40 | static void writeToProto(const Rect& rect, std::function<RectProto*()> getRectProto); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 41 | static void writeToProto(const Rect& rect, RectProto* rectProto); |
| 42 | static void readFromProto(const RectProto& proto, Rect& outRect); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 43 | static void writeToProto(const FloatRect& rect, |
| 44 | std::function<FloatRectProto*()> getFloatRectProto); |
| 45 | static void writeToProto(const Region& region, std::function<RegionProto*()> getRegionProto); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 46 | static void writeToProto(const Region& region, RegionProto* regionProto); |
| 47 | static void readFromProto(const RegionProto& regionProto, Region& outRegion); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 48 | static void writeToProto(const half4 color, std::function<ColorProto*()> getColorProto); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 49 | // This writeToProto for transform is incorrect, but due to backwards compatibility, we can't |
| 50 | // update Layers to use it. Use writeTransformToProto for any new transform proto data. |
| 51 | static void writeToProtoDeprecated(const ui::Transform& transform, |
| 52 | TransformProto* transformProto); |
| 53 | static void writeTransformToProto(const ui::Transform& transform, |
| 54 | TransformProto* transformProto); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 55 | static void writeToProto(const renderengine::ExternalTexture& buffer, |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 56 | std::function<ActiveBufferProto*()> getActiveBufferProto); |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 57 | static void writeToProto(const gui::WindowInfo& inputInfo, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 58 | const wp<Layer>& touchableRegionBounds, |
| 59 | std::function<InputWindowInfoProto*()> getInputWindowInfoProto); |
chaviw | ddeae26 | 2020-01-06 10:31:23 -0800 | [diff] [blame] | 60 | static void writeToProto(const mat4 matrix, ColorTransformProto* colorTransformProto); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 61 | static void readFromProto(const ColorTransformProto& colorTransformProto, mat4& matrix); |
| 62 | static void writeToProto(const android::BlurRegion region, BlurRegion*); |
| 63 | static void readFromProto(const BlurRegion& proto, android::BlurRegion& outRegion); |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 64 | static void writeSnapshotToProto(LayerProto* outProto, |
| 65 | const frontend::RequestedLayerState& requestedState, |
| 66 | const frontend::LayerSnapshot& snapshot, uint32_t traceFlags); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 67 | static google::protobuf::RepeatedPtrField<DisplayProto> writeDisplayInfoToProto( |
| 68 | const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displayInfos); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 71 | class LayerProtoFromSnapshotGenerator { |
| 72 | public: |
| 73 | LayerProtoFromSnapshotGenerator( |
| 74 | const frontend::LayerSnapshotBuilder& snapshotBuilder, |
| 75 | const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displayInfos, |
| 76 | const std::unordered_map<uint32_t, sp<Layer>>& legacyLayers, uint32_t traceFlags) |
| 77 | : mSnapshotBuilder(snapshotBuilder), |
| 78 | mLegacyLayers(legacyLayers), |
| 79 | mDisplayInfos(displayInfos), |
| 80 | mTraceFlags(traceFlags) {} |
| 81 | LayersProto generate(const frontend::LayerHierarchy& root); |
| 82 | |
| 83 | private: |
| 84 | void writeHierarchyToProto(const frontend::LayerHierarchy& root, |
| 85 | frontend::LayerHierarchy::TraversalPath& path); |
| 86 | frontend::LayerSnapshot* getSnapshot(frontend::LayerHierarchy::TraversalPath& path, |
| 87 | const frontend::RequestedLayerState& layer); |
| 88 | |
| 89 | const frontend::LayerSnapshotBuilder& mSnapshotBuilder; |
| 90 | const std::unordered_map<uint32_t, sp<Layer>>& mLegacyLayers; |
| 91 | const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& mDisplayInfos; |
| 92 | uint32_t mTraceFlags; |
| 93 | LayersProto mLayersProto; |
| 94 | // winscope expects all the layers, so provide a snapshot even if it not currently drawing |
| 95 | std::unordered_map<frontend::LayerHierarchy::TraversalPath, frontend::LayerSnapshot, |
| 96 | frontend::LayerHierarchy::TraversalPathHash> |
| 97 | mDefaultSnapshots; |
| 98 | std::unordered_map<uint32_t /* child unique seq*/, uint32_t /* relative parent unique seq*/> |
| 99 | mChildToRelativeParent; |
| 100 | std::unordered_map<uint32_t /* child unique seq*/, uint32_t /* parent unique seq*/> |
| 101 | mChildToParent; |
| 102 | }; |
| 103 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 104 | } // namespace surfaceflinger |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 105 | } // namespace android |