⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winsurf.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "hxtypes.h"
#include <math.h>
#include "ddraw.h"
#include "hxcom.h"
#include "hxmtypes.h"
#include "hxwintyp.h"
#include "hxvsurf.h"
#include "hxslist.h"

#include "winsurf.h"
#include "winsite.h"
#include "colormap.h"
#include "hxprefs.h"
#include "hxtick.h"
#include "hxheap.h"
#include "hxevent.h"

// these are defined in basesurf.cpp and should probably be moved to a .h file
#define HX_OVER_KEYDEST    1
#define HX_OVER_HIDE       2
#define HX_OVER_SHOW       4  
#define OVERLAY_NOT_VISIBLE 0

#ifdef _DEBUG
#undef HX_THIS_FILE             
static const char HX_THIS_FILE[] = __FILE__;

#include "winthrd.h"
#endif


CWinSurface::CWinSurface(IUnknown* pContext, CHXBaseSite* pSite) :
    CBaseSurface(pContext,pSite)
 ,  m_nBitsPerPixel(0)
 ,  m_nHozRes(0)
 ,  m_nVertRes(0)
 ,  m_nLastBltMode(HX_NO_BLT)
{
    // initialize data so we don't have invalid ptrs floating around.
    memset(&m_surface,0,sizeof(m_surface));
}

CWinSurface::~CWinSurface()
{
}

void CWinSurface::_ReleaseSurface(CBaseRootSurface* pSurface)
{
    WINDRAW* pWindraw = ((CWinBaseRootSurface*)pSurface)->GetWinDraw();
    WinDraw2_ReleaseSurface(pWindraw, &m_surface);

    m_nLastBltMode = HX_NO_BLT;
}

void CWinSurface::_ReleaseSurface(CWinBaseRootSurface* pSurface)
{
    WINDRAW* pWindraw = pSurface->GetWinDraw();
    WinDraw2_ReleaseSurface(pWindraw, &m_surface);

    m_nLastBltMode = HX_NO_BLT;
}

void CWinSurface::_DrawBlack(void* pWindow)
{
}

void CWinSurface::_CreateBuffer()
{
    CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
    pSurface->OpenWindraw();
    WINDRAW* pWindraw = pSurface->GetWinDraw();
        
    BMI bmi;
    memset(&bmi, 0, sizeof(BMI));
    WinDraw2_GetDisplayFormat(pWindraw, &bmi);
    int cid = GetBitmapColor((LPBITMAPINFO)&bmi);
        
    memset(&bmi, 0, sizeof(BMI));
    MakeBitmap((LPBITMAPINFO)&bmi, sizeof(BMI), cid, m_pOptimizedFormat->biWidth, m_pOptimizedFormat->biHeight, NULL, NULL);
    memset(&m_surface, 0, sizeof(WINDRAWSURFACE));
    
    if (NOERROR == WinDraw2_CreateSurface(pWindraw, &m_surface, &bmi, pSurface->GetSurfaceType(), 0, 0))
    {
        m_surfaceSize.cx = m_pOptimizedFormat->biWidth;
        m_surfaceSize.cy = m_pOptimizedFormat->biHeight;
        m_nSurfaceCID = cid;
        m_nBltMode = HX_BLT_YUV_STRETCH;

        if (!m_nBitsPerPixel ||
            !m_nHozRes ||
            !m_nVertRes)
        {
            // Store the display mode we were created in.
            m_pSite->_GetDeviceCaps(NULL, m_nBitsPerPixel, m_nHozRes, m_nVertRes);
        }
    }
}

HX_RESULT CWinSurface::_GetCaps(UINT32 *pfSurfaceCaps)
{
    CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
    pSurface->OpenWindraw();
    WINDRAW* pWindraw = pSurface->GetWinDraw();
        
    //    UINT32 fSurfaceCaps;
    UINT32 garbagea, garbageb;
        
    if (NOERROR != Windraw_GetCaps(pWindraw, pfSurfaceCaps, &garbagea, &garbageb))
    {
        return HXR_FAIL;
    }
    else
    {
        return HXR_OK;
    }
}

HX_RESULT CWinSurface::_CreateOverlay(BOOL bOverlay, int cid, int x, int y)
{
    //Get our windraw object from the root surface
    CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
   
    HX_ASSERT( pSurface );
    if( !pSurface )
        return HXR_FAIL;
   
    pSurface->OpenWindraw();
    WINDRAW* pWindraw = pSurface->GetWinDraw();
    BMI bmi;
    memset(&bmi, 0, sizeof(BMI));
    MakeBitmap((LPBITMAPINFO)&bmi, sizeof(BMI), cid, x, y, NULL, NULL);
    memset(&m_surface, 0, sizeof(WINDRAWSURFACE));
        
    int fFlags = 0;
        
    if (bOverlay)
    {
        fFlags = WINDRAWSURFACE_DIRECTDRAW | WINDRAWSURFACE_OVERLAY | WINDRAWSURFACE_VIDEOMEMORY;
    }
    else
    {
        fFlags = WINDRAWSURFACE_DIRECTDRAW | WINDRAWSURFACE_DEFAULTMEMORY;
    }
        
    int numBuffers = (m_bFlipOverlay && bOverlay) ? m_nBackBufferCount+1 : 1;
    for (; numBuffers; numBuffers--)
    {
        if (NOERROR == WinDraw2_CreateSurface(pWindraw, &m_surface, &bmi, fFlags, numBuffers-1, 0))
        {
            m_nDDSurfaceSize = bmi.bmiHeader.biSizeImage;
            m_surfaceSize.cx = x;
            m_surfaceSize.cy = y;
            m_nSurfaceCID = cid;
            m_nBackBufferCount = numBuffers-1;

            if (bOverlay)
            {
                m_nBltMode = HX_OVERLAY_BLT;
            }
            else
            {
                m_nBltMode = HX_BLT_YUV_STRETCH;
            }
            UpdateDestRect();

            if (!m_nBitsPerPixel ||
                !m_nHozRes ||
                !m_nVertRes)
            {
                // Store the display mode we were created in.
                m_pSite->_GetDeviceCaps(NULL, m_nBitsPerPixel, m_nHozRes, m_nVertRes);
            }

            return HXR_OK;
        }
    }
        
    return HXR_FAIL;
}

HX_RESULT CWinSurface::_BltToPrimary(REF(HXxRect) rDestRect, REF(HXxRect) rSrcRect)
{
#ifdef _CHECK_PERFORMANCE
    static LARGE_INTEGER QueryPerformanceCounterResult = {0,0};
    static LARGE_INTEGER QueryPerformanceFrequencyResult = {0,0};
        
    QueryPerformanceFrequency(&QueryPerformanceFrequencyResult);
        
    double frequency = ((double)QueryPerformanceFrequencyResult.LowPart + 4294967296.0*QueryPerformanceFrequencyResult.HighPart);
    QueryPerformanceCounter(&QueryPerformanceCounterResult);
        
    double startTime = ((double)QueryPerformanceCounterResult.LowPart + 4294967296.0*QueryPerformanceCounterResult.HighPart)/frequency;
#endif
        
    if ((m_surfaceSize.cx==0  && m_surfaceSize.cy == 0)  || HX_BLT_YUV_STRETCH != m_nBltMode )
    {
        return HXR_FAIL;
    }
        
    CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
    WINDRAW* pWindraw = pSurface->GetWinDraw();
        
    HX_RESULT retVal = HXR_FAIL;
        
    if (NOERROR == WinDrawSurface_Blt(pWindraw, &m_surface, (RECT*)&rDestRect, (RECT*)&rSrcRect))
    {
        retVal = HXR_OK;        
    }
        
#ifdef _CHECK_PERFORMANCE
    QueryPerformanceCounter(&QueryPerformanceCounterResult);
    double endTime = ((double)QueryPerformanceCounterResult.LowPart + 4294967296.0*QueryPerformanceCounterResult.HighPart)/frequency;
        
    static UINT32 z_nNumTimes = 0;
    static double z_fTotalTime;
    static double z_fAverageTime;
        
    z_nNumTimes++;
    z_fTotalTime += endTime - startTime;
    z_fAverageTime = z_fTotalTime / (double) z_nNumTimes;
        
    if (! (z_nNumTimes % 25))
    {
        FILE* f1 = ::fopen("c:\\performance.txt", "a+"); /* Flawfinder: ignore */
        ::fprintf(f1, "WINDRAW2 - BltToPrimary: %d blts. Total CPU time: %f, CPU/Blt: %f -- Blt/s Second Max: %f\n", z_nNumTimes, z_fTotalTime, z_fAverageTime, 1.0/z_fAverageTime);
        fclose(f1);
    }
#endif
    return retVal;
}

HX_RESULT CWinSurface::_LockInternalSurface(UCHAR** ppSurfPtr, LONG* pnSurfPitch, REF(HXxSize) srcSize)
{
    HX_RESULT ret = HXR_OK;
    IDirectDrawSurface *pBackBuffer = NULL;
    
    CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
    WINDRAW* pWindraw = pSurface->GetWinDraw();

    //See comments in _UnlockInternalSurface below.....
    if( m_bVideoSurface2 && m_surface.dd.lpDDBackBuffer )
    {
        pBackBuffer = m_surface.dd.lpDDBackBuffer;
        m_surface.dd.lpDDBackBuffer = NULL;
    }

    if (NOERROR == WinDrawSurface_Lock(pWindraw, &m_surface, 0, (void**) ppSurfPtr, pnSurfPitch))
        ret =  HXR_OK;
    else
        ret = HXR_FAIL;

⌨️ 快捷键说明

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