1ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson/*
2ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Copyright (C) 2008 The Android Open Source Project
3ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
4ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*
5ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Licensed under the Apache License, Version 2.0 (the "License");
6ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* you may not use this file except in compliance with the License.
7ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* You may obtain a copy of the License at
8ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*
9ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*      http://www.apache.org/licenses/LICENSE-2.0
10ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*
11ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Unless required by applicable law or agreed to in writing, software
12ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* distributed under the License is distributed on an "AS IS" BASIS,
13ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* See the License for the specific language governing permissions and
15ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* limitations under the License.
16ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson*/
17ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
18ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#ifndef OVERLAY_MDP_H
19ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#define OVERLAY_MDP_H
20ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
21ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include <linux/msm_mdp.h>
22ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
23ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "overlayUtils.h"
24ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "mdpWrapper.h"
25ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "qdMetaData.h"
26ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#ifdef USES_POST_PROCESSING
27ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include "lib-postproc.h"
28ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif
29ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
30ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonnamespace overlay{
31ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
32ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson/*
33ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* Mdp Ctrl holds corresponding fd and MDP related struct.
34ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* It is simple wrapper to MDP services
35ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson* */
36ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonclass MdpCtrl {
37ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonpublic:
38ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* ctor reset */
39a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    explicit MdpCtrl(const int& dpy);
40ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* dtor close */
41ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    ~MdpCtrl();
42a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    /* init underlying device using fbnum for dpy */
43a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    bool init(const int& dpy);
44ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* unset overlay, reset and close fd */
45ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool close();
46ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* reset and set ov id to -1 / MSMFB_NEW_REQUEST */
47ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void reset();
48ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* calls overlay set
49ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson     * Set would always consult last good known ov instance.
50ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson     * Only if it is different, set would actually exectue ioctl.
51ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson     * On a sucess ioctl. last good known ov instance is updated */
52ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool set();
53ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* Sets the source total width, height, format */
54ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setSource(const utils::PipeArgs& pargs);
55ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /*
56ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson     * Sets ROI, the unpadded region, for source buffer.
57ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson     * Dim - ROI dimensions.
58ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson     */
59ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setCrop(const utils::Dim& d);
60a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    /* set color for mdp pipe */
61a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    void setColor(const uint32_t color);
62ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setTransform(const utils::eTransform& orient);
63ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* given a dim and w/h, set overlay dim */
64ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setPosition(const utils::Dim& dim);
65ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* using user_data, sets/unsets roationvalue in mdp flags */
66ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setRotationFlags();
67ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* Update the src format with rotator's dest*/
68ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void updateSrcFormat(const uint32_t& rotDstFormat);
69ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* dump state of the object */
70ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void dump() const;
71ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* Return the dump in the specified buffer */
72ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void getDump(char *buf, size_t len);
73ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* returns session id */
74ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getPipeId() const;
75ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* returns the fd associated to ctrl*/
76ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getFd() const;
77ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* returns a copy ro dst rect dim */
78ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    utils::Dim getDstRectDim() const;
79ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* returns a copy to src rect dim */
80ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    utils::Dim getSrcRectDim() const;
810bc6186c13bed6530aadad53308916869871aa8cSaurabh Shah    /* return pipe priority */
820bc6186c13bed6530aadad53308916869871aa8cSaurabh Shah    uint8_t getPriority() const;
83ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* setVisualParam */
84ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool setVisualParams(const MetaData_t& data);
85ab05b00fefd34a761dfaf1ccaf8ad14d325873f4radhakrishna    /* sets pipe type RGB/DMA/VG */
86ab05b00fefd34a761dfaf1ccaf8ad14d325873f4radhakrishna    void setPipeType(const utils::eMdpPipeType& pType);
87ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
88a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    static bool validateAndSet(MdpCtrl* mdpCtrlArray[], const int& count,
89a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson            const int& fbFd);
90ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonprivate:
91ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* Perform transformation calculations */
92ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void doTransform();
93ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void doDownscale();
94ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* get orient / user_data[0] */
95a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    int getOrient() const;
96ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* returns flags from mdp structure */
97ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getFlags() const;
98ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set flags to mdp structure */
99ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setFlags(int f);
100ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set z order */
101ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setZ(utils::eZorder z);
102ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set isFg flag */
103ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setIsFg(utils::eIsFg isFg);
104ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* return a copy of src whf*/
105ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    utils::Whf getSrcWhf() const;
106ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set plane alpha */
107ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setPlaneAlpha(int planeAlpha);
108ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set blending method */
109ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setBlending(overlay::utils::eBlending blending);
110ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
111ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set src whf */
112ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setSrcWhf(const utils::Whf& whf);
113ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set src/dst rect dim */
114ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setSrcRectDim(const utils::Dim d);
115ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setDstRectDim(const utils::Dim d);
116ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* returns user_data[0]*/
117ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getUserData() const;
118ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* sets user_data[0] */
119ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setUserData(int v);
120ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
121ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    utils::eTransform mOrientation; //Holds requested orientation
122ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* Actual overlay mdp structure */
123ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mdp_overlay   mOVInfo;
124ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* FD for the mdp fbnum */
125ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    OvFD          mFd;
126a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    int mDpy;
127ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
128ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#ifdef USES_POST_PROCESSING
129ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* PP Compute Params */
130ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    struct compute_params mParams;
131ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif
132ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson};
133ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
134ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson/* MDP data */
135ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonclass MdpData {
136ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonpublic:
137ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* ctor reset data */
138a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    explicit MdpData(const int& dpy);
139ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* dtor close*/
140ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    ~MdpData();
141ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* init FD */
142a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    bool init(const int& dpy);
143ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* memset0 the underlying mdp object */
144ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void reset();
145ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* close fd, and reset */
146ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool close();
147ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* set id of mdp data */
148ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void setPipeId(int id);
149ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* return ses id of data */
150ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getPipeId() const;
151ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* get underlying fd*/
152ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getFd() const;
153ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* get memory_id */
154ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int getSrcMemoryId() const;
155ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* calls wrapper play */
156ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool play(int fd, uint32_t offset);
157ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* dump state of the object */
158ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void dump() const;
159ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* Return the dump in the specified buffer */
160ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void getDump(char *buf, size_t len);
161ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
162ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonprivate:
163ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
164ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* actual overlay mdp data */
165ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    msmfb_overlay_data mOvData;
166ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    /* fd to mdp fbnum */
167ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    OvFD mFd;
168ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson};
169ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
170ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson//--------------Inlines---------------------------------
171ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
172ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson/////   MdpCtrl  //////
173ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
174a653efede03423aa840da24634f1ec6f20796f1eSimon Wilsoninline MdpCtrl::MdpCtrl(const int& dpy) {
175ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    reset();
176a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    init(dpy);
177ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
178ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
179ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline MdpCtrl::~MdpCtrl() {
180ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    close();
181ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
182ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
183ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpCtrl::getOrient() const {
184ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return getUserData();
185ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
186ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
187ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpCtrl::getPipeId() const {
188ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return mOVInfo.id;
189ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
190ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
191ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpCtrl::getFd() const {
192ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return mFd.getFD();
193ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
194ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
195ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpCtrl::getFlags() const {
196ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return mOVInfo.flags;
197ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
198ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
199ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setFlags(int f) {
200ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.flags = f;
201ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
202ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
203ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setZ(overlay::utils::eZorder z) {
204ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.z_order = z;
205ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
206ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
207ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setIsFg(overlay::utils::eIsFg isFg) {
208ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.is_fg = isFg;
209ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
210ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
211ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setPlaneAlpha(int planeAlpha) {
212ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.alpha = planeAlpha;
213ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
214ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
215ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setBlending(overlay::utils::eBlending blending) {
216ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    switch((int) blending) {
217ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    case utils::OVERLAY_BLENDING_OPAQUE:
218ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mOVInfo.blend_op = BLEND_OP_OPAQUE;
219ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        break;
220ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    case utils::OVERLAY_BLENDING_PREMULT:
221ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mOVInfo.blend_op = BLEND_OP_PREMULTIPLIED;
222ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        break;
223ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    case utils::OVERLAY_BLENDING_COVERAGE:
224ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    default:
225ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mOVInfo.blend_op = BLEND_OP_COVERAGE;
226ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
227ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
228ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
229ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline overlay::utils::Whf MdpCtrl::getSrcWhf() const {
230ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return utils::Whf(  mOVInfo.src.width,
231ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.src.height,
232ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.src.format);
233ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
234ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
235ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) {
236ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src.width  = whf.w;
237ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src.height = whf.h;
238ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src.format = whf.format;
239ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
240ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
241ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline overlay::utils::Dim MdpCtrl::getSrcRectDim() const {
242ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return utils::Dim(  mOVInfo.src_rect.x,
243ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.src_rect.y,
244ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.src_rect.w,
245ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.src_rect.h);
246ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
247ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
248ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) {
249ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src_rect.x = d.x;
250ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src_rect.y = d.y;
251ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src_rect.w = d.w;
252ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.src_rect.h = d.h;
253ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
254ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
255ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline overlay::utils::Dim MdpCtrl::getDstRectDim() const {
256ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return utils::Dim(  mOVInfo.dst_rect.x,
257ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.dst_rect.y,
258ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.dst_rect.w,
259ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson                        mOVInfo.dst_rect.h);
260ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
261ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
262ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) {
263ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.dst_rect.x = d.x;
264ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.dst_rect.y = d.y;
265ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.dst_rect.w = d.w;
266ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOVInfo.dst_rect.h = d.h;
267ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
268ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
269ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpCtrl::getUserData() const { return mOVInfo.user_data[0]; }
270ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
271ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setUserData(int v) { mOVInfo.user_data[0] = v; }
272ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
273ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpCtrl::setRotationFlags() {
274ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    const int u = getUserData();
275ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if (u & MDP_ROT_90)
276ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
277ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
278ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
2790bc6186c13bed6530aadad53308916869871aa8cSaurabh Shahinline uint8_t MdpCtrl::getPriority() const {
2800bc6186c13bed6530aadad53308916869871aa8cSaurabh Shah    return mOVInfo.priority;
2810bc6186c13bed6530aadad53308916869871aa8cSaurabh Shah}
2820bc6186c13bed6530aadad53308916869871aa8cSaurabh Shah
283ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson///////    MdpData   //////
284ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
285a653efede03423aa840da24634f1ec6f20796f1eSimon Wilsoninline MdpData::MdpData(const int& dpy) {
286a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    reset();
287a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson    init(dpy);
288a653efede03423aa840da24634f1ec6f20796f1eSimon Wilson}
289ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
290ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline MdpData::~MdpData() { close(); }
291ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
292ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpData::reset() {
293ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    overlay::utils::memset0(mOvData);
294ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOvData.data.memory_id = -1;
295ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
296ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
297ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline bool MdpData::close() {
298ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    reset();
299ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return mFd.close();
300ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
301ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
302ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; }
303ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
304ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline void MdpData::setPipeId(int id) { mOvData.id = id; }
305ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
306ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpData::getPipeId() const { return mOvData.id; }
307ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
308ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline int MdpData::getFd() const { return mFd.getFD(); }
309ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
310ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsoninline bool MdpData::play(int fd, uint32_t offset) {
311ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOvData.data.memory_id = fd;
312ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    mOvData.data.offset = offset;
313ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    if(!mdp_wrapper::play(mFd.getFD(), mOvData)){
314ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        ALOGE("MdpData failed to play");
315ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        dump();
316ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        return false;
317ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    }
318ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    return true;
319ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson}
320ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
321ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson} // overlay
322ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
323ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif // OVERLAY_MDP_H
324