blob: abeb2a92eb485a9145c2b9013fdc245aaa6d78ce [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.
Huihong Luod3d8f8e2022-03-08 14:48:46 -080056 sp<IBinder> handle;
Ady Abrahamd11bade2022-08-01 16:18:03 -070057 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), name.c_str(),
58 static_cast<uint32_t>(flags), std::move(metadata));
Vishnu Naircb8be502022-10-12 19:03:23 +000059 args.parentHandle = parent;
60 const status_t status = mFlinger->createLayer(args, *outResult);
Huihong Luod3d8f8e2022-03-08 14:48:46 -080061 return binderStatusFromStatusT(status);
Mathias Agopiandb403e82012-06-18 16:47:56 -070062}
Mathias Agopianac9fa422013-02-11 16:40:36 -080063
Huihong Luod3d8f8e2022-03-08 14:48:46 -080064binder::Status Client::clearLayerFrameStats(const sp<IBinder>& handle) {
65 status_t status;
Vishnu Nair989c5102022-10-28 06:08:35 +000066 sp<Layer> layer = LayerHandle::getLayer(handle);
Peiyong Lin566a3b42018-01-09 18:22:43 -080067 if (layer == nullptr) {
Huihong Luod3d8f8e2022-03-08 14:48:46 -080068 status = NAME_NOT_FOUND;
69 } else {
70 layer->clearFrameStats();
71 status = NO_ERROR;
Svetoslavd85084b2014-03-20 10:28:31 -070072 }
Huihong Luod3d8f8e2022-03-08 14:48:46 -080073 return binderStatusFromStatusT(status);
Svetoslavd85084b2014-03-20 10:28:31 -070074}
75
Huihong Luod3d8f8e2022-03-08 14:48:46 -080076binder::Status Client::getLayerFrameStats(const sp<IBinder>& handle, gui::FrameStats* outStats) {
77 status_t status;
Vishnu Nair989c5102022-10-28 06:08:35 +000078 sp<Layer> layer = LayerHandle::getLayer(handle);
Peiyong Lin566a3b42018-01-09 18:22:43 -080079 if (layer == nullptr) {
Huihong Luod3d8f8e2022-03-08 14:48:46 -080080 status = NAME_NOT_FOUND;
81 } else {
82 FrameStats stats;
83 layer->getFrameStats(&stats);
84 outStats->refreshPeriodNano = stats.refreshPeriodNano;
85 outStats->desiredPresentTimesNano.reserve(stats.desiredPresentTimesNano.size());
86 for (const auto& t : stats.desiredPresentTimesNano) {
87 outStats->desiredPresentTimesNano.push_back(t);
88 }
89 outStats->actualPresentTimesNano.reserve(stats.actualPresentTimesNano.size());
90 for (const auto& t : stats.actualPresentTimesNano) {
91 outStats->actualPresentTimesNano.push_back(t);
92 }
93 outStats->frameReadyTimesNano.reserve(stats.frameReadyTimesNano.size());
94 for (const auto& t : stats.frameReadyTimesNano) {
95 outStats->frameReadyTimesNano.push_back(t);
96 }
97 status = NO_ERROR;
Svetoslavd85084b2014-03-20 10:28:31 -070098 }
Huihong Luod3d8f8e2022-03-08 14:48:46 -080099 return binderStatusFromStatusT(status);
100}
101
102binder::Status Client::mirrorSurface(const sp<IBinder>& mirrorFromHandle,
Patrick Williamsa361de62022-10-06 20:34:10 +0000103 gui::CreateSurfaceResult* outResult) {
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800104 sp<IBinder> handle;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700105 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), "MirrorRoot",
106 0 /* flags */, gui::LayerMetadata());
Patrick Williamsa361de62022-10-06 20:34:10 +0000107 status_t status = mFlinger->mirrorLayer(args, mirrorFromHandle, *outResult);
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800108 return binderStatusFromStatusT(status);
Svetoslavd85084b2014-03-20 10:28:31 -0700109}
110
Patrick Williamsa361de62022-10-06 20:34:10 +0000111binder::Status Client::mirrorDisplay(int64_t displayId, gui::CreateSurfaceResult* outResult) {
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000112 sp<IBinder> handle;
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000113 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this),
114 "MirrorRoot-" + std::to_string(displayId), 0 /* flags */,
115 gui::LayerMetadata());
116 std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId));
Patrick Williamsa361de62022-10-06 20:34:10 +0000117 status_t status = mFlinger->mirrorDisplay(*id, args, *outResult);
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000118 return binderStatusFromStatusT(status);
119}
120
Ady Abraham07d03c42023-09-27 19:15:08 -0700121binder::Status Client::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) {
122 return gui::getSchedulingPolicy(outPolicy);
123}
124
Mathias Agopiandb403e82012-06-18 16:47:56 -0700125// ---------------------------------------------------------------------------
126}; // namespace android