Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 1 | /* |
| 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 Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 20 | #include <binder/IPCThreadState.h> |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 21 | |
| 22 | #include <private/android_filesystem_config.h> |
| 23 | |
Alec Mouri | 924f950 | 2024-08-15 20:01:08 +0000 | [diff] [blame^] | 24 | #include <gui/AidlUtil.h> |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 25 | #include <gui/SchedulingPolicy.h> |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 26 | |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 27 | #include "Client.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 28 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 989c510 | 2022-10-28 06:08:35 +0000 | [diff] [blame] | 29 | #include "FrontEnd/LayerHandle.h" |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 30 | #include "Layer.h" |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 31 | #include "SurfaceFlinger.h" |
| 32 | |
| 33 | namespace android { |
| 34 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 35 | using gui::aidl_utils::binderStatusFromStatusT; |
| 36 | |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 37 | // --------------------------------------------------------------------------- |
| 38 | |
| 39 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
| 43 | Client::Client(const sp<SurfaceFlinger>& flinger) |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 44 | : mFlinger(flinger) |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 48 | status_t Client::initCheck() const { |
| 49 | return NO_ERROR; |
| 50 | } |
| 51 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 52 | binder::Status Client::createSurface(const std::string& name, int32_t flags, |
| 53 | const sp<IBinder>& parent, const gui::LayerMetadata& metadata, |
| 54 | gui::CreateSurfaceResult* outResult) { |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 55 | // We rely on createLayer to check permissions. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 56 | sp<IBinder> handle; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 57 | LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), name.c_str(), |
| 58 | static_cast<uint32_t>(flags), std::move(metadata)); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 59 | args.parentHandle = parent; |
| 60 | const status_t status = mFlinger->createLayer(args, *outResult); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 61 | return binderStatusFromStatusT(status); |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 62 | } |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 63 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 64 | binder::Status Client::clearLayerFrameStats(const sp<IBinder>& handle) { |
| 65 | status_t status; |
Vishnu Nair | 989c510 | 2022-10-28 06:08:35 +0000 | [diff] [blame] | 66 | sp<Layer> layer = LayerHandle::getLayer(handle); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 67 | if (layer == nullptr) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 68 | status = NAME_NOT_FOUND; |
| 69 | } else { |
| 70 | layer->clearFrameStats(); |
| 71 | status = NO_ERROR; |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 72 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 73 | return binderStatusFromStatusT(status); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 76 | binder::Status Client::getLayerFrameStats(const sp<IBinder>& handle, gui::FrameStats* outStats) { |
| 77 | status_t status; |
Vishnu Nair | 989c510 | 2022-10-28 06:08:35 +0000 | [diff] [blame] | 78 | sp<Layer> layer = LayerHandle::getLayer(handle); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 79 | if (layer == nullptr) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 80 | 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; |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 98 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 99 | return binderStatusFromStatusT(status); |
| 100 | } |
| 101 | |
| 102 | binder::Status Client::mirrorSurface(const sp<IBinder>& mirrorFromHandle, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 103 | gui::CreateSurfaceResult* outResult) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 104 | sp<IBinder> handle; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 105 | LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), "MirrorRoot", |
| 106 | 0 /* flags */, gui::LayerMetadata()); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 107 | status_t status = mFlinger->mirrorLayer(args, mirrorFromHandle, *outResult); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 108 | return binderStatusFromStatusT(status); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 111 | binder::Status Client::mirrorDisplay(int64_t displayId, gui::CreateSurfaceResult* outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 112 | sp<IBinder> handle; |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 113 | 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 Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 117 | status_t status = mFlinger->mirrorDisplay(*id, args, *outResult); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 118 | return binderStatusFromStatusT(status); |
| 119 | } |
| 120 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 121 | binder::Status Client::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 122 | return gui::getSchedulingPolicy(outPolicy); |
| 123 | } |
| 124 | |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 125 | // --------------------------------------------------------------------------- |
| 126 | }; // namespace android |