Skip to content

Commit a2977c3

Browse files
pixelflingerAndroid (Google) Code Review
authored andcommitted
Merge changes Ie03796ae,Ide3e980a into gingerbread
* changes: [3171580] SurfaceFlinger Bypass mode. (DO NOT MERGE) [3171580] Add transform field to native buffers. (DO NOT MERGE)
2 parents 05813b0 + 025005f commit a2977c3

File tree

11 files changed

+201
-19
lines changed

11 files changed

+201
-19
lines changed

include/ui/GraphicBuffer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <utils/Flattenable.h>
2727
#include <pixelflinger/pixelflinger.h>
2828

29+
#include <hardware/hardware.h>
30+
2931
struct android_native_buffer_t;
3032

3133
namespace android {
@@ -63,6 +65,13 @@ class GraphicBuffer
6365
USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
6466
};
6567

68+
enum {
69+
TRANSFORM_IDENTITY = 0,
70+
TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
71+
TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
72+
TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270
73+
};
74+
6675
GraphicBuffer();
6776

6877
// creates w * h buffer
@@ -79,6 +88,7 @@ class GraphicBuffer
7988
uint32_t getHeight() const { return height; }
8089
uint32_t getStride() const { return stride; }
8190
uint32_t getUsage() const { return usage; }
91+
uint32_t getTransform() const { return transform; }
8292
PixelFormat getPixelFormat() const { return format; }
8393
Rect getBounds() const { return Rect(width, height); }
8494

include/ui/android_native_buffer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ typedef struct android_native_buffer_t
5151
int stride;
5252
int format;
5353
int usage;
54-
55-
void* reserved[2];
54+
55+
/* transformation as defined in hardware.h */
56+
uint8_t transform;
57+
58+
uint8_t reserved_bytes[3];
59+
void* reserved[1];
5660

5761
buffer_handle_t handle;
5862

libs/ui/GraphicBuffer.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ GraphicBuffer::GraphicBuffer()
4545
stride =
4646
format =
4747
usage = 0;
48+
transform = 0;
4849
handle = NULL;
4950
}
5051

@@ -57,7 +58,8 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h,
5758
height =
5859
stride =
5960
format =
60-
usage = 0;
61+
usage =
62+
transform = 0;
6163
handle = NULL;
6264
mInitCheck = initSize(w, h, reqFormat, reqUsage);
6365
}
@@ -74,6 +76,7 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h,
7476
stride = inStride;
7577
format = inFormat;
7678
usage = inUsage;
79+
transform = 0;
7780
handle = inHandle;
7881
}
7982

@@ -182,8 +185,10 @@ status_t GraphicBuffer::lock(GGLSurface* sur, uint32_t usage)
182185
return res;
183186
}
184187

188+
const int kFlattenFdsOffset = 9;
189+
185190
size_t GraphicBuffer::getFlattenedSize() const {
186-
return (8 + (handle ? handle->numInts : 0))*sizeof(int);
191+
return (kFlattenFdsOffset + (handle ? handle->numInts : 0))*sizeof(int);
187192
}
188193

189194
size_t GraphicBuffer::getFdCount() const {
@@ -208,13 +213,14 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size,
208213
buf[5] = usage;
209214
buf[6] = 0;
210215
buf[7] = 0;
216+
buf[8] = transform;
211217

212218
if (handle) {
213219
buf[6] = handle->numFds;
214220
buf[7] = handle->numInts;
215221
native_handle_t const* const h = handle;
216222
memcpy(fds, h->data, h->numFds*sizeof(int));
217-
memcpy(&buf[8], h->data + h->numFds, h->numInts*sizeof(int));
223+
memcpy(&buf[kFlattenFdsOffset], h->data + h->numFds, h->numInts*sizeof(int));
218224
}
219225

220226
return NO_ERROR;
@@ -223,15 +229,15 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size,
223229
status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
224230
int fds[], size_t count)
225231
{
226-
if (size < 8*sizeof(int)) return NO_MEMORY;
232+
if (size < kFlattenFdsOffset*sizeof(int)) return NO_MEMORY;
227233

228234
int const* buf = static_cast<int const*>(buffer);
229235
if (buf[0] != 'GBFR') return BAD_TYPE;
230236

231237
const size_t numFds = buf[6];
232238
const size_t numInts = buf[7];
233239

234-
const size_t sizeNeeded = (8 + numInts) * sizeof(int);
240+
const size_t sizeNeeded = (kFlattenFdsOffset + numInts) * sizeof(int);
235241
if (size < sizeNeeded) return NO_MEMORY;
236242

237243
size_t fdCountNeeded = 0;
@@ -248,9 +254,10 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
248254
stride = buf[3];
249255
format = buf[4];
250256
usage = buf[5];
257+
transform = buf[8];
251258
native_handle* h = native_handle_create(numFds, numInts);
252259
memcpy(h->data, fds, numFds*sizeof(int));
253-
memcpy(h->data + numFds, &buf[8], numInts*sizeof(int));
260+
memcpy(h->data + numFds, &buf[kFlattenFdsOffset], numInts*sizeof(int));
254261
handle = h;
255262
} else {
256263
width = height = stride = format = usage = 0;

services/surfaceflinger/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ifeq ($(TARGET_BOARD_PLATFORM), omap3)
2525
endif
2626
ifeq ($(TARGET_BOARD_PLATFORM), s5pc110)
2727
LOCAL_CFLAGS += -DHAS_CONTEXT_PRIORITY
28+
LOCAL_CFLAGS += -DUSE_COMPOSITION_BYPASS
2829
endif
2930

3031

services/surfaceflinger/DisplayHardware/DisplayHardware.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ void DisplayHardware::flip(const Region& dirty) const
339339
//glClear(GL_COLOR_BUFFER_BIT);
340340
}
341341

342+
status_t DisplayHardware::postBypassBuffer(const native_handle_t* handle) const
343+
{
344+
framebuffer_device_t *fbDev = (framebuffer_device_t *)mNativeWindow->getDevice();
345+
return fbDev->post(fbDev, handle);
346+
}
347+
342348
uint32_t DisplayHardware::getFlags() const
343349
{
344350
return mFlags;

services/surfaceflinger/DisplayHardware/DisplayHardware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class DisplayHardware : public DisplayHardwareBase
6464
// Flip the front and back buffers if the back buffer is "dirty". Might
6565
// be instantaneous, might involve copying the frame buffer around.
6666
void flip(const Region& dirty) const;
67+
status_t postBypassBuffer(const native_handle_t* handle) const;
6768

6869
float getDpiX() const;
6970
float getDpiY() const;

services/surfaceflinger/Layer.cpp

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
392469
uint32_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
}

services/surfaceflinger/Layer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class Layer : public LayerBaseClient
8181
virtual sp<Surface> createSurface() const;
8282
virtual status_t ditch();
8383
virtual void onRemoved();
84+
virtual bool setBypass(bool enable);
85+
86+
inline sp<GraphicBuffer> getBypassBuffer() const {
87+
return mBufferManager.getActiveBuffer(); }
8488

8589
// only for debugging
8690
inline sp<GraphicBuffer> getBuffer(int i) const {
@@ -232,6 +236,7 @@ class Layer : public LayerBaseClient
232236
uint32_t mReqFormat;
233237
bool mNeedsScaling;
234238
bool mFixedSize;
239+
bool mBypassState;
235240
};
236241

237242
// ---------------------------------------------------------------------------

services/surfaceflinger/LayerBase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include <pixelflinger/pixelflinger.h>
3737

38+
#include "DisplayHardware/DisplayHardware.h"
3839
#include "Transform.h"
3940

4041
namespace android {
@@ -117,6 +118,11 @@ class LayerBase : public RefBase
117118
virtual void draw(const Region& clip) const;
118119
virtual void drawForSreenShot() const;
119120

121+
/**
122+
* bypass mode
123+
*/
124+
virtual bool setBypass(bool enable) { return false; }
125+
120126
/**
121127
* onDraw - draws the surface.
122128
*/

0 commit comments

Comments
 (0)