2012-11-19 21:58:37 +04:00
|
|
|
/*
|
2013-08-14 23:26:44 +04:00
|
|
|
* Copyright (c) 2012, 2013 The Linux Foundation. All rights reserved.
|
2012-11-19 21:58:37 +04:00
|
|
|
*
|
|
|
|
* 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 <android/log.h>
|
2013-05-08 07:58:22 +04:00
|
|
|
#include <string.h>
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2014-12-07 04:12:50 +03:00
|
|
|
#include "ImageLayers.h"
|
2013-05-08 07:58:22 +04:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
2012-11-19 21:58:37 +04:00
|
|
|
#include "HwcComposer2D.h"
|
2015-04-12 05:06:00 +03:00
|
|
|
#include "HwcUtils.h"
|
2014-07-03 03:17:00 +04:00
|
|
|
#include "LayerScope.h"
|
2015-04-12 05:06:00 +03:00
|
|
|
#include "Units.h"
|
2014-09-24 17:50:45 +04:00
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2013-06-06 02:14:51 +04:00
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
2013-04-24 22:42:40 +04:00
|
|
|
#include "mozilla/layers/PLayerTransaction.h"
|
2012-11-19 21:58:37 +04:00
|
|
|
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
|
2014-02-25 08:23:41 +04:00
|
|
|
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
|
2012-11-19 21:58:37 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-01-09 16:56:37 +04:00
|
|
|
#include "cutils/properties.h"
|
2014-01-16 11:22:19 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2015-01-20 16:21:00 +03:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "VsyncSource.h"
|
2014-10-02 00:01:59 +04:00
|
|
|
|
2014-02-21 17:30:20 +04:00
|
|
|
#if ANDROID_VERSION >= 17
|
2015-04-23 16:49:40 +03:00
|
|
|
#include "libdisplay/DisplaySurface.h"
|
2014-08-27 09:17:00 +04:00
|
|
|
#include "gfxPrefs.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2015-02-03 21:38:21 +03:00
|
|
|
#endif
|
2014-08-27 09:17:00 +04:00
|
|
|
|
2015-02-03 21:38:21 +03:00
|
|
|
#if ANDROID_VERSION >= 21
|
|
|
|
#ifndef HWC_BLIT
|
|
|
|
#define HWC_BLIT 0xFF
|
|
|
|
#endif
|
|
|
|
#elif ANDROID_VERSION >= 17
|
2014-01-16 21:47:35 +04:00
|
|
|
#ifndef HWC_BLIT
|
|
|
|
#define HWC_BLIT (HWC_FRAMEBUFFER_TARGET + 1)
|
|
|
|
#endif
|
2013-09-11 17:10:33 +04:00
|
|
|
#endif
|
|
|
|
|
2014-03-04 12:45:50 +04:00
|
|
|
#ifdef LOG_TAG
|
|
|
|
#undef LOG_TAG
|
|
|
|
#endif
|
2012-11-19 21:58:37 +04:00
|
|
|
#define LOG_TAG "HWComposer"
|
|
|
|
|
2013-09-18 06:10:35 +04:00
|
|
|
/*
|
|
|
|
* By default the debug message of hwcomposer (LOG_DEBUG level) are undefined,
|
|
|
|
* but can be enabled by uncommenting HWC_DEBUG below.
|
|
|
|
*/
|
|
|
|
//#define HWC_DEBUG
|
|
|
|
|
|
|
|
#ifdef HWC_DEBUG
|
2012-11-19 21:58:37 +04:00
|
|
|
#define LOGD(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, ## args)
|
|
|
|
#else
|
|
|
|
#define LOGD(args...) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
2013-09-18 06:10:35 +04:00
|
|
|
#define LOGI(args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, ## args)
|
2012-11-19 21:58:37 +04:00
|
|
|
#define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
|
|
|
|
|
|
|
|
#define LAYER_COUNT_INCREMENTS 5
|
|
|
|
|
|
|
|
using namespace android;
|
2014-08-22 17:40:02 +04:00
|
|
|
using namespace mozilla::gfx;
|
2012-11-19 21:58:37 +04:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-08-27 09:17:00 +04:00
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
static void
|
|
|
|
HookInvalidate(const struct hwc_procs* aProcs)
|
|
|
|
{
|
2014-09-24 17:50:45 +04:00
|
|
|
HwcComposer2D::GetInstance()->Invalidate();
|
2014-08-27 09:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
HookVsync(const struct hwc_procs* aProcs, int aDisplay,
|
|
|
|
int64_t aTimestamp)
|
|
|
|
{
|
|
|
|
HwcComposer2D::GetInstance()->Vsync(aDisplay, aTimestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
HookHotplug(const struct hwc_procs* aProcs, int aDisplay,
|
|
|
|
int aConnected)
|
|
|
|
{
|
|
|
|
// no op
|
|
|
|
}
|
|
|
|
|
|
|
|
static const hwc_procs_t sHWCProcs = {
|
|
|
|
&HookInvalidate, // 1st: void (*invalidate)(...)
|
|
|
|
&HookVsync, // 2nd: void (*vsync)(...)
|
|
|
|
&HookHotplug // 3rd: void (*hotplug)(...)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-11-19 21:58:37 +04:00
|
|
|
static StaticRefPtr<HwcComposer2D> sInstance;
|
|
|
|
|
|
|
|
HwcComposer2D::HwcComposer2D()
|
2014-03-04 12:45:51 +04:00
|
|
|
: mHwc(nullptr)
|
2012-11-19 21:58:37 +04:00
|
|
|
, mList(nullptr)
|
2015-04-17 19:28:41 +03:00
|
|
|
, mDpy(EGL_NO_DISPLAY)
|
|
|
|
, mSur(EGL_NO_SURFACE)
|
2014-07-01 00:01:24 +04:00
|
|
|
, mGLContext(nullptr)
|
2014-03-04 12:45:51 +04:00
|
|
|
, mMaxLayerCount(0)
|
2013-09-28 00:37:19 +04:00
|
|
|
, mColorFill(false)
|
|
|
|
, mRBSwapSupport(false)
|
2013-12-12 00:37:25 +04:00
|
|
|
, mPrepared(false)
|
2014-08-27 09:17:00 +04:00
|
|
|
, mHasHWVsync(false)
|
2014-09-24 17:50:45 +04:00
|
|
|
, mLock("mozilla.HwcComposer2D.mLock")
|
2012-11-19 21:58:37 +04:00
|
|
|
{
|
2015-01-15 18:56:12 +03:00
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
RegisterHwcEventCallback();
|
|
|
|
#endif
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2013-09-11 17:10:33 +04:00
|
|
|
mHwc = (HwcDevice*)GetGonkDisplay()->GetHWCDevice();
|
2013-05-08 07:58:22 +04:00
|
|
|
if (!mHwc) {
|
2015-04-17 19:28:41 +03:00
|
|
|
LOGD("no hwc support");
|
|
|
|
return;
|
2012-11-19 21:58:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntSize screenSize;
|
|
|
|
|
2014-07-23 00:46:27 +04:00
|
|
|
ANativeWindow *win = GetGonkDisplay()->GetNativeWindow();
|
|
|
|
win->query(win, NATIVE_WINDOW_WIDTH, &screenSize.width);
|
|
|
|
win->query(win, NATIVE_WINDOW_HEIGHT, &screenSize.height);
|
2015-04-21 18:04:57 +03:00
|
|
|
mScreenRect = gfx::IntRect(gfx::IntPoint(0, 0), screenSize);
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2014-02-21 17:30:20 +04:00
|
|
|
#if ANDROID_VERSION >= 17
|
2013-09-28 00:37:19 +04:00
|
|
|
int supported = 0;
|
2014-02-27 20:38:36 +04:00
|
|
|
|
|
|
|
if (mHwc->query) {
|
|
|
|
if (mHwc->query(mHwc, HwcUtils::HWC_COLOR_FILL, &supported) == NO_ERROR) {
|
|
|
|
mColorFill = !!supported;
|
|
|
|
}
|
|
|
|
if (mHwc->query(mHwc, HwcUtils::HWC_FORMAT_RB_SWAP, &supported) == NO_ERROR) {
|
|
|
|
mRBSwapSupport = !!supported;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mColorFill = false;
|
|
|
|
mRBSwapSupport = false;
|
2013-09-28 00:37:19 +04:00
|
|
|
}
|
|
|
|
#else
|
2013-01-09 16:56:37 +04:00
|
|
|
char propValue[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.display.colorfill", propValue, "0");
|
|
|
|
mColorFill = (atoi(propValue) == 1) ? true : false;
|
2013-09-28 00:37:19 +04:00
|
|
|
mRBSwapSupport = true;
|
|
|
|
#endif
|
2015-04-17 19:28:41 +03:00
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
|
2015-04-17 19:28:41 +03:00
|
|
|
HwcComposer2D::~HwcComposer2D() {
|
|
|
|
free(mList);
|
2012-11-19 21:58:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HwcComposer2D*
|
|
|
|
HwcComposer2D::GetInstance()
|
|
|
|
{
|
|
|
|
if (!sInstance) {
|
2013-09-18 06:10:35 +04:00
|
|
|
LOGI("Creating new instance");
|
2012-11-19 21:58:37 +04:00
|
|
|
sInstance = new HwcComposer2D();
|
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:25:09 +03:00
|
|
|
bool
|
2014-08-27 09:17:00 +04:00
|
|
|
HwcComposer2D::EnableVsync(bool aEnable)
|
|
|
|
{
|
2015-05-17 19:12:00 +03:00
|
|
|
// Only support hardware vsync on kitkat, L and up due to inaccurate timings
|
|
|
|
// with JellyBean.
|
|
|
|
#if (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
|
2014-12-18 08:25:09 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!mHasHWVsync) {
|
|
|
|
return false;
|
2014-08-27 09:17:00 +04:00
|
|
|
}
|
2014-12-18 08:25:09 +03:00
|
|
|
|
|
|
|
HwcDevice* device = (HwcDevice*)GetGonkDisplay()->GetHWCDevice();
|
|
|
|
if (!device) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-20 19:31:10 +03:00
|
|
|
return !device->eventControl(device, HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, aEnable) && aEnable;
|
2015-01-15 18:56:12 +03:00
|
|
|
#else
|
|
|
|
return false;
|
2014-08-27 09:17:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
bool
|
|
|
|
HwcComposer2D::RegisterHwcEventCallback()
|
|
|
|
{
|
|
|
|
HwcDevice* device = (HwcDevice*)GetGonkDisplay()->GetHWCDevice();
|
|
|
|
if (!device || !device->registerProcs) {
|
|
|
|
LOGE("Failed to get hwc");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable Vsync first, and then register callback functions.
|
|
|
|
device->eventControl(device, HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, false);
|
|
|
|
device->registerProcs(device, &sHWCProcs);
|
2015-04-14 17:31:58 +03:00
|
|
|
|
2015-05-17 19:12:00 +03:00
|
|
|
// Only support hardware vsync on kitkat, L and up due to inaccurate timings
|
|
|
|
// with JellyBean.
|
|
|
|
#if (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
|
2014-12-18 08:25:09 +03:00
|
|
|
mHasHWVsync = gfxPrefs::HardwareVsyncEnabled();
|
2015-04-14 17:31:58 +03:00
|
|
|
#else
|
|
|
|
mHasHWVsync = false;
|
|
|
|
#endif
|
2014-09-23 22:14:39 +04:00
|
|
|
return mHasHWVsync;
|
2014-08-27 09:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-02 00:01:59 +04:00
|
|
|
HwcComposer2D::Vsync(int aDisplay, nsecs_t aVsyncTimestamp)
|
2014-08-27 09:17:00 +04:00
|
|
|
{
|
2015-05-17 19:12:00 +03:00
|
|
|
// Only support hardware vsync on kitkat, L and up due to inaccurate timings
|
|
|
|
// with JellyBean.
|
|
|
|
#if (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
|
2014-11-19 00:28:42 +03:00
|
|
|
TimeStamp vsyncTime = mozilla::TimeStamp::FromSystemTime(aVsyncTimestamp);
|
2015-01-20 16:21:00 +03:00
|
|
|
gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay().NotifyVsync(vsyncTime);
|
2015-05-17 19:12:00 +03:00
|
|
|
#else
|
|
|
|
// If this device doesn't support vsync, this function should not be used.
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
#endif
|
2014-08-27 09:17:00 +04:00
|
|
|
}
|
2014-09-24 17:50:45 +04:00
|
|
|
|
|
|
|
// Called on the "invalidator" thread (run from HAL).
|
|
|
|
void
|
|
|
|
HwcComposer2D::Invalidate()
|
|
|
|
{
|
2015-04-17 19:28:41 +03:00
|
|
|
if (!mHwc) {
|
2014-09-24 17:50:45 +04:00
|
|
|
LOGE("HwcComposer2D::Invalidate failed!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
if (mCompositorParent) {
|
|
|
|
mCompositorParent->ScheduleRenderOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 09:17:00 +04:00
|
|
|
#endif
|
|
|
|
|
2014-09-24 17:50:45 +04:00
|
|
|
void
|
|
|
|
HwcComposer2D::SetCompositorParent(CompositorParent* aCompositorParent)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
mCompositorParent = aCompositorParent;
|
|
|
|
}
|
|
|
|
|
2015-04-17 19:28:41 +03:00
|
|
|
void
|
|
|
|
HwcComposer2D::SetEGLInfo(hwc_display_t aDisplay, hwc_surface_t aSurface, gl::GLContext* aGLContext)
|
|
|
|
{
|
|
|
|
mDpy = aDisplay;
|
|
|
|
mSur = aSurface;
|
|
|
|
mGLContext = aGLContext;
|
|
|
|
}
|
|
|
|
|
2012-11-19 21:58:37 +04:00
|
|
|
bool
|
|
|
|
HwcComposer2D::ReallocLayerList()
|
|
|
|
{
|
2013-09-11 17:10:33 +04:00
|
|
|
int size = sizeof(HwcList) +
|
|
|
|
((mMaxLayerCount + LAYER_COUNT_INCREMENTS) * sizeof(HwcLayer));
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2013-09-11 17:10:33 +04:00
|
|
|
HwcList* listrealloc = (HwcList*)realloc(mList, size);
|
2012-11-19 21:58:37 +04:00
|
|
|
|
|
|
|
if (!listrealloc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mList) {
|
|
|
|
//first alloc, initialize
|
|
|
|
listrealloc->numHwLayers = 0;
|
|
|
|
listrealloc->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mList = listrealloc;
|
|
|
|
mMaxLayerCount += LAYER_COUNT_INCREMENTS;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-06 02:55:00 +04:00
|
|
|
void
|
|
|
|
HwcComposer2D::setCrop(HwcLayer* layer, hwc_rect_t srcCrop)
|
|
|
|
{
|
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
if (mHwc->common.version >= HWC_DEVICE_API_VERSION_1_3) {
|
|
|
|
layer->sourceCropf.left = srcCrop.left;
|
|
|
|
layer->sourceCropf.top = srcCrop.top;
|
|
|
|
layer->sourceCropf.right = srcCrop.right;
|
|
|
|
layer->sourceCropf.bottom = srcCrop.bottom;
|
|
|
|
} else {
|
|
|
|
layer->sourceCrop = srcCrop;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
layer->sourceCrop = srcCrop;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
void
|
|
|
|
HwcComposer2D::setHwcGeometry(bool aGeometryChanged)
|
|
|
|
{
|
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
mList->flags = aGeometryChanged ? HWC_GEOMETRY_CHANGED : 0;
|
|
|
|
#else
|
|
|
|
mList->flags = HWC_GEOMETRY_CHANGED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-19 21:58:37 +04:00
|
|
|
bool
|
|
|
|
HwcComposer2D::PrepareLayerList(Layer* aLayer,
|
2013-01-18 01:34:01 +04:00
|
|
|
const nsIntRect& aClip,
|
2014-09-10 23:59:00 +04:00
|
|
|
const Matrix& aParentTransform)
|
2012-11-19 21:58:37 +04:00
|
|
|
{
|
|
|
|
// NB: we fall off this path whenever there are container layers
|
|
|
|
// that require intermediate surfaces. That means all the
|
|
|
|
// GetEffective*() coordinates are relative to the framebuffer.
|
|
|
|
|
2013-01-09 16:56:37 +04:00
|
|
|
bool fillColor = false;
|
2012-11-19 21:58:37 +04:00
|
|
|
|
|
|
|
const nsIntRegion& visibleRegion = aLayer->GetEffectiveVisibleRegion();
|
|
|
|
if (visibleRegion.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-16 02:37:13 +04:00
|
|
|
uint8_t opacity = std::min(0xFF, (int)(aLayer->GetEffectiveOpacity() * 256.0));
|
2015-03-07 00:52:34 +03:00
|
|
|
if (opacity == 0) {
|
|
|
|
LOGD("%s Layer has zero opacity; skipping", aLayer->Name());
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-16 02:37:13 +04:00
|
|
|
#if ANDROID_VERSION < 18
|
|
|
|
if (opacity < 0xFF) {
|
2014-12-11 18:15:52 +03:00
|
|
|
LOGD("%s Layer has planar semitransparency which is unsupported by hwcomposer", aLayer->Name());
|
2012-11-19 21:58:37 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-16 02:37:13 +04:00
|
|
|
#endif
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2014-12-11 18:15:52 +03:00
|
|
|
if (aLayer->GetMaskLayer()) {
|
|
|
|
LOGD("%s Layer has MaskLayer which is unsupported by hwcomposer", aLayer->Name());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-18 01:34:01 +04:00
|
|
|
nsIntRect clip;
|
2015-04-12 05:06:00 +03:00
|
|
|
nsIntRect layerClip = aLayer->GetEffectiveClipRect() ?
|
|
|
|
ParentLayerIntRect::ToUntyped(*aLayer->GetEffectiveClipRect()) : nsIntRect();
|
|
|
|
nsIntRect* layerClipPtr = aLayer->GetEffectiveClipRect() ? &layerClip : nullptr;
|
2014-09-10 23:59:00 +04:00
|
|
|
if (!HwcUtils::CalculateClipRect(aParentTransform,
|
2015-04-12 05:06:00 +03:00
|
|
|
layerClipPtr,
|
2013-08-29 19:17:59 +04:00
|
|
|
aClip,
|
|
|
|
&clip))
|
2013-01-18 01:34:01 +04:00
|
|
|
{
|
2013-06-11 14:14:33 +04:00
|
|
|
LOGD("%s Clip rect is empty. Skip layer", aLayer->Name());
|
2013-01-18 01:34:01 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-14 23:26:44 +04:00
|
|
|
// HWC supports only the following 2D transformations:
|
|
|
|
//
|
2013-09-11 17:10:33 +04:00
|
|
|
// Scaling via the sourceCrop and displayFrame in HwcLayer
|
|
|
|
// Translation via the sourceCrop and displayFrame in HwcLayer
|
2013-08-14 23:26:44 +04:00
|
|
|
// Rotation (in square angles only) via the HWC_TRANSFORM_ROT_* flags
|
|
|
|
// Reflection (horizontal and vertical) via the HWC_TRANSFORM_FLIP_* flags
|
|
|
|
//
|
|
|
|
// A 2D transform with PreservesAxisAlignedRectangles() has all the attributes
|
|
|
|
// above
|
2014-12-07 04:12:50 +03:00
|
|
|
Matrix layerTransform;
|
|
|
|
if (!aLayer->GetEffectiveTransform().Is2D(&layerTransform) ||
|
|
|
|
!layerTransform.PreservesAxisAlignedRectangles()) {
|
|
|
|
LOGD("Layer EffectiveTransform has a 3D transform or a non-square angle rotation");
|
2013-01-18 01:34:01 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-07 04:12:50 +03:00
|
|
|
Matrix layerBufferTransform;
|
|
|
|
if (!aLayer->GetEffectiveTransformForBuffer().Is2D(&layerBufferTransform) ||
|
|
|
|
!layerBufferTransform.PreservesAxisAlignedRectangles()) {
|
|
|
|
LOGD("Layer EffectiveTransformForBuffer has a 3D transform or a non-square angle rotation");
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-19 21:58:37 +04:00
|
|
|
|
|
|
|
if (ContainerLayer* container = aLayer->AsContainerLayer()) {
|
2014-05-06 00:26:51 +04:00
|
|
|
if (container->UseIntermediateSurface()) {
|
|
|
|
LOGD("Container layer needs intermediate surface");
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-19 21:58:37 +04:00
|
|
|
nsAutoTArray<Layer*, 12> children;
|
|
|
|
container->SortChildrenBy3DZOrder(children);
|
|
|
|
|
2013-01-08 03:21:50 +04:00
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
2014-12-07 04:12:50 +03:00
|
|
|
if (!PrepareLayerList(children[i], clip, layerTransform)) {
|
2012-11-19 21:58:37 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-06 02:14:51 +04:00
|
|
|
LayerRenderState state = aLayer->GetRenderState();
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2014-11-05 23:59:10 +03:00
|
|
|
if (!state.mSurface.get()) {
|
|
|
|
if (aLayer->AsColorLayer() && mColorFill) {
|
|
|
|
fillColor = true;
|
|
|
|
} else {
|
|
|
|
LOGD("%s Layer doesn't have a gralloc buffer", aLayer->Name());
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-19 21:58:37 +04:00
|
|
|
}
|
|
|
|
|
2014-11-05 23:59:10 +03:00
|
|
|
nsIntRect visibleRect = visibleRegion.GetBounds();
|
|
|
|
|
2013-01-09 16:56:37 +04:00
|
|
|
nsIntRect bufferRect;
|
|
|
|
if (fillColor) {
|
2013-01-10 14:51:43 +04:00
|
|
|
bufferRect = nsIntRect(visibleRect);
|
2013-01-09 16:56:37 +04:00
|
|
|
} else {
|
2014-12-07 04:12:50 +03:00
|
|
|
nsIntRect layerRect;
|
2014-11-05 23:59:10 +03:00
|
|
|
if (state.mHasOwnOffset) {
|
2013-01-10 14:51:43 +04:00
|
|
|
bufferRect = nsIntRect(state.mOffset.x, state.mOffset.y,
|
2013-06-06 02:14:51 +04:00
|
|
|
state.mSize.width, state.mSize.height);
|
2014-12-07 04:12:50 +03:00
|
|
|
layerRect = bufferRect;
|
2013-01-10 14:51:43 +04:00
|
|
|
} else {
|
2013-06-28 06:22:37 +04:00
|
|
|
//Since the buffer doesn't have its own offset, assign the whole
|
|
|
|
//surface size as its buffer bounds
|
|
|
|
bufferRect = nsIntRect(0, 0, state.mSize.width, state.mSize.height);
|
2014-12-07 04:12:50 +03:00
|
|
|
layerRect = bufferRect;
|
|
|
|
if (aLayer->GetType() == Layer::TYPE_IMAGE) {
|
|
|
|
ImageLayer* imageLayer = static_cast<ImageLayer*>(aLayer);
|
|
|
|
if(imageLayer->GetScaleMode() != ScaleMode::SCALE_NONE) {
|
|
|
|
layerRect = nsIntRect(0, 0, imageLayer->GetScaleToSize().width, imageLayer->GetScaleToSize().height);
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 14:51:43 +04:00
|
|
|
}
|
2014-11-05 23:59:10 +03:00
|
|
|
// In some cases the visible rect assigned to the layer can be larger
|
|
|
|
// than the layer's surface, e.g., an ImageLayer with a small Image
|
|
|
|
// in it.
|
2014-12-07 04:12:50 +03:00
|
|
|
visibleRect.IntersectRect(visibleRect, layerRect);
|
2014-11-05 23:59:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer rotation is not to be confused with the angled rotation done by a transform matrix
|
|
|
|
// It's a fancy PaintedLayer feature used for scrolling
|
|
|
|
if (state.BufferRotated()) {
|
|
|
|
LOGD("%s Layer has a rotated buffer", aLayer->Name());
|
|
|
|
return false;
|
2013-01-09 16:56:37 +04:00
|
|
|
}
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2014-11-18 04:02:19 +03:00
|
|
|
const bool needsYFlip = state.OriginBottomLeft() ? true
|
|
|
|
: false;
|
|
|
|
|
2014-03-17 22:51:26 +04:00
|
|
|
hwc_rect_t sourceCrop, displayFrame;
|
2013-08-29 19:17:59 +04:00
|
|
|
if(!HwcUtils::PrepareLayerRects(visibleRect,
|
2014-12-07 04:12:50 +03:00
|
|
|
layerTransform,
|
|
|
|
layerBufferTransform,
|
2013-01-18 01:34:01 +04:00
|
|
|
clip,
|
|
|
|
bufferRect,
|
2014-11-18 04:02:19 +03:00
|
|
|
needsYFlip,
|
2014-02-06 02:55:00 +04:00
|
|
|
&(sourceCrop),
|
2014-03-17 22:51:26 +04:00
|
|
|
&(displayFrame)))
|
2013-01-18 01:34:01 +04:00
|
|
|
{
|
2012-11-19 21:58:37 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-17 22:51:26 +04:00
|
|
|
// OK! We can compose this layer with hwc.
|
|
|
|
int current = mList ? mList->numHwLayers : 0;
|
|
|
|
|
2014-10-07 03:28:46 +04:00
|
|
|
// Do not compose any layer below full-screen Opaque layer
|
|
|
|
// Note: It can be generalized to non-fullscreen Opaque layers.
|
2014-10-30 05:32:41 +03:00
|
|
|
bool isOpaque = opacity == 0xFF &&
|
|
|
|
(state.mFlags & LayerRenderStateFlags::OPAQUE);
|
2014-10-29 23:07:11 +03:00
|
|
|
// Currently we perform opacity calculation using the *bounds* of the layer.
|
|
|
|
// We can only make this assumption if we're not dealing with a complex visible region.
|
2014-10-30 05:32:41 +03:00
|
|
|
bool isSimpleVisibleRegion = visibleRegion.Contains(visibleRect);
|
2014-10-29 23:07:11 +03:00
|
|
|
if (current && isOpaque && isSimpleVisibleRegion) {
|
2014-10-07 03:28:46 +04:00
|
|
|
nsIntRect displayRect = nsIntRect(displayFrame.left, displayFrame.top,
|
|
|
|
displayFrame.right - displayFrame.left, displayFrame.bottom - displayFrame.top);
|
2014-03-17 22:51:26 +04:00
|
|
|
if (displayRect.Contains(mScreenRect)) {
|
2014-10-07 03:28:46 +04:00
|
|
|
// In z-order, all previous layers are below
|
|
|
|
// the current layer. We can ignore them now.
|
2014-03-17 22:51:26 +04:00
|
|
|
mList->numHwLayers = current = 0;
|
|
|
|
mHwcLayerMap.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mList || current >= mMaxLayerCount) {
|
|
|
|
if (!ReallocLayerList() || current >= mMaxLayerCount) {
|
|
|
|
LOGE("PrepareLayerList failed! Could not increase the maximum layer count");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HwcLayer& hwcLayer = mList->hwLayers[current];
|
|
|
|
hwcLayer.displayFrame = displayFrame;
|
2014-02-06 02:55:00 +04:00
|
|
|
setCrop(&hwcLayer, sourceCrop);
|
2013-06-06 02:14:51 +04:00
|
|
|
buffer_handle_t handle = fillColor ? nullptr : state.mSurface->getNativeBuffer()->handle;
|
2012-11-19 21:58:37 +04:00
|
|
|
hwcLayer.handle = handle;
|
|
|
|
|
2014-06-05 01:27:21 +04:00
|
|
|
hwcLayer.flags = 0;
|
2012-11-19 21:58:37 +04:00
|
|
|
hwcLayer.hints = 0;
|
2014-03-17 22:51:26 +04:00
|
|
|
hwcLayer.blending = isOpaque ? HWC_BLENDING_NONE : HWC_BLENDING_PREMULT;
|
2014-02-21 17:30:20 +04:00
|
|
|
#if ANDROID_VERSION >= 17
|
2013-09-11 17:10:33 +04:00
|
|
|
hwcLayer.compositionType = HWC_FRAMEBUFFER;
|
|
|
|
|
|
|
|
hwcLayer.acquireFenceFd = -1;
|
|
|
|
hwcLayer.releaseFenceFd = -1;
|
2014-02-21 17:30:20 +04:00
|
|
|
#if ANDROID_VERSION >= 18
|
2013-10-16 02:37:13 +04:00
|
|
|
hwcLayer.planeAlpha = opacity;
|
2014-02-21 17:30:20 +04:00
|
|
|
#endif
|
2013-09-11 17:10:33 +04:00
|
|
|
#else
|
2013-08-29 19:17:59 +04:00
|
|
|
hwcLayer.compositionType = HwcUtils::HWC_USE_COPYBIT;
|
2013-09-11 17:10:33 +04:00
|
|
|
#endif
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2013-01-09 16:56:37 +04:00
|
|
|
if (!fillColor) {
|
2013-06-11 14:14:33 +04:00
|
|
|
if (state.FormatRBSwapped()) {
|
2013-09-28 00:37:19 +04:00
|
|
|
if (!mRBSwapSupport) {
|
|
|
|
LOGD("No R/B swap support in H/W Composer");
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-29 19:17:59 +04:00
|
|
|
hwcLayer.flags |= HwcUtils::HWC_FORMAT_RB_SWAP;
|
2013-06-11 14:14:33 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 23:26:44 +04:00
|
|
|
// Translation and scaling have been addressed in PrepareLayerRects().
|
|
|
|
// Given the above and that we checked for PreservesAxisAlignedRectangles()
|
|
|
|
// the only possible transformations left to address are
|
|
|
|
// square angle rotation and horizontal/vertical reflection.
|
|
|
|
//
|
|
|
|
// The rotation and reflection permutations total 16 but can be
|
|
|
|
// reduced to 8 transformations after eliminating redundancies.
|
|
|
|
//
|
|
|
|
// All matrices represented here are in the form
|
|
|
|
//
|
|
|
|
// | xx xy |
|
|
|
|
// | yx yy |
|
|
|
|
//
|
|
|
|
// And ignore scaling.
|
|
|
|
//
|
|
|
|
// Reflection is applied before rotation
|
2014-12-07 04:12:50 +03:00
|
|
|
gfx::Matrix rotation = layerTransform;
|
2013-08-14 23:26:44 +04:00
|
|
|
// Compute fuzzy zero like PreservesAxisAlignedRectangles()
|
2014-06-17 21:35:51 +04:00
|
|
|
if (fabs(rotation._11) < 1e-6) {
|
|
|
|
if (rotation._21 < 0) {
|
|
|
|
if (rotation._12 > 0) {
|
2013-08-14 23:26:44 +04:00
|
|
|
// 90 degree rotation
|
|
|
|
//
|
|
|
|
// | 0 -1 |
|
|
|
|
// | 1 0 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_90;
|
|
|
|
LOGD("Layer rotated 90 degrees");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Horizontal reflection then 90 degree rotation
|
|
|
|
//
|
|
|
|
// | 0 -1 | | -1 0 | = | 0 -1 |
|
|
|
|
// | 1 0 | | 0 1 | | -1 0 |
|
|
|
|
//
|
|
|
|
// same as vertical reflection then 270 degree rotation
|
|
|
|
//
|
|
|
|
// | 0 1 | | 1 0 | = | 0 -1 |
|
|
|
|
// | -1 0 | | 0 -1 | | -1 0 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_90 | HWC_TRANSFORM_FLIP_H;
|
|
|
|
LOGD("Layer vertically reflected then rotated 270 degrees");
|
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
} else {
|
2014-06-17 21:35:51 +04:00
|
|
|
if (rotation._12 < 0) {
|
2013-08-14 23:26:44 +04:00
|
|
|
// 270 degree rotation
|
|
|
|
//
|
|
|
|
// | 0 1 |
|
|
|
|
// | -1 0 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_270;
|
|
|
|
LOGD("Layer rotated 270 degrees");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Vertical reflection then 90 degree rotation
|
|
|
|
//
|
|
|
|
// | 0 1 | | -1 0 | = | 0 1 |
|
|
|
|
// | -1 0 | | 0 1 | | 1 0 |
|
|
|
|
//
|
|
|
|
// Same as horizontal reflection then 270 degree rotation
|
|
|
|
//
|
|
|
|
// | 0 -1 | | 1 0 | = | 0 1 |
|
|
|
|
// | 1 0 | | 0 -1 | | 1 0 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_90 | HWC_TRANSFORM_FLIP_V;
|
|
|
|
LOGD("Layer horizontally reflected then rotated 270 degrees");
|
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
}
|
2014-06-17 21:35:51 +04:00
|
|
|
} else if (rotation._11 < 0) {
|
|
|
|
if (rotation._22 > 0) {
|
2013-08-14 23:26:44 +04:00
|
|
|
// Horizontal reflection
|
|
|
|
//
|
|
|
|
// | -1 0 |
|
|
|
|
// | 0 1 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_FLIP_H;
|
|
|
|
LOGD("Layer rotated 180 degrees");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// 180 degree rotation
|
|
|
|
//
|
|
|
|
// | -1 0 |
|
|
|
|
// | 0 -1 |
|
|
|
|
//
|
|
|
|
// Same as horizontal and vertical reflection
|
|
|
|
//
|
|
|
|
// | -1 0 | | 1 0 | = | -1 0 |
|
|
|
|
// | 0 1 | | 0 -1 | | 0 -1 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_180;
|
|
|
|
LOGD("Layer rotated 180 degrees");
|
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
} else {
|
2014-06-17 21:35:51 +04:00
|
|
|
if (rotation._22 < 0) {
|
2013-08-14 23:26:44 +04:00
|
|
|
// Vertical reflection
|
|
|
|
//
|
|
|
|
// | 1 0 |
|
|
|
|
// | 0 -1 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_FLIP_V;
|
|
|
|
LOGD("Layer rotated 180 degrees");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No rotation or reflection
|
|
|
|
//
|
|
|
|
// | 1 0 |
|
|
|
|
// | 0 1 |
|
|
|
|
//
|
|
|
|
hwcLayer.transform = 0;
|
|
|
|
}
|
2012-11-19 21:58:37 +04:00
|
|
|
}
|
|
|
|
|
2014-11-18 04:02:19 +03:00
|
|
|
const bool needsYFlip = state.OriginBottomLeft() ? true
|
|
|
|
: false;
|
|
|
|
|
|
|
|
if (needsYFlip) {
|
2013-08-14 23:26:44 +04:00
|
|
|
// Invert vertical reflection flag if it was already set
|
|
|
|
hwcLayer.transform ^= HWC_TRANSFORM_FLIP_V;
|
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
hwc_region_t region;
|
2013-04-30 04:21:54 +04:00
|
|
|
if (visibleRegion.GetNumRects() > 1) {
|
2013-08-29 19:17:59 +04:00
|
|
|
mVisibleRegions.push_back(HwcUtils::RectVector());
|
|
|
|
HwcUtils::RectVector* visibleRects = &(mVisibleRegions.back());
|
2015-06-04 17:07:36 +03:00
|
|
|
bool isVisible = false;
|
2013-08-29 19:17:59 +04:00
|
|
|
if(!HwcUtils::PrepareVisibleRegion(visibleRegion,
|
2014-12-07 04:12:50 +03:00
|
|
|
layerTransform,
|
|
|
|
layerBufferTransform,
|
2013-04-30 04:21:54 +04:00
|
|
|
clip,
|
|
|
|
bufferRect,
|
2015-06-04 17:07:36 +03:00
|
|
|
visibleRects,
|
|
|
|
isVisible)) {
|
|
|
|
LOGD("A region of layer is too small to be rendered by HWC");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!isVisible) {
|
|
|
|
// Layer is not visible, no need to render it
|
2013-04-30 04:21:54 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
region.numRects = visibleRects->size();
|
|
|
|
region.rects = &((*visibleRects)[0]);
|
|
|
|
} else {
|
|
|
|
region.numRects = 1;
|
|
|
|
region.rects = &(hwcLayer.displayFrame);
|
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
hwcLayer.visibleRegionScreen = region;
|
|
|
|
} else {
|
2013-08-29 19:17:59 +04:00
|
|
|
hwcLayer.flags |= HwcUtils::HWC_COLOR_FILL;
|
2013-04-30 04:20:51 +04:00
|
|
|
ColorLayer* colorLayer = aLayer->AsColorLayer();
|
|
|
|
if (colorLayer->GetColor().a < 1.0) {
|
|
|
|
LOGD("Color layer has semitransparency which is unsupported");
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-09 16:56:37 +04:00
|
|
|
hwcLayer.transform = colorLayer->GetColor().Packed();
|
|
|
|
}
|
2012-11-19 21:58:37 +04:00
|
|
|
|
2013-10-16 01:01:42 +04:00
|
|
|
mHwcLayerMap.AppendElement(static_cast<LayerComposite*>(aLayer->ImplData()));
|
2012-11-19 21:58:37 +04:00
|
|
|
mList->numHwLayers++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2014-02-21 17:30:20 +04:00
|
|
|
#if ANDROID_VERSION >= 17
|
2013-09-11 17:10:33 +04:00
|
|
|
bool
|
|
|
|
HwcComposer2D::TryHwComposition()
|
|
|
|
{
|
2015-04-23 16:49:40 +03:00
|
|
|
DisplaySurface* dispSurface = (DisplaySurface*)(GetGonkDisplay()->GetDispSurface());
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2015-04-23 16:49:40 +03:00
|
|
|
if (!(dispSurface && dispSurface->lastHandle)) {
|
|
|
|
LOGD("H/W Composition failed. DispSurface not initialized.");
|
2013-10-08 19:29:35 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add FB layer
|
|
|
|
int idx = mList->numHwLayers++;
|
|
|
|
if (idx >= mMaxLayerCount) {
|
|
|
|
if (!ReallocLayerList() || idx >= mMaxLayerCount) {
|
|
|
|
LOGE("TryHwComposition failed! Could not add FB layer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:49:40 +03:00
|
|
|
Prepare(dispSurface->lastHandle, -1);
|
2013-10-08 19:29:35 +04:00
|
|
|
|
2014-01-16 21:47:35 +04:00
|
|
|
/* Possible composition paths, after hwc prepare:
|
|
|
|
1. GPU Composition
|
|
|
|
2. BLIT Composition
|
|
|
|
3. Full OVERLAY Composition
|
|
|
|
4. Partial OVERLAY Composition (GPU + OVERLAY) */
|
|
|
|
|
|
|
|
bool gpuComposite = false;
|
|
|
|
bool blitComposite = false;
|
|
|
|
bool overlayComposite = true;
|
|
|
|
|
|
|
|
for (int j=0; j < idx; j++) {
|
|
|
|
if (mList->hwLayers[j].compositionType == HWC_FRAMEBUFFER ||
|
|
|
|
mList->hwLayers[j].compositionType == HWC_BLIT) {
|
|
|
|
// Full OVERLAY composition is not possible on this frame
|
|
|
|
// It is either GPU / BLIT / partial OVERLAY composition.
|
|
|
|
overlayComposite = false;
|
2013-10-16 01:01:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-16 21:47:35 +04:00
|
|
|
if (!overlayComposite) {
|
2013-10-16 01:01:42 +04:00
|
|
|
for (int k=0; k < idx; k++) {
|
2014-01-16 21:47:35 +04:00
|
|
|
switch (mList->hwLayers[k].compositionType) {
|
|
|
|
case HWC_FRAMEBUFFER:
|
|
|
|
gpuComposite = true;
|
|
|
|
break;
|
|
|
|
case HWC_BLIT:
|
|
|
|
blitComposite = true;
|
|
|
|
break;
|
|
|
|
case HWC_OVERLAY:
|
|
|
|
// HWC will compose HWC_OVERLAY layers in partial
|
|
|
|
// Overlay Composition, set layer composition flag
|
|
|
|
// on mapped LayerComposite to skip GPU composition
|
|
|
|
mHwcLayerMap[k]->SetLayerComposited(true);
|
2014-03-14 01:22:18 +04:00
|
|
|
if ((mList->hwLayers[k].hints & HWC_HINT_CLEAR_FB) &&
|
2014-01-18 06:55:30 +04:00
|
|
|
(mList->hwLayers[k].blending == HWC_BLENDING_NONE)) {
|
|
|
|
// Clear visible rect on FB with transparent pixels.
|
2014-02-27 23:07:34 +04:00
|
|
|
hwc_rect_t r = mList->hwLayers[k].displayFrame;
|
|
|
|
mHwcLayerMap[k]->SetClearRect(nsIntRect(r.left, r.top,
|
|
|
|
r.right - r.left,
|
|
|
|
r.bottom - r.top));
|
2014-01-18 06:55:30 +04:00
|
|
|
}
|
2014-01-16 21:47:35 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-10-16 01:01:42 +04:00
|
|
|
}
|
2013-10-08 19:29:35 +04:00
|
|
|
}
|
2014-01-16 21:47:35 +04:00
|
|
|
|
|
|
|
if (gpuComposite) {
|
|
|
|
// GPU or partial OVERLAY Composition
|
|
|
|
return false;
|
|
|
|
} else if (blitComposite) {
|
2015-04-23 16:49:40 +03:00
|
|
|
// BLIT Composition, flip DispSurface target
|
|
|
|
GetGonkDisplay()->UpdateDispSurface(mDpy, mSur);
|
|
|
|
DisplaySurface* dispSurface = (DisplaySurface*)(GetGonkDisplay()->GetDispSurface());
|
|
|
|
if (!dispSurface) {
|
|
|
|
LOGE("H/W Composition failed. NULL DispSurface.");
|
2014-01-16 21:47:35 +04:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-23 16:49:40 +03:00
|
|
|
mList->hwLayers[idx].handle = dispSurface->lastHandle;
|
|
|
|
mList->hwLayers[idx].acquireFenceFd = dispSurface->GetPrevDispAcquireFd();
|
2014-01-16 21:47:35 +04:00
|
|
|
}
|
2013-10-08 19:29:35 +04:00
|
|
|
}
|
|
|
|
|
2014-01-16 21:47:35 +04:00
|
|
|
// BLIT or full OVERLAY Composition
|
2013-10-08 19:29:35 +04:00
|
|
|
Commit();
|
|
|
|
|
2015-04-23 16:49:40 +03:00
|
|
|
GetGonkDisplay()->SetDispReleaseFd(mList->hwLayers[idx].releaseFenceFd);
|
2014-08-08 01:34:25 +04:00
|
|
|
mList->hwLayers[idx].releaseFenceFd = -1;
|
2013-10-08 19:29:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-17 19:28:41 +03:00
|
|
|
HwcComposer2D::Render()
|
2013-10-08 19:29:35 +04:00
|
|
|
{
|
2015-04-17 19:28:41 +03:00
|
|
|
// HWC module does not exist or mList is not created yet.
|
|
|
|
if (!mHwc || !mList) {
|
|
|
|
return GetGonkDisplay()->SwapBuffers(mDpy, mSur);
|
2013-10-08 19:29:35 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 16:49:40 +03:00
|
|
|
DisplaySurface* dispSurface = (DisplaySurface*)(GetGonkDisplay()->GetDispSurface());
|
|
|
|
if (!dispSurface) {
|
|
|
|
LOGE("H/W Composition failed. DispSurface not initialized.");
|
2013-09-11 17:10:33 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-12 00:37:25 +04:00
|
|
|
if (mPrepared) {
|
2013-10-08 19:29:35 +04:00
|
|
|
// No mHwc prepare, if already prepared in current draw cycle
|
2015-04-23 16:49:40 +03:00
|
|
|
mList->hwLayers[mList->numHwLayers - 1].handle = dispSurface->lastHandle;
|
|
|
|
mList->hwLayers[mList->numHwLayers - 1].acquireFenceFd = dispSurface->GetPrevDispAcquireFd();
|
2013-10-08 19:29:35 +04:00
|
|
|
} else {
|
2014-04-04 05:59:13 +04:00
|
|
|
mList->flags = HWC_GEOMETRY_CHANGED;
|
2013-10-08 19:29:35 +04:00
|
|
|
mList->numHwLayers = 2;
|
|
|
|
mList->hwLayers[0].hints = 0;
|
2014-03-28 22:05:43 +04:00
|
|
|
mList->hwLayers[0].compositionType = HWC_FRAMEBUFFER;
|
2013-10-08 19:29:35 +04:00
|
|
|
mList->hwLayers[0].flags = HWC_SKIP_LAYER;
|
|
|
|
mList->hwLayers[0].backgroundColor = {0};
|
2013-12-03 04:58:39 +04:00
|
|
|
mList->hwLayers[0].acquireFenceFd = -1;
|
|
|
|
mList->hwLayers[0].releaseFenceFd = -1;
|
2013-10-08 19:29:35 +04:00
|
|
|
mList->hwLayers[0].displayFrame = {0, 0, mScreenRect.width, mScreenRect.height};
|
2015-04-23 16:49:40 +03:00
|
|
|
Prepare(dispSurface->lastHandle, dispSurface->GetPrevDispAcquireFd());
|
2013-10-08 19:29:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GPU or partial HWC Composition
|
|
|
|
Commit();
|
|
|
|
|
2015-04-23 16:49:40 +03:00
|
|
|
GetGonkDisplay()->SetDispReleaseFd(mList->hwLayers[mList->numHwLayers - 1].releaseFenceFd);
|
2014-08-08 01:34:25 +04:00
|
|
|
mList->hwLayers[mList->numHwLayers - 1].releaseFenceFd = -1;
|
2013-10-08 19:29:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-23 16:49:40 +03:00
|
|
|
HwcComposer2D::Prepare(buffer_handle_t dispHandle, int fence)
|
2013-10-08 19:29:35 +04:00
|
|
|
{
|
|
|
|
int idx = mList->numHwLayers - 1;
|
2013-09-11 17:10:33 +04:00
|
|
|
const hwc_rect_t r = {0, 0, mScreenRect.width, mScreenRect.height};
|
2013-10-08 19:29:35 +04:00
|
|
|
hwc_display_contents_1_t *displays[HWC_NUM_DISPLAY_TYPES] = { nullptr };
|
2013-09-11 17:10:33 +04:00
|
|
|
|
|
|
|
displays[HWC_DISPLAY_PRIMARY] = mList;
|
2013-10-08 19:29:35 +04:00
|
|
|
mList->outbufAcquireFenceFd = -1;
|
|
|
|
mList->outbuf = nullptr;
|
2013-09-11 17:10:33 +04:00
|
|
|
mList->retireFenceFd = -1;
|
|
|
|
|
|
|
|
mList->hwLayers[idx].hints = 0;
|
|
|
|
mList->hwLayers[idx].flags = 0;
|
|
|
|
mList->hwLayers[idx].transform = 0;
|
2015-04-23 16:49:40 +03:00
|
|
|
mList->hwLayers[idx].handle = dispHandle;
|
2013-09-11 17:10:33 +04:00
|
|
|
mList->hwLayers[idx].blending = HWC_BLENDING_PREMULT;
|
|
|
|
mList->hwLayers[idx].compositionType = HWC_FRAMEBUFFER_TARGET;
|
2014-02-06 02:55:00 +04:00
|
|
|
setCrop(&mList->hwLayers[idx], r);
|
2013-09-11 17:10:33 +04:00
|
|
|
mList->hwLayers[idx].displayFrame = r;
|
|
|
|
mList->hwLayers[idx].visibleRegionScreen.numRects = 1;
|
2014-02-06 02:55:00 +04:00
|
|
|
mList->hwLayers[idx].visibleRegionScreen.rects = &mList->hwLayers[idx].displayFrame;
|
2013-10-08 19:29:35 +04:00
|
|
|
mList->hwLayers[idx].acquireFenceFd = fence;
|
2013-09-11 17:10:33 +04:00
|
|
|
mList->hwLayers[idx].releaseFenceFd = -1;
|
2014-02-21 17:30:20 +04:00
|
|
|
#if ANDROID_VERSION >= 18
|
2013-09-11 17:10:33 +04:00
|
|
|
mList->hwLayers[idx].planeAlpha = 0xFF;
|
2014-02-21 17:30:20 +04:00
|
|
|
#endif
|
2013-12-12 00:37:25 +04:00
|
|
|
if (mPrepared) {
|
|
|
|
LOGE("Multiple hwc prepare calls!");
|
|
|
|
}
|
2013-09-11 17:10:33 +04:00
|
|
|
mHwc->prepare(mHwc, HWC_NUM_DISPLAY_TYPES, displays);
|
2013-12-12 00:37:25 +04:00
|
|
|
mPrepared = true;
|
2013-10-08 19:29:35 +04:00
|
|
|
}
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2013-10-08 19:29:35 +04:00
|
|
|
bool
|
|
|
|
HwcComposer2D::Commit()
|
|
|
|
{
|
|
|
|
hwc_display_contents_1_t *displays[HWC_NUM_DISPLAY_TYPES] = { nullptr };
|
|
|
|
displays[HWC_DISPLAY_PRIMARY] = mList;
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2014-06-13 05:46:25 +04:00
|
|
|
for (uint32_t j=0; j < (mList->numHwLayers - 1); j++) {
|
2014-08-08 01:34:25 +04:00
|
|
|
mList->hwLayers[j].acquireFenceFd = -1;
|
2014-06-17 00:05:14 +04:00
|
|
|
if (mHwcLayerMap.IsEmpty() ||
|
2014-06-13 05:46:25 +04:00
|
|
|
(mList->hwLayers[j].compositionType == HWC_FRAMEBUFFER)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LayerRenderState state = mHwcLayerMap[j]->GetLayer()->GetRenderState();
|
|
|
|
if (!state.mTexture) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-20 08:43:00 +03:00
|
|
|
FenceHandle fence = state.mTexture->GetAndResetAcquireFenceHandle();
|
2015-05-13 01:37:00 +03:00
|
|
|
if (fence.IsValid()) {
|
|
|
|
nsRefPtr<FenceHandle::FdObj> fdObj = fence.GetAndResetFdObj();
|
|
|
|
mList->hwLayers[j].acquireFenceFd = fdObj->GetAndResetFd();
|
2014-06-13 05:46:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 19:29:35 +04:00
|
|
|
int err = mHwc->set(mHwc, HWC_NUM_DISPLAY_TYPES, displays);
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2015-05-13 01:37:00 +03:00
|
|
|
mPrevRetireFence.TransferToAnotherFenceHandle(mPrevDisplayFence);
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2013-10-16 01:01:42 +04:00
|
|
|
for (uint32_t j=0; j < (mList->numHwLayers - 1); j++) {
|
2013-11-28 05:38:42 +04:00
|
|
|
if (mList->hwLayers[j].releaseFenceFd >= 0) {
|
2014-02-25 08:23:41 +04:00
|
|
|
int fd = mList->hwLayers[j].releaseFenceFd;
|
|
|
|
mList->hwLayers[j].releaseFenceFd = -1;
|
2015-05-13 01:37:00 +03:00
|
|
|
nsRefPtr<FenceHandle::FdObj> fdObj = new FenceHandle::FdObj(fd);
|
|
|
|
FenceHandle fence(fdObj);
|
2014-02-25 08:23:41 +04:00
|
|
|
|
|
|
|
LayerRenderState state = mHwcLayerMap[j]->GetLayer()->GetRenderState();
|
|
|
|
if (!state.mTexture) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-20 08:43:00 +03:00
|
|
|
state.mTexture->SetReleaseFenceHandle(fence);
|
2015-05-13 01:37:00 +03:00
|
|
|
}
|
|
|
|
}
|
2013-09-11 17:10:33 +04:00
|
|
|
|
2013-11-28 05:38:42 +04:00
|
|
|
if (mList->retireFenceFd >= 0) {
|
2015-05-13 01:37:00 +03:00
|
|
|
mPrevRetireFence = FenceHandle(new FenceHandle::FdObj(mList->retireFenceFd));
|
2013-11-28 05:38:42 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 00:37:25 +04:00
|
|
|
mPrepared = false;
|
2013-10-08 19:29:35 +04:00
|
|
|
return !err;
|
2013-09-11 17:10:33 +04:00
|
|
|
}
|
2013-12-12 00:37:25 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
HwcComposer2D::Reset()
|
|
|
|
{
|
|
|
|
LOGD("hwcomposer is already prepared, reset with null set");
|
|
|
|
hwc_display_contents_1_t *displays[HWC_NUM_DISPLAY_TYPES] = { nullptr };
|
|
|
|
displays[HWC_DISPLAY_PRIMARY] = nullptr;
|
|
|
|
mHwc->set(mHwc, HWC_DISPLAY_PRIMARY, displays);
|
|
|
|
mPrepared = false;
|
|
|
|
}
|
2013-09-11 17:10:33 +04:00
|
|
|
#else
|
|
|
|
bool
|
|
|
|
HwcComposer2D::TryHwComposition()
|
|
|
|
{
|
|
|
|
return !mHwc->set(mHwc, mDpy, mSur, mList);
|
|
|
|
}
|
2013-10-08 19:29:35 +04:00
|
|
|
|
|
|
|
bool
|
2015-04-17 19:28:41 +03:00
|
|
|
HwcComposer2D::Render()
|
2013-10-08 19:29:35 +04:00
|
|
|
{
|
2015-04-17 19:28:41 +03:00
|
|
|
return GetGonkDisplay()->SwapBuffers(mDpy, mSur);
|
2013-10-08 19:29:35 +04:00
|
|
|
}
|
2013-12-12 00:37:25 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
HwcComposer2D::Reset()
|
|
|
|
{
|
|
|
|
mPrepared = false;
|
|
|
|
}
|
2013-09-11 17:10:33 +04:00
|
|
|
#endif
|
|
|
|
|
2012-11-19 21:58:37 +04:00
|
|
|
bool
|
2015-04-17 19:28:41 +03:00
|
|
|
HwcComposer2D::TryRenderWithHwc(Layer* aRoot,
|
|
|
|
bool aGeometryChanged)
|
2012-11-19 21:58:37 +04:00
|
|
|
{
|
2015-04-17 19:28:41 +03:00
|
|
|
if (!mHwc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-19 21:58:37 +04:00
|
|
|
if (mList) {
|
2014-04-04 05:59:13 +04:00
|
|
|
setHwcGeometry(aGeometryChanged);
|
2012-11-19 21:58:37 +04:00
|
|
|
mList->numHwLayers = 0;
|
2013-10-16 01:01:42 +04:00
|
|
|
mHwcLayerMap.Clear();
|
2012-11-19 21:58:37 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 00:37:25 +04:00
|
|
|
if (mPrepared) {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2013-04-30 04:21:54 +04:00
|
|
|
// XXX: The clear() below means all rect vectors will be have to be
|
|
|
|
// reallocated. We may want to avoid this if possible
|
|
|
|
mVisibleRegions.clear();
|
|
|
|
|
2013-10-16 01:01:42 +04:00
|
|
|
MOZ_ASSERT(mHwcLayerMap.IsEmpty());
|
2013-01-18 01:34:01 +04:00
|
|
|
if (!PrepareLayerList(aRoot,
|
|
|
|
mScreenRect,
|
2014-09-10 23:59:00 +04:00
|
|
|
gfx::Matrix()))
|
2013-01-18 01:34:01 +04:00
|
|
|
{
|
2014-06-17 00:05:14 +04:00
|
|
|
mHwcLayerMap.Clear();
|
2012-11-19 21:58:37 +04:00
|
|
|
LOGD("Render aborted. Nothing was drawn to the screen");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
// Send data to LayerScope for debugging
|
|
|
|
SendtoLayerScope();
|
|
|
|
|
2013-09-11 17:10:33 +04:00
|
|
|
if (!TryHwComposition()) {
|
2015-04-17 19:28:41 +03:00
|
|
|
LOGD("Full HWC Composition failed. Fallback to GPU Composition or partial OVERLAY Composition");
|
2014-07-03 03:17:00 +04:00
|
|
|
LayerScope::CleanLayer();
|
2013-10-08 19:29:35 +04:00
|
|
|
return false;
|
2012-11-19 21:58:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGD("Frame rendered");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
HwcComposer2D::SendtoLayerScope()
|
|
|
|
{
|
|
|
|
if (!LayerScope::CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int len = mList->numHwLayers;
|
|
|
|
for (int i = 0; i < len; ++i) {
|
|
|
|
LayerComposite* layer = mHwcLayerMap[i];
|
|
|
|
const hwc_rect_t r = mList->hwLayers[i].displayFrame;
|
|
|
|
LayerScope::SendLayer(layer, r.right - r.left, r.bottom - r.top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 21:58:37 +04:00
|
|
|
} // namespace mozilla
|