Bug 946245 - Port GonkDisplay to KK, r=mwu,sotaro,pchang

This commit is contained in:
Solomon Chiu 2014-01-09 18:42:54 +08:00
parent 72760e2144
commit 517e1fd1b3
4 changed files with 75 additions and 14 deletions

View File

@ -44,13 +44,33 @@ void
ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
const paramType& aParam)
{
#if ANDROID_VERSION >= 19
sp<GraphicBuffer> flattenable = aParam.mGraphicBuffer;
#else
Flattenable *flattenable = aParam.mGraphicBuffer.get();
#endif
size_t nbytes = flattenable->getFlattenedSize();
size_t nfds = flattenable->getFdCount();
char data[nbytes];
int fds[nfds];
#if ANDROID_VERSION >= 19
// Make a copy of "data" and "fds" for flatten() to avoid casting problem
void *pdata = (void *)data;
int *pfds = fds;
flattenable->flatten(pdata, nbytes, pfds, nfds);
// In Kitkat, flatten() will change the value of nbytes and nfds, which dues
// to multiple parcelable object consumption. The actual size and fd count
// which returned by getFlattenedSize() and getFdCount() are not changed.
// So we change nbytes and nfds back by call corresponding calls.
nbytes = flattenable->getFlattenedSize();
nfds = flattenable->getFdCount();
#else
flattenable->flatten(data, nbytes, fds, nfds);
#endif
aMsg->WriteSize(nbytes);
aMsg->WriteSize(nfds);
@ -96,9 +116,17 @@ ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
}
sp<GraphicBuffer> buffer(new GraphicBuffer());
#if ANDROID_VERSION >= 19
// Make a copy of "data" and "fds" for unflatten() to avoid casting problem
void const *pdata = (void const *)data;
int const *pfds = fds;
if (NO_ERROR == buffer->unflatten(pdata, nbytes, pfds, nfds)) {
#else
Flattenable *flattenable = buffer.get();
if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) {
#endif
aResult->mGraphicBuffer = buffer;
return true;
}

View File

@ -49,30 +49,44 @@ namespace android {
* This implements the (main) framebuffer management. This class
* was adapted from the version in SurfaceFlinger
*/
FramebufferSurface::FramebufferSurface(int disp, uint32_t width, uint32_t height, uint32_t format, sp<IGraphicBufferAlloc>& alloc) :
ConsumerBase(new BufferQueue(true, alloc)),
FramebufferSurface::FramebufferSurface(int disp, uint32_t width, uint32_t height, uint32_t format,
sp<BufferQueue>& bq) :
#if ANDROID_VERSION >= 19
ConsumerBase(bq, true),
#else
ConsumerBase(bq),
#endif
mDisplayType(disp),
mCurrentBufferSlot(-1),
mCurrentBuffer(0),
lastHandle(0)
{
mName = "FramebufferSurface";
mBufferQueue->setConsumerName(mName);
mBufferQueue->setConsumerUsageBits(GRALLOC_USAGE_HW_FB |
GRALLOC_USAGE_HW_RENDER |
GRALLOC_USAGE_HW_COMPOSER);
mBufferQueue->setDefaultBufferFormat(format);
mBufferQueue->setDefaultBufferSize(width, height);
mBufferQueue->setSynchronousMode(true);
mBufferQueue->setDefaultMaxBufferCount(NUM_FRAMEBUFFER_SURFACE_BUFFERS);
#if ANDROID_VERSION >= 19
sp<IGraphicBufferConsumer> consumer = mConsumer;
#else
sp<BufferQueue> consumer = mBufferQueue;
consumer->setSynchronousMode(true);
#endif
consumer->setConsumerName(mName);
consumer->setConsumerUsageBits(GRALLOC_USAGE_HW_FB |
GRALLOC_USAGE_HW_RENDER |
GRALLOC_USAGE_HW_COMPOSER);
consumer->setDefaultBufferFormat(format);
consumer->setDefaultBufferSize(width, height);
consumer->setDefaultMaxBufferCount(NUM_FRAMEBUFFER_SURFACE_BUFFERS);
}
status_t FramebufferSurface::nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence) {
Mutex::Autolock lock(mMutex);
BufferQueue::BufferItem item;
#if ANDROID_VERSION >= 19
status_t err = acquireBufferLocked(&item, 0);
#else
status_t err = acquireBufferLocked(&item);
#endif
if (err == BufferQueue::NO_BUFFER_AVAILABLE) {
outBuffer = mCurrentBuffer;
return NO_ERROR;
@ -92,8 +106,13 @@ status_t FramebufferSurface::nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>&
if (mCurrentBufferSlot != BufferQueue::INVALID_BUFFER_SLOT &&
item.mBuf != mCurrentBufferSlot) {
// Release the previous buffer.
#if ANDROID_VERSION >= 19
err = releaseBufferLocked(mCurrentBufferSlot, mCurrentBuffer,
EGL_NO_DISPLAY, EGL_NO_SYNC_KHR);
#else
err = releaseBufferLocked(mCurrentBufferSlot, EGL_NO_DISPLAY,
EGL_NO_SYNC_KHR);
#endif
if (err != NO_ERROR && err != BufferQueue::STALE_BUFFER_SLOT) {
ALOGE("error releasing buffer: %s (%d)", strerror(-err), err);
return err;
@ -136,7 +155,11 @@ status_t FramebufferSurface::setReleaseFenceFd(int fenceFd) {
if (fenceFd >= 0) {
sp<Fence> fence(new Fence(fenceFd));
if (mCurrentBufferSlot != BufferQueue::INVALID_BUFFER_SLOT) {
#if ANDROID_VERSION >= 19
status_t err = addReleaseFence(mCurrentBufferSlot, mCurrentBuffer, fence);
#else
status_t err = addReleaseFence(mCurrentBufferSlot, fence);
#endif
ALOGE_IF(err, "setReleaseFenceFd: failed to add the fence: %s (%d)",
strerror(-err), err);
}
@ -158,6 +181,10 @@ void FramebufferSurface::dump(String8& result) {
ConsumerBase::dump(result);
}
void FramebufferSurface::dump(String8& result, const char* prefix) {
ConsumerBase::dump(result);
}
// ----------------------------------------------------------------------------
}; // namespace android
// ----------------------------------------------------------------------------

View File

@ -34,13 +34,14 @@ class HWComposer;
class FramebufferSurface : public ConsumerBase {
public:
FramebufferSurface(int disp, uint32_t width, uint32_t height, uint32_t format, sp<IGraphicBufferAlloc>& alloc);
FramebufferSurface(int disp, uint32_t width, uint32_t height, uint32_t format, sp<BufferQueue>& bq);
bool isUpdateOnDemand() const { return false; }
status_t setUpdateRectangle(const Rect& updateRect);
status_t compositionComplete();
virtual void dump(String8& result);
virtual void dump(String8& result, const char* prefix);
// setReleaseFenceFd stores a fence file descriptor that will signal when the
// current buffer is no longer being read. This fence will be returned to

View File

@ -114,12 +114,17 @@ GonkDisplayJB::GonkDisplayJB()
mBootAnimBuffer = mAlloc->createGraphicBuffer(mWidth, mHeight, surfaceformat, usage, &error);
}
mFBSurface = new FramebufferSurface(0, mWidth, mHeight, surfaceformat, mAlloc);
#if ANDROID_VERSION >= 19
sp<BufferQueue> bq = new BufferQueue(mAlloc);
#else
sp<BufferQueue> bq = new BufferQueue(true, mAlloc);
#endif
mFBSurface = new FramebufferSurface(0, mWidth, mHeight, surfaceformat, bq);
#if ANDROID_VERSION == 17
sp<SurfaceTextureClient> stc = new SurfaceTextureClient(static_cast<sp<ISurfaceTexture> >(mFBSurface->getBufferQueue()));
#else
sp<Surface> stc = new Surface(static_cast<sp<IGraphicBufferProducer> >(mFBSurface->getBufferQueue()));
sp<Surface> stc = new Surface(static_cast<sp<IGraphicBufferProducer> >(bq));
#endif
mSTClient = stc;