display_main.cpp

来自「6410BSP3」· C++ 代码 · 共 1,962 行 · 第 1/5 页

CPP
1,962
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// Copyright (c) Samsung Electronics. Co. LTD. All rights reserved.
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:

    display_main.cpp

Abstract:

    This module implement the main class that derived from DDGPE of display driver to support DirectDraw
    The class S3C6410Disp has many method and member variables, so implementation code is split to other module

Functions:

    Common Initalization, Deinitialization,
Notes:

--*/

#include "precomp.h"
#include "pmplatform.h"
#include <syspal.h>    // for 8Bpp we use the natural palette
#include <gxinfo.h>
//#define DISPPERF_DECLARE    //< This is defined in ddi_if.cpp in GPE component in CE6R2
#include "dispperf.h"
#if    (SMDK6410_LCD_MODULE == LCD_MODULE_LTM030DK)
#include "iic.h"

static BOOL LDI_LTM030DK_SetALC();
#endif

DDGPE * gGPE = (DDGPE *)NULL;
#define DBG_MSG_HEADER      _T("[DISPDRV]")

#ifdef DEBUG
// NOTE:  One file should use INSTANTIATE_GPE_ZONES.  This allows it to be pre-compiled
// initialZones should typically be 0x0003 (refer to "gpe.h")
INSTANTIATE_GPE_ZONES(DISPDRV_DEBUGZONES, __MODULE__, "", "")
#else


DBGPARAM dpCurSettings =                                \
{                                                       \
    TEXT(__MODULE__),                                      \
    {                                                   \
        TEXT("Errors"),                 /* 0  */        \
        TEXT("Warnings"),               /* 1  */        \
        TEXT("Performance"),            /* 2  */        \
        TEXT("Temporary tests"),        /* 3  */        \
        TEXT("Enter,Exit"),             /* 4  */        \
        TEXT("Initialize"),             /* 5  */        \
        TEXT("Blt Calls"),              /* 6  */        \
        TEXT("Blt Verbose"),            /* 7  */        \
        TEXT("Surface Create"),         /* 8  */        \
        TEXT("Flip"),                   /* 9  */        \
        TEXT("Line"),                   /* 10 */        \
        TEXT("Post"),                   /* 11 */        \
        TEXT("Rotator"),                /* 12 */        \
        TEXT("TV Scaler"),              /* 13 */        \
        TEXT("TV Encoder"),             /* 14 */        \
        TEXT("2D"),                     /* 15 */        \
    },                                                  \
    (DISPDRV_RETAILZONES)                               \
};
#endif

// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA * data, PENGCALLBACKS engineCallbacks);

BOOL AdvertisePowerInterface(HMODULE hInst);
BOOL ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid);
CEDEVICE_POWER_STATE VideoToPmPowerState(VIDEO_POWER_STATE vps);
VIDEO_POWER_STATE PmToVideoPowerState(CEDEVICE_POWER_STATE pmDx);

BOOL
APIENTRY
DrvEnableDriver(
    ULONG           engineVersion,
    ULONG           cj,
    DRVENABLEDATA * data,
    PENGCALLBACKS   engineCallbacks
    )
{
    return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}

GPE *
GetGPE()
{
    if (!gGPE)
    {
        gGPE = new S3C6410Disp();
    }

    return gGPE;
}

// This is Temporary Code. Must fix bug & delete
#define TEMP_FIX_ROTATION_BUG

#ifdef TEMP_FIX_ROTATION_BUG
BOOL g_bTempFirstRotation=FALSE;
#endif

S3C6410Disp::S3C6410Disp()
{
    DWORD dwSplashFrameBufferSize;

    RETAILMSG(DISP_ZONE_ENTER,(_T("[DISPDRV] ++%s()\n\r"),_T(__FUNCTION__)));

    m_pDispConReg = NULL;
    m_pGPIOReg = NULL;
    m_pSPIReg = NULL;

    m_VideoMemoryPhysicalBase = NULL;
    m_VideoMemoryVirtualBase = NULL;
    m_VideoMemorySize = 0;
    m_pVideoMemoryHeap = NULL;

    m_hVideoDrv = NULL;

    m_CursorVisible = FALSE;
    m_CursorDisabled = TRUE;
    m_CursorForcedOff = FALSE;
    memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));

    m_InDDraw = FALSE;

    InitalizeOverlayContext();

    m_bTVDMARunning = FALSE;

    m_TVDMACtxt.dwSourceFormat = 0;
    m_TVDMACtxt.uiSrcBaseWidth = 0;
    m_TVDMACtxt.uiSrcBaseHeight = 0;
    m_TVDMACtxt.uiSrcWidth = 0;
    m_TVDMACtxt.uiSrcHeight = 0;
    m_TVDMACtxt.uiSrcOffsetX = 0;
    m_TVDMACtxt.uiSrcOffsetY = 0;

//---------------------
// Setup Mode Information
//---------------------

    // Initial Output Interface
    m_eOutputInterface = OUTPUT_IF_RGB;
    //m_eOutputInterface = OUTPUT_IF_TV;
    m_eTVDMAMode = TV_DMA_DISABLE;

    // Initialize Screen Dimensions
    m_dwDeviceScreenWidth = LCD_WIDTH;
    m_dwDeviceScreenHeight = LCD_HEIGHT;
    m_nScreenWidthSave = m_dwDeviceScreenWidth;
    m_nScreenHeightSave = m_dwDeviceScreenHeight;

    // Initialize Rotate Mode
#ifdef TEMP_FIX_ROTATION_BUG
    m_iRotate = 0;
    g_bTempFirstRotation = TRUE;
#else
    m_iRotate = GetRotateModeFromReg();
#endif
    SetRotateParams();

    //----------------------------------------
    // Initialize ModeInfoEX, modeInfo Data Structure
    //----------------------------------------

    InitializeDisplayMode();



    // Initialize Power State
    m_VideoPowerState = VideoPowerOn;

    // Mapping Virtual Address (SFR, VideoMemory)
    if (AllocResource() == FALSE)
    {
        RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] %s() : AllocResource() Fail\n\r"), _T(__FUNCTION__)));
        return;
    }

    // Clear Video Memory (Leave frame buffer for splash image)
    dwSplashFrameBufferSize = m_dwDeviceScreenWidth*m_dwDeviceScreenHeight*m_pMode->Bpp/8;
    memset ((void *)(m_VideoMemoryVirtualBase+dwSplashFrameBufferSize), 0x0, m_VideoMemorySize-dwSplashFrameBufferSize);

    InitAcceleration();
    
    if(m_G2DControlArgs.HWOnOff)
    {
        m_oG2D = new FIMGSE2D;
        if(m_oG2D == NULL)
        {
            RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] %s() : 2D Accelerator Initialization Fail\n\r"), _T(__FUNCTION__)));
        }

        // Initialize Interrupt (Event, Interrupt)
        if (m_oG2D)
        {
            BOOL bResult;

            bResult = m_oG2D->InitializeInterrupt();
            if(bResult==FALSE)
            {
                RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] InitializeInterrupt() 2D Object is failed.\n\r")));
            }
        }
        else
        {
            RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] InitializeInterrupt() : 2D Object is not created.\n\r")));
        }
    }

    // Initialize Critical Section
    InitializeCriticalSection(&m_csDevice);
    InitializeCriticalSection(&m_cs2D);

    // Initialize Display Controller
    if (DevInitialize() == FALSE)
    {
        RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] %s() : InitializeDevice() Fail\n\r"), _T(__FUNCTION__)));
        return;
    }

    //Allocate Primary Surface
    if (NULL == m_pPrimarySurface)
    {
        if (FAILED(AllocSurface((DDGPESurf **)&m_pPrimarySurface,
                            m_nScreenWidthSave, m_nScreenHeightSave,
                            m_pMode->format, m_pModeEx->ePixelFormat,
                            GPE_REQUIRE_VIDEO_MEMORY)))
        {
            RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] %s() : m_pPrimarySurface AllocSurface() Fail\n\r"), _T(__FUNCTION__)));
         }
        else
        {
            m_pVisibleSurface = (S3C6410Surf*)m_pPrimarySurface;
        }
    }
    RETAILMSG(TRUE,(TEXT("m_nScreenWidth:%d, m_nScreenHeight:%d, m_nWS:%d, m_nHS:%d, m_iRotate:%d, PriRot:%d\r\n"),
        m_nScreenWidth, m_nScreenHeight, m_nScreenWidthSave, m_nScreenHeightSave, m_iRotate, m_pPrimarySurface->Rotate()));
    m_pPrimarySurface->SetRotation(m_nScreenWidth, m_nScreenHeight, m_iRotate);
    RETAILMSG(TRUE,(TEXT("Primary ScreenWidth:%d, ScreenHeight:%d, m_iRotate:%d\r\n"),
        m_pPrimarySurface->ScreenWidth(), m_pPrimarySurface->ScreenHeight(), m_pPrimarySurface->Rotate()));
    

    AdvertisePowerInterface(g_hmodDisplayDll);

    RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] --%s()\n\r"), _T(__FUNCTION__)));
}

S3C6410Disp::~S3C6410Disp()
{
    RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s()\n\r"), _T(__FUNCTION__)));

    if (m_oG2D)
    {
        m_oG2D->DeinitInterrupt();
        delete m_oG2D;
    }
    else
    {
        RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] DeinitInterrupt() : 2D Object is not created.\n\r")));
    }

    ReleaseResource();

    RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV] --%s()\n\r"), _T(__FUNCTION__)));
}

void
S3C6410Disp::InitAcceleration(void)
{
#if G2D_ACCELERATE
    m_G2DControlArgs.HWOnOff = 1;
    m_G2DControlArgs.UseBitBlt = 1;
    m_G2DControlArgs.UseLineDraw = 1;
#else
    m_G2DControlArgs.HWOnOff = 0;    
    m_G2DControlArgs.UseBitBlt = 0;
    m_G2DControlArgs.UseLineDraw = 0;
#endif
    // Determine AccelLevel, Currently not used strictly.
    m_G2DControlArgs.AccelLevel = 0x8;
    
    m_G2DControlArgs.UseSWAccel = USE_SECEMUL_LIBRARY;
    m_G2DControlArgs.CachedBlt = G2D_TRY_CBLT;
    m_G2DControlArgs.UseAlphaBlend = (G2D_BYPASS_HW_ALPHABLEND) ? (0) : (1);
    m_G2DControlArgs.UseStretchBlt = (G2D_BYPASS_HW_STRETCHBLT) ? (0) : (1);
    m_G2DControlArgs.UseFillRect = (G2D_BYPASS_HW_FILLRECT) ? (0) : (1);    
    m_G2DControlArgs.UsePACSurf = USE_PACSURF; 
    m_G2DControlArgs.SetBltLimitSize = G2D_BLT_OPTIMIZE;
    m_G2DControlArgs.AllocBoundSize = PAC_ALLOCATION_BOUNDARY;
    m_G2DControlArgs.BltLimitSize = G2D_COMPROMISE_LIMIT;
    m_G2DControlArgs.OverrideEmulFunc = G2D_OVERRIDE_EMULSEL;

    RETAILMSG(DISP_ZONE_INIT, (TEXT("LV:%d, HW:%d, BitBlt:%d, Line:%d, Alpha:%d, Fill:%d, SW:%d, Cached:%d, Stretch:%d, PAC:%d, Limit:%d, Alloc:%d, BltLimit:%d\r\n"),
    m_G2DControlArgs.AccelLevel,
    m_G2DControlArgs.HWOnOff,
    m_G2DControlArgs.UseBitBlt,
    m_G2DControlArgs.UseLineDraw,
    m_G2DControlArgs.UseAlphaBlend,
    m_G2DControlArgs.UseFillRect,
    m_G2DControlArgs.UseSWAccel,
    m_G2DControlArgs.CachedBlt,
    m_G2DControlArgs.UseStretchBlt,
    m_G2DControlArgs.UsePACSurf,
    m_G2DControlArgs.SetBltLimitSize,
    m_G2DControlArgs.AllocBoundSize,
    m_G2DControlArgs.BltLimitSize));
    
}

void
S3C6410Disp::WaitForNotBusy(void)
{
    if( m_VideoPowerState != VideoPowerOff && // to avoid hanging while bring up display H/W
        m_oG2D)
    {
        m_oG2D->WaitForIdle();
    }
}

int
S3C6410Disp::IsBusy(void)
{
    if( m_VideoPowerState != VideoPowerOff && // to avoid hanging while bring up display H/W
        m_oG2D)
    {
        return m_oG2D->CheckFifo();
    }
    return    0;        //< 2D HW not yet start
}

void
S3C6410Disp::GetPhysicalVideoMemory(unsigned long *physicalMemoryBase, unsigned long *videoMemorySize)
{
    RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] %s()\n\r"), _T(__FUNCTION__)));

    *physicalMemoryBase = m_VideoMemoryPhysicalBase;
    *videoMemorySize = m_VideoMemorySize;
}

void
S3C6410Disp::GetVirtualVideoMemory(unsigned long *virtualMemoryBase, unsigned long *videoMemorySize)
{
    RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] %s()\n\r"), _T(__FUNCTION__)));

    *virtualMemoryBase = m_VideoMemoryVirtualBase;
    *videoMemorySize = m_VideoMemorySize;
}


int
S3C6410Disp::InDisplay(void)
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("%s()\r\n"), _T(__FUNCTION__)));

    if (DevGetVerticalStatus() == DISP_V_ACTIVE)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

int
S3C6410Disp::InVBlank(void)
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("%s()\r\n"), _T(__FUNCTION__)));

    switch(DevGetVerticalStatus())
    {
        case DISP_V_VSYNC:
        case DISP_V_BACKPORCH:
            return TRUE;
            break;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?