blob: c17842a5dbd46f1c23d56821cff5df4ed8743837 [file] [log] [blame]
radhakrishna2f00c8f2013-10-21 16:49:21 +05301/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2* Redistribution and use in source and binary forms, with or without
3* * modification, are permitted provided that the following conditions are
4* met:
5* * Redistributions of source code must retain the above copyrigh
6* notice, this list of conditions and the following disclaimer
7* * Redistributions in binary form must reproduce the above
8* copyright notice, this list of conditions and the following
9* disclaimer in the documentation and/or other materials provided
10* with the distribution.
11* * Neither the name of The Linux Foundation nor the names of its
12* contributors may be used to endorse or promote products derived
13* from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
16* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
18* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
19* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23* * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#include "cb_utils.h"
Ramakant Singh762ae082013-11-28 18:45:34 +053029#include "cb_swap_rect.h"
radhakrishna2f00c8f2013-10-21 16:49:21 +053030/* get union of two rects into 3rd rect */
31void getUnion(hwc_rect_t& rect1,hwc_rect_t& rect2, hwc_rect_t& irect) {
Ramakant Singh762ae082013-11-28 18:45:34 +053032
radhakrishna2f00c8f2013-10-21 16:49:21 +053033 irect.left = min(rect1.left, rect2.left);
34 irect.top = min(rect1.top, rect2.top);
35 irect.right = max(rect1.right, rect2.right);
36 irect.bottom = max(rect1.bottom, rect2.bottom);
37}
38
39using namespace android;
40using namespace qhwc;
41namespace qdutils {
42
43int CBUtils::getuiClearRegion(hwc_display_contents_1_t* list,
Dileep Kumar Reddif4e2e0c2014-12-16 11:24:34 +053044 hwc_rect_t &clearWormholeRect, LayerProp *layerProp, int dirtyIndex) {
radhakrishna2f00c8f2013-10-21 16:49:21 +053045
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +053046 size_t last = list->numHwLayers - 1;
radhakrishna2f00c8f2013-10-21 16:49:21 +053047 hwc_rect_t fbFrame = list->hwLayers[last].displayFrame;
radhakrishna2f00c8f2013-10-21 16:49:21 +053048 Rect fbFrameRect(fbFrame.left,fbFrame.top,fbFrame.right,fbFrame.bottom);
49 Region wormholeRegion(fbFrameRect);
50
Dileep Kumar Reddif4e2e0c2014-12-16 11:24:34 +053051 if (dirtyIndex != -1) {
52#ifdef QCOM_BSP
53 /*
54 * 1. Map dirty rect of updating layer to its display frame.
55 * 2. Use this display frame as wormholeRegion instead of full Frame
56 * */
57 hwc_rect_t dirtyRect = list->hwLayers[dirtyIndex].dirtyRect;
58 hwc_rect_t displayFrame = list->hwLayers[dirtyIndex].displayFrame;
59 hwc_frect_t sCropF = list->hwLayers[dirtyIndex].sourceCropf;
60 hwc_rect_t srcRect = {int(ceilf(sCropF.left)), int(ceilf(sCropF.top)),
61 int(ceilf(sCropF.right)), int(ceilf(sCropF.bottom))};
62
63 displayFrame.left += dirtyRect.left - srcRect.left;
64 displayFrame.top += dirtyRect.top - srcRect.top;
65 displayFrame.right -= srcRect.right - dirtyRect.right;
66 displayFrame.bottom -= srcRect.bottom - dirtyRect.bottom;
67
68 Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right,
69 displayFrame.bottom);
70 Region tmpRegion(tmpRect);
71 wormholeRegion = wormholeRegion.intersect(tmpRegion);
72#endif
73 }
Ramakant Singh762ae082013-11-28 18:45:34 +053074 if(cb_swap_rect::getInstance().checkSwapRectFeature_on() == true){
75 wormholeRegion.set(0,0);
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +053076 for(size_t i = 0 ; i < last; i++) {
radhakrishna160c9ea2014-11-07 17:18:53 +053077 if(((list->hwLayers[i].blending == HWC_BLENDING_NONE) &&
78 (list->hwLayers[i].planeAlpha == 0xFF)) ||
Ramakant Singh762ae082013-11-28 18:45:34 +053079 !(layerProp[i].mFlags & HWC_COPYBIT) ||
80 (list->hwLayers[i].flags & HWC_SKIP_HWC_COMPOSITION))
81 continue ;
82 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
83 Rect tmpRect(displayFrame.left,displayFrame.top,
84 displayFrame.right,displayFrame.bottom);
85 wormholeRegion.set(tmpRect);
86 }
87 }else{
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +053088 for (size_t i = 0 ; i < last; i++) {
radhakrishna2f00c8f2013-10-21 16:49:21 +053089 // need to take care only in per pixel blending.
90 // Restrict calculation only for copybit layers.
91 if((list->hwLayers[i].blending != HWC_BLENDING_NONE) ||
radhakrishna160c9ea2014-11-07 17:18:53 +053092 (list->hwLayers[i].planeAlpha != 0xFF) ||
radhakrishna2f00c8f2013-10-21 16:49:21 +053093 !(layerProp[i].mFlags & HWC_COPYBIT))
94 continue ;
95 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
96 Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right,
97 displayFrame.bottom);
98 Region tmpRegion(tmpRect);
99 wormholeRegion.subtractSelf(wormholeRegion.intersect(tmpRegion));
Ramakant Singh762ae082013-11-28 18:45:34 +0530100 }
101 }
102 if(wormholeRegion.isEmpty()){
radhakrishna2f00c8f2013-10-21 16:49:21 +0530103 return 0;
Ramakant Singh762ae082013-11-28 18:45:34 +0530104 }
105 //TO DO :- 1. remove union and call clear for each rect.
106 Region::const_iterator it = wormholeRegion.begin();
107 Region::const_iterator const end = wormholeRegion.end();
108 while (it != end) {
109 const Rect& r = *it++;
110 hwc_rect_t tmpWormRect = {r.left,r.top,r.right,r.bottom};
111 int dst_w = clearWormholeRect.right - clearWormholeRect.left;
112 int dst_h = clearWormholeRect.bottom - clearWormholeRect.top;
radhakrishna2f00c8f2013-10-21 16:49:21 +0530113
Ramakant Singh762ae082013-11-28 18:45:34 +0530114 if (!(dst_w || dst_h))
115 clearWormholeRect = tmpWormRect;
116 else
117 getUnion(clearWormholeRect, tmpWormRect, clearWormholeRect);
118
119 }
120 return 1;
radhakrishna2f00c8f2013-10-21 16:49:21 +0530121}
122
123}//namespace qdutils