blob: 5582a5c7719d539c1032831a20c020d4db5e61dc [file] [log] [blame]
Irvelc274c632016-06-13 16:44:08 -07001/*
2 * Copyright 2016 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#ifndef ANDROID_SURFACEINTERCEPTOR_H
18#define ANDROID_SURFACEINTERCEPTOR_H
19
20#include <frameworks/native/cmds/surfacecapturereplay/proto/src/trace.pb.h>
21
22#include <mutex>
23
24namespace android {
25
26class BufferItem;
27class Layer;
28struct layer_state_t;
29
30constexpr auto DEFAULT_FILENAME = "/data/SurfaceTrace.dat";
31
32/*
33 * SurfaceInterceptor intercepts and stores incoming streams of window
34 * properties on SurfaceFlinger.
35 */
36class SurfaceInterceptor {
37public:
38 // The layer vector is used to capture the inital snapshot in the trace
39 void enable(const SortedVector<sp<Layer>>& layers);
40 void disable();
41 void setOutputFileName(const std::string& OutputFileName);
42
43 void saveLayerUpdates(const Vector<ComposerState>& state, uint32_t flags);
44 void saveLayerCreate(const sp<const Layer>& layer);
45 void saveLayerDelete(const sp<const Layer>& layer);
46 void saveBufferUpdate(const sp<const Layer>& layer, uint32_t width, uint32_t height,
47 uint64_t frameNumber);
48 void saveVSyncEvent(nsecs_t timestamp);
49
50private:
51 void saveExistingLayers(const SortedVector<sp<Layer>>& layers);
52 void saveInitialLayerStateLocked(const sp<const Layer>& layer);
53 void saveLayerCreateLocked(const sp<const Layer>& layer);
54 status_t writeProtoFileLocked();
55 const sp<const Layer> getLayer(const sp<const IBinder>& handle);
56 const std::string getLayerName(const sp<const Layer>& layer);
57 int32_t getLayerId(const sp<const Layer>& layer);
58 Increment* addTraceIncrementLocked();
59
60 void addUpdatedLayersLocked(Increment* increment, uint32_t flags,
61 const Vector<ComposerState>& stateUpdates);
62 void addCreatedLayerLocked(Increment* increment, const sp<const Layer>& layer);
63 void addDeletedLayerLocked(Increment* increment, const sp<const Layer>& layer);
64 void addUpdatedBufferLocked(Increment* increment, const sp<const Layer>& layer, uint32_t width,
65 uint32_t height, uint64_t frameNumber);
66 void addUpdatedVsyncLocked(Increment* increment, nsecs_t timestamp);
67
68 Change* addChangeLocked(Transaction* transaction, int32_t layerId);
69 void setProtoRectLocked(Rectangle* protoRect, const Rect& rect);
70 void addPositionLocked(Transaction* transaction, int32_t layerId, float x, float y);
71 void addDepthLocked(Transaction* transaction, int32_t layerId, uint32_t z);
72 void addSizeLocked(Transaction* transaction, int32_t layerId, uint32_t w, uint32_t h);
73 void addAlphaLocked(Transaction* transaction, int32_t layerId, float alpha);
74 void addMatrixLocked(Transaction* transaction, int32_t layerId,
75 const layer_state_t::matrix22_t& matrix);
76 void addTransparentRegionLocked(Transaction* transaction, int32_t layerId,
77 const Region& transRegion);
78 void addFlagsLocked(Transaction* transaction, int32_t layerId, uint8_t flags);
79 void addLayerStackLocked(Transaction* transaction, int32_t layerId, uint32_t layerStack);
80 void addCropLocked(Transaction* transaction, int32_t layerId, const Rect& rect);
81 void addDeferTransactionLocked(Transaction* transaction, int32_t layerId,
82 const sp<const IBinder>& handle, uint64_t frameNumber);
83 void addFinalCropLocked(Transaction* transaction, int32_t layerId, const Rect& rect);
84 void addOverrideScalingModeLocked(Transaction* transaction, int32_t layerId,
85 int32_t overrideScalingMode);
86 void addChangedPropertiesLocked(Transaction* transaction, const layer_state_t& state);
87
88 bool mEnabled {false};
89 std::string mOutputFileName {DEFAULT_FILENAME};
90 std::mutex mTraceMutex {};
91 Trace mTrace {};
92};
93
94}
95
96#endif // ANDROID_SURFACEINTERCEPTOR_H