2 * Copyright (c) 2013 The Linux Foundation. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <android/log.h>
20 #include "gfx2DGlue.h"
22 #define LOG_TAG "HwcUtils"
25 #define LOGD(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, ## args)
27 #define LOGD(args...) ((void)0)
30 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
35 /* Utility functions for HwcComposer */
40 HwcUtils::PrepareLayerRects(nsIntRect aVisible
,
41 const gfx::Matrix
& aLayerTransform
,
42 const gfx::Matrix
& aLayerBufferTransform
,
43 nsIntRect aClip
, nsIntRect aBufferRect
,
45 hwc_rect_t
* aSourceCrop
, hwc_rect_t
* aVisibleRegionScreen
) {
47 gfxMatrix aTransform
= gfx::ThebesMatrix(aLayerTransform
);
48 gfxRect
visibleRect(aVisible
);
50 gfxRect visibleRectScreen
= aTransform
.TransformBounds(visibleRect
);
51 // |clip| is guaranteed to be integer
52 visibleRectScreen
.IntersectRect(visibleRectScreen
, clip
);
54 if (visibleRectScreen
.IsEmpty()) {
58 gfxMatrix inverse
= gfx::ThebesMatrix(aLayerBufferTransform
);
60 gfxRect crop
= inverse
.TransformBounds(visibleRectScreen
);
63 crop
.IntersectRect(crop
, aBufferRect
);
70 //propagate buffer clipping back to visible rect
71 gfxMatrix layerBufferTransform
= gfx::ThebesMatrix(aLayerBufferTransform
);
72 visibleRectScreen
= layerBufferTransform
.TransformBounds(crop
);
73 visibleRectScreen
.Round();
75 // Map from layer space to buffer space
76 crop
-= aBufferRect
.TopLeft();
78 crop
.y
= aBufferRect
.height
- (crop
.y
+ crop
.height
);
81 aSourceCrop
->left
= crop
.x
;
82 aSourceCrop
->top
= crop
.y
;
83 aSourceCrop
->right
= crop
.x
+ crop
.width
;
84 aSourceCrop
->bottom
= crop
.y
+ crop
.height
;
86 aVisibleRegionScreen
->left
= visibleRectScreen
.x
;
87 aVisibleRegionScreen
->top
= visibleRectScreen
.y
;
88 aVisibleRegionScreen
->right
= visibleRectScreen
.x
+ visibleRectScreen
.width
;
89 aVisibleRegionScreen
->bottom
= visibleRectScreen
.y
+ visibleRectScreen
.height
;
95 HwcUtils::PrepareVisibleRegion(const nsIntRegion
& aVisible
,
96 const gfx::Matrix
& aLayerTransform
,
97 const gfx::Matrix
& aLayerBufferTransform
,
98 nsIntRect aClip
, nsIntRect aBufferRect
,
99 RectVector
* aVisibleRegionScreen
) {
101 gfxMatrix layerTransform
= gfx::ThebesMatrix(aLayerTransform
);
102 gfxMatrix layerBufferTransform
= gfx::ThebesMatrix(aLayerBufferTransform
);
103 gfxRect bufferRect
= layerBufferTransform
.TransformBounds(aBufferRect
);
104 nsIntRegionRectIterator
rect(aVisible
);
105 bool isVisible
= false;
106 while (const nsIntRect
* visibleRect
= rect
.Next()) {
107 hwc_rect_t visibleRectScreen
;
110 screenRect
= layerTransform
.TransformBounds(gfxRect(*visibleRect
));
111 screenRect
.IntersectRect(screenRect
, bufferRect
);
112 screenRect
.IntersectRect(screenRect
, aClip
);
114 if (screenRect
.IsEmpty()) {
117 visibleRectScreen
.left
= screenRect
.x
;
118 visibleRectScreen
.top
= screenRect
.y
;
119 visibleRectScreen
.right
= screenRect
.XMost();
120 visibleRectScreen
.bottom
= screenRect
.YMost();
121 aVisibleRegionScreen
->push_back(visibleRectScreen
);
129 HwcUtils::CalculateClipRect(const gfx::Matrix
& transform
,
130 const nsIntRect
* aLayerClip
,
131 nsIntRect aParentClip
, nsIntRect
* aRenderClip
) {
133 gfxMatrix aTransform
= gfx::ThebesMatrix(transform
);
134 *aRenderClip
= aParentClip
;
140 if (aLayerClip
->IsEmpty()) {
144 nsIntRect clip
= *aLayerClip
;
147 gfxRect trClip
= aTransform
.TransformBounds(r
);
149 gfxUtils::GfxRectToIntRect(trClip
, &clip
);
151 aRenderClip
->IntersectRect(*aRenderClip
, clip
);
155 } // namespace mozilla