1 /* 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"
29 #include "cb_swap_rect.h"
30 #include <ui/Region.h>
31 /* get union of two rects into 3rd rect */
getUnion(hwc_rect_t & rect1,hwc_rect_t & rect2,hwc_rect_t & irect)32 void getUnion(hwc_rect_t& rect1,hwc_rect_t& rect2, hwc_rect_t& irect) {
33 
34     irect.left   = min(rect1.left, rect2.left);
35     irect.top    = min(rect1.top, rect2.top);
36     irect.right  = max(rect1.right, rect2.right);
37     irect.bottom = max(rect1.bottom, rect2.bottom);
38 }
39 
40 using namespace android;
41 using namespace qhwc;
42 namespace qdutils {
43 
getuiClearRegion(hwc_display_contents_1_t * list,hwc_rect_t & clearWormholeRect,LayerProp * layerProp)44 int CBUtils::getuiClearRegion(hwc_display_contents_1_t* list,
45           hwc_rect_t &clearWormholeRect, LayerProp *layerProp) {
46 
47     size_t last = list->numHwLayers - 1;
48     hwc_rect_t fbFrame = list->hwLayers[last].displayFrame;
49     Rect fbFrameRect(fbFrame.left,fbFrame.top,fbFrame.right,fbFrame.bottom);
50     Region wormholeRegion(fbFrameRect);
51 
52     if(cb_swap_rect::getInstance().checkSwapRectFeature_on() == true){
53       wormholeRegion.set(0,0);
54       for(size_t i = 0 ; i < last; i++) {
55          if(((list->hwLayers[i].blending == HWC_BLENDING_NONE) &&
56            (list->hwLayers[i].planeAlpha == 0xFF)) ||
57            !(layerProp[i].mFlags & HWC_COPYBIT) ||
58            (list->hwLayers[i].flags  & HWC_SKIP_HWC_COMPOSITION))
59               continue ;
60          hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
61          Rect tmpRect(displayFrame.left,displayFrame.top,
62                       displayFrame.right,displayFrame.bottom);
63          wormholeRegion.set(tmpRect);
64       }
65    }else{
66      for (size_t i = 0 ; i < last; i++) {
67         // need to take care only in per pixel blending.
68         // Restrict calculation only for copybit layers.
69         if((list->hwLayers[i].blending != HWC_BLENDING_NONE) ||
70            (list->hwLayers[i].planeAlpha != 0xFF) ||
71            !(layerProp[i].mFlags & HWC_COPYBIT))
72             continue ;
73         hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
74         Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right,
75         displayFrame.bottom);
76         Region tmpRegion(tmpRect);
77         wormholeRegion.subtractSelf(wormholeRegion.intersect(tmpRegion));
78      }
79    }
80    if(wormholeRegion.isEmpty()){
81         return 0;
82    }
83    //TO DO :- 1. remove union and call clear for each rect.
84    Region::const_iterator it = wormholeRegion.begin();
85    Region::const_iterator const end = wormholeRegion.end();
86    while (it != end) {
87        const Rect& r = *it++;
88        hwc_rect_t tmpWormRect = {r.left,r.top,r.right,r.bottom};
89        int dst_w =  clearWormholeRect.right -  clearWormholeRect.left;
90        int dst_h =  clearWormholeRect.bottom -  clearWormholeRect.top;
91 
92        if (!(dst_w || dst_h))
93              clearWormholeRect = tmpWormRect;
94        else
95              getUnion(clearWormholeRect, tmpWormRect, clearWormholeRect);
96 
97    }
98    return 1;
99 }
100 
101 }//namespace qdutils
102