overlayUtils.h revision e012f7ad3026349c5a6edafbd550cd83655b99d5
129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Copyright (c) 2011-2012, Code Aurora Forum. 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
14829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
149f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline uint32_t colorFormat(uint32_t fmt) {
150f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /*TODO enable this block only if format has interlace / 3D info in top bits.
151f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    if(fmt & INTERLACE_MASK) {
152f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
153f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    }
154f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    fmt = fmt & 0xFFF;*/
155f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    return fmt;
156f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}
15729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3DOutput(uint32_t x) {
15829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x & 0xF000) >> SHIFT_OUT_3D; }
15929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
16029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmeduint32_t getColorFormat(uint32_t format);
16129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
16229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool isHDMIConnected ();
16329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool is3DTV();
16429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool isPanel3D();
16529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool usePanel3D();
16629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool send3DInfoPacket (uint32_t fmt);
16729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool enableBarrier (uint32_t orientation);
16829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmeduint32_t getS3DFormat(uint32_t fmt);
169f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
17029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
171f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedbool getPositionS3D(const Whf& whf, Dim& out);
172f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
17329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
174f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedbool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
175f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
17629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class Type>
177f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedvoid swapWidthHeight(Type& width, Type& height);
17829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
17929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Dim {
18029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim () : x(0), y(0),
18129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    w(0), h(0),
18229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    o(0) {}
18329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
18429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        x(_x), y(_y),
18529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(_w), h(_h) {}
18629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
18729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        x(_x), y(_y),
18829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(_w), h(_h),
18929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        o(_o) {}
19029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool check(uint32_t _w, uint32_t _h) const {
19129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return (x+w <= _w && y+h <= _h);
19229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
19329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
19429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
19529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator==(const Dim& d) const {
19629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return d.x == x && d.y == y &&
19729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                d.w == w && d.h == h &&
19829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                d.o == o;
19929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
20029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
20129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator!=(const Dim& d) const {
20229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return !operator==(d);
20329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
20429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
20529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
20629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t x;
20729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t y;
20829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t w;
20929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t h;
21029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t o;
21129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
21229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
21329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// TODO have Whfz
21429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
21529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Whf {
21629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf() : w(0), h(0), format(0), size(0) {}
21729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf(uint32_t wi, uint32_t he, uint32_t f) :
21829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(wi), h(he), format(f), size(0) {}
21929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
22029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(wi), h(he), format(f), size(s) {}
22129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // FIXME not comparing size at the moment
22229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator==(const Whf& whf) const {
22329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return whf.w == w && whf.h == h &&
22429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                whf.format == format;
22529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
22629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator!=(const Whf& whf) const {
22729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return !operator==(whf);
22829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
22929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
23029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t w;
23129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t h;
23229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t format;
23329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t size;
23429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
23529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
23629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { MAX_PATH_LEN = 256 };
23729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
23829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/**
23929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Rotator flags: not to be confused with orientation flags.
24029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Ususally, you want to open the rotator to make sure it is
24129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ready for business.
24229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ROT_FLAG_DISABLED: Rotator would not kick in. (ioctl will emit errors).
24329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ROT_FLAG_ENABLED: and when rotation is needed.
24429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *                   (prim video playback)
24529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *                   (UI mirroring on HDMI w/ 0 degree rotator. - just memcpy)
24629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * In HDMI UI mirroring, rotator is always used.
24729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Even when w/o orienation change on primary,
24829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * we do 0 rotation on HDMI and using rotator buffers.
24929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * That is because we might see tearing otherwise. so
25029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * we use another buffer (rotator).
25129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * When a simple video playback on HDMI, no rotator is being used.(null r).
25229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
25329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eRotFlags {
25429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_FLAG_DISABLED = 0,
25529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_FLAG_ENABLED = 1 // needed in rot
25629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
25729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
25829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* The values for is_fg flag for control alpha and transp
25929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IS_FG_OFF means is_fg = 0
26029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IS_FG_SET means is_fg = 1
26129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed */
26229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eIsFg {
26329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    IS_FG_OFF = 0,
26429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    IS_FG_SET = 1
26529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
26629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
26729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
26829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
26929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * kernel/common/linux/msm_mdp.h
27029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
27129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
27229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eMdpFlags {
27329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_FLAGS_NONE = 0,
27429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_SHARE =  MDP_OV_PIPE_SHARE,
27529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
276f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
277f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
278f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
27929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
28029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
28129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eZorder {
28229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_0,
28329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_1,
28429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_2,
28529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Z_SYSTEM_ALLOC = 0xFFFF
28629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
28729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
28829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eMdpPipeType {
28929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_RGB,
29029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_VG
29129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
29229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
29329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Max pipes via overlay (VG0, VG1, RGB1)
29429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { MAX_PIPES = 3 };
29529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
29629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* Used to identify destination channels and
29729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * also 3D channels e.g. when in 3D mode with 2
29829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * pipes opened and it is used in get crop/pos 3D
29929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
30029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eDest {
30129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE0 = 1 << 0,
30229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE1 = 1 << 1,
30329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE2 = 1 << 2,
30429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_PIPE_ALL  = (OV_PIPE0 | OV_PIPE1 | OV_PIPE2)
30529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
30629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
30729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
30829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eTransform {
30929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* No rot */
310f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_0 = 0x0,
311f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* flip source image horizontally 0x1 */
312f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
313f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* flip source image vertically 0x2 */
314f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
31529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate source image 180 degrees
31629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * It is basically bit-or-ed  H | V == 0x3 */
317f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
318f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees 0x4 */
319f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
320f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees and flip horizontally 0x5 */
321f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
322f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                                      HAL_TRANSFORM_FLIP_H,
323f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees and flip vertically 0x6 */
324f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
325f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                                      HAL_TRANSFORM_FLIP_V,
32629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate source image 270 degrees
32729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * Basically 180 | 90 == 0x7 */
328f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
32929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate invalid like in Transform.h */
330f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_INV = 0x80
33129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
33229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
33329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Used to consolidate pipe params
33429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct PipeArgs {
33529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
33629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        zorder(Z_SYSTEM_ALLOC),
33729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        isFg(IS_FG_OFF),
33829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        rotFlags(ROT_FLAG_DISABLED){
33929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
34029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
341f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    PipeArgs(eMdpFlags f, Whf _whf,
34229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            eZorder z, eIsFg fg, eRotFlags r) :
34329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mdpFlags(f),
34429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        whf(_whf),
34529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        zorder(z),
34629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        isFg(fg),
34729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        rotFlags(r) {
34829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
34929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
350f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    eMdpFlags mdpFlags; // for mdp_overlay flags
35129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf whf;
35229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eZorder zorder; // stage number
35329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eIsFg isFg; // control alpha & transp
35429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eRotFlags rotFlags;
35529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
35629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
35729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eOverlayState{
35829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* No pipes from overlay open */
35929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_CLOSED = 0,
36029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
36129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* 2D Video */
36229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_2D_VIDEO_ON_PANEL,
36329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_2D_VIDEO_ON_PANEL_TV,
3642cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed    OV_2D_VIDEO_ON_TV,
36529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
36629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* 3D Video on one display (panel or TV) */
36729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_2D_PANEL,
36829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_3D_PANEL,
36929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_3D_TV,
37029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
37129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* 3D Video on two displays (panel and TV) */
37229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_3D_VIDEO_ON_2D_PANEL_2D_TV,
37329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
37429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* UI Mirroring */
37529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_UI_MIRROR,
37629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_2D_TRUE_UI_MIRROR,
37729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
37829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Composition Bypass */
37929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_BYPASS_1_LAYER,
38029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_BYPASS_2_LAYER,
38129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_BYPASS_3_LAYER,
3822cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed
3832cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed    /* External only for dual-disp */
3842cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed    OV_DUAL_DISP,
38529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
38629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
38729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
38829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    f = static_cast<eMdpFlags>(setBit(f, v));
38929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
39029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
39229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    f = static_cast<eMdpFlags>(clrBit(f, v));
39329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
39429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// fb 0/1/2
39629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { FB0, FB1, FB2 };
39729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Panels could be categorized as primary and external
39929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { PRIMARY, EXTERNAL };
40029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
40129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//External Panels could use HDMI or WFD
40229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum {
40329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HDMI = 1,
40429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    WFD = 2
40529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
40629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
407f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed//TODO Make this a part of some appropriate class
40829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic int sExtType = HDMI; //HDMI or WFD
40929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Set by client as HDMI/WFD
410f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedvoid setExtType(const int& type);
41129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Return External panel type set by client.
412f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedint getExtType();
413f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
41429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
41529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Gets the FB number for the external type.
41629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//As of now, HDMI always has fb1, WFD could use fb1 or fb2
41729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Assumes Ext type set by setExtType() from client.
41829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic int getFBForPanel(int panel) { // PRIMARY OR EXTERNAL
41929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(panel) {
42029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case PRIMARY: return FB0;
42129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
42229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case EXTERNAL:
42329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            switch(getExtType()) {
42429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                case HDMI: return FB1;
42529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    break;
42629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                case WFD: return FB2;//Hardcoding fb2 for wfd. Will change.
42729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    break;
42829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            }
42929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
43029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
43129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s: Unrecognized PANEL category %d", __func__, panel);
43229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
43329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
43429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
43529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
43629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
43729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// number of rgb pipes bufs (max)
438f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
43929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// 2 for rgb0/1 double bufs
44029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { RGB_PIPE_NUM_BUFS = 2 };
44129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
44229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct ScreenInfo {
44329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ScreenInfo() : mFBWidth(0),
44429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBHeight(0),
44529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBbpp(0),
44629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBystride(0) {}
44729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump(const char* const s) const;
44829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBWidth;
44929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBHeight;
45029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBbpp;
45129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBystride;
45229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
45329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
45429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getMdpFormat(int format);
45529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getRotOutFmt(uint32_t format);
45629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* flip is upside down and such. V, H flip
45729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * rotation is 90, 180 etc
45829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * It returns MDP related enum/define that match rot+flip*/
45929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getMdpOrient(eTransform rotation);
46029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedconst char* getFormatString(uint32_t format);
46129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedconst char* getStateString(eOverlayState state);
46229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
46329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
46429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
46529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { HW_OV_MAGNIFICATION_LIMIT = 20,
46629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HW_OV_MINIFICATION_LIMIT  = 8
46729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
46829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
46929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class T>
470f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
47129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
47229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class T> inline void swap ( T& a, T& b )
47329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
47429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    T c(a); a=b; b=c;
47529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
47629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
47729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int alignup(int value, int a) {
47829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //if align = 0, return the value. Else, do alignment.
47929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return a ? ((((value - 1) / a) + 1) * a) : value;
48029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
48129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
48229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FIXME that align should replace the upper one.
48329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int align(int value, int a) {
48429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //if align = 0, return the value. Else, do alignment.
48529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return a ? ((value + (a-1)) & ~(a-1)) : value;
48629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
48729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
48829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eRotOutFmt {
48929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_OUT_FMT_DEFAULT,
49029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_OUT_FMT_Y_CRCB_H2V2
49129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
49229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
49329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int ROT_OUT_FMT> struct RotOutFmt;
49429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
49529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FIXME, taken from gralloc_priv.h. Need to
49629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// put it back as soon as overlay takes place of the old one
49729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* possible formats for 3D content*/
49829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum {
49929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_NO_3D                         = 0x0000,
50029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_SIDE_BY_SIDE_L_R        = 0x10000,
50129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_TOP_BOTTOM              = 0x20000,
50229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_INTERLEAVE              = 0x40000,
50329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_SIDE_BY_SIDE_R_L        = 0x80000,
50429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_SIDE_BY_SIDE           = 0x1000,
50529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_TOP_BOTTOM             = 0x2000,
50629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_INTERLEAVE             = 0x4000,
50729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_MONOSCOPIC             = 0x8000
50829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
50929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
51029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { HAL_3D_OUT_SBS_MASK =
51129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
51229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_TOP_BOT_MASK =
51329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
51429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_INTERL_MASK =
51529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
51629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_MONOS_MASK =
51729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
51829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
51929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
52029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
52129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isYuv(uint32_t format) {
52229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(format){
52329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V1:
52429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2:
52529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2:
52629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2_TILE:
52729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2_TILE:
52829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return true;
52929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
53029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return false;
53129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
53229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
53329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
53429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
53529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isRgb(uint32_t format) {
53629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(format) {
53729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGBA_8888:
53829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_BGRA_8888:
53929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGBX_8888:
54029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGB_565:
54129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return true;
54229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
54329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return false;
54429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
54529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
54629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
54729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
54829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isValidDest(eDest dest)
54929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
55029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if ((OV_PIPE0 & dest) ||
55129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            (OV_PIPE1 & dest) ||
55229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            (OV_PIPE2 & dest)) {
55329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return true;
55429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
55529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
55629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
55729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
55829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline const char* getFormatString(uint32_t format){
55929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const formats[] = {
56029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGB_565",
56129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_XRGB_8888",
56229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V2",
563f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H2V2_ADRENO",
56429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_ARGB_8888",
56529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGB_888",
56629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V2",
56729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_YCRYCB_H2V1",
56829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V1",
56929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V1",
570f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CRCB_H1V2",
571f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H1V2",
57229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGBA_8888",
57329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_BGRA_8888",
57429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGBX_8888",
57529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V2_TILE",
57629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V2_TILE",
57729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CR_CB_H2V2",
578f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CR_CB_GH2V2",
57929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CB_CR_H2V2",
580f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CRCB_H1V1",
581f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H1V1",
582f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_YCRCB_H1V1",
583f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_YCBCR_H1V1",
58429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_BGR_565",
585f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_IMGTYPE_LIMIT",
586f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_RGB_BORDERFILL",
58729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_FB_FORMAT",
58829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_IMGTYPE_LIMIT2"
58929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    };
59029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OVASSERT(format < sizeof(formats) / sizeof(formats[0]),
59129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            "getFormatString wrong fmt %d", format);
59229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return formats[format];
59329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
59429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
59529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline const char* getStateString(eOverlayState state){
59629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (state) {
59729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_CLOSED:
59829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_CLOSED";
59929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_2D_VIDEO_ON_PANEL:
60029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_2D_VIDEO_ON_PANEL";
60129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_2D_VIDEO_ON_PANEL_TV:
60229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_2D_VIDEO_ON_PANEL_TV";
6032cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed        case OV_2D_VIDEO_ON_TV:
6042cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed            return "OV_2D_VIDEO_ON_TV";
60529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_2D_PANEL:
60629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_2D_PANEL";
60729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_3D_PANEL:
60829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_3D_PANEL";
60929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_3D_TV:
61029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_3D_TV";
61129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
61229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_3D_VIDEO_ON_2D_PANEL_2D_TV";
61329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_UI_MIRROR:
61429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_UI_MIRROR";
61529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_2D_TRUE_UI_MIRROR:
61629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_2D_TRUE_UI_MIRROR";
61729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_BYPASS_1_LAYER:
61829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_BYPASS_1_LAYER";
61929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_BYPASS_2_LAYER:
62029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_BYPASS_2_LAYER";
62129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OV_BYPASS_3_LAYER:
62229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "OV_BYPASS_3_LAYER";
6232cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed        case OV_DUAL_DISP:
6242cc53dd510a5e1ffaaac8493b1ff65a908df6c13Naseer Ahmed            return "OV_DUAL_DISP";
62529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
62629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return "UNKNOWN_STATE";
62729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
62829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return "BAD_STATE";
62929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
63029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
63129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void Whf::dump() const {
63229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
63329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            w, h, format, size);
63429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
63529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
63629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void Dim::dump() const {
63729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
63829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
63929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
64029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int getMdpOrient(eTransform rotation) {
64129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
642f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    switch(rotation)
64329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
64429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OVERLAY_TRANSFORM_0 : return 0;
645f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_FLIP_V:  return MDP_FLIP_UD;
646f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_FLIP_H:  return MDP_FLIP_LR;
647f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_90:  return MDP_ROT_90;
648a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        //getMdpOrient will switch the flips if the source is 90 rotated.
649a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        //Clients in Android dont factor in 90 rotation while deciding flip.
650f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
651f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                return MDP_ROT_90 | MDP_FLIP_LR;
652a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
653a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah                return MDP_ROT_90 | MDP_FLIP_UD;
654f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
655f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
65629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
657f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed            ALOGE("%s: invalid rotation value (value = 0x%x",
658f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                    __FUNCTION__, rotation);
65929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
66029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
66129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
66229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
66329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int getRotOutFmt(uint32_t format) {
66429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (format) {
66529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2_TILE:
66629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CRCB_H2V2;
66729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2_TILE:
66829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CBCR_H2V2;
66929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CB_CR_H2V2:
67029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CBCR_H2V2;
67129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
67229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return format;
67329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
67429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // not reached
67529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OVASSERT(false, "%s not reached", __FUNCTION__);
67629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
67729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
67829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
67929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
68029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t getColorFormat(uint32_t format)
68129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
682f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    return (format == HAL_PIXEL_FORMAT_YV12) ?
683f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed            format : colorFormat(format);
68429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
68529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
68629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FB0
68729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
68829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getPositionS3DImpl(const Whf& whf)
68929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
69029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (whf.format & OUTPUT_3D_MASK)
69129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
69229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_SBS_MASK:
69329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // x, y, w, h
69429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w/2, whf.h);
69529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_TOP_BOT_MASK:
69629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w, whf.h/2);
69729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_MONOS_MASK:
69829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
69929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_INTERL_MASK:
70029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // FIXME error?
70129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
70229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
70329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
70429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
70529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    whf.format);
70629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
70729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
70829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
70929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
71029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <>
71129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getPositionS3DImpl<utils::OV_PIPE1>(const Whf& whf)
71229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
71329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (whf.format & OUTPUT_3D_MASK)
71429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
71529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_SBS_MASK:
71629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(whf.w/2, 0, whf.w/2, whf.h);
71729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_TOP_BOT_MASK:
71829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, whf.h/2, whf.w, whf.h/2);
71929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_MONOS_MASK:
72029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w, whf.h);
72129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_INTERL_MASK:
72229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // FIXME error?
72329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
72429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
72529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
72629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
72729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    whf.format);
72829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
72929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
73029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
73129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
73229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
73329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool getPositionS3D(const Whf& whf, Dim& out) {
73429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    out = getPositionS3DImpl<CHAN>(whf);
73529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (out != Dim());
73629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
73729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
73829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
73929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
74029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (fmt & INPUT_3D_MASK)
74129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
74229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_L_R:
74329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w/2, in.h);
74429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_R_L:
74529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(in.w/2, 0, in.w/2, in.h);
74629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_TOP_BOTTOM:
74729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w, in.h/2);
74829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_INTERLEAVE:
74929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
75029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
75129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
75229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
75329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
75429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
75529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
75629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
75729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
75829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <>
75929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getCropS3DImpl<utils::OV_PIPE1>(const Dim& in, uint32_t fmt) {
76029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (fmt & INPUT_3D_MASK)
76129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
76229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_L_R:
76329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(in.w/2, 0, in.w/2, in.h);
76429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_R_L:
76529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w/2, in.h);
76629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_TOP_BOTTOM:
76729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, in.h/2, in.w, in.h/2);
76829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_INTERLEAVE:
76929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
77029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
77129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
77229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
77329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
77429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
77529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
77629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
77729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
77829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
77929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
78029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
78129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    out = getCropS3DImpl<CHAN>(in, fmt);
78229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (out != Dim());
78329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
78429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
78529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class Type>
78629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid swapWidthHeight(Type& width, Type& height) {
78729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Type tmp = width;
78829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    width = height;
78929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    height = tmp;
79029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
79129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
79229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void ScreenInfo::dump(const char* const s) const {
79329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump %s ScreenInfo w=%d h=%d"
79429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            " bpp=%d stride=%d start/end ==",
79529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
79629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
79729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
798e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahinline bool openDev(OvFD& fd, int fbnum,
799e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    const char* const devpath, int flags) {
800e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    return overlay::open(fd, fbnum, devpath, flags);
801e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah}
802e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah
80329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed} // namespace utils ends
80429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
80529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------------Class Res stuff (namespace overlay only) -----------
80629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
80729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass Res {
80829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
80929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /dev/graphics/fb%u
810f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    static const char* const fbPath;
81129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /dev/msm_rotator
81229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const rotPath;
81329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/class/graphics/fb1/format_3d
81429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const format3DFile;
81529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/class/graphics/fb1/3d_present
81629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const edid3dInfoFile;
81729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
81829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const barrierFile;
81929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
82029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------------Class OvFD stuff (namespace overlay only) -----------
82329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
82529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Holds one FD
82629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Dtor will NOT close the underlying FD.
82729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* That enables us to copy that object around
82829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* */
82929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass OvFD {
83029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
83129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Ctor */
83229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    explicit OvFD();
83329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
83429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* dtor will NOT close the underlying FD */
83529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ~OvFD();
83629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
83729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Open fd using the path given by dev.
83829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * return false in failure */
83929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool open(const char* const dev,
84029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            int flags = O_RDWR);
84129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
84229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* populate path */
84329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void setPath(const char* const dev);
84429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
84529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Close fd if we have a valid fd. */
84629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool close();
84729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
84829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* returns underlying fd.*/
84929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getFD() const;
85029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
85129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* returns true if fd is valid */
85229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool valid() const;
85329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
85429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* like operator= */
85529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void copy(int fd);
85629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
85729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* dump the state of the instance */
85829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
85929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
86029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* helper enum for determine valid/invalid fd */
86129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    enum { INVAL = -1 };
86229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
86329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* actual os fd */
86429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFD;
86529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
86629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* path, for debugging */
86729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    char mPath[utils::MAX_PATH_LEN];
86829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
86929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//-------------------Inlines--------------------------
87129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
87329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
87429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    char dev_name[64] = {0};
87529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    snprintf(dev_name, sizeof(dev_name), dev, fbnum);
87629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return fd.open(dev_name, flags);
87729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
87829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline OvFD::OvFD() : mFD (INVAL) {
88029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mPath[0] = 0;
88129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
88229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
883f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline OvFD::~OvFD() {
884f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    //no op since copy() can be used to share fd, in 3d cases.
885f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}
88629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
88729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::open(const char* const dev, int flags)
88829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
88929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFD = ::open(dev, flags, 0);
89029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if (mFD < 0) {
89129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        // FIXME errno, strerror in bionic?
89229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        ALOGE("Cant open device %s err=%d", dev, errno);
89329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return false;
89429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
89529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    setPath(dev);
89629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return true;
89729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
89829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
89929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::setPath(const char* const dev)
90029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
90129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
90229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
90329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::close()
90529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
90629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int ret = 0;
90729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if(valid()) {
90829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        ret = ::close(mFD);
90929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mFD = INVAL;
91029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
91129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (ret == 0);
91229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
91329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
91429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::valid() const
91529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
91629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (mFD != INVAL);
91729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
91829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
91929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int OvFD::getFD() const { return mFD; }
92029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
92129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::copy(int fd) {
92229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFD = fd;
92329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
92429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
92529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::dump() const
92629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
92729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
92829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            mFD, mPath);
92929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
93029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
93129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------- class OvFD stuff ends ---------------------
93229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
93329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed} // overlay
93429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
93529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
93629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#endif // OVERLAY_UTILS_H
937