blob: bdbc79b8e1728a9182e6abff5dc784e8cadc71a9 [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
Huihong Luod3d8f8e2022-03-08 14:48:46 -080024#include <gui/AidlStatusUtil.h>
25
Mathias Agopiandb403e82012-06-18 16:47:56 -070026#include "Client.h"
Vishnu Naircb8be502022-10-12 19:03:23 +000027#include "FrontEnd/LayerCreationArgs.h"
Vishnu Nair989c5102022-10-28 06:08:35 +000028#include "FrontEnd/LayerHandle.h"
Mathias Agopian921e6ac2012-07-23 23:11:29 -070029#include "Layer.h"
Mathias Agopiandb403e82012-06-18 16:47:56 -070030#include "SurfaceFlinger.h"
31
32namespace android {
33
Huihong Luod3d8f8e2022-03-08 14:48:46 -080034using gui::aidl_utils::binderStatusFromStatusT;
35
Mathias Agopiandb403e82012-06-18 16:47:56 -070036// ---------------------------------------------------------------------------
37
38const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
39
40// ---------------------------------------------------------------------------
41
42Client::Client(const sp<SurfaceFlinger>& flinger)
Robert Carrb89ea9d2018-12-10 13:01:14 -080043 : mFlinger(flinger)
Mathias Agopiandb403e82012-06-18 16:47:56 -070044{
45}
46
Mathias Agopiandb403e82012-06-18 16:47:56 -070047status_t Client::initCheck() const {
48 return NO_ERROR;
49}
50
Huihong Luod3d8f8e2022-03-08 14:48:46 -080051binder::Status Client::createSurface(const std::string& name, int32_t flags,
52 const sp<IBinder>& parent, const gui::LayerMetadata& metadata,
53 gui::CreateSurfaceResult* outResult) {
Robert Carrb89ea9d2018-12-10 13:01:14 -080054 // We rely on createLayer to check permissions.
Huihong Luod3d8f8e2022-03-08 14:48:46 -080055 sp<IBinder> handle;
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) {
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800103 sp<IBinder> handle;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700104 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), "MirrorRoot",
105 0 /* flags */, gui::LayerMetadata());
Patrick Williamsa361de62022-10-06 20:34:10 +0000106 status_t status = mFlinger->mirrorLayer(args, mirrorFromHandle, *outResult);
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800107 return binderStatusFromStatusT(status);
Svetoslavd85084b2014-03-20 10:28:31 -0700108}
109
Patrick Williamsa361de62022-10-06 20:34:10 +0000110binder::Status Client::mirrorDisplay(int64_t displayId, gui::CreateSurfaceResult* outResult) {
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000111 sp<IBinder> handle;
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000112 LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this),
113 "MirrorRoot-" + std::to_string(displayId), 0 /* flags */,
114 gui::LayerMetadata());
115 std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId));
Patrick Williamsa361de62022-10-06 20:34:10 +0000116 status_t status = mFlinger->mirrorDisplay(*id, args, *outResult);
Chavi Weingarten7043a7d2022-07-19 23:40:35 +0000117 return binderStatusFromStatusT(status);
118}
119
Mathias Agopiandb403e82012-06-18 16:47:56 -0700120// ---------------------------------------------------------------------------
121}; // namespace android