• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
18 #include <renderengine/ExternalTexture.h>
19 
20 #include <Layer.h>
21 #include <gui/WindowInfo.h>
22 #include <math/vec4.h>
23 #include <ui/BlurRegion.h>
24 #include <ui/GraphicBuffer.h>
25 #include <ui/Rect.h>
26 #include <ui/Region.h>
27 #include <ui/Transform.h>
28 #include <cstdint>
29 
30 #include "FrontEnd/DisplayInfo.h"
31 #include "FrontEnd/LayerHierarchy.h"
32 #include "FrontEnd/LayerSnapshot.h"
33 
34 namespace android {
35 namespace surfaceflinger {
36 class LayerProtoHelper {
37 public:
38     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);
43     static void writeToProto(const Rect& rect, RectProto* rectProto);
44     static void readFromProto(const RectProto& proto, Rect& outRect);
45     static void writeToProto(const FloatRect& rect,
46                              std::function<FloatRectProto*()> getFloatRectProto);
47     static void writeToProto(const Region& region, std::function<RegionProto*()> getRegionProto);
48     static void writeToProto(const Region& region, RegionProto* regionProto);
49     static void readFromProto(const RegionProto& regionProto, Region& outRegion);
50     static void writeToProto(const half4 color, std::function<ColorProto*()> getColorProto);
51     // 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);
57     static void writeToProto(const renderengine::ExternalTexture& buffer,
58                              std::function<ActiveBufferProto*()> getActiveBufferProto);
59     static void writeToProto(const gui::WindowInfo& inputInfo,
60                              const wp<Layer>& touchableRegionBounds,
61                              std::function<InputWindowInfoProto*()> getInputWindowInfoProto);
62     static void writeToProto(const mat4 matrix, ColorTransformProto* colorTransformProto);
63     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);
66     static void writeSnapshotToProto(LayerProto* outProto,
67                                      const frontend::RequestedLayerState& requestedState,
68                                      const frontend::LayerSnapshot& snapshot, uint32_t traceFlags);
69     static google::protobuf::RepeatedPtrField<DisplayProto> writeDisplayInfoToProto(
70             const frontend::DisplayInfos&);
71 };
72 
73 class LayerProtoFromSnapshotGenerator {
74 public:
LayerProtoFromSnapshotGenerator(const frontend::LayerSnapshotBuilder & snapshotBuilder,const frontend::DisplayInfos & displayInfos,const std::unordered_map<uint32_t,sp<Layer>> & legacyLayers,uint32_t traceFlags)75     LayerProtoFromSnapshotGenerator(const frontend::LayerSnapshotBuilder& snapshotBuilder,
76                                     const frontend::DisplayInfos& displayInfos,
77                                     const std::unordered_map<uint32_t, sp<Layer>>& legacyLayers,
78                                     uint32_t traceFlags)
79           : mSnapshotBuilder(snapshotBuilder),
80             mLegacyLayers(legacyLayers),
81             mDisplayInfos(displayInfos),
82             mTraceFlags(traceFlags) {}
83     LayersProto generate(const frontend::LayerHierarchy& root);
84 
85 private:
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;
93     const frontend::DisplayInfos& mDisplayInfos;
94     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 
106 } // namespace surfaceflinger
107 } // namespace android
108