widget/gonk/HwcUtils.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2013 The Linux Foundation. All rights reserved.
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #include <android/log.h>
michael@0 18 #include "HwcUtils.h"
michael@0 19 #include "gfxUtils.h"
michael@0 20
michael@0 21 #define LOG_TAG "HwcUtils"
michael@0 22
michael@0 23 #if (LOG_NDEBUG == 0)
michael@0 24 #define LOGD(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, ## args)
michael@0 25 #else
michael@0 26 #define LOGD(args...) ((void)0)
michael@0 27 #endif
michael@0 28
michael@0 29 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
michael@0 30
michael@0 31
michael@0 32 namespace mozilla {
michael@0 33
michael@0 34 /* Utility functions for HwcComposer */
michael@0 35
michael@0 36
michael@0 37
michael@0 38 /* static */ bool
michael@0 39 HwcUtils::PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform,
michael@0 40 nsIntRect aClip, nsIntRect aBufferRect,
michael@0 41 bool aYFlipped,
michael@0 42 hwc_rect_t* aSourceCrop, hwc_rect_t* aVisibleRegionScreen) {
michael@0 43
michael@0 44 gfxRect visibleRect(aVisible);
michael@0 45 gfxRect clip(aClip);
michael@0 46 gfxRect visibleRectScreen = aTransform.TransformBounds(visibleRect);
michael@0 47 // |clip| is guaranteed to be integer
michael@0 48 visibleRectScreen.IntersectRect(visibleRectScreen, clip);
michael@0 49
michael@0 50 if (visibleRectScreen.IsEmpty()) {
michael@0 51 LOGD("Skip layer");
michael@0 52 return false;
michael@0 53 }
michael@0 54
michael@0 55 gfxMatrix inverse(aTransform);
michael@0 56 inverse.Invert();
michael@0 57 gfxRect crop = inverse.TransformBounds(visibleRectScreen);
michael@0 58
michael@0 59 //clip to buffer size
michael@0 60 crop.IntersectRect(crop, aBufferRect);
michael@0 61 crop.Round();
michael@0 62
michael@0 63 if (crop.IsEmpty()) {
michael@0 64 LOGD("Skip layer");
michael@0 65 return false;
michael@0 66 }
michael@0 67
michael@0 68 //propagate buffer clipping back to visible rect
michael@0 69 visibleRectScreen = aTransform.TransformBounds(crop);
michael@0 70 visibleRectScreen.Round();
michael@0 71
michael@0 72 // Map from layer space to buffer space
michael@0 73 crop -= aBufferRect.TopLeft();
michael@0 74 if (aYFlipped) {
michael@0 75 crop.y = aBufferRect.height - (crop.y + crop.height);
michael@0 76 }
michael@0 77
michael@0 78 aSourceCrop->left = crop.x;
michael@0 79 aSourceCrop->top = crop.y;
michael@0 80 aSourceCrop->right = crop.x + crop.width;
michael@0 81 aSourceCrop->bottom = crop.y + crop.height;
michael@0 82
michael@0 83 aVisibleRegionScreen->left = visibleRectScreen.x;
michael@0 84 aVisibleRegionScreen->top = visibleRectScreen.y;
michael@0 85 aVisibleRegionScreen->right = visibleRectScreen.x + visibleRectScreen.width;
michael@0 86 aVisibleRegionScreen->bottom = visibleRectScreen.y + visibleRectScreen.height;
michael@0 87
michael@0 88 return true;
michael@0 89 }
michael@0 90
michael@0 91 /* static */ bool
michael@0 92 HwcUtils::PrepareVisibleRegion(const nsIntRegion& aVisible,
michael@0 93 const gfxMatrix& aTransform,
michael@0 94 nsIntRect aClip, nsIntRect aBufferRect,
michael@0 95 RectVector* aVisibleRegionScreen) {
michael@0 96
michael@0 97 nsIntRegionRectIterator rect(aVisible);
michael@0 98 bool isVisible = false;
michael@0 99 while (const nsIntRect* visibleRect = rect.Next()) {
michael@0 100 hwc_rect_t visibleRectScreen;
michael@0 101 gfxRect screenRect;
michael@0 102
michael@0 103 screenRect.IntersectRect(gfxRect(*visibleRect), aBufferRect);
michael@0 104 screenRect = aTransform.TransformBounds(screenRect);
michael@0 105 screenRect.IntersectRect(screenRect, aClip);
michael@0 106 screenRect.Round();
michael@0 107 if (screenRect.IsEmpty()) {
michael@0 108 continue;
michael@0 109 }
michael@0 110 visibleRectScreen.left = screenRect.x;
michael@0 111 visibleRectScreen.top = screenRect.y;
michael@0 112 visibleRectScreen.right = screenRect.XMost();
michael@0 113 visibleRectScreen.bottom = screenRect.YMost();
michael@0 114 aVisibleRegionScreen->push_back(visibleRectScreen);
michael@0 115 isVisible = true;
michael@0 116 }
michael@0 117
michael@0 118 return isVisible;
michael@0 119 }
michael@0 120
michael@0 121 /* static */ bool
michael@0 122 HwcUtils::CalculateClipRect(const gfxMatrix& aTransform,
michael@0 123 const nsIntRect* aLayerClip,
michael@0 124 nsIntRect aParentClip, nsIntRect* aRenderClip) {
michael@0 125
michael@0 126 *aRenderClip = aParentClip;
michael@0 127
michael@0 128 if (!aLayerClip) {
michael@0 129 return true;
michael@0 130 }
michael@0 131
michael@0 132 if (aLayerClip->IsEmpty()) {
michael@0 133 return false;
michael@0 134 }
michael@0 135
michael@0 136 nsIntRect clip = *aLayerClip;
michael@0 137
michael@0 138 gfxRect r(clip);
michael@0 139 gfxRect trClip = aTransform.TransformBounds(r);
michael@0 140 trClip.Round();
michael@0 141 gfxUtils::GfxRectToIntRect(trClip, &clip);
michael@0 142
michael@0 143 aRenderClip->IntersectRect(*aRenderClip, clip);
michael@0 144 return true;
michael@0 145 }
michael@0 146
michael@0 147 } // namespace mozilla

mercurial