radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 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" |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 29 | #include "cb_swap_rect.h" |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 30 | /* get union of two rects into 3rd rect */ |
| 31 | void getUnion(hwc_rect_t& rect1,hwc_rect_t& rect2, hwc_rect_t& irect) { |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 32 | |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 33 | 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 | |
Dileep Kumar Reddi | 2d0c0ef | 2015-05-07 17:24:23 +0530 | [diff] [blame^] | 39 | int clear (copybit_device_t *copybit, private_handle_t* hnd, hwc_rect_t& rect) |
| 40 | { |
| 41 | int ret = 0; |
| 42 | copybit_rect_t clear_rect = {rect.left, rect.top,rect.right,rect.bottom}; |
| 43 | |
| 44 | copybit_image_t buf; |
| 45 | buf.w = ALIGN(getWidth(hnd),32); |
| 46 | buf.h = getHeight(hnd); |
| 47 | buf.format = hnd->format; |
| 48 | buf.base = (void *)hnd->base; |
| 49 | buf.handle = (native_handle_t *)hnd; |
| 50 | |
| 51 | ret = copybit->clear(copybit, &buf, &clear_rect); |
| 52 | return ret; |
| 53 | } |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 54 | using namespace android; |
| 55 | using namespace qhwc; |
| 56 | namespace qdutils { |
| 57 | |
Dileep Kumar Reddi | 2d0c0ef | 2015-05-07 17:24:23 +0530 | [diff] [blame^] | 58 | int CBUtils::uiClearRegion(hwc_display_contents_1_t* list, |
| 59 | int version, LayerProp *layerProp, int dirtyIndex, |
| 60 | copybit_device_t *copybit, private_handle_t *renderBuffer) { |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 61 | |
Dileep Kumar Reddi | bf333c7 | 2014-02-25 14:32:51 +0530 | [diff] [blame] | 62 | size_t last = list->numHwLayers - 1; |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 63 | hwc_rect_t fbFrame = list->hwLayers[last].displayFrame; |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 64 | Rect fbFrameRect(fbFrame.left,fbFrame.top,fbFrame.right,fbFrame.bottom); |
| 65 | Region wormholeRegion(fbFrameRect); |
| 66 | |
Dileep Kumar Reddi | f4e2e0c | 2014-12-16 11:24:34 +0530 | [diff] [blame] | 67 | if (dirtyIndex != -1) { |
| 68 | #ifdef QCOM_BSP |
| 69 | /* |
| 70 | * 1. Map dirty rect of updating layer to its display frame. |
| 71 | * 2. Use this display frame as wormholeRegion instead of full Frame |
| 72 | * */ |
| 73 | hwc_rect_t dirtyRect = list->hwLayers[dirtyIndex].dirtyRect; |
| 74 | hwc_rect_t displayFrame = list->hwLayers[dirtyIndex].displayFrame; |
| 75 | hwc_frect_t sCropF = list->hwLayers[dirtyIndex].sourceCropf; |
| 76 | hwc_rect_t srcRect = {int(ceilf(sCropF.left)), int(ceilf(sCropF.top)), |
| 77 | int(ceilf(sCropF.right)), int(ceilf(sCropF.bottom))}; |
| 78 | |
| 79 | displayFrame.left += dirtyRect.left - srcRect.left; |
| 80 | displayFrame.top += dirtyRect.top - srcRect.top; |
| 81 | displayFrame.right -= srcRect.right - dirtyRect.right; |
| 82 | displayFrame.bottom -= srcRect.bottom - dirtyRect.bottom; |
| 83 | |
| 84 | Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right, |
| 85 | displayFrame.bottom); |
| 86 | Region tmpRegion(tmpRect); |
| 87 | wormholeRegion = wormholeRegion.intersect(tmpRegion); |
| 88 | #endif |
| 89 | } |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 90 | if(cb_swap_rect::getInstance().checkSwapRectFeature_on() == true){ |
| 91 | wormholeRegion.set(0,0); |
Dileep Kumar Reddi | bf333c7 | 2014-02-25 14:32:51 +0530 | [diff] [blame] | 92 | for(size_t i = 0 ; i < last; i++) { |
radhakrishna | 160c9ea | 2014-11-07 17:18:53 +0530 | [diff] [blame] | 93 | if(((list->hwLayers[i].blending == HWC_BLENDING_NONE) && |
| 94 | (list->hwLayers[i].planeAlpha == 0xFF)) || |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 95 | !(layerProp[i].mFlags & HWC_COPYBIT) || |
| 96 | (list->hwLayers[i].flags & HWC_SKIP_HWC_COMPOSITION)) |
| 97 | continue ; |
| 98 | hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; |
| 99 | Rect tmpRect(displayFrame.left,displayFrame.top, |
| 100 | displayFrame.right,displayFrame.bottom); |
| 101 | wormholeRegion.set(tmpRect); |
| 102 | } |
| 103 | }else{ |
Dileep Kumar Reddi | bf333c7 | 2014-02-25 14:32:51 +0530 | [diff] [blame] | 104 | for (size_t i = 0 ; i < last; i++) { |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 105 | // need to take care only in per pixel blending. |
| 106 | // Restrict calculation only for copybit layers. |
| 107 | if((list->hwLayers[i].blending != HWC_BLENDING_NONE) || |
radhakrishna | 160c9ea | 2014-11-07 17:18:53 +0530 | [diff] [blame] | 108 | (list->hwLayers[i].planeAlpha != 0xFF) || |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 109 | !(layerProp[i].mFlags & HWC_COPYBIT)) |
| 110 | continue ; |
| 111 | hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; |
| 112 | Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right, |
| 113 | displayFrame.bottom); |
| 114 | Region tmpRegion(tmpRect); |
| 115 | wormholeRegion.subtractSelf(wormholeRegion.intersect(tmpRegion)); |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | if(wormholeRegion.isEmpty()){ |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 119 | return 0; |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 120 | } |
| 121 | //TO DO :- 1. remove union and call clear for each rect. |
| 122 | Region::const_iterator it = wormholeRegion.begin(); |
| 123 | Region::const_iterator const end = wormholeRegion.end(); |
| 124 | while (it != end) { |
| 125 | const Rect& r = *it++; |
| 126 | hwc_rect_t tmpWormRect = {r.left,r.top,r.right,r.bottom}; |
Dileep Kumar Reddi | 2d0c0ef | 2015-05-07 17:24:23 +0530 | [diff] [blame^] | 127 | if (version == qdutils::MDP_V3_0_4 || |
| 128 | version == qdutils::MDP_V3_0_5) { |
| 129 | int clear_w = tmpWormRect.right - tmpWormRect.left; |
| 130 | int clear_h = tmpWormRect.bottom - tmpWormRect.top; |
| 131 | //mdp can't handle solid fill for one line |
| 132 | //making solid fill as full in this case |
| 133 | //disable swap rect if presents |
| 134 | if ((clear_w == 1) || (clear_h ==1)) { |
| 135 | clear(copybit, renderBuffer, fbFrame); |
| 136 | return 0; |
| 137 | } else { |
| 138 | clear(copybit, renderBuffer, tmpWormRect); |
| 139 | } |
| 140 | } else { |
| 141 | clear(copybit, renderBuffer, tmpWormRect); |
| 142 | } |
Ramakant Singh | 762ae08 | 2013-11-28 18:45:34 +0530 | [diff] [blame] | 143 | } |
| 144 | return 1; |
radhakrishna | 2f00c8f | 2013-10-21 16:49:21 +0530 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | }//namespace qdutils |