widget/gonk/HwcUtils.cpp

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

mercurial