1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker #include <gui/SurfaceComposerClient.h>
18*38e8c45fSAndroid Build Coastguard Worker #include <ui/Fence.h>
19*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rect.h>
20*38e8c45fSAndroid Build Coastguard Worker
21*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerCreationArgs.h"
22*38e8c45fSAndroid Build Coastguard Worker #include "LayerProtoHelper.h"
23*38e8c45fSAndroid Build Coastguard Worker #include "TransactionProtoParser.h"
24*38e8c45fSAndroid Build Coastguard Worker #include "TransactionState.h"
25*38e8c45fSAndroid Build Coastguard Worker #include "gui/LayerState.h"
26*38e8c45fSAndroid Build Coastguard Worker
27*38e8c45fSAndroid Build Coastguard Worker namespace android::surfaceflinger {
28*38e8c45fSAndroid Build Coastguard Worker
29*38e8c45fSAndroid Build Coastguard Worker class FakeExternalTexture : public renderengine::ExternalTexture {
30*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer> mEmptyBuffer = nullptr;
31*38e8c45fSAndroid Build Coastguard Worker uint32_t mWidth;
32*38e8c45fSAndroid Build Coastguard Worker uint32_t mHeight;
33*38e8c45fSAndroid Build Coastguard Worker uint64_t mId;
34*38e8c45fSAndroid Build Coastguard Worker PixelFormat mPixelFormat;
35*38e8c45fSAndroid Build Coastguard Worker uint64_t mUsage;
36*38e8c45fSAndroid Build Coastguard Worker
37*38e8c45fSAndroid Build Coastguard Worker public:
FakeExternalTexture(uint32_t width,uint32_t height,uint64_t id,PixelFormat pixelFormat,uint64_t usage)38*38e8c45fSAndroid Build Coastguard Worker FakeExternalTexture(uint32_t width, uint32_t height, uint64_t id, PixelFormat pixelFormat,
39*38e8c45fSAndroid Build Coastguard Worker uint64_t usage)
40*38e8c45fSAndroid Build Coastguard Worker : mWidth(width), mHeight(height), mId(id), mPixelFormat(pixelFormat), mUsage(usage) {}
getBuffer() const41*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& getBuffer() const { return mEmptyBuffer; }
hasSameBuffer(const renderengine::ExternalTexture & other) const42*38e8c45fSAndroid Build Coastguard Worker bool hasSameBuffer(const renderengine::ExternalTexture& other) const override {
43*38e8c45fSAndroid Build Coastguard Worker return getId() == other.getId();
44*38e8c45fSAndroid Build Coastguard Worker }
getWidth() const45*38e8c45fSAndroid Build Coastguard Worker uint32_t getWidth() const override { return mWidth; }
getHeight() const46*38e8c45fSAndroid Build Coastguard Worker uint32_t getHeight() const override { return mHeight; }
getId() const47*38e8c45fSAndroid Build Coastguard Worker uint64_t getId() const override { return mId; }
getPixelFormat() const48*38e8c45fSAndroid Build Coastguard Worker PixelFormat getPixelFormat() const override { return mPixelFormat; }
getUsage() const49*38e8c45fSAndroid Build Coastguard Worker uint64_t getUsage() const override { return mUsage; }
remapBuffer()50*38e8c45fSAndroid Build Coastguard Worker void remapBuffer() override {}
51*38e8c45fSAndroid Build Coastguard Worker ~FakeExternalTexture() = default;
52*38e8c45fSAndroid Build Coastguard Worker };
53*38e8c45fSAndroid Build Coastguard Worker
toProto(const TransactionState & t)54*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
55*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::TransactionState proto;
56*38e8c45fSAndroid Build Coastguard Worker proto.set_pid(t.originPid);
57*38e8c45fSAndroid Build Coastguard Worker proto.set_uid(t.originUid);
58*38e8c45fSAndroid Build Coastguard Worker proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
59*38e8c45fSAndroid Build Coastguard Worker proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
60*38e8c45fSAndroid Build Coastguard Worker proto.set_post_time(t.postTime);
61*38e8c45fSAndroid Build Coastguard Worker proto.set_transaction_id(t.id);
62*38e8c45fSAndroid Build Coastguard Worker
63*38e8c45fSAndroid Build Coastguard Worker proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
64*38e8c45fSAndroid Build Coastguard Worker for (auto& layerState : t.states) {
65*38e8c45fSAndroid Build Coastguard Worker proto.mutable_layer_changes()->Add(toProto(layerState));
66*38e8c45fSAndroid Build Coastguard Worker }
67*38e8c45fSAndroid Build Coastguard Worker
68*38e8c45fSAndroid Build Coastguard Worker proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
69*38e8c45fSAndroid Build Coastguard Worker for (auto& displayState : t.displays) {
70*38e8c45fSAndroid Build Coastguard Worker proto.mutable_display_changes()->Add(toProto(displayState));
71*38e8c45fSAndroid Build Coastguard Worker }
72*38e8c45fSAndroid Build Coastguard Worker
73*38e8c45fSAndroid Build Coastguard Worker proto.mutable_merged_transaction_ids()->Reserve(
74*38e8c45fSAndroid Build Coastguard Worker static_cast<int32_t>(t.mergedTransactionIds.size()));
75*38e8c45fSAndroid Build Coastguard Worker for (auto& mergedTransactionId : t.mergedTransactionIds) {
76*38e8c45fSAndroid Build Coastguard Worker proto.mutable_merged_transaction_ids()->Add(mergedTransactionId);
77*38e8c45fSAndroid Build Coastguard Worker }
78*38e8c45fSAndroid Build Coastguard Worker
79*38e8c45fSAndroid Build Coastguard Worker return proto;
80*38e8c45fSAndroid Build Coastguard Worker }
81*38e8c45fSAndroid Build Coastguard Worker
toProto(const std::map<uint32_t,TracingLayerState> & states)82*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::TransactionState TransactionProtoParser::toProto(
83*38e8c45fSAndroid Build Coastguard Worker const std::map<uint32_t /* layerId */, TracingLayerState>& states) {
84*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::TransactionState proto;
85*38e8c45fSAndroid Build Coastguard Worker proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
86*38e8c45fSAndroid Build Coastguard Worker for (auto& [layerId, state] : states) {
87*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState layerProto = toProto(state);
88*38e8c45fSAndroid Build Coastguard Worker layerProto.set_has_sideband_stream(state.hasSidebandStream);
89*38e8c45fSAndroid Build Coastguard Worker proto.mutable_layer_changes()->Add(std::move(layerProto));
90*38e8c45fSAndroid Build Coastguard Worker }
91*38e8c45fSAndroid Build Coastguard Worker return proto;
92*38e8c45fSAndroid Build Coastguard Worker }
93*38e8c45fSAndroid Build Coastguard Worker
toProto(const ResolvedComposerState & resolvedComposerState)94*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState TransactionProtoParser::toProto(
95*38e8c45fSAndroid Build Coastguard Worker const ResolvedComposerState& resolvedComposerState) {
96*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState proto;
97*38e8c45fSAndroid Build Coastguard Worker auto& layer = resolvedComposerState.state;
98*38e8c45fSAndroid Build Coastguard Worker proto.set_layer_id(resolvedComposerState.layerId);
99*38e8c45fSAndroid Build Coastguard Worker proto.set_what(layer.what);
100*38e8c45fSAndroid Build Coastguard Worker
101*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::ePositionChanged) {
102*38e8c45fSAndroid Build Coastguard Worker proto.set_x(layer.x);
103*38e8c45fSAndroid Build Coastguard Worker proto.set_y(layer.y);
104*38e8c45fSAndroid Build Coastguard Worker }
105*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eLayerChanged) {
106*38e8c45fSAndroid Build Coastguard Worker proto.set_z(layer.z);
107*38e8c45fSAndroid Build Coastguard Worker }
108*38e8c45fSAndroid Build Coastguard Worker
109*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eLayerStackChanged) {
110*38e8c45fSAndroid Build Coastguard Worker proto.set_layer_stack(layer.layerStack.id);
111*38e8c45fSAndroid Build Coastguard Worker }
112*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eFlagsChanged) {
113*38e8c45fSAndroid Build Coastguard Worker proto.set_flags(layer.flags);
114*38e8c45fSAndroid Build Coastguard Worker proto.set_mask(layer.mask);
115*38e8c45fSAndroid Build Coastguard Worker }
116*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eMatrixChanged) {
117*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
118*38e8c45fSAndroid Build Coastguard Worker matrixProto->set_dsdx(layer.matrix.dsdx);
119*38e8c45fSAndroid Build Coastguard Worker matrixProto->set_dsdy(layer.matrix.dsdy);
120*38e8c45fSAndroid Build Coastguard Worker matrixProto->set_dtdx(layer.matrix.dtdx);
121*38e8c45fSAndroid Build Coastguard Worker matrixProto->set_dtdy(layer.matrix.dtdy);
122*38e8c45fSAndroid Build Coastguard Worker }
123*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eCornerRadiusChanged) {
124*38e8c45fSAndroid Build Coastguard Worker proto.set_corner_radius(layer.cornerRadius);
125*38e8c45fSAndroid Build Coastguard Worker }
126*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
127*38e8c45fSAndroid Build Coastguard Worker proto.set_background_blur_radius(layer.backgroundBlurRadius);
128*38e8c45fSAndroid Build Coastguard Worker }
129*38e8c45fSAndroid Build Coastguard Worker
130*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eAlphaChanged) {
131*38e8c45fSAndroid Build Coastguard Worker proto.set_alpha(layer.color.a);
132*38e8c45fSAndroid Build Coastguard Worker }
133*38e8c45fSAndroid Build Coastguard Worker
134*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eColorChanged) {
135*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState_Color3* colorProto = proto.mutable_color();
136*38e8c45fSAndroid Build Coastguard Worker colorProto->set_r(layer.color.r);
137*38e8c45fSAndroid Build Coastguard Worker colorProto->set_g(layer.color.g);
138*38e8c45fSAndroid Build Coastguard Worker colorProto->set_b(layer.color.b);
139*38e8c45fSAndroid Build Coastguard Worker }
140*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eTransparentRegionChanged) {
141*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
142*38e8c45fSAndroid Build Coastguard Worker }
143*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eBufferTransformChanged) {
144*38e8c45fSAndroid Build Coastguard Worker proto.set_transform(layer.bufferTransform);
145*38e8c45fSAndroid Build Coastguard Worker }
146*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
147*38e8c45fSAndroid Build Coastguard Worker proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
148*38e8c45fSAndroid Build Coastguard Worker }
149*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eCropChanged) {
150*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(Rect(layer.crop), proto.mutable_crop());
151*38e8c45fSAndroid Build Coastguard Worker }
152*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eBufferChanged) {
153*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
154*38e8c45fSAndroid Build Coastguard Worker if (resolvedComposerState.externalTexture) {
155*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_buffer_id(resolvedComposerState.externalTexture->getId());
156*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_width(resolvedComposerState.externalTexture->getWidth());
157*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_height(resolvedComposerState.externalTexture->getHeight());
158*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_pixel_format(
159*38e8c45fSAndroid Build Coastguard Worker static_cast<perfetto::protos::LayerState_BufferData_PixelFormat>(
160*38e8c45fSAndroid Build Coastguard Worker resolvedComposerState.externalTexture->getPixelFormat()));
161*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_usage(resolvedComposerState.externalTexture->getUsage());
162*38e8c45fSAndroid Build Coastguard Worker }
163*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_frame_number(layer.bufferData->frameNumber);
164*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_flags(layer.bufferData->flags.get());
165*38e8c45fSAndroid Build Coastguard Worker bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
166*38e8c45fSAndroid Build Coastguard Worker }
167*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eSidebandStreamChanged) {
168*38e8c45fSAndroid Build Coastguard Worker proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
169*38e8c45fSAndroid Build Coastguard Worker }
170*38e8c45fSAndroid Build Coastguard Worker
171*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eApiChanged) {
172*38e8c45fSAndroid Build Coastguard Worker proto.set_api(layer.api);
173*38e8c45fSAndroid Build Coastguard Worker }
174*38e8c45fSAndroid Build Coastguard Worker
175*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eColorTransformChanged) {
176*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
177*38e8c45fSAndroid Build Coastguard Worker }
178*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eBlurRegionsChanged) {
179*38e8c45fSAndroid Build Coastguard Worker for (auto& region : layer.blurRegions) {
180*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
181*38e8c45fSAndroid Build Coastguard Worker }
182*38e8c45fSAndroid Build Coastguard Worker }
183*38e8c45fSAndroid Build Coastguard Worker
184*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eReparent) {
185*38e8c45fSAndroid Build Coastguard Worker proto.set_parent_id(resolvedComposerState.parentId);
186*38e8c45fSAndroid Build Coastguard Worker }
187*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eRelativeLayerChanged) {
188*38e8c45fSAndroid Build Coastguard Worker proto.set_relative_parent_id(resolvedComposerState.relativeParentId);
189*38e8c45fSAndroid Build Coastguard Worker proto.set_z(layer.z);
190*38e8c45fSAndroid Build Coastguard Worker }
191*38e8c45fSAndroid Build Coastguard Worker
192*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eInputInfoChanged) {
193*38e8c45fSAndroid Build Coastguard Worker if (layer.windowInfoHandle) {
194*38e8c45fSAndroid Build Coastguard Worker const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
195*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState_WindowInfo* windowInfoProto =
196*38e8c45fSAndroid Build Coastguard Worker proto.mutable_window_info_handle();
197*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
198*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_layout_params_type(
199*38e8c45fSAndroid Build Coastguard Worker static_cast<int32_t>(inputInfo->layoutParamsType));
200*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_input_config(inputInfo->inputConfig.get());
201*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
202*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->mutable_touchable_region());
203*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
204*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_focusable(
205*38e8c45fSAndroid Build Coastguard Worker !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
206*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
207*38e8c45fSAndroid Build Coastguard Worker gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
208*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
209*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::Transform* transformProto = windowInfoProto->mutable_transform();
210*38e8c45fSAndroid Build Coastguard Worker transformProto->set_dsdx(inputInfo->transform.dsdx());
211*38e8c45fSAndroid Build Coastguard Worker transformProto->set_dtdx(inputInfo->transform.dtdx());
212*38e8c45fSAndroid Build Coastguard Worker transformProto->set_dtdy(inputInfo->transform.dtdy());
213*38e8c45fSAndroid Build Coastguard Worker transformProto->set_dsdy(inputInfo->transform.dsdy());
214*38e8c45fSAndroid Build Coastguard Worker transformProto->set_tx(inputInfo->transform.tx());
215*38e8c45fSAndroid Build Coastguard Worker transformProto->set_ty(inputInfo->transform.ty());
216*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_replace_touchable_region_with_crop(
217*38e8c45fSAndroid Build Coastguard Worker inputInfo->replaceTouchableRegionWithCrop);
218*38e8c45fSAndroid Build Coastguard Worker windowInfoProto->set_crop_layer_id(resolvedComposerState.touchCropId);
219*38e8c45fSAndroid Build Coastguard Worker }
220*38e8c45fSAndroid Build Coastguard Worker }
221*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eBackgroundColorChanged) {
222*38e8c45fSAndroid Build Coastguard Worker proto.set_bg_color_alpha(layer.bgColor.a);
223*38e8c45fSAndroid Build Coastguard Worker proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
224*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerState_Color3* colorProto = proto.mutable_color();
225*38e8c45fSAndroid Build Coastguard Worker colorProto->set_r(layer.bgColor.r);
226*38e8c45fSAndroid Build Coastguard Worker colorProto->set_g(layer.bgColor.g);
227*38e8c45fSAndroid Build Coastguard Worker colorProto->set_b(layer.bgColor.b);
228*38e8c45fSAndroid Build Coastguard Worker }
229*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
230*38e8c45fSAndroid Build Coastguard Worker proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
231*38e8c45fSAndroid Build Coastguard Worker }
232*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eShadowRadiusChanged) {
233*38e8c45fSAndroid Build Coastguard Worker proto.set_shadow_radius(layer.shadowRadius);
234*38e8c45fSAndroid Build Coastguard Worker }
235*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
236*38e8c45fSAndroid Build Coastguard Worker proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
237*38e8c45fSAndroid Build Coastguard Worker }
238*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eFrameRateChanged) {
239*38e8c45fSAndroid Build Coastguard Worker proto.set_frame_rate(layer.frameRate);
240*38e8c45fSAndroid Build Coastguard Worker proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
241*38e8c45fSAndroid Build Coastguard Worker proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
242*38e8c45fSAndroid Build Coastguard Worker }
243*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eFixedTransformHintChanged) {
244*38e8c45fSAndroid Build Coastguard Worker proto.set_fixed_transform_hint(layer.fixedTransformHint);
245*38e8c45fSAndroid Build Coastguard Worker }
246*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eAutoRefreshChanged) {
247*38e8c45fSAndroid Build Coastguard Worker proto.set_auto_refresh(layer.autoRefresh);
248*38e8c45fSAndroid Build Coastguard Worker }
249*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eTrustedOverlayChanged) {
250*38e8c45fSAndroid Build Coastguard Worker proto.set_is_trusted_overlay(layer.trustedOverlay == gui::TrustedOverlay::ENABLED);
251*38e8c45fSAndroid Build Coastguard Worker // TODO(b/339701674) update protos
252*38e8c45fSAndroid Build Coastguard Worker }
253*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eBufferCropChanged) {
254*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
255*38e8c45fSAndroid Build Coastguard Worker }
256*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eDestinationFrameChanged) {
257*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
258*38e8c45fSAndroid Build Coastguard Worker }
259*38e8c45fSAndroid Build Coastguard Worker if (layer.what & layer_state_t::eDropInputModeChanged) {
260*38e8c45fSAndroid Build Coastguard Worker proto.set_drop_input_mode(
261*38e8c45fSAndroid Build Coastguard Worker static_cast<perfetto::protos::LayerState_DropInputMode>(layer.dropInputMode));
262*38e8c45fSAndroid Build Coastguard Worker }
263*38e8c45fSAndroid Build Coastguard Worker return proto;
264*38e8c45fSAndroid Build Coastguard Worker }
265*38e8c45fSAndroid Build Coastguard Worker
toProto(const DisplayState & display)266*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
267*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::DisplayState proto;
268*38e8c45fSAndroid Build Coastguard Worker proto.set_what(display.what);
269*38e8c45fSAndroid Build Coastguard Worker proto.set_id(mMapper->getDisplayId(display.token));
270*38e8c45fSAndroid Build Coastguard Worker
271*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eLayerStackChanged) {
272*38e8c45fSAndroid Build Coastguard Worker proto.set_layer_stack(display.layerStack.id);
273*38e8c45fSAndroid Build Coastguard Worker }
274*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eDisplayProjectionChanged) {
275*38e8c45fSAndroid Build Coastguard Worker proto.set_orientation(static_cast<uint32_t>(display.orientation));
276*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
277*38e8c45fSAndroid Build Coastguard Worker proto.mutable_oriented_display_space_rect());
278*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
279*38e8c45fSAndroid Build Coastguard Worker proto.mutable_layer_stack_space_rect());
280*38e8c45fSAndroid Build Coastguard Worker }
281*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eDisplaySizeChanged) {
282*38e8c45fSAndroid Build Coastguard Worker proto.set_width(display.width);
283*38e8c45fSAndroid Build Coastguard Worker proto.set_height(display.height);
284*38e8c45fSAndroid Build Coastguard Worker }
285*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eFlagsChanged) {
286*38e8c45fSAndroid Build Coastguard Worker proto.set_flags(display.flags);
287*38e8c45fSAndroid Build Coastguard Worker }
288*38e8c45fSAndroid Build Coastguard Worker return proto;
289*38e8c45fSAndroid Build Coastguard Worker }
290*38e8c45fSAndroid Build Coastguard Worker
toProto(const LayerCreationArgs & args)291*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerCreationArgs TransactionProtoParser::toProto(const LayerCreationArgs& args) {
292*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayerCreationArgs proto;
293*38e8c45fSAndroid Build Coastguard Worker proto.set_layer_id(args.sequence);
294*38e8c45fSAndroid Build Coastguard Worker proto.set_name(args.name);
295*38e8c45fSAndroid Build Coastguard Worker proto.set_flags(args.flags);
296*38e8c45fSAndroid Build Coastguard Worker proto.set_parent_id(args.parentId);
297*38e8c45fSAndroid Build Coastguard Worker proto.set_mirror_from_id(args.layerIdToMirror);
298*38e8c45fSAndroid Build Coastguard Worker proto.set_add_to_root(args.addToRoot);
299*38e8c45fSAndroid Build Coastguard Worker proto.set_layer_stack_to_mirror(args.layerStackToMirror.id);
300*38e8c45fSAndroid Build Coastguard Worker return proto;
301*38e8c45fSAndroid Build Coastguard Worker }
302*38e8c45fSAndroid Build Coastguard Worker
fromProto(const perfetto::protos::TransactionState & proto)303*38e8c45fSAndroid Build Coastguard Worker TransactionState TransactionProtoParser::fromProto(
304*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::TransactionState& proto) {
305*38e8c45fSAndroid Build Coastguard Worker TransactionState t;
306*38e8c45fSAndroid Build Coastguard Worker t.originPid = proto.pid();
307*38e8c45fSAndroid Build Coastguard Worker t.originUid = proto.uid();
308*38e8c45fSAndroid Build Coastguard Worker t.frameTimelineInfo.vsyncId = proto.vsync_id();
309*38e8c45fSAndroid Build Coastguard Worker t.frameTimelineInfo.inputEventId = proto.input_event_id();
310*38e8c45fSAndroid Build Coastguard Worker t.postTime = proto.post_time();
311*38e8c45fSAndroid Build Coastguard Worker t.id = proto.transaction_id();
312*38e8c45fSAndroid Build Coastguard Worker
313*38e8c45fSAndroid Build Coastguard Worker int32_t layerCount = proto.layer_changes_size();
314*38e8c45fSAndroid Build Coastguard Worker t.states.reserve(static_cast<size_t>(layerCount));
315*38e8c45fSAndroid Build Coastguard Worker for (int i = 0; i < layerCount; i++) {
316*38e8c45fSAndroid Build Coastguard Worker ResolvedComposerState s;
317*38e8c45fSAndroid Build Coastguard Worker s.state.what = 0;
318*38e8c45fSAndroid Build Coastguard Worker fromProto(proto.layer_changes(i), s);
319*38e8c45fSAndroid Build Coastguard Worker t.states.emplace_back(s);
320*38e8c45fSAndroid Build Coastguard Worker }
321*38e8c45fSAndroid Build Coastguard Worker
322*38e8c45fSAndroid Build Coastguard Worker int32_t displayCount = proto.display_changes_size();
323*38e8c45fSAndroid Build Coastguard Worker t.displays.reserve(static_cast<size_t>(displayCount));
324*38e8c45fSAndroid Build Coastguard Worker for (int i = 0; i < displayCount; i++) {
325*38e8c45fSAndroid Build Coastguard Worker t.displays.add(fromProto(proto.display_changes(i)));
326*38e8c45fSAndroid Build Coastguard Worker }
327*38e8c45fSAndroid Build Coastguard Worker return t;
328*38e8c45fSAndroid Build Coastguard Worker }
329*38e8c45fSAndroid Build Coastguard Worker
fromProto(const perfetto::protos::LayerCreationArgs & proto,LayerCreationArgs & outArgs)330*38e8c45fSAndroid Build Coastguard Worker void TransactionProtoParser::fromProto(const perfetto::protos::LayerCreationArgs& proto,
331*38e8c45fSAndroid Build Coastguard Worker LayerCreationArgs& outArgs) {
332*38e8c45fSAndroid Build Coastguard Worker outArgs.sequence = proto.layer_id();
333*38e8c45fSAndroid Build Coastguard Worker
334*38e8c45fSAndroid Build Coastguard Worker outArgs.name = proto.name();
335*38e8c45fSAndroid Build Coastguard Worker outArgs.flags = proto.flags();
336*38e8c45fSAndroid Build Coastguard Worker outArgs.parentId = proto.parent_id();
337*38e8c45fSAndroid Build Coastguard Worker outArgs.layerIdToMirror = proto.mirror_from_id();
338*38e8c45fSAndroid Build Coastguard Worker outArgs.addToRoot = proto.add_to_root();
339*38e8c45fSAndroid Build Coastguard Worker outArgs.layerStackToMirror.id = proto.layer_stack_to_mirror();
340*38e8c45fSAndroid Build Coastguard Worker }
341*38e8c45fSAndroid Build Coastguard Worker
mergeFromProto(const perfetto::protos::LayerState & proto,TracingLayerState & outState)342*38e8c45fSAndroid Build Coastguard Worker void TransactionProtoParser::mergeFromProto(const perfetto::protos::LayerState& proto,
343*38e8c45fSAndroid Build Coastguard Worker TracingLayerState& outState) {
344*38e8c45fSAndroid Build Coastguard Worker ResolvedComposerState resolvedComposerState;
345*38e8c45fSAndroid Build Coastguard Worker fromProto(proto, resolvedComposerState);
346*38e8c45fSAndroid Build Coastguard Worker layer_state_t& state = resolvedComposerState.state;
347*38e8c45fSAndroid Build Coastguard Worker outState.state.merge(state);
348*38e8c45fSAndroid Build Coastguard Worker outState.layerId = resolvedComposerState.layerId;
349*38e8c45fSAndroid Build Coastguard Worker
350*38e8c45fSAndroid Build Coastguard Worker if (state.what & layer_state_t::eReparent) {
351*38e8c45fSAndroid Build Coastguard Worker outState.parentId = resolvedComposerState.parentId;
352*38e8c45fSAndroid Build Coastguard Worker }
353*38e8c45fSAndroid Build Coastguard Worker if (state.what & layer_state_t::eRelativeLayerChanged) {
354*38e8c45fSAndroid Build Coastguard Worker outState.relativeParentId = resolvedComposerState.relativeParentId;
355*38e8c45fSAndroid Build Coastguard Worker }
356*38e8c45fSAndroid Build Coastguard Worker if (state.what & layer_state_t::eInputInfoChanged) {
357*38e8c45fSAndroid Build Coastguard Worker outState.touchCropId = resolvedComposerState.touchCropId;
358*38e8c45fSAndroid Build Coastguard Worker }
359*38e8c45fSAndroid Build Coastguard Worker if (state.what & layer_state_t::eBufferChanged) {
360*38e8c45fSAndroid Build Coastguard Worker outState.externalTexture = resolvedComposerState.externalTexture;
361*38e8c45fSAndroid Build Coastguard Worker }
362*38e8c45fSAndroid Build Coastguard Worker if (state.what & layer_state_t::eSidebandStreamChanged) {
363*38e8c45fSAndroid Build Coastguard Worker outState.hasSidebandStream = proto.has_sideband_stream();
364*38e8c45fSAndroid Build Coastguard Worker }
365*38e8c45fSAndroid Build Coastguard Worker }
366*38e8c45fSAndroid Build Coastguard Worker
fromProto(const perfetto::protos::LayerState & proto,ResolvedComposerState & resolvedComposerState)367*38e8c45fSAndroid Build Coastguard Worker void TransactionProtoParser::fromProto(const perfetto::protos::LayerState& proto,
368*38e8c45fSAndroid Build Coastguard Worker ResolvedComposerState& resolvedComposerState) {
369*38e8c45fSAndroid Build Coastguard Worker auto& layer = resolvedComposerState.state;
370*38e8c45fSAndroid Build Coastguard Worker resolvedComposerState.layerId = proto.layer_id();
371*38e8c45fSAndroid Build Coastguard Worker layer.what |= proto.what();
372*38e8c45fSAndroid Build Coastguard Worker
373*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::ePositionChanged) {
374*38e8c45fSAndroid Build Coastguard Worker layer.x = proto.x();
375*38e8c45fSAndroid Build Coastguard Worker layer.y = proto.y();
376*38e8c45fSAndroid Build Coastguard Worker }
377*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eLayerChanged) {
378*38e8c45fSAndroid Build Coastguard Worker layer.z = proto.z();
379*38e8c45fSAndroid Build Coastguard Worker }
380*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eLayerStackChanged) {
381*38e8c45fSAndroid Build Coastguard Worker layer.layerStack.id = proto.layer_stack();
382*38e8c45fSAndroid Build Coastguard Worker }
383*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eFlagsChanged) {
384*38e8c45fSAndroid Build Coastguard Worker layer.flags = proto.flags();
385*38e8c45fSAndroid Build Coastguard Worker layer.mask = proto.mask();
386*38e8c45fSAndroid Build Coastguard Worker }
387*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eMatrixChanged) {
388*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::LayerState_Matrix22& matrixProto = proto.matrix();
389*38e8c45fSAndroid Build Coastguard Worker layer.matrix.dsdx = matrixProto.dsdx();
390*38e8c45fSAndroid Build Coastguard Worker layer.matrix.dsdy = matrixProto.dsdy();
391*38e8c45fSAndroid Build Coastguard Worker layer.matrix.dtdx = matrixProto.dtdx();
392*38e8c45fSAndroid Build Coastguard Worker layer.matrix.dtdy = matrixProto.dtdy();
393*38e8c45fSAndroid Build Coastguard Worker }
394*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eCornerRadiusChanged) {
395*38e8c45fSAndroid Build Coastguard Worker layer.cornerRadius = proto.corner_radius();
396*38e8c45fSAndroid Build Coastguard Worker }
397*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
398*38e8c45fSAndroid Build Coastguard Worker layer.backgroundBlurRadius = proto.background_blur_radius();
399*38e8c45fSAndroid Build Coastguard Worker }
400*38e8c45fSAndroid Build Coastguard Worker
401*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eAlphaChanged) {
402*38e8c45fSAndroid Build Coastguard Worker layer.color.a = proto.alpha();
403*38e8c45fSAndroid Build Coastguard Worker }
404*38e8c45fSAndroid Build Coastguard Worker
405*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eColorChanged) {
406*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::LayerState_Color3& colorProto = proto.color();
407*38e8c45fSAndroid Build Coastguard Worker layer.color.r = colorProto.r();
408*38e8c45fSAndroid Build Coastguard Worker layer.color.g = colorProto.g();
409*38e8c45fSAndroid Build Coastguard Worker layer.color.b = colorProto.b();
410*38e8c45fSAndroid Build Coastguard Worker }
411*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eTransparentRegionChanged) {
412*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
413*38e8c45fSAndroid Build Coastguard Worker }
414*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eBufferTransformChanged) {
415*38e8c45fSAndroid Build Coastguard Worker layer.bufferTransform = proto.transform();
416*38e8c45fSAndroid Build Coastguard Worker }
417*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
418*38e8c45fSAndroid Build Coastguard Worker layer.transformToDisplayInverse = proto.transform_to_display_inverse();
419*38e8c45fSAndroid Build Coastguard Worker }
420*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eCropChanged) {
421*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
422*38e8c45fSAndroid Build Coastguard Worker }
423*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eBufferChanged) {
424*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::LayerState_BufferData& bufferProto = proto.buffer_data();
425*38e8c45fSAndroid Build Coastguard Worker layer.bufferData =
426*38e8c45fSAndroid Build Coastguard Worker std::make_shared<fake::BufferData>(bufferProto.buffer_id(), bufferProto.width(),
427*38e8c45fSAndroid Build Coastguard Worker bufferProto.height(), bufferProto.pixel_format(),
428*38e8c45fSAndroid Build Coastguard Worker bufferProto.usage());
429*38e8c45fSAndroid Build Coastguard Worker resolvedComposerState.externalTexture =
430*38e8c45fSAndroid Build Coastguard Worker std::make_shared<FakeExternalTexture>(layer.bufferData->getWidth(),
431*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->getHeight(),
432*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->getId(),
433*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->getPixelFormat(),
434*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->getUsage());
435*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->frameNumber = bufferProto.frame_number();
436*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags());
437*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
438*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->acquireFence = Fence::NO_FENCE;
439*38e8c45fSAndroid Build Coastguard Worker layer.bufferData->dequeueTime = -1;
440*38e8c45fSAndroid Build Coastguard Worker }
441*38e8c45fSAndroid Build Coastguard Worker
442*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eApiChanged) {
443*38e8c45fSAndroid Build Coastguard Worker layer.api = proto.api();
444*38e8c45fSAndroid Build Coastguard Worker }
445*38e8c45fSAndroid Build Coastguard Worker
446*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eColorTransformChanged) {
447*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
448*38e8c45fSAndroid Build Coastguard Worker }
449*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eBlurRegionsChanged) {
450*38e8c45fSAndroid Build Coastguard Worker layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
451*38e8c45fSAndroid Build Coastguard Worker for (int i = 0; i < proto.blur_regions_size(); i++) {
452*38e8c45fSAndroid Build Coastguard Worker android::BlurRegion region;
453*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
454*38e8c45fSAndroid Build Coastguard Worker layer.blurRegions.push_back(region);
455*38e8c45fSAndroid Build Coastguard Worker }
456*38e8c45fSAndroid Build Coastguard Worker }
457*38e8c45fSAndroid Build Coastguard Worker
458*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eReparent) {
459*38e8c45fSAndroid Build Coastguard Worker resolvedComposerState.parentId = proto.parent_id();
460*38e8c45fSAndroid Build Coastguard Worker }
461*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eRelativeLayerChanged) {
462*38e8c45fSAndroid Build Coastguard Worker resolvedComposerState.relativeParentId = proto.relative_parent_id();
463*38e8c45fSAndroid Build Coastguard Worker layer.z = proto.z();
464*38e8c45fSAndroid Build Coastguard Worker }
465*38e8c45fSAndroid Build Coastguard Worker
466*38e8c45fSAndroid Build Coastguard Worker if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
467*38e8c45fSAndroid Build Coastguard Worker gui::WindowInfo inputInfo;
468*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
469*38e8c45fSAndroid Build Coastguard Worker
470*38e8c45fSAndroid Build Coastguard Worker inputInfo.layoutParamsFlags =
471*38e8c45fSAndroid Build Coastguard Worker static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
472*38e8c45fSAndroid Build Coastguard Worker inputInfo.layoutParamsType =
473*38e8c45fSAndroid Build Coastguard Worker static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
474*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
475*38e8c45fSAndroid Build Coastguard Worker inputInfo.touchableRegion);
476*38e8c45fSAndroid Build Coastguard Worker inputInfo.inputConfig =
477*38e8c45fSAndroid Build Coastguard Worker ftl::Flags<gui::WindowInfo::InputConfig>(windowInfoProto.input_config());
478*38e8c45fSAndroid Build Coastguard Worker inputInfo.surfaceInset = windowInfoProto.surface_inset();
479*38e8c45fSAndroid Build Coastguard Worker inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
480*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::Transform& transformProto = windowInfoProto.transform();
481*38e8c45fSAndroid Build Coastguard Worker inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
482*38e8c45fSAndroid Build Coastguard Worker transformProto.dsdy());
483*38e8c45fSAndroid Build Coastguard Worker inputInfo.transform.set(transformProto.tx(), transformProto.ty());
484*38e8c45fSAndroid Build Coastguard Worker inputInfo.replaceTouchableRegionWithCrop =
485*38e8c45fSAndroid Build Coastguard Worker windowInfoProto.replace_touchable_region_with_crop();
486*38e8c45fSAndroid Build Coastguard Worker resolvedComposerState.touchCropId = windowInfoProto.crop_layer_id();
487*38e8c45fSAndroid Build Coastguard Worker
488*38e8c45fSAndroid Build Coastguard Worker layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
489*38e8c45fSAndroid Build Coastguard Worker }
490*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eBackgroundColorChanged) {
491*38e8c45fSAndroid Build Coastguard Worker layer.bgColor.a = proto.bg_color_alpha();
492*38e8c45fSAndroid Build Coastguard Worker layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
493*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::LayerState_Color3& colorProto = proto.color();
494*38e8c45fSAndroid Build Coastguard Worker layer.bgColor.r = colorProto.r();
495*38e8c45fSAndroid Build Coastguard Worker layer.bgColor.g = colorProto.g();
496*38e8c45fSAndroid Build Coastguard Worker layer.bgColor.b = colorProto.b();
497*38e8c45fSAndroid Build Coastguard Worker }
498*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
499*38e8c45fSAndroid Build Coastguard Worker layer.colorSpaceAgnostic = proto.color_space_agnostic();
500*38e8c45fSAndroid Build Coastguard Worker }
501*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eShadowRadiusChanged) {
502*38e8c45fSAndroid Build Coastguard Worker layer.shadowRadius = proto.shadow_radius();
503*38e8c45fSAndroid Build Coastguard Worker }
504*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
505*38e8c45fSAndroid Build Coastguard Worker layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
506*38e8c45fSAndroid Build Coastguard Worker }
507*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eFrameRateChanged) {
508*38e8c45fSAndroid Build Coastguard Worker layer.frameRate = proto.frame_rate();
509*38e8c45fSAndroid Build Coastguard Worker layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
510*38e8c45fSAndroid Build Coastguard Worker layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
511*38e8c45fSAndroid Build Coastguard Worker }
512*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
513*38e8c45fSAndroid Build Coastguard Worker layer.fixedTransformHint =
514*38e8c45fSAndroid Build Coastguard Worker static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
515*38e8c45fSAndroid Build Coastguard Worker }
516*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eAutoRefreshChanged) {
517*38e8c45fSAndroid Build Coastguard Worker layer.autoRefresh = proto.auto_refresh();
518*38e8c45fSAndroid Build Coastguard Worker }
519*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
520*38e8c45fSAndroid Build Coastguard Worker layer.trustedOverlay = proto.is_trusted_overlay() ? gui::TrustedOverlay::ENABLED
521*38e8c45fSAndroid Build Coastguard Worker : gui::TrustedOverlay::UNSET;
522*38e8c45fSAndroid Build Coastguard Worker }
523*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eBufferCropChanged) {
524*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
525*38e8c45fSAndroid Build Coastguard Worker }
526*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eDestinationFrameChanged) {
527*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
528*38e8c45fSAndroid Build Coastguard Worker }
529*38e8c45fSAndroid Build Coastguard Worker if (proto.what() & layer_state_t::eDropInputModeChanged) {
530*38e8c45fSAndroid Build Coastguard Worker layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
531*38e8c45fSAndroid Build Coastguard Worker }
532*38e8c45fSAndroid Build Coastguard Worker }
533*38e8c45fSAndroid Build Coastguard Worker
fromProto(const perfetto::protos::DisplayState & proto)534*38e8c45fSAndroid Build Coastguard Worker DisplayState TransactionProtoParser::fromProto(const perfetto::protos::DisplayState& proto) {
535*38e8c45fSAndroid Build Coastguard Worker DisplayState display;
536*38e8c45fSAndroid Build Coastguard Worker display.what = proto.what();
537*38e8c45fSAndroid Build Coastguard Worker display.token = mMapper->getDisplayHandle(proto.id());
538*38e8c45fSAndroid Build Coastguard Worker
539*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eLayerStackChanged) {
540*38e8c45fSAndroid Build Coastguard Worker display.layerStack.id = proto.layer_stack();
541*38e8c45fSAndroid Build Coastguard Worker }
542*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eDisplayProjectionChanged) {
543*38e8c45fSAndroid Build Coastguard Worker display.orientation = static_cast<ui::Rotation>(proto.orientation());
544*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
545*38e8c45fSAndroid Build Coastguard Worker display.orientedDisplaySpaceRect);
546*38e8c45fSAndroid Build Coastguard Worker LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
547*38e8c45fSAndroid Build Coastguard Worker display.layerStackSpaceRect);
548*38e8c45fSAndroid Build Coastguard Worker }
549*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eDisplaySizeChanged) {
550*38e8c45fSAndroid Build Coastguard Worker display.width = proto.width();
551*38e8c45fSAndroid Build Coastguard Worker display.height = proto.height();
552*38e8c45fSAndroid Build Coastguard Worker }
553*38e8c45fSAndroid Build Coastguard Worker if (display.what & DisplayState::eFlagsChanged) {
554*38e8c45fSAndroid Build Coastguard Worker display.flags = proto.flags();
555*38e8c45fSAndroid Build Coastguard Worker }
556*38e8c45fSAndroid Build Coastguard Worker return display;
557*38e8c45fSAndroid Build Coastguard Worker }
558*38e8c45fSAndroid Build Coastguard Worker
asProto(perfetto::protos::Transform * proto,const ui::Transform & transform)559*38e8c45fSAndroid Build Coastguard Worker void asProto(perfetto::protos::Transform* proto, const ui::Transform& transform) {
560*38e8c45fSAndroid Build Coastguard Worker proto->set_dsdx(transform.dsdx());
561*38e8c45fSAndroid Build Coastguard Worker proto->set_dtdx(transform.dtdx());
562*38e8c45fSAndroid Build Coastguard Worker proto->set_dtdy(transform.dtdy());
563*38e8c45fSAndroid Build Coastguard Worker proto->set_dsdy(transform.dsdy());
564*38e8c45fSAndroid Build Coastguard Worker proto->set_tx(transform.tx());
565*38e8c45fSAndroid Build Coastguard Worker proto->set_ty(transform.ty());
566*38e8c45fSAndroid Build Coastguard Worker }
567*38e8c45fSAndroid Build Coastguard Worker
toProto(const frontend::DisplayInfo & displayInfo,uint32_t layerStack)568*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::DisplayInfo TransactionProtoParser::toProto(
569*38e8c45fSAndroid Build Coastguard Worker const frontend::DisplayInfo& displayInfo, uint32_t layerStack) {
570*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::DisplayInfo proto;
571*38e8c45fSAndroid Build Coastguard Worker proto.set_layer_stack(layerStack);
572*38e8c45fSAndroid Build Coastguard Worker proto.set_display_id(displayInfo.info.displayId.val());
573*38e8c45fSAndroid Build Coastguard Worker proto.set_logical_width(displayInfo.info.logicalWidth);
574*38e8c45fSAndroid Build Coastguard Worker proto.set_logical_height(displayInfo.info.logicalHeight);
575*38e8c45fSAndroid Build Coastguard Worker asProto(proto.mutable_transform_inverse(), displayInfo.info.transform);
576*38e8c45fSAndroid Build Coastguard Worker asProto(proto.mutable_transform(), displayInfo.transform);
577*38e8c45fSAndroid Build Coastguard Worker proto.set_receives_input(displayInfo.receivesInput);
578*38e8c45fSAndroid Build Coastguard Worker proto.set_is_secure(displayInfo.isSecure);
579*38e8c45fSAndroid Build Coastguard Worker proto.set_is_primary(displayInfo.isPrimary);
580*38e8c45fSAndroid Build Coastguard Worker proto.set_is_virtual(displayInfo.isVirtual);
581*38e8c45fSAndroid Build Coastguard Worker proto.set_rotation_flags((int)displayInfo.rotationFlags);
582*38e8c45fSAndroid Build Coastguard Worker proto.set_transform_hint((int)displayInfo.transformHint);
583*38e8c45fSAndroid Build Coastguard Worker return proto;
584*38e8c45fSAndroid Build Coastguard Worker }
585*38e8c45fSAndroid Build Coastguard Worker
fromProto2(ui::Transform & outTransform,const perfetto::protos::Transform & proto)586*38e8c45fSAndroid Build Coastguard Worker void fromProto2(ui::Transform& outTransform, const perfetto::protos::Transform& proto) {
587*38e8c45fSAndroid Build Coastguard Worker outTransform.set(proto.dsdx(), proto.dtdx(), proto.dtdy(), proto.dsdy());
588*38e8c45fSAndroid Build Coastguard Worker outTransform.set(proto.tx(), proto.ty());
589*38e8c45fSAndroid Build Coastguard Worker }
590*38e8c45fSAndroid Build Coastguard Worker
fromProto(const perfetto::protos::DisplayInfo & proto)591*38e8c45fSAndroid Build Coastguard Worker frontend::DisplayInfo TransactionProtoParser::fromProto(
592*38e8c45fSAndroid Build Coastguard Worker const perfetto::protos::DisplayInfo& proto) {
593*38e8c45fSAndroid Build Coastguard Worker frontend::DisplayInfo displayInfo;
594*38e8c45fSAndroid Build Coastguard Worker displayInfo.info.displayId = ui::LogicalDisplayId{proto.display_id()};
595*38e8c45fSAndroid Build Coastguard Worker displayInfo.info.logicalWidth = proto.logical_width();
596*38e8c45fSAndroid Build Coastguard Worker displayInfo.info.logicalHeight = proto.logical_height();
597*38e8c45fSAndroid Build Coastguard Worker fromProto2(displayInfo.info.transform, proto.transform_inverse());
598*38e8c45fSAndroid Build Coastguard Worker fromProto2(displayInfo.transform, proto.transform());
599*38e8c45fSAndroid Build Coastguard Worker displayInfo.receivesInput = proto.receives_input();
600*38e8c45fSAndroid Build Coastguard Worker displayInfo.isSecure = proto.is_secure();
601*38e8c45fSAndroid Build Coastguard Worker displayInfo.isPrimary = proto.is_primary();
602*38e8c45fSAndroid Build Coastguard Worker displayInfo.isVirtual = proto.is_virtual();
603*38e8c45fSAndroid Build Coastguard Worker displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags();
604*38e8c45fSAndroid Build Coastguard Worker displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint();
605*38e8c45fSAndroid Build Coastguard Worker return displayInfo;
606*38e8c45fSAndroid Build Coastguard Worker }
607*38e8c45fSAndroid Build Coastguard Worker
fromProto(const google::protobuf::RepeatedPtrField<perfetto::protos::DisplayInfo> & proto,frontend::DisplayInfos & outDisplayInfos)608*38e8c45fSAndroid Build Coastguard Worker void TransactionProtoParser::fromProto(
609*38e8c45fSAndroid Build Coastguard Worker const google::protobuf::RepeatedPtrField<perfetto::protos::DisplayInfo>& proto,
610*38e8c45fSAndroid Build Coastguard Worker frontend::DisplayInfos& outDisplayInfos) {
611*38e8c45fSAndroid Build Coastguard Worker outDisplayInfos.clear();
612*38e8c45fSAndroid Build Coastguard Worker for (const perfetto::protos::DisplayInfo& displayInfo : proto) {
613*38e8c45fSAndroid Build Coastguard Worker outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()),
614*38e8c45fSAndroid Build Coastguard Worker fromProto(displayInfo));
615*38e8c45fSAndroid Build Coastguard Worker }
616*38e8c45fSAndroid Build Coastguard Worker }
617*38e8c45fSAndroid Build Coastguard Worker
618*38e8c45fSAndroid Build Coastguard Worker } // namespace android::surfaceflinger
619