1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright@ Samsung Electronics Co. LTD
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*!
19  * \file      libscaler-m2m1shot.h
20  * \brief     source file for Scaler HAL
21  * \author    Cho KyongHo <pullip.cho@samsung.com>
22  * \date      2014/05/08
23  *
24  * <b>Revision History: </b>
25  * - 2014.05.08 : Cho KyongHo (pullip.cho@samsung.com) \n
26  *   Create
27  */
28 #ifndef _LIBSCALER_M2M1SHOT_H_
29 #define _LIBSCALER_M2M1SHOT_H_
30 
31 #include "m2m1shot.h"
32 
33 class CScalerM2M1SHOT {
34     int m_iFD;
35     m2m1shot m_task;
36 
37     bool SetFormat(m2m1shot_pix_format &fmt, m2m1shot_buffer &buf,
38                    unsigned int width, unsigned int height, unsigned int v4l2_fmt);
39     bool SetCrop(m2m1shot_pix_format &fmt,
40                    unsigned int l, unsigned int t, unsigned int w, unsigned int h);
41     bool SetAddr(m2m1shot_buffer &buf, void *addr[SC_NUM_OF_PLANES], int mem_type);
42 
43     bool RunSWScaling();
44 public:
45     CScalerM2M1SHOT(int devid, int allow_drm = 0);
46     ~CScalerM2M1SHOT();
47 
48     bool Run();
49 
Valid()50     inline bool Valid() { return m_iFD >= 0; }
51 
SetSrcFormat(unsigned int width,unsigned int height,unsigned int v4l2_fmt)52     inline bool SetSrcFormat(unsigned int width, unsigned int height, unsigned int v4l2_fmt) {
53         return SetFormat(m_task.fmt_out, m_task.buf_out, width, height, v4l2_fmt);
54     }
55 
SetDstFormat(unsigned int width,unsigned int height,unsigned int v4l2_fmt)56     inline bool SetDstFormat(unsigned int width, unsigned int height, unsigned int v4l2_fmt) {
57         return SetFormat(m_task.fmt_cap, m_task.buf_cap, width, height, v4l2_fmt);
58     }
59 
SetSrcCrop(unsigned int l,unsigned int t,unsigned int w,unsigned int h)60     inline bool SetSrcCrop(unsigned int l, unsigned int t, unsigned int w, unsigned int h) {
61         return SetCrop(m_task.fmt_out, l, t, w, h);
62     }
63 
SetDstCrop(unsigned int l,unsigned int t,unsigned int w,unsigned int h)64     inline bool SetDstCrop(unsigned int l, unsigned int t, unsigned int w, unsigned int h) {
65         return SetCrop(m_task.fmt_cap, l, t, w, h);
66     }
67 
SetSrcAddr(void * addr[SC_NUM_OF_PLANES],int mem_type)68     inline bool SetSrcAddr(void *addr[SC_NUM_OF_PLANES], int mem_type) {
69         return SetAddr(m_task.buf_out, addr, mem_type);
70     }
71 
SetDstAddr(void * addr[SC_NUM_OF_PLANES],int mem_type)72     inline bool SetDstAddr(void *addr[SC_NUM_OF_PLANES], int mem_type) {
73         return SetAddr(m_task.buf_cap, addr, mem_type);
74     }
75 
76     bool SetRotate(int rot, int hflip, int vflip);
77 
SetCSCWide(bool wide)78     inline void SetCSCWide(bool wide) {
79         m_task.op.op &= ~(M2M1SHOT_OP_CSC_WIDE | M2M1SHOT_OP_CSC_NARROW);
80         m_task.op.op |= wide ? M2M1SHOT_OP_CSC_WIDE : M2M1SHOT_OP_CSC_NARROW;
81     }
82 
SetCSCEq(unsigned int colorspace)83     inline void SetCSCEq(unsigned int colorspace) {
84         /* TODO: need to add M2M1SHOT_OP_CSC_2020 */
85         m_task.op.op &= ~(M2M1SHOT_OP_CSC_601 | M2M1SHOT_OP_CSC_709);
86         if (colorspace == V4L2_COLORSPACE_REC709)
87             m_task.op.op |= M2M1SHOT_OP_CSC_709;
88         else
89             m_task.op.op |= M2M1SHOT_OP_CSC_601;
90     }
91 
SetFilter(unsigned int filter)92     inline void SetFilter(unsigned int filter) {
93         m_task.op.op &= ~LIBSC_M2M1SHOT_OP_FILTER_MASK;
94         m_task.op.op |= filter << LIBSC_M2M1SHOT_OP_FILTER_SHIFT;
95     }
96 
SetFrameRate(int framerate)97     inline void SetFrameRate(int framerate) {
98         m_task.reserved[0] = (unsigned long)framerate;
99     }
100 
101     /* No effect in M2M1SHOT */
SetDRM(bool __UNUSED__ drm)102     inline void SetDRM(bool __UNUSED__ drm) { }
SetSrcPremultiplied(bool __UNUSED__ premultiplied)103     inline void SetSrcPremultiplied(bool __UNUSED__ premultiplied) { }
SetDstPremultiplied(bool __UNUSED__ premultiplied)104     inline void SetDstPremultiplied(bool __UNUSED__ premultiplied) { }
SetSrcCacheable(bool __UNUSED__ cacheable)105     inline void SetSrcCacheable(bool __UNUSED__ cacheable) { }
SetDstCacheable(bool __UNUSED__ cacheable)106     inline void SetDstCacheable(bool __UNUSED__ cacheable) { }
Stop()107     inline bool Stop() { return true; }
DevSetCtrl()108     inline bool DevSetCtrl() { return false; }
DevSetFormat()109     inline bool DevSetFormat() { return false; }
ReqBufs()110     inline bool ReqBufs() { return false; }
StreamOn()111     inline bool StreamOn() { return false; }
DQBuf()112     inline bool DQBuf() { return false; }
113     inline bool QBuf(int __UNUSED__ *pfdSrcReleaseFence = NULL, int __UNUSED__ *pfdDstReleaseFence = NULL) {
114 	    return false;
115     }
116 
117 };
118 
119 #endif //_LIBSCALER_M2M1SHOT_H_
120