overlayUtils.h revision a43fb8fce6d9be5577de1e0f49c99bd4fe2f6d44
129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
2580dfd3c4aa61ffe48dc24dd4168ec8c2eb1cd43Sushil Chauhan* Copyright (c) 2011-2013, 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.
13a43fb8fce6d9be5577de1e0f49c99bd4fe2f6d44Duy Truong*    * Neither the name of The Linux Foundation 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
46d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed
47580dfd3c4aa61ffe48dc24dd4168ec8c2eb1cd43Sushil Chauhan// Older platforms do not support Venus.
48580dfd3c4aa61ffe48dc24dd4168ec8c2eb1cd43Sushil Chauhan#ifndef VENUS_COLOR_FORMAT
49d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
50d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan#endif
51d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan
5229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
5329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
5429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Collection of utilities functions/structs/enums etc...
5529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
5629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* */
5729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
5829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// comment that out if you want to remove asserts
5929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// or put it as -D in Android.mk. your choice.
6029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define OVERLAY_HAS_ASSERT
6129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#ifdef OVERLAY_HAS_ASSERT
6329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
6429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#else
6529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
6629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#endif // OVERLAY_HAS_ASSERT
6729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define DEBUG_OVERLAY 0
6929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define PROFILE_OVERLAY 0
7029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
716457316fc7ae8ea29d763edce3fc1ffc78dd7387Saurabh Shah#ifndef MDSS_MDP_RIGHT_MIXER
726457316fc7ae8ea29d763edce3fc1ffc78dd7387Saurabh Shah#define MDSS_MDP_RIGHT_MIXER 0x100
736457316fc7ae8ea29d763edce3fc1ffc78dd7387Saurabh Shah#endif
746457316fc7ae8ea29d763edce3fc1ffc78dd7387Saurabh Shah
7529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmednamespace overlay {
7629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
7729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// fwd
7829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass Overlay;
79e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahclass OvFD;
80e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah
81e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah/* helper function to open by using fbnum */
82e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahbool open(OvFD& fd, uint32_t fbnum, const char* const dev,
83e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    int flags = O_RDWR);
8429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
8529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmednamespace utils {
8629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Whf;
8729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Dim;
8829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
8929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t setBit(uint32_t x, uint32_t mask) {
9029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x | mask);
9129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
9229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
9329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t clrBit(uint32_t x, uint32_t mask) {
9429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x & ~mask);
9529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
9629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
9729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* Utility class to help avoid copying instances by making the copy ctor
9829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* and assignment operator private
9929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
10029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Usage:
101f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed*    class SomeClass : utils::NoCopy {...};
10229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*/
10329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass NoCopy {
10429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprotected:
10529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    NoCopy(){}
10629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ~NoCopy() {}
10729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
10829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    NoCopy(const NoCopy&);
10929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    const NoCopy& operator=(const NoCopy&);
11029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
11129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
11229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
11329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Utility class to query the framebuffer info for primary display
11429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*
11529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Usage:
11629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    Outside of functions:
11729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*       utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
11829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*    Inside functions:
11929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*       utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
12029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed*/
12129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass FrameBufferInfo {
12229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
12329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
12429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* ctor init */
12529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    explicit FrameBufferInfo();
12629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
12729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Gets an instance if one does not already exist */
12829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static FrameBufferInfo* getInstance();
12929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
13029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Gets width of primary framebuffer */
13129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getWidth() const;
13229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
13329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Gets height of primary framebuffer */
13429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getHeight() const;
13529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
13629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
13729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFBWidth;
13829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFBHeight;
13929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool mBorderFillSupported;
14029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static FrameBufferInfo *sFBInfoInstance;
14129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
14229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
14329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* 3D related utils, defines etc...
14429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * The compound format passed to the overlay is
14529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ABCCC where A is the input 3D format
14629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * B is the output 3D format
14729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
14829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { SHIFT_OUT_3D = 12,
14929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    SHIFT_TOT_3D = 16 };
15029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { INPUT_3D_MASK = 0xFFFF0000,
15129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OUTPUT_3D_MASK = 0x0000FFFF };
15229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { BARRIER_LAND = 1,
15329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    BARRIER_PORT = 2 };
15429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
155cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
156cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani * close all the pipes if it is opened after reboot.
157cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani */
158cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudaniint initOverlay(void);
159cb3da0a5e4313f55bd27514006c3ce64293ff8a2Ajay Dudani
16029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
161f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline uint32_t colorFormat(uint32_t fmt) {
162f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /*TODO enable this block only if format has interlace / 3D info in top bits.
163f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    if(fmt & INTERLACE_MASK) {
164f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
165f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    }
166f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    fmt = fmt & 0xFFF;*/
167f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    return fmt;
168f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}
16929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3DOutput(uint32_t x) {
17029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (x & 0xF000) >> SHIFT_OUT_3D; }
17129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
17229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmeduint32_t getColorFormat(uint32_t format);
17329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
17429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool isHDMIConnected ();
17529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool is3DTV();
17629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool isPanel3D();
17729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool usePanel3D();
17829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool send3DInfoPacket (uint32_t fmt);
17929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedbool enableBarrier (uint32_t orientation);
18029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmeduint32_t getS3DFormat(uint32_t fmt);
181f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
18229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
183f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedbool getPositionS3D(const Whf& whf, Dim& out);
184f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
18529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
186f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedbool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
187f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed
18829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class Type>
189f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedvoid swapWidthHeight(Type& width, Type& height);
19029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
19129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Dim {
19229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim () : x(0), y(0),
19329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    w(0), h(0),
19429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    o(0) {}
19529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
19629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        x(_x), y(_y),
19729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(_w), h(_h) {}
19829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
19929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        x(_x), y(_y),
20029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(_w), h(_h),
20129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        o(_o) {}
20229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool check(uint32_t _w, uint32_t _h) const {
20329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return (x+w <= _w && y+h <= _h);
20429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
20529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
20629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
20729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator==(const Dim& d) const {
20829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return d.x == x && d.y == y &&
20929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                d.w == w && d.h == h &&
21029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                d.o == o;
21129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
21229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
21329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator!=(const Dim& d) const {
21429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return !operator==(d);
21529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
21629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
21729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
21829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t x;
21929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t y;
22029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t w;
22129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t h;
22229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t o;
22329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
22429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
22529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// TODO have Whfz
22629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
22729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct Whf {
22829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf() : w(0), h(0), format(0), size(0) {}
22929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf(uint32_t wi, uint32_t he, uint32_t f) :
23029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(wi), h(he), format(f), size(0) {}
23129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
23229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        w(wi), h(he), format(f), size(s) {}
23329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // FIXME not comparing size at the moment
23429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator==(const Whf& whf) const {
23529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return whf.w == w && whf.h == h &&
23629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                whf.format == format;
23729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
23829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool operator!=(const Whf& whf) const {
23929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return !operator==(whf);
24029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
24129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
24229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t w;
24329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t h;
24429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t format;
24529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t size;
24629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
24729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
24829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { MAX_PATH_LEN = 256 };
24929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
25029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/**
25129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Rotator flags: not to be confused with orientation flags.
25229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Ususally, you want to open the rotator to make sure it is
25329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ready for business.
254d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed * ROT_FLAG_DISABLED: Rotator not used unless required.
255d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed * ROT_FLAG_ENABLED: Rotator used even if not required.
25629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
257d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan enum eRotFlags {
258d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_FLAGS_NONE = 0,
259d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    //Use rotator for 0 rotation. It is used anyway for others.
260d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_0_ENABLED = 1 << 0,
261d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    //Enable rotator downscale optimization for hardware bugs not handled in
262d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    //driver. If downscale optimizatation is required,
263d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    //then rotator will be used even if its 0 rotation case.
264d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_DOWNSCALE_ENABLED = 1 << 1,
265d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan};
266d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan
267d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnanenum eRotDownscale {
268d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_DS_NONE = 0,
269d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_DS_HALF = 1,
270d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_DS_FOURTH = 2,
271d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    ROT_DS_EIGHTH = 3,
27229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
27329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
27429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* The values for is_fg flag for control alpha and transp
27529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IS_FG_OFF means is_fg = 0
27629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IS_FG_SET means is_fg = 1
27729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed */
27829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eIsFg {
27929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    IS_FG_OFF = 0,
28029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    IS_FG_SET = 1
28129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
28229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
28329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
28429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
28529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * kernel/common/linux/msm_mdp.h
28629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
28729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * */
28829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eMdpFlags {
28929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_FLAGS_NONE = 0,
29029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_SHARE =  MDP_OV_PIPE_SHARE,
29129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
292f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
293f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
294f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
295799a39759ba03b08cb96ffb4bb7a2359a2959d93Saurabh Shah    OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
29691a6a994e8d799ea2d4c4cbe6ff2e9be76105988Saurabh Shah    OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
297e87b66d295a83b90e22bf4b7c48051eaea01ef75Saurabh Shah    OV_MDP_FLIP_H = MDP_FLIP_LR,
298e87b66d295a83b90e22bf4b7c48051eaea01ef75Saurabh Shah    OV_MDP_FLIP_V = MDP_FLIP_UD,
2996457316fc7ae8ea29d763edce3fc1ffc78dd7387Saurabh Shah    OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
30029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
30129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
30229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eZorder {
30329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_0,
30429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_1,
30529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ZORDER_2,
306d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    ZORDER_3,
30729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Z_SYSTEM_ALLOC = 0xFFFF
30829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
30929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
31029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eMdpPipeType {
31129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OV_MDP_PIPE_RGB,
312d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_MDP_PIPE_VG,
313d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_MDP_PIPE_ANY, //Any
31429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
31529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
316d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed/* Used to identify destination pipes
317d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed */
31829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eDest {
319d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_VG0 = 0,
320d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_RGB0,
321d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_VG1,
322d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_RGB1,
323d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_VG2,
324d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_RGB2,
325d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_INVALID,
326d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed};
327d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed
328d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed/* Used when a buffer is split over 2 pipes and sent to display */
329d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmedenum {
330d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_LEFT_SPLIT = 0,
331d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    OV_RIGHT_SPLIT,
33229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
33329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
33429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
33529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eTransform {
33629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* No rot */
337f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_0 = 0x0,
338f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* flip source image horizontally 0x1 */
339f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
340f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* flip source image vertically 0x2 */
341f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
34229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate source image 180 degrees
34329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * It is basically bit-or-ed  H | V == 0x3 */
344f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
345f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees 0x4 */
346f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
347f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees and flip horizontally 0x5 */
348f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
349f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                                      HAL_TRANSFORM_FLIP_H,
350f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    /* rotate source image 90 degrees and flip vertically 0x6 */
351f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
352f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                                      HAL_TRANSFORM_FLIP_V,
35329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate source image 270 degrees
35429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * Basically 180 | 90 == 0x7 */
355f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
35629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* rotate invalid like in Transform.h */
357f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    OVERLAY_TRANSFORM_INV = 0x80
35829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
35929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
36029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Used to consolidate pipe params
36129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct PipeArgs {
36229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
36329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        zorder(Z_SYSTEM_ALLOC),
36429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        isFg(IS_FG_OFF),
365d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan        rotFlags(ROT_FLAGS_NONE){
36629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
36729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
368f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    PipeArgs(eMdpFlags f, Whf _whf,
36929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            eZorder z, eIsFg fg, eRotFlags r) :
37029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mdpFlags(f),
37129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        whf(_whf),
37229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        zorder(z),
37329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        isFg(fg),
37429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        rotFlags(r) {
37529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
37629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
377f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    eMdpFlags mdpFlags; // for mdp_overlay flags
37829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Whf whf;
37929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eZorder zorder; // stage number
38029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eIsFg isFg; // control alpha & transp
38129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    eRotFlags rotFlags;
38229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
38329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
38429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
38529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    f = static_cast<eMdpFlags>(setBit(f, v));
38629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
38729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
38829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
38929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    f = static_cast<eMdpFlags>(clrBit(f, v));
39029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
39129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// fb 0/1/2
39329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { FB0, FB1, FB2 };
39429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Panels could be categorized as primary and external
39629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { PRIMARY, EXTERNAL };
39729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// 2 for rgb0/1 double bufs
39929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { RGB_PIPE_NUM_BUFS = 2 };
40029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
40129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct ScreenInfo {
40229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ScreenInfo() : mFBWidth(0),
40329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBHeight(0),
40429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBbpp(0),
40529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFBystride(0) {}
40629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump(const char* const s) const;
40729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBWidth;
40829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBHeight;
40929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBbpp;
41029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    uint32_t mFBystride;
41129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
41229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
41329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getMdpFormat(int format);
41429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getRotOutFmt(uint32_t format);
41529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* flip is upside down and such. V, H flip
41629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * rotation is 90, 180 etc
41729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * It returns MDP related enum/define that match rot+flip*/
41829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedint getMdpOrient(eTransform rotation);
4199c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shahconst char* getFormatString(int format);
42029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
42129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
42229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
42329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { HW_OV_MAGNIFICATION_LIMIT = 20,
42429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HW_OV_MINIFICATION_LIMIT  = 8
42529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
42629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
42729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class T>
428f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
42929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
43029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class T> inline void swap ( T& a, T& b )
43129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
43229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    T c(a); a=b; b=c;
43329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
43429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
43529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int alignup(int value, int a) {
43629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //if align = 0, return the value. Else, do alignment.
43729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return a ? ((((value - 1) / a) + 1) * a) : value;
43829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
43929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
440d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnaninline int aligndown(int value, int a) {
441d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    //if align = 0, return the value. Else, do alignment.
442d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan    return a ? ((value) & ~(a-1)) : value;
443d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan}
444d82ce1da8ebdba46e6d0119fac1aa8d4b9b033b7Ramkumar Radhakrishnan
44529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FIXME that align should replace the upper one.
44629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int align(int value, int a) {
44729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //if align = 0, return the value. Else, do alignment.
44829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return a ? ((value + (a-1)) & ~(a-1)) : value;
44929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
45029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
45129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum eRotOutFmt {
45229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_OUT_FMT_DEFAULT,
45329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ROT_OUT_FMT_Y_CRCB_H2V2
45429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
45529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
45629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int ROT_OUT_FMT> struct RotOutFmt;
45729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
45829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FIXME, taken from gralloc_priv.h. Need to
45929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// put it back as soon as overlay takes place of the old one
46029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/* possible formats for 3D content*/
46129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum {
46229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_NO_3D                         = 0x0000,
46329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_SIDE_BY_SIDE_L_R        = 0x10000,
46429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_TOP_BOTTOM              = 0x20000,
46529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_INTERLEAVE              = 0x40000,
46629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_IN_SIDE_BY_SIDE_R_L        = 0x80000,
46729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_SIDE_BY_SIDE           = 0x1000,
46829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_TOP_BOTTOM             = 0x2000,
46929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_INTERLEAVE             = 0x4000,
47029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_MONOSCOPIC             = 0x8000
47129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
47229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
47329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedenum { HAL_3D_OUT_SBS_MASK =
47429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
47529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_TOP_BOT_MASK =
47629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
47729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_INTERL_MASK =
47829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
47929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    HAL_3D_OUT_MONOS_MASK =
48029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
48129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
48229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
48329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
48429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isYuv(uint32_t format) {
48529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(format){
48629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V1:
48729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2:
48829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2:
489b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        case MDP_Y_CRCB_H1V1:
490b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        case MDP_Y_CRCB_H2V1:
49129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2_TILE:
49229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2_TILE:
493b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        case MDP_Y_CR_CB_H2V2:
494ae1044e0cbab8d26851782e85525ee9e0e6127e6Saurabh Shah        case MDP_Y_CR_CB_GH2V2:
495d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan        case MDP_Y_CBCR_H2V2_VENUS:
49629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return true;
49729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
49829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return false;
49929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
50029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
50129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
50229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
50329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool isRgb(uint32_t format) {
50429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch(format) {
50529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGBA_8888:
50629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_BGRA_8888:
50729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGBX_8888:
50829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_RGB_565:
50929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return true;
51029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
51129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return false;
51229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
51329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return false;
51429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
51529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
5169c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shahinline const char* getFormatString(int format){
51729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const formats[] = {
51829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGB_565",
51929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_XRGB_8888",
52029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V2",
521f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H2V2_ADRENO",
52229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_ARGB_8888",
52329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGB_888",
52429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V2",
52529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_YCRYCB_H2V1",
52629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V1",
52729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V1",
528f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CRCB_H1V2",
529f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H1V2",
53029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGBA_8888",
53129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_BGRA_8888",
53229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_RGBX_8888",
53329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CRCB_H2V2_TILE",
53429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CBCR_H2V2_TILE",
53529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CR_CB_H2V2",
536f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CR_CB_GH2V2",
53729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_Y_CB_CR_H2V2",
538f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CRCB_H1V1",
539f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_Y_CBCR_H1V1",
540f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_YCRCB_H1V1",
541f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_YCBCR_H1V1",
54229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_BGR_565",
543d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan        "MDP_BGR_888",
544d28fbcbdca035d5ca238aeba5628add89172c573Sushil Chauhan        "MDP_Y_CBCR_H2V2_VENUS",
545f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_IMGTYPE_LIMIT",
546f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        "MDP_RGB_BORDERFILL",
54729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_FB_FORMAT",
54829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        "MDP_IMGTYPE_LIMIT2"
54929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    };
5509c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah    if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
5519c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah        ALOGE("%s wrong fmt %d", __FUNCTION__, format);
5529c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah        return "Unsupported format";
5539c876d9f8c446aaf01cf8dc3a2cd5cff48dc3585Saurabh Shah    }
55429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return formats[format];
55529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
55629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
55729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void Whf::dump() const {
55829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
55929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            w, h, format, size);
56029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
56129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
56229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void Dim::dump() const {
56329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
56429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
56529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
56629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int getMdpOrient(eTransform rotation) {
56729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
568f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    switch(rotation)
56929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
57029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case OVERLAY_TRANSFORM_0 : return 0;
571f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_FLIP_V:  return MDP_FLIP_UD;
572f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_FLIP_H:  return MDP_FLIP_LR;
573f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_90:  return MDP_ROT_90;
574a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        //getMdpOrient will switch the flips if the source is 90 rotated.
575a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        //Clients in Android dont factor in 90 rotation while deciding flip.
576f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
577f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                return MDP_ROT_90 | MDP_FLIP_LR;
578a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah        case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
579a73738dc7058df8821807b42a43c289e372136b8Saurabh Shah                return MDP_ROT_90 | MDP_FLIP_UD;
580f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
581f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
58229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
583f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed            ALOGE("%s: invalid rotation value (value = 0x%x",
584f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed                    __FUNCTION__, rotation);
58529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
58629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
58729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
58829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
58929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int getRotOutFmt(uint32_t format) {
59029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (format) {
59129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CRCB_H2V2_TILE:
59229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CRCB_H2V2;
59329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CBCR_H2V2_TILE:
59429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CBCR_H2V2;
59529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case MDP_Y_CB_CR_H2V2:
59629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return MDP_Y_CBCR_H2V2;
597ae1044e0cbab8d26851782e85525ee9e0e6127e6Saurabh Shah        case MDP_Y_CR_CB_GH2V2:
598ae1044e0cbab8d26851782e85525ee9e0e6127e6Saurabh Shah            return MDP_Y_CRCB_H2V2;
59929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
60029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return format;
60129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
60229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // not reached
60329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    OVASSERT(false, "%s not reached", __FUNCTION__);
60429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return -1;
60529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
60629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
60729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
60829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline uint32_t getColorFormat(uint32_t format)
60929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
610f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    return (format == HAL_PIXEL_FORMAT_YV12) ?
611f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed            format : colorFormat(format);
61229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
61329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
61429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// FB0
61529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
61629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getPositionS3DImpl(const Whf& whf)
61729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
61829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (whf.format & OUTPUT_3D_MASK)
61929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
62029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_SBS_MASK:
62129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // x, y, w, h
62229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w/2, whf.h);
62329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_TOP_BOT_MASK:
62429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w, whf.h/2);
62529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_MONOS_MASK:
62629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
62729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_INTERL_MASK:
62829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // FIXME error?
62929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
63029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
63129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
63229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
63329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    whf.format);
63429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
63529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
63629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
63729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
63829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <>
639d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmedinline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
64029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
64129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (whf.format & OUTPUT_3D_MASK)
64229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
64329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_SBS_MASK:
64429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(whf.w/2, 0, whf.w/2, whf.h);
64529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_TOP_BOT_MASK:
64629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, whf.h/2, whf.w, whf.h/2);
64729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_MONOS_MASK:
64829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, whf.w, whf.h);
64929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_OUT_INTERL_MASK:
65029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            // FIXME error?
65129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
65229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim();
65329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
65429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
65529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                    whf.format);
65629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
65729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
65829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
65929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
66029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
66129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool getPositionS3D(const Whf& whf, Dim& out) {
66229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    out = getPositionS3DImpl<CHAN>(whf);
66329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (out != Dim());
66429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
66529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
66629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
66729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
66829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (fmt & INPUT_3D_MASK)
66929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
67029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_L_R:
67129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w/2, in.h);
67229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_R_L:
67329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(in.w/2, 0, in.w/2, in.h);
67429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_TOP_BOTTOM:
67529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w, in.h/2);
67629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_INTERLEAVE:
67729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
67829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
67929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
68029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
68129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
68229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
68329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
68429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
68529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
68629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <>
687d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmedinline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
68829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    switch (fmt & INPUT_3D_MASK)
68929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    {
69029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_L_R:
69129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(in.w/2, 0, in.w/2, in.h);
69229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_SIDE_BY_SIDE_R_L:
69329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, 0, in.w/2, in.h);
69429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_TOP_BOTTOM:
69529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return Dim(0, in.h/2, in.w, in.h/2);
69629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        case HAL_3D_IN_INTERLEAVE:
69729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
69829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
69929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        default:
70029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
70129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            break;
70229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
70329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return Dim();
70429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
70529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
70629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <int CHAN>
70729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
70829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
70929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    out = getCropS3DImpl<CHAN>(in, fmt);
71029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (out != Dim());
71129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
71229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
71329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedtemplate <class Type>
71429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid swapWidthHeight(Type& width, Type& height) {
71529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    Type tmp = width;
71629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    width = height;
71729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    height = tmp;
71829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
71929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
72029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void ScreenInfo::dump(const char* const s) const {
72129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump %s ScreenInfo w=%d h=%d"
72229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            " bpp=%d stride=%d start/end ==",
72329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
72429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
72529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
726e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shahinline bool openDev(OvFD& fd, int fbnum,
727e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    const char* const devpath, int flags) {
728e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah    return overlay::open(fd, fbnum, devpath, flags);
729e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah}
730e012f7ad3026349c5a6edafbd550cd83655b99d5Saurabh Shah
731b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahtemplate <class T>
732b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahinline void even_ceil(T& value) {
733b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah    if(value & 1)
734b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        value++;
735b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah}
736b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah
737b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahtemplate <class T>
738b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shahinline void even_floor(T& value) {
739b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah    if(value & 1)
740b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah        value--;
741b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah}
742b121e140e51d0dfcd4885289d56fb54b4d0d8e6eSaurabh Shah
743d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmedinline const char* getDestStr(eDest dest) {
744d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    switch(dest) {
745d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_VG0: return "VG0";
746d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_RGB0: return "RGB0";
747d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_VG1: return "VG1";
748d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_RGB1: return "RGB1";
749d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_VG2: return "VG2";
750d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_RGB2: return "RGB2";
751d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        default: return "Invalid";
752d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    }
753d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    return "Invalid";
754d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed}
755d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed
756d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmedinline eMdpPipeType getPipeType(eDest dest) {
757d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    switch(dest) {
758d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_VG0:
759d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_VG1:
760d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_VG2:
761d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed            return OV_MDP_PIPE_VG;
762d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_RGB0:
763d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_RGB1:
764d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        case OV_RGB2:
765d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed            return OV_MDP_PIPE_RGB;
766d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed        default:
767d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed            return OV_MDP_PIPE_ANY;
768d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    }
769d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed    return OV_MDP_PIPE_ANY;
770d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed}
771d551ebe2cb65d9da47d3e25f6004b8870afec8b4Naseer Ahmed
77229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed} // namespace utils ends
77329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
77429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------------Class Res stuff (namespace overlay only) -----------
77529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
77629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass Res {
77729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
77829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /dev/graphics/fb%u
779f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    static const char* const fbPath;
78029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /dev/msm_rotator
78129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const rotPath;
78229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/class/graphics/fb1/format_3d
78329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const format3DFile;
78429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/class/graphics/fb1/3d_present
78529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const edid3dInfoFile;
78629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
78729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static const char* const barrierFile;
78829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
78929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
79029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
79129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------------Class OvFD stuff (namespace overlay only) -----------
79229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
79329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
79429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Holds one FD
79529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* Dtor will NOT close the underlying FD.
79629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* That enables us to copy that object around
79729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed* */
79829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedclass OvFD {
79929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedpublic:
80029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Ctor */
80129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    explicit OvFD();
80229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
80329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* dtor will NOT close the underlying FD */
80429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ~OvFD();
80529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
80629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Open fd using the path given by dev.
80729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed     * return false in failure */
80829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool open(const char* const dev,
80929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            int flags = O_RDWR);
81029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
81129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* populate path */
81229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void setPath(const char* const dev);
81329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
81429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* Close fd if we have a valid fd. */
81529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool close();
81629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
81729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* returns underlying fd.*/
81829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int getFD() const;
81929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* returns true if fd is valid */
82129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool valid() const;
82229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* like operator= */
82429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void copy(int fd);
82529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
82629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* dump the state of the instance */
82729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void dump() const;
82829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
82929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* helper enum for determine valid/invalid fd */
83029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    enum { INVAL = -1 };
83129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
83229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* actual os fd */
83329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int mFD;
83429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
83529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    /* path, for debugging */
83629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    char mPath[utils::MAX_PATH_LEN];
83729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
83829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
83929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//-------------------Inlines--------------------------
84029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
84129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
84229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
84329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    char dev_name[64] = {0};
84429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    snprintf(dev_name, sizeof(dev_name), dev, fbnum);
84529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return fd.open(dev_name, flags);
84629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
84729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
84829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline OvFD::OvFD() : mFD (INVAL) {
84929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mPath[0] = 0;
85029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
85129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
852f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedinline OvFD::~OvFD() {
853f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    //no op since copy() can be used to share fd, in 3d cases.
854f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}
85529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
85629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::open(const char* const dev, int flags)
85729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
85829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFD = ::open(dev, flags, 0);
85929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if (mFD < 0) {
86029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        // FIXME errno, strerror in bionic?
86129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        ALOGE("Cant open device %s err=%d", dev, errno);
86229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return false;
86329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
86429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    setPath(dev);
86529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return true;
86629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
86729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
86829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::setPath(const char* const dev)
86929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
87029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
87129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
87229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
87329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::close()
87429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
87529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int ret = 0;
87629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    if(valid()) {
87729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        ret = ::close(mFD);
87829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mFD = INVAL;
87929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
88029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (ret == 0);
88129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
88229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
88329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline bool OvFD::valid() const
88429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
88529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (mFD != INVAL);
88629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
88729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
88829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline int OvFD::getFD() const { return mFD; }
88929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
89029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::copy(int fd) {
89129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mFD = fd;
89229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
89329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
89429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedinline void OvFD::dump() const
89529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed{
89629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
89729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            mFD, mPath);
89829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
89929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//--------------- class OvFD stuff ends ---------------------
90129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed} // overlay
90329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
90529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#endif // OVERLAY_UTILS_H
906