hwc_utils.cpp revision ad17afc8bcda6c2d6006a3b005defb011042aaac
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012-2013, The Linux Foundation All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#define HWC_UTILS_DEBUG 0
21#include <math.h>
22#include <sys/ioctl.h>
23#include <binder/IServiceManager.h>
24#include <EGL/egl.h>
25#include <cutils/properties.h>
26#include <gralloc_priv.h>
27#include <overlay.h>
28#include <overlayRotator.h>
29#include <overlayWriteback.h>
30#include "hwc_utils.h"
31#include "hwc_mdpcomp.h"
32#include "hwc_fbupdate.h"
33#include "hwc_ad.h"
34#include "mdp_version.h"
35#include "hwc_copybit.h"
36#include "external.h"
37#include "hwc_qclient.h"
38#include "QService.h"
39#include "comptype.h"
40
41using namespace qClient;
42using namespace qService;
43using namespace android;
44using namespace overlay;
45using namespace overlay::utils;
46namespace ovutils = overlay::utils;
47
48namespace qhwc {
49
50static int openFramebufferDevice(hwc_context_t *ctx)
51{
52    struct fb_fix_screeninfo finfo;
53    struct fb_var_screeninfo info;
54
55    int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
56    if(fb_fd < 0) {
57        ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
58        return -errno;
59    }
60
61    if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
62        ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
63                                                       strerror(errno));
64        close(fb_fd);
65        return -errno;
66    }
67
68    if (int(info.width) <= 0 || int(info.height) <= 0) {
69        // the driver doesn't return that information
70        // default to 160 dpi
71        info.width  = ((info.xres * 25.4f)/160.0f + 0.5f);
72        info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
73    }
74
75    float xdpi = (info.xres * 25.4f) / info.width;
76    float ydpi = (info.yres * 25.4f) / info.height;
77
78#ifdef MSMFB_METADATA_GET
79    struct msmfb_metadata metadata;
80    memset(&metadata, 0 , sizeof(metadata));
81    metadata.op = metadata_op_frame_rate;
82
83    if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
84        ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
85                                                      strerror(errno));
86        close(fb_fd);
87        return -errno;
88    }
89
90    float fps  = metadata.data.panel_frame_rate;
91#else
92    //XXX: Remove reserved field usage on all baselines
93    //The reserved[3] field is used to store FPS by the driver.
94    float fps  = info.reserved[3] & 0xFF;
95#endif
96
97    if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
98        ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
99                                                       strerror(errno));
100        close(fb_fd);
101        return -errno;
102    }
103
104    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
105    //xres, yres may not be 32 aligned
106    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
107    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
108    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
109    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
110    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
111    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps;
112
113    //Unblank primary on first boot
114    if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
115        ALOGE("%s: Failed to unblank display", __FUNCTION__);
116        return -errno;
117    }
118    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
119
120    return 0;
121}
122
123void initContext(hwc_context_t *ctx)
124{
125    memset(&ctx->dpyAttr, 0, sizeof(ctx->dpyAttr));
126    if(openFramebufferDevice(ctx) < 0) {
127        ALOGE("%s: failed to open framebuffer!!", __FUNCTION__);
128    }
129
130    overlay::Overlay::initOverlay();
131    ctx->mOverlay = overlay::Overlay::getInstance();
132    ctx->mRotMgr = new RotMgr();
133    ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
134    ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
135    ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
136    const int rightSplit = qdutils::MDPVersion::getInstance().getRightSplit();
137    overlay::Overlay::initOverlay();
138    ctx->mOverlay = overlay::Overlay::getInstance();
139    ctx->mRotMgr = new RotMgr();
140
141    //Is created and destroyed only once for primary
142    //For external it could get created and destroyed multiple times depending
143    //on what external we connect to.
144    ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
145        IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
146                rightSplit, HWC_DISPLAY_PRIMARY);
147
148    // Check if the target supports copybit compostion (dyn/mdp/c2d) to
149    // decide if we need to open the copybit module.
150    int compositionType =
151        qdutils::QCCompositionType::getInstance().getCompositionType();
152
153    if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
154                           qdutils::COMPOSITION_TYPE_MDP |
155                           qdutils::COMPOSITION_TYPE_C2D)) {
156            ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit();
157    }
158
159    ctx->mExtDisplay = new ExternalDisplay(ctx);
160
161    for (uint32_t i = 0; i < MAX_DISPLAYS; i++) {
162        ctx->mLayerRotMap[i] = new LayerRotMap();
163    }
164
165    ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
166         MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
167                rightSplit, HWC_DISPLAY_PRIMARY);
168
169    MDPComp::init(ctx);
170    ctx->mAD = new AssertiveDisplay();
171
172    ctx->vstate.enable = false;
173    ctx->vstate.fakevsync = false;
174
175    //Right now hwc starts the service but anybody could do it, or it could be
176    //independent process as well.
177    QService::init();
178    sp<IQClient> client = new QClient(ctx);
179    interface_cast<IQService>(
180            defaultServiceManager()->getService(
181            String16("display.qservice")))->connect(client);
182
183    ALOGI("Initializing Qualcomm Hardware Composer");
184    ALOGI("MDP version: %d", ctx->mMDP.version);
185}
186
187void closeContext(hwc_context_t *ctx)
188{
189    if(ctx->mOverlay) {
190        delete ctx->mOverlay;
191        ctx->mOverlay = NULL;
192    }
193
194    if(ctx->mRotMgr) {
195        delete ctx->mRotMgr;
196        ctx->mRotMgr = NULL;
197    }
198
199    for(int i = 0; i < MAX_DISPLAYS; i++) {
200        if(ctx->mCopyBit[i]) {
201            delete ctx->mCopyBit[i];
202            ctx->mCopyBit[i] = NULL;
203        }
204    }
205
206    if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
207        close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
208        ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
209    }
210
211    if(ctx->mExtDisplay) {
212        delete ctx->mExtDisplay;
213        ctx->mExtDisplay = NULL;
214    }
215
216    for(int i = 0; i < MAX_DISPLAYS; i++) {
217        if(ctx->mFBUpdate[i]) {
218            delete ctx->mFBUpdate[i];
219            ctx->mFBUpdate[i] = NULL;
220        }
221        if(ctx->mMDPComp[i]) {
222            delete ctx->mMDPComp[i];
223            ctx->mMDPComp[i] = NULL;
224        }
225        if(ctx->mLayerRotMap[i]) {
226            delete ctx->mLayerRotMap[i];
227            ctx->mLayerRotMap[i] = NULL;
228        }
229    }
230
231    if(ctx->mAD) {
232        delete ctx->mAD;
233        ctx->mAD = NULL;
234    }
235}
236
237
238void dumpsys_log(android::String8& buf, const char* fmt, ...)
239{
240    va_list varargs;
241    va_start(varargs, fmt);
242    buf.appendFormatV(fmt, varargs);
243    va_end(varargs);
244}
245
246/* Calculates the destination position based on the action safe rectangle */
247void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x,
248                           uint32_t& y, uint32_t& w, uint32_t& h) {
249
250    // if external supports underscan, do nothing
251    // it will be taken care in the driver
252    if(ctx->mExtDisplay->isCEUnderscanSupported())
253        return;
254
255    char value[PROPERTY_VALUE_MAX];
256    // Read action safe properties
257    property_get("persist.sys.actionsafe.width", value, "0");
258    int asWidthRatio = atoi(value);
259    property_get("persist.sys.actionsafe.height", value, "0");
260    int asHeightRatio = atoi(value);
261
262    if(!asWidthRatio && !asHeightRatio) {
263        //No action safe ratio set, return
264        return;
265    }
266
267    float wRatio = 1.0;
268    float hRatio = 1.0;
269    float xRatio = 1.0;
270    float yRatio = 1.0;
271
272    float fbWidth = ctx->dpyAttr[dpy].xres;
273    float fbHeight = ctx->dpyAttr[dpy].yres;
274
275    float asX = 0;
276    float asY = 0;
277    float asW = fbWidth;
278    float asH= fbHeight;
279
280    // based on the action safe ratio, get the Action safe rectangle
281    asW = fbWidth * (1.0f -  asWidthRatio / 100.0f);
282    asH = fbHeight * (1.0f -  asHeightRatio / 100.0f);
283    asX = (fbWidth - asW) / 2;
284    asY = (fbHeight - asH) / 2;
285
286    // calculate the position ratio
287    xRatio = (float)x/fbWidth;
288    yRatio = (float)y/fbHeight;
289    wRatio = (float)w/fbWidth;
290    hRatio = (float)h/fbHeight;
291
292    //Calculate the position...
293    x = (xRatio * asW) + asX;
294    y = (yRatio * asH) + asY;
295    w = (wRatio * asW);
296    h = (hRatio * asH);
297
298    return;
299}
300
301bool needsScaling(hwc_context_t* ctx, hwc_layer_1_t const* layer,
302        const int& dpy) {
303    int dst_w, dst_h, src_w, src_h;
304
305    hwc_rect_t displayFrame  = layer->displayFrame;
306    hwc_rect_t sourceCrop = layer->sourceCrop;
307    trimLayer(ctx, dpy, layer->transform, sourceCrop, displayFrame);
308
309    dst_w = displayFrame.right - displayFrame.left;
310    dst_h = displayFrame.bottom - displayFrame.top;
311    src_w = sourceCrop.right - sourceCrop.left;
312    src_h = sourceCrop.bottom - sourceCrop.top;
313
314    if(((src_w != dst_w) || (src_h != dst_h)))
315        return true;
316
317    return false;
318}
319
320bool isAlphaScaled(hwc_context_t* ctx, hwc_layer_1_t const* layer,
321        const int& dpy) {
322    if(needsScaling(ctx, layer, dpy) && isAlphaPresent(layer)) {
323        return true;
324    }
325    return false;
326}
327
328bool isAlphaPresent(hwc_layer_1_t const* layer) {
329    private_handle_t *hnd = (private_handle_t *)layer->handle;
330    if(hnd) {
331        int format = hnd->format;
332        switch(format) {
333        case HAL_PIXEL_FORMAT_RGBA_8888:
334        case HAL_PIXEL_FORMAT_BGRA_8888:
335            // In any more formats with Alpha go here..
336            return true;
337        default : return false;
338        }
339    }
340    return false;
341}
342
343// Let CABL know we have a YUV layer
344static void setYUVProp(int yuvCount) {
345    static char property[PROPERTY_VALUE_MAX];
346    if(yuvCount > 0) {
347        if (property_get("hw.cabl.yuv", property, NULL) > 0) {
348            if (atoi(property) != 1) {
349                property_set("hw.cabl.yuv", "1");
350            }
351        }
352    } else {
353        if (property_get("hw.cabl.yuv", property, NULL) > 0) {
354            if (atoi(property) != 0) {
355                property_set("hw.cabl.yuv", "0");
356            }
357        }
358    }
359}
360
361void setListStats(hwc_context_t *ctx,
362        const hwc_display_contents_1_t *list, int dpy) {
363    const int prevYuvCount = ctx->listStats[dpy].yuvCount;
364    memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
365    ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
366    ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
367    ctx->listStats[dpy].skipCount = 0;
368    ctx->listStats[dpy].needsAlphaScale = false;
369    ctx->listStats[dpy].preMultipliedAlpha = false;
370    ctx->listStats[dpy].planeAlpha = false;
371    ctx->listStats[dpy].yuvCount = 0;
372
373    for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
374        hwc_layer_1_t const* layer = &list->hwLayers[i];
375        private_handle_t *hnd = (private_handle_t *)layer->handle;
376
377        // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
378        if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
379            continue;
380
381        //reset yuv indices
382        ctx->listStats[dpy].yuvIndices[i] = -1;
383
384        if (isSkipLayer(&list->hwLayers[i])) {
385            ctx->listStats[dpy].skipCount++;
386        } else if (UNLIKELY(isYuvBuffer(hnd))) {
387            int& yuvCount = ctx->listStats[dpy].yuvCount;
388            ctx->listStats[dpy].yuvIndices[yuvCount] = i;
389            yuvCount++;
390
391            if((layer->transform & HWC_TRANSFORM_ROT_90) &&
392                    canUseRotator(ctx)) {
393                if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
394                    ctx->isPaddingRound = true;
395                }
396                Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
397            }
398        }
399        if(layer->blending == HWC_BLENDING_PREMULT)
400            ctx->listStats[dpy].preMultipliedAlpha = true;
401        if(layer->planeAlpha < 0xFF)
402            ctx->listStats[dpy].planeAlpha = true;
403        if(!ctx->listStats[dpy].needsAlphaScale)
404            ctx->listStats[dpy].needsAlphaScale =
405                    isAlphaScaled(ctx, layer, dpy);
406    }
407    setYUVProp(ctx->listStats[dpy].yuvCount);
408    //The marking of video begin/end is useful on some targets where we need
409    //to have a padding round to be able to shift pipes across mixers.
410    if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
411        ctx->mVideoTransFlag = true;
412    }
413    if(dpy == HWC_DISPLAY_PRIMARY) {
414        ctx->mAD->markDoable(ctx, list);
415    }
416}
417
418
419static void calc_cut(double& leftCutRatio, double& topCutRatio,
420        double& rightCutRatio, double& bottomCutRatio, int orient) {
421    if(orient & HAL_TRANSFORM_FLIP_H) {
422        swap(leftCutRatio, rightCutRatio);
423    }
424    if(orient & HAL_TRANSFORM_FLIP_V) {
425        swap(topCutRatio, bottomCutRatio);
426    }
427    if(orient & HAL_TRANSFORM_ROT_90) {
428        //Anti clock swapping
429        double tmpCutRatio = leftCutRatio;
430        leftCutRatio = topCutRatio;
431        topCutRatio = rightCutRatio;
432        rightCutRatio = bottomCutRatio;
433        bottomCutRatio = tmpCutRatio;
434    }
435}
436
437bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
438    if((ctx->mMDP.version < qdutils::MDSS_V5) &&
439       (ctx->mMDP.version > qdutils::MDP_V3_0) &&
440        ctx->mSecuring) {
441        return true;
442    }
443    //  On A-Family, Secure policy is applied system wide and not on
444    //  buffers.
445    if (isSecureModePolicy(ctx->mMDP.version)) {
446        private_handle_t *hnd = (private_handle_t *)layer->handle;
447        if(ctx->mSecureMode) {
448            if (! isSecureBuffer(hnd)) {
449                // This code path executes for the following usecase:
450                // Some Apps in which first few seconds, framework
451                // sends non-secure buffer and with out destroying
452                // surfaces, switches to secure buffer thereby exposing
453                // vulnerability on A-family devices. Catch this situation
454                // and handle it gracefully by allowing it to be composed by
455                // GPU.
456                ALOGD_IF(HWC_UTILS_DEBUG, "%s: Handle non-secure video layer"
457                         "during secure playback gracefully", __FUNCTION__);
458                return true;
459            }
460        } else {
461            if (isSecureBuffer(hnd)) {
462                // This code path executes for the following usecase:
463                // For some Apps, when User terminates playback, Framework
464                // doesnt destroy video surface and video surface still
465                // comes to Display HAL. This exposes vulnerability on
466                // A-family. Catch this situation and handle it gracefully
467                // by allowing it to be composed by GPU.
468                ALOGD_IF(HWC_UTILS_DEBUG, "%s: Handle secure video layer"
469                         "during non-secure playback gracefully", __FUNCTION__);
470                return true;
471            }
472        }
473    }
474    return false;
475}
476
477bool isSecureModePolicy(int mdpVersion) {
478    if (mdpVersion < qdutils::MDSS_V5)
479        return true;
480    else
481        return false;
482}
483
484int getBlending(int blending) {
485    switch(blending) {
486    case HWC_BLENDING_NONE:
487        return overlay::utils::OVERLAY_BLENDING_OPAQUE;
488    case HWC_BLENDING_PREMULT:
489        return overlay::utils::OVERLAY_BLENDING_PREMULT;
490    case HWC_BLENDING_COVERAGE :
491    default:
492        return overlay::utils::OVERLAY_BLENDING_COVERAGE;
493    }
494}
495
496//Crops source buffer against destination and FB boundaries
497void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
498                          const hwc_rect_t& scissor, int orient) {
499
500    int& crop_l = crop.left;
501    int& crop_t = crop.top;
502    int& crop_r = crop.right;
503    int& crop_b = crop.bottom;
504    int crop_w = crop.right - crop.left;
505    int crop_h = crop.bottom - crop.top;
506
507    int& dst_l = dst.left;
508    int& dst_t = dst.top;
509    int& dst_r = dst.right;
510    int& dst_b = dst.bottom;
511    int dst_w = abs(dst.right - dst.left);
512    int dst_h = abs(dst.bottom - dst.top);
513
514    const int& sci_l = scissor.left;
515    const int& sci_t = scissor.top;
516    const int& sci_r = scissor.right;
517    const int& sci_b = scissor.bottom;
518    int sci_w = abs(sci_r - sci_l);
519    int sci_h = abs(sci_b - sci_t);
520
521    double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
522            bottomCutRatio = 0.0;
523
524    if(dst_l < sci_l) {
525        leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
526        dst_l = sci_l;
527    }
528
529    if(dst_r > sci_r) {
530        rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
531        dst_r = sci_r;
532    }
533
534    if(dst_t < sci_t) {
535        topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
536        dst_t = sci_t;
537    }
538
539    if(dst_b > sci_b) {
540        bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
541        dst_b = sci_b;
542    }
543
544    calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
545    crop_l += crop_w * leftCutRatio;
546    crop_t += crop_h * topCutRatio;
547    crop_r -= crop_w * rightCutRatio;
548    crop_b -= crop_h * bottomCutRatio;
549}
550
551void getNonWormholeRegion(hwc_display_contents_1_t* list,
552                              hwc_rect_t& nwr)
553{
554    uint32_t last = list->numHwLayers - 1;
555    hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
556    //Initiliaze nwr to first frame
557    nwr.left =  list->hwLayers[0].displayFrame.left;
558    nwr.top =  list->hwLayers[0].displayFrame.top;
559    nwr.right =  list->hwLayers[0].displayFrame.right;
560    nwr.bottom =  list->hwLayers[0].displayFrame.bottom;
561
562    for (uint32_t i = 1; i < last; i++) {
563        hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
564        nwr.left   = min(nwr.left, displayFrame.left);
565        nwr.top    = min(nwr.top, displayFrame.top);
566        nwr.right  = max(nwr.right, displayFrame.right);
567        nwr.bottom = max(nwr.bottom, displayFrame.bottom);
568    }
569
570    //Intersect with the framebuffer
571    nwr.left   = max(nwr.left, fbDisplayFrame.left);
572    nwr.top    = max(nwr.top, fbDisplayFrame.top);
573    nwr.right  = min(nwr.right, fbDisplayFrame.right);
574    nwr.bottom = min(nwr.bottom, fbDisplayFrame.bottom);
575
576}
577
578bool isSecondaryConfiguring(hwc_context_t* ctx) {
579    return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring |
580            ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring);
581}
582
583void closeAcquireFds(hwc_display_contents_1_t* list) {
584    if(LIKELY(list)) {
585        for(uint32_t i = 0; i < list->numHwLayers; i++) {
586            //Close the acquireFenceFds
587            //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
588            if(list->hwLayers[i].acquireFenceFd >= 0) {
589                close(list->hwLayers[i].acquireFenceFd);
590                list->hwLayers[i].acquireFenceFd = -1;
591            }
592        }
593    }
594}
595
596int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
597        int fd) {
598    int ret = 0;
599    int acquireFd[MAX_NUM_APP_LAYERS];
600    int count = 0;
601    int releaseFd = -1;
602    int fbFd = -1;
603    int rotFd = -1;
604    bool swapzero = false;
605    int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
606
607    struct mdp_buf_sync data;
608    memset(&data, 0, sizeof(data));
609    //Until B-family supports sync for rotator
610    if(mdpVersion >= qdutils::MDSS_V5) {
611        data.flags = MDP_BUF_SYNC_FLAG_WAIT;
612    }
613    data.acq_fen_fd = acquireFd;
614    data.rel_fen_fd = &releaseFd;
615
616    char property[PROPERTY_VALUE_MAX];
617    if(property_get("debug.egl.swapinterval", property, "1") > 0) {
618        if(atoi(property) == 0)
619            swapzero = true;
620    }
621
622#ifndef MDSS_TARGET
623    //Send acquireFenceFds to rotator
624    if(mdpVersion < qdutils::MDSS_V5) {
625        //A-family
626        int rotFd = ctx->mRotMgr->getRotDevFd();
627        struct msm_rotator_buf_sync rotData;
628
629        for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
630            memset(&rotData, 0, sizeof(rotData));
631            int& acquireFenceFd =
632                ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd;
633            rotData.acq_fen_fd = acquireFenceFd;
634            rotData.session_id = ctx->mLayerRotMap[dpy]->getRot(i)->getSessId();
635            ioctl(rotFd, MSM_ROTATOR_IOCTL_BUFFER_SYNC, &rotData);
636            close(acquireFenceFd);
637             //For MDP to wait on.
638            acquireFenceFd = dup(rotData.rel_fen_fd);
639            //A buffer is free to be used by producer as soon as its copied to
640            //rotator.
641            ctx->mLayerRotMap[dpy]->getLayer(i)->releaseFenceFd =
642                    rotData.rel_fen_fd;
643        }
644    } else {
645        //TODO B-family
646    }
647
648#endif
649    //Accumulate acquireFenceFds for MDP
650    for(uint32_t i = 0; i < list->numHwLayers; i++) {
651        if(list->hwLayers[i].compositionType == HWC_OVERLAY &&
652                        list->hwLayers[i].acquireFenceFd >= 0) {
653            if(UNLIKELY(swapzero))
654                acquireFd[count++] = -1;
655            else
656                acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
657        }
658        if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
659            if(UNLIKELY(swapzero))
660                acquireFd[count++] = -1;
661            else if(fd >= 0) {
662                //set the acquireFD from fd - which is coming from c2d
663                acquireFd[count++] = fd;
664                // Buffer sync IOCTL should be async when using c2d fence is
665                // used
666                data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
667            } else if(list->hwLayers[i].acquireFenceFd >= 0)
668                acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
669        }
670    }
671
672    data.acq_fen_fd_cnt = count;
673    fbFd = ctx->dpyAttr[dpy].fd;
674
675    //Waits for acquire fences, returns a release fence
676    if(LIKELY(!swapzero)) {
677        uint64_t start = systemTime();
678        ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
679        ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
680                            __FUNCTION__, (size_t) ns2ms(systemTime() - start));
681    }
682
683    if(ret < 0) {
684        ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
685                  __FUNCTION__, strerror(errno));
686        ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d",
687              __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
688              dpy, list->numHwLayers);
689    }
690
691    for(uint32_t i = 0; i < list->numHwLayers; i++) {
692        if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
693           list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
694            //Populate releaseFenceFds.
695            if(UNLIKELY(swapzero)) {
696                list->hwLayers[i].releaseFenceFd = -1;
697            } else if(list->hwLayers[i].releaseFenceFd < 0) {
698                //If rotator has not already populated this field.
699                list->hwLayers[i].releaseFenceFd = dup(releaseFd);
700            }
701        }
702    }
703
704    if(fd >= 0) {
705        close(fd);
706        fd = -1;
707    }
708
709    if (ctx->mCopyBit[dpy])
710        ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
711
712    //A-family
713    if(mdpVersion < qdutils::MDSS_V5) {
714        //Signals when MDP finishes reading rotator buffers.
715        ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
716    }
717
718    if(UNLIKELY(swapzero)){
719        list->retireFenceFd = -1;
720        close(releaseFd);
721    } else {
722        list->retireFenceFd = releaseFd;
723    }
724
725    return ret;
726}
727
728void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
729        hwc_rect_t& crop, hwc_rect_t& dst) {
730    int hw_w = ctx->dpyAttr[dpy].xres;
731    int hw_h = ctx->dpyAttr[dpy].yres;
732    if(dst.left < 0 || dst.top < 0 ||
733            dst.right > hw_w || dst.bottom > hw_h) {
734        hwc_rect_t scissor = {0, 0, hw_w, hw_h };
735        qhwc::calculate_crop_rects(crop, dst, scissor, transform);
736    }
737}
738
739void setMdpFlags(hwc_layer_1_t *layer,
740        ovutils::eMdpFlags &mdpFlags,
741        int rotDownscale) {
742    private_handle_t *hnd = (private_handle_t *)layer->handle;
743    MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
744    const int& transform = layer->transform;
745
746    if(layer->blending == HWC_BLENDING_PREMULT) {
747        ovutils::setMdpFlags(mdpFlags,
748                ovutils::OV_MDP_BLEND_FG_PREMULT);
749    }
750
751    if(isYuvBuffer(hnd)) {
752        if(isSecureBuffer(hnd)) {
753            ovutils::setMdpFlags(mdpFlags,
754                    ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
755        }
756        if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
757                metadata->interlaced) {
758            ovutils::setMdpFlags(mdpFlags,
759                    ovutils::OV_MDP_DEINTERLACE);
760        }
761        //Pre-rotation will be used using rotator.
762        if(transform & HWC_TRANSFORM_ROT_90) {
763            ovutils::setMdpFlags(mdpFlags,
764                    ovutils::OV_MDP_SOURCE_ROTATED_90);
765        }
766    }
767
768    //No 90 component and no rot-downscale then flips done by MDP
769    //If we use rot then it might as well do flips
770    if(!(layer->transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
771        if(layer->transform & HWC_TRANSFORM_FLIP_H) {
772            ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
773        }
774
775        if(layer->transform & HWC_TRANSFORM_FLIP_V) {
776            ovutils::setMdpFlags(mdpFlags,  ovutils::OV_MDP_FLIP_V);
777        }
778    }
779
780    if(metadata &&
781        ((metadata->operation & PP_PARAM_HSIC)
782        || (metadata->operation & PP_PARAM_IGC)
783        || (metadata->operation & PP_PARAM_SHARP2))) {
784        ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
785    }
786}
787
788int configRotator(Rotator *rot, const Whf& whf,
789        hwc_rect_t& crop, const eMdpFlags& mdpFlags,
790        const eTransform& orient, const int& downscale) {
791    rot->setSource(whf);
792
793    if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
794        qdutils::MDSS_V5) {
795        uint32_t crop_w = (crop.right - crop.left);
796        uint32_t crop_h = (crop.bottom - crop.top);
797        if (ovutils::isYuv(whf.format)) {
798            ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
799            ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
800            // For interlaced, crop.h should be 4-aligned
801            if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
802                crop_h = ovutils::aligndown(crop_h, 4);
803            crop.right = crop.left + crop_w;
804            crop.bottom = crop.top + crop_h;
805        }
806        Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
807        rot->setCrop(rotCrop);
808    }
809
810    rot->setFlags(mdpFlags);
811    rot->setTransform(orient);
812    rot->setDownscale(downscale);
813    if(!rot->commit()) return -1;
814    return 0;
815}
816
817int configMdp(Overlay *ov, const PipeArgs& parg,
818        const eTransform& orient, const hwc_rect_t& crop,
819        const hwc_rect_t& pos, const MetaData_t *metadata,
820        const eDest& dest) {
821    ov->setSource(parg, dest);
822    ov->setTransform(orient, dest);
823
824    int crop_w = crop.right - crop.left;
825    int crop_h = crop.bottom - crop.top;
826    Dim dcrop(crop.left, crop.top, crop_w, crop_h);
827    ov->setCrop(dcrop, dest);
828
829    int posW = pos.right - pos.left;
830    int posH = pos.bottom - pos.top;
831    Dim position(pos.left, pos.top, posW, posH);
832    ov->setPosition(position, dest);
833
834    if (metadata)
835        ov->setVisualParams(*metadata, dest);
836
837    if (!ov->commit(dest)) {
838        return -1;
839    }
840    return 0;
841}
842
843void updateSource(eTransform& orient, Whf& whf,
844        hwc_rect_t& crop) {
845    Dim srcCrop(crop.left, crop.top,
846            crop.right - crop.left,
847            crop.bottom - crop.top);
848    orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
849    preRotateSource(orient, whf, srcCrop);
850    if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
851        qdutils::MDSS_V5) {
852        // Source for overlay will be the cropped (and rotated)
853        crop.left = 0;
854        crop.top = 0;
855        crop.right = srcCrop.w;
856        crop.bottom = srcCrop.h;
857        // Set width & height equal to sourceCrop w & h
858        whf.w = srcCrop.w;
859        whf.h = srcCrop.h;
860    } else {
861        crop.left = srcCrop.x;
862        crop.top = srcCrop.y;
863        crop.right = srcCrop.x + srcCrop.w;
864        crop.bottom = srcCrop.y + srcCrop.h;
865    }
866}
867
868int configureLowRes(hwc_context_t *ctx, hwc_layer_1_t *layer,
869        const int& dpy, eMdpFlags& mdpFlags, const eZorder& z,
870        const eIsFg& isFg, const eDest& dest, Rotator **rot) {
871
872    private_handle_t *hnd = (private_handle_t *)layer->handle;
873    if(!hnd) {
874        ALOGE("%s: layer handle is NULL", __FUNCTION__);
875        ctx->mLayerRotMap[dpy]->reset();
876        return -1;
877    }
878
879    MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
880
881    hwc_rect_t crop = layer->sourceCrop;
882    hwc_rect_t dst = layer->displayFrame;
883    int transform = layer->transform;
884    eTransform orient = static_cast<eTransform>(transform);
885    int downscale = 0;
886    int rotFlags = ovutils::ROT_FLAGS_NONE;
887    Whf whf(getWidth(hnd), getHeight(hnd),
888            getMdpFormat(hnd->format), hnd->size);
889
890    uint32_t x = dst.left, y  = dst.top;
891    uint32_t w = dst.right - dst.left;
892    uint32_t h = dst.bottom - dst.top;
893
894    if(dpy) {
895        // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
896        getActionSafePosition(ctx, dpy, x, y, w, h);
897        // Convert position to hwc_rect_t
898        dst.left = x;
899        dst.top = y;
900        dst.right = w + dst.left;
901        dst.bottom = h + dst.top;
902    }
903
904    if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
905       ctx->mMDP.version < qdutils::MDSS_V5) {
906        downscale =  getDownscaleFactor(
907            crop.right - crop.left,
908            crop.bottom - crop.top,
909            dst.right - dst.left,
910            dst.bottom - dst.top);
911        if(downscale) {
912            rotFlags = ROT_DOWNSCALE_ENABLED;
913        }
914    }
915
916    setMdpFlags(layer, mdpFlags, downscale);
917    trimLayer(ctx, dpy, transform, crop, dst);
918
919    //Will do something only if feature enabled and conditions suitable
920    //hollow call otherwise
921    if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
922        overlay::Writeback *wb = overlay::Writeback::getInstance();
923        whf.format = wb->getOutputFormat();
924    }
925
926    if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
927            ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
928        *rot = ctx->mRotMgr->getNext();
929        if(*rot == NULL) return -1;
930        BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags);
931        //Configure rotator for pre-rotation
932        if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
933            ALOGE("%s: configRotator failed!", __FUNCTION__);
934            ctx->mOverlay->clear(dpy);
935            return -1;
936        }
937        ctx->mLayerRotMap[dpy]->add(layer, *rot);
938        whf.format = (*rot)->getDstFormat();
939        updateSource(orient, whf, crop);
940        rotFlags |= ovutils::ROT_PREROTATED;
941    }
942
943    //For the mdp, since either we are pre-rotating or MDP does flips
944    orient = OVERLAY_TRANSFORM_0;
945    transform = 0;
946
947    PipeArgs parg(mdpFlags, whf, z, isFg,
948                  static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
949                  (ovutils::eBlending) getBlending(layer->blending));
950
951    if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
952        ALOGE("%s: commit failed for low res panel", __FUNCTION__);
953        ctx->mLayerRotMap[dpy]->reset();
954        return -1;
955    }
956    return 0;
957}
958
959int configureHighRes(hwc_context_t *ctx, hwc_layer_1_t *layer,
960        const int& dpy, eMdpFlags& mdpFlagsL, const eZorder& z,
961        const eIsFg& isFg, const eDest& lDest, const eDest& rDest,
962        Rotator **rot) {
963    private_handle_t *hnd = (private_handle_t *)layer->handle;
964    if(!hnd) {
965        ALOGE("%s: layer handle is NULL", __FUNCTION__);
966        return -1;
967    }
968
969    MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
970
971    int hw_w = ctx->dpyAttr[dpy].xres;
972    int hw_h = ctx->dpyAttr[dpy].yres;
973    hwc_rect_t crop = layer->sourceCrop;
974    hwc_rect_t dst = layer->displayFrame;
975    int transform = layer->transform;
976    eTransform orient = static_cast<eTransform>(transform);
977    const int downscale = 0;
978    int rotFlags = ROT_FLAGS_NONE;
979
980    Whf whf(getWidth(hnd), getHeight(hnd),
981            getMdpFormat(hnd->format), hnd->size);
982
983    setMdpFlags(layer, mdpFlagsL, 0);
984    trimLayer(ctx, dpy, transform, crop, dst);
985
986    //Will do something only if feature enabled and conditions suitable
987    //hollow call otherwise
988    if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
989        overlay::Writeback *wb = overlay::Writeback::getInstance();
990        whf.format = wb->getOutputFormat();
991    }
992
993    if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
994        (*rot) = ctx->mRotMgr->getNext();
995        if((*rot) == NULL) return -1;
996        //Configure rotator for pre-rotation
997        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
998            ALOGE("%s: configRotator failed!", __FUNCTION__);
999            ctx->mOverlay->clear(dpy);
1000            return -1;
1001        }
1002        ctx->mLayerRotMap[dpy]->add(layer, *rot);
1003        whf.format = (*rot)->getDstFormat();
1004        updateSource(orient, whf, crop);
1005        rotFlags |= ROT_PREROTATED;
1006    }
1007
1008    eMdpFlags mdpFlagsR = mdpFlagsL;
1009    setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1010
1011    hwc_rect_t tmp_cropL, tmp_dstL;
1012    hwc_rect_t tmp_cropR, tmp_dstR;
1013
1014    const int lSplit = getLeftSplit(ctx, dpy);
1015
1016    if(lDest != OV_INVALID) {
1017        tmp_cropL = crop;
1018        tmp_dstL = dst;
1019        hwc_rect_t scissor = {0, 0, lSplit, hw_h };
1020        qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1021    }
1022    if(rDest != OV_INVALID) {
1023        tmp_cropR = crop;
1024        tmp_dstR = dst;
1025        hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
1026        qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1027    }
1028
1029    //When buffer is H-flipped, contents of mixer config also needs to swapped
1030    //Not needed if the layer is confined to one half of the screen.
1031    //If rotator has been used then it has also done the flips, so ignore them.
1032    if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
1033            && rDest != OV_INVALID && (*rot) == NULL) {
1034        hwc_rect_t new_cropR;
1035        new_cropR.left = tmp_cropL.left;
1036        new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1037
1038        hwc_rect_t new_cropL;
1039        new_cropL.left  = new_cropR.right;
1040        new_cropL.right = tmp_cropR.right;
1041
1042        tmp_cropL.left =  new_cropL.left;
1043        tmp_cropL.right =  new_cropL.right;
1044
1045        tmp_cropR.left = new_cropR.left;
1046        tmp_cropR.right =  new_cropR.right;
1047
1048    }
1049
1050    //For the mdp, since either we are pre-rotating or MDP does flips
1051    orient = OVERLAY_TRANSFORM_0;
1052    transform = 0;
1053
1054    //configure left mixer
1055    if(lDest != OV_INVALID) {
1056        PipeArgs pargL(mdpFlagsL, whf, z, isFg,
1057                       static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1058                       (ovutils::eBlending) getBlending(layer->blending));
1059
1060        if(configMdp(ctx->mOverlay, pargL, orient,
1061                tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
1062            ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1063            return -1;
1064        }
1065    }
1066
1067    //configure right mixer
1068    if(rDest != OV_INVALID) {
1069        PipeArgs pargR(mdpFlagsR, whf, z, isFg,
1070                static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1071                (ovutils::eBlending) getBlending(layer->blending));
1072
1073        tmp_dstR.right = tmp_dstR.right - lSplit;
1074        tmp_dstR.left = tmp_dstR.left - lSplit;
1075        if(configMdp(ctx->mOverlay, pargR, orient,
1076                tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
1077            ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1078            return -1;
1079        }
1080    }
1081
1082    return 0;
1083}
1084
1085bool canUseRotator(hwc_context_t *ctx) {
1086    if(qdutils::MDPVersion::getInstance().is8x26() &&
1087            ctx->mExtDisplay->isExternalConnected()) {
1088        return false;
1089    }
1090    if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1091        return false;
1092    return true;
1093}
1094
1095int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
1096    //Default even split for all displays with high res
1097    int lSplit = ctx->dpyAttr[dpy].xres / 2;
1098    if(dpy == HWC_DISPLAY_PRIMARY &&
1099            qdutils::MDPVersion::getInstance().getLeftSplit()) {
1100        //Override if split published by driver for primary
1101        lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1102    }
1103    return lSplit;
1104}
1105
1106void setupSecondaryObjs(hwc_context_t *ctx, const int& dpy) {
1107    const int rSplit = 0;
1108    ctx->mFBUpdate[dpy] =
1109            IFBUpdate::getObject(ctx->dpyAttr[dpy].xres, rSplit, dpy);
1110    ctx->mMDPComp[dpy] =  MDPComp::getObject(
1111            ctx->dpyAttr[dpy].xres, rSplit, dpy);
1112
1113    int compositionType =
1114            qdutils::QCCompositionType::getInstance().getCompositionType();
1115    if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
1116                           qdutils::COMPOSITION_TYPE_MDP |
1117                           qdutils::COMPOSITION_TYPE_C2D)) {
1118        ctx->mCopyBit[dpy] = new CopyBit();
1119    }
1120}
1121
1122void clearSecondaryObjs(hwc_context_t *ctx, const int& dpy) {
1123    if(ctx->mFBUpdate[dpy]) {
1124        delete ctx->mFBUpdate[dpy];
1125        ctx->mFBUpdate[dpy] = NULL;
1126    }
1127    if(ctx->mCopyBit[dpy]){
1128        delete ctx->mCopyBit[dpy];
1129        ctx->mCopyBit[dpy] = NULL;
1130    }
1131    if(ctx->mMDPComp[dpy]) {
1132        delete ctx->mMDPComp[dpy];
1133        ctx->mMDPComp[dpy] = NULL;
1134    }
1135}
1136
1137void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
1138            const hwc_rect_t& dst, const int& transform,
1139            ovutils::eMdpFlags& mdpFlags) {
1140    //Target doesnt support Bwc
1141    if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
1142        return;
1143    }
1144    //src width > MAX mixer supported dim
1145    if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1146        return;
1147    }
1148    //External connected
1149    if(ctx->mExtDisplay->isExternalConnected()) {
1150        return;
1151    }
1152    //Decimation necessary, cannot use BWC. H/W requirement.
1153    if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
1154        int src_w = crop.right - crop.left;
1155        int src_h = crop.bottom - crop.top;
1156        int dst_w = dst.right - dst.left;
1157        int dst_h = dst.bottom - dst.top;
1158        if(transform & HAL_TRANSFORM_ROT_90) {
1159            swap(src_w, src_h);
1160        }
1161        float horDscale = 0.0f;
1162        float verDscale = 0.0f;
1163        int horzDeci = 0;
1164        int vertDeci = 0;
1165        ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
1166                verDscale);
1167        //TODO Use log2f once math.h has it
1168        if((int)horDscale)
1169            horzDeci = (int)(log(horDscale) / log(2));
1170        if((int)verDscale)
1171            vertDeci = (int)(log(verDscale) / log(2));
1172        if(horzDeci || vertDeci) return;
1173    }
1174    //Property
1175    char value[PROPERTY_VALUE_MAX];
1176    property_get("debug.disable.bwc", value, "0");
1177     if(atoi(value)) return;
1178
1179    ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
1180}
1181
1182void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
1183    if(mCount >= MAX_SESS) return;
1184    mLayer[mCount] = layer;
1185    mRot[mCount] = rot;
1186    mCount++;
1187}
1188
1189void LayerRotMap::reset() {
1190    for (int i = 0; i < MAX_SESS; i++) {
1191        mLayer[i] = 0;
1192        mRot[i] = 0;
1193    }
1194    mCount = 0;
1195}
1196
1197void LayerRotMap::setReleaseFd(const int& fence) {
1198    for(uint32_t i = 0; i < mCount; i++) {
1199        mRot[i]->setReleaseFd(dup(fence));
1200    }
1201}
1202
1203};//namespace qhwc
1204