hwc_utils.cpp revision d80659c540b719660c7af9f530445268bc409db6
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    if(openFramebufferDevice(ctx) < 0) {
126        ALOGE("%s: failed to open framebuffer!!", __FUNCTION__);
127    }
128
129    overlay::Overlay::initOverlay();
130    ctx->mOverlay = overlay::Overlay::getInstance();
131    ctx->mRotMgr = new RotMgr();
132    ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
133    ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
134    ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
135    const int rightSplit = qdutils::MDPVersion::getInstance().getRightSplit();
136    overlay::Overlay::initOverlay();
137    ctx->mOverlay = overlay::Overlay::getInstance();
138    ctx->mRotMgr = new RotMgr();
139
140    //Is created and destroyed only once for primary
141    //For external it could get created and destroyed multiple times depending
142    //on what external we connect to.
143    ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
144        IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
145                rightSplit, HWC_DISPLAY_PRIMARY);
146
147    // Check if the target supports copybit compostion (dyn/mdp/c2d) to
148    // decide if we need to open the copybit module.
149    int compositionType =
150        qdutils::QCCompositionType::getInstance().getCompositionType();
151
152    if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
153                           qdutils::COMPOSITION_TYPE_MDP |
154                           qdutils::COMPOSITION_TYPE_C2D)) {
155            ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit();
156    }
157
158    ctx->mExtDisplay = new ExternalDisplay(ctx);
159
160    for (uint32_t i = 0; i < MAX_DISPLAYS; i++) {
161        ctx->mLayerRotMap[i] = new LayerRotMap();
162    }
163
164    ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
165         MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
166                rightSplit, HWC_DISPLAY_PRIMARY);
167
168    MDPComp::init(ctx);
169    ctx->mAD = new AssertiveDisplay();
170
171    ctx->vstate.enable = false;
172    ctx->vstate.fakevsync = false;
173    ctx->mExtDispConfiguring = false;
174    ctx->mBasePipeSetup = false;
175
176    //Right now hwc starts the service but anybody could do it, or it could be
177    //independent process as well.
178    QService::init();
179    sp<IQClient> client = new QClient(ctx);
180    interface_cast<IQService>(
181            defaultServiceManager()->getService(
182            String16("display.qservice")))->connect(client);
183
184    ALOGI("Initializing Qualcomm Hardware Composer");
185    ALOGI("MDP version: %d", ctx->mMDP.version);
186}
187
188void closeContext(hwc_context_t *ctx)
189{
190    if(ctx->mOverlay) {
191        delete ctx->mOverlay;
192        ctx->mOverlay = NULL;
193    }
194
195    if(ctx->mRotMgr) {
196        delete ctx->mRotMgr;
197        ctx->mRotMgr = NULL;
198    }
199
200    for(int i = 0; i < MAX_DISPLAYS; i++) {
201        if(ctx->mCopyBit[i]) {
202            delete ctx->mCopyBit[i];
203            ctx->mCopyBit[i] = NULL;
204        }
205    }
206
207    if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
208        close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
209        ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
210    }
211
212    if(ctx->mExtDisplay) {
213        delete ctx->mExtDisplay;
214        ctx->mExtDisplay = NULL;
215    }
216
217    for(int i = 0; i < MAX_DISPLAYS; i++) {
218        if(ctx->mFBUpdate[i]) {
219            delete ctx->mFBUpdate[i];
220            ctx->mFBUpdate[i] = NULL;
221        }
222        if(ctx->mMDPComp[i]) {
223            delete ctx->mMDPComp[i];
224            ctx->mMDPComp[i] = NULL;
225        }
226        if(ctx->mLayerRotMap[i]) {
227            delete ctx->mLayerRotMap[i];
228            ctx->mLayerRotMap[i] = NULL;
229        }
230    }
231
232    if(ctx->mAD) {
233        delete ctx->mAD;
234        ctx->mAD = NULL;
235    }
236}
237
238
239void dumpsys_log(android::String8& buf, const char* fmt, ...)
240{
241    va_list varargs;
242    va_start(varargs, fmt);
243    buf.appendFormatV(fmt, varargs);
244    va_end(varargs);
245}
246
247/* Calculates the destination position based on the action safe rectangle */
248void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x,
249                           uint32_t& y, uint32_t& w, uint32_t& h) {
250
251    // if external supports underscan, do nothing
252    // it will be taken care in the driver
253    if(ctx->mExtDisplay->isCEUnderscanSupported())
254        return;
255
256    char value[PROPERTY_VALUE_MAX];
257    // Read action safe properties
258    property_get("persist.sys.actionsafe.width", value, "0");
259    int asWidthRatio = atoi(value);
260    property_get("persist.sys.actionsafe.height", value, "0");
261    int asHeightRatio = atoi(value);
262
263    if(!asWidthRatio && !asHeightRatio) {
264        //No action safe ratio set, return
265        return;
266    }
267
268    float wRatio = 1.0;
269    float hRatio = 1.0;
270    float xRatio = 1.0;
271    float yRatio = 1.0;
272
273    float fbWidth = ctx->dpyAttr[dpy].xres;
274    float fbHeight = ctx->dpyAttr[dpy].yres;
275
276    float asX = 0;
277    float asY = 0;
278    float asW = fbWidth;
279    float asH= fbHeight;
280
281    // based on the action safe ratio, get the Action safe rectangle
282    asW = fbWidth * (1.0f -  asWidthRatio / 100.0f);
283    asH = fbHeight * (1.0f -  asHeightRatio / 100.0f);
284    asX = (fbWidth - asW) / 2;
285    asY = (fbHeight - asH) / 2;
286
287    // calculate the position ratio
288    xRatio = (float)x/fbWidth;
289    yRatio = (float)y/fbHeight;
290    wRatio = (float)w/fbWidth;
291    hRatio = (float)h/fbHeight;
292
293    //Calculate the position...
294    x = (xRatio * asW) + asX;
295    y = (yRatio * asH) + asY;
296    w = (wRatio * asW);
297    h = (hRatio * asH);
298
299    return;
300}
301
302bool needsScaling(hwc_context_t* ctx, hwc_layer_1_t const* layer,
303        const int& dpy) {
304    int dst_w, dst_h, src_w, src_h;
305
306    hwc_rect_t displayFrame  = layer->displayFrame;
307    hwc_rect_t sourceCrop = layer->sourceCrop;
308    trimLayer(ctx, dpy, layer->transform, sourceCrop, displayFrame);
309
310    dst_w = displayFrame.right - displayFrame.left;
311    dst_h = displayFrame.bottom - displayFrame.top;
312    src_w = sourceCrop.right - sourceCrop.left;
313    src_h = sourceCrop.bottom - sourceCrop.top;
314
315    if(((src_w != dst_w) || (src_h != dst_h)))
316        return true;
317
318    return false;
319}
320
321bool isAlphaScaled(hwc_context_t* ctx, hwc_layer_1_t const* layer,
322        const int& dpy) {
323    if(needsScaling(ctx, layer, dpy) && isAlphaPresent(layer)) {
324        return true;
325    }
326    return false;
327}
328
329bool isAlphaPresent(hwc_layer_1_t const* layer) {
330    private_handle_t *hnd = (private_handle_t *)layer->handle;
331    if(hnd) {
332        int format = hnd->format;
333        switch(format) {
334        case HAL_PIXEL_FORMAT_RGBA_8888:
335        case HAL_PIXEL_FORMAT_BGRA_8888:
336            // In any more formats with Alpha go here..
337            return true;
338        default : return false;
339        }
340    }
341    return false;
342}
343
344// Let CABL know we have a YUV layer
345static void setYUVProp(int yuvCount) {
346    static char property[PROPERTY_VALUE_MAX];
347    if(yuvCount > 0) {
348        if (property_get("hw.cabl.yuv", property, NULL) > 0) {
349            if (atoi(property) != 1) {
350                property_set("hw.cabl.yuv", "1");
351            }
352        }
353    } else {
354        if (property_get("hw.cabl.yuv", property, NULL) > 0) {
355            if (atoi(property) != 0) {
356                property_set("hw.cabl.yuv", "0");
357            }
358        }
359    }
360}
361
362void setListStats(hwc_context_t *ctx,
363        const hwc_display_contents_1_t *list, int dpy) {
364    const int prevYuvCount = ctx->listStats[dpy].yuvCount;
365    memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
366    ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
367    ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
368    ctx->listStats[dpy].skipCount = 0;
369    ctx->listStats[dpy].needsAlphaScale = false;
370    ctx->listStats[dpy].preMultipliedAlpha = false;
371    ctx->listStats[dpy].planeAlpha = false;
372    ctx->listStats[dpy].yuvCount = 0;
373
374    for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
375        hwc_layer_1_t const* layer = &list->hwLayers[i];
376        private_handle_t *hnd = (private_handle_t *)layer->handle;
377
378        // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
379        if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
380            continue;
381
382        //reset yuv indices
383        ctx->listStats[dpy].yuvIndices[i] = -1;
384
385        if (isSkipLayer(&list->hwLayers[i])) {
386            ctx->listStats[dpy].skipCount++;
387        } else if (UNLIKELY(isYuvBuffer(hnd))) {
388            int& yuvCount = ctx->listStats[dpy].yuvCount;
389            ctx->listStats[dpy].yuvIndices[yuvCount] = i;
390            yuvCount++;
391
392            if((layer->transform & HWC_TRANSFORM_ROT_90) &&
393                    canUseRotator(ctx)) {
394                if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
395                    ctx->isPaddingRound = true;
396                }
397                Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
398            }
399        }
400        if(layer->blending == HWC_BLENDING_PREMULT)
401            ctx->listStats[dpy].preMultipliedAlpha = true;
402        if(layer->planeAlpha < 0xFF)
403            ctx->listStats[dpy].planeAlpha = true;
404        if(!ctx->listStats[dpy].needsAlphaScale)
405            ctx->listStats[dpy].needsAlphaScale =
406                    isAlphaScaled(ctx, layer, dpy);
407    }
408    setYUVProp(ctx->listStats[dpy].yuvCount);
409    //The marking of video begin/end is useful on some targets where we need
410    //to have a padding round to be able to shift pipes across mixers.
411    if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
412        ctx->mVideoTransFlag = true;
413    }
414    if(dpy == HWC_DISPLAY_PRIMARY) {
415        ctx->mAD->markDoable(ctx, list);
416    }
417}
418
419
420static void calc_cut(double& leftCutRatio, double& topCutRatio,
421        double& rightCutRatio, double& bottomCutRatio, int orient) {
422    if(orient & HAL_TRANSFORM_FLIP_H) {
423        swap(leftCutRatio, rightCutRatio);
424    }
425    if(orient & HAL_TRANSFORM_FLIP_V) {
426        swap(topCutRatio, bottomCutRatio);
427    }
428    if(orient & HAL_TRANSFORM_ROT_90) {
429        //Anti clock swapping
430        double tmpCutRatio = leftCutRatio;
431        leftCutRatio = topCutRatio;
432        topCutRatio = rightCutRatio;
433        rightCutRatio = bottomCutRatio;
434        bottomCutRatio = tmpCutRatio;
435    }
436}
437
438bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
439    if((ctx->mMDP.version < qdutils::MDSS_V5) &&
440       (ctx->mMDP.version > qdutils::MDP_V3_0) &&
441        ctx->mSecuring) {
442        return true;
443    }
444    //  On A-Family, Secure policy is applied system wide and not on
445    //  buffers.
446    if (isSecureModePolicy(ctx->mMDP.version)) {
447        private_handle_t *hnd = (private_handle_t *)layer->handle;
448        if(ctx->mSecureMode) {
449            if (! isSecureBuffer(hnd)) {
450                // This code path executes for the following usecase:
451                // Some Apps in which first few seconds, framework
452                // sends non-secure buffer and with out destroying
453                // surfaces, switches to secure buffer thereby exposing
454                // vulnerability on A-family devices. Catch this situation
455                // and handle it gracefully by allowing it to be composed by
456                // GPU.
457                ALOGD_IF(HWC_UTILS_DEBUG, "%s: Handle non-secure video layer"
458                         "during secure playback gracefully", __FUNCTION__);
459                return true;
460            }
461        } else {
462            if (isSecureBuffer(hnd)) {
463                // This code path executes for the following usecase:
464                // For some Apps, when User terminates playback, Framework
465                // doesnt destroy video surface and video surface still
466                // comes to Display HAL. This exposes vulnerability on
467                // A-family. Catch this situation and handle it gracefully
468                // by allowing it to be composed by GPU.
469                ALOGD_IF(HWC_UTILS_DEBUG, "%s: Handle secure video layer"
470                         "during non-secure playback gracefully", __FUNCTION__);
471                return true;
472            }
473        }
474    }
475    return false;
476}
477
478bool isSecureModePolicy(int mdpVersion) {
479    if (mdpVersion < qdutils::MDSS_V5)
480        return true;
481    else
482        return false;
483}
484
485int getBlending(int blending) {
486    switch(blending) {
487    case HWC_BLENDING_NONE:
488        return overlay::utils::OVERLAY_BLENDING_OPAQUE;
489    case HWC_BLENDING_PREMULT:
490        return overlay::utils::OVERLAY_BLENDING_PREMULT;
491    case HWC_BLENDING_COVERAGE :
492    default:
493        return overlay::utils::OVERLAY_BLENDING_COVERAGE;
494    }
495}
496
497//Crops source buffer against destination and FB boundaries
498void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
499                          const hwc_rect_t& scissor, int orient) {
500
501    int& crop_l = crop.left;
502    int& crop_t = crop.top;
503    int& crop_r = crop.right;
504    int& crop_b = crop.bottom;
505    int crop_w = crop.right - crop.left;
506    int crop_h = crop.bottom - crop.top;
507
508    int& dst_l = dst.left;
509    int& dst_t = dst.top;
510    int& dst_r = dst.right;
511    int& dst_b = dst.bottom;
512    int dst_w = abs(dst.right - dst.left);
513    int dst_h = abs(dst.bottom - dst.top);
514
515    const int& sci_l = scissor.left;
516    const int& sci_t = scissor.top;
517    const int& sci_r = scissor.right;
518    const int& sci_b = scissor.bottom;
519    int sci_w = abs(sci_r - sci_l);
520    int sci_h = abs(sci_b - sci_t);
521
522    double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
523            bottomCutRatio = 0.0;
524
525    if(dst_l < sci_l) {
526        leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
527        dst_l = sci_l;
528    }
529
530    if(dst_r > sci_r) {
531        rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
532        dst_r = sci_r;
533    }
534
535    if(dst_t < sci_t) {
536        topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
537        dst_t = sci_t;
538    }
539
540    if(dst_b > sci_b) {
541        bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
542        dst_b = sci_b;
543    }
544
545    calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
546    crop_l += crop_w * leftCutRatio;
547    crop_t += crop_h * topCutRatio;
548    crop_r -= crop_w * rightCutRatio;
549    crop_b -= crop_h * bottomCutRatio;
550}
551
552void getNonWormholeRegion(hwc_display_contents_1_t* list,
553                              hwc_rect_t& nwr)
554{
555    uint32_t last = list->numHwLayers - 1;
556    hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
557    //Initiliaze nwr to first frame
558    nwr.left =  list->hwLayers[0].displayFrame.left;
559    nwr.top =  list->hwLayers[0].displayFrame.top;
560    nwr.right =  list->hwLayers[0].displayFrame.right;
561    nwr.bottom =  list->hwLayers[0].displayFrame.bottom;
562
563    for (uint32_t i = 1; i < last; i++) {
564        hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
565        nwr.left   = min(nwr.left, displayFrame.left);
566        nwr.top    = min(nwr.top, displayFrame.top);
567        nwr.right  = max(nwr.right, displayFrame.right);
568        nwr.bottom = max(nwr.bottom, displayFrame.bottom);
569    }
570
571    //Intersect with the framebuffer
572    nwr.left   = max(nwr.left, fbDisplayFrame.left);
573    nwr.top    = max(nwr.top, fbDisplayFrame.top);
574    nwr.right  = min(nwr.right, fbDisplayFrame.right);
575    nwr.bottom = min(nwr.bottom, fbDisplayFrame.bottom);
576
577}
578
579bool isExternalActive(hwc_context_t* ctx) {
580    return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
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
817/*
818 * Sets up BORDERFILL as default base pipe and detaches RGB0.
819 * Framebuffer is always updated using PLAY ioctl.
820 */
821bool setupBasePipe(hwc_context_t *ctx) {
822    const int dpy = HWC_DISPLAY_PRIMARY;
823    int fb_stride = ctx->dpyAttr[dpy].stride;
824    int fb_width = ctx->dpyAttr[dpy].xres;
825    int fb_height = ctx->dpyAttr[dpy].yres;
826    int fb_fd = ctx->dpyAttr[dpy].fd;
827
828    mdp_overlay ovInfo;
829    msmfb_overlay_data ovData;
830    memset(&ovInfo, 0, sizeof(mdp_overlay));
831    memset(&ovData, 0, sizeof(msmfb_overlay_data));
832
833    ovInfo.src.format = MDP_RGB_BORDERFILL;
834    ovInfo.src.width  = fb_width;
835    ovInfo.src.height = fb_height;
836    ovInfo.src_rect.w = fb_width;
837    ovInfo.src_rect.h = fb_height;
838    ovInfo.dst_rect.w = fb_width;
839    ovInfo.dst_rect.h = fb_height;
840    ovInfo.id = MSMFB_NEW_REQUEST;
841
842    if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
843        ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
844                strerror(errno));
845        return false;
846    }
847
848    ovData.id = ovInfo.id;
849    if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
850        ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
851                strerror(errno));
852        return false;
853    }
854    ctx->mBasePipeSetup = true;
855    return true;
856}
857
858int configMdp(Overlay *ov, const PipeArgs& parg,
859        const eTransform& orient, const hwc_rect_t& crop,
860        const hwc_rect_t& pos, const MetaData_t *metadata,
861        const eDest& dest) {
862    ov->setSource(parg, dest);
863    ov->setTransform(orient, dest);
864
865    int crop_w = crop.right - crop.left;
866    int crop_h = crop.bottom - crop.top;
867    Dim dcrop(crop.left, crop.top, crop_w, crop_h);
868    ov->setCrop(dcrop, dest);
869
870    int posW = pos.right - pos.left;
871    int posH = pos.bottom - pos.top;
872    Dim position(pos.left, pos.top, posW, posH);
873    ov->setPosition(position, dest);
874
875    if (metadata)
876        ov->setVisualParams(*metadata, dest);
877
878    if (!ov->commit(dest)) {
879        return -1;
880    }
881    return 0;
882}
883
884void updateSource(eTransform& orient, Whf& whf,
885        hwc_rect_t& crop) {
886    Dim srcCrop(crop.left, crop.top,
887            crop.right - crop.left,
888            crop.bottom - crop.top);
889    orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
890    preRotateSource(orient, whf, srcCrop);
891    if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
892        qdutils::MDSS_V5) {
893        // Source for overlay will be the cropped (and rotated)
894        crop.left = 0;
895        crop.top = 0;
896        crop.right = srcCrop.w;
897        crop.bottom = srcCrop.h;
898        // Set width & height equal to sourceCrop w & h
899        whf.w = srcCrop.w;
900        whf.h = srcCrop.h;
901    } else {
902        crop.left = srcCrop.x;
903        crop.top = srcCrop.y;
904        crop.right = srcCrop.x + srcCrop.w;
905        crop.bottom = srcCrop.y + srcCrop.h;
906    }
907}
908
909int configureLowRes(hwc_context_t *ctx, hwc_layer_1_t *layer,
910        const int& dpy, eMdpFlags& mdpFlags, const eZorder& z,
911        const eIsFg& isFg, const eDest& dest, Rotator **rot) {
912
913    private_handle_t *hnd = (private_handle_t *)layer->handle;
914    if(!hnd) {
915        ALOGE("%s: layer handle is NULL", __FUNCTION__);
916        ctx->mLayerRotMap[dpy]->reset();
917        return -1;
918    }
919
920    MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
921
922    hwc_rect_t crop = layer->sourceCrop;
923    hwc_rect_t dst = layer->displayFrame;
924    int transform = layer->transform;
925    eTransform orient = static_cast<eTransform>(transform);
926    int downscale = 0;
927    int rotFlags = ovutils::ROT_FLAGS_NONE;
928    Whf whf(hnd->width, hnd->height,
929            getMdpFormat(hnd->format), hnd->size);
930
931    uint32_t x = dst.left, y  = dst.top;
932    uint32_t w = dst.right - dst.left;
933    uint32_t h = dst.bottom - dst.top;
934
935    if(dpy) {
936        // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
937        getActionSafePosition(ctx, dpy, x, y, w, h);
938        // Convert position to hwc_rect_t
939        dst.left = x;
940        dst.top = y;
941        dst.right = w + dst.left;
942        dst.bottom = h + dst.top;
943    }
944
945    if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
946       ctx->mMDP.version < qdutils::MDSS_V5) {
947        downscale =  getDownscaleFactor(
948            crop.right - crop.left,
949            crop.bottom - crop.top,
950            dst.right - dst.left,
951            dst.bottom - dst.top);
952        if(downscale) {
953            rotFlags = ROT_DOWNSCALE_ENABLED;
954        }
955    }
956
957    setMdpFlags(layer, mdpFlags, downscale);
958    trimLayer(ctx, dpy, transform, crop, dst);
959
960    //Will do something only if feature enabled and conditions suitable
961    //hollow call otherwise
962    if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
963        overlay::Writeback *wb = overlay::Writeback::getInstance();
964        whf.format = wb->getOutputFormat();
965    }
966
967    if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
968            ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
969        *rot = ctx->mRotMgr->getNext();
970        if(*rot == NULL) return -1;
971        BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags);
972        //Configure rotator for pre-rotation
973        if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
974            ALOGE("%s: configRotator failed!", __FUNCTION__);
975            ctx->mOverlay->clear(dpy);
976            return -1;
977        }
978        ctx->mLayerRotMap[dpy]->add(layer, *rot);
979        whf.format = (*rot)->getDstFormat();
980        updateSource(orient, whf, crop);
981        rotFlags |= ovutils::ROT_PREROTATED;
982    }
983
984    //For the mdp, since either we are pre-rotating or MDP does flips
985    orient = OVERLAY_TRANSFORM_0;
986    transform = 0;
987
988    PipeArgs parg(mdpFlags, whf, z, isFg,
989                  static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
990                  (ovutils::eBlending) getBlending(layer->blending));
991
992    if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
993        ALOGE("%s: commit failed for low res panel", __FUNCTION__);
994        ctx->mLayerRotMap[dpy]->reset();
995        return -1;
996    }
997    return 0;
998}
999
1000int configureHighRes(hwc_context_t *ctx, hwc_layer_1_t *layer,
1001        const int& dpy, eMdpFlags& mdpFlagsL, const eZorder& z,
1002        const eIsFg& isFg, const eDest& lDest, const eDest& rDest,
1003        Rotator **rot) {
1004    private_handle_t *hnd = (private_handle_t *)layer->handle;
1005    if(!hnd) {
1006        ALOGE("%s: layer handle is NULL", __FUNCTION__);
1007        return -1;
1008    }
1009
1010    MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1011
1012    int hw_w = ctx->dpyAttr[dpy].xres;
1013    int hw_h = ctx->dpyAttr[dpy].yres;
1014    hwc_rect_t crop = layer->sourceCrop;
1015    hwc_rect_t dst = layer->displayFrame;
1016    int transform = layer->transform;
1017    eTransform orient = static_cast<eTransform>(transform);
1018    const int downscale = 0;
1019    int rotFlags = ROT_FLAGS_NONE;
1020
1021    Whf whf(hnd->width, hnd->height,
1022            getMdpFormat(hnd->format), hnd->size);
1023
1024    setMdpFlags(layer, mdpFlagsL, 0);
1025    trimLayer(ctx, dpy, transform, crop, dst);
1026
1027    //Will do something only if feature enabled and conditions suitable
1028    //hollow call otherwise
1029    if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
1030        overlay::Writeback *wb = overlay::Writeback::getInstance();
1031        whf.format = wb->getOutputFormat();
1032    }
1033
1034    if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1035        (*rot) = ctx->mRotMgr->getNext();
1036        if((*rot) == NULL) return -1;
1037        //Configure rotator for pre-rotation
1038        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1039            ALOGE("%s: configRotator failed!", __FUNCTION__);
1040            ctx->mOverlay->clear(dpy);
1041            return -1;
1042        }
1043        ctx->mLayerRotMap[dpy]->add(layer, *rot);
1044        whf.format = (*rot)->getDstFormat();
1045        updateSource(orient, whf, crop);
1046        rotFlags |= ROT_PREROTATED;
1047    }
1048
1049    eMdpFlags mdpFlagsR = mdpFlagsL;
1050    setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1051
1052    hwc_rect_t tmp_cropL, tmp_dstL;
1053    hwc_rect_t tmp_cropR, tmp_dstR;
1054
1055    const int lSplit = getLeftSplit(ctx, dpy);
1056
1057    if(lDest != OV_INVALID) {
1058        tmp_cropL = crop;
1059        tmp_dstL = dst;
1060        hwc_rect_t scissor = {0, 0, lSplit, hw_h };
1061        qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1062    }
1063    if(rDest != OV_INVALID) {
1064        tmp_cropR = crop;
1065        tmp_dstR = dst;
1066        hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
1067        qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1068    }
1069
1070    //When buffer is H-flipped, contents of mixer config also needs to swapped
1071    //Not needed if the layer is confined to one half of the screen.
1072    //If rotator has been used then it has also done the flips, so ignore them.
1073    if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
1074            && rDest != OV_INVALID && (*rot) == NULL) {
1075        hwc_rect_t new_cropR;
1076        new_cropR.left = tmp_cropL.left;
1077        new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1078
1079        hwc_rect_t new_cropL;
1080        new_cropL.left  = new_cropR.right;
1081        new_cropL.right = tmp_cropR.right;
1082
1083        tmp_cropL.left =  new_cropL.left;
1084        tmp_cropL.right =  new_cropL.right;
1085
1086        tmp_cropR.left = new_cropR.left;
1087        tmp_cropR.right =  new_cropR.right;
1088
1089    }
1090
1091    //For the mdp, since either we are pre-rotating or MDP does flips
1092    orient = OVERLAY_TRANSFORM_0;
1093    transform = 0;
1094
1095    //configure left mixer
1096    if(lDest != OV_INVALID) {
1097        PipeArgs pargL(mdpFlagsL, whf, z, isFg,
1098                       static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1099                       (ovutils::eBlending) getBlending(layer->blending));
1100
1101        if(configMdp(ctx->mOverlay, pargL, orient,
1102                tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
1103            ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1104            return -1;
1105        }
1106    }
1107
1108    //configure right mixer
1109    if(rDest != OV_INVALID) {
1110        PipeArgs pargR(mdpFlagsR, whf, z, isFg,
1111                static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1112                (ovutils::eBlending) getBlending(layer->blending));
1113
1114        tmp_dstR.right = tmp_dstR.right - lSplit;
1115        tmp_dstR.left = tmp_dstR.left - lSplit;
1116        if(configMdp(ctx->mOverlay, pargR, orient,
1117                tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
1118            ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1119            return -1;
1120        }
1121    }
1122
1123    return 0;
1124}
1125
1126bool canUseRotator(hwc_context_t *ctx) {
1127    if(qdutils::MDPVersion::getInstance().is8x26() &&
1128            ctx->mExtDisplay->isExternalConnected()) {
1129        return false;
1130    }
1131    if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1132        return false;
1133    return true;
1134}
1135
1136int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
1137    //Default even split for all displays with high res
1138    int lSplit = ctx->dpyAttr[dpy].xres / 2;
1139    if(dpy == HWC_DISPLAY_PRIMARY &&
1140            qdutils::MDPVersion::getInstance().getLeftSplit()) {
1141        //Override if split published by driver for primary
1142        lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1143    }
1144    return lSplit;
1145}
1146
1147void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
1148            const hwc_rect_t& dst, const int& transform,
1149            ovutils::eMdpFlags& mdpFlags) {
1150    //Target doesnt support Bwc
1151    if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
1152        return;
1153    }
1154    //src width > MAX mixer supported dim
1155    if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1156        return;
1157    }
1158    //External connected
1159    if(ctx->mExtDisplay->isExternalConnected()) {
1160        return;
1161    }
1162    //Decimation necessary, cannot use BWC. H/W requirement.
1163    if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
1164        int src_w = crop.right - crop.left;
1165        int src_h = crop.bottom - crop.top;
1166        int dst_w = dst.right - dst.left;
1167        int dst_h = dst.bottom - dst.top;
1168        if(transform & HAL_TRANSFORM_ROT_90) {
1169            swap(src_w, src_h);
1170        }
1171        float horDscale = 0.0f;
1172        float verDscale = 0.0f;
1173        int horzDeci = 0;
1174        int vertDeci = 0;
1175        ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
1176                verDscale);
1177        //TODO Use log2f once math.h has it
1178        if((int)horDscale)
1179            horzDeci = (int)(log(horDscale) / log(2));
1180        if((int)verDscale)
1181            vertDeci = (int)(log(verDscale) / log(2));
1182        if(horzDeci || vertDeci) return;
1183    }
1184    //Property
1185    char value[PROPERTY_VALUE_MAX];
1186    property_get("debug.disable.bwc", value, "0");
1187     if(atoi(value)) return;
1188
1189    ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
1190}
1191
1192void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
1193    if(mCount >= MAX_SESS) return;
1194    mLayer[mCount] = layer;
1195    mRot[mCount] = rot;
1196    mCount++;
1197}
1198
1199void LayerRotMap::reset() {
1200    for (int i = 0; i < MAX_SESS; i++) {
1201        mLayer[i] = 0;
1202        mRot[i] = 0;
1203    }
1204    mCount = 0;
1205}
1206
1207void LayerRotMap::setReleaseFd(const int& fence) {
1208    for(uint32_t i = 0; i < mCount; i++) {
1209        mRot[i]->setReleaseFd(dup(fence));
1210    }
1211}
1212
1213};//namespace qhwc
1214