diff --git a/widget/gonk/nsScreenManagerGonk.cpp b/widget/gonk/nsScreenManagerGonk.cpp index 221ff233db87..a8f0a9d33bd9 100644 --- a/widget/gonk/nsScreenManagerGonk.cpp +++ b/widget/gonk/nsScreenManagerGonk.cpp @@ -359,6 +359,39 @@ nsScreenGonk::BringToTop(nsWindow* aWindow) mTopWindows.InsertElementAt(0, aWindow); } +ANativeWindowBuffer* +nsScreenGonk::DequeueBuffer() +{ + ANativeWindowBuffer* buf = nullptr; +#if ANDROID_VERSION >= 17 + int fenceFd = -1; + mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buf, &fenceFd); + android::sp fence(new android::Fence(fenceFd)); +#if ANDROID_VERSION == 17 + fence->waitForever(1000, "nsScreenGonk_DequeueBuffer"); + // 1000 is what Android uses. It is a warning timeout in ms. + // This timeout was removed in ANDROID_VERSION 18. +#else + fence->waitForever("nsScreenGonk_DequeueBuffer"); +#endif +#else + mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buf); +#endif + return buf; +} + +bool +nsScreenGonk::QueueBuffer(ANativeWindowBuffer* buf) +{ +#if ANDROID_VERSION >= 17 + int ret = mNativeWindow->queueBuffer(mNativeWindow.get(), buf, -1); + return ret == 0; +#else + int ret = mNativeWindow->queueBuffer(mNativeWindow.get(), buf); + return ret == 0; +#endif +} + #if ANDROID_VERSION >= 17 android::DisplaySurface* nsScreenGonk::GetDisplaySurface() diff --git a/widget/gonk/nsScreenManagerGonk.h b/widget/gonk/nsScreenManagerGonk.h index 7d93d3e4bb77..f2d9f027b272 100644 --- a/widget/gonk/nsScreenManagerGonk.h +++ b/widget/gonk/nsScreenManagerGonk.h @@ -74,6 +74,9 @@ public: ScreenConfiguration GetConfiguration(); bool IsPrimaryScreen(); + ANativeWindowBuffer* DequeueBuffer(); + bool QueueBuffer(ANativeWindowBuffer* buf); + #if ANDROID_VERSION >= 17 android::DisplaySurface* GetDisplaySurface(); int GetPrevDispAcquireFd(); diff --git a/widget/gonk/nsWindow.cpp b/widget/gonk/nsWindow.cpp index 87ab08bfcbea..4fb0e6f51799 100644 --- a/widget/gonk/nsWindow.cpp +++ b/widget/gonk/nsWindow.cpp @@ -654,8 +654,7 @@ HalFormatToSurfaceFormat(int aHalFormat, int* bytepp) already_AddRefed nsWindow::StartRemoteDrawing() { - GonkDisplay* display = GetGonkDisplay(); - mFramebuffer = display->DequeueBuffer(); + mFramebuffer = mScreen->DequeueBuffer(); int width = mFramebuffer->width, height = mFramebuffer->height; void *vaddr; if (gralloc_module()->lock(gralloc_module(), mFramebuffer->handle, @@ -667,7 +666,7 @@ nsWindow::StartRemoteDrawing() return nullptr; } int bytepp; - SurfaceFormat format = HalFormatToSurfaceFormat(display->surfaceformat, + SurfaceFormat format = HalFormatToSurfaceFormat(mScreen->GetSurfaceFormat(), &bytepp); mFramebufferTarget = Factory::CreateDrawTargetForData( BackendType::CAIRO, (uint8_t*)vaddr, @@ -696,7 +695,7 @@ nsWindow::EndRemoteDrawing() gralloc_module()->unlock(gralloc_module(), mFramebuffer->handle); } if (mFramebuffer) { - GetGonkDisplay()->QueueBuffer(mFramebuffer); + mScreen->QueueBuffer(mFramebuffer); } mFramebuffer = nullptr; mFramebufferTarget = nullptr;