winsurf.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:18k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: winsurf.cpp,v 1.3.34.2 2004/07/26 10:28:31 pankajgupta Exp $
  3.  *
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  *
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  *
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  *
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  *
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  *
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  *
  46.  * Contributor(s):
  47.  *
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hxtypes.h"
  50. #include <math.h>
  51. #include "ddraw.h"
  52. #include "hxcom.h"
  53. #include "hxwintyp.h"
  54. #include "hxvsurf.h"
  55. #include "hxslist.h"
  56. #include "winsurf.h"
  57. #include "winsite.h"
  58. #include "colormap.h"
  59. #include "hxprefs.h"
  60. #include "hxtick.h"
  61. #include "hxheap.h"
  62. #include "hxevent.h"
  63. // these are defined in basesurf.cpp and should probably be moved to a .h file
  64. #define HX_OVER_KEYDEST    1
  65. #define HX_OVER_HIDE       2
  66. #define HX_OVER_SHOW       4
  67. #define OVERLAY_NOT_VISIBLE 0
  68. #ifdef _DEBUG
  69. #undef HX_THIS_FILE
  70. static const char HX_THIS_FILE[] = __FILE__;
  71. #include "winthrd.h"
  72. #endif
  73. CWinSurface::CWinSurface(IUnknown* pContext, CHXBaseSite* pSite) :
  74.     CBaseSurface(pContext,pSite)
  75.  ,  m_nBitsPerPixel(0)
  76.  ,  m_nHozRes(0)
  77.  ,  m_nVertRes(0)
  78.  ,  m_nLastBltMode(HX_NO_BLT)
  79. {
  80.     // initialize data so we don't have invalid ptrs floating around.
  81.     memset(&m_surface,0,sizeof(m_surface));
  82. }
  83. CWinSurface::~CWinSurface()
  84. {
  85. }
  86. void CWinSurface::_ReleaseSurface(CBaseRootSurface* pSurface)
  87. {
  88.     WINDRAW* pWindraw = ((CWinBaseRootSurface*)pSurface)->GetWinDraw();
  89.     WinDraw2_ReleaseSurface(pWindraw, &m_surface);
  90.     m_nLastBltMode = HX_NO_BLT;
  91. }
  92. void CWinSurface::_ReleaseSurface(CWinBaseRootSurface* pSurface)
  93. {
  94.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  95.     WinDraw2_ReleaseSurface(pWindraw, &m_surface);
  96.     m_nLastBltMode = HX_NO_BLT;
  97. }
  98. void CWinSurface::_DrawBlack(void* pWindow)
  99. {
  100. }
  101. void CWinSurface::_CreateBuffer()
  102. {
  103.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  104.     pSurface->OpenWindraw();
  105.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  106.     BMI bmi;
  107.     memset(&bmi, 0, sizeof(BMI));
  108.     WinDraw2_GetDisplayFormat(pWindraw, &bmi);
  109.     int cid = GetBitmapColor((LPBITMAPINFO)&bmi);
  110.     memset(&bmi, 0, sizeof(BMI));
  111.     MakeBitmap((LPBITMAPINFO)&bmi, sizeof(BMI), cid, m_pOptimizedFormat->biWidth, m_pOptimizedFormat->biHeight, NULL, NULL);
  112.     memset(&m_surface, 0, sizeof(WINDRAWSURFACE));
  113.     if (NOERROR == WinDraw2_CreateSurface(pWindraw, &m_surface, &bmi, pSurface->GetSurfaceType(), 0, 0))
  114.     {
  115.         m_surfaceSize.cx = m_pOptimizedFormat->biWidth;
  116.         m_surfaceSize.cy = m_pOptimizedFormat->biHeight;
  117.         m_nSurfaceCID = cid;
  118.         m_nBltMode = HX_BLT_YUV_STRETCH;
  119.         if (!m_nBitsPerPixel ||
  120.             !m_nHozRes ||
  121.             !m_nVertRes)
  122.         {
  123.             // Store the display mode we were created in.
  124.             m_pSite->_GetDeviceCaps(NULL, m_nBitsPerPixel, m_nHozRes, m_nVertRes);
  125.         }
  126.     }
  127. }
  128. HX_RESULT CWinSurface::_GetCaps(UINT32 *pfSurfaceCaps)
  129. {
  130.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  131.     pSurface->OpenWindraw();
  132.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  133.     //    UINT32 fSurfaceCaps;
  134.     UINT32 garbagea, garbageb;
  135.     if (NOERROR != Windraw_GetCaps(pWindraw, pfSurfaceCaps, &garbagea, &garbageb))
  136.     {
  137.         return HXR_FAIL;
  138.     }
  139.     else
  140.     {
  141.         return HXR_OK;
  142.     }
  143. }
  144. HX_RESULT CWinSurface::_CreateOverlay(BOOL bOverlay, int cid, int x, int y)
  145. {
  146.     //Get our windraw object from the root surface
  147.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  148.     HX_ASSERT( pSurface );
  149.     if( !pSurface )
  150.         return HXR_FAIL;
  151.     pSurface->OpenWindraw();
  152.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  153.     BMI bmi;
  154.     memset(&bmi, 0, sizeof(BMI));
  155.     MakeBitmap((LPBITMAPINFO)&bmi, sizeof(BMI), cid, x, y, NULL, NULL);
  156.     memset(&m_surface, 0, sizeof(WINDRAWSURFACE));
  157.     int fFlags = 0;
  158.     if (bOverlay)
  159.     {
  160.         fFlags = WINDRAWSURFACE_DIRECTDRAW | WINDRAWSURFACE_OVERLAY | WINDRAWSURFACE_VIDEOMEMORY;
  161.     }
  162.     else
  163.     {
  164.         fFlags = WINDRAWSURFACE_DIRECTDRAW | WINDRAWSURFACE_DEFAULTMEMORY;
  165.     }
  166.     int numBuffers = (m_bFlipOverlay && bOverlay) ? m_nBackBufferCount+1 : 1;
  167.     for (; numBuffers; numBuffers--)
  168.     {
  169.         if (NOERROR == WinDraw2_CreateSurface(pWindraw, &m_surface, &bmi, fFlags, numBuffers-1, 0))
  170.         {
  171.             m_nDDSurfaceSize = bmi.bmiHeader.biSizeImage;
  172.             m_surfaceSize.cx = x;
  173.             m_surfaceSize.cy = y;
  174.             m_nSurfaceCID = cid;
  175.             m_nBackBufferCount = numBuffers-1;
  176.             if (bOverlay)
  177.             {
  178.                 m_nBltMode = HX_OVERLAY_BLT;
  179.             }
  180.             else
  181.             {
  182.                 m_nBltMode = HX_BLT_YUV_STRETCH;
  183.             }
  184.             UpdateDestRect();
  185.             if (!m_nBitsPerPixel ||
  186.                 !m_nHozRes ||
  187.                 !m_nVertRes)
  188.             {
  189.                 // Store the display mode we were created in.
  190.                 m_pSite->_GetDeviceCaps(NULL, m_nBitsPerPixel, m_nHozRes, m_nVertRes);
  191.             }
  192.             return HXR_OK;
  193.         }
  194.     }
  195.     return HXR_FAIL;
  196. }
  197. HX_RESULT CWinSurface::_BltToPrimary(REF(HXxRect) rDestRect, REF(HXxRect) rSrcRect)
  198. {
  199. #ifdef _CHECK_PERFORMANCE
  200.     static LARGE_INTEGER QueryPerformanceCounterResult = {0,0};
  201.     static LARGE_INTEGER QueryPerformanceFrequencyResult = {0,0};
  202.     QueryPerformanceFrequency(&QueryPerformanceFrequencyResult);
  203.     double frequency = ((double)QueryPerformanceFrequencyResult.LowPart + 4294967296.0*QueryPerformanceFrequencyResult.HighPart);
  204.     QueryPerformanceCounter(&QueryPerformanceCounterResult);
  205.     double startTime = ((double)QueryPerformanceCounterResult.LowPart + 4294967296.0*QueryPerformanceCounterResult.HighPart)/frequency;
  206. #endif
  207.     if ((m_surfaceSize.cx==0  && m_surfaceSize.cy == 0)  || HX_BLT_YUV_STRETCH != m_nBltMode )
  208.     {
  209.         return HXR_FAIL;
  210.     }
  211.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  212.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  213.     HX_RESULT retVal = HXR_FAIL;
  214.     if (NOERROR == WinDrawSurface_Blt(pWindraw, &m_surface, (RECT*)&rDestRect, (RECT*)&rSrcRect))
  215.     {
  216.         retVal = HXR_OK;
  217.     }
  218. #ifdef _CHECK_PERFORMANCE
  219.     QueryPerformanceCounter(&QueryPerformanceCounterResult);
  220.     double endTime = ((double)QueryPerformanceCounterResult.LowPart + 4294967296.0*QueryPerformanceCounterResult.HighPart)/frequency;
  221.     static UINT32 z_nNumTimes = 0;
  222.     static double z_fTotalTime;
  223.     static double z_fAverageTime;
  224.     z_nNumTimes++;
  225.     z_fTotalTime += endTime - startTime;
  226.     z_fAverageTime = z_fTotalTime / (double) z_nNumTimes;
  227.     if (! (z_nNumTimes % 25))
  228.     {
  229.         FILE* f1 = ::fopen("c:\performance.txt", "a+"); /* Flawfinder: ignore */
  230.         ::fprintf(f1, "WINDRAW2 - BltToPrimary: %d blts. Total CPU time: %f, CPU/Blt: %f -- Blt/s Second Max: %fn", z_nNumTimes, z_fTotalTime, z_fAverageTime, 1.0/z_fAverageTime);
  231.         fclose(f1);
  232.     }
  233. #endif
  234.     return retVal;
  235. }
  236. HX_RESULT CWinSurface::_LockInternalSurface(UCHAR** ppSurfPtr, LONG* pnSurfPitch, REF(HXxSize) srcSize)
  237. {
  238.     HX_RESULT ret = HXR_OK;
  239.     IDirectDrawSurface *pBackBuffer = NULL;
  240.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  241.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  242.     //See comments in _UnlockInternalSurface below.....
  243.     if( m_bVideoSurface2 && m_surface.dd.lpDDBackBuffer )
  244.     {
  245.         pBackBuffer = m_surface.dd.lpDDBackBuffer;
  246.         m_surface.dd.lpDDBackBuffer = NULL;
  247.     }
  248.     if (NOERROR == WinDrawSurface_Lock(pWindraw, &m_surface, 0, (void**) ppSurfPtr, pnSurfPitch))
  249.         ret =  HXR_OK;
  250.     else
  251.         ret = HXR_FAIL;
  252.     if (pBackBuffer)
  253.         m_surface.dd.lpDDBackBuffer = pBackBuffer;
  254.     return ret;
  255. }
  256. // Note that the pSurfPtr is not used... but other implementations will
  257. // probbaly use it.
  258. HX_RESULT CWinSurface::_UnlockInternalSurface(UCHAR* pSurfPtr)
  259. {
  260.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  261.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  262.     if (m_pSite->HasFocusRect())
  263.     {
  264.         pSurface->DrawFocusRect(//&m_surface,
  265.             m_nSurfaceCID,
  266.             &m_surfaceSize,
  267.             pSurfPtr,
  268.             m_pSite);
  269.     }
  270.     IDirectDrawSurface *pBackBuffer = NULL;
  271.     //This is a VS1 only call. If we are calling this and we are in
  272.     //VS2 mode then it means we are sharing the overlay.
  273.     //VS1 only uses the front buffer and so we need to hide the back
  274.     //buffer from VS1 to keep the flip from happening.
  275.     //PR70865, Fixes the 'shaking' bug.
  276.     if( m_bVideoSurface2 && m_surface.dd.lpDDBackBuffer )
  277.     {
  278.         //XXXgfw This assumes that VS1 *NEVER* uses a flipping chain.
  279.         pBackBuffer = m_surface.dd.lpDDBackBuffer;
  280.         m_surface.dd.lpDDBackBuffer = NULL;
  281.     }
  282.     WinDrawSurface_Unlock(pWindraw, &m_surface, 0);
  283.     if (pBackBuffer)
  284.         m_surface.dd.lpDDBackBuffer = pBackBuffer;
  285.     return HXR_OK;
  286. }
  287. void CWinSurface::_SetupDCObjects(HXxDC hxxDC, void** phOldBrush, void** phOldPen)
  288. {
  289.     HDC hdc = (HDC) hxxDC;
  290.     LOGBRUSH brush;
  291.     brush.lbStyle = BS_SOLID;
  292.     brush.lbColor = GetOverlayColor();
  293.     brush.lbHatch = 0;
  294.     HBRUSH  hBrush      = (HBRUSH)CreateBrushIndirect(&brush);
  295.     HPEN    hPen        = (HPEN)CreatePen(PS_SOLID, 1, GetOverlayColor());
  296.     *phOldBrush         = (void*)SelectObject(hdc, hBrush);
  297.     *phOldPen           = (void*)SelectObject(hdc, hPen);
  298. }
  299. void CWinSurface::_FillRectangle(HXxDC hxxDC, UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
  300. {
  301.     HDC hdc = (HDC)hxxDC;
  302.     LOGBRUSH brush;
  303.     brush.lbStyle = BS_SOLID;
  304. //  Do NOT use _InsureColorMatch() here.  This color must be RGB(8,8,8) format and _InsureColorMatch()
  305. //  will return a different format if display isn't in 24 or 32-bit mode.
  306.     brush.lbColor = GetOverlayColor();
  307.     brush.lbHatch = 0;
  308.     HBRUSH  hBrush      = (HBRUSH)CreateBrushIndirect(&brush);
  309.     HPEN    hPen        = (HPEN)CreatePen(PS_SOLID, 1, brush.lbColor);
  310.     HBRUSH  hOldBrush   = (HBRUSH)SelectObject(hdc, hBrush);
  311.     HPEN    hOldPen     = (HPEN)SelectObject(hdc, hPen);
  312.     Rectangle(hdc, left, top, right, bottom);
  313.     SelectObject(hdc, hOldBrush);
  314.     SelectObject(hdc, hOldPen);
  315.     DeleteObject(hBrush);
  316.     DeleteObject(hPen);
  317. }
  318. void CWinSurface::_RestoreDCObjects(HXxDC hxxDC, void* hOldBrush, void* hOldPen)
  319. {
  320.     HBRUSH hBrush = (HBRUSH)SelectObject((HDC) hxxDC, (HBRUSH) hOldBrush);
  321.     HPEN hPen = (HPEN)SelectObject((HDC) hxxDC, (HPEN) hOldPen);
  322.     DeleteObject(hBrush);
  323.     DeleteObject(hPen);
  324. }
  325. void CWinSurface::_GetCompositionSurfaceHXxDC(HXxDC *hdc)
  326. {
  327.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  328.     WINDRAWSURFACE* pDrawSurface = pSurface->GetCompositionSurface();
  329.     WINDRAW*    pWindraw = pSurface->GetWinDraw();
  330.     WinDrawSurface_GetDC(pWindraw, pDrawSurface, (HDC*)hdc);
  331.     // XXXAH Huh? Fix this up!
  332. }
  333. void CWinSurface::_ReleaseCompositionSurfaceHXxDC(HXxDC hdc)
  334. {
  335.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  336.     WINDRAWSURFACE* pDrawSurface = pSurface->GetCompositionSurface();
  337.     WINDRAW*    pWindraw = pSurface->GetWinDraw();
  338.     WinDrawSurface_ReleaseDC(pWindraw, pDrawSurface, (HDC)hdc);
  339. }
  340. INT32 CWinSurface::_InsureColorMatch(INT32 InColor)
  341. {
  342.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  343.     WINDRAW*    pWindraw = pSurface->GetWinDraw();
  344.     return Windraw_ColorMatch(pWindraw, InColor);
  345. }
  346. void CWinSurface::_SetColorKey(INT32 nColorSpaceLowValue, INT32 nColorSpaceHighValue)
  347. {
  348.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  349.     WINDRAW*    pWindraw = pSurface->GetWinDraw();
  350.     HRESULT hr = WinDraw2_SetColorKey(pWindraw, m_convertedOverlayColor, m_convertedOverlayColor);
  351. }
  352. void CWinSurface::_UpdateOverlay(HXxRect* dest, HXxRect* src, INT32 inFlags)
  353. {
  354.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  355.     WINDRAW*    pWindraw = pSurface->GetWinDraw();
  356.     // convert flags.
  357.     INT32 flags = 0;
  358.     if (inFlags & HX_OVER_KEYDEST)
  359.     {
  360.         flags |= DDOVER_KEYDEST;
  361.     }
  362.     if (inFlags & HX_OVER_HIDE)
  363.     {
  364.         flags |= DDOVER_HIDE;
  365.     }
  366.     if (inFlags & HX_OVER_SHOW)
  367.     {
  368.         flags |= DDOVER_SHOW;
  369.     }
  370.     HRESULT hr = WinDraw2_UpdateOverlay(pWindraw, &m_surface, (RECT*)dest, (RECT*)src, flags);
  371.     // We can only have one visible overlay and someone else has it :(
  372.     // Drop to offscreen mode.
  373.     if (DDERR_OUTOFCAPS == hr)
  374.     {
  375.         m_nBltMode = HX_BASIC_BLT;
  376.         m_bMultipleOverlay = !m_bLostHWAcceleration;//TRUE;
  377.     }
  378.     // If we lost/restored our surfaces, the video will be garbage so force
  379.     // a redraw.
  380.     else if (DDERR_SURFACELOST == hr)
  381.         m_nLastBltMode = HX_NO_BLT;
  382. }
  383. BOOL CWinSurface::_IsSurfaceVisible()
  384. {
  385.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  386.     if (!pSurface)
  387.         return FALSE;
  388.     WINDRAW* pWindraw = pSurface->GetWinDraw();
  389.     return WinDraw2_IsSurfaceVisible(pWindraw, &m_surface);
  390. }
  391. void CWinSurface::_ReleaseSurface()
  392. {
  393.     CWinBaseRootSurface* pSurface = (CWinBaseRootSurface*)m_pSite->GetRootSurface();
  394.     if (pSurface)
  395.     {
  396.         WINDRAW* pWindraw = pSurface->GetWinDraw();
  397.         if (pWindraw)
  398.         {
  399.             WinDraw2_ReleaseSurface(pWindraw, &m_surface);
  400.         }
  401.     }
  402.     m_nLastBltMode = HX_NO_BLT;
  403. }
  404. HXxDC CWinSurface::_GetDC(HXxWindow* pWindow)
  405. {
  406.     HWND hwnd = (HWND) pWindow->window;
  407.     return     (HXxDC) GetDC(hwnd);
  408. }
  409. void CWinSurface::_ReleaseDC(HXxWindow* pWindow, HXxDC hdc)
  410. {
  411.     HWND hwnd = (HWND) pWindow->window;
  412.     ReleaseDC(hwnd, (HDC)hdc);
  413. }
  414. void CWinSurface::_GetWindowDeviceCords(HXxRect* rect)
  415. {
  416.     HXxWindow* pWin = m_pSite->GetWindow();
  417.     if( pWin )
  418.     {
  419.         HWND hwnd = (HWND) pWin->window;
  420.         GetWindowRect(hwnd,(RECT*)rect);
  421.     }
  422. }
  423. HX_RESULT CWinSurface::RelinquishOverlay()
  424. {
  425.     return CBaseSurface::RelinquishOverlay();
  426. }
  427. HX_RESULT CWinSurface::AcquireOverlay()
  428. {
  429.     return CBaseSurface::AcquireOverlay();
  430. }
  431. void CWinSurface::_ColorWindows()
  432. {
  433.     int index = m_pSite->m_pTopLevelSite->m_nWindowColor++;
  434.     if (m_pSite && m_pSite->GetWindow())
  435.     {
  436.         HWND hwnd = (HWND) (m_pSite->GetWindow())->window;
  437.         HDC hdc = GetDC(hwnd);
  438.         LOGBRUSH logBrush;
  439.         logBrush.lbStyle = BS_SOLID;
  440.         UCHAR red   =  (index) * 16;
  441.         UCHAR green =  (index+5) * 16;
  442.         UCHAR blue  =  (index+10) * 16;
  443.         logBrush.lbColor = (red << 16) | (green <<8) | blue;
  444.         logBrush.lbHatch = 0;
  445.         HBRUSH brush = CreateBrushIndirect(&logBrush);
  446.         HBRUSH oldBrush = (HBRUSH) SelectObject(hdc, brush);
  447.         Rectangle(hdc, 0,0, 1000, 1000);
  448.         SelectObject(hdc, oldBrush);
  449.         DeleteObject(brush);
  450.         ReleaseDC(hwnd, hdc);
  451.         RECT rect;
  452.         ::GetWindowRect(hwnd, &rect);
  453.         FILE* f = fopen("c:\color.txt", "a+"); /* Flawfinder: ignore */
  454.         fprintf(f, "%p HWND %p %p (%d, %d, %d, %d)n", this, hwnd, logBrush.lbColor, rect.left, rect.top, rect.right, rect.bottom);
  455.         HRGN r = CreateRectRgn(0,0,0,0);
  456.         GetWindowRgn( hwnd, r);
  457.         DWORD dwCount = GetRegionData( r, 0, 0);
  458.         char* p = (char* ) calloc(dwCount, 1);
  459.         LPRGNDATA pdata = (LPRGNDATA)p;
  460.         DWORD ret = GetRegionData( r, dwCount, pdata);
  461.         fprintf(f, "tCount: %d Size: %dn", pdata->rdh.nCount, dwCount);
  462.         RECT* pr = (RECT*)pdata->Buffer;
  463.         for(int i = 0; i< pdata->rdh.nCount; i++)
  464.             fprintf(f, "tt(%d, %d, %d, %d)n", pr[i]);
  465.         DeleteObject(r);
  466.         free(p);
  467.         fclose(f);
  468.     }
  469. }
  470. BOOL  CWinSurface::UsingOverlay()
  471. {
  472.     if (m_surface.fMode & WINDRAWSURFACE_OVERLAY)
  473.     {
  474.         return TRUE;
  475.     }
  476.     if (m_pLinkedOverlay)
  477.     {
  478.         return m_pLinkedOverlay->UsingOverlay();
  479.     }
  480.     return FALSE;
  481. }