1bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* Redistribution and use in source and binary forms, with or without
3bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* * modification, are permitted provided that the following conditions are
4bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* met:
5bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*   * Redistributions of source code must retain the above copyrigh
6bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*     notice, this list of conditions and the following disclaimer
7bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*   * Redistributions in binary form must reproduce the above
8bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*     copyright notice, this list of conditions and the following
9bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*     disclaimer in the documentation and/or other materials provided
10bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*     with the distribution.
11bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*   * Neither the name of The Linux Foundation nor the names of its
12bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*     contributors may be used to endorse or promote products derived
13bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*     from this software without specific prior written permission.
14bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*
15bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
16bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
18bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
19bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna*/
27bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
28bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna#include "cb_utils.h"
2905317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh#include "cb_swap_rect.h"
30bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna/* get union of two rects into 3rd rect */
31bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishnavoid getUnion(hwc_rect_t& rect1,hwc_rect_t& rect2, hwc_rect_t& irect) {
3205317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh
33bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    irect.left   = min(rect1.left, rect2.left);
34bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    irect.top    = min(rect1.top, rect2.top);
35bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    irect.right  = max(rect1.right, rect2.right);
36bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    irect.bottom = max(rect1.bottom, rect2.bottom);
37bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna}
38bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
39bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishnausing namespace android;
40bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishnausing namespace qhwc;
41bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishnanamespace qdutils {
42bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
43bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishnaint CBUtils::getuiClearRegion(hwc_display_contents_1_t* list,
44bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna          hwc_rect_t &clearWormholeRect, LayerProp *layerProp) {
45bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
46cf40ec929a1ddf18023dad9647e7be08638b659dDileep Kumar Reddi    size_t last = list->numHwLayers - 1;
47bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    hwc_rect_t fbFrame = list->hwLayers[last].displayFrame;
48bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    Rect fbFrameRect(fbFrame.left,fbFrame.top,fbFrame.right,fbFrame.bottom);
49bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna    Region wormholeRegion(fbFrameRect);
50bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
5105317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh    if(cb_swap_rect::getInstance().checkSwapRectFeature_on() == true){
5205317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh      wormholeRegion.set(0,0);
53cf40ec929a1ddf18023dad9647e7be08638b659dDileep Kumar Reddi      for(size_t i = 0 ; i < last; i++) {
5405317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh         if((list->hwLayers[i].blending == HWC_BLENDING_NONE) ||
5505317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh           !(layerProp[i].mFlags & HWC_COPYBIT) ||
5605317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh           (list->hwLayers[i].flags  & HWC_SKIP_HWC_COMPOSITION))
5705317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh              continue ;
5805317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh         hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
5905317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh         Rect tmpRect(displayFrame.left,displayFrame.top,
6005317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh                      displayFrame.right,displayFrame.bottom);
6105317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh         wormholeRegion.set(tmpRect);
6205317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh      }
6305317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   }else{
64cf40ec929a1ddf18023dad9647e7be08638b659dDileep Kumar Reddi     for (size_t i = 0 ; i < last; i++) {
65bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        // need to take care only in per pixel blending.
66bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        // Restrict calculation only for copybit layers.
67bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        if((list->hwLayers[i].blending != HWC_BLENDING_NONE) ||
68bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna           !(layerProp[i].mFlags & HWC_COPYBIT))
69bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna            continue ;
70bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
71bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right,
72bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        displayFrame.bottom);
73bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        Region tmpRegion(tmpRect);
74bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        wormholeRegion.subtractSelf(wormholeRegion.intersect(tmpRegion));
7505317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh     }
7605317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   }
7705317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   if(wormholeRegion.isEmpty()){
78bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna        return 0;
7905317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   }
8005317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   //TO DO :- 1. remove union and call clear for each rect.
8105317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   Region::const_iterator it = wormholeRegion.begin();
8205317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   Region::const_iterator const end = wormholeRegion.end();
8305317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   while (it != end) {
8405317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh       const Rect& r = *it++;
8505317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh       hwc_rect_t tmpWormRect = {r.left,r.top,r.right,r.bottom};
8605317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh       int dst_w =  clearWormholeRect.right -  clearWormholeRect.left;
8705317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh       int dst_h =  clearWormholeRect.bottom -  clearWormholeRect.top;
8805317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh
8905317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh       if (!(dst_w || dst_h))
9005317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh             clearWormholeRect = tmpWormRect;
9105317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh       else
9205317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh             getUnion(clearWormholeRect, tmpWormRect, clearWormholeRect);
93bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
9405317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   }
9505317317b22f6618cd714fed603530aa87c5f7ebRamakant Singh   return 1;
96bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna}
97bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna
98bf5bd0784e67c95c5ce4bf1ab063c1b178525592radhakrishna}//namespace qdutils
99