2013-08-26 10:11:24 -07:00
|
|
|
/*
|
2013-08-29 08:17:59 -07:00
|
|
|
* Copyright (c) 2013 The Linux Foundation. All rights reserved.
|
2013-08-26 10:11:24 -07: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-08-29 08:17:59 -07:00
|
|
|
#include "HwcUtils.h"
|
2013-08-26 10:11:24 -07:00
|
|
|
#include "gfxUtils.h"
|
|
|
|
|
2013-08-29 08:17:59 -07:00
|
|
|
#define LOG_TAG "HwcUtils"
|
2013-08-26 10:11:24 -07:00
|
|
|
|
|
|
|
#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)
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-08-29 08:17:59 -07:00
|
|
|
/* Utility functions for HwcComposer */
|
2013-08-26 10:11:24 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-29 08:17:59 -07:00
|
|
|
/* static */ bool
|
|
|
|
HwcUtils::PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform,
|
|
|
|
nsIntRect aClip, nsIntRect aBufferRect,
|
|
|
|
hwc_rect_t* aSourceCrop, hwc_rect_t* aVisibleRegionScreen) {
|
2013-08-26 10:11:24 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
//clip to buffer size
|
|
|
|
crop.IntersectRect(crop, aBufferRect);
|
|
|
|
crop.Round();
|
|
|
|
|
|
|
|
if (crop.IsEmpty()) {
|
|
|
|
LOGD("Skip layer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//propagate buffer clipping back to visible rect
|
|
|
|
visibleRectScreen = aTransform.TransformBounds(crop);
|
|
|
|
visibleRectScreen.Round();
|
|
|
|
|
|
|
|
// Map from layer space to buffer space
|
|
|
|
crop -= aBufferRect.TopLeft();
|
|
|
|
|
|
|
|
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-08-29 08:17:59 -07:00
|
|
|
/* static */ bool
|
|
|
|
HwcUtils::PrepareVisibleRegion(const nsIntRegion& aVisible,
|
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
nsIntRect aClip, nsIntRect aBufferRect,
|
|
|
|
RectVector* aVisibleRegionScreen) {
|
2013-08-26 10:11:24 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
screenRect.Round();
|
|
|
|
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-08-29 08:17:59 -07:00
|
|
|
/* static */ bool
|
|
|
|
HwcUtils::CalculateClipRect(const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aLayerClip,
|
|
|
|
nsIntRect aParentClip, nsIntRect* aRenderClip) {
|
2013-08-26 10:11:24 -07:00
|
|
|
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|