blob: b84a49b27c9a8b0bc42e2e93ea8558d55a12000c [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>
29#include "FrontEnd/LayerHierarchy.h"
30#include "FrontEnd/LayerSnapshot.h"
chaviw1d044282017-09-27 12:19:28 -070031
32namespace android {
33namespace surfaceflinger {
34class LayerProtoHelper {
35public:
Nataniel Borges797b0e42019-02-15 14:11:58 -080036 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 Nair6b591152021-10-08 11:45:14 -070041 static void writeToProto(const Rect& rect, RectProto* rectProto);
42 static void readFromProto(const RectProto& proto, Rect& outRect);
Nataniel Borges797b0e42019-02-15 14:11:58 -080043 static void writeToProto(const FloatRect& rect,
44 std::function<FloatRectProto*()> getFloatRectProto);
45 static void writeToProto(const Region& region, std::function<RegionProto*()> getRegionProto);
Vishnu Nair6b591152021-10-08 11:45:14 -070046 static void writeToProto(const Region& region, RegionProto* regionProto);
47 static void readFromProto(const RegionProto& regionProto, Region& outRegion);
Nataniel Borges797b0e42019-02-15 14:11:58 -080048 static void writeToProto(const half4 color, std::function<ColorProto*()> getColorProto);
chaviw0a398992021-08-13 10:13:01 -050049 // 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 Naird37343b2022-01-12 16:18:56 -080055 static void writeToProto(const renderengine::ExternalTexture& buffer,
Nataniel Borges797b0e42019-02-15 14:11:58 -080056 std::function<ActiveBufferProto*()> getActiveBufferProto);
chaviw98318de2021-05-19 16:45:23 -050057 static void writeToProto(const gui::WindowInfo& inputInfo,
Vishnu Nair9245d3b2019-03-22 13:38:56 -070058 const wp<Layer>& touchableRegionBounds,
59 std::function<InputWindowInfoProto*()> getInputWindowInfoProto);
chaviwddeae262020-01-06 10:31:23 -080060 static void writeToProto(const mat4 matrix, ColorTransformProto* colorTransformProto);
Vishnu Nair6b591152021-10-08 11:45:14 -070061 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 Nairea6ff812023-02-27 17:41:39 +000064 static void writeSnapshotToProto(LayerProto* outProto,
65 const frontend::RequestedLayerState& requestedState,
66 const frontend::LayerSnapshot& snapshot, uint32_t traceFlags);
Vishnu Nair81750622023-03-08 15:02:06 -080067 static google::protobuf::RepeatedPtrField<DisplayProto> writeDisplayInfoToProto(
68 const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displayInfos);
chaviw1d044282017-09-27 12:19:28 -070069};
70
Vishnu Naird0183602023-03-16 18:52:15 +000071class LayerProtoFromSnapshotGenerator {
72public:
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
83private:
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
chaviw1d044282017-09-27 12:19:28 -0700104} // namespace surfaceflinger
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800105} // namespace android