2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "SurfaceComposerClient"
20 #include <sys/types.h>
22 #include <utils/Errors.h>
23 #include <utils/Log.h>
24 #include <utils/Singleton.h>
25 #include <utils/SortedVector.h>
26 #include <utils/String8.h>
27 #include <utils/threads.h>
29 #include <binder/IMemory.h>
30 #include <binder/IServiceManager.h>
32 #include <system/graphics.h>
34 #include <ui/DisplayInfo.h>
36 #include <gui/CpuConsumer.h>
37 #include <gui/IGraphicBufferProducer.h>
38 #include <gui/ISurfaceComposer.h>
39 #include <gui/ISurfaceComposerClient.h>
40 #include <gui/SurfaceComposerClient.h>
42 #include <private/gui/ComposerService.h>
43 #include <private/gui/LayerState.h>
46 // ---------------------------------------------------------------------------
48 ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
50 ComposerService::ComposerService()
51 : Singleton<ComposerService>() {
52 Mutex::Autolock _l(mLock);
56 void ComposerService::connectLocked() {
57 const String16 name("SurfaceFlinger");
58 while (getService(name, &mComposerService) != NO_ERROR) {
61 assert(mComposerService != NULL);
63 // Create the death listener.
64 class DeathObserver : public IBinder::DeathRecipient {
65 ComposerService& mComposerService;
66 virtual void binderDied(const wp<IBinder>& who) {
67 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
69 mComposerService.composerServiceDied();
72 DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
75 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
76 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
79 /*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
80 ComposerService& instance = ComposerService::getInstance();
81 Mutex::Autolock _l(instance.mLock);
82 if (instance.mComposerService == NULL) {
83 ComposerService::getInstance().connectLocked();
84 assert(instance.mComposerService != NULL);
85 ALOGD("ComposerService reconnected");
87 return instance.mComposerService;
90 void ComposerService::composerServiceDied()
92 Mutex::Autolock _l(mLock);
93 mComposerService = NULL;
94 mDeathObserver = NULL;
97 // ---------------------------------------------------------------------------
100 int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
101 if (lhs.client < rhs.client) return -1;
102 if (lhs.client > rhs.client) return 1;
103 if (lhs.state.surface < rhs.state.surface) return -1;
104 if (lhs.state.surface > rhs.state.surface) return 1;
109 int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
110 return compare_type(lhs.token, rhs.token);
113 class Composer : public Singleton<Composer>
115 friend class Singleton<Composer>;
118 SortedVector<ComposerState> mComposerStates;
119 SortedVector<DisplayState > mDisplayStates;
120 uint32_t mForceSynchronous;
121 uint32_t mTransactionNestCount;
124 Composer() : Singleton<Composer>(),
125 mForceSynchronous(0), mTransactionNestCount(0),
129 void openGlobalTransactionImpl();
130 void closeGlobalTransactionImpl(bool synchronous);
131 void setAnimationTransactionImpl();
133 layer_state_t* getLayerStateLocked(
134 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
136 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
139 sp<IBinder> createDisplay(const String8& displayName, bool secure);
140 void destroyDisplay(const sp<IBinder>& display);
141 sp<IBinder> getBuiltInDisplay(int32_t id);
143 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
145 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
146 uint32_t w, uint32_t h);
147 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
149 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
150 uint32_t flags, uint32_t mask);
151 status_t setTransparentRegionHint(
152 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
153 const Region& transparentRegion);
154 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
156 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
157 float dsdx, float dtdx, float dsdy, float dtdy);
158 status_t setOrientation(int orientation);
159 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
161 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
162 const sp<IBinder>& id, const Rect& crop);
163 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
164 const sp<IBinder>& id, uint32_t layerStack);
165 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
166 const sp<IBinder>& id, const sp<IBinder>& handle,
167 uint64_t frameNumber);
168 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
169 const sp<IBinder>& id, int32_t overrideScalingMode);
170 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
171 const sp<IBinder>& id);
173 void setDisplaySurface(const sp<IBinder>& token,
174 const sp<IGraphicBufferProducer>& bufferProducer);
175 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
176 void setDisplayProjection(const sp<IBinder>& token,
177 uint32_t orientation,
178 const Rect& layerStackRect,
179 const Rect& displayRect);
180 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
182 static void setAnimationTransaction() {
183 Composer::getInstance().setAnimationTransactionImpl();
186 static void openGlobalTransaction() {
187 Composer::getInstance().openGlobalTransactionImpl();
190 static void closeGlobalTransaction(bool synchronous) {
191 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
195 ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
197 // ---------------------------------------------------------------------------
199 sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
200 return ComposerService::getComposerService()->createDisplay(displayName,
204 void Composer::destroyDisplay(const sp<IBinder>& display) {
205 return ComposerService::getComposerService()->destroyDisplay(display);
208 sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
209 return ComposerService::getComposerService()->getBuiltInDisplay(id);
212 void Composer::openGlobalTransactionImpl() {
213 { // scope for the lock
214 Mutex::Autolock _l(mLock);
215 mTransactionNestCount += 1;
219 void Composer::closeGlobalTransactionImpl(bool synchronous) {
220 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
222 Vector<ComposerState> transaction;
223 Vector<DisplayState> displayTransaction;
226 { // scope for the lock
227 Mutex::Autolock _l(mLock);
228 mForceSynchronous |= synchronous;
229 if (!mTransactionNestCount) {
230 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
231 "call to openGlobalTransaction().");
232 } else if (--mTransactionNestCount) {
236 transaction = mComposerStates;
237 mComposerStates.clear();
239 displayTransaction = mDisplayStates;
240 mDisplayStates.clear();
242 if (mForceSynchronous) {
243 flags |= ISurfaceComposer::eSynchronous;
246 flags |= ISurfaceComposer::eAnimation;
249 mForceSynchronous = false;
253 sm->setTransactionState(transaction, displayTransaction, flags);
256 void Composer::setAnimationTransactionImpl() {
257 Mutex::Autolock _l(mLock);
261 layer_state_t* Composer::getLayerStateLocked(
262 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
265 s.client = client->mClient;
266 s.state.surface = id;
268 ssize_t index = mComposerStates.indexOf(s);
270 // we don't have it, add an initialized layer_state to our list
271 index = mComposerStates.add(s);
274 ComposerState* const out = mComposerStates.editArray();
275 return &(out[index].state);
278 status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
279 const sp<IBinder>& id, float x, float y) {
280 Mutex::Autolock _l(mLock);
281 layer_state_t* s = getLayerStateLocked(client, id);
284 s->what |= layer_state_t::ePositionChanged;
290 status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
291 const sp<IBinder>& id, uint32_t w, uint32_t h) {
292 Mutex::Autolock _l(mLock);
293 layer_state_t* s = getLayerStateLocked(client, id);
296 s->what |= layer_state_t::eSizeChanged;
300 // Resizing a surface makes the transaction synchronous.
301 mForceSynchronous = true;
306 status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
307 const sp<IBinder>& id, uint32_t z) {
308 Mutex::Autolock _l(mLock);
309 layer_state_t* s = getLayerStateLocked(client, id);
312 s->what |= layer_state_t::eLayerChanged;
317 status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
318 const sp<IBinder>& id, uint32_t flags,
320 Mutex::Autolock _l(mLock);
321 layer_state_t* s = getLayerStateLocked(client, id);
324 if ((mask & layer_state_t::eLayerOpaque) ||
325 (mask & layer_state_t::eLayerHidden) ||
326 (mask & layer_state_t::eLayerSecure)) {
327 s->what |= layer_state_t::eFlagsChanged;
330 s->flags |= (flags & mask);
335 status_t Composer::setTransparentRegionHint(
336 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
337 const Region& transparentRegion) {
338 Mutex::Autolock _l(mLock);
339 layer_state_t* s = getLayerStateLocked(client, id);
342 s->what |= layer_state_t::eTransparentRegionChanged;
343 s->transparentRegion = transparentRegion;
347 status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
348 const sp<IBinder>& id, float alpha) {
349 Mutex::Autolock _l(mLock);
350 layer_state_t* s = getLayerStateLocked(client, id);
353 s->what |= layer_state_t::eAlphaChanged;
358 status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
359 const sp<IBinder>& id, uint32_t layerStack) {
360 Mutex::Autolock _l(mLock);
361 layer_state_t* s = getLayerStateLocked(client, id);
364 s->what |= layer_state_t::eLayerStackChanged;
365 s->layerStack = layerStack;
369 status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
370 const sp<IBinder>& id, float dsdx, float dtdx,
371 float dsdy, float dtdy) {
372 Mutex::Autolock _l(mLock);
373 layer_state_t* s = getLayerStateLocked(client, id);
376 s->what |= layer_state_t::eMatrixChanged;
377 layer_state_t::matrix22_t matrix;
386 status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
387 const sp<IBinder>& id, const Rect& crop) {
388 Mutex::Autolock _l(mLock);
389 layer_state_t* s = getLayerStateLocked(client, id);
392 s->what |= layer_state_t::eCropChanged;
397 status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
398 const sp<IBinder>& id, const Rect& crop) {
399 Mutex::Autolock _l(mLock);
400 layer_state_t* s = getLayerStateLocked(client, id);
404 s->what |= layer_state_t::eFinalCropChanged;
409 status_t Composer::deferTransactionUntil(
410 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
411 const sp<IBinder>& handle, uint64_t frameNumber) {
412 Mutex::Autolock lock(mLock);
413 layer_state_t* s = getLayerStateLocked(client, id);
417 s->what |= layer_state_t::eDeferTransaction;
419 s->frameNumber = frameNumber;
423 status_t Composer::setOverrideScalingMode(
424 const sp<SurfaceComposerClient>& client,
425 const sp<IBinder>& id, int32_t overrideScalingMode) {
426 Mutex::Autolock lock(mLock);
427 layer_state_t* s = getLayerStateLocked(client, id);
432 switch (overrideScalingMode) {
433 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
434 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
435 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
436 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
440 ALOGE("unknown scaling mode: %d",
441 overrideScalingMode);
445 s->what |= layer_state_t::eOverrideScalingModeChanged;
446 s->overrideScalingMode = overrideScalingMode;
450 status_t Composer::setGeometryAppliesWithResize(
451 const sp<SurfaceComposerClient>& client,
452 const sp<IBinder>& id) {
453 Mutex::Autolock lock(mLock);
454 layer_state_t* s = getLayerStateLocked(client, id);
458 s->what |= layer_state_t::eGeometryAppliesWithResize;
462 // ---------------------------------------------------------------------------
464 DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
467 ssize_t index = mDisplayStates.indexOf(s);
469 // we don't have it, add an initialized layer_state to our list
471 index = mDisplayStates.add(s);
473 return mDisplayStates.editItemAt(static_cast<size_t>(index));
476 void Composer::setDisplaySurface(const sp<IBinder>& token,
477 const sp<IGraphicBufferProducer>& bufferProducer) {
478 Mutex::Autolock _l(mLock);
479 DisplayState& s(getDisplayStateLocked(token));
480 s.surface = bufferProducer;
481 s.what |= DisplayState::eSurfaceChanged;
484 void Composer::setDisplayLayerStack(const sp<IBinder>& token,
485 uint32_t layerStack) {
486 Mutex::Autolock _l(mLock);
487 DisplayState& s(getDisplayStateLocked(token));
488 s.layerStack = layerStack;
489 s.what |= DisplayState::eLayerStackChanged;
492 void Composer::setDisplayProjection(const sp<IBinder>& token,
493 uint32_t orientation,
494 const Rect& layerStackRect,
495 const Rect& displayRect) {
496 Mutex::Autolock _l(mLock);
497 DisplayState& s(getDisplayStateLocked(token));
498 s.orientation = orientation;
499 s.viewport = layerStackRect;
500 s.frame = displayRect;
501 s.what |= DisplayState::eDisplayProjectionChanged;
502 mForceSynchronous = true; // TODO: do we actually still need this?
505 void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
506 Mutex::Autolock _l(mLock);
507 DisplayState& s(getDisplayStateLocked(token));
510 s.what |= DisplayState::eDisplaySizeChanged;
513 // ---------------------------------------------------------------------------
515 SurfaceComposerClient::SurfaceComposerClient()
516 : mStatus(NO_INIT), mComposer(Composer::getInstance())
520 void SurfaceComposerClient::onFirstRef() {
521 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
523 sp<ISurfaceComposerClient> conn = sm->createConnection();
531 SurfaceComposerClient::~SurfaceComposerClient() {
535 status_t SurfaceComposerClient::initCheck() const {
539 sp<IBinder> SurfaceComposerClient::connection() const {
540 return IInterface::asBinder(mClient);
543 status_t SurfaceComposerClient::linkToComposerDeath(
544 const sp<IBinder::DeathRecipient>& recipient,
545 void* cookie, uint32_t flags) {
546 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
547 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
550 void SurfaceComposerClient::dispose() {
551 // this can be called more than once.
552 sp<ISurfaceComposerClient> client;
553 Mutex::Autolock _lm(mLock);
555 client = mClient; // hold ref while lock is held
561 sp<SurfaceControl> SurfaceComposerClient::createSurface(
568 sp<SurfaceControl> sur;
569 if (mStatus == NO_ERROR) {
571 sp<IGraphicBufferProducer> gbp;
572 status_t err = mClient->createSurface(name, w, h, format, flags,
574 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
575 if (err == NO_ERROR) {
576 sur = new SurfaceControl(this, handle, gbp);
582 sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
584 return Composer::getInstance().createDisplay(displayName, secure);
587 void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
588 Composer::getInstance().destroyDisplay(display);
591 sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
592 return Composer::getInstance().getBuiltInDisplay(id);
595 status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
596 if (mStatus != NO_ERROR)
598 status_t err = mClient->destroySurface(sid);
602 status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
603 if (mStatus != NO_ERROR) {
606 return mClient->clearLayerFrameStats(token);
609 status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
610 FrameStats* outStats) const {
611 if (mStatus != NO_ERROR) {
614 return mClient->getLayerFrameStats(token, outStats);
617 status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
618 bool* outTransformToDisplayInverse) const {
619 if (mStatus != NO_ERROR) {
622 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
625 inline Composer& SurfaceComposerClient::getComposer() {
629 // ----------------------------------------------------------------------------
631 void SurfaceComposerClient::openGlobalTransaction() {
632 Composer::openGlobalTransaction();
635 void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
636 Composer::closeGlobalTransaction(synchronous);
639 void SurfaceComposerClient::setAnimationTransaction() {
640 Composer::setAnimationTransaction();
643 // ----------------------------------------------------------------------------
645 status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
646 return getComposer().setCrop(this, id, crop);
649 status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
651 return getComposer().setFinalCrop(this, id, crop);
654 status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
655 return getComposer().setPosition(this, id, x, y);
658 status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
659 return getComposer().setSize(this, id, w, h);
662 status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
663 return getComposer().setLayer(this, id, z);
666 status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
667 return getComposer().setFlags(this, id,
668 layer_state_t::eLayerHidden,
669 layer_state_t::eLayerHidden);
672 status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
673 return getComposer().setFlags(this, id,
675 layer_state_t::eLayerHidden);
678 status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
680 return getComposer().setFlags(this, id, flags, mask);
683 status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
684 const Region& transparentRegion) {
685 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
688 status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
689 return getComposer().setAlpha(this, id, alpha);
692 status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
693 return getComposer().setLayerStack(this, id, layerStack);
696 status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
697 float dsdy, float dtdy) {
698 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
701 status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
702 const sp<IBinder>& handle, uint64_t frameNumber) {
703 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
706 status_t SurfaceComposerClient::setOverrideScalingMode(
707 const sp<IBinder>& id, int32_t overrideScalingMode) {
708 return getComposer().setOverrideScalingMode(
709 this, id, overrideScalingMode);
712 status_t SurfaceComposerClient::setGeometryAppliesWithResize(
713 const sp<IBinder>& id) {
714 return getComposer().setGeometryAppliesWithResize(this, id);
717 // ----------------------------------------------------------------------------
719 void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
720 const sp<IGraphicBufferProducer>& bufferProducer) {
721 Composer::getInstance().setDisplaySurface(token, bufferProducer);
724 void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
725 uint32_t layerStack) {
726 Composer::getInstance().setDisplayLayerStack(token, layerStack);
729 void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
730 uint32_t orientation,
731 const Rect& layerStackRect,
732 const Rect& displayRect) {
733 Composer::getInstance().setDisplayProjection(token, orientation,
734 layerStackRect, displayRect);
737 void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
738 uint32_t width, uint32_t height) {
739 Composer::getInstance().setDisplaySize(token, width, height);
742 // ----------------------------------------------------------------------------
744 status_t SurfaceComposerClient::getDisplayConfigs(
745 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
747 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
750 status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
752 Vector<DisplayInfo> configs;
753 status_t result = getDisplayConfigs(display, &configs);
754 if (result != NO_ERROR) {
758 int activeId = getActiveConfig(display);
760 ALOGE("No active configuration found");
761 return NAME_NOT_FOUND;
764 *info = configs[static_cast<size_t>(activeId)];
768 int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
769 return ComposerService::getComposerService()->getActiveConfig(display);
772 status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
773 return ComposerService::getComposerService()->setActiveConfig(display, id);
776 status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
777 Vector<android_color_mode_t>* outColorModes) {
778 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
781 android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
782 return ComposerService::getComposerService()->getActiveColorMode(display);
785 status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
786 android_color_mode_t colorMode) {
787 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
790 void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
792 ComposerService::getComposerService()->setPowerMode(token, mode);
795 status_t SurfaceComposerClient::clearAnimationFrameStats() {
796 return ComposerService::getComposerService()->clearAnimationFrameStats();
799 status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
800 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
803 status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
804 HdrCapabilities* outCapabilities) {
805 return ComposerService::getComposerService()->getHdrCapabilities(display,
809 // ----------------------------------------------------------------------------
811 status_t ScreenshotClient::capture(
812 const sp<IBinder>& display,
813 const sp<IGraphicBufferProducer>& producer,
814 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
815 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
816 sp<ISurfaceComposer> s(ComposerService::getComposerService());
817 if (s == NULL) return NO_INIT;
818 return s->captureScreen(display, producer, sourceCrop,
819 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
822 ScreenshotClient::ScreenshotClient()
823 : mHaveBuffer(false) {
824 memset(&mBuffer, 0, sizeof(mBuffer));
827 ScreenshotClient::~ScreenshotClient() {
828 ScreenshotClient::release();
831 sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
832 if (mCpuConsumer == NULL) {
833 sp<IGraphicBufferConsumer> consumer;
834 BufferQueue::createBufferQueue(&mProducer, &consumer);
835 mCpuConsumer = new CpuConsumer(consumer, 1);
836 mCpuConsumer->setName(String8("ScreenshotClient"));
841 status_t ScreenshotClient::update(const sp<IBinder>& display,
842 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
843 uint32_t minLayerZ, uint32_t maxLayerZ,
844 bool useIdentityTransform, uint32_t rotation) {
845 sp<ISurfaceComposer> s(ComposerService::getComposerService());
846 if (s == NULL) return NO_INIT;
847 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
850 mCpuConsumer->unlockBuffer(mBuffer);
851 memset(&mBuffer, 0, sizeof(mBuffer));
855 status_t err = s->captureScreen(display, mProducer, sourceCrop,
856 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
857 static_cast<ISurfaceComposer::Rotation>(rotation));
859 if (err == NO_ERROR) {
860 err = mCpuConsumer->lockNextBuffer(&mBuffer);
861 if (err == NO_ERROR) {
868 status_t ScreenshotClient::update(const sp<IBinder>& display,
869 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
870 uint32_t minLayerZ, uint32_t maxLayerZ,
871 bool useIdentityTransform) {
873 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
874 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
877 status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
878 bool useIdentityTransform) {
879 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
880 useIdentityTransform, ISurfaceComposer::eRotateNone);
883 status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
884 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
885 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
886 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
889 void ScreenshotClient::release() {
891 mCpuConsumer->unlockBuffer(mBuffer);
892 memset(&mBuffer, 0, sizeof(mBuffer));
895 mCpuConsumer.clear();
898 void const* ScreenshotClient::getPixels() const {
902 uint32_t ScreenshotClient::getWidth() const {
903 return mBuffer.width;
906 uint32_t ScreenshotClient::getHeight() const {
907 return mBuffer.height;
910 PixelFormat ScreenshotClient::getFormat() const {
911 return mBuffer.format;
914 uint32_t ScreenshotClient::getStride() const {
915 return mBuffer.stride;
918 size_t ScreenshotClient::getSize() const {
919 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
922 // ----------------------------------------------------------------------------
923 }; // namespace android