/* 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.
 *
 *****************************************************************************/
/*-----------------------------------------------------------------------------
 *
 * $Author: brianpc.huang $
 * $Date: 2015/05/29 $
 * $RCSfile: gfx_sw.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/** @file gfx_sw.h
 *  gfx driver software module interfaces
 *  init, get register base, isr, callback, op count and action
 */

#ifndef GFX_SW_H
#define GFX_SW_H

//---------------------------------------------------------------------------
// Include files
//---------------------------------------------------------------------------

#include "gfx_if.h"
#include "gfx_common_if.h"

#if defined(GFX_ENABLE_SW_MODE)
//---------------------------------------------------------------------------
// Configurations
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Type definitions
//---------------------------------------------------------------------------

typedef struct _GFX_YCBCR
{
    UINT8 y;
    UINT8 cb;
    UINT8 cr;
}GFX_YCBCR_T;

typedef struct _GFX_YCBCR2RGB_DATA_T
{
    UINT8 *pu1LumaBase;
    UINT8 *pu1ChromaBase;
    UINT8 *pu1DstBase;
    UINT32 u4LumaPitch;
    UINT32 u4ChromaPitch;
    UINT32 u4DstPitch;
    UINT32 u4DstCM;
    UINT32 u4YCFormat;
    UINT32 u4VideoStd;
    UINT32 u4VideoSys;
    UINT32 u4VideoClip;
    UINT32 u4PicSelect;
    UINT32 u4SwapMode;
    UINT32 u4Width;
    UINT32 u4Height;
}GFX_YCBCR2RGB_DATA_T;

typedef struct _GFX_GRADIENT_DATA_T
{
    UINT8 *pu1DstBase;
    UINT32 u4DstPitch;
    UINT32 u4DstCM;
    UINT32 u4X_Pix_Inc;
    UINT32 u4Y_Pix_Inc;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4GradMode;
    UINT32 u4RectColor;
    UINT8 u1Delta_X_C0;
    UINT8 u1Delta_X_C1;
    UINT8 u1Delta_X_C2;
    UINT8 u1Delta_X_C3;
    UINT8 u1Delta_Y_C0;
    UINT8 u1Delta_Y_C1;
    UINT8 u1Delta_Y_C2;
    UINT8 u1Delta_Y_C3;
}GFX_GRADIENT_DATA_T;

typedef struct _GFX_BITBLT_DATA_T
{
    UINT8 *pu1SrcBase;
    UINT8 *pu1DstBase;
    UINT32 u4SrcPitch;
    UINT32 u4DstPitch;
    UINT32 u4SrcCM;
    UINT32 u4DstCM;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4ColorMin;
    UINT32 u4ColorMax;
    UINT32 u4TransEn;
    UINT32 u4ColchgEn;
    UINT32 u4KeynotEn;
    UINT32 u4Color;
}GFX_BITBLT_DATA_T;

// alpha composition loop mode
typedef struct _GFX_ACLM_DATA_T
{
    UINT8 *pu1SrcBase;
    UINT8 *pu1DstBase;
    UINT32 u4SrcPitch;
    UINT32 u4DstPitch;
    UINT32 u4SrcCM;
    UINT32 u4DstCM;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4AlComAr;
    UINT32 u4AlComOpCode;
    UINT32 u4AlComRectSrc;
    UINT32 u4RectColor;
}GFX_ACLM_DATA_T;

typedef struct _GFX_ROP_DATA_T
{
    UINT8 *pu1SrcBase;
    UINT8 *pu1DstBase;
    UINT32 u4SrcPitch;
    UINT32 u4DstPitch;
    UINT32 u4SrcCM;
    UINT32 u4DstCM;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4RopOpCode;
    UINT32 u4RopNoWr;
}GFX_ROP_DATA_T;

typedef struct _GFX_IDX2DIR_DATA_T
{
    UINT8 *pu1SrcBase;
    UINT8 *pu1DstBase;
    UINT32 u4SrcPitch;
    UINT32 u4DstPitch;
    UINT32 u4CharCM; // src color mode
    UINT32 u4DstCM; // dst color mode
    UINT32 u4Width;
    UINT32 u4Height;
    UINT8 *pu1PaleBase; // palette table address
    UINT32 u4MsbLeft;
    UINT32 u4ByteAlign;
}GFX_IDX2DIR_DATA_T;

typedef struct _GFX_HORI2VERT_DATA_T
{
    UINT8 *pu1SrcBase;
    UINT8 *pu1DstBase;
    UINT32 u4SrcPitch;
    UINT32 u4DstPitch;
    UINT32 u4SrcCM;
    UINT32 u4DstCM;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4DstPitchDec;
    UINT32 u4StrDstWidth;
    UINT32 u4StrDstHeight;
}GFX_HORI2VERT_DATA_T;

//---------------------------------------------------------------------------
// Inter-file functions
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Public functions
//---------------------------------------------------------------------------

extern void GFX_SwInit(void);

extern void GFX_SwGetRegBase(UINT32 **ppu4RegBase);

extern void GFX_SwISR(void);

extern INT32 GFX_SwSetCallBack(void (*pfnCallBack)(void *pvTag), void *pvTag);

extern UINT32 GFX_SwGetOpCount(void);

extern void GFX_SwAction(void);

extern void GFX_SwSetColorComponent(UINT8 **ppu1DestFb, UINT32 u4CM,
        const INT32 *pi4sColorComponent);

extern void GFX_SwGetColorComponent(UINT8 **ppu1DestFb, UINT32 u4CM,
        INT32 *pi4ColorComponent);

extern void GFX_SwGetColorComponent_5381(UINT8 **ppu1DestFb, UINT32 u4CM,
        INT32 *pi4ColorComponent);

extern void GFX_SwSetRopColorComp(UINT8 **ppu1DestFb, UINT32 u4CM, const UINT32 *pu4sColorComp);

extern void GFX_SwGetRopColorComp(UINT8 **ppu1DestFb, UINT32 u4CM, UINT32 *pu4ColorComp);

extern INT32 GFX_SwBitBlt(UINT8 *pu1SrcBase, UINT8 *pu1DstBase, UINT32 u4SrcPitch,
        UINT32 u4DstPitch, UINT32 u4SrcCM, UINT32 u4DstCM, UINT32 u4Width,
        UINT32 u4Height, UINT32 u4ColorMin, UINT32 u4ColorMax, UINT32 u4TransEn,
        UINT32 u4KeynotEn, UINT32 u4ColchgEn, UINT32 u4KeySdSel, UINT32 u4Color);

extern INT32 GFX_SwAlphaMapBitBlt(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        UINT32 u4SrcPitch, UINT32 u4DstPitch, UINT32 u4SrcCM, UINT32 u4DstCM,
        UINT32 u4Width, UINT32 u4Height);

extern INT32 GFX_SwAlphaComposePass_5381(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        UINT32 u4SrcPitch, UINT32 u4DstPitch, UINT32 u4SrcCM, UINT32 u4DstCM,
        UINT32 u4Width, UINT32 u4Height, UINT32 u4AlphaValue, UINT32 u4AlcomPass);

extern INT32 GFX_SwAlphaCompositionLoop(const GFX_ACLM_DATA_T *prsData);

extern INT32 GFX_SwBlock2Linear(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        INT32 i4Width, INT32 i4Height, INT32 i4MBWidth, INT32 i4MBHeight);

extern INT32 GFX_SwBlock2Swap(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        INT32 i4Width, INT32 i4Height, INT32 i4MBWidth, INT32 i4MBHeight);

extern INT32 GFX_SwBlock2Mergetop(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        INT32 i4Width, INT32 i4Height, INT32 i4MBWidth, INT32 i4MBHeight);

extern INT32 GFX_SwYCbCrLinearScan(const GFX_YCBCR2RGB_DATA_T *prsData);

extern INT32 GFX_SwYCbCr601toArgbVideoEqu(const GFX_YCBCR_T *prsSrc,
        INT32 *pi4ColorComponent);

extern INT32 GFX_SwYCbCr601toArgbCompEqu(const GFX_YCBCR_T *prsSrc,
        INT32 *pi4ColorComponent);

extern INT32 GFX_SwYCbCr709toArgbVideoEqu(const GFX_YCBCR_T *prsSrc,
        INT32 *pi4ColorComponent);

extern INT32 GFX_SwYCbCr709toArgbCompEqu(const GFX_YCBCR_T *prsSrc,
        INT32 *pi4ColorComponent);

extern INT32 GFX_SwYCbCr2RGB(const GFX_YCBCR2RGB_DATA_T *prsData);

extern INT32 GFX_SwAlphaBlending(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        UINT32 u4SrcPitch, UINT32 u4DstPitch, UINT32 u4Dst_CM, UINT32 u4Alpha,
        UINT32 u4Width, UINT32 u4Height);

extern INT32 GFX_SwAlphaBlending_5381(UINT8 *pu1SrcBase, UINT8 *pu1DstBase,
        UINT32 u4SrcPitch, UINT32 u4DstPitch, UINT32 u4Dst_CM, UINT32 u4Alpha,
        UINT32 u4Width, UINT32 u4Height);

extern INT32 GFX_SwBigEndianAndLittleEndianConversion(UINT8 *pu1DstAddr,
        UINT8 *pu1SrcAddr, UINT32 u4TotalPixels, UINT32 u4ColorMode);

extern INT32 GFX_SwGradientFill(const GFX_GRADIENT_DATA_T *prsData);

extern void GFX_SwRop_NotSrc(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_NotDst(const GFX_ROP_DATA_T *prsData);

extern void GFX_SwRop_Src_Xor_Dst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_Src_XNor_Dst(const GFX_ROP_DATA_T *prsData);

extern void GFX_SwRop_Src_And_Dst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_NotSrc_And_Dst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_Src_And_NotDst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_NotSrc_And_NotDst(const GFX_ROP_DATA_T *prsData);

extern void GFX_SwRop_Src_Or_Dst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_NotSrc_Or_Dst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_Src_Or_NotDst(const GFX_ROP_DATA_T *prsData);
extern void GFX_SwRop_NotSrc_Or_NotDst(const GFX_ROP_DATA_T *prsData);

extern INT32 GFX_SwRopBitBlt(const GFX_ROP_DATA_T *prsData);

extern INT32 GFX_SwMemCompare(const GFX_ROP_DATA_T *prsData);

extern void GFX_SwSetMemCompareResult(INT32 i4Val);

extern INT32 GFX_SwGetMemCompareResult(void);

extern void GFX_SwSetIdx2DirComp(UINT8 **ppu1DestFb, UINT32 u4DstCM,
        const UINT8 *pu1PaleBase, UINT32 u4PaleIdx);

extern void GFX_SwGetIdx2DirComp(UINT8 **ppu1DestFb, UINT8 *pu1SrcByte);

extern UINT32 GFX_SwGetPaleIdx(UINT32 u4CharCM, UINT32 u4ShiftBit, UINT8 u1SrcByte);

extern INT32 GFX_SwIndexToDirectBitBlt(const GFX_IDX2DIR_DATA_T *prsData);

extern INT32 GFX_SwHoriLineToVertLine(const GFX_HORI2VERT_DATA_T *prsData);

extern INT32 GFX_SwClipping(INT32 i4Value);

#endif //#if defined(GFX_ENABLE_SW_MODE)

#endif // GFX_SW_H
