2013-05-08 07:58:22 +04:00
|
|
|
/* Copyright 2013 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GonkDisplayJB.h"
|
2013-09-12 06:24:47 +04:00
|
|
|
#if ANDROID_VERSION == 17
|
|
|
|
#include <gui/SurfaceTextureClient.h>
|
|
|
|
#else
|
2013-07-30 21:36:53 +04:00
|
|
|
#include <gui/Surface.h>
|
2013-09-18 06:04:03 +04:00
|
|
|
#include <gui/GraphicBufferAlloc.h>
|
2013-09-12 06:24:47 +04:00
|
|
|
#endif
|
2013-05-08 07:58:22 +04:00
|
|
|
|
|
|
|
#include <hardware/hardware.h>
|
|
|
|
#include <hardware/hwcomposer.h>
|
2013-07-09 22:51:09 +04:00
|
|
|
#include <hardware/power.h>
|
2013-05-08 07:58:22 +04:00
|
|
|
#include <suspend/autosuspend.h>
|
|
|
|
|
2013-09-18 06:04:03 +04:00
|
|
|
#if ANDROID_VERSION == 17
|
2013-05-08 07:58:22 +04:00
|
|
|
#include "GraphicBufferAlloc.h"
|
2013-09-18 06:04:03 +04:00
|
|
|
#endif
|
2013-05-08 07:58:22 +04:00
|
|
|
#include "BootAnimation.h"
|
|
|
|
|
|
|
|
using namespace android;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
static GonkDisplayJB* sGonkDisplay = nullptr;
|
|
|
|
|
|
|
|
GonkDisplayJB::GonkDisplayJB()
|
|
|
|
: mList(nullptr)
|
|
|
|
, mModule(nullptr)
|
2013-06-21 08:04:53 +04:00
|
|
|
, mFBModule(nullptr)
|
2013-05-08 07:58:22 +04:00
|
|
|
, mHwc(nullptr)
|
2013-06-21 08:04:53 +04:00
|
|
|
, mFBDevice(nullptr)
|
2013-07-02 03:03:17 +04:00
|
|
|
, mEnabledCallback(nullptr)
|
2013-07-09 22:51:09 +04:00
|
|
|
, mPowerModule(nullptr)
|
2013-05-08 07:58:22 +04:00
|
|
|
{
|
2013-06-21 08:04:53 +04:00
|
|
|
int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mFBModule);
|
|
|
|
ALOGW_IF(err, "%s module not found", GRALLOC_HARDWARE_MODULE_ID);
|
|
|
|
if (!err) {
|
|
|
|
err = framebuffer_open(mFBModule, &mFBDevice);
|
|
|
|
ALOGW_IF(err, "could not open framebuffer");
|
|
|
|
}
|
|
|
|
|
2013-09-12 06:07:53 +04:00
|
|
|
if (!err && mFBDevice) {
|
2013-06-21 08:04:53 +04:00
|
|
|
mWidth = mFBDevice->width;
|
2013-09-12 06:07:53 +04:00
|
|
|
mHeight = mFBDevice->height;
|
|
|
|
xdpi = mFBDevice->xdpi;
|
2013-06-21 08:16:37 +04:00
|
|
|
/* The emulator actually reports RGBA_8888, but EGL doesn't return
|
|
|
|
* any matching configuration. We force RGBX here to fix it. */
|
2013-06-21 08:04:53 +04:00
|
|
|
surfaceformat = HAL_PIXEL_FORMAT_RGBX_8888;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule);
|
2013-05-08 07:58:22 +04:00
|
|
|
ALOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID);
|
2013-06-21 08:04:53 +04:00
|
|
|
if (!err) {
|
|
|
|
err = hwc_open_1(mModule, &mHwc);
|
|
|
|
ALOGE_IF(err, "%s device failed to initialize (%s)",
|
|
|
|
HWC_HARDWARE_COMPOSER, strerror(-err));
|
|
|
|
}
|
|
|
|
|
2013-07-11 10:14:35 +04:00
|
|
|
/* Fallback on the FB rendering path instead of trying to support HWC 1.0 */
|
|
|
|
if (!err && mHwc->common.version == HWC_DEVICE_API_VERSION_1_0) {
|
|
|
|
hwc_close_1(mHwc);
|
|
|
|
mHwc = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err && mHwc) {
|
2013-06-21 08:04:53 +04:00
|
|
|
if (mFBDevice) {
|
|
|
|
framebuffer_close(mFBDevice);
|
|
|
|
mFBDevice = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t values[3];
|
|
|
|
const uint32_t attrs[] = {
|
|
|
|
HWC_DISPLAY_WIDTH,
|
|
|
|
HWC_DISPLAY_HEIGHT,
|
|
|
|
HWC_DISPLAY_DPI_X,
|
|
|
|
HWC_DISPLAY_NO_ATTRIBUTE
|
|
|
|
};
|
|
|
|
mHwc->getDisplayAttributes(mHwc, 0, 0, attrs, values);
|
|
|
|
|
|
|
|
mWidth = values[0];
|
|
|
|
mHeight = values[1];
|
2013-07-17 04:57:41 +04:00
|
|
|
xdpi = values[2] / 1000.0f;
|
2013-06-21 08:04:53 +04:00
|
|
|
surfaceformat = HAL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
}
|
2013-05-08 07:58:22 +04:00
|
|
|
|
2013-07-09 22:51:09 +04:00
|
|
|
err = hw_get_module(POWER_HARDWARE_MODULE_ID,
|
|
|
|
(hw_module_t const**)&mPowerModule);
|
|
|
|
if (!err)
|
|
|
|
mPowerModule->init(mPowerModule);
|
|
|
|
ALOGW_IF(err, "Couldn't load %s module (%s)", POWER_HARDWARE_MODULE_ID, strerror(-err));
|
|
|
|
|
2013-05-08 07:58:22 +04:00
|
|
|
mAlloc = new GraphicBufferAlloc();
|
2013-10-03 06:26:30 +04:00
|
|
|
|
|
|
|
status_t error;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-08 07:58:22 +04:00
|
|
|
mFBSurface = new FramebufferSurface(0, mWidth, mHeight, surfaceformat, mAlloc);
|
|
|
|
|
2013-09-12 06:24:47 +04:00
|
|
|
#if ANDROID_VERSION == 17
|
|
|
|
sp<SurfaceTextureClient> stc = new SurfaceTextureClient(static_cast<sp<ISurfaceTexture> >(mFBSurface->getBufferQueue()));
|
|
|
|
#else
|
2013-07-30 21:36:53 +04:00
|
|
|
sp<Surface> stc = new Surface(static_cast<sp<IGraphicBufferProducer> >(mFBSurface->getBufferQueue()));
|
2013-09-12 06:24:47 +04:00
|
|
|
#endif
|
2013-05-08 07:58:22 +04:00
|
|
|
mSTClient = stc;
|
|
|
|
|
|
|
|
mList = (hwc_display_contents_1_t *)malloc(sizeof(*mList) + (sizeof(hwc_layer_1_t)*2));
|
2013-07-02 07:34:11 +04:00
|
|
|
if (mHwc)
|
|
|
|
mHwc->blank(mHwc, HWC_DISPLAY_PRIMARY, 0);
|
2013-05-08 07:58:22 +04:00
|
|
|
|
2013-10-03 06:26:30 +04:00
|
|
|
if (error == NO_ERROR && mBootAnimBuffer.get()) {
|
|
|
|
ALOGI("Starting bootanimation with (%d) format framebuffer", surfaceformat);
|
2013-09-12 06:07:53 +04:00
|
|
|
StartBootAnimation();
|
2013-10-03 06:26:30 +04:00
|
|
|
} else
|
2013-09-12 06:07:53 +04:00
|
|
|
ALOGW("Couldn't show bootanimation (%s)", strerror(-error));
|
2013-05-08 07:58:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GonkDisplayJB::~GonkDisplayJB()
|
|
|
|
{
|
|
|
|
if (mHwc)
|
|
|
|
hwc_close_1(mHwc);
|
2013-06-21 08:04:53 +04:00
|
|
|
if (mFBDevice)
|
|
|
|
framebuffer_close(mFBDevice);
|
2013-05-08 07:58:22 +04:00
|
|
|
free(mList);
|
|
|
|
}
|
|
|
|
|
|
|
|
ANativeWindow*
|
|
|
|
GonkDisplayJB::GetNativeWindow()
|
|
|
|
{
|
|
|
|
return mSTClient.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GonkDisplayJB::SetEnabled(bool enabled)
|
|
|
|
{
|
2013-07-09 22:51:09 +04:00
|
|
|
if (enabled) {
|
2013-05-08 07:58:22 +04:00
|
|
|
autosuspend_disable();
|
2013-07-09 22:51:09 +04:00
|
|
|
mPowerModule->setInteractive(mPowerModule, true);
|
|
|
|
}
|
2013-06-21 08:04:53 +04:00
|
|
|
|
|
|
|
if (mHwc)
|
|
|
|
mHwc->blank(mHwc, HWC_DISPLAY_PRIMARY, !enabled);
|
|
|
|
else if (mFBDevice->enableScreen)
|
|
|
|
mFBDevice->enableScreen(mFBDevice, enabled);
|
|
|
|
|
2013-07-02 03:03:17 +04:00
|
|
|
if (mEnabledCallback)
|
|
|
|
mEnabledCallback(enabled);
|
|
|
|
|
2013-07-09 22:51:09 +04:00
|
|
|
if (!enabled) {
|
2013-05-08 07:58:22 +04:00
|
|
|
autosuspend_enable();
|
2013-07-09 22:51:09 +04:00
|
|
|
mPowerModule->setInteractive(mPowerModule, false);
|
|
|
|
}
|
2013-05-08 07:58:22 +04:00
|
|
|
}
|
|
|
|
|
2013-07-02 03:03:17 +04:00
|
|
|
void
|
|
|
|
GonkDisplayJB::OnEnabled(OnEnabledCallbackType callback)
|
|
|
|
{
|
|
|
|
mEnabledCallback = callback;
|
|
|
|
}
|
|
|
|
|
2013-05-08 07:58:22 +04:00
|
|
|
void*
|
|
|
|
GonkDisplayJB::GetHWCDevice()
|
|
|
|
{
|
|
|
|
return mHwc;
|
|
|
|
}
|
|
|
|
|
2013-09-11 17:10:23 +04:00
|
|
|
void*
|
|
|
|
GonkDisplayJB::GetFBSurface()
|
|
|
|
{
|
|
|
|
return mFBSurface.get();
|
|
|
|
}
|
|
|
|
|
2013-05-08 07:58:22 +04:00
|
|
|
bool
|
|
|
|
GonkDisplayJB::SwapBuffers(EGLDisplay dpy, EGLSurface sur)
|
|
|
|
{
|
|
|
|
StopBootAnimation();
|
|
|
|
mBootAnimBuffer = nullptr;
|
|
|
|
|
2013-08-19 16:43:16 +04:00
|
|
|
// Should be called when composition rendering is complete for a frame.
|
|
|
|
// Only HWC v1.0 needs this call.
|
|
|
|
// HWC > v1.0 case, do not call compositionComplete().
|
|
|
|
// mFBDevice is present only when HWC is v1.0.
|
|
|
|
if (mFBDevice && mFBDevice->compositionComplete) {
|
|
|
|
mFBDevice->compositionComplete(mFBDevice);
|
|
|
|
}
|
2013-09-12 06:24:47 +04:00
|
|
|
|
|
|
|
#if ANDROID_VERSION == 17
|
|
|
|
mList->dpy = dpy;
|
|
|
|
mList->sur = sur;
|
|
|
|
#else
|
2013-07-30 21:36:53 +04:00
|
|
|
mList->outbuf = nullptr;
|
|
|
|
mList->outbufAcquireFenceFd = -1;
|
2013-09-12 06:24:47 +04:00
|
|
|
#endif
|
2013-05-08 07:58:22 +04:00
|
|
|
eglSwapBuffers(dpy, sur);
|
|
|
|
return Post(mFBSurface->lastHandle, mFBSurface->lastFenceFD);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GonkDisplayJB::Post(buffer_handle_t buf, int fence)
|
|
|
|
{
|
2013-06-21 08:04:53 +04:00
|
|
|
if (!mHwc) {
|
|
|
|
if (fence >= 0)
|
|
|
|
close(fence);
|
|
|
|
return !mFBDevice->post(mFBDevice, buf);
|
|
|
|
}
|
|
|
|
|
2013-05-08 07:58:22 +04:00
|
|
|
hwc_display_contents_1_t *displays[HWC_NUM_DISPLAY_TYPES] = {NULL};
|
|
|
|
const hwc_rect_t r = { 0, 0, mWidth, mHeight };
|
|
|
|
displays[HWC_DISPLAY_PRIMARY] = mList;
|
|
|
|
mList->retireFenceFd = -1;
|
|
|
|
mList->numHwLayers = 2;
|
|
|
|
mList->flags = HWC_GEOMETRY_CHANGED;
|
|
|
|
mList->hwLayers[0].compositionType = HWC_BACKGROUND;
|
|
|
|
mList->hwLayers[0].hints = 0;
|
2013-07-30 21:36:53 +04:00
|
|
|
/* Skip this layer so the hwc module doesn't complain about null handles */
|
|
|
|
mList->hwLayers[0].flags = HWC_SKIP_LAYER;
|
2013-05-08 07:58:22 +04:00
|
|
|
mList->hwLayers[0].backgroundColor = {0};
|
2013-07-30 21:36:53 +04:00
|
|
|
/* hwc module checks displayFrame even though it shouldn't */
|
|
|
|
mList->hwLayers[0].displayFrame = r;
|
2013-05-08 07:58:22 +04:00
|
|
|
mList->hwLayers[1].compositionType = HWC_FRAMEBUFFER_TARGET;
|
|
|
|
mList->hwLayers[1].hints = 0;
|
|
|
|
mList->hwLayers[1].flags = 0;
|
|
|
|
mList->hwLayers[1].handle = buf;
|
|
|
|
mList->hwLayers[1].transform = 0;
|
|
|
|
mList->hwLayers[1].blending = HWC_BLENDING_PREMULT;
|
|
|
|
mList->hwLayers[1].sourceCrop = r;
|
|
|
|
mList->hwLayers[1].displayFrame = r;
|
|
|
|
mList->hwLayers[1].visibleRegionScreen.numRects = 1;
|
2013-07-30 21:36:53 +04:00
|
|
|
mList->hwLayers[1].visibleRegionScreen.rects = &mList->hwLayers[1].sourceCrop;
|
2013-05-08 07:58:22 +04:00
|
|
|
mList->hwLayers[1].acquireFenceFd = fence;
|
|
|
|
mList->hwLayers[1].releaseFenceFd = -1;
|
2013-09-12 06:24:47 +04:00
|
|
|
#if ANDROID_VERSION == 18
|
2013-07-30 21:36:53 +04:00
|
|
|
mList->hwLayers[1].planeAlpha = 0xFF;
|
2013-09-12 06:24:47 +04:00
|
|
|
#endif
|
2013-05-08 07:58:22 +04:00
|
|
|
mHwc->prepare(mHwc, HWC_NUM_DISPLAY_TYPES, displays);
|
|
|
|
int err = mHwc->set(mHwc, HWC_NUM_DISPLAY_TYPES, displays);
|
|
|
|
mFBSurface->setReleaseFenceFd(mList->hwLayers[1].releaseFenceFd);
|
|
|
|
if (mList->retireFenceFd >= 0)
|
|
|
|
close(mList->retireFenceFd);
|
|
|
|
return !err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANativeWindowBuffer*
|
|
|
|
GonkDisplayJB::DequeueBuffer()
|
|
|
|
{
|
|
|
|
return static_cast<ANativeWindowBuffer*>(mBootAnimBuffer.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GonkDisplayJB::QueueBuffer(ANativeWindowBuffer* buf)
|
|
|
|
{
|
|
|
|
bool success = Post(buf->handle, -1);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__ ((visibility ("default")))
|
|
|
|
GonkDisplay*
|
|
|
|
GetGonkDisplay()
|
|
|
|
{
|
|
|
|
if (!sGonkDisplay)
|
|
|
|
sGonkDisplay = new GonkDisplayJB();
|
|
|
|
return sGonkDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|