2012-11-19 09:58:37 -08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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-07 20:58:22 -07:00
|
|
|
#include <string.h>
|
2012-11-19 09:58:37 -08:00
|
|
|
|
2013-05-07 20:58:22 -07:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
2012-11-19 09:58:37 -08:00
|
|
|
#include "Framebuffer.h"
|
|
|
|
#include "HwcComposer2D.h"
|
2013-06-05 15:14:51 -07:00
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
2013-04-24 11:42:40 -07:00
|
|
|
#include "mozilla/layers/PLayerTransaction.h"
|
2012-11-19 09:58:37 -08:00
|
|
|
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-01-09 04:56:37 -08:00
|
|
|
#include "cutils/properties.h"
|
2013-01-17 13:34:01 -08:00
|
|
|
#include "gfxUtils.h"
|
2012-11-19 09:58:37 -08:00
|
|
|
|
|
|
|
#define LOG_TAG "HWComposer"
|
|
|
|
|
|
|
|
#if (LOG_NDEBUG == 0)
|
|
|
|
#define LOGD(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, ## args)
|
|
|
|
#else
|
|
|
|
#define LOGD(args...) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
|
|
|
|
|
|
|
|
#define LAYER_COUNT_INCREMENTS 5
|
|
|
|
|
|
|
|
using namespace android;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
HWC_USE_GPU = HWC_FRAMEBUFFER,
|
|
|
|
HWC_USE_OVERLAY = HWC_OVERLAY,
|
|
|
|
HWC_USE_COPYBIT
|
|
|
|
};
|
|
|
|
|
2013-01-09 04:56:37 -08:00
|
|
|
// HWC layer flags
|
|
|
|
enum {
|
|
|
|
// Draw a solid color rectangle
|
|
|
|
// The color should be set on the transform member of the hwc_layer_t struct
|
|
|
|
// The expected format is a 32 bit ABGR with 8 bits per component
|
2013-06-11 03:14:33 -07:00
|
|
|
HWC_COLOR_FILL = 0x8,
|
|
|
|
// Swap the RB pixels of gralloc buffer, like RGBA<->BGRA or RGBX<->BGRX
|
|
|
|
// The flag will be set inside LayerRenderState
|
|
|
|
HWC_FORMAT_RB_SWAP = 0x40
|
2013-01-09 04:56:37 -08:00
|
|
|
};
|
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
static StaticRefPtr<HwcComposer2D> sInstance;
|
|
|
|
|
|
|
|
HwcComposer2D::HwcComposer2D()
|
|
|
|
: mMaxLayerCount(0)
|
|
|
|
, mList(nullptr)
|
2013-05-07 20:58:22 -07:00
|
|
|
, mHwc(nullptr)
|
2012-11-19 09:58:37 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HwcComposer2D::~HwcComposer2D() {
|
|
|
|
free(mList);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
HwcComposer2D::Init(hwc_display_t dpy, hwc_surface_t sur)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!Initialized());
|
|
|
|
|
2013-05-07 20:58:22 -07:00
|
|
|
mHwc = (hwc_composer_device_t*)GetGonkDisplay()->GetHWCDevice();
|
|
|
|
if (!mHwc) {
|
2012-11-19 09:58:37 -08:00
|
|
|
LOGE("Failed to initialize hwc");
|
2013-05-07 20:58:22 -07:00
|
|
|
return -1;
|
2012-11-19 09:58:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntSize screenSize;
|
|
|
|
|
|
|
|
mozilla::Framebuffer::GetSize(&screenSize);
|
2013-01-17 13:34:01 -08:00
|
|
|
mScreenRect = nsIntRect(nsIntPoint(0, 0), screenSize);
|
2012-11-19 09:58:37 -08:00
|
|
|
|
2013-01-09 04:56:37 -08:00
|
|
|
char propValue[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.display.colorfill", propValue, "0");
|
|
|
|
mColorFill = (atoi(propValue) == 1) ? true : false;
|
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
mDpy = dpy;
|
|
|
|
mSur = sur;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HwcComposer2D*
|
|
|
|
HwcComposer2D::GetInstance()
|
|
|
|
{
|
|
|
|
if (!sInstance) {
|
|
|
|
LOGD("Creating new instance");
|
|
|
|
sInstance = new HwcComposer2D();
|
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HwcComposer2D::ReallocLayerList()
|
|
|
|
{
|
|
|
|
int size = sizeof(hwc_layer_list_t) +
|
|
|
|
((mMaxLayerCount + LAYER_COUNT_INCREMENTS) * sizeof(hwc_layer_t));
|
|
|
|
|
|
|
|
hwc_layer_list_t* listrealloc = (hwc_layer_list_t*)realloc(mList, size);
|
|
|
|
|
|
|
|
if (!listrealloc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mList) {
|
|
|
|
//first alloc, initialize
|
|
|
|
listrealloc->numHwLayers = 0;
|
|
|
|
listrealloc->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mList = listrealloc;
|
|
|
|
mMaxLayerCount += LAYER_COUNT_INCREMENTS;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets hwc layer rectangles required for hwc composition
|
|
|
|
*
|
|
|
|
* @param aVisible Input. Layer's unclipped visible rectangle
|
2013-01-10 02:51:43 -08:00
|
|
|
* The origin is the top-left corner of the layer
|
2012-11-19 09:58:37 -08:00
|
|
|
* @param aTransform Input. Layer's transformation matrix
|
|
|
|
* It transforms from layer space to screen space
|
|
|
|
* @param aClip Input. A clipping rectangle.
|
|
|
|
* The origin is the top-left corner of the screen
|
|
|
|
* @param aBufferRect Input. The layer's buffer bounds
|
2013-01-10 02:51:43 -08:00
|
|
|
* The origin is the top-left corner of the layer
|
2012-11-19 09:58:37 -08:00
|
|
|
* @param aSurceCrop Output. Area of the source to consider,
|
|
|
|
* the origin is the top-left corner of the buffer
|
|
|
|
* @param aVisibleRegionScreen Output. Visible region in screen space.
|
|
|
|
* The origin is the top-left corner of the screen
|
|
|
|
* @return true if the layer should be rendered.
|
|
|
|
* false if the layer can be skipped
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform,
|
|
|
|
nsIntRect aClip, nsIntRect aBufferRect,
|
|
|
|
hwc_rect_t* aSourceCrop, hwc_rect_t* aVisibleRegionScreen) {
|
|
|
|
|
|
|
|
gfxRect visibleRect(aVisible);
|
|
|
|
gfxRect clip(aClip);
|
|
|
|
gfxRect visibleRectScreen = aTransform.TransformBounds(visibleRect);
|
|
|
|
// |clip| is guaranteed to be integer
|
|
|
|
visibleRectScreen.IntersectRect(visibleRectScreen, clip);
|
|
|
|
|
|
|
|
if (visibleRectScreen.IsEmpty()) {
|
|
|
|
LOGD("Skip layer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix inverse(aTransform);
|
|
|
|
inverse.Invert();
|
|
|
|
gfxRect crop = inverse.TransformBounds(visibleRectScreen);
|
2013-01-10 02:51:43 -08:00
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
//clip to buffer size
|
|
|
|
crop.IntersectRect(crop, aBufferRect);
|
2013-04-29 16:51:51 -07:00
|
|
|
crop.Round();
|
2012-11-19 09:58:37 -08:00
|
|
|
|
|
|
|
if (crop.IsEmpty()) {
|
|
|
|
LOGD("Skip layer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//propagate buffer clipping back to visible rect
|
2013-01-10 02:51:43 -08:00
|
|
|
visibleRectScreen = aTransform.TransformBounds(crop);
|
2013-04-29 16:51:51 -07:00
|
|
|
visibleRectScreen.Round();
|
2012-11-19 09:58:37 -08:00
|
|
|
|
2013-01-10 02:51:43 -08:00
|
|
|
// Map from layer space to buffer space
|
|
|
|
crop -= aBufferRect.TopLeft();
|
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
aSourceCrop->left = crop.x;
|
|
|
|
aSourceCrop->top = crop.y;
|
|
|
|
aSourceCrop->right = crop.x + crop.width;
|
|
|
|
aSourceCrop->bottom = crop.y + crop.height;
|
|
|
|
|
|
|
|
aVisibleRegionScreen->left = visibleRectScreen.x;
|
|
|
|
aVisibleRegionScreen->top = visibleRectScreen.y;
|
|
|
|
aVisibleRegionScreen->right = visibleRectScreen.x + visibleRectScreen.width;
|
|
|
|
aVisibleRegionScreen->bottom = visibleRectScreen.y + visibleRectScreen.height;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-29 17:21:54 -07:00
|
|
|
/**
|
|
|
|
* Prepares hwc layer visible region required for hwc composition
|
|
|
|
*
|
|
|
|
* @param aVisible Input. Layer's unclipped visible region
|
|
|
|
* The origin is the top-left corner of the layer
|
|
|
|
* @param aTransform Input. Layer's transformation matrix
|
|
|
|
* It transforms from layer space to screen space
|
|
|
|
* @param aClip Input. A clipping rectangle.
|
|
|
|
* The origin is the top-left corner of the screen
|
|
|
|
* @param aBufferRect Input. The layer's buffer bounds
|
|
|
|
* The origin is the top-left corner of the layer
|
|
|
|
* @param aVisibleRegionScreen Output. Visible region in screen space.
|
|
|
|
* The origin is the top-left corner of the screen
|
|
|
|
* @return true if the layer should be rendered.
|
|
|
|
* false if the layer can be skipped
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
PrepareVisibleRegion(const nsIntRegion& aVisible,
|
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
nsIntRect aClip, nsIntRect aBufferRect,
|
|
|
|
RectVector* aVisibleRegionScreen) {
|
|
|
|
|
|
|
|
nsIntRegionRectIterator rect(aVisible);
|
|
|
|
bool isVisible = false;
|
|
|
|
while (const nsIntRect* visibleRect = rect.Next()) {
|
|
|
|
hwc_rect_t visibleRectScreen;
|
|
|
|
gfxRect screenRect;
|
|
|
|
|
|
|
|
screenRect.IntersectRect(gfxRect(*visibleRect), aBufferRect);
|
|
|
|
screenRect = aTransform.TransformBounds(screenRect);
|
|
|
|
screenRect.IntersectRect(screenRect, aClip);
|
2013-04-29 16:51:51 -07:00
|
|
|
screenRect.Round();
|
2013-04-29 17:21:54 -07:00
|
|
|
if (screenRect.IsEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
visibleRectScreen.left = screenRect.x;
|
|
|
|
visibleRectScreen.top = screenRect.y;
|
|
|
|
visibleRectScreen.right = screenRect.XMost();
|
|
|
|
visibleRectScreen.bottom = screenRect.YMost();
|
|
|
|
aVisibleRegionScreen->push_back(visibleRectScreen);
|
|
|
|
isVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isVisible;
|
|
|
|
}
|
|
|
|
|
2013-01-17 13:34:01 -08:00
|
|
|
/**
|
|
|
|
* Calculates the layer's clipping rectangle
|
|
|
|
*
|
|
|
|
* @param aTransform Input. A transformation matrix
|
|
|
|
* It transforms the clip rect to screen space
|
|
|
|
* @param aLayerClip Input. The layer's internal clipping rectangle.
|
|
|
|
* This may be NULL which means the layer has no internal clipping
|
|
|
|
* The origin is the top-left corner of the layer
|
|
|
|
* @param aParentClip Input. The parent layer's rendering clipping rectangle
|
|
|
|
* The origin is the top-left corner of the screen
|
|
|
|
* @param aRenderClip Output. The layer's rendering clipping rectangle
|
|
|
|
* The origin is the top-left corner of the screen
|
|
|
|
* @return true if the layer should be rendered.
|
|
|
|
* false if the layer can be skipped
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
CalculateClipRect(const gfxMatrix& aTransform, const nsIntRect* aLayerClip,
|
|
|
|
nsIntRect aParentClip, nsIntRect* aRenderClip) {
|
|
|
|
|
|
|
|
*aRenderClip = aParentClip;
|
|
|
|
|
|
|
|
if (!aLayerClip) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLayerClip->IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect clip = *aLayerClip;
|
|
|
|
|
|
|
|
gfxRect r(clip);
|
|
|
|
gfxRect trClip = aTransform.TransformBounds(r);
|
|
|
|
trClip.Round();
|
|
|
|
gfxUtils::GfxRectToIntRect(trClip, &clip);
|
|
|
|
|
|
|
|
aRenderClip->IntersectRect(*aRenderClip, clip);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
bool
|
|
|
|
HwcComposer2D::PrepareLayerList(Layer* aLayer,
|
2013-01-17 13:34:01 -08:00
|
|
|
const nsIntRect& aClip,
|
|
|
|
const gfxMatrix& aParentTransform,
|
|
|
|
const gfxMatrix& aGLWorldTransform)
|
2012-11-19 09:58:37 -08: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 04:56:37 -08:00
|
|
|
bool fillColor = false;
|
2012-11-19 09:58:37 -08:00
|
|
|
|
|
|
|
const nsIntRegion& visibleRegion = aLayer->GetEffectiveVisibleRegion();
|
|
|
|
if (visibleRegion.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
float opacity = aLayer->GetEffectiveOpacity();
|
2013-04-29 17:20:51 -07:00
|
|
|
if (opacity < 1) {
|
2013-06-11 03:14:33 -07:00
|
|
|
LOGD("%s Layer has planar semitransparency which is unsupported", aLayer->Name());
|
2012-11-19 09:58:37 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-17 13:34:01 -08:00
|
|
|
nsIntRect clip;
|
|
|
|
if (!CalculateClipRect(aParentTransform * aGLWorldTransform,
|
|
|
|
aLayer->GetEffectiveClipRect(),
|
|
|
|
aClip,
|
|
|
|
&clip))
|
|
|
|
{
|
2013-06-11 03:14:33 -07:00
|
|
|
LOGD("%s Clip rect is empty. Skip layer", aLayer->Name());
|
2013-01-17 13:34:01 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix transform;
|
|
|
|
const gfx3DMatrix& transform3D = aLayer->GetEffectiveTransform();
|
|
|
|
if (!transform3D.Is2D(&transform) || !transform.PreservesAxisAlignedRectangles()) {
|
|
|
|
LOGD("Layer has a 3D transform or a non-square angle rotation");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
|
|
|
|
if (ContainerLayer* container = aLayer->AsContainerLayer()) {
|
|
|
|
if (container->UseIntermediateSurface()) {
|
|
|
|
LOGD("Container layer needs intermediate surface");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsAutoTArray<Layer*, 12> children;
|
|
|
|
container->SortChildrenBy3DZOrder(children);
|
|
|
|
|
2013-01-07 15:21:50 -08:00
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
2013-01-17 13:34:01 -08:00
|
|
|
if (!PrepareLayerList(children[i], clip, transform, aGLWorldTransform)) {
|
2012-11-19 09:58:37 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:14:51 -07:00
|
|
|
LayerRenderState state = aLayer->GetRenderState();
|
2013-04-29 17:21:16 -07:00
|
|
|
nsIntSize surfaceSize;
|
2012-11-19 09:58:37 -08:00
|
|
|
|
2013-06-05 15:14:51 -07:00
|
|
|
if (state.mSurface.get()) {
|
|
|
|
surfaceSize = state.mSize;
|
|
|
|
} else {
|
2013-01-09 04:56:37 -08:00
|
|
|
if (aLayer->AsColorLayer() && mColorFill) {
|
|
|
|
fillColor = true;
|
|
|
|
} else {
|
2013-06-11 03:14:33 -07:00
|
|
|
LOGD("%s Layer doesn't have a gralloc buffer", aLayer->Name());
|
2013-01-09 04:56:37 -08:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-19 09:58:37 -08:00
|
|
|
}
|
|
|
|
if (state.BufferRotated()) {
|
2013-06-11 03:14:33 -07:00
|
|
|
LOGD("%s Layer has a rotated buffer", aLayer->Name());
|
2012-11-19 09:58:37 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// OK! We can compose this layer with hwc.
|
|
|
|
|
|
|
|
int current = mList ? mList->numHwLayers : 0;
|
|
|
|
if (!mList || current >= mMaxLayerCount) {
|
|
|
|
if (!ReallocLayerList() || current >= mMaxLayerCount) {
|
|
|
|
LOGE("PrepareLayerList failed! Could not increase the maximum layer count");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect visibleRect = visibleRegion.GetBounds();
|
|
|
|
|
2013-01-09 04:56:37 -08:00
|
|
|
nsIntRect bufferRect;
|
|
|
|
if (fillColor) {
|
2013-01-10 02:51:43 -08:00
|
|
|
bufferRect = nsIntRect(visibleRect);
|
2013-01-09 04:56:37 -08:00
|
|
|
} else {
|
2013-01-10 02:51:43 -08:00
|
|
|
if(state.mHasOwnOffset) {
|
|
|
|
bufferRect = nsIntRect(state.mOffset.x, state.mOffset.y,
|
2013-06-05 15:14:51 -07:00
|
|
|
state.mSize.width, state.mSize.height);
|
2013-01-10 02:51:43 -08:00
|
|
|
} else {
|
2013-06-27 19:22:37 -07: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);
|
2013-01-10 02:51:43 -08:00
|
|
|
}
|
2013-01-09 04:56:37 -08:00
|
|
|
}
|
2012-11-19 09:58:37 -08:00
|
|
|
|
|
|
|
hwc_layer_t& hwcLayer = mList->hwLayers[current];
|
|
|
|
|
2013-01-17 13:34:01 -08:00
|
|
|
if(!PrepareLayerRects(visibleRect,
|
|
|
|
transform * aGLWorldTransform,
|
|
|
|
clip,
|
|
|
|
bufferRect,
|
|
|
|
&(hwcLayer.sourceCrop),
|
|
|
|
&(hwcLayer.displayFrame)))
|
|
|
|
{
|
2012-11-19 09:58:37 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:14:51 -07:00
|
|
|
buffer_handle_t handle = fillColor ? nullptr : state.mSurface->getNativeBuffer()->handle;
|
2012-11-19 09:58:37 -08:00
|
|
|
hwcLayer.handle = handle;
|
|
|
|
|
|
|
|
hwcLayer.flags = 0;
|
|
|
|
hwcLayer.hints = 0;
|
2013-02-12 10:47:07 -08:00
|
|
|
hwcLayer.blending = HWC_BLENDING_PREMULT;
|
2012-11-19 09:58:37 -08:00
|
|
|
hwcLayer.compositionType = HWC_USE_COPYBIT;
|
|
|
|
|
2013-01-09 04:56:37 -08:00
|
|
|
if (!fillColor) {
|
2013-06-11 03:14:33 -07:00
|
|
|
if (state.FormatRBSwapped()) {
|
|
|
|
hwcLayer.flags |= HWC_FORMAT_RB_SWAP;
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:21:04 -08:00
|
|
|
gfxMatrix rotation = transform * aGLWorldTransform;
|
|
|
|
// Compute fuzzy equal like PreservesAxisAlignedRectangles()
|
|
|
|
if (fabs(rotation.xx) < 1e-6) {
|
|
|
|
if (rotation.xy < 0) {
|
2013-01-09 04:56:37 -08:00
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_90;
|
|
|
|
LOGD("Layer buffer rotated 90 degrees");
|
|
|
|
} else {
|
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_270;
|
|
|
|
LOGD("Layer buffer rotated 270 degrees");
|
|
|
|
}
|
2013-01-29 17:21:04 -08:00
|
|
|
} else if (rotation.xx < 0) {
|
2013-01-09 04:56:37 -08:00
|
|
|
hwcLayer.transform = HWC_TRANSFORM_ROT_180;
|
|
|
|
LOGD("Layer buffer rotated 180 degrees");
|
|
|
|
} else {
|
|
|
|
hwcLayer.transform = 0;
|
2012-11-19 09:58:37 -08:00
|
|
|
}
|
|
|
|
|
2013-01-09 04:56:37 -08:00
|
|
|
hwcLayer.transform |= state.YFlipped() ? HWC_TRANSFORM_FLIP_V : 0;
|
|
|
|
hwc_region_t region;
|
2013-04-29 17:21:54 -07:00
|
|
|
if (visibleRegion.GetNumRects() > 1) {
|
|
|
|
mVisibleRegions.push_back(RectVector());
|
|
|
|
RectVector* visibleRects = &(mVisibleRegions.back());
|
|
|
|
if(!PrepareVisibleRegion(visibleRegion,
|
|
|
|
transform * aGLWorldTransform,
|
|
|
|
clip,
|
|
|
|
bufferRect,
|
|
|
|
visibleRects)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
region.numRects = visibleRects->size();
|
|
|
|
region.rects = &((*visibleRects)[0]);
|
|
|
|
} else {
|
|
|
|
region.numRects = 1;
|
|
|
|
region.rects = &(hwcLayer.displayFrame);
|
|
|
|
}
|
2013-01-09 04:56:37 -08:00
|
|
|
hwcLayer.visibleRegionScreen = region;
|
|
|
|
} else {
|
|
|
|
hwcLayer.flags |= HWC_COLOR_FILL;
|
2013-04-29 17:20:51 -07:00
|
|
|
ColorLayer* colorLayer = aLayer->AsColorLayer();
|
|
|
|
if (colorLayer->GetColor().a < 1.0) {
|
|
|
|
LOGD("Color layer has semitransparency which is unsupported");
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-09 04:56:37 -08:00
|
|
|
hwcLayer.transform = colorLayer->GetColor().Packed();
|
|
|
|
}
|
2012-11-19 09:58:37 -08:00
|
|
|
|
|
|
|
mList->numHwLayers++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HwcComposer2D::TryRender(Layer* aRoot,
|
|
|
|
const gfxMatrix& aGLWorldTransform)
|
|
|
|
{
|
2013-01-29 17:21:04 -08:00
|
|
|
if (!aGLWorldTransform.PreservesAxisAlignedRectangles()) {
|
|
|
|
LOGD("Render aborted. World transform has non-square angle rotation");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-19 09:58:37 -08:00
|
|
|
MOZ_ASSERT(Initialized());
|
|
|
|
if (mList) {
|
|
|
|
mList->numHwLayers = 0;
|
|
|
|
}
|
|
|
|
|
2013-04-29 17:21:54 -07: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-01-17 13:34:01 -08:00
|
|
|
if (!PrepareLayerList(aRoot,
|
|
|
|
mScreenRect,
|
|
|
|
gfxMatrix(),
|
|
|
|
aGLWorldTransform))
|
|
|
|
{
|
2012-11-19 09:58:37 -08:00
|
|
|
LOGD("Render aborted. Nothing was drawn to the screen");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHwc->set(mHwc, mDpy, mSur, mList)) {
|
|
|
|
LOGE("Hardware device failed to render");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGD("Frame rendered");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|