blob: 6088e255df8dc605bcd305d41ca427020133a967 [file] [log] [blame]
Mathias Agopiandb403e82012-06-18 16:47:56 -07001/*
2 * Copyright (C) 2012 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 <stdint.h>
18#include <sys/types.h>
19
Mathias Agopian4f4f0942013-08-19 17:26:18 -070020#include <binder/IPCThreadState.h>
Mathias Agopiandb403e82012-06-18 16:47:56 -070021
22#include <private/android_filesystem_config.h>
23
Alec Mouri924f9502024-08-15 20:01:08 +000024#include <gui/AidlUtil.h>
Ady Abraham07d03c42023-09-27 19:15:08 -070025#include <gui/SchedulingPolicy.h>
Huihong Luod3d8f8e2022-03-08 14:48:46 -080026
Mathias Agopiandb403e82012-06-18 16:47:56 -070027#include "Client.h"
Vishnu Naircb8be502022-10-12 19:03:23 +000028#include "FrontEnd/LayerCreationArgs.h"
Vishnu Nair989c5102022-10-28 06:08:35 +000029#include "FrontEnd/LayerHandle.h"
Mathias Agopian921e6ac2012-07-23 23:11:29 -070030#include "Layer.h"
Mathias Agopiandb403e82012-06-18 16:47:56 -070031#include "SurfaceFlinger.h"
32
33namespace android {
34
Huihong Luod3d8f8e2022-03-08 14:48:46 -080035using gui::aidl_utils::binderStatusFromStatusT;
36
Mathias Agopiandb403e82012-06-18 16:47:56 -070037// ---------------------------------------------------------------------------
38
39const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
40
41// ---------------------------------------------------------------------------
42
43Client::Client(const sp<SurfaceFlinger>& flinger)
Robert Carrb89ea9d2018-12-10 13:01:14 -080044 : mFlinger(flinger)
Mathias Agopiandb403e82012-06-18 16:47:56 -070045{
46}
47
Mathias Agopiandb403e82012-06-18 16:47:56 -070048status_t Client::initCheck() const {
49 return NO_ERROR;
50}
51
Huihong Luod3d8f8e2022-03-08 14:48:46 -080052binder::Status Client::createSurface(const std::string& name, int32_t flags,
53 const sp<IBinder>& parent, const gui::LayerMetadata& metadata,
54 gui::CreateSurfaceResult* outResult) {
Robert Carrb89ea9d2018-12-10 13:01:14 -080055 // We rely on createLayer to check permissions.
Ady Abrahamd11bade2022-08-01 16:18:03 -070056 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), name.c_str(),
57 static_cast<uint32_t>(flags), std::move(metadata));
Vishnu Naircb8be502022-10-12 19:03:23 +000058 args.parentHandle = parent;
59 const status_t status = mFlinger->createLayer(args, *outResult);
Huihong Luod3d8f8e2022-03-08 14:48:46 -080060 return binderStatusFromStatusT(status);
Mathias Agopiandb403e82012-06-18 16:47:56 -070061}
Mathias Agopianac9fa422013-02-11 16:40:36 -080062
Huihong Luod3d8f8e2022-03-08 14:48:46 -080063binder::Status Client::clearLayerFrameStats(const sp<IBinder>& handle) {
64 status_t status;
Vishnu Nair989c5102022-10-28 06:08:35 +000065 sp<Layer> layer = LayerHandle::getLayer(handle);
Peiyong Lin566a3b42018-01-09 18:22:43 -080066 if (layer == nullptr) {
Huihong Luod3d8f8e2022-03-08 14:48:46 -080067 status = NAME_NOT_FOUND;
68 } else {
69 layer->clearFrameStats();
70 status = NO_ERROR;
Svetoslavd85084b2014-03-20 10:28:31 -070071 }
Huihong Luod3d8f8e2022-03-08 14:48:46 -080072 return binderStatusFromStatusT(status);
Svetoslavd85084b2014-03-20 10:28:31 -070073}
74
Huihong Luod3d8f8e2022-03-08 14:48:46 -080075binder::Status Client::getLayerFrameStats(const sp<IBinder>& handle, gui::FrameStats* outStats) {
76 status_t status;
Vishnu Nair989c5102022-10-28 06:08:35 +000077 sp<Layer> layer = LayerHandle::getLayer(handle);
Peiyong Lin566a3b42018-01-09 18:22:43 -080078 if (layer == nullptr) {
Huihong Luod3d8f8e2022-03-08 14:48:46 -080079 status = NAME_NOT_FOUND;
80 } else {
81 FrameStats stats;
82 layer->getFrameStats(&stats);
83 outStats->refreshPeriodNano = stats.refreshPeriodNano;
84 outStats->desiredPresentTimesNano.reserve(stats.desiredPresentTimesNano.size());
85 for (const auto& t : stats.desiredPresentTimesNano) {
86 outStats->desiredPresentTimesNano.push_back(t);
87 }
88 outStats->actualPresentTimesNano.reserve(stats.actualPresentTimesNano.size());
89 for (const auto& t : stats.actualPresentTimesNano) {
90 outStats->actualPresentTimesNano.push_back(t);
91 }
92 outStats->frameReadyTimesNano.reserve(stats.frameReadyTimesNano.size());
93 for (const auto& t : stats.frameReadyTimesNano) {
94 outStats->frameReadyTimesNano.push_back(t);
95 }
96 status = NO_ERROR;
Svetoslavd85084b2014-03-20 10:28:31 -070097 }
Huihong Luod3d8f8e2022-03-08 14:48:46 -080098 return binderStatusFromStatusT(status);
99}
100
101binder::Status Client::mirrorSurface(const sp<IBinder>& mirrorFromHandle,
Patrick Williamsa361de62022-10-06 20:34:10 +0000102 gui::CreateSurfaceResult* outResult) {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700103 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), "MirrorRoot",
104 0 /* flags */, gui::LayerMetadata());
Patrick Williamsa361de62022-10-06 20:34:10 +0000105 status_t status = mFlinger->mirrorLayer(args, mirrorFromHandle, *outResult);
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800106 return binderStatusFromStatusT(status);
Svetoslavd85084b2014-03-20 10:28:31 -0700107}
108
Patrick Williamsa361de62022-10-06 20:34:10 +0000109binder::Status Client::mirrorDisplay(int64_t displayId, gui::CreateSurfaceResult* outResult) {
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000110 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this),
111 "MirrorRoot-" + std::to_string(displayId), 0 /* flags */,
112 gui::LayerMetadata());
Gil Dekelbddaa242025-01-29 17:31:34 -0500113 const DisplayId id = DisplayId::fromValue(static_cast<uint64_t>(displayId));
114 status_t status = mFlinger->mirrorDisplay(id, args, *outResult);
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000115 return binderStatusFromStatusT(status);
116}
117
Ady Abraham07d03c42023-09-27 19:15:08 -0700118binder::Status Client::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) {
119 return gui::getSchedulingPolicy(outPolicy);
120}
121
Mathias Agopiandb403e82012-06-18 16:47:56 -0700122// ---------------------------------------------------------------------------
123}; // namespace android