blob: 346685f25949f425a2ee63b0db9cbda1ce89d8bc [file] [log] [blame]
chaviw1d044282017-09-27 12:19:28 -07001/*
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 Naird37343b2022-01-12 16:18:56 -080018#include <renderengine/ExternalTexture.h>
chaviw1d044282017-09-27 12:19:28 -070019
Vishnu Nair9245d3b2019-03-22 13:38:56 -070020#include <Layer.h>
chaviw98318de2021-05-19 16:45:23 -050021#include <gui/WindowInfo.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070022#include <math/vec4.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070023#include <ui/BlurRegion.h>
chaviw1d044282017-09-27 12:19:28 -070024#include <ui/GraphicBuffer.h>
25#include <ui/Rect.h>
26#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070027#include <ui/Transform.h>
Vishnu Naird0183602023-03-16 18:52:15 +000028#include <cstdint>
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050029
30#include "FrontEnd/DisplayInfo.h"
Vishnu Naird0183602023-03-16 18:52:15 +000031#include "FrontEnd/LayerHierarchy.h"
32#include "FrontEnd/LayerSnapshot.h"
chaviw1d044282017-09-27 12:19:28 -070033
34namespace android {
35namespace surfaceflinger {
36class LayerProtoHelper {
37public:
Nataniel Borges797b0e42019-02-15 14:11:58 -080038 static void writePositionToProto(const float x, const float y,
39 std::function<PositionProto*()> getPositionProto);
40 static void writeSizeToProto(const uint32_t w, const uint32_t h,
41 std::function<SizeProto*()> getSizeProto);
42 static void writeToProto(const Rect& rect, std::function<RectProto*()> getRectProto);
Vishnu Nair6b591152021-10-08 11:45:14 -070043 static void writeToProto(const Rect& rect, RectProto* rectProto);
44 static void readFromProto(const RectProto& proto, Rect& outRect);
Nataniel Borges797b0e42019-02-15 14:11:58 -080045 static void writeToProto(const FloatRect& rect,
46 std::function<FloatRectProto*()> getFloatRectProto);
47 static void writeToProto(const Region& region, std::function<RegionProto*()> getRegionProto);
Vishnu Nair6b591152021-10-08 11:45:14 -070048 static void writeToProto(const Region& region, RegionProto* regionProto);
49 static void readFromProto(const RegionProto& regionProto, Region& outRegion);
Nataniel Borges797b0e42019-02-15 14:11:58 -080050 static void writeToProto(const half4 color, std::function<ColorProto*()> getColorProto);
chaviw0a398992021-08-13 10:13:01 -050051 // This writeToProto for transform is incorrect, but due to backwards compatibility, we can't
52 // update Layers to use it. Use writeTransformToProto for any new transform proto data.
53 static void writeToProtoDeprecated(const ui::Transform& transform,
54 TransformProto* transformProto);
55 static void writeTransformToProto(const ui::Transform& transform,
56 TransformProto* transformProto);
Vishnu Naird37343b2022-01-12 16:18:56 -080057 static void writeToProto(const renderengine::ExternalTexture& buffer,
Nataniel Borges797b0e42019-02-15 14:11:58 -080058 std::function<ActiveBufferProto*()> getActiveBufferProto);
chaviw98318de2021-05-19 16:45:23 -050059 static void writeToProto(const gui::WindowInfo& inputInfo,
Vishnu Nair9245d3b2019-03-22 13:38:56 -070060 const wp<Layer>& touchableRegionBounds,
61 std::function<InputWindowInfoProto*()> getInputWindowInfoProto);
chaviwddeae262020-01-06 10:31:23 -080062 static void writeToProto(const mat4 matrix, ColorTransformProto* colorTransformProto);
Vishnu Nair6b591152021-10-08 11:45:14 -070063 static void readFromProto(const ColorTransformProto& colorTransformProto, mat4& matrix);
64 static void writeToProto(const android::BlurRegion region, BlurRegion*);
65 static void readFromProto(const BlurRegion& proto, android::BlurRegion& outRegion);
Vishnu Nairea6ff812023-02-27 17:41:39 +000066 static void writeSnapshotToProto(LayerProto* outProto,
67 const frontend::RequestedLayerState& requestedState,
68 const frontend::LayerSnapshot& snapshot, uint32_t traceFlags);
Vishnu Nair81750622023-03-08 15:02:06 -080069 static google::protobuf::RepeatedPtrField<DisplayProto> writeDisplayInfoToProto(
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050070 const frontend::DisplayInfos&);
chaviw1d044282017-09-27 12:19:28 -070071};
72
Vishnu Naird0183602023-03-16 18:52:15 +000073class LayerProtoFromSnapshotGenerator {
74public:
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050075 LayerProtoFromSnapshotGenerator(const frontend::LayerSnapshotBuilder& snapshotBuilder,
76 const frontend::DisplayInfos& displayInfos,
77 const std::unordered_map<uint32_t, sp<Layer>>& legacyLayers,
78 uint32_t traceFlags)
Vishnu Naird0183602023-03-16 18:52:15 +000079 : mSnapshotBuilder(snapshotBuilder),
80 mLegacyLayers(legacyLayers),
81 mDisplayInfos(displayInfos),
82 mTraceFlags(traceFlags) {}
83 LayersProto generate(const frontend::LayerHierarchy& root);
84
85private:
86 void writeHierarchyToProto(const frontend::LayerHierarchy& root,
87 frontend::LayerHierarchy::TraversalPath& path);
88 frontend::LayerSnapshot* getSnapshot(frontend::LayerHierarchy::TraversalPath& path,
89 const frontend::RequestedLayerState& layer);
90
91 const frontend::LayerSnapshotBuilder& mSnapshotBuilder;
92 const std::unordered_map<uint32_t, sp<Layer>>& mLegacyLayers;
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050093 const frontend::DisplayInfos& mDisplayInfos;
Vishnu Naird0183602023-03-16 18:52:15 +000094 uint32_t mTraceFlags;
95 LayersProto mLayersProto;
96 // winscope expects all the layers, so provide a snapshot even if it not currently drawing
97 std::unordered_map<frontend::LayerHierarchy::TraversalPath, frontend::LayerSnapshot,
98 frontend::LayerHierarchy::TraversalPathHash>
99 mDefaultSnapshots;
100 std::unordered_map<uint32_t /* child unique seq*/, uint32_t /* relative parent unique seq*/>
101 mChildToRelativeParent;
102 std::unordered_map<uint32_t /* child unique seq*/, uint32_t /* parent unique seq*/>
103 mChildToParent;
104};
105
chaviw1d044282017-09-27 12:19:28 -0700106} // namespace surfaceflinger
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800107} // namespace android