blob: c5a4389ae819542f1dfe50b9890433288366b756 [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 Agopiana67932f2011-04-20 14:20:59 -070029#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080030
Michael Wright28f24d02016-07-12 13:30:53 -070031#include <system/graphics.h>
32
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
Robert Carr673134e2017-01-09 19:48:38 -080035#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070036#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080038#include <gui/ISurfaceComposer.h>
39#include <gui/ISurfaceComposerClient.h>
Robert Carr0d480722017-01-10 16:42:54 -080040#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Mathias Agopian41f673c2011-11-17 17:48:35 -080043#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080044#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
46namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047// ---------------------------------------------------------------------------
48
Mathias Agopian7e27f052010-05-28 14:22:23 -070049ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
50
Mathias Agopianb7e930d2010-06-01 15:12:58 -070051ComposerService::ComposerService()
52: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070053 Mutex::Autolock _l(mLock);
54 connectLocked();
55}
56
57void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 const String16 name("SurfaceFlinger");
59 while (getService(name, &mComposerService) != NO_ERROR) {
60 usleep(250000);
61 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070062 assert(mComposerService != NULL);
63
64 // Create the death listener.
65 class DeathObserver : public IBinder::DeathRecipient {
66 ComposerService& mComposerService;
67 virtual void binderDied(const wp<IBinder>& who) {
68 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
69 who.unsafe_get());
70 mComposerService.composerServiceDied();
71 }
72 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070073 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070074 };
75
76 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080077 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070078}
79
Andy McFadden6652b3e2012-09-06 18:45:56 -070080/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
81 ComposerService& instance = ComposerService::getInstance();
82 Mutex::Autolock _l(instance.mLock);
83 if (instance.mComposerService == NULL) {
84 ComposerService::getInstance().connectLocked();
85 assert(instance.mComposerService != NULL);
86 ALOGD("ComposerService reconnected");
87 }
88 return instance.mComposerService;
89}
90
91void ComposerService::composerServiceDied()
92{
93 Mutex::Autolock _l(mLock);
94 mComposerService = NULL;
95 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070096}
97
Mathias Agopian7e27f052010-05-28 14:22:23 -070098// ---------------------------------------------------------------------------
99
Mathias Agopian698c0872011-06-28 19:09:31 -0700100static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700101int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700102 if (lhs.client < rhs.client) return -1;
103 if (lhs.client > rhs.client) return 1;
104 if (lhs.state.surface < rhs.state.surface) return -1;
105 if (lhs.state.surface > rhs.state.surface) return 1;
106 return 0;
107}
108
Mathias Agopiane57f2922012-08-09 16:29:12 -0700109static inline
110int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
111 return compare_type(lhs.token, rhs.token);
112}
113
Mathias Agopian7e27f052010-05-28 14:22:23 -0700114class Composer : public Singleton<Composer>
115{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700116 friend class Singleton<Composer>;
117
Mathias Agopian698c0872011-06-28 19:09:31 -0700118 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700119 SortedVector<ComposerState> mComposerStates;
120 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700121 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700122 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700123 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700124
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700125 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700126 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700127 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700128 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700129
Jeff Brownf3f7db62012-08-31 02:18:38 -0700130 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700131 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700132 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700133 status_t enableVSyncInjectionsImpl(bool enable);
134 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-28 19:09:31 -0700135
136 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800137 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700138
Mathias Agopiane57f2922012-08-09 16:29:12 -0700139 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
140
Mathias Agopiand4784a32010-05-27 19:41:15 -0700141public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700142 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700143 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700144 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700145
Mathias Agopianac9fa422013-02-11 16:40:36 -0800146 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700147 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800148 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700149 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800150 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Robert Carrae060832016-11-28 10:51:00 -0800151 int32_t z);
Robert Carrdb66e622017-04-10 16:55:57 -0700152 status_t setRelativeLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
153 const sp<IBinder>& relativeTo, int32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800154 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700155 uint32_t flags, uint32_t mask);
156 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800157 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700158 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800159 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700160 float alpha);
chaviw13fdc492017-06-27 12:40:18 -0700161 status_t setColor(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
162 const half3& color);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800163 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800164 float dsdx, float dtdx, float dtdy, float dsdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700165 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800166 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700167 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000168 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
169 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700170 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800171 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700172 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
173 const sp<IBinder>& id, const sp<IBinder>& handle,
174 uint64_t frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800175 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
176 const sp<IBinder>& id, const sp<Surface>& barrierSurface,
177 uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800178 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
179 const sp<IBinder>& id,
180 const sp<IBinder>& newParentHandle);
chaviwf1961f72017-09-18 16:41:07 -0700181 status_t reparent(const sp<SurfaceComposerClient>& client,
182 const sp<IBinder>& id, const sp<IBinder>& newParentHandle);
Robert Carr9524cb32017-02-13 11:32:32 -0800183 status_t detachChildren(const sp<SurfaceComposerClient>& client,
184 const sp<IBinder>& id);
Robert Carrc3574f72016-03-24 12:19:32 -0700185 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
186 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700187 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700188 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700189
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700190 status_t setDisplaySurface(const sp<IBinder>& token,
191 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700192 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700193 void setDisplayProjection(const sp<IBinder>& token,
194 uint32_t orientation,
195 const Rect& layerStackRect,
196 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700197 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700198
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700199 static void setAnimationTransaction() {
200 Composer::getInstance().setAnimationTransactionImpl();
201 }
202
Jeff Brownf3f7db62012-08-31 02:18:38 -0700203 static void openGlobalTransaction() {
204 Composer::getInstance().openGlobalTransactionImpl();
205 }
206
Jamie Gennis28378392011-10-12 17:39:00 -0700207 static void closeGlobalTransaction(bool synchronous) {
208 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700209 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700210
211 static status_t enableVSyncInjections(bool enable) {
212 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
213 }
214
215 static status_t injectVSync(nsecs_t when) {
216 return Composer::getInstance().injectVSyncImpl(when);
217 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700218};
219
220ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
221
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222// ---------------------------------------------------------------------------
223
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700224sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
225 return ComposerService::getComposerService()->createDisplay(displayName,
226 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700227}
228
Jesse Hall6c913be2013-08-08 12:15:49 -0700229void Composer::destroyDisplay(const sp<IBinder>& display) {
230 return ComposerService::getComposerService()->destroyDisplay(display);
231}
232
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700233sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
234 return ComposerService::getComposerService()->getBuiltInDisplay(id);
235}
236
Jeff Brownf3f7db62012-08-31 02:18:38 -0700237void Composer::openGlobalTransactionImpl() {
238 { // scope for the lock
239 Mutex::Autolock _l(mLock);
240 mTransactionNestCount += 1;
241 }
242}
243
Jamie Gennis28378392011-10-12 17:39:00 -0700244void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700245 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700246
247 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700248 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700249 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700250
251 { // scope for the lock
252 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700253 mForceSynchronous |= synchronous;
254 if (!mTransactionNestCount) {
255 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
256 "call to openGlobalTransaction().");
257 } else if (--mTransactionNestCount) {
258 return;
259 }
260
Mathias Agopiane57f2922012-08-09 16:29:12 -0700261 transaction = mComposerStates;
262 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700263
Mathias Agopiane57f2922012-08-09 16:29:12 -0700264 displayTransaction = mDisplayStates;
265 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700266
Jeff Brownf3f7db62012-08-31 02:18:38 -0700267 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700268 flags |= ISurfaceComposer::eSynchronous;
269 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700270 if (mAnimation) {
271 flags |= ISurfaceComposer::eAnimation;
272 }
273
Jamie Gennis28378392011-10-12 17:39:00 -0700274 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700275 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700276 }
277
Mathias Agopian8b33f032012-07-24 20:43:54 -0700278 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800279}
280
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700281status_t Composer::enableVSyncInjectionsImpl(bool enable) {
282 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
283 return sm->enableVSyncInjections(enable);
284}
285
286status_t Composer::injectVSyncImpl(nsecs_t when) {
287 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
288 return sm->injectVSync(when);
289}
290
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700291void Composer::setAnimationTransactionImpl() {
292 Mutex::Autolock _l(mLock);
293 mAnimation = true;
294}
295
Mathias Agopian698c0872011-06-28 19:09:31 -0700296layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800297 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700298
299 ComposerState s;
300 s.client = client->mClient;
301 s.state.surface = id;
302
Mathias Agopiane57f2922012-08-09 16:29:12 -0700303 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 if (index < 0) {
305 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700306 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700307 }
308
Mathias Agopiane57f2922012-08-09 16:29:12 -0700309 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700310 return &(out[index].state);
311}
312
313status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800314 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700315 Mutex::Autolock _l(mLock);
316 layer_state_t* s = getLayerStateLocked(client, id);
317 if (!s)
318 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700319 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700320 s->x = x;
321 s->y = y;
322 return NO_ERROR;
323}
324
325status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800326 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700327 Mutex::Autolock _l(mLock);
328 layer_state_t* s = getLayerStateLocked(client, id);
329 if (!s)
330 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700331 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700332 s->w = w;
333 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700334
Jorim Jaggi092123c2016-04-13 01:40:35 +0000335 // Resizing a surface makes the transaction synchronous.
336 mForceSynchronous = true;
337
Mathias Agopian698c0872011-06-28 19:09:31 -0700338 return NO_ERROR;
339}
340
341status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800342 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 Mutex::Autolock _l(mLock);
344 layer_state_t* s = getLayerStateLocked(client, id);
345 if (!s)
346 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700347 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700348 s->z = z;
349 return NO_ERROR;
350}
351
Robert Carrdb66e622017-04-10 16:55:57 -0700352status_t Composer::setRelativeLayer(const sp<SurfaceComposerClient>& client,
353 const sp<IBinder>& id, const sp<IBinder>& relativeTo,
354 int32_t z) {
355 Mutex::Autolock _l(mLock);
356 layer_state_t* s = getLayerStateLocked(client, id);
357 if (!s) {
358 return BAD_INDEX;
359 }
360 s->what |= layer_state_t::eRelativeLayerChanged;
361 s->relativeLayerHandle = relativeTo;
362 s->z = z;
363 return NO_ERROR;
364}
365
Mathias Agopian698c0872011-06-28 19:09:31 -0700366status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800367 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700368 uint32_t mask) {
369 Mutex::Autolock _l(mLock);
370 layer_state_t* s = getLayerStateLocked(client, id);
371 if (!s)
372 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700373 if ((mask & layer_state_t::eLayerOpaque) ||
374 (mask & layer_state_t::eLayerHidden) ||
375 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700376 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800377 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700378 s->flags &= ~mask;
379 s->flags |= (flags & mask);
380 s->mask |= mask;
381 return NO_ERROR;
382}
383
384status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800385 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700386 const Region& transparentRegion) {
387 Mutex::Autolock _l(mLock);
388 layer_state_t* s = getLayerStateLocked(client, id);
389 if (!s)
390 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700391 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700392 s->transparentRegion = transparentRegion;
393 return NO_ERROR;
394}
395
396status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800397 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700398 Mutex::Autolock _l(mLock);
399 layer_state_t* s = getLayerStateLocked(client, id);
400 if (!s)
401 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700402 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700403 s->alpha = alpha;
404 return NO_ERROR;
405}
406
chaviw13fdc492017-06-27 12:40:18 -0700407status_t Composer::setColor(const sp<SurfaceComposerClient>& client,
408 const sp<IBinder>& id, const half3& color) {
409 Mutex::Autolock _l(mLock);
410 layer_state_t* s = getLayerStateLocked(client, id);
411 if (!s)
412 return BAD_INDEX;
413 s->what |= layer_state_t::eColorChanged;
414 s->color = color;
415 return NO_ERROR;
416}
417
Mathias Agopian87855782012-07-24 21:41:09 -0700418status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800419 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700420 Mutex::Autolock _l(mLock);
421 layer_state_t* s = getLayerStateLocked(client, id);
422 if (!s)
423 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700424 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700425 s->layerStack = layerStack;
426 return NO_ERROR;
427}
428
Mathias Agopian698c0872011-06-28 19:09:31 -0700429status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800430 const sp<IBinder>& id, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800431 float dtdy, float dsdy) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700432 Mutex::Autolock _l(mLock);
433 layer_state_t* s = getLayerStateLocked(client, id);
434 if (!s)
435 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700436 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700437 layer_state_t::matrix22_t matrix;
438 matrix.dsdx = dsdx;
439 matrix.dtdx = dtdx;
440 matrix.dsdy = dsdy;
441 matrix.dtdy = dtdy;
442 s->matrix = matrix;
443 return NO_ERROR;
444}
445
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700446status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800447 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700448 Mutex::Autolock _l(mLock);
449 layer_state_t* s = getLayerStateLocked(client, id);
450 if (!s)
451 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700452 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700453 s->crop = crop;
454 return NO_ERROR;
455}
456
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000457status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
458 const sp<IBinder>& id, const Rect& crop) {
459 Mutex::Autolock _l(mLock);
460 layer_state_t* s = getLayerStateLocked(client, id);
461 if (!s) {
462 return BAD_INDEX;
463 }
464 s->what |= layer_state_t::eFinalCropChanged;
465 s->finalCrop = crop;
466 return NO_ERROR;
467}
468
Dan Stoza7dde5992015-05-22 09:51:44 -0700469status_t Composer::deferTransactionUntil(
470 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
471 const sp<IBinder>& handle, uint64_t frameNumber) {
472 Mutex::Autolock lock(mLock);
473 layer_state_t* s = getLayerStateLocked(client, id);
474 if (!s) {
475 return BAD_INDEX;
476 }
477 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-10 16:42:54 -0800478 s->barrierHandle = handle;
479 s->frameNumber = frameNumber;
480 return NO_ERROR;
481}
482
483status_t Composer::deferTransactionUntil(
484 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
485 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
486 Mutex::Autolock lock(mLock);
487 layer_state_t* s = getLayerStateLocked(client, id);
488 if (!s) {
489 return BAD_INDEX;
490 }
491 s->what |= layer_state_t::eDeferTransaction;
492 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 09:51:44 -0700493 s->frameNumber = frameNumber;
494 return NO_ERROR;
495}
496
Robert Carr1db73f62016-12-21 12:58:51 -0800497status_t Composer::reparentChildren(
498 const sp<SurfaceComposerClient>& client,
499 const sp<IBinder>& id,
500 const sp<IBinder>& newParentHandle) {
501 Mutex::Autolock lock(mLock);
502 layer_state_t* s = getLayerStateLocked(client, id);
503 if (!s) {
504 return BAD_INDEX;
505 }
506 s->what |= layer_state_t::eReparentChildren;
507 s->reparentHandle = newParentHandle;
508 return NO_ERROR;
509}
510
chaviwf1961f72017-09-18 16:41:07 -0700511status_t Composer::reparent(const sp<SurfaceComposerClient>& client,
chaviw06178942017-07-27 10:25:59 -0700512 const sp<IBinder>& id,
chaviwf1961f72017-09-18 16:41:07 -0700513 const sp<IBinder>& newParentHandle) {
chaviw06178942017-07-27 10:25:59 -0700514 Mutex::Autolock lock(mLock);
515 layer_state_t* s = getLayerStateLocked(client, id);
516 if (!s) {
517 return BAD_INDEX;
518 }
chaviwf1961f72017-09-18 16:41:07 -0700519 s->what |= layer_state_t::eReparent;
chaviw06178942017-07-27 10:25:59 -0700520 s->parentHandleForChild = newParentHandle;
chaviw06178942017-07-27 10:25:59 -0700521 return NO_ERROR;
522}
523
Robert Carr9524cb32017-02-13 11:32:32 -0800524status_t Composer::detachChildren(
525 const sp<SurfaceComposerClient>& client,
526 const sp<IBinder>& id) {
527 Mutex::Autolock lock(mLock);
528 layer_state_t* s = getLayerStateLocked(client, id);
529 if (!s) {
530 return BAD_INDEX;
531 }
532 s->what |= layer_state_t::eDetachChildren;
533 return NO_ERROR;
534}
535
Robert Carrc3574f72016-03-24 12:19:32 -0700536status_t Composer::setOverrideScalingMode(
537 const sp<SurfaceComposerClient>& client,
538 const sp<IBinder>& id, int32_t overrideScalingMode) {
539 Mutex::Autolock lock(mLock);
540 layer_state_t* s = getLayerStateLocked(client, id);
541 if (!s) {
542 return BAD_INDEX;
543 }
544
545 switch (overrideScalingMode) {
546 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
547 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
548 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
549 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
550 case -1:
551 break;
552 default:
553 ALOGE("unknown scaling mode: %d",
554 overrideScalingMode);
555 return BAD_VALUE;
556 }
557
558 s->what |= layer_state_t::eOverrideScalingModeChanged;
559 s->overrideScalingMode = overrideScalingMode;
560 return NO_ERROR;
561}
562
Robert Carr99e27f02016-06-16 15:18:02 -0700563status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700564 const sp<SurfaceComposerClient>& client,
565 const sp<IBinder>& id) {
566 Mutex::Autolock lock(mLock);
567 layer_state_t* s = getLayerStateLocked(client, id);
568 if (!s) {
569 return BAD_INDEX;
570 }
Robert Carr99e27f02016-06-16 15:18:02 -0700571 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700572 return NO_ERROR;
573}
574
Mathias Agopian698c0872011-06-28 19:09:31 -0700575// ---------------------------------------------------------------------------
576
Mathias Agopiane57f2922012-08-09 16:29:12 -0700577DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
578 DisplayState s;
579 s.token = token;
580 ssize_t index = mDisplayStates.indexOf(s);
581 if (index < 0) {
582 // we don't have it, add an initialized layer_state to our list
583 s.what = 0;
584 index = mDisplayStates.add(s);
585 }
Dan Stozad723bd72014-11-18 10:24:03 -0800586 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700587}
588
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700589status_t Composer::setDisplaySurface(const sp<IBinder>& token,
590 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700591 if (bufferProducer.get() != nullptr) {
592 // Make sure that composition can never be stalled by a virtual display
593 // consumer that isn't processing buffers fast enough.
594 status_t err = bufferProducer->setAsyncMode(true);
595 if (err != NO_ERROR) {
596 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
597 "BufferQueue. This BufferQueue cannot be used for virtual "
598 "display. (%d)", err);
599 return err;
600 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700601 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700602 Mutex::Autolock _l(mLock);
603 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800604 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700605 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700606 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700607}
608
609void Composer::setDisplayLayerStack(const sp<IBinder>& token,
610 uint32_t layerStack) {
611 Mutex::Autolock _l(mLock);
612 DisplayState& s(getDisplayStateLocked(token));
613 s.layerStack = layerStack;
614 s.what |= DisplayState::eLayerStackChanged;
615}
616
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700617void Composer::setDisplayProjection(const sp<IBinder>& token,
618 uint32_t orientation,
619 const Rect& layerStackRect,
620 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700621 Mutex::Autolock _l(mLock);
622 DisplayState& s(getDisplayStateLocked(token));
623 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700624 s.viewport = layerStackRect;
625 s.frame = displayRect;
626 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000627 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700628}
629
Michael Wright1f6078a2014-06-26 16:01:02 -0700630void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
631 Mutex::Autolock _l(mLock);
632 DisplayState& s(getDisplayStateLocked(token));
633 s.width = width;
634 s.height = height;
635 s.what |= DisplayState::eDisplaySizeChanged;
636}
637
Mathias Agopiane57f2922012-08-09 16:29:12 -0700638// ---------------------------------------------------------------------------
639
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800640SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700641 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800642{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800643}
644
Robert Carr1db73f62016-12-21 12:58:51 -0800645SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
646 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
647{
648}
649
Mathias Agopian698c0872011-06-28 19:09:31 -0700650void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700651 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700652 if (sm != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800653 auto rootProducer = mParent.promote();
654 sp<ISurfaceComposerClient> conn;
655 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
656 sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700657 if (conn != 0) {
658 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700659 mStatus = NO_ERROR;
660 }
661 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800662}
663
Mathias Agopian698c0872011-06-28 19:09:31 -0700664SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700665 dispose();
666}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700667
Mathias Agopian698c0872011-06-28 19:09:31 -0700668status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800669 return mStatus;
670}
671
Mathias Agopian698c0872011-06-28 19:09:31 -0700672sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800673 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800674}
675
Mathias Agopiand4784a32010-05-27 19:41:15 -0700676status_t SurfaceComposerClient::linkToComposerDeath(
677 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700678 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700679 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800680 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800681}
682
Mathias Agopian698c0872011-06-28 19:09:31 -0700683void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800684 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700685 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700686 Mutex::Autolock _lm(mLock);
687 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700688 client = mClient; // hold ref while lock is held
689 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800690 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700691 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800692}
693
Mathias Agopian698c0872011-06-28 19:09:31 -0700694sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700695 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700696 uint32_t w,
697 uint32_t h,
698 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700699 uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500700 SurfaceControl* parent,
701 uint32_t windowType,
702 uint32_t ownerUid)
Mathias Agopian698c0872011-06-28 19:09:31 -0700703{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700704 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700705 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700706 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700707 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700708 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700709
710 if (parent != nullptr) {
711 parentHandle = parent->getHandle();
712 }
713 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500714 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700715 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
716 if (err == NO_ERROR) {
717 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700718 }
719 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700720 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700721}
722
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700723sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
724 bool secure) {
725 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700726}
727
Jesse Hall6c913be2013-08-08 12:15:49 -0700728void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
729 Composer::getInstance().destroyDisplay(display);
730}
731
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700732sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
733 return Composer::getInstance().getBuiltInDisplay(id);
734}
735
Mathias Agopianac9fa422013-02-11 16:40:36 -0800736status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700737 if (mStatus != NO_ERROR)
738 return mStatus;
739 status_t err = mClient->destroySurface(sid);
740 return err;
741}
742
Svetoslavd85084b2014-03-20 10:28:31 -0700743status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
744 if (mStatus != NO_ERROR) {
745 return mStatus;
746 }
747 return mClient->clearLayerFrameStats(token);
748}
749
750status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
751 FrameStats* outStats) const {
752 if (mStatus != NO_ERROR) {
753 return mStatus;
754 }
755 return mClient->getLayerFrameStats(token, outStats);
756}
757
Mathias Agopian698c0872011-06-28 19:09:31 -0700758inline Composer& SurfaceComposerClient::getComposer() {
759 return mComposer;
760}
761
762// ----------------------------------------------------------------------------
763
764void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700765 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700766}
767
Jamie Gennis28378392011-10-12 17:39:00 -0700768void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
769 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700770}
771
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700772void SurfaceComposerClient::setAnimationTransaction() {
773 Composer::setAnimationTransaction();
774}
775
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700776status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
777 return Composer::enableVSyncInjections(enable);
778}
779
780status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
781 return Composer::injectVSync(when);
782}
783
Mathias Agopian698c0872011-06-28 19:09:31 -0700784// ----------------------------------------------------------------------------
785
Mathias Agopianac9fa422013-02-11 16:40:36 -0800786status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700787 return getComposer().setCrop(this, id, crop);
788}
789
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000790status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
791 const Rect& crop) {
792 return getComposer().setFinalCrop(this, id, crop);
793}
794
Mathias Agopianac9fa422013-02-11 16:40:36 -0800795status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700796 return getComposer().setPosition(this, id, x, y);
797}
798
Mathias Agopianac9fa422013-02-11 16:40:36 -0800799status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700800 return getComposer().setSize(this, id, w, h);
801}
802
Robert Carrae060832016-11-28 10:51:00 -0800803status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700804 return getComposer().setLayer(this, id, z);
805}
806
Robert Carrdb66e622017-04-10 16:55:57 -0700807status_t SurfaceComposerClient::setRelativeLayer(const sp<IBinder>& id,
808 const sp<IBinder>& relativeTo, int32_t z) {
809 return getComposer().setRelativeLayer(this, id, relativeTo, z);
810}
811
Mathias Agopianac9fa422013-02-11 16:40:36 -0800812status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700813 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700814 layer_state_t::eLayerHidden,
815 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700816}
817
Mathias Agopianac9fa422013-02-11 16:40:36 -0800818status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700819 return getComposer().setFlags(this, id,
820 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700821 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700822}
823
Mathias Agopianac9fa422013-02-11 16:40:36 -0800824status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700825 uint32_t mask) {
826 return getComposer().setFlags(this, id, flags, mask);
827}
828
Mathias Agopianac9fa422013-02-11 16:40:36 -0800829status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700830 const Region& transparentRegion) {
831 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
832}
833
Mathias Agopianac9fa422013-02-11 16:40:36 -0800834status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700835 return getComposer().setAlpha(this, id, alpha);
836}
837
chaviw13fdc492017-06-27 12:40:18 -0700838status_t SurfaceComposerClient::setColor(const sp<IBinder>& id, const half3& color) {
839 return getComposer().setColor(this, id, color);
840}
841
Mathias Agopianac9fa422013-02-11 16:40:36 -0800842status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700843 return getComposer().setLayerStack(this, id, layerStack);
844}
845
Mathias Agopianac9fa422013-02-11 16:40:36 -0800846status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800847 float dtdy, float dsdy) {
848 return getComposer().setMatrix(this, id, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian698c0872011-06-28 19:09:31 -0700849}
850
Dan Stoza7dde5992015-05-22 09:51:44 -0700851status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
852 const sp<IBinder>& handle, uint64_t frameNumber) {
853 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
854}
855
Robert Carr0d480722017-01-10 16:42:54 -0800856status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
857 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
858 return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber);
859}
860
Robert Carr1db73f62016-12-21 12:58:51 -0800861status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
862 const sp<IBinder>& newParentHandle) {
863 return getComposer().reparentChildren(this, id, newParentHandle);
864}
865
chaviwf1961f72017-09-18 16:41:07 -0700866status_t SurfaceComposerClient::reparent(const sp<IBinder>& id,
867 const sp<IBinder>& newParentHandle) {
868 return getComposer().reparent(this, id, newParentHandle);
chaviw06178942017-07-27 10:25:59 -0700869}
870
Robert Carr9524cb32017-02-13 11:32:32 -0800871status_t SurfaceComposerClient::detachChildren(const sp<IBinder>& id) {
872 return getComposer().detachChildren(this, id);
873}
874
Robert Carrc3574f72016-03-24 12:19:32 -0700875status_t SurfaceComposerClient::setOverrideScalingMode(
876 const sp<IBinder>& id, int32_t overrideScalingMode) {
877 return getComposer().setOverrideScalingMode(
878 this, id, overrideScalingMode);
879}
880
Robert Carr99e27f02016-06-16 15:18:02 -0700881status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700882 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700883 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700884}
885
Mathias Agopian698c0872011-06-28 19:09:31 -0700886// ----------------------------------------------------------------------------
887
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700888status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
889 sp<IGraphicBufferProducer> bufferProducer) {
890 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700891}
892
893void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
894 uint32_t layerStack) {
895 Composer::getInstance().setDisplayLayerStack(token, layerStack);
896}
897
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700898void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
899 uint32_t orientation,
900 const Rect& layerStackRect,
901 const Rect& displayRect) {
902 Composer::getInstance().setDisplayProjection(token, orientation,
903 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700904}
905
Michael Wright1f6078a2014-06-26 16:01:02 -0700906void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
907 uint32_t width, uint32_t height) {
908 Composer::getInstance().setDisplaySize(token, width, height);
909}
910
Mathias Agopiane57f2922012-08-09 16:29:12 -0700911// ----------------------------------------------------------------------------
912
Dan Stoza7f7da322014-05-02 15:26:25 -0700913status_t SurfaceComposerClient::getDisplayConfigs(
914 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800915{
Dan Stoza7f7da322014-05-02 15:26:25 -0700916 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
917}
918
919status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
920 DisplayInfo* info) {
921 Vector<DisplayInfo> configs;
922 status_t result = getDisplayConfigs(display, &configs);
923 if (result != NO_ERROR) {
924 return result;
925 }
926
927 int activeId = getActiveConfig(display);
928 if (activeId < 0) {
929 ALOGE("No active configuration found");
930 return NAME_NOT_FOUND;
931 }
932
Dan Stozad723bd72014-11-18 10:24:03 -0800933 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700934 return NO_ERROR;
935}
936
937int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
938 return ComposerService::getComposerService()->getActiveConfig(display);
939}
940
941status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
942 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800943}
944
Michael Wright28f24d02016-07-12 13:30:53 -0700945status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
946 Vector<android_color_mode_t>* outColorModes) {
947 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
948}
949
950android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
951 return ComposerService::getComposerService()->getActiveColorMode(display);
952}
953
954status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
955 android_color_mode_t colorMode) {
956 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
957}
958
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700959void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
960 int mode) {
961 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700962}
963
Svetoslavd85084b2014-03-20 10:28:31 -0700964status_t SurfaceComposerClient::clearAnimationFrameStats() {
965 return ComposerService::getComposerService()->clearAnimationFrameStats();
966}
967
968status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
969 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
970}
971
Dan Stozac4f471e2016-03-24 09:31:08 -0700972status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
973 HdrCapabilities* outCapabilities) {
974 return ComposerService::getComposerService()->getHdrCapabilities(display,
975 outCapabilities);
976}
977
Mathias Agopian698c0872011-06-28 19:09:31 -0700978// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800979
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800980status_t ScreenshotClient::capture(
981 const sp<IBinder>& display,
982 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700983 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800984 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800985 sp<ISurfaceComposer> s(ComposerService::getComposerService());
986 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700987 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800988 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800989}
990
Robert Carr673134e2017-01-09 19:48:38 -0800991status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
992 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800993 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800994 uint32_t rotation,
995 sp<GraphicBuffer>* outBuffer) {
996 sp<ISurfaceComposer> s(ComposerService::getComposerService());
997 if (s == NULL) return NO_INIT;
998
999 sp<IGraphicBufferConsumer> gbpConsumer;
1000 sp<IGraphicBufferProducer> producer;
1001 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
1002 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
1003 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
1004 1, true));
1005
1006 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
1007 minLayerZ, maxLayerZ, useIdentityTransform,
1008 static_cast<ISurfaceComposer::Rotation>(rotation));
1009 if (ret != NO_ERROR) {
1010 return ret;
1011 }
1012 BufferItem b;
1013 consumer->acquireBuffer(&b, 0, true);
1014 *outBuffer = b.mGraphicBuffer;
1015 return ret;
1016}
1017
Mathias Agopian74c40c02010-09-29 13:02:36 -07001018ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -07001019 : mHaveBuffer(false) {
1020 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -07001021}
1022
Mathias Agopian8000d062013-03-26 18:15:35 -07001023ScreenshotClient::~ScreenshotClient() {
1024 ScreenshotClient::release();
1025}
1026
Mathias Agopianabe815d2013-03-19 22:22:21 -07001027sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
1028 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -07001029 sp<IGraphicBufferConsumer> consumer;
1030 BufferQueue::createBufferQueue(&mProducer, &consumer);
1031 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -07001032 mCpuConsumer->setName(String8("ScreenshotClient"));
1033 }
1034 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08001035}
1036
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001037status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -07001038 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001039 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001040 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08001041 sp<ISurfaceComposer> s(ComposerService::getComposerService());
1042 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -07001043 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
1044
1045 if (mHaveBuffer) {
1046 mCpuConsumer->unlockBuffer(mBuffer);
1047 memset(&mBuffer, 0, sizeof(mBuffer));
1048 mHaveBuffer = false;
1049 }
1050
Dan Stozac1879002014-05-22 15:59:05 -07001051 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001052 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
1053 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -07001054
1055 if (err == NO_ERROR) {
1056 err = mCpuConsumer->lockNextBuffer(&mBuffer);
1057 if (err == NO_ERROR) {
1058 mHaveBuffer = true;
1059 }
1060 }
1061 return err;
1062}
1063
Riley Andrewsd15ef272014-09-04 16:19:44 -07001064status_t ScreenshotClient::update(const sp<IBinder>& display,
1065 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001066 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001067 bool useIdentityTransform) {
1068
1069 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
1070 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
1071}
1072
Dan Stozac1879002014-05-22 15:59:05 -07001073status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001074 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -08001075 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1076 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001077 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -07001078}
1079
Dan Stozac1879002014-05-22 15:59:05 -07001080status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001081 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -07001082 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001083 INT32_MIN, INT32_MAX,
1084 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001085}
1086
1087void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001088 if (mHaveBuffer) {
1089 mCpuConsumer->unlockBuffer(mBuffer);
1090 memset(&mBuffer, 0, sizeof(mBuffer));
1091 mHaveBuffer = false;
1092 }
1093 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -07001094}
1095
1096void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001097 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001098}
1099
1100uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001101 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001102}
1103
1104uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001105 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001106}
1107
1108PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001109 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001110}
1111
1112uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001113 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001114}
1115
1116size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001117 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001118}
1119
Romain Guy88d37dd2017-05-26 17:57:05 -07001120android_dataspace ScreenshotClient::getDataSpace() const {
1121 return mBuffer.dataSpace;
1122}
1123
Mathias Agopian74c40c02010-09-29 13:02:36 -07001124// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001125}; // namespace android