blob: fd277f1beb2678f990287e97cd604a5b32bd1caf [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiand4784a32010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian9cce3252010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Michael Wright28f24d02016-07-12 13:30:53 -070032#include <system/graphics.h>
33
Mathias Agopian076b1cc2009-04-10 14:24:30 -070034#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
Robert Carr673134e2017-01-09 19:48:38 -080036#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070037#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080038#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080039#include <gui/ISurfaceComposer.h>
40#include <gui/ISurfaceComposerClient.h>
Robert Carr0d480722017-01-10 16:42:54 -080041#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080042#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Mathias Agopian41f673c2011-11-17 17:48:35 -080044#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080045#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046
47namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048// ---------------------------------------------------------------------------
49
Mathias Agopian7e27f052010-05-28 14:22:23 -070050ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
51
Mathias Agopianb7e930d2010-06-01 15:12:58 -070052ComposerService::ComposerService()
53: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070054 Mutex::Autolock _l(mLock);
55 connectLocked();
56}
57
58void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070059 const String16 name("SurfaceFlinger");
60 while (getService(name, &mComposerService) != NO_ERROR) {
61 usleep(250000);
62 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070063 assert(mComposerService != NULL);
64
65 // Create the death listener.
66 class DeathObserver : public IBinder::DeathRecipient {
67 ComposerService& mComposerService;
68 virtual void binderDied(const wp<IBinder>& who) {
69 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
70 who.unsafe_get());
71 mComposerService.composerServiceDied();
72 }
73 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070074 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070075 };
76
77 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080078 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070079}
80
Andy McFadden6652b3e2012-09-06 18:45:56 -070081/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
82 ComposerService& instance = ComposerService::getInstance();
83 Mutex::Autolock _l(instance.mLock);
84 if (instance.mComposerService == NULL) {
85 ComposerService::getInstance().connectLocked();
86 assert(instance.mComposerService != NULL);
87 ALOGD("ComposerService reconnected");
88 }
89 return instance.mComposerService;
90}
91
92void ComposerService::composerServiceDied()
93{
94 Mutex::Autolock _l(mLock);
95 mComposerService = NULL;
96 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070097}
98
Mathias Agopian7e27f052010-05-28 14:22:23 -070099// ---------------------------------------------------------------------------
100
Mathias Agopian698c0872011-06-28 19:09:31 -0700101static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700102int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700103 if (lhs.client < rhs.client) return -1;
104 if (lhs.client > rhs.client) return 1;
105 if (lhs.state.surface < rhs.state.surface) return -1;
106 if (lhs.state.surface > rhs.state.surface) return 1;
107 return 0;
108}
109
Mathias Agopiane57f2922012-08-09 16:29:12 -0700110static inline
111int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
112 return compare_type(lhs.token, rhs.token);
113}
114
Mathias Agopian7e27f052010-05-28 14:22:23 -0700115class Composer : public Singleton<Composer>
116{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700117 friend class Singleton<Composer>;
118
Mathias Agopian698c0872011-06-28 19:09:31 -0700119 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700120 SortedVector<ComposerState> mComposerStates;
121 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700122 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700123 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700124 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700125
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700126 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700127 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700128 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700129 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700130
Jeff Brownf3f7db62012-08-31 02:18:38 -0700131 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700132 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700133 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700134 status_t enableVSyncInjectionsImpl(bool enable);
135 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-28 19:09:31 -0700136
137 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800138 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700139
Mathias Agopiane57f2922012-08-09 16:29:12 -0700140 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
141
Mathias Agopiand4784a32010-05-27 19:41:15 -0700142public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700143 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700144 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700145 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700146
Mathias Agopianac9fa422013-02-11 16:40:36 -0800147 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700148 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800149 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700150 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800151 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Robert Carrae060832016-11-28 10:51:00 -0800152 int32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800153 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700154 uint32_t flags, uint32_t mask);
155 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800156 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700157 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800158 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700159 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800160 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700161 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700162 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800163 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700164 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000165 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
166 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700167 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800168 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700169 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
170 const sp<IBinder>& id, const sp<IBinder>& handle,
171 uint64_t frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800172 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
173 const sp<IBinder>& id, const sp<Surface>& barrierSurface,
174 uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800175 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
176 const sp<IBinder>& id,
177 const sp<IBinder>& newParentHandle);
Robert Carrc3574f72016-03-24 12:19:32 -0700178 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
179 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700180 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700181 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700182
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700183 status_t setDisplaySurface(const sp<IBinder>& token,
184 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700185 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700186 void setDisplayProjection(const sp<IBinder>& token,
187 uint32_t orientation,
188 const Rect& layerStackRect,
189 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700190 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700191
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700192 static void setAnimationTransaction() {
193 Composer::getInstance().setAnimationTransactionImpl();
194 }
195
Jeff Brownf3f7db62012-08-31 02:18:38 -0700196 static void openGlobalTransaction() {
197 Composer::getInstance().openGlobalTransactionImpl();
198 }
199
Jamie Gennis28378392011-10-12 17:39:00 -0700200 static void closeGlobalTransaction(bool synchronous) {
201 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700202 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700203
204 static status_t enableVSyncInjections(bool enable) {
205 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
206 }
207
208 static status_t injectVSync(nsecs_t when) {
209 return Composer::getInstance().injectVSyncImpl(when);
210 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700211};
212
213ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
214
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215// ---------------------------------------------------------------------------
216
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700217sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
218 return ComposerService::getComposerService()->createDisplay(displayName,
219 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700220}
221
Jesse Hall6c913be2013-08-08 12:15:49 -0700222void Composer::destroyDisplay(const sp<IBinder>& display) {
223 return ComposerService::getComposerService()->destroyDisplay(display);
224}
225
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700226sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
227 return ComposerService::getComposerService()->getBuiltInDisplay(id);
228}
229
Jeff Brownf3f7db62012-08-31 02:18:38 -0700230void Composer::openGlobalTransactionImpl() {
231 { // scope for the lock
232 Mutex::Autolock _l(mLock);
233 mTransactionNestCount += 1;
234 }
235}
236
Jamie Gennis28378392011-10-12 17:39:00 -0700237void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700238 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700239
240 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700241 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700242 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700243
244 { // scope for the lock
245 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700246 mForceSynchronous |= synchronous;
247 if (!mTransactionNestCount) {
248 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
249 "call to openGlobalTransaction().");
250 } else if (--mTransactionNestCount) {
251 return;
252 }
253
Mathias Agopiane57f2922012-08-09 16:29:12 -0700254 transaction = mComposerStates;
255 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700256
Mathias Agopiane57f2922012-08-09 16:29:12 -0700257 displayTransaction = mDisplayStates;
258 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700259
Jeff Brownf3f7db62012-08-31 02:18:38 -0700260 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700261 flags |= ISurfaceComposer::eSynchronous;
262 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700263 if (mAnimation) {
264 flags |= ISurfaceComposer::eAnimation;
265 }
266
Jamie Gennis28378392011-10-12 17:39:00 -0700267 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700268 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700269 }
270
Mathias Agopian8b33f032012-07-24 20:43:54 -0700271 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272}
273
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700274status_t Composer::enableVSyncInjectionsImpl(bool enable) {
275 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
276 return sm->enableVSyncInjections(enable);
277}
278
279status_t Composer::injectVSyncImpl(nsecs_t when) {
280 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
281 return sm->injectVSync(when);
282}
283
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700284void Composer::setAnimationTransactionImpl() {
285 Mutex::Autolock _l(mLock);
286 mAnimation = true;
287}
288
Mathias Agopian698c0872011-06-28 19:09:31 -0700289layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800290 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700291
292 ComposerState s;
293 s.client = client->mClient;
294 s.state.surface = id;
295
Mathias Agopiane57f2922012-08-09 16:29:12 -0700296 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700297 if (index < 0) {
298 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700299 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700300 }
301
Mathias Agopiane57f2922012-08-09 16:29:12 -0700302 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700303 return &(out[index].state);
304}
305
306status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800307 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700308 Mutex::Autolock _l(mLock);
309 layer_state_t* s = getLayerStateLocked(client, id);
310 if (!s)
311 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700312 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700313 s->x = x;
314 s->y = y;
315 return NO_ERROR;
316}
317
318status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800319 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700320 Mutex::Autolock _l(mLock);
321 layer_state_t* s = getLayerStateLocked(client, id);
322 if (!s)
323 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700324 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700325 s->w = w;
326 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700327
Jorim Jaggi092123c2016-04-13 01:40:35 +0000328 // Resizing a surface makes the transaction synchronous.
329 mForceSynchronous = true;
330
Mathias Agopian698c0872011-06-28 19:09:31 -0700331 return NO_ERROR;
332}
333
334status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800335 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700336 Mutex::Autolock _l(mLock);
337 layer_state_t* s = getLayerStateLocked(client, id);
338 if (!s)
339 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700340 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700341 s->z = z;
342 return NO_ERROR;
343}
344
345status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800346 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700347 uint32_t mask) {
348 Mutex::Autolock _l(mLock);
349 layer_state_t* s = getLayerStateLocked(client, id);
350 if (!s)
351 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700352 if ((mask & layer_state_t::eLayerOpaque) ||
353 (mask & layer_state_t::eLayerHidden) ||
354 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700355 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800356 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700357 s->flags &= ~mask;
358 s->flags |= (flags & mask);
359 s->mask |= mask;
360 return NO_ERROR;
361}
362
363status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800364 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700365 const Region& transparentRegion) {
366 Mutex::Autolock _l(mLock);
367 layer_state_t* s = getLayerStateLocked(client, id);
368 if (!s)
369 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700370 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700371 s->transparentRegion = transparentRegion;
372 return NO_ERROR;
373}
374
375status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800376 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700377 Mutex::Autolock _l(mLock);
378 layer_state_t* s = getLayerStateLocked(client, id);
379 if (!s)
380 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700381 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700382 s->alpha = alpha;
383 return NO_ERROR;
384}
385
Mathias Agopian87855782012-07-24 21:41:09 -0700386status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800387 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700388 Mutex::Autolock _l(mLock);
389 layer_state_t* s = getLayerStateLocked(client, id);
390 if (!s)
391 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700392 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700393 s->layerStack = layerStack;
394 return NO_ERROR;
395}
396
Mathias Agopian698c0872011-06-28 19:09:31 -0700397status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800398 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700399 float dsdy, float dtdy) {
400 Mutex::Autolock _l(mLock);
401 layer_state_t* s = getLayerStateLocked(client, id);
402 if (!s)
403 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700404 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700405 layer_state_t::matrix22_t matrix;
406 matrix.dsdx = dsdx;
407 matrix.dtdx = dtdx;
408 matrix.dsdy = dsdy;
409 matrix.dtdy = dtdy;
410 s->matrix = matrix;
411 return NO_ERROR;
412}
413
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700414status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800415 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700416 Mutex::Autolock _l(mLock);
417 layer_state_t* s = getLayerStateLocked(client, id);
418 if (!s)
419 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700420 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700421 s->crop = crop;
422 return NO_ERROR;
423}
424
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000425status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
426 const sp<IBinder>& id, const Rect& crop) {
427 Mutex::Autolock _l(mLock);
428 layer_state_t* s = getLayerStateLocked(client, id);
429 if (!s) {
430 return BAD_INDEX;
431 }
432 s->what |= layer_state_t::eFinalCropChanged;
433 s->finalCrop = crop;
434 return NO_ERROR;
435}
436
Dan Stoza7dde5992015-05-22 09:51:44 -0700437status_t Composer::deferTransactionUntil(
438 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
439 const sp<IBinder>& handle, uint64_t frameNumber) {
440 Mutex::Autolock lock(mLock);
441 layer_state_t* s = getLayerStateLocked(client, id);
442 if (!s) {
443 return BAD_INDEX;
444 }
445 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-10 16:42:54 -0800446 s->barrierHandle = handle;
447 s->frameNumber = frameNumber;
448 return NO_ERROR;
449}
450
451status_t Composer::deferTransactionUntil(
452 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
453 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
454 Mutex::Autolock lock(mLock);
455 layer_state_t* s = getLayerStateLocked(client, id);
456 if (!s) {
457 return BAD_INDEX;
458 }
459 s->what |= layer_state_t::eDeferTransaction;
460 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 09:51:44 -0700461 s->frameNumber = frameNumber;
462 return NO_ERROR;
463}
464
Robert Carr1db73f62016-12-21 12:58:51 -0800465status_t Composer::reparentChildren(
466 const sp<SurfaceComposerClient>& client,
467 const sp<IBinder>& id,
468 const sp<IBinder>& newParentHandle) {
469 Mutex::Autolock lock(mLock);
470 layer_state_t* s = getLayerStateLocked(client, id);
471 if (!s) {
472 return BAD_INDEX;
473 }
474 s->what |= layer_state_t::eReparentChildren;
475 s->reparentHandle = newParentHandle;
476 return NO_ERROR;
477}
478
Robert Carrc3574f72016-03-24 12:19:32 -0700479status_t Composer::setOverrideScalingMode(
480 const sp<SurfaceComposerClient>& client,
481 const sp<IBinder>& id, int32_t overrideScalingMode) {
482 Mutex::Autolock lock(mLock);
483 layer_state_t* s = getLayerStateLocked(client, id);
484 if (!s) {
485 return BAD_INDEX;
486 }
487
488 switch (overrideScalingMode) {
489 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
490 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
491 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
492 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
493 case -1:
494 break;
495 default:
496 ALOGE("unknown scaling mode: %d",
497 overrideScalingMode);
498 return BAD_VALUE;
499 }
500
501 s->what |= layer_state_t::eOverrideScalingModeChanged;
502 s->overrideScalingMode = overrideScalingMode;
503 return NO_ERROR;
504}
505
Robert Carr99e27f02016-06-16 15:18:02 -0700506status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700507 const sp<SurfaceComposerClient>& client,
508 const sp<IBinder>& id) {
509 Mutex::Autolock lock(mLock);
510 layer_state_t* s = getLayerStateLocked(client, id);
511 if (!s) {
512 return BAD_INDEX;
513 }
Robert Carr99e27f02016-06-16 15:18:02 -0700514 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700515 return NO_ERROR;
516}
517
Mathias Agopian698c0872011-06-28 19:09:31 -0700518// ---------------------------------------------------------------------------
519
Mathias Agopiane57f2922012-08-09 16:29:12 -0700520DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
521 DisplayState s;
522 s.token = token;
523 ssize_t index = mDisplayStates.indexOf(s);
524 if (index < 0) {
525 // we don't have it, add an initialized layer_state to our list
526 s.what = 0;
527 index = mDisplayStates.add(s);
528 }
Dan Stozad723bd72014-11-18 10:24:03 -0800529 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700530}
531
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700532status_t Composer::setDisplaySurface(const sp<IBinder>& token,
533 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700534 if (bufferProducer.get() != nullptr) {
535 // Make sure that composition can never be stalled by a virtual display
536 // consumer that isn't processing buffers fast enough.
537 status_t err = bufferProducer->setAsyncMode(true);
538 if (err != NO_ERROR) {
539 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
540 "BufferQueue. This BufferQueue cannot be used for virtual "
541 "display. (%d)", err);
542 return err;
543 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700544 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700545 Mutex::Autolock _l(mLock);
546 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800547 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700548 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700549 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700550}
551
552void Composer::setDisplayLayerStack(const sp<IBinder>& token,
553 uint32_t layerStack) {
554 Mutex::Autolock _l(mLock);
555 DisplayState& s(getDisplayStateLocked(token));
556 s.layerStack = layerStack;
557 s.what |= DisplayState::eLayerStackChanged;
558}
559
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700560void Composer::setDisplayProjection(const sp<IBinder>& token,
561 uint32_t orientation,
562 const Rect& layerStackRect,
563 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700564 Mutex::Autolock _l(mLock);
565 DisplayState& s(getDisplayStateLocked(token));
566 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700567 s.viewport = layerStackRect;
568 s.frame = displayRect;
569 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000570 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700571}
572
Michael Wright1f6078a2014-06-26 16:01:02 -0700573void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
574 Mutex::Autolock _l(mLock);
575 DisplayState& s(getDisplayStateLocked(token));
576 s.width = width;
577 s.height = height;
578 s.what |= DisplayState::eDisplaySizeChanged;
579}
580
Mathias Agopiane57f2922012-08-09 16:29:12 -0700581// ---------------------------------------------------------------------------
582
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800583SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700584 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800585{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800586}
587
Robert Carr1db73f62016-12-21 12:58:51 -0800588SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
589 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
590{
591}
592
Mathias Agopian698c0872011-06-28 19:09:31 -0700593void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700594 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700595 if (sm != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800596 auto rootProducer = mParent.promote();
597 sp<ISurfaceComposerClient> conn;
598 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
599 sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700600 if (conn != 0) {
601 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700602 mStatus = NO_ERROR;
603 }
604 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800605}
606
Mathias Agopian698c0872011-06-28 19:09:31 -0700607SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700608 dispose();
609}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700610
Mathias Agopian698c0872011-06-28 19:09:31 -0700611status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800612 return mStatus;
613}
614
Mathias Agopian698c0872011-06-28 19:09:31 -0700615sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800616 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800617}
618
Mathias Agopiand4784a32010-05-27 19:41:15 -0700619status_t SurfaceComposerClient::linkToComposerDeath(
620 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700621 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700622 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800623 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800624}
625
Mathias Agopian698c0872011-06-28 19:09:31 -0700626void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800627 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700628 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700629 Mutex::Autolock _lm(mLock);
630 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700631 client = mClient; // hold ref while lock is held
632 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800633 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700634 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800635}
636
Mathias Agopian698c0872011-06-28 19:09:31 -0700637sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700638 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700639 uint32_t w,
640 uint32_t h,
641 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700642 uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500643 SurfaceControl* parent,
644 uint32_t windowType,
645 uint32_t ownerUid)
Mathias Agopian698c0872011-06-28 19:09:31 -0700646{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700647 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700648 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700649 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700650 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700651 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700652
653 if (parent != nullptr) {
654 parentHandle = parent->getHandle();
655 }
656 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500657 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700658 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
659 if (err == NO_ERROR) {
660 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700661 }
662 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700663 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700664}
665
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700666sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
667 bool secure) {
668 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700669}
670
Jesse Hall6c913be2013-08-08 12:15:49 -0700671void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
672 Composer::getInstance().destroyDisplay(display);
673}
674
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700675sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
676 return Composer::getInstance().getBuiltInDisplay(id);
677}
678
Mathias Agopianac9fa422013-02-11 16:40:36 -0800679status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700680 if (mStatus != NO_ERROR)
681 return mStatus;
682 status_t err = mClient->destroySurface(sid);
683 return err;
684}
685
Svetoslavd85084b2014-03-20 10:28:31 -0700686status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
687 if (mStatus != NO_ERROR) {
688 return mStatus;
689 }
690 return mClient->clearLayerFrameStats(token);
691}
692
693status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
694 FrameStats* outStats) const {
695 if (mStatus != NO_ERROR) {
696 return mStatus;
697 }
698 return mClient->getLayerFrameStats(token, outStats);
699}
700
Robert Carr367c5682016-06-20 11:55:28 -0700701status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
702 bool* outTransformToDisplayInverse) const {
703 if (mStatus != NO_ERROR) {
704 return mStatus;
705 }
706 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
707}
708
Mathias Agopian698c0872011-06-28 19:09:31 -0700709inline Composer& SurfaceComposerClient::getComposer() {
710 return mComposer;
711}
712
713// ----------------------------------------------------------------------------
714
715void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700716 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700717}
718
Jamie Gennis28378392011-10-12 17:39:00 -0700719void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
720 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700721}
722
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700723void SurfaceComposerClient::setAnimationTransaction() {
724 Composer::setAnimationTransaction();
725}
726
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700727status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
728 return Composer::enableVSyncInjections(enable);
729}
730
731status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
732 return Composer::injectVSync(when);
733}
734
Mathias Agopian698c0872011-06-28 19:09:31 -0700735// ----------------------------------------------------------------------------
736
Mathias Agopianac9fa422013-02-11 16:40:36 -0800737status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700738 return getComposer().setCrop(this, id, crop);
739}
740
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000741status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
742 const Rect& crop) {
743 return getComposer().setFinalCrop(this, id, crop);
744}
745
Mathias Agopianac9fa422013-02-11 16:40:36 -0800746status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700747 return getComposer().setPosition(this, id, x, y);
748}
749
Mathias Agopianac9fa422013-02-11 16:40:36 -0800750status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700751 return getComposer().setSize(this, id, w, h);
752}
753
Robert Carrae060832016-11-28 10:51:00 -0800754status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700755 return getComposer().setLayer(this, id, z);
756}
757
Mathias Agopianac9fa422013-02-11 16:40:36 -0800758status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700759 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700760 layer_state_t::eLayerHidden,
761 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700762}
763
Mathias Agopianac9fa422013-02-11 16:40:36 -0800764status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700765 return getComposer().setFlags(this, id,
766 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700767 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700768}
769
Mathias Agopianac9fa422013-02-11 16:40:36 -0800770status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700771 uint32_t mask) {
772 return getComposer().setFlags(this, id, flags, mask);
773}
774
Mathias Agopianac9fa422013-02-11 16:40:36 -0800775status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700776 const Region& transparentRegion) {
777 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
778}
779
Mathias Agopianac9fa422013-02-11 16:40:36 -0800780status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700781 return getComposer().setAlpha(this, id, alpha);
782}
783
Mathias Agopianac9fa422013-02-11 16:40:36 -0800784status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700785 return getComposer().setLayerStack(this, id, layerStack);
786}
787
Mathias Agopianac9fa422013-02-11 16:40:36 -0800788status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700789 float dsdy, float dtdy) {
790 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
791}
792
Dan Stoza7dde5992015-05-22 09:51:44 -0700793status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
794 const sp<IBinder>& handle, uint64_t frameNumber) {
795 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
796}
797
Robert Carr0d480722017-01-10 16:42:54 -0800798status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
799 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
800 return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber);
801}
802
Robert Carr1db73f62016-12-21 12:58:51 -0800803status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
804 const sp<IBinder>& newParentHandle) {
805 return getComposer().reparentChildren(this, id, newParentHandle);
806}
807
Robert Carrc3574f72016-03-24 12:19:32 -0700808status_t SurfaceComposerClient::setOverrideScalingMode(
809 const sp<IBinder>& id, int32_t overrideScalingMode) {
810 return getComposer().setOverrideScalingMode(
811 this, id, overrideScalingMode);
812}
813
Robert Carr99e27f02016-06-16 15:18:02 -0700814status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700815 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700816 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700817}
818
Mathias Agopian698c0872011-06-28 19:09:31 -0700819// ----------------------------------------------------------------------------
820
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700821status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
822 sp<IGraphicBufferProducer> bufferProducer) {
823 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700824}
825
826void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
827 uint32_t layerStack) {
828 Composer::getInstance().setDisplayLayerStack(token, layerStack);
829}
830
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700831void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
832 uint32_t orientation,
833 const Rect& layerStackRect,
834 const Rect& displayRect) {
835 Composer::getInstance().setDisplayProjection(token, orientation,
836 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700837}
838
Michael Wright1f6078a2014-06-26 16:01:02 -0700839void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
840 uint32_t width, uint32_t height) {
841 Composer::getInstance().setDisplaySize(token, width, height);
842}
843
Mathias Agopiane57f2922012-08-09 16:29:12 -0700844// ----------------------------------------------------------------------------
845
Dan Stoza7f7da322014-05-02 15:26:25 -0700846status_t SurfaceComposerClient::getDisplayConfigs(
847 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800848{
Dan Stoza7f7da322014-05-02 15:26:25 -0700849 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
850}
851
852status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
853 DisplayInfo* info) {
854 Vector<DisplayInfo> configs;
855 status_t result = getDisplayConfigs(display, &configs);
856 if (result != NO_ERROR) {
857 return result;
858 }
859
860 int activeId = getActiveConfig(display);
861 if (activeId < 0) {
862 ALOGE("No active configuration found");
863 return NAME_NOT_FOUND;
864 }
865
Dan Stozad723bd72014-11-18 10:24:03 -0800866 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700867 return NO_ERROR;
868}
869
870int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
871 return ComposerService::getComposerService()->getActiveConfig(display);
872}
873
874status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
875 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800876}
877
Michael Wright28f24d02016-07-12 13:30:53 -0700878status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
879 Vector<android_color_mode_t>* outColorModes) {
880 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
881}
882
883android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
884 return ComposerService::getComposerService()->getActiveColorMode(display);
885}
886
887status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
888 android_color_mode_t colorMode) {
889 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
890}
891
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700892void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
893 int mode) {
894 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700895}
896
Svetoslavd85084b2014-03-20 10:28:31 -0700897status_t SurfaceComposerClient::clearAnimationFrameStats() {
898 return ComposerService::getComposerService()->clearAnimationFrameStats();
899}
900
901status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
902 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
903}
904
Dan Stozac4f471e2016-03-24 09:31:08 -0700905status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
906 HdrCapabilities* outCapabilities) {
907 return ComposerService::getComposerService()->getHdrCapabilities(display,
908 outCapabilities);
909}
910
Mathias Agopian698c0872011-06-28 19:09:31 -0700911// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800912
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800913status_t ScreenshotClient::capture(
914 const sp<IBinder>& display,
915 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700916 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800917 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800918 sp<ISurfaceComposer> s(ComposerService::getComposerService());
919 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700920 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800921 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800922}
923
Robert Carr673134e2017-01-09 19:48:38 -0800924status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
925 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800926 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800927 uint32_t rotation,
928 sp<GraphicBuffer>* outBuffer) {
929 sp<ISurfaceComposer> s(ComposerService::getComposerService());
930 if (s == NULL) return NO_INIT;
931
932 sp<IGraphicBufferConsumer> gbpConsumer;
933 sp<IGraphicBufferProducer> producer;
934 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
935 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
936 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
937 1, true));
938
939 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
940 minLayerZ, maxLayerZ, useIdentityTransform,
941 static_cast<ISurfaceComposer::Rotation>(rotation));
942 if (ret != NO_ERROR) {
943 return ret;
944 }
945 BufferItem b;
946 consumer->acquireBuffer(&b, 0, true);
947 *outBuffer = b.mGraphicBuffer;
948 return ret;
949}
950
Mathias Agopian74c40c02010-09-29 13:02:36 -0700951ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700952 : mHaveBuffer(false) {
953 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700954}
955
Mathias Agopian8000d062013-03-26 18:15:35 -0700956ScreenshotClient::~ScreenshotClient() {
957 ScreenshotClient::release();
958}
959
Mathias Agopianabe815d2013-03-19 22:22:21 -0700960sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
961 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700962 sp<IGraphicBufferConsumer> consumer;
963 BufferQueue::createBufferQueue(&mProducer, &consumer);
964 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700965 mCpuConsumer->setName(String8("ScreenshotClient"));
966 }
967 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800968}
969
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700970status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700971 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800972 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700973 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800974 sp<ISurfaceComposer> s(ComposerService::getComposerService());
975 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700976 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
977
978 if (mHaveBuffer) {
979 mCpuConsumer->unlockBuffer(mBuffer);
980 memset(&mBuffer, 0, sizeof(mBuffer));
981 mHaveBuffer = false;
982 }
983
Dan Stozac1879002014-05-22 15:59:05 -0700984 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700985 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
986 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700987
988 if (err == NO_ERROR) {
989 err = mCpuConsumer->lockNextBuffer(&mBuffer);
990 if (err == NO_ERROR) {
991 mHaveBuffer = true;
992 }
993 }
994 return err;
995}
996
Riley Andrewsd15ef272014-09-04 16:19:44 -0700997status_t ScreenshotClient::update(const sp<IBinder>& display,
998 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800999 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001000 bool useIdentityTransform) {
1001
1002 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
1003 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
1004}
1005
Dan Stozac1879002014-05-22 15:59:05 -07001006status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001007 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -08001008 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1009 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001010 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -07001011}
1012
Dan Stozac1879002014-05-22 15:59:05 -07001013status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001014 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -07001015 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001016 INT32_MIN, INT32_MAX,
1017 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001018}
1019
1020void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001021 if (mHaveBuffer) {
1022 mCpuConsumer->unlockBuffer(mBuffer);
1023 memset(&mBuffer, 0, sizeof(mBuffer));
1024 mHaveBuffer = false;
1025 }
1026 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -07001027}
1028
1029void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001030 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001031}
1032
1033uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001034 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001035}
1036
1037uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001038 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001039}
1040
1041PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001042 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001043}
1044
1045uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001046 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001047}
1048
1049size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001050 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001051}
1052
1053// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001054}; // namespace android