overlayUtils.h revision 91a6a994e8d799ea2d4c4cbe6ff2e9be76105988
129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
256f610dd235b577725198e9341caae92379fdf23Saurabh Shah* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Redistribution and use in source and binary forms, with or without
529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* modification, are permitted provided that the following conditions are
629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* met:
729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    * Redistributions of source code must retain the above copyright
829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*      notice, this list of conditions and the following disclaimer.
929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    * Redistributions in binary form must reproduce the above
1029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*      copyright notice, this list of conditions and the following
1129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*      disclaimer in the documentation and/or other materials provided
1229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*      with the distribution.
1329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    * Neither the name of Code Aurora Forum, Inc. nor the names of its
1429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*      contributors may be used to endorse or promote products derived
1529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*      from this software without specific prior written permission.
1629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
1729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
1829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
2029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
2129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*/
2929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
3029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#ifndef OVERLAY_UTILS_H
3129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define OVERLAY_UTILS_H
3229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
3329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <cutils/log.h> // ALOGE, etc
3429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <errno.h>
3529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <fcntl.h> // open, O_RDWR, etc
3629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <hardware/hardware.h>
3729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <hardware/gralloc.h> // buffer_handle_t
38f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed#include <linux/msm_mdp.h> // flags
3929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <stdio.h>
4029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <stdlib.h>
4129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <string.h>
4229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <sys/stat.h>
4329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <sys/types.h>
4429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <utils/Log.h>
45f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed#include "gralloc_priv.h" //for interlace
4629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
4729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
4829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Collection of utilities functions/structs/enums etc...
4929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
5029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* */
5129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
5229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// comment that out if you want to remove asserts
5329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// or put it as -D in Android.mk. your choice.
5429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define OVERLAY_HAS_ASSERT
5529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
5629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#ifdef OVERLAY_HAS_ASSERT
5729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
5829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#else
5929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
6029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#endif // OVERLAY_HAS_ASSERT
6129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define DEBUG_OVERLAY 0
6329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define PROFILE_OVERLAY 0
6429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmednamespace overlay {
6629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// fwd
6829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass Overlay;
69e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahclass OvFD;
70e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah
71e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah/* helper function to open by using fbnum */
72e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahbool open(OvFD& fd, uint32_t fbnum, const char* const dev,
73e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    int flags = O_RDWR);
7429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
7529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmednamespace utils {
7629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Whf;
7729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Dim;
7829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
7929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t setBit(uint32_t x, uint32_t mask) {
8029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x | mask);
8129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
8229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
8329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t clrBit(uint32_t x, uint32_t mask) {
8429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x & ~mask);
8529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
8629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
8729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* Utility class to help avoid copying instances by making the copy ctor
8829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* and assignment operator private
8929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
9029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Usage:
91f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed*    class SomeClass : utils::NoCopy {...};
9229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*/
9329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass NoCopy {
9429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprotected:
9529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    NoCopy(){}
9629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ~NoCopy() {}
9729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
9829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    NoCopy(const NoCopy&);
9929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    const NoCopy& operator=(const NoCopy&);
10029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
10129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
10229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
10329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Utility class to query the framebuffer info for primary display
10429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
10529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Usage:
10629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    Outside of functions:
10729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*       utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
10829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    Inside functions:
10929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*       utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
11029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*/
11129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass FrameBufferInfo {
11229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
11329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
11429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* ctor init */
11529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    explicit FrameBufferInfo();
11629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
11729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Gets an instance if one does not already exist */
11829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static FrameBufferInfo* getInstance();
11929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
12029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Gets width of primary framebuffer */
12129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getWidth() const;
12229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
12329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Gets height of primary framebuffer */
12429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getHeight() const;
12529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
12629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Indicates whether true mirroring is supported */
12729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool supportTrueMirroring() const;
12829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
12929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
13029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFBWidth;
13129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFBHeight;
13229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool mBorderFillSupported;
13329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static FrameBufferInfo *sFBInfoInstance;
13429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
13529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
13629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* 3D related utils, defines etc...
13729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * The compound format passed to the overlay is
13829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ABCCC where A is the input 3D format
13929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * B is the output 3D format
14029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
14129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { SHIFT_OUT_3D = 12,
14229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    SHIFT_TOT_3D = 16 };
14329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { INPUT_3D_MASK = 0xFFFF0000,
14429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OUTPUT_3D_MASK = 0x0000FFFF };
14529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { BARRIER_LAND = 1,
14629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    BARRIER_PORT = 2 };
14729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
148cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
149cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani * close all the pipes if it is opened after reboot.
150cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani */
151cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudaniint initOverlay(void);
152cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani
15329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
154f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline uint32_t colorFormat(uint32_t fmt) {
155f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /*TODO enable this block only if format has interlace / 3D info in top bits.
156f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    if(fmt & INTERLACE_MASK) {
157f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
158f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    }
159f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    fmt = fmt & 0xFFF;*/
160f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    return fmt;
161f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}
16229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3DOutput(uint32_t x) {
16329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x & 0xF000) >> SHIFT_OUT_3D; }
16429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
16529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmeduint32_t getColorFormat(uint32_t format);
16629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
16729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool isHDMIConnected ();
16829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool is3DTV();
16929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool isPanel3D();
17029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool usePanel3D();
17129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool send3DInfoPacket (uint32_t fmt);
17229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool enableBarrier (uint32_t orientation);
17329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmeduint32_t getS3DFormat(uint32_t fmt);
174f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
17529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
176f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedbool getPositionS3D(const Whf& whf, Dim& out);
177f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
17829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
179f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedbool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
180f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
18129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class Type>
182f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedvoid swapWidthHeight(Type& width, Type& height);
18329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
18429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Dim {
18529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim () : x(0), y(0),
18629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    w(0), h(0),
18729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    o(0) {}
18829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
18929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        x(_x), y(_y),
19029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(_w), h(_h) {}
19129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
19229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        x(_x), y(_y),
19329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(_w), h(_h),
19429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        o(_o) {}
19529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool check(uint32_t _w, uint32_t _h) const {
19629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return (x+w <= _w && y+h <= _h);
19729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
19829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
19929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
20029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator==(const Dim& d) const {
20129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return d.x == x && d.y == y &&
20229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                d.w == w && d.h == h &&
20329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                d.o == o;
20429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
20529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
20629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator!=(const Dim& d) const {
20729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return !operator==(d);
20829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
20929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
21029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
21129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t x;
21229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t y;
21329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t w;
21429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t h;
21529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t o;
21629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
21729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
21829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// TODO have Whfz
21929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
22029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Whf {
22129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf() : w(0), h(0), format(0), size(0) {}
22229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf(uint32_t wi, uint32_t he, uint32_t f) :
22329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(wi), h(he), format(f), size(0) {}
22429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
22529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(wi), h(he), format(f), size(s) {}
22629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // FIXME not comparing size at the moment
22729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator==(const Whf& whf) const {
22829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return whf.w == w && whf.h == h &&
22929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                whf.format == format;
23029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
23129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator!=(const Whf& whf) const {
23229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return !operator==(whf);
23329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
23429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
23529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t w;
23629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t h;
23729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t format;
23829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t size;
23929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
24029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
24156f610dd235b577725198e9341caae92379fdf23Saurabh Shahclass ActionSafe {
24256f610dd235b577725198e9341caae92379fdf23Saurabh Shahprivate:
24356f610dd235b577725198e9341caae92379fdf23Saurabh Shah    ActionSafe() : mWidth(0.0f), mHeight(0.0f) { };
24456f610dd235b577725198e9341caae92379fdf23Saurabh Shah    float mWidth;
24556f610dd235b577725198e9341caae92379fdf23Saurabh Shah    float mHeight;
24656f610dd235b577725198e9341caae92379fdf23Saurabh Shah    static ActionSafe *sActionSafe;
24756f610dd235b577725198e9341caae92379fdf23Saurabh Shahpublic:
24856f610dd235b577725198e9341caae92379fdf23Saurabh Shah    ~ActionSafe() { };
24956f610dd235b577725198e9341caae92379fdf23Saurabh Shah    static ActionSafe* getInstance() {
25056f610dd235b577725198e9341caae92379fdf23Saurabh Shah        if(!sActionSafe) {
25156f610dd235b577725198e9341caae92379fdf23Saurabh Shah            sActionSafe = new ActionSafe();
25256f610dd235b577725198e9341caae92379fdf23Saurabh Shah        }
25356f610dd235b577725198e9341caae92379fdf23Saurabh Shah        return sActionSafe;
25456f610dd235b577725198e9341caae92379fdf23Saurabh Shah    }
25556f610dd235b577725198e9341caae92379fdf23Saurabh Shah    void setDimension(int w, int h) {
25656f610dd235b577725198e9341caae92379fdf23Saurabh Shah        mWidth = (float)w;
25756f610dd235b577725198e9341caae92379fdf23Saurabh Shah        mHeight = (float)h;
25856f610dd235b577725198e9341caae92379fdf23Saurabh Shah    }
25956f610dd235b577725198e9341caae92379fdf23Saurabh Shah    float getWidth() { return mWidth; }
26056f610dd235b577725198e9341caae92379fdf23Saurabh Shah    float getHeight() { return mHeight; }
26156f610dd235b577725198e9341caae92379fdf23Saurabh Shah};
26256f610dd235b577725198e9341caae92379fdf23Saurabh Shah
26329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { MAX_PATH_LEN = 256 };
26429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
26529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/**
26629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Rotator flags: not to be confused with orientation flags.
26729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Ususally, you want to open the rotator to make sure it is
26829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ready for business.
26929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ROT_FLAG_DISABLED: Rotator would not kick in. (ioctl will emit errors).
27029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ROT_FLAG_ENABLED: and when rotation is needed.
27129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *                   (prim video playback)
27229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *                   (UI mirroring on HDMI w/ 0 degree rotator. - just memcpy)
27329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * In HDMI UI mirroring, rotator is always used.
27429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Even when w/o orienation change on primary,
27529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * we do 0 rotation on HDMI and using rotator buffers.
27629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * That is because we might see tearing otherwise. so
27729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * we use another buffer (rotator).
27829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * When a simple video playback on HDMI, no rotator is being used.(null r).
27929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
28029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eRotFlags {
28129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_FLAG_DISABLED = 0,
28229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_FLAG_ENABLED = 1 // needed in rot
28329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
28429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
28529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* The values for is_fg flag for control alpha and transp
28629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IS_FG_OFF means is_fg = 0
28729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IS_FG_SET means is_fg = 1
28829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed */
28929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eIsFg {
29029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    IS_FG_OFF = 0,
29129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    IS_FG_SET = 1
29229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
29329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
29429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
29529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
29629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * kernel/common/linux/msm_mdp.h
29729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
29829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
29929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eMdpFlags {
30029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_FLAGS_NONE = 0,
30129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_SHARE =  MDP_OV_PIPE_SHARE,
30229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
303f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
304f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
305f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
306799a39759ba03b08cb96ffb4bb7a2359a2959d93Saurabh Shah    OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
30791a6a994e8d799ea2d4c4cbe6ff2e9be76105988Saurabh Shah    OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
30829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
30929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
31029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eZorder {
31129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_0,
31229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_1,
31329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_2,
31429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Z_SYSTEM_ALLOC = 0xFFFF
31529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
31629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
31729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eMdpPipeType {
31829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_RGB,
31929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_VG
32029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
32129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
32229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Max pipes via overlay (VG0, VG1, RGB1)
32329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { MAX_PIPES = 3 };
32429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
32529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* Used to identify destination channels and
32629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * also 3D channels e.g. when in 3D mode with 2
32729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * pipes opened and it is used in get crop/pos 3D
32829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
32929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eDest {
33029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE0 = 1 << 0,
33129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE1 = 1 << 1,
33229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE2 = 1 << 2,
33329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE_ALL  = (OV_PIPE0 | OV_PIPE1 | OV_PIPE2)
33429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
33529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
33629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
33729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eTransform {
33829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* No rot */
339f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_0 = 0x0,
340f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* flip source image horizontally 0x1 */
341f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
342f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* flip source image vertically 0x2 */
343f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
34429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate source image 180 degrees
34529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * It is basically bit-or-ed  H | V == 0x3 */
346f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
347f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees 0x4 */
348f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
349f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees and flip horizontally 0x5 */
350f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
351f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                                      HAL_TRANSFORM_FLIP_H,
352f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees and flip vertically 0x6 */
353f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
354f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                                      HAL_TRANSFORM_FLIP_V,
35529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate source image 270 degrees
35629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * Basically 180 | 90 == 0x7 */
357f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
35829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate invalid like in Transform.h */
359f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_INV = 0x80
36029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
36129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
36229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Used to consolidate pipe params
36329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct PipeArgs {
36429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
36529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        zorder(Z_SYSTEM_ALLOC),
36629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        isFg(IS_FG_OFF),
36729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        rotFlags(ROT_FLAG_DISABLED){
36829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
36929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
370f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    PipeArgs(eMdpFlags f, Whf _whf,
37129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            eZorder z, eIsFg fg, eRotFlags r) :
37229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mdpFlags(f),
37329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        whf(_whf),
37429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        zorder(z),
37529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        isFg(fg),
37629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        rotFlags(r) {
37729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
37829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
379f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    eMdpFlags mdpFlags; // for mdp_overlay flags
38029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf whf;
38129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eZorder zorder; // stage number
38229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eIsFg isFg; // control alpha & transp
38329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eRotFlags rotFlags;
38429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
38529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
38629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eOverlayState{
38729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* No pipes from overlay open */
38829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_CLOSED = 0,
38929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* 2D Video */
39129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_2D_VIDEO_ON_PANEL,
39229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_2D_VIDEO_ON_PANEL_TV,
3932cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed    OV_2D_VIDEO_ON_TV,
39429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* 3D Video on one display (panel or TV) */
39629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_2D_PANEL,
39729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_3D_PANEL,
39829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_3D_TV,
39929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
40029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* 3D Video on two displays (panel and TV) */
40129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_2D_PANEL_2D_TV,
40229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
40329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* UI Mirroring */
40429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_UI_MIRROR,
40529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_2D_TRUE_UI_MIRROR,
406c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah    /* Dual display with video */
407c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah    OV_UI_VIDEO_TV,
40829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
40929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Composition Bypass */
41029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_BYPASS_1_LAYER,
41129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_BYPASS_2_LAYER,
41229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_BYPASS_3_LAYER,
4132cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed
4142cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed    /* External only for dual-disp */
4152cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed    OV_DUAL_DISP,
41629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
41729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
41829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
41929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    f = static_cast<eMdpFlags>(setBit(f, v));
42029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
42129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
42229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
42329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    f = static_cast<eMdpFlags>(clrBit(f, v));
42429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
42529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
42629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// fb 0/1/2
42729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { FB0, FB1, FB2 };
42829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
42929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Panels could be categorized as primary and external
43029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { PRIMARY, EXTERNAL };
43129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
43229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//External Panels could use HDMI or WFD
43329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum {
43429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HDMI = 1,
43529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    WFD = 2
43629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
43729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
438f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed//TODO Make this a part of some appropriate class
43929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic int sExtType = HDMI; //HDMI or WFD
44029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Set by client as HDMI/WFD
441f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedvoid setExtType(const int& type);
44229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Return External panel type set by client.
443f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedint getExtType();
444f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
44529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
44629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Gets the FB number for the external type.
44729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//As of now, HDMI always has fb1, WFD could use fb1 or fb2
44829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Assumes Ext type set by setExtType() from client.
44929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic int getFBForPanel(int panel) { // PRIMARY OR EXTERNAL
45029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(panel) {
45129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case PRIMARY: return FB0;
45229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
45329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case EXTERNAL:
45429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            switch(getExtType()) {
45529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                case HDMI: return FB1;
45629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    break;
45729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                case WFD: return FB2;//Hardcoding fb2 for wfd. Will change.
45829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    break;
45929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            }
46029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
46129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
46229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s: Unrecognized PANEL category %d", __func__, panel);
46329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
46429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
46529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
46629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
46729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
46829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// number of rgb pipes bufs (max)
469f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
47029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// 2 for rgb0/1 double bufs
47129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { RGB_PIPE_NUM_BUFS = 2 };
47229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
47329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct ScreenInfo {
47429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ScreenInfo() : mFBWidth(0),
47529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBHeight(0),
47629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBbpp(0),
47729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBystride(0) {}
47829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump(const char* const s) const;
47929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBWidth;
48029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBHeight;
48129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBbpp;
48229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBystride;
48329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
48429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
48529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getMdpFormat(int format);
48629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getRotOutFmt(uint32_t format);
48729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* flip is upside down and such. V, H flip
48829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * rotation is 90, 180 etc
48929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * It returns MDP related enum/define that match rot+flip*/
49029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getMdpOrient(eTransform rotation);
4919c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shahconst char* getFormatString(int format);
49229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedconst char* getStateString(eOverlayState state);
49329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
49429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
49529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
49629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { HW_OV_MAGNIFICATION_LIMIT = 20,
49729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HW_OV_MINIFICATION_LIMIT  = 8
49829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
49929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
50029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class T>
501f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
50229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
50329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class T> inline void swap ( T& a, T& b )
50429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
50529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    T c(a); a=b; b=c;
50629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
50729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
50829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int alignup(int value, int a) {
50929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //if align = 0, return the value. Else, do alignment.
51029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return a ? ((((value - 1) / a) + 1) * a) : value;
51129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
51229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
51329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FIXME that align should replace the upper one.
51429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int align(int value, int a) {
51529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //if align = 0, return the value. Else, do alignment.
51629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return a ? ((value + (a-1)) & ~(a-1)) : value;
51729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
51829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
51929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eRotOutFmt {
52029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_OUT_FMT_DEFAULT,
52129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_OUT_FMT_Y_CRCB_H2V2
52229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
52329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
52429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int ROT_OUT_FMT> struct RotOutFmt;
52529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
52629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FIXME, taken from gralloc_priv.h. Need to
52729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// put it back as soon as overlay takes place of the old one
52829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* possible formats for 3D content*/
52929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum {
53029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_NO_3D                         = 0x0000,
53129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_SIDE_BY_SIDE_L_R        = 0x10000,
53229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_TOP_BOTTOM              = 0x20000,
53329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_INTERLEAVE              = 0x40000,
53429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_SIDE_BY_SIDE_R_L        = 0x80000,
53529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_SIDE_BY_SIDE           = 0x1000,
53629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_TOP_BOTTOM             = 0x2000,
53729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_INTERLEAVE             = 0x4000,
53829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_MONOSCOPIC             = 0x8000
53929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
54029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
54129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { HAL_3D_OUT_SBS_MASK =
54229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
54329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_TOP_BOT_MASK =
54429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
54529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_INTERL_MASK =
54629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
54729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_MONOS_MASK =
54829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
54929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
55029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
55129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
55229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isYuv(uint32_t format) {
55329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(format){
55429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V1:
55529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2:
55629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2:
557b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        case MDP_Y_CRCB_H1V1:
558b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        case MDP_Y_CRCB_H2V1:
55929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2_TILE:
56029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2_TILE:
561b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        case MDP_Y_CR_CB_H2V2:
562ae1044e0cbab8d26851782e85525ee9e0e6127e6Saurabh Shah        case MDP_Y_CR_CB_GH2V2:
56329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return true;
56429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
56529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return false;
56629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
56729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
56829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
56929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
57029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isRgb(uint32_t format) {
57129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(format) {
57229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGBA_8888:
57329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_BGRA_8888:
57429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGBX_8888:
57529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGB_565:
57629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return true;
57729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
57829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return false;
57929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
58029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
58129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
58229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
58329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isValidDest(eDest dest)
58429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
58529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if ((OV_PIPE0 & dest) ||
58629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            (OV_PIPE1 & dest) ||
58729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            (OV_PIPE2 & dest)) {
58829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return true;
58929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
59029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
59129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
59229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
5939c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shahinline const char* getFormatString(int format){
59429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const formats[] = {
59529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGB_565",
59629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_XRGB_8888",
59729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V2",
598f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H2V2_ADRENO",
59929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_ARGB_8888",
60029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGB_888",
60129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V2",
60229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_YCRYCB_H2V1",
60329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V1",
60429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V1",
605f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CRCB_H1V2",
606f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H1V2",
60729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGBA_8888",
60829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_BGRA_8888",
60929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGBX_8888",
61029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V2_TILE",
61129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V2_TILE",
61229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CR_CB_H2V2",
613f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CR_CB_GH2V2",
61429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CB_CR_H2V2",
615f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CRCB_H1V1",
616f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H1V1",
617f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_YCRCB_H1V1",
618f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_YCBCR_H1V1",
61929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_BGR_565",
620f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_IMGTYPE_LIMIT",
621f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_RGB_BORDERFILL",
62229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_FB_FORMAT",
62329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_IMGTYPE_LIMIT2"
62429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    };
6259c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah    if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
6269c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah        ALOGE("%s wrong fmt %d", __FUNCTION__, format);
6279c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah        return "Unsupported format";
6289c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah    }
62929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return formats[format];
63029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
63129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
63229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline const char* getStateString(eOverlayState state){
63329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (state) {
63429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_CLOSED:
63529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_CLOSED";
63629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_2D_VIDEO_ON_PANEL:
63729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_2D_VIDEO_ON_PANEL";
63829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_2D_VIDEO_ON_PANEL_TV:
63929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_2D_VIDEO_ON_PANEL_TV";
6402cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed        case OV_2D_VIDEO_ON_TV:
6412cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed            return "OV_2D_VIDEO_ON_TV";
64229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_2D_PANEL:
64329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_2D_PANEL";
64429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_3D_PANEL:
64529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_3D_PANEL";
64629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_3D_TV:
64729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_3D_TV";
64829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
64929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_2D_PANEL_2D_TV";
65029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_UI_MIRROR:
65129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_UI_MIRROR";
65229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_2D_TRUE_UI_MIRROR:
65329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_2D_TRUE_UI_MIRROR";
654c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah        case OV_UI_VIDEO_TV:
655c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah            return "OV_UI_VIDEO_TV";
65629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_BYPASS_1_LAYER:
65729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_BYPASS_1_LAYER";
65829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_BYPASS_2_LAYER:
65929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_BYPASS_2_LAYER";
66029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_BYPASS_3_LAYER:
66129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_BYPASS_3_LAYER";
6622cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed        case OV_DUAL_DISP:
6632cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed            return "OV_DUAL_DISP";
66429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
66529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "UNKNOWN_STATE";
66629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
66729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return "BAD_STATE";
66829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
66929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
67029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void Whf::dump() const {
67129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
67229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            w, h, format, size);
67329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
67429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
67529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void Dim::dump() const {
67629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
67729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
67829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
67929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int getMdpOrient(eTransform rotation) {
68029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
681f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    switch(rotation)
68229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
68329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OVERLAY_TRANSFORM_0 : return 0;
684f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_FLIP_V:  return MDP_FLIP_UD;
685f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_FLIP_H:  return MDP_FLIP_LR;
686f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_90:  return MDP_ROT_90;
687a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        //getMdpOrient will switch the flips if the source is 90 rotated.
688a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        //Clients in Android dont factor in 90 rotation while deciding flip.
689f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
690f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                return MDP_ROT_90 | MDP_FLIP_LR;
691a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
692a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah                return MDP_ROT_90 | MDP_FLIP_UD;
693f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
694f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
69529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
696f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed            ALOGE("%s: invalid rotation value (value = 0x%x",
697f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                    __FUNCTION__, rotation);
69829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
69929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
70029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
70129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
70229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int getRotOutFmt(uint32_t format) {
70329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (format) {
70429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2_TILE:
70529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CRCB_H2V2;
70629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2_TILE:
70729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CBCR_H2V2;
70829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CB_CR_H2V2:
70929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CBCR_H2V2;
710ae1044e0cbab8d26851782e85525ee9e0e6127e6Saurabh Shah        case MDP_Y_CR_CB_GH2V2:
711ae1044e0cbab8d26851782e85525ee9e0e6127e6Saurabh Shah            return MDP_Y_CRCB_H2V2;
71229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
71329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return format;
71429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
71529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // not reached
71629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OVASSERT(false, "%s not reached", __FUNCTION__);
71729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
71829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
71929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
72029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
72129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t getColorFormat(uint32_t format)
72229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
723f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    return (format == HAL_PIXEL_FORMAT_YV12) ?
724f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed            format : colorFormat(format);
72529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
72629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
72729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FB0
72829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
72929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getPositionS3DImpl(const Whf& whf)
73029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
73129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (whf.format & OUTPUT_3D_MASK)
73229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
73329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_SBS_MASK:
73429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // x, y, w, h
73529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w/2, whf.h);
73629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_TOP_BOT_MASK:
73729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w, whf.h/2);
73829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_MONOS_MASK:
73929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
74029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_INTERL_MASK:
74129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // FIXME error?
74229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
74329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
74429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
74529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
74629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    whf.format);
74729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
74829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
74929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
75029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
75129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <>
75229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getPositionS3DImpl<utils::OV_PIPE1>(const Whf& whf)
75329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
75429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (whf.format & OUTPUT_3D_MASK)
75529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
75629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_SBS_MASK:
75729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(whf.w/2, 0, whf.w/2, whf.h);
75829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_TOP_BOT_MASK:
75929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, whf.h/2, whf.w, whf.h/2);
76029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_MONOS_MASK:
76129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w, whf.h);
76229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_INTERL_MASK:
76329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // FIXME error?
76429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
76529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
76629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
76729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
76829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    whf.format);
76929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
77029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
77129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
77229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
77329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
77429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool getPositionS3D(const Whf& whf, Dim& out) {
77529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    out = getPositionS3DImpl<CHAN>(whf);
77629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (out != Dim());
77729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
77829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
77929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
78029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
78129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (fmt & INPUT_3D_MASK)
78229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
78329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_L_R:
78429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w/2, in.h);
78529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_R_L:
78629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(in.w/2, 0, in.w/2, in.h);
78729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_TOP_BOTTOM:
78829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w, in.h/2);
78929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_INTERLEAVE:
79029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
79129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
79229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
79329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
79429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
79529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
79629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
79729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
79829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
79929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <>
80029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getCropS3DImpl<utils::OV_PIPE1>(const Dim& in, uint32_t fmt) {
80129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (fmt & INPUT_3D_MASK)
80229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
80329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_L_R:
80429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(in.w/2, 0, in.w/2, in.h);
80529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_R_L:
80629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w/2, in.h);
80729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_TOP_BOTTOM:
80829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, in.h/2, in.w, in.h/2);
80929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_INTERLEAVE:
81029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
81129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
81229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
81329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
81429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
81529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
81629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
81729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
81829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
81929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
82029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
82129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
82229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    out = getCropS3DImpl<CHAN>(in, fmt);
82329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (out != Dim());
82429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
82529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class Type>
82729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid swapWidthHeight(Type& width, Type& height) {
82829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Type tmp = width;
82929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    width = height;
83029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    height = tmp;
83129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
83229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
83329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void ScreenInfo::dump(const char* const s) const {
83429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump %s ScreenInfo w=%d h=%d"
83529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            " bpp=%d stride=%d start/end ==",
83629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
83729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
83829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
839e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahinline bool openDev(OvFD& fd, int fbnum,
840e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    const char* const devpath, int flags) {
841e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    return overlay::open(fd, fbnum, devpath, flags);
842e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah}
843e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah
844b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahtemplate <class T>
845b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahinline void even_ceil(T& value) {
846b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah    if(value & 1)
847b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        value++;
848b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah}
849b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah
850b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahtemplate <class T>
851b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahinline void even_floor(T& value) {
852b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah    if(value & 1)
853b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        value--;
854b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah}
855b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah
85629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed} // namespace utils ends
85729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
85829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------------Class Res stuff (namespace overlay only) -----------
85929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
86029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass Res {
86129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
86229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /dev/graphics/fb%u
863f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    static const char* const fbPath;
86429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /dev/msm_rotator
86529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const rotPath;
86629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/class/graphics/fb1/format_3d
86729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const format3DFile;
86829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/class/graphics/fb1/3d_present
86929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const edid3dInfoFile;
87029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
87129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const barrierFile;
87229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
87329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------------Class OvFD stuff (namespace overlay only) -----------
87629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
87829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Holds one FD
87929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Dtor will NOT close the underlying FD.
88029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* That enables us to copy that object around
88129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* */
88229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass OvFD {
88329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
88429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Ctor */
88529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    explicit OvFD();
88629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
88729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* dtor will NOT close the underlying FD */
88829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ~OvFD();
88929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
89029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Open fd using the path given by dev.
89129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * return false in failure */
89229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool open(const char* const dev,
89329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            int flags = O_RDWR);
89429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
89529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* populate path */
89629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void setPath(const char* const dev);
89729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
89829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Close fd if we have a valid fd. */
89929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool close();
90029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* returns underlying fd.*/
90229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getFD() const;
90329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* returns true if fd is valid */
90529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool valid() const;
90629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* like operator= */
90829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void copy(int fd);
90929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
91029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* dump the state of the instance */
91129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
91229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
91329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* helper enum for determine valid/invalid fd */
91429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    enum { INVAL = -1 };
91529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
91629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* actual os fd */
91729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFD;
91829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
91929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* path, for debugging */
92029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    char mPath[utils::MAX_PATH_LEN];
92129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
92229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
92329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//-------------------Inlines--------------------------
92429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
92529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
92629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
92729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    char dev_name[64] = {0};
92829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    snprintf(dev_name, sizeof(dev_name), dev, fbnum);
92929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return fd.open(dev_name, flags);
93029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
93129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
93229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline OvFD::OvFD() : mFD (INVAL) {
93329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mPath[0] = 0;
93429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
93529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
936f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline OvFD::~OvFD() {
937f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    //no op since copy() can be used to share fd, in 3d cases.
938f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}
93929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
94029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::open(const char* const dev, int flags)
94129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
94229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFD = ::open(dev, flags, 0);
94329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if (mFD < 0) {
94429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        // FIXME errno, strerror in bionic?
94529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        ALOGE("Cant open device %s err=%d", dev, errno);
94629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return false;
94729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
94829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    setPath(dev);
94929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return true;
95029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
95129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
95229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::setPath(const char* const dev)
95329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
95429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
95529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
95629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
95729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::close()
95829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
95929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int ret = 0;
96029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if(valid()) {
96129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        ret = ::close(mFD);
96229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mFD = INVAL;
96329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
96429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (ret == 0);
96529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
96629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
96729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::valid() const
96829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
96929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (mFD != INVAL);
97029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
97129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
97229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int OvFD::getFD() const { return mFD; }
97329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
97429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::copy(int fd) {
97529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFD = fd;
97629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
97729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
97829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::dump() const
97929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
98029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
98129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            mFD, mPath);
98229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
98329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
98429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------- class OvFD stuff ends ---------------------
98529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
98629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed} // overlay
98729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
98829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
98929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#endif // OVERLAY_UTILS_H
990