@@ -57,7 +57,8 @@ Layer::Layer(SurfaceFlinger* flinger,
5757 mSecure(false ),
5858 mTextureManager(),
5959 mBufferManager(mTextureManager ),
60- mWidth(0 ), mHeight(0 ), mNeedsScaling(false ), mFixedSize(false )
60+ mWidth(0 ), mHeight(0 ), mNeedsScaling(false ), mFixedSize(false ),
61+ mBypassState(false )
6162{
6263}
6364
@@ -251,6 +252,29 @@ void Layer::onDraw(const Region& clip) const
251252 }
252253 return ;
253254 }
255+
256+ #ifdef USE_COMPOSITION_BYPASS
257+ sp<GraphicBuffer> buffer (mBufferManager .getActiveBuffer ());
258+ if ((buffer != NULL ) && (buffer->transform )) {
259+ // Here we have a "bypass" buffer, but we need to composite it
260+ // most likely because it's not fullscreen anymore.
261+ // Since the buffer may have a transformation applied by the client
262+ // we need to inverse this transformation here.
263+
264+ // calculate the inverse of the buffer transform
265+ const uint32_t mask = HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
266+ const uint32_t bufferTransformInverse = buffer->transform ^ mask;
267+
268+ // To accomplish the inverse transform, we use "mBufferTransform"
269+ // which is not used by Layer.cpp
270+ const_cast <Layer*>(this )->mBufferTransform = bufferTransformInverse;
271+ drawWithOpenGL (clip, tex);
272+ // reset to "no transfrom"
273+ const_cast <Layer*>(this )->mBufferTransform = 0 ;
274+ return ;
275+ }
276+ #endif
277+
254278 drawWithOpenGL (clip, tex);
255279}
256280
@@ -311,11 +335,12 @@ sp<GraphicBuffer> Layer::requestBuffer(int index,
311335 * buffer 'index' as our front buffer.
312336 */
313337
314- status_t err = NO_ERROR;
315- uint32_t w, h, f;
338+ uint32_t w, h, f, bypass;
316339 { // scope for the lock
317340 Mutex::Autolock _l (mLock );
318341
342+ bypass = mBypassState ;
343+
319344 // zero means default
320345 mFixedSize = reqWidth && reqHeight;
321346 if (!reqFormat) reqFormat = mFormat ;
@@ -340,9 +365,40 @@ sp<GraphicBuffer> Layer::requestBuffer(int index,
340365 // here we have to reallocate a new buffer because the buffer could be
341366 // used as the front buffer, or by a client in our process
342367 // (eg: status bar), and we can't release the handle under its feet.
343- const uint32_t effectiveUsage = getEffectiveUsage (usage);
344- buffer = new GraphicBuffer (w, h, f, effectiveUsage);
345- err = buffer->initCheck ();
368+ uint32_t effectiveUsage = getEffectiveUsage (usage);
369+
370+ status_t err = NO_MEMORY;
371+
372+ #ifdef USE_COMPOSITION_BYPASS
373+ if (!mSecure && bypass && (effectiveUsage & GRALLOC_USAGE_HW_RENDER)) {
374+ // always allocate a buffer matching the screen size. the size
375+ // may be different from (w,h) if the buffer is rotated.
376+ const DisplayHardware& hw (graphicPlane (0 ).displayHardware ());
377+ int32_t w = hw.getWidth ();
378+ int32_t h = hw.getHeight ();
379+ int32_t f = hw.getFormat ();
380+
381+ buffer = new GraphicBuffer (w, h, f, effectiveUsage | GRALLOC_USAGE_HW_FB);
382+ err = buffer->initCheck ();
383+ buffer->transform = uint8_t (getOrientation ());
384+
385+ if (err != NO_ERROR) {
386+ // allocation didn't succeed, probably because an older bypass
387+ // window hasn't released all its resources yet.
388+ ClientRef::Access sharedClient (mUserClientRef );
389+ SharedBufferServer* lcblk (sharedClient.get ());
390+ if (lcblk) {
391+ // all buffers need reallocation
392+ lcblk->reallocateAll ();
393+ }
394+ }
395+ }
396+ #endif
397+
398+ if (err != NO_ERROR) {
399+ buffer = new GraphicBuffer (w, h, f, effectiveUsage);
400+ err = buffer->initCheck ();
401+ }
346402
347403 if (err || buffer->handle == 0 ) {
348404 GraphicBuffer::dumpAllocationsToSystemLog ();
@@ -389,6 +445,27 @@ uint32_t Layer::getEffectiveUsage(uint32_t usage) const
389445 return usage;
390446}
391447
448+ bool Layer::setBypass (bool enable)
449+ {
450+ Mutex::Autolock _l (mLock );
451+
452+ if (mNeedsScaling || mNeedsFiltering ) {
453+ return false ;
454+ }
455+
456+ if (mBypassState != enable) {
457+ mBypassState = enable;
458+ ClientRef::Access sharedClient (mUserClientRef );
459+ SharedBufferServer* lcblk (sharedClient.get ());
460+ if (lcblk) {
461+ // all buffers need reallocation
462+ lcblk->reallocateAll ();
463+ }
464+ }
465+
466+ return true ;
467+ }
468+
392469uint32_t Layer::doTransaction (uint32_t flags)
393470{
394471 const Layer::State& front (drawingState ());
@@ -639,9 +716,9 @@ void Layer::dump(String8& result, char* buffer, size_t SIZE) const
639716 snprintf (buffer, SIZE,
640717 " "
641718 " format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
642- " freezeLock=%p, dq-q-time=%u us\n " ,
719+ " freezeLock=%p, bypass=%d, dq-q-time=%u us\n " ,
643720 mFormat , w0, h0, s0, w1, h1, s1,
644- getFreezeLock ().get (), totalTime);
721+ getFreezeLock ().get (), mBypassState , totalTime);
645722
646723 result.append (buffer);
647724}
0 commit comments