blob: 6d7b732b366f6fe479e7fbc5e871ac59d252bd5b [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
24#include "Client.h"
Mathias Agopian921e6ac2012-07-23 23:11:29 -070025#include "Layer.h"
Mathias Agopiandb403e82012-06-18 16:47:56 -070026#include "SurfaceFlinger.h"
27
28namespace android {
29
30// ---------------------------------------------------------------------------
31
32const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
33
34// ---------------------------------------------------------------------------
35
36Client::Client(const sp<SurfaceFlinger>& flinger)
Robert Carrb89ea9d2018-12-10 13:01:14 -080037 : mFlinger(flinger)
Mathias Agopiandb403e82012-06-18 16:47:56 -070038{
39}
40
Mathias Agopiandb403e82012-06-18 16:47:56 -070041status_t Client::initCheck() const {
42 return NO_ERROR;
43}
44
Mathias Agopian13127d82013-03-05 17:47:11 -080045void Client::attachLayer(const sp<IBinder>& handle, const sp<Layer>& layer)
Mathias Agopiandb403e82012-06-18 16:47:56 -070046{
47 Mutex::Autolock _l(mLock);
Mathias Agopianac9fa422013-02-11 16:40:36 -080048 mLayers.add(handle, layer);
Mathias Agopiandb403e82012-06-18 16:47:56 -070049}
50
Mathias Agopian13127d82013-03-05 17:47:11 -080051void Client::detachLayer(const Layer* layer)
Mathias Agopiandb403e82012-06-18 16:47:56 -070052{
53 Mutex::Autolock _l(mLock);
54 // we do a linear search here, because this doesn't happen often
55 const size_t count = mLayers.size();
56 for (size_t i=0 ; i<count ; i++) {
57 if (mLayers.valueAt(i) == layer) {
58 mLayers.removeItemsAt(i, 1);
59 break;
60 }
61 }
62}
Mathias Agopian13127d82013-03-05 17:47:11 -080063sp<Layer> Client::getLayerUser(const sp<IBinder>& handle) const
Mathias Agopiandb403e82012-06-18 16:47:56 -070064{
65 Mutex::Autolock _l(mLock);
Mathias Agopian13127d82013-03-05 17:47:11 -080066 sp<Layer> lbc;
67 wp<Layer> layer(mLayers.valueFor(handle));
Mathias Agopiandb403e82012-06-18 16:47:56 -070068 if (layer != 0) {
69 lbc = layer.promote();
Mathias Agopianac9fa422013-02-11 16:40:36 -080070 ALOGE_IF(lbc==0, "getLayerUser(name=%p) is dead", handle.get());
Mathias Agopiandb403e82012-06-18 16:47:56 -070071 }
72 return lbc;
73}
74
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -080075status_t Client::createSurface(const String8& name, uint32_t /* w */, uint32_t /* h */,
76 PixelFormat /* format */, uint32_t flags,
77 const sp<IBinder>& parentHandle, LayerMetadata metadata,
78 sp<IBinder>* outHandle, sp<IGraphicBufferProducer>* /* gbp */,
79 int32_t* outLayerId, uint32_t* outTransformHint) {
Robert Carrb89ea9d2018-12-10 13:01:14 -080080 // We rely on createLayer to check permissions.
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -080081 LayerCreationArgs args(mFlinger.get(), this, name.c_str(), flags, std::move(metadata));
82 return mFlinger->createLayer(args, outHandle, parentHandle, outLayerId, nullptr,
83 outTransformHint);
Mathias Agopiandb403e82012-06-18 16:47:56 -070084}
Mathias Agopianac9fa422013-02-11 16:40:36 -080085
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -080086status_t Client::createWithSurfaceParent(const String8& /* name */, uint32_t /* w */,
87 uint32_t /* h */, PixelFormat /* format */,
88 uint32_t /* flags */,
89 const sp<IGraphicBufferProducer>& /* parent */,
90 LayerMetadata /* metadata */, sp<IBinder>* /* handle */,
91 sp<IGraphicBufferProducer>* /* gbp */,
92 int32_t* /* outLayerId */,
93 uint32_t* /* outTransformHint */) {
94 // This api does not make sense with blast since SF no longer tracks IGBP. This api should be
95 // removed.
96 return BAD_VALUE;
Marissa Wall35187b32019-01-08 10:08:52 -080097}
98
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +000099status_t Client::mirrorSurface(const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle,
Ady Abraham9f0a4002020-10-05 15:47:26 -0700100 int32_t* outLayerId) {
Vishnu Nair84125ac2021-12-02 08:47:48 -0800101 LayerCreationArgs args(mFlinger.get(), this, "MirrorRoot", 0 /* flags */, LayerMetadata());
102 return mFlinger->mirrorLayer(args, mirrorFromHandle, outHandle, outLayerId);
chaviwfe94a222019-08-21 13:52:59 -0700103}
104
Svetoslavd85084b2014-03-20 10:28:31 -0700105status_t Client::clearLayerFrameStats(const sp<IBinder>& handle) const {
106 sp<Layer> layer = getLayerUser(handle);
Peiyong Lin566a3b42018-01-09 18:22:43 -0800107 if (layer == nullptr) {
Svetoslavd85084b2014-03-20 10:28:31 -0700108 return NAME_NOT_FOUND;
109 }
110 layer->clearFrameStats();
111 return NO_ERROR;
112}
113
114status_t Client::getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
115 sp<Layer> layer = getLayerUser(handle);
Peiyong Lin566a3b42018-01-09 18:22:43 -0800116 if (layer == nullptr) {
Svetoslavd85084b2014-03-20 10:28:31 -0700117 return NAME_NOT_FOUND;
118 }
119 layer->getFrameStats(outStats);
120 return NO_ERROR;
121}
122
Mathias Agopiandb403e82012-06-18 16:47:56 -0700123// ---------------------------------------------------------------------------
124}; // namespace android