hwc_fbupdate.cpp revision a0e87cbc523323604e8fb7cb5526f410a1ed26df
1ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed/*
2ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * Copyright (C) 2010 The Android Open Source Project
3bbee5b1c3475b630caa5061fbf535f87f21743f7Saurabh Shah * Copyright (C) 2012, The Linux Foundation. All rights reserved.
4ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed *
5ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * Not a Contribution, Apache license notifications and license are
6ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * retained for attribution purposes only.
7ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed *
8ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * Licensed under the Apache License, Version 2.0 (the "License");
9ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * you may not use this file except in compliance with the License.
10ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * You may obtain a copy of the License at
11ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed *
12ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed *      http://www.apache.org/licenses/LICENSE-2.0
13ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed *
14ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * Unless required by applicable law or agreed to in writing, software
15ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * distributed under the License is distributed on an "AS IS" BASIS,
16ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * See the License for the specific language governing permissions and
18ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed * limitations under the License.
19ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed */
20ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
21640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah#define DEBUG_FBUPDATE 0
223b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R#include <cutils/properties.h>
231589dee5c27293d278d3e549af8a4bda27e080f8Naseer Ahmed#include <gralloc_priv.h>
243b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R#include <overlayRotator.h>
2547377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed#include "hwc_fbupdate.h"
268fe8c938d27e528fcf7fb4a408711b4b6e405f13Saurabh Shah#include "mdp_version.h"
273b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R#include "external.h"
288fe8c938d27e528fcf7fb4a408711b4b6e405f13Saurabh Shah
298fe8c938d27e528fcf7fb4a408711b4b6e405f13Saurabh Shahusing namespace qdutils;
30ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
313b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.Rusing overlay::Rotator;
323b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R
33ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmednamespace qhwc {
34ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
3547377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmednamespace ovutils = overlay::utils;
36ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
37640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh ShahIFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) {
38640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if(width > MAX_DISPLAY_DIM) {
39640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        return new FBUpdateHighRes(dpy);
40640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    }
41640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    return new FBUpdateLowRes(dpy);
42640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah}
43640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
44640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shahinline void IFBUpdate::reset() {
45640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    mModeOn = false;
463b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    mRot = NULL;
47640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah}
48640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
49640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah//================= Low res====================================
50640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh ShahFBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
5147377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed
52640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shahinline void FBUpdateLowRes::reset() {
53640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    IFBUpdate::reset();
54640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    mDest = ovutils::OV_INVALID;
55bbee5b1c3475b630caa5061fbf535f87f21743f7Saurabh Shah}
56ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
57f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaranbool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
58f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                             int fbZorder) {
59b3c6e058ce1dbc689f27e7d7acbf1529d37307d8Naseer Ahmed    if(!ctx->mMDP.hasOverlay) {
60640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
61f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                 __FUNCTION__);
62f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        return false;
63080cfcaf2e972513fc09a0207d034ef5dcc975d8Naseer Ahmed    }
64f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran    mModeOn = configure(ctx, list, fbZorder);
65640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    return mModeOn;
66ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed}
67ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
68ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed// Configure
69f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaranbool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
70f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                               int fbZorder) {
7147377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed    bool ret = false;
7204a2afbd65e9f8bc580a637bf44bfc4e627edce0Naseer Ahmed    hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
7347377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed    if (LIKELY(ctx->mOverlay)) {
74eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
75eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        // ext only layer present..
76eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        if(extOnlyLayerIndex != -1) {
77eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R            layer = &list->hwLayers[extOnlyLayerIndex];
78eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R            layer->compositionType = HWC_OVERLAY;
79eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        }
8047377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed        overlay::Overlay& ov = *(ctx->mOverlay);
8176443245d153635b512539fbc68fdf7a904fdf6fSaurabh Shah        private_handle_t *hnd = (private_handle_t *)layer->handle;
82327b2ba85538669304a50d0fb6cc2f6aab7aaf3bSaurabh Shah        ovutils::Whf info(hnd->width, hnd->height,
83f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                          ovutils::getMdpFormat(hnd->format), hnd->size);
8447377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed
8547377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed        //Request an RGB pipe
86f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
8747377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed        if(dest == ovutils::OV_INVALID) { //None available
88af5f82d1c39754b14e9fc91eedc0d0429020c049Saurabh Shah            ALOGE("%s: No pipes available to configure fb for dpy %d",
89af5f82d1c39754b14e9fc91eedc0d0429020c049Saurabh Shah                __FUNCTION__, mDpy);
9047377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed            return false;
9147377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed        }
9247377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed
93640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        mDest = dest;
9476443245d153635b512539fbc68fdf7a904fdf6fSaurabh Shah
95f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
963b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        ovutils::eIsFg isFg = ovutils::IS_FG_OFF;
97f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
98ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
99eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        hwc_rect_t sourceCrop = layer->sourceCrop;
100eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        hwc_rect_t displayFrame = layer->displayFrame;
10176443245d153635b512539fbc68fdf7a904fdf6fSaurabh Shah        int transform = layer->transform;
1023b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        int fbWidth  = ctx->dpyAttr[mDpy].xres;
1033b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        int fbHeight = ctx->dpyAttr[mDpy].yres;
1043b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        int rotFlags = ovutils::ROT_FLAGS_NONE;
1053b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R
10676443245d153635b512539fbc68fdf7a904fdf6fSaurabh Shah        ovutils::eTransform orient =
1073b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                    static_cast<ovutils::eTransform>(transform);
1083b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        if(mDpy && ctx->mExtOrientation) {
1093b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            // If there is a external orientation set, use that
1103b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            transform = ctx->mExtOrientation;
1113b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            orient = static_cast<ovutils::eTransform >(ctx->mExtOrientation);
1123b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        }
113ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
114a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        // Do not use getNonWormholeRegion() function to calculate the
115a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        // sourceCrop during animation on external display and
1163b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        // Dont do wormhole calculation when extorientation is set on External
117a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
118a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan            sourceCrop = layer->displayFrame;
119a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan            displayFrame = sourceCrop;
120a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        } else if((!mDpy || (mDpy && !ctx->mExtOrientation))
1213b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                               && extOnlyLayerIndex == -1) {
1223b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            getNonWormholeRegion(list, sourceCrop);
1233b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            displayFrame = sourceCrop;
1243b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        }
12576443245d153635b512539fbc68fdf7a904fdf6fSaurabh Shah        ovutils::Dim dpos(displayFrame.left,
126f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                          displayFrame.top,
127f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                          displayFrame.right - displayFrame.left,
128f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                          displayFrame.bottom - displayFrame.top);
1290ae34e340382b0b3b767b844305db19e91257eddArun Kumar K.R        // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
1303b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        if(mDpy && !ctx->mExtOrientation)
1310ae34e340382b0b3b767b844305db19e91257eddArun Kumar K.R            getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
1322e449280f98f003bb5831c274fc07ab722ac1a94Saurabh Shah
1333b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        if(mDpy) {
1343b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            getAspectRatioPosition(ctx, mDpy, ctx->mExtOrientation, dpos.x,
1353b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                                    dpos.y, dpos.w, dpos.h);
1363b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            // Convert dim to hwc_rect_t
1373b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            displayFrame.left = dpos.x;
1383b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            displayFrame.top = dpos.y;
1393b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            displayFrame.right = dpos.w + displayFrame.left;
1403b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            displayFrame.bottom = dpos.h + displayFrame.top;
1413b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        }
1423b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        setMdpFlags(layer, mdpFlags, 0);
1433b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        // For External use rotator if there is a rotation value set
1443b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        if(mDpy && (ctx->mExtOrientation & HWC_TRANSFORM_ROT_90)) {
1453b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            mRot = ctx->mRotMgr->getNext();
1463b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            if(mRot == NULL) return -1;
1473b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            //Configure rotator for pre-rotation
1483b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
1493b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                ALOGE("%s: configRotator Failed!", __FUNCTION__);
1503b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                mRot = NULL;
1513b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                return -1;
1523b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            }
1533b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            info.format = (mRot)->getDstFormat();
1543b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            updateSource(orient, info, sourceCrop);
1553b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            rotFlags |= ovutils::ROT_PREROTATED;
1563b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        }
1573b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        //For the mdp, since either we are pre-rotating or MDP does flips
1583b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        orient = ovutils::OVERLAY_TRANSFORM_0;
1593b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        transform = 0;
1603b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        ovutils::PipeArgs parg(mdpFlags, info, zOrder, isFg,
1613b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                                static_cast<ovutils::eRotFlags>(rotFlags));
16247377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed        ret = true;
1633b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
1643b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R                    NULL, mDest) < 0) {
1653b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            ALOGE("%s: ConfigMdp failed for low res", __FUNCTION__);
16647377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed            ret = false;
167ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed        }
168ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed    }
16947377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed    return ret;
170ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed}
171ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
17204a2afbd65e9f8bc580a637bf44bfc4e627edce0Naseer Ahmedbool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
173ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed{
174640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if(!mModeOn) {
175ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed        return true;
176ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed    }
177ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed    bool ret = true;
17847377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed    overlay::Overlay& ov = *(ctx->mOverlay);
179640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    ovutils::eDest dest = mDest;
1803b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    int fd = hnd->fd;
1813b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    uint32_t offset = hnd->offset;
1823b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    if(mRot) {
1833b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        if(!mRot->queueBuffer(fd, offset))
1843b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R            return false;
1853b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        fd = mRot->getDstMemId();
1863b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R        offset = mRot->getDstOffset();
1873b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    }
1883b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    if (!ov.queueBuffer(fd, offset, dest)) {
1899513fc6f6c9a7eb26a57838c6bbe95ecd29a7ca5Amara Venkata Mastan Manoj Kumar        ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
19047377987cc4eef72ee3b0cdced8c3a15038b39ebNaseer Ahmed        ret = false;
191ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed    }
192ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed    return ret;
193ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed}
194ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed
195640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah//================= High res====================================
196640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh ShahFBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
197640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
198640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shahinline void FBUpdateHighRes::reset() {
199640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    IFBUpdate::reset();
200640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    mDestLeft = ovutils::OV_INVALID;
201640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    mDestRight = ovutils::OV_INVALID;
2023b9570a337a3115ad05dee3c1aa2ecc6f82f6ab1Arun Kumar K.R    mRot = NULL;
203640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah}
204640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
205f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaranbool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
206f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                              int fbZorder) {
207640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if(!ctx->mMDP.hasOverlay) {
208640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
209f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                 __FUNCTION__);
210f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        return false;
211640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    }
212640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
213f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran    mModeOn = configure(ctx, list, fbZorder);
214640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    return mModeOn;
215640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah}
216640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
217640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah// Configure
21804a2afbd65e9f8bc580a637bf44bfc4e627edce0Naseer Ahmedbool FBUpdateHighRes::configure(hwc_context_t *ctx,
219f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                hwc_display_contents_1 *list, int fbZorder) {
220640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    bool ret = false;
22104a2afbd65e9f8bc580a637bf44bfc4e627edce0Naseer Ahmed    hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
222640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if (LIKELY(ctx->mOverlay)) {
223eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
224eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        // ext only layer present..
225eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        if(extOnlyLayerIndex != -1) {
226eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R            layer = &list->hwLayers[extOnlyLayerIndex];
227eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R            layer->compositionType = HWC_OVERLAY;
228eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        }
229640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        overlay::Overlay& ov = *(ctx->mOverlay);
230640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        private_handle_t *hnd = (private_handle_t *)layer->handle;
231327b2ba85538669304a50d0fb6cc2f6aab7aaf3bSaurabh Shah        ovutils::Whf info(hnd->width, hnd->height,
232f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                          ovutils::getMdpFormat(hnd->format), hnd->size);
233640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
234640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        //Request left RGB pipe
235640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
236640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        if(destL == ovutils::OV_INVALID) { //None available
237af5f82d1c39754b14e9fc91eedc0d0429020c049Saurabh Shah            ALOGE("%s: No pipes available to configure fb for dpy %d's left"
238af5f82d1c39754b14e9fc91eedc0d0429020c049Saurabh Shah                    " mixer", __FUNCTION__, mDpy);
239640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah            return false;
240640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        }
241640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        //Request right RGB pipe
242640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
243640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        if(destR == ovutils::OV_INVALID) { //None available
244af5f82d1c39754b14e9fc91eedc0d0429020c049Saurabh Shah            ALOGE("%s: No pipes available to configure fb for dpy %d's right"
245af5f82d1c39754b14e9fc91eedc0d0429020c049Saurabh Shah                    " mixer", __FUNCTION__, mDpy);
246640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah            return false;
247640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        }
248640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
249640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        mDestLeft = destL;
250640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        mDestRight = destR;
251640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
252f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_BLEND_FG_PREMULT;
2535c937230915bced21130a3e5d129c4f470fd74d3Sravan Kumar D.V.N
254f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran        ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
255640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
256640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::PipeArgs pargL(mdpFlagsL,
257f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                info,
258f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                zOrder,
259f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                ovutils::IS_FG_OFF,
260f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                ovutils::ROT_FLAGS_NONE);
261640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ov.setSource(pargL, destL);
262640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
263640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
264640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
265640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::PipeArgs pargR(mdpFlagsR,
266f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                info,
267f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                zOrder,
268f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                ovutils::IS_FG_OFF,
269f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                                ovutils::ROT_FLAGS_NONE);
270640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ov.setSource(pargR, destR);
271640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
272eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        hwc_rect_t sourceCrop = layer->sourceCrop;
273eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        hwc_rect_t displayFrame = layer->displayFrame;
274a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        // Do not use getNonWormholeRegion() function to calculate the
275a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        // sourceCrop during animation on external display.
276a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
277a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan            sourceCrop = layer->displayFrame;
278a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan            displayFrame = sourceCrop;
279a0e87cbc523323604e8fb7cb5526f410a1ed26dfRamkumar Radhakrishnan        } else if(extOnlyLayerIndex == -1) {
280eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R            getNonWormholeRegion(list, sourceCrop);
281eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R            displayFrame = sourceCrop;
282eb43d2b7b681164a58e3f86bd0b0d88eea6a3591Arun Kumar K.R        }
283640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
284f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                            (sourceCrop.right - sourceCrop.left) / 2,
285f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                            sourceCrop.bottom - sourceCrop.top);
286640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::Dim dcropR(
287f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran            sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
288f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran            sourceCrop.top,
289f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran            (sourceCrop.right - sourceCrop.left) / 2,
290f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran            sourceCrop.bottom - sourceCrop.top);
291640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ov.setCrop(dcropL, destL);
292640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ov.setCrop(dcropR, destR);
293640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
294640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        int transform = layer->transform;
295640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ovutils::eTransform orient =
296f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran            static_cast<ovutils::eTransform>(transform);
297640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ov.setTransform(orient, destL);
298640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ov.setTransform(orient, destR);
299640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
300c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah        const int halfWidth = (displayFrame.right - displayFrame.left) / 2;
301c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah        const int height = displayFrame.bottom - displayFrame.top;
302c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah
303f099baf4315c82a9718e987f20f3de4b91b53311Saurabh Shah        const int halfDpy = ctx->dpyAttr[mDpy].xres / 2;
304f099baf4315c82a9718e987f20f3de4b91b53311Saurabh Shah        ovutils::Dim dposL(halfDpy - halfWidth,
305f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                           displayFrame.top,
306c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah                           halfWidth,
307c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah                           height);
30893f93515d4b36db7ddb56da15563e3ea6e7ce18cArun Kumar K.R        ov.setPosition(dposL, destL);
309c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah
31093f93515d4b36db7ddb56da15563e3ea6e7ce18cArun Kumar K.R        ovutils::Dim dposR(0,
311f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran                           displayFrame.top,
312c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah                           halfWidth,
313c515b0f37640828e8d9c1d9d7fef0d452684fec4Saurabh Shah                           height);
31493f93515d4b36db7ddb56da15563e3ea6e7ce18cArun Kumar K.R        ov.setPosition(dposR, destR);
315640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
316640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ret = true;
317640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        if (!ov.commit(destL)) {
318640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah            ALOGE("%s: commit fails for left", __FUNCTION__);
319640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah            ret = false;
320640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        }
321640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        if (!ov.commit(destR)) {
322640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah            ALOGE("%s: commit fails for right", __FUNCTION__);
323640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah            ret = false;
324640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        }
325640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    }
326640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    return ret;
327640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah}
328640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
32904a2afbd65e9f8bc580a637bf44bfc4e627edce0Naseer Ahmedbool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
330640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah{
331640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if(!mModeOn) {
332640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        return true;
333640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    }
334640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    bool ret = true;
335640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    overlay::Overlay& ov = *(ctx->mOverlay);
336640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    ovutils::eDest destL = mDestLeft;
337640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    ovutils::eDest destR = mDestRight;
338640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
339640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ALOGE("%s: queue failed for left of dpy = %d",
340f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran              __FUNCTION__, mDpy);
341640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ret = false;
342640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    }
343640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
344640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ALOGE("%s: queue failed for right of dpy = %d",
345f9572cdbe3541d85522adea584f925671b375300Jeykumar Sankaran              __FUNCTION__, mDpy);
346640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah        ret = false;
347640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    }
348640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah    return ret;
349640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah}
350640cb9421639c13248aeb30c3496cdfaec6d894cSaurabh Shah
351ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed//---------------------------------------------------------------------
352ccf943e44f9e9d615a6019459625148830039f8dNaseer Ahmed}; //namespace qhwc
353