/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/


#if ! defined(__MT53_GAL__)
#include "osd_drvif.h"

#define MT_PAL_LENGTH 256
#define MT_GAL_2DTO3D_SHIFT_VALUE 16

typedef enum 
{
	MT_GAL_PIXEL_FORMAT_ARGB = 0,	/**< 32 bit ARGB (4 byte, alpha 8\@24, red 8\@16, green 8\@8, blue 8\@0) */
	MT_GAL_PIXEL_FORMAT_LUT8, 		/**< 8 bit LUT (8 bit color and alpha lookup from palette) */
	MT_GAL_PIXEL_FORMAT_ARGB1555, 	/**< 16 bit ARGB (2 byte, alpha 1\@15, red 5\@10, green 5\@5, blue 5\@0) */
	MT_GAL_PIXEL_FORMAT_RGB16, 	/**< 16 bit RGB (2 byte, red 5\@11, green 6\@5, blue 5\@0) */
	MT_GAL_PIXEL_FORMAT_ARGB4444, 	/**< 16 bit ARGB (2 byte, alpha 4\@12, red 4\@8, green 4\@4, blue 4\@0) */
	MT_GAL_PIXEL_FORMAT_A8, 		/**< 8 bit A (1 byte, alpha 8\@0) */
	MT_GAL_PIXEL_FORMAT_MAX		/**< Maximum number of MT_GAL_PIXEL_FORMAT_T */
} MT_GAL_PIXEL_FORMAT_T;

typedef enum
{
	MT_GAL_PLANE_ARGB_EX = 0x00000000,
	MT_GAL_PLANE_YUV_EX	= 0x00000001,
	MT_GAL_PLANE_MAX_EX	= 0x00000010,
} MT_GAL_PLANE_FORMAT_T;

typedef struct
{
	unsigned int	*pPalette;	/**< point to the palette arry */
	unsigned int	length;		/**< size of palette (max: 256) */
} MT_GAL_PALETTE_INFO_T;

typedef struct
{
	unsigned int			offset;				/**< bytes offset from the start of graphic memory */
	unsigned int			virtualAddress;   /**< virtual address of surface */
	unsigned int			physicalAddress;  /**< physical address of surface */
	unsigned short			pitch;				/**< pitch: length of horizontal line */
	unsigned short			bpp;				/**< bits per pixel */
	unsigned short			width;				/**< width of surface */
	unsigned short			height;				/**< height of surface */
	MT_GAL_PIXEL_FORMAT_T	pixelFormat;		/**< pixel format of surface */
	MT_GAL_PALETTE_INFO_T	paletteInfo;		/**< palette information, this field is used when the surface's pixel format is based on indexed color. */
	signed int				id;					/**< surface identifier */
	signed int 				pid;				/**< request process id */
	unsigned int			property;			/**< reserved for future use */
} MT_GAL_SURFACE_INFO_T;

typedef struct {
	unsigned int		physicalAddr;		/**< physical address of surface pool base */
	unsigned int		virtualAddr;		/**< virtual address of surface pool base */
	unsigned int		startOffset;		/**< the end of allocated layers (surface pool start with zero offset.) */
	unsigned int		size;				/**< size of surface pool (in bytes). It is not from startOffset but zero offset which means base point of surface pool. */
	unsigned short		byteOffsetAlign;	/**< bytes alignment constraint for the offset value of each surface allocation */
	unsigned short		bytePitchAlign;		/**< bytes alignment constraint for the surface's pitch value */
} MT_GAL_SURFACE_POOL_INFO_T;

typedef enum
{
   MTGAL_OK					=  0,   ///< Success
   MTGAL_NOT_OK				= -1,   ///< Not ok
   MTGAL_INVALID_PARAM		= -2,   ///< Not ok
   MTGAL_OUT_OF_MEMORY		= -3
} MTGAL_RESULT_T;

typedef struct
{
    unsigned int u4Addr;
    unsigned int u4Size;
} MT_GAL_BUFPROP_T;

typedef struct
{
	int x, y;
	int w, h;
} MT_GAL_RECT_T;

typedef enum 
{
	MT_GAL_2D_TO_3D = 0,	/**2d->3d */
	MT_GAL_S3D, 		/**sterei 3d */
	MT_GAL_3D_DISABLE, 
	MT_GAL_MAX
} MT_GAL_3D_MODE;

typedef enum
{
  MT_GAL_NORMAL_MODE,
  MT_GAL_3DPR_MODE,
  MT_GAL_3DSG_MODE,
  MT_GAL_3DPDP_MODE, //PDP special case, 
  MT_GAL_MAX_MODE,
} MT_GAL_MODE_T;

typedef enum
{
	MT_GAL_PLANE_ATTRIBUTE_NULL,
	MT_GAL_PLANE_ATTRIBUTE_RECT_IN,   /* x, y, w, h */
	MT_GAL_PLANE_ATTRIBUTE_RECT_OUT,  /* x, y, w, h */
	MT_GAL_PLANE_ATTRIBUTE_STEREO,    /* on/off, mode */
	MT_GAL_PLANE_ATTRIBUTE_FORMAT,	  /* plane format, not surface format */
	MT_GAL_PLANE_ATTRIBUTE_SURFACE,
	MT_GAL_PLANE_ATTRIBUTE_RUN,
	MT_GAL_PLANE_ATTRIBUTE_MAX
} MT_GAL_PLANE_ATTRIBUTE_T;

extern void				MT_GAL_InitSurfaceSema(void);
extern void				MT_GAL_SetSurfacePool(MT_GAL_SURFACE_POOL_INFO_T *u4SurfacePool);
extern MTGAL_RESULT_T	MT_GAL_CreateSurface(unsigned short width, unsigned short height, int pixelFormat, MT_GAL_SURFACE_INFO_T *pSurfaceInfo);
extern MTGAL_RESULT_T	MT_GAL_DestroySurface(MT_GAL_SURFACE_INFO_T *pSurfaceInfo);
extern MT_GAL_SURFACE_INFO_T * MT_GAL_GetSurfaceFromOffset(unsigned int offset);
extern MTGAL_RESULT_T	MT_GAL_SyncSurface(MT_GAL_SURFACE_INFO_T *u4SurfacePool);
extern MTGAL_RESULT_T	MT_GAL_GALInit(unsigned int u4PhyAddr, unsigned int u4VirAddr, unsigned int u4Size);
extern MTGAL_RESULT_T	MT_GAL_GetTempBuffer(INT32 *pSurfaceInfo, INT32 *pSurfaceInfo2);
extern MTGAL_RESULT_T	MT_GAL_GetTempSurface(MT_GAL_SURFACE_INFO_T *pSurfaceInfo, MT_GAL_SURFACE_INFO_T *pSurfaceInfo2);
extern MTGAL_RESULT_T	MT_GAL_SetFrameSurface(UINT32 u4Plane, MT_GAL_SURFACE_INFO_T *pSurfaceInfo);
extern void				MT_GAL_InitUsrSaceSema(void);
extern MTGAL_RESULT_T	MT_GAL_MultiProcLock(void);
extern MTGAL_RESULT_T	MT_GAL_MultiProcUnLock(void);
extern MTGAL_RESULT_T	MT_GAL_MallocToOffset(INT32 u4Length,INT32 * offset );
extern MTGAL_RESULT_T	MT_GAL_Set3DMode(UINT32 u4Plane, UINT32 u4Enable, UINT32 u4Mode);
extern void				MT_GAL_SetStereoMode(UINT32 u4Mode);
extern MTGAL_RESULT_T	MT_GAL_ResetFrameSurface(UINT32 u4Plane);
extern MTGAL_RESULT_T	MT_GAL_GetFrameSurfaceAttributes(UINT32 u4Plane, MT_GAL_PLANE_ATTRIBUTE_T *attributes, INT32 *values);
extern MTGAL_RESULT_T	MT_GAL_SetFrameSurfaceAttributes(UINT32 u4Plane, MT_GAL_PLANE_ATTRIBUTE_T *attributes, const INT32 *values);

#endif

