Bug 946245 - Port GonkDisplay to KK, r=mwu,sotaro,pchang
authorSolomon Chiu <schiu@mozilla.com>
Thu, 09 Jan 2014 18:42:54 +0800
changeset 163115 4c2fe1a97191f8d36c41f05e09c7b0e8380a6ee3
parent 163114 e9a7aaad1771e987f2b78eef42009256f103c0d7
child 163116 11f424f343cf427e9addb6446c45ced2a4fc0fea
push id25982
push userryanvm@gmail.com
push dateMon, 13 Jan 2014 22:30:39 +0000
treeherdermozilla-central@d524c4b2cbb8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu, sotaro, pchang
bugs946245
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 946245 - Port GonkDisplay to KK, r=mwu,sotaro,pchang
gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp
widget/gonk/libdisplay/FramebufferSurface.cpp
widget/gonk/libdisplay/FramebufferSurface.h
widget/gonk/libdisplay/GonkDisplayJB.cpp
--- a/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp
+++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp
@@ -39,23 +39,43 @@ using namespace mozilla::layers;
 using namespace mozilla::gl;
 
 namespace IPC {
 
 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);
 
   aMsg->WriteBytes(data, nbytes);
   for (size_t n = 0; n < nfds; ++n) {
     // These buffers can't die in transit because they're created
     // synchonously and the parent-side buffer can only be dropped if
@@ -91,19 +111,27 @@ ParamTraits<MagicGrallocBufferHandle>::R
     // deal with it here.  NB: only the "default" (master) process can
     // alloc gralloc buffers.
     bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default);
     int dupFd = sameProcess ? dup(fd.fd) : fd.fd;
     fds[n] = dupFd;
   }
 
   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;
   }
   return false;
 }
 
 } // namespace IPC
 
--- a/widget/gonk/libdisplay/FramebufferSurface.cpp
+++ b/widget/gonk/libdisplay/FramebufferSurface.cpp
@@ -44,40 +44,54 @@
 // ----------------------------------------------------------------------------
 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;
     } else if (err != NO_ERROR) {
         ALOGE("error acquiring buffer: %s (%d)", strerror(-err), err);
         return err;
     }
 
@@ -87,18 +101,23 @@ status_t FramebufferSurface::nextBuffer(
     // would have returned STALE_BUFFER_SLOT, and we would have called
     // freeBufferLocked on that slot.  Because the buffer slot has already
     // been overwritten with the new buffer all we have to do is skip the
     // releaseBuffer call and we should be in the same state we'd be in if we
     // had released the old buffer first.
     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;
         }
     }
     mCurrentBufferSlot = item.mBuf;
     mCurrentBuffer = mSlots[mCurrentBufferSlot].mGraphicBuffer;
     outFence = item.mFence;
@@ -131,17 +150,21 @@ void FramebufferSurface::freeBufferLocke
     }
 }
 
 status_t FramebufferSurface::setReleaseFenceFd(int fenceFd) {
     status_t err = NO_ERROR;
     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);
         }
     }
     return err;
 }
 
 status_t FramebufferSurface::setUpdateRectangle(const Rect& r)
@@ -153,11 +176,15 @@ status_t FramebufferSurface::composition
 {
     return NO_ERROR;
 }
 
 void FramebufferSurface::dump(String8& result) {
     ConsumerBase::dump(result);
 }
 
+void FramebufferSurface::dump(String8& result, const char* prefix) {
+    ConsumerBase::dump(result);
+}
+
 // ----------------------------------------------------------------------------
 }; // namespace android
 // ----------------------------------------------------------------------------
--- a/widget/gonk/libdisplay/FramebufferSurface.h
+++ b/widget/gonk/libdisplay/FramebufferSurface.h
@@ -29,23 +29,24 @@ namespace android {
 class Rect;
 class String8;
 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
     // the producer when the current buffer is released by updateTexImage().
     // Multiple fences can be set for a given buffer; they will be merged into
     // a single union fence. The SurfaceTexture will close the file descriptor
     // when finished with it.
     status_t setReleaseFenceFd(int fenceFd);
--- a/widget/gonk/libdisplay/GonkDisplayJB.cpp
+++ b/widget/gonk/libdisplay/GonkDisplayJB.cpp
@@ -109,22 +109,27 @@ GonkDisplayJB::GonkDisplayJB()
     uint32_t usage = GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER;
     mBootAnimBuffer = mAlloc->createGraphicBuffer(mWidth, mHeight, surfaceformat, usage, &error);
     if (error != NO_ERROR || !mBootAnimBuffer.get()) {
         ALOGI("Trying to create BRGA format framebuffer");
         surfaceformat = HAL_PIXEL_FORMAT_BGRA_8888;
         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;
 
     mList = (hwc_display_contents_1_t *)malloc(sizeof(*mList) + (sizeof(hwc_layer_1_t)*2));
     if (mHwc)
         mHwc->blank(mHwc, HWC_DISPLAY_PRIMARY, 0);
 
     if (error == NO_ERROR && mBootAnimBuffer.get()) {