"git@repo.buzztime.com:halo/packages_apps_launcher2.git" did not exist on "e8697d95fa5f9ba97a1e2bd15f4960d4e59d2213"
SurfaceComposerClient.cpp 20.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "SurfaceComposerClient"

#include <stdint.h>
#include <sys/types.h>

#include <utils/Errors.h>
23
#include <utils/Log.h>
24
#include <utils/Singleton.h>
25 26 27
#include <utils/SortedVector.h>
#include <utils/String8.h>
#include <utils/threads.h>
28

29
#include <binder/IMemory.h>
30
#include <binder/IServiceManager.h>
31

32
#include <ui/DisplayInfo.h>
33

34
#include <gui/IGraphicBufferProducer.h>
Mathias Agopian's avatar
Mathias Agopian committed
35 36 37 38
#include <gui/ISurface.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposerClient.h>
#include <gui/SurfaceComposerClient.h>
39

40
#include <private/gui/ComposerService.h>
Mathias Agopian's avatar
Mathias Agopian committed
41
#include <private/gui/LayerState.h>
42 43 44 45

namespace android {
// ---------------------------------------------------------------------------

46
ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
47

48 49
ComposerService::ComposerService()
: Singleton<ComposerService>() {
Andy McFadden's avatar
Andy McFadden committed
50 51 52 53 54
    Mutex::Autolock _l(mLock);
    connectLocked();
}

void ComposerService::connectLocked() {
55 56 57
    const String16 name("SurfaceFlinger");
    while (getService(name, &mComposerService) != NO_ERROR) {
        usleep(250000);
58
    }
Andy McFadden's avatar
Andy McFadden committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    assert(mComposerService != NULL);

    // Create the death listener.
    class DeathObserver : public IBinder::DeathRecipient {
        ComposerService& mComposerService;
        virtual void binderDied(const wp<IBinder>& who) {
            ALOGW("ComposerService remote (surfaceflinger) died [%p]",
                  who.unsafe_get());
            mComposerService.composerServiceDied();
        }
     public:
        DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
    };

    mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
    mComposerService->asBinder()->linkToDeath(mDeathObserver);
}

/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
    ComposerService& instance = ComposerService::getInstance();
    Mutex::Autolock _l(instance.mLock);
    if (instance.mComposerService == NULL) {
        ComposerService::getInstance().connectLocked();
        assert(instance.mComposerService != NULL);
        ALOGD("ComposerService reconnected");
    }
    return instance.mComposerService;
86
}
87

Andy McFadden's avatar
Andy McFadden committed
88 89 90 91 92
void ComposerService::composerServiceDied()
{
    Mutex::Autolock _l(mLock);
    mComposerService = NULL;
    mDeathObserver = NULL;
93
}
94 95 96

// ---------------------------------------------------------------------------

97
static inline
Mathias Agopian's avatar
Mathias Agopian committed
98
int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
99 100 101 102 103 104 105
    if (lhs.client < rhs.client)  return -1;
    if (lhs.client > rhs.client)  return 1;
    if (lhs.state.surface < rhs.state.surface)  return -1;
    if (lhs.state.surface > rhs.state.surface)  return 1;
    return 0;
}

Mathias Agopian's avatar
Mathias Agopian committed
106 107 108 109 110
static inline
int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
    return compare_type(lhs.token, rhs.token);
}

111 112
class Composer : public Singleton<Composer>
{
113
    friend class Singleton<Composer>;
114

115
    mutable Mutex               mLock;
Mathias Agopian's avatar
Mathias Agopian committed
116 117
    SortedVector<ComposerState> mComposerStates;
    SortedVector<DisplayState > mDisplayStates;
118
    uint32_t                    mForceSynchronous;
119
    uint32_t                    mTransactionNestCount;
120
    bool                        mAnimation;
121

122
    Composer() : Singleton<Composer>(),
123
        mForceSynchronous(0), mTransactionNestCount(0),
124
        mAnimation(false)
125
    { }
126

127
    void openGlobalTransactionImpl();
128
    void closeGlobalTransactionImpl(bool synchronous);
129
    void setAnimationTransactionImpl();
130

131
    layer_state_t* getLayerStateLocked(
132
            const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
133

Mathias Agopian's avatar
Mathias Agopian committed
134 135
    DisplayState& getDisplayStateLocked(const sp<IBinder>& token);

136
public:
137
    sp<IBinder> createDisplay(const String8& displayName, bool secure);
138
    sp<IBinder> getBuiltInDisplay(int32_t id);
139

140
    status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
141
            float x, float y);
142
    status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
143
            uint32_t w, uint32_t h);
144
    status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
145
            int32_t z);
146
    status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
147 148
            uint32_t flags, uint32_t mask);
    status_t setTransparentRegionHint(
149
            const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
150
            const Region& transparentRegion);
151
    status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
152
            float alpha);
153
    status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
154
            float dsdx, float dtdx, float dsdy, float dtdy);
155
    status_t setOrientation(int orientation);
156
    status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
157
            const Rect& crop);
158
    status_t setLayerStack(const sp<SurfaceComposerClient>& client,
159
            const sp<IBinder>& id, uint32_t layerStack);
160

161 162
    void setDisplaySurface(const sp<IBinder>& token,
            const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopian's avatar
Mathias Agopian committed
163
    void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
164 165 166 167
    void setDisplayProjection(const sp<IBinder>& token,
            uint32_t orientation,
            const Rect& layerStackRect,
            const Rect& displayRect);
Mathias Agopian's avatar
Mathias Agopian committed
168

169 170 171 172
    static void setAnimationTransaction() {
        Composer::getInstance().setAnimationTransactionImpl();
    }

173 174 175 176
    static void openGlobalTransaction() {
        Composer::getInstance().openGlobalTransactionImpl();
    }

177 178
    static void closeGlobalTransaction(bool synchronous) {
        Composer::getInstance().closeGlobalTransactionImpl(synchronous);
179
    }
180 181 182 183
};

ANDROID_SINGLETON_STATIC_INSTANCE(Composer);

184 185
// ---------------------------------------------------------------------------

186 187 188
sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
    return ComposerService::getComposerService()->createDisplay(displayName,
            secure);
Mathias Agopian's avatar
Mathias Agopian committed
189 190
}

191 192 193 194
sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
    return ComposerService::getComposerService()->getBuiltInDisplay(id);
}

195 196 197 198 199 200 201
void Composer::openGlobalTransactionImpl() {
    { // scope for the lock
        Mutex::Autolock _l(mLock);
        mTransactionNestCount += 1;
    }
}

202
void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopian's avatar
Mathias Agopian committed
203
    sp<ISurfaceComposer> sm(ComposerService::getComposerService());
204 205

    Vector<ComposerState> transaction;
206
    Vector<DisplayState> displayTransaction;
207
    uint32_t flags = 0;
208 209 210

    { // scope for the lock
        Mutex::Autolock _l(mLock);
211 212 213 214 215 216 217 218
        mForceSynchronous |= synchronous;
        if (!mTransactionNestCount) {
            ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
                    "call to openGlobalTransaction().");
        } else if (--mTransactionNestCount) {
            return;
        }

Mathias Agopian's avatar
Mathias Agopian committed
219 220
        transaction = mComposerStates;
        mComposerStates.clear();
221

Mathias Agopian's avatar
Mathias Agopian committed
222 223
        displayTransaction = mDisplayStates;
        mDisplayStates.clear();
224

225
        if (mForceSynchronous) {
226 227
            flags |= ISurfaceComposer::eSynchronous;
        }
228 229 230 231
        if (mAnimation) {
            flags |= ISurfaceComposer::eAnimation;
        }

232
        mForceSynchronous = false;
233
        mAnimation = false;
234 235
    }

236
   sm->setTransactionState(transaction, displayTransaction, flags);
237 238
}

239 240 241 242 243
void Composer::setAnimationTransactionImpl() {
    Mutex::Autolock _l(mLock);
    mAnimation = true;
}

244
layer_state_t* Composer::getLayerStateLocked(
245
        const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
246 247 248 249 250

    ComposerState s;
    s.client = client->mClient;
    s.state.surface = id;

Mathias Agopian's avatar
Mathias Agopian committed
251
    ssize_t index = mComposerStates.indexOf(s);
252 253
    if (index < 0) {
        // we don't have it, add an initialized layer_state to our list
Mathias Agopian's avatar
Mathias Agopian committed
254
        index = mComposerStates.add(s);
255 256
    }

Mathias Agopian's avatar
Mathias Agopian committed
257
    ComposerState* const out = mComposerStates.editArray();
258 259 260 261
    return &(out[index].state);
}

status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
262
        const sp<IBinder>& id, float x, float y) {
263 264 265 266
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
267
    s->what |= layer_state_t::ePositionChanged;
268 269 270 271 272 273
    s->x = x;
    s->y = y;
    return NO_ERROR;
}

status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
274
        const sp<IBinder>& id, uint32_t w, uint32_t h) {
275 276 277 278
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
279
    s->what |= layer_state_t::eSizeChanged;
280 281
    s->w = w;
    s->h = h;
282 283 284 285

    // Resizing a surface makes the transaction synchronous.
    mForceSynchronous = true;

286 287 288 289
    return NO_ERROR;
}

status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
290
        const sp<IBinder>& id, int32_t z) {
291 292 293 294
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
295
    s->what |= layer_state_t::eLayerChanged;
296 297 298 299 300
    s->z = z;
    return NO_ERROR;
}

status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
301
        const sp<IBinder>& id, uint32_t flags,
302 303 304 305 306
        uint32_t mask) {
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
307
    s->what |= layer_state_t::eVisibilityChanged;
308 309 310 311 312 313 314
    s->flags &= ~mask;
    s->flags |= (flags & mask);
    s->mask |= mask;
    return NO_ERROR;
}

status_t Composer::setTransparentRegionHint(
315
        const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
316 317 318 319 320
        const Region& transparentRegion) {
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
321
    s->what |= layer_state_t::eTransparentRegionChanged;
322 323 324 325 326
    s->transparentRegion = transparentRegion;
    return NO_ERROR;
}

status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
327
        const sp<IBinder>& id, float alpha) {
328 329 330 331
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
332
    s->what |= layer_state_t::eAlphaChanged;
333 334 335 336
    s->alpha = alpha;
    return NO_ERROR;
}

337
status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
338
        const sp<IBinder>& id, uint32_t layerStack) {
339 340 341 342
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
343
    s->what |= layer_state_t::eLayerStackChanged;
344 345 346 347
    s->layerStack = layerStack;
    return NO_ERROR;
}

348
status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
349
        const sp<IBinder>& id, float dsdx, float dtdx,
350 351 352 353 354
        float dsdy, float dtdy) {
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
355
    s->what |= layer_state_t::eMatrixChanged;
356 357 358 359 360 361 362
    layer_state_t::matrix22_t matrix;
    matrix.dsdx = dsdx;
    matrix.dtdx = dtdx;
    matrix.dsdy = dsdy;
    matrix.dtdy = dtdy;
    s->matrix = matrix;
    return NO_ERROR;
363 364
}

365
status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
366
        const sp<IBinder>& id, const Rect& crop) {
367 368 369 370
    Mutex::Autolock _l(mLock);
    layer_state_t* s = getLayerStateLocked(client, id);
    if (!s)
        return BAD_INDEX;
Mathias Agopian's avatar
Mathias Agopian committed
371
    s->what |= layer_state_t::eCropChanged;
372 373 374 375
    s->crop = crop;
    return NO_ERROR;
}

376 377
// ---------------------------------------------------------------------------

Mathias Agopian's avatar
Mathias Agopian committed
378 379 380 381 382 383 384 385 386 387 388 389 390
DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
    DisplayState s;
    s.token = token;
    ssize_t index = mDisplayStates.indexOf(s);
    if (index < 0) {
        // we don't have it, add an initialized layer_state to our list
        s.what = 0;
        index = mDisplayStates.add(s);
    }
    return mDisplayStates.editItemAt(index);
}

void Composer::setDisplaySurface(const sp<IBinder>& token,
391
        const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopian's avatar
Mathias Agopian committed
392 393
    Mutex::Autolock _l(mLock);
    DisplayState& s(getDisplayStateLocked(token));
394
    s.surface = bufferProducer;
Mathias Agopian's avatar
Mathias Agopian committed
395 396 397 398 399 400 401 402 403 404 405
    s.what |= DisplayState::eSurfaceChanged;
}

void Composer::setDisplayLayerStack(const sp<IBinder>& token,
        uint32_t layerStack) {
    Mutex::Autolock _l(mLock);
    DisplayState& s(getDisplayStateLocked(token));
    s.layerStack = layerStack;
    s.what |= DisplayState::eLayerStackChanged;
}

406 407 408 409
void Composer::setDisplayProjection(const sp<IBinder>& token,
        uint32_t orientation,
        const Rect& layerStackRect,
        const Rect& displayRect) {
Mathias Agopian's avatar
Mathias Agopian committed
410 411 412
    Mutex::Autolock _l(mLock);
    DisplayState& s(getDisplayStateLocked(token));
    s.orientation = orientation;
413 414 415
    s.viewport = layerStackRect;
    s.frame = displayRect;
    s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopian's avatar
Mathias Agopian committed
416 417 418 419 420
    mForceSynchronous = true; // TODO: do we actually still need this?
}

// ---------------------------------------------------------------------------

421
SurfaceComposerClient::SurfaceComposerClient()
422
    : mStatus(NO_INIT), mComposer(Composer::getInstance())
423 424 425
{
}

426
void SurfaceComposerClient::onFirstRef() {
Mathias Agopian's avatar
Mathias Agopian committed
427
    sp<ISurfaceComposer> sm(ComposerService::getComposerService());
428
    if (sm != 0) {
429
        sp<ISurfaceComposerClient> conn = sm->createConnection();
430 431 432 433
        if (conn != 0) {
            mClient = conn;
            mStatus = NO_ERROR;
        }
434 435 436
    }
}

437
SurfaceComposerClient::~SurfaceComposerClient() {
438
    dispose();
439 440
}

441
status_t SurfaceComposerClient::initCheck() const {
442 443 444
    return mStatus;
}

445
sp<IBinder> SurfaceComposerClient::connection() const {
446 447 448
    return (mClient != 0) ? mClient->asBinder() : 0;
}

449 450
status_t SurfaceComposerClient::linkToComposerDeath(
        const sp<IBinder::DeathRecipient>& recipient,
451
        void* cookie, uint32_t flags) {
Mathias Agopian's avatar
Mathias Agopian committed
452
    sp<ISurfaceComposer> sm(ComposerService::getComposerService());
453
    return sm->asBinder()->linkToDeath(recipient, cookie, flags);
454 455
}

456
void SurfaceComposerClient::dispose() {
457
    // this can be called more than once.
458
    sp<ISurfaceComposerClient> client;
459 460 461 462
    Mutex::Autolock _lm(mLock);
    if (mClient != 0) {
        client = mClient; // hold ref while lock is held
        mClient.clear();
463
    }
464
    mStatus = NO_INIT;
465 466
}

467 468 469 470 471 472
sp<SurfaceControl> SurfaceComposerClient::createSurface(
        const String8& name,
        uint32_t w,
        uint32_t h,
        PixelFormat format,
        uint32_t flags)
473
{
474
    sp<SurfaceControl> result;
475
    if (mStatus == NO_ERROR) {
476
        sp<ISurface> surface = mClient->createSurface(name, w, h, format, flags);
477
        if (surface != 0) {
478
            result = new SurfaceControl(this, surface);
479 480 481 482 483
        }
    }
    return result;
}

484 485 486
sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
        bool secure) {
    return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopian's avatar
Mathias Agopian committed
487 488
}

489 490 491 492
sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
    return Composer::getInstance().getBuiltInDisplay(id);
}

493
status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
494 495 496 497 498 499
    if (mStatus != NO_ERROR)
        return mStatus;
    status_t err = mClient->destroySurface(sid);
    return err;
}

500 501
inline Composer& SurfaceComposerClient::getComposer() {
    return mComposer;
502 503
}

504
// ----------------------------------------------------------------------------
505

506
void SurfaceComposerClient::openGlobalTransaction() {
507
    Composer::openGlobalTransaction();
508 509
}

510 511
void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
    Composer::closeGlobalTransaction(synchronous);
512 513
}

514 515 516 517
void SurfaceComposerClient::setAnimationTransaction() {
    Composer::setAnimationTransaction();
}

518
// ----------------------------------------------------------------------------
519

520
status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
521 522 523
    return getComposer().setCrop(this, id, crop);
}

524
status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
525 526
    return getComposer().setPosition(this, id, x, y);
}
527

528
status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
529 530
    return getComposer().setSize(this, id, w, h);
}
531

532
status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
533
    return getComposer().setLayer(this, id, z);
534 535
}

536
status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
537
    return getComposer().setFlags(this, id,
Mathias Agopian's avatar
Mathias Agopian committed
538 539
            layer_state_t::eLayerHidden,
            layer_state_t::eLayerHidden);
540
}
541

542
status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
543 544
    return getComposer().setFlags(this, id,
            0,
Mathias Agopian's avatar
Mathias Agopian committed
545
            layer_state_t::eLayerHidden);
546 547
}

548
status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
549 550
        uint32_t mask) {
    return getComposer().setFlags(this, id, flags, mask);
551 552
}

553
status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
554 555
        const Region& transparentRegion) {
    return getComposer().setTransparentRegionHint(this, id, transparentRegion);
556 557
}

558
status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
559
    return getComposer().setAlpha(this, id, alpha);
560 561
}

562
status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
563 564 565
    return getComposer().setLayerStack(this, id, layerStack);
}

566
status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
567 568
        float dsdy, float dtdy) {
    return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
569 570
}

571 572
// ----------------------------------------------------------------------------

Mathias Agopian's avatar
Mathias Agopian committed
573
void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
574 575
        const sp<IGraphicBufferProducer>& bufferProducer) {
    Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopian's avatar
Mathias Agopian committed
576 577 578 579 580 581 582
}

void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
        uint32_t layerStack) {
    Composer::getInstance().setDisplayLayerStack(token, layerStack);
}

583 584 585 586 587 588
void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
        uint32_t orientation,
        const Rect& layerStackRect,
        const Rect& displayRect) {
    Composer::getInstance().setDisplayProjection(token, orientation,
            layerStackRect, displayRect);
Mathias Agopian's avatar
Mathias Agopian committed
589 590 591 592
}

// ----------------------------------------------------------------------------

593
status_t SurfaceComposerClient::getDisplayInfo(
594
        const sp<IBinder>& display, DisplayInfo* info)
595
{
596
    return ComposerService::getComposerService()->getDisplayInfo(display, info);
597 598
}

599 600 601 602 603 604 605 606
void SurfaceComposerClient::blankDisplay(const sp<IBinder>& token) {
    ComposerService::getComposerService()->blank(token);
}

void SurfaceComposerClient::unblankDisplay(const sp<IBinder>& token) {
    ComposerService::getComposerService()->unblank(token);
}

607 608
// ----------------------------------------------------------------------------

Mathias Agopian's avatar
Mathias Agopian committed
609 610 611 612
ScreenshotClient::ScreenshotClient()
    : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
}

613
status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian's avatar
Mathias Agopian committed
614 615 616
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    if (s == NULL) return NO_INIT;
    mHeap = 0;
617
    return s->captureScreen(display, &mHeap,
618 619
            &mWidth, &mHeight, &mFormat, 0, 0,
            0, -1UL);
Mathias Agopian's avatar
Mathias Agopian committed
620 621
}

622 623
status_t ScreenshotClient::update(const sp<IBinder>& display,
        uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian's avatar
Mathias Agopian committed
624 625 626
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    if (s == NULL) return NO_INIT;
    mHeap = 0;
627
    return s->captureScreen(display, &mHeap,
628 629 630 631
            &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
            0, -1UL);
}

632 633
status_t ScreenshotClient::update(const sp<IBinder>& display,
        uint32_t reqWidth, uint32_t reqHeight,
634 635 636 637
        uint32_t minLayerZ, uint32_t maxLayerZ) {
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    if (s == NULL) return NO_INIT;
    mHeap = 0;
638
    return s->captureScreen(display, &mHeap,
639 640
            &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
            minLayerZ, maxLayerZ);
Mathias Agopian's avatar
Mathias Agopian committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
}

void ScreenshotClient::release() {
    mHeap = 0;
}

void const* ScreenshotClient::getPixels() const {
    return mHeap->getBase();
}

uint32_t ScreenshotClient::getWidth() const {
    return mWidth;
}

uint32_t ScreenshotClient::getHeight() const {
    return mHeight;
}

PixelFormat ScreenshotClient::getFormat() const {
    return mFormat;
}

uint32_t ScreenshotClient::getStride() const {
    return mWidth;
}

size_t ScreenshotClient::getSize() const {
    return mHeap->getSize();
}

671
// ----------------------------------------------------------------------------
672
}; // namespace android