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

Symbian

开发平台:

Visual C++

  1. STDMETHODIMP CHXBaseSite::SetSharpness(float sharpness)
  2. {
  3.     if (m_pParentSite)
  4.     {
  5.         return m_pParentSite->SetSharpness(sharpness);
  6.     }
  7.     m_fSharpness = sharpness;
  8.     ScheduleCallback(REPAINT, 0);
  9.     return HXR_OK;
  10. }
  11. STDMETHODIMP CHXBaseSite::SetModeSharpness(UINT16 dFlag)
  12. {
  13.     m_bModeSharpness = dFlag;
  14.     return HXR_OK;
  15. }
  16. STDMETHODIMP_(BOOL) CHXBaseSite::IsInterruptSafe()
  17. {
  18.     return TRUE;
  19. }
  20. STDMETHODIMP CHXBaseSite::SetKeyboardFocus(IHXSiteUser* pSiteUser)
  21. {
  22. #ifdef FUTURE_WORKING_FOCUS
  23.     if (m_pTopLevelSite->m_pKeyBoardFocusUser)
  24.     {
  25.         HXxEvent event = {HX_LOSE_FOCUS, m_pWindow ? m_pWindow->window : NULL, NULL, NULL, 0, 0};
  26.         m_pTopLevelSite->m_pKeyBoardFocusUser->HandleEvent(&event);
  27.         m_pTopLevelSite->m_pKeyBoardFocusUser->Release();
  28.         m_pTopLevelSite->m_pKeyBoardFocusUser = NULL;
  29.     }
  30.     if (pSiteUser)
  31.     {
  32.         m_pTopLevelSite->m_pKeyBoardFocusUser = pSiteUser;
  33.         m_pTopLevelSite->m_pKeyBoardFocusUser->AddRef();
  34.         HXxEvent event = {HX_SET_FOCUS, m_pWindow ? m_pWindow->window : NULL, NULL, NULL, 0, 0};
  35.         m_pTopLevelSite->m_pKeyBoardFocusUser->HandleEvent(&event);
  36.     }
  37. #else
  38.     HXxWindow* pFocusWindow = GetWindow();
  39.     if(pFocusWindow && pFocusWindow->window)
  40.     {
  41.         SafeSetFocus(pFocusWindow);
  42.     }
  43. #endif // FUTURE_WORKING_FOCUS
  44.     return HXR_OK;
  45. }
  46. STDMETHODIMP CHXBaseSite::GetKeyboardFocus(IHXSiteUser* &pSiteUser)
  47. {
  48.     pSiteUser = m_pTopLevelSite->m_pKeyBoardFocusUser;
  49.     if (pSiteUser)
  50.     {
  51.         pSiteUser->AddRef();
  52.         return HXR_OK;
  53.     }
  54.     else
  55.         return HXR_FAILED;
  56. }
  57. STDMETHODIMP CHXBaseSite::SetStyle(IHXValues* pProperties)
  58. {
  59.     // Map IHXValues to drawing properties
  60.     ULONG32 ulTemp = HX_SOLID_LINE;
  61.     pProperties->GetPropertyULONG32("LINE_STYLE", ulTemp);
  62.     m_rcFocusRect.ulLineStyle = ulTemp;
  63.     // Store custom line pattern
  64.     HX_RELEASE(m_rcFocusRect.pCustomPattern);
  65.     m_rcFocusRect.ulCustomEntries = 0;
  66.     if (ulTemp == HX_CUSTOM_LINE)
  67.     {
  68.         pProperties->GetPropertyBuffer("CUSTOM_LINE_PATTERN", m_rcFocusRect.pCustomPattern);
  69.         if (m_rcFocusRect.pCustomPattern)
  70.         {
  71.             m_rcFocusRect.pCustomPattern->AddRef();
  72.             ulTemp = 0;
  73.             pProperties->GetPropertyULONG32("CUSTOM_LINE_ENTRIES", ulTemp);
  74.             m_rcFocusRect.ulCustomEntries = ulTemp;
  75.         }
  76.     }
  77.     // Store line width
  78.     ulTemp = 1;
  79.     pProperties->GetPropertyULONG32("LINE_WIDTH", ulTemp);
  80.     m_rcFocusRect.ulLineWidth = ulTemp;
  81.     // Store primary color
  82.     ulTemp = 0;
  83.     pProperties->GetPropertyULONG32("RED", ulTemp);
  84.     m_rcFocusRect.red = (UINT8)ulTemp;
  85.     ulTemp = 0;
  86.     pProperties->GetPropertyULONG32("GREEN", ulTemp);
  87.     m_rcFocusRect.green = (UINT8)ulTemp;
  88.     ulTemp = 0;
  89.     pProperties->GetPropertyULONG32("BLUE", ulTemp);
  90.     m_rcFocusRect.blue = (UINT8)ulTemp;
  91.     m_rcFocusRect.bSecondaryColors = FALSE;
  92.     // Store secondary color
  93.     ulTemp = 0;
  94.     if (HXR_OK == pProperties->GetPropertyULONG32("RED2", ulTemp))
  95.         m_rcFocusRect.bSecondaryColors = TRUE;
  96.     m_rcFocusRect.red2 = (UINT8)ulTemp;
  97.     ulTemp = 0;
  98.     if (HXR_OK == pProperties->GetPropertyULONG32("GREEN2", ulTemp))
  99.         m_rcFocusRect.bSecondaryColors = TRUE;
  100.     m_rcFocusRect.green2 = (UINT8)ulTemp;
  101.     ulTemp = 0;
  102.     if (HXR_OK == pProperties->GetPropertyULONG32("BLUE2", ulTemp))
  103.         m_rcFocusRect.bSecondaryColors = TRUE;
  104.     m_rcFocusRect.blue2 = (UINT8)ulTemp;
  105.     return HXR_OK;
  106. }
  107. STDMETHODIMP CHXBaseSite::ClearFocus()
  108. {
  109.     m_rcFocusRect.bRectActive = FALSE;
  110.     // Clear the focus rect but preserve the properties
  111.     if (m_rcFocusRect.ulShape & DRAW_POLYGON)
  112.     {
  113.         m_rcFocusRect.ulShape &= ~DRAW_POLYGON;
  114.         if (m_rcFocusRect.polygon.pFocusPoints)
  115.         {
  116.             delete [] m_rcFocusRect.polygon.pFocusPoints;
  117.             m_rcFocusRect.polygon.pFocusPoints = NULL;
  118.             m_rcFocusRect.polygon.ulFocusPoints = 0;
  119.         }
  120.     }
  121.     else
  122.     {
  123.         m_rcFocusRect.ulShape &= ~DRAW_RECT;
  124.         m_rcFocusRect.ulShape &= ~DRAW_ELLIPSE;
  125.         memset(&m_rcFocusRect.rcFocus, 0, sizeof(m_rcFocusRect.rcFocus));
  126.     }
  127.     return HXR_OK;
  128. }
  129. STDMETHODIMP CHXBaseSite::SetFocusPolygon(HXxPoint* pPoints, ULONG32 numPoints)
  130. {
  131.     if (!m_rcFocusRect.ulLineWidth)
  132.         return HXR_FAIL;
  133.     if (m_rcFocusRect.bRectActive)
  134.         ClearFocus();
  135.     m_rcFocusRect.polygon.ulFocusPoints = numPoints;
  136.     m_rcFocusRect.polygon.pFocusPoints = new HXxPoint[numPoints];
  137.     m_rcFocusRect.ulShape |= DRAW_POLYGON;
  138.     for (ULONG32 i=0; i<numPoints; i++)
  139.         m_rcFocusRect.polygon.pFocusPoints[i] = pPoints[i];
  140.     m_rcFocusRect.bRectActive = TRUE;
  141.     return HXR_OK;
  142. }
  143. STDMETHODIMP CHXBaseSite::SetFocusRect(HXxRect* pRect)
  144. {
  145.     if (!m_rcFocusRect.ulLineWidth)
  146.         return HXR_FAIL;
  147.     if (m_rcFocusRect.bRectActive)
  148.         ClearFocus();
  149.     m_rcFocusRect.rcFocus = *pRect;
  150.     m_rcFocusRect.ulShape |= DRAW_RECT;
  151.     m_rcFocusRect.bRectActive = TRUE;
  152.     return HXR_OK;
  153. }
  154. STDMETHODIMP CHXBaseSite::SetFocusEllipse(HXxRect* pRect)
  155. {
  156.     if (!m_rcFocusRect.ulLineWidth)
  157.         return HXR_FAIL;
  158.     if (m_rcFocusRect.bRectActive)
  159.         ClearFocus();
  160.     m_rcFocusRect.rcFocus = *pRect;
  161.     m_rcFocusRect.ulShape |= DRAW_ELLIPSE;
  162.     m_rcFocusRect.bRectActive = TRUE;
  163.     return HXR_OK;
  164. }
  165. void CHXBaseSite::_DrawFocusRect(UCHAR* pImage,
  166.                                  HXBitmapInfoHeader* pImageInfo,
  167.                                  HXxRect* pImageRect,
  168.                                  void* pOsSpecificData)
  169. {
  170.     // Do we have an active rect
  171.     if (!m_rcFocusRect.bRectActive)
  172.         return;
  173.     // Only support rgb for now
  174.     if (IsYUV(GETBITMAPCOLOR(pImageInfo)))
  175.         return;
  176.     int *pUpperLeft = (int*)pImage + (pImageRect->left + pImageRect->top) * pImageInfo->biBitCount/8;
  177.     INT32 nStyle = SOLID_LINE;
  178.     if (m_rcFocusRect.ulLineStyle == HX_DASHED_LINE)
  179.         nStyle = DASHED_LINE;
  180.     else if (m_rcFocusRect.ulLineStyle == HX_DOTTED_LINE)
  181.         nStyle = DOTTED_LINE;
  182.     else if (m_rcFocusRect.ulLineStyle == HX_CUSTOM_LINE)
  183.         nStyle = CUSTOM_LINE;
  184.     INT32 *pCustomPattern = NULL;
  185.     if (m_rcFocusRect.pCustomPattern)
  186.         pCustomPattern = (INT32*)(m_rcFocusRect.pCustomPattern->GetBuffer());
  187.     PixelProps primary = {m_rcFocusRect.red,
  188.                           m_rcFocusRect.green,
  189.                           m_rcFocusRect.blue,
  190.                           TRUE};
  191.     PixelProps secondary = {m_rcFocusRect.red2,
  192.                             m_rcFocusRect.green2,
  193.                             m_rcFocusRect.blue2,
  194.                             m_rcFocusRect.bSecondaryColors};
  195.     // Draw the rect into the pImage
  196.     if (m_rcFocusRect.ulShape & DRAW_RECT)
  197.     {
  198.         StraightLine((void*)pImage,
  199.                      GETBITMAPPITCH(pImageInfo),
  200.                      pImageInfo->biBitCount,
  201.                      pImageRect->right-pImageRect->left,
  202.                      pImageRect->bottom-pImageRect->top,
  203.                      m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.top,
  204.                      m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.top,
  205.                      (UINT8)m_rcFocusRect.ulLineWidth,
  206.                      &primary, &secondary,
  207.                      nStyle,
  208.                      pCustomPattern, m_rcFocusRect.ulCustomEntries);
  209.         StraightLine((void*)pImage,
  210.                      GETBITMAPPITCH(pImageInfo),
  211.                      pImageInfo->biBitCount,
  212.                      pImageRect->right-pImageRect->left,
  213.                      pImageRect->bottom-pImageRect->top,
  214.                      m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.top,
  215.                      m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.bottom,
  216.                      (UINT8)m_rcFocusRect.ulLineWidth,
  217.                      &primary, &secondary,
  218.                      nStyle,
  219.                      pCustomPattern, m_rcFocusRect.ulCustomEntries);
  220.         StraightLine((void*)pImage,
  221.                      GETBITMAPPITCH(pImageInfo),
  222.                      pImageInfo->biBitCount,
  223.                      pImageRect->right-pImageRect->left,
  224.                      pImageRect->bottom-pImageRect->top,
  225.                      m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.bottom,
  226.                      m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.bottom,
  227.                      (UINT8)m_rcFocusRect.ulLineWidth,
  228.                      &primary, &secondary,
  229.                      nStyle,
  230.                      pCustomPattern, m_rcFocusRect.ulCustomEntries);
  231.         StraightLine((void*)pImage,
  232.                      GETBITMAPPITCH(pImageInfo),
  233.                      pImageInfo->biBitCount,
  234.                      pImageRect->right-pImageRect->left,
  235.                      pImageRect->bottom-pImageRect->top,
  236.                      m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.bottom,
  237.                      m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.top,
  238.                      (UINT8)m_rcFocusRect.ulLineWidth,
  239.                      &primary, &secondary,
  240.                      nStyle,
  241.                      pCustomPattern, m_rcFocusRect.ulCustomEntries);
  242.     }
  243.     else if (m_rcFocusRect.ulShape & DRAW_ELLIPSE)
  244.     {
  245.     }
  246.     else if (m_rcFocusRect.ulShape & DRAW_POLYGON)
  247.     {
  248.         UINT32 i=0;
  249.         for (i=0; i<m_rcFocusRect.polygon.ulFocusPoints-1; i++)
  250.         {
  251.             StraightLine((void*)pImage,
  252.                          GETBITMAPPITCH(pImageInfo),
  253.                          pImageInfo->biBitCount,
  254.                          pImageRect->right-pImageRect->left,
  255.                          pImageRect->bottom-pImageRect->top,
  256.                          m_rcFocusRect.polygon.pFocusPoints[i].x, m_rcFocusRect.polygon.pFocusPoints[i].y,
  257.                          m_rcFocusRect.polygon.pFocusPoints[i+1].x, m_rcFocusRect.polygon.pFocusPoints[i+1].y,
  258.                          (UINT8)m_rcFocusRect.ulLineWidth,
  259.                          &primary, &secondary,
  260.                          nStyle,
  261.                          pCustomPattern, m_rcFocusRect.ulCustomEntries);
  262.         }
  263.         StraightLine((void*)pImage,
  264.                      GETBITMAPPITCH(pImageInfo),
  265.                      pImageInfo->biBitCount,
  266.                      pImageRect->right-pImageRect->left,
  267.                      pImageRect->bottom-pImageRect->top,
  268.                      m_rcFocusRect.polygon.pFocusPoints[i].x, m_rcFocusRect.polygon.pFocusPoints[i].y,
  269.                      m_rcFocusRect.polygon.pFocusPoints[0].x, m_rcFocusRect.polygon.pFocusPoints[0].y,
  270.                      (UINT8)m_rcFocusRect.ulLineWidth,
  271.                      &primary, &secondary,
  272.                      nStyle,
  273.                      pCustomPattern, m_rcFocusRect.ulCustomEntries);
  274.     }
  275. }
  276. /************************************************************************
  277.  ************************************************************************
  278.  *                      INTERNAL HELPER FUNCTIONS
  279.  ************************************************************************
  280.  ************************************************************************/
  281. void CHXBaseSite::SetXSliderRange(INT32 range)
  282. {
  283.     _TryCreateXSlider();
  284.     if (m_XSliderRange != range)
  285.     {
  286.         if (m_XSliderRange)
  287.         {
  288.             m_XSliderPos = m_XSliderPos * range / m_XSliderRange;
  289.         }
  290.         HXxSize parentSize;
  291.         memset(&parentSize, 0, sizeof(HXxSize));
  292.         if (m_pParentSite)
  293.         {
  294.             m_pParentSite->GetSize(parentSize);
  295.         }
  296.         m_XSliderRange = range;
  297.         _SetXSliderValues(m_XSliderRange, parentSize.cx);
  298.     }
  299. }
  300. INT32 CHXBaseSite::GetXSliderRange()
  301. {
  302.     return m_XSliderRange;
  303. }
  304. INT32 CHXBaseSite::GetYSliderRange()
  305. {
  306.     return m_YSliderRange;
  307. }
  308. void CHXBaseSite::SetYSliderRange(INT32 range)
  309. {
  310.     _TryCreateYSlider();
  311.     if (m_YSliderRange != range)
  312.     {
  313.         if (m_YSliderRange)
  314.         {
  315.             m_YSliderPos = m_YSliderPos * range / m_YSliderRange;
  316.         }
  317.         HXxSize parentSize;
  318.         memset(&parentSize, 0, sizeof(HXxSize));
  319.         if (m_pParentSite)
  320.         {
  321.             m_pParentSite->GetSize(parentSize);
  322.         }
  323.         m_YSliderRange = range;
  324.         _SetYSliderValues(m_YSliderRange, parentSize.cy);
  325.     }
  326. }
  327. INT32 CHXBaseSite::GetXSliderPos()
  328. {
  329.     return m_XSliderPos;
  330. }
  331. INT32 CHXBaseSite::GetYSliderPos()
  332. {
  333.     return m_YSliderPos;
  334. }
  335. INT32 CHXBaseSite::GetSliderWidth()
  336. {
  337.     INT32 Width, Height;
  338.     _GetSystemSizeOfSliders(&Width, &Height);
  339.     return Width;
  340. }
  341. INT32 CHXBaseSite::GetSliderHeight()
  342. {
  343.     INT32 Width, Height;
  344.     _GetSystemSizeOfSliders(&Width, &Height);
  345.     return Height;
  346. }
  347. // XXXAH this function is pretty poorly named and I want to change it.
  348. // however in keeping with the idea behind this conversion (namely CHANGE
  349. // NOTHING on windows), I will leave it in here for the moment.
  350. void CHXBaseSite::GetWindowRect(HXxRect* pRect)
  351. {
  352.     if (m_RegionForMouse)
  353.     {
  354.         pRect->left   = m_Region->extents.x1;
  355.         pRect->top    = m_Region->extents.y1;
  356.         pRect->right  = m_Region->extents.x2;
  357.         pRect->bottom = m_Region->extents.y2;
  358.     }
  359. }
  360. void CHXBaseSite::GetExtentsWithoutChildren(HXxRect* pRect)
  361. {
  362.     if (m_RegionWithoutChildren)
  363.     {
  364.         pRect->left   = m_RegionWithoutChildren->extents.x1;
  365.         pRect->top    = m_RegionWithoutChildren->extents.y1;
  366.         pRect->right  = m_RegionWithoutChildren->extents.x2;
  367.         pRect->bottom = m_RegionWithoutChildren->extents.y2;
  368.     }
  369. }
  370. void CHXBaseSite::RecursiveSizeSliders()
  371. {
  372.     SizeSliders();
  373.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  374.     while(pos)
  375.     {
  376.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  377.         pSite->RecursiveSizeSliders();
  378.     }
  379. }
  380. void CHXBaseSite::SizeSliders()
  381. {
  382.     //Size the X slider 1st.
  383.     INT32 width;
  384.     INT32 height;
  385.     _GetSystemSizeOfSliders(&width, &height);
  386.     // The size of the SITE is the size of the bounding rect of the
  387.     // region.
  388.     HXxRect boundRect;
  389.     memset( &boundRect, 0, sizeof( HXxRect ) );
  390.     if (m_pParentSite)
  391.     {
  392.         m_pParentSite->GetExtentsWithoutChildren(&boundRect);
  393.     }
  394.     else
  395.     {
  396.         GetWindowRect(&boundRect);
  397.     }
  398.     // XXXAH why am I using this function? Will Have to check later to
  399.     // see why IHXSite2::IsSiteVisible is insufficient.  AHH I now
  400.     // remember this is due to a bug with the sliders appearing on TOP
  401.     // of the buffering animation.
  402.     BOOL siteVisible = _IsWindowVisible();
  403.     /*
  404.      *  Modify boundRect by the screen offset.
  405.      */
  406.     HXxPoint screenOffset;
  407.     if (m_pParentSite)
  408.     {
  409.         screenOffset = m_pParentSite->GetScreenOffset();
  410.     }
  411.     else
  412.     {
  413.         screenOffset = GetScreenOffset();
  414.     }
  415.     boundRect.left       += screenOffset.x;
  416.     boundRect.right      += screenOffset.x;
  417.     boundRect.top        += screenOffset.y;
  418.     boundRect.bottom     += screenOffset.y;
  419.     _ShowXSlider((siteVisible && m_bIsVisible) ? TRUE : FALSE);
  420.     _MoveXSlider(boundRect.left, boundRect.bottom - height, boundRect.right - boundRect.left, height, TRUE);
  421.     _ShowYSlider((siteVisible && m_bIsVisible) ? TRUE : FALSE);
  422.     _MoveYSlider(boundRect.right - width, boundRect.top, width, boundRect.bottom - boundRect.top - (_DoesXSliderExist() ? height : 0), TRUE);
  423.     // XXXMEH - checking siteVisible above prevents scroll bars
  424.     // from appearing above the buffering animation logo. For datatypes
  425.     // which ForceRedraw over and over, this is no problem. The scroll bars
  426.     // just show up one blt late. However, most still image datatypes
  427.     // just ForceRedraw once at the first timesync. So for those
  428.     // datatypes, that fix is preventing the scroll bars from showing up.
  429.     // So if m_bIsVisible is TRUE and siteVisible is FALSE (where we
  430.     // *would* have turned the scrollbars on but were prevented by the
  431.     // fact that the site was not yet visible), then we will set up
  432.     // a callback to check again.
  433.     if (m_bIsVisible && !siteVisible && m_bScrollingSite)
  434.     {
  435.         // Have we already scheduled a callback?
  436.         if (!m_ScrollSiteCallbackHandle)
  437.         {
  438.             // Have we already created a ScrollSiteCallback
  439.             if (!m_pScrollSiteCallback)
  440.             {
  441.                 m_pScrollSiteCallback = new ScrollSiteCallback(this);
  442.             }
  443.             if (m_pScrollSiteCallback && m_pScheduler)
  444.             {
  445.                 m_ScrollSiteCallbackHandle = m_pScheduler->RelativeEnter(m_pScrollSiteCallback, 20);
  446.             }
  447.         }
  448.     }
  449. }
  450. void CHXBaseSite::FuncSizeSliders()
  451. {
  452.     m_ScrollSiteCallbackHandle = 0;
  453.     SizeSliders();
  454. }
  455. HX_RESULT CHXBaseSite::ConvertStringToXYDepth(const char* pszModeString, REF(INT32) x, REF(INT32) y, REF(INT32) depth)
  456. {
  457.     HX_RESULT    retVal          = HXR_FAIL;
  458.     int          stringLength    = strlen(pszModeString);
  459.     char*        pszTempString   = new char[stringLength+1];
  460.     memcpy(pszTempString, pszModeString, stringLength+1); /* Flawfinder: ignore */
  461.     char*   token = strtok( pszTempString, MODE_DESRIPTION_SEPS);
  462.     if (!token)
  463.     {
  464.         goto cleanup;
  465.     }
  466.     x     = atoi(token);
  467.     token  = strtok( NULL, MODE_DESRIPTION_SEPS);
  468.     if (!token)
  469.     {
  470.         goto cleanup;
  471.     }
  472.     y = atoi(token);
  473.     token  = strtok( NULL, MODE_DESRIPTION_SEPS);
  474.     if (!token)
  475.     {
  476.         goto cleanup;
  477.     }
  478.     depth   = atoi(token);
  479.     retVal  = HXR_OK;
  480.   cleanup:
  481.     HX_VECTOR_DELETE(pszTempString);
  482.     return retVal;
  483. }
  484. void CHXBaseSite::SetDisplayMode()
  485. {
  486.     m_bSettingDisplayMode = TRUE;
  487.     _TLSLock();
  488.     // check to see if the top level client has set the resolution of
  489.     // full screen. If not then we will stay in the same resolution.
  490.     // if they did then we will will call DD and set the mode.
  491.     IHXPreferences* pPreferences    = NULL;
  492.     IHXBuffer*      pBuffer         = NULL;
  493.     char*            pszModesToTest  = NULL;
  494.     char             szBuffer[255]; /* Flawfinder: ignore */
  495.     if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  496.     {
  497.         strcpy(szBuffer, REGKEY_FULLSCREEN_DATA); /* Flawfinder: ignore */
  498.         strcat(szBuffer, "\"); /* Flawfinder: ignore */
  499.         strcat(szBuffer, REGKEY_FULLSCREEN_PREFERED_MODE); /* Flawfinder: ignore */
  500.         pPreferences->ReadPref(szBuffer, pBuffer);
  501.         INT32 x       = 0;
  502.         INT32 y       = 0;
  503.         INT32 depth   = 0;
  504.         if (pBuffer)
  505.         {
  506.             if (HXR_OK ==ConvertStringToXYDepth((char*)pBuffer->GetBuffer(), x, y, depth))
  507.             {
  508.                 DestroySurfaces();
  509.                 if (zm_bInFullScreenTest)
  510.                 {
  511.                     m_pRootSurface->SetResolution(x, y, depth, m_pWindow ? m_pWindow->window : NULL);
  512.                 }
  513.                 else
  514.                 {
  515.                     void* pWindow = _GetContainingWindow();
  516.                     m_pRootSurface->SetResolution(x, y, depth, pWindow);
  517.                 }
  518.                 ReInitSurfaces();
  519.             }
  520.             HX_RELEASE(pBuffer);
  521.         }
  522.         HX_RELEASE(pPreferences);
  523.     }
  524.     m_bSettingDisplayMode = FALSE;
  525.     _TLSUnlock();
  526. }
  527. //Not used in unix land.......
  528. BOOL CHXBaseSite::GenerateMouseLeaveMessage()
  529. {
  530.     if (m_pMouseInSite)
  531.     {
  532.         void* pWindowHandle = _GetWindowWithCursor();
  533.         // XXXAH this is different than the current implemenation!! XXXAH
  534.         // But the current impementation has a bug in it!!
  535.         //XXXgfw why do we test for GetWindow() and then use m_pWindow??
  536.         HXxWindow* pWindow = GetWindow();
  537.         if(pWindow && (pWindowHandle != pWindow->window))
  538.         {
  539.             HXxPoint oobPoint;
  540.             oobPoint.x = -1;
  541.             oobPoint.y = -1;
  542.             HXxEvent event = {HX_MOUSE_LEAVE, m_pWindow ? m_pWindow->window : NULL, (void*)&oobPoint, 0, 0, FALSE};
  543.             m_pMouseInSite->EventOccurred(&event);
  544.             m_pMouseInSite = NULL;
  545.             return TRUE;
  546.         }
  547.     }
  548.     return FALSE;
  549. }
  550. void CHXBaseSite::CheckExposeEvents()
  551. {
  552.     if (!m_pRootSurface)
  553.     {
  554.         m_bRepaintScheduled = FALSE;
  555.         return;
  556.     }
  557.     if (!m_pParentSite)
  558.     {
  559.         m_pRootSurface->SetBltLock(TRUE);
  560.     }
  561.     if (m_bRepaintScheduled)
  562.     {
  563.         InternalForceRedraw();
  564.         m_bRepaintScheduled = FALSE;
  565.     }
  566.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  567.     while(pos)
  568.     {
  569.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  570.         pSite->CheckExposeEvents();
  571.     }
  572.     m_pVideoSurface->FillColorKey();
  573.     m_pVideoSurface->UpdateDestRect();
  574.     if (!m_pParentSite)
  575.     {
  576.         m_pRootSurface->SetBltLock(FALSE);
  577.     }
  578. }
  579. BOOL CHXBaseSite::_TakesPartInAlphaChain()
  580. {
  581.     BOOL retVal=FALSE;
  582.     int nCID=-1;
  583.     if( !IsSiteVisible() )
  584.         return FALSE;
  585.     if( m_pVideoSurface )
  586.         nCID = GETBITMAPCOLOR(&(m_pVideoSurface->m_bmiLastBlt));
  587.     //Current conditions to force conversion to ARGB and inclusion in
  588.     //the alpha blending chain.
  589.     //
  590.     // 1) Native format is ARGB
  591.     // 2) Has not blt'ed at least once (CID_UNKNOWN)
  592.     // 3) m_bSiteNeverBlts type of regions (see through).
  593.     // 4) _BlendedBordersActive() type. We must have ARGB to blend the borders.
  594.     // 5) m_nEventSensitivity==SENSITIVITY_TRANSPARENT we need these to be part
  595.     //    of the alpha chain so that we can find the site that click belongs to.
  596.     // 6) any site with a fade transition in effect.
  597.     if(CID_ARGB32==nCID || CID_UNKNOWN==nCID || m_bSiteNeverBlts )
  598. //   if(CID_ARGB32==nCID || m_bSiteNeverBlts )
  599.         retVal = TRUE;
  600.     else if( m_nEventSensitivity==SENSITIVITY_TRANSPARENT )
  601.         retVal = TRUE;
  602.     else if( _BlendedBordersActive() )
  603.         retVal = TRUE;
  604.     else if( m_fpTransitionEffect == Crossfade )
  605.         retVal = TRUE;
  606.     else if( m_fpTransitionEffect == FadeToColor )
  607.         retVal = TRUE;
  608.     else if( m_fpTransitionEffect == FadeFromColor )
  609.         retVal = TRUE;
  610.     return retVal;
  611. }
  612. BOOL CHXBaseSite::ComputeSubRects()
  613. {
  614.     _TLSLock();
  615.     BOOL         retVal          = TRUE;
  616.     HXREGION*      hTemp           = NULL;
  617.     HXREGION*      hTemp2          = NULL;
  618.     BOOL         bRepaintMessage = TRUE;
  619.     HXxSize      size;
  620.     HXxPoint*    pPosition       = NULL;
  621.     HXxRect      rectClientRect;
  622.     LISTPOSITION pos             = NULL;
  623.     m_pVideoSurface->_RemoveYUVImageLists();
  624.     if( m_pValues )
  625.     {
  626.         IHXBuffer* pBuf=NULL;
  627.         m_bSiteNeverBlts=FALSE;
  628.         m_pValues->GetPropertyCString( "SiteNeverBlts", pBuf );
  629.         if( pBuf )
  630.         {
  631.             m_bSiteNeverBlts = atoi( (const char*)pBuf->GetBuffer() )==1;
  632.             if( m_bSiteNeverBlts )
  633.             {
  634.                 //Make these sites naturally transparent to events.
  635.                 m_nEventSensitivity = SENSITIVITY_TRANSPARENT;
  636.             }
  637.             HX_RELEASE(pBuf);
  638.         }
  639.     }
  640.     if (m_Region)
  641.     {
  642.         hTemp2 = HXCreateRectRegion(0,0,0,0);
  643.         HXUnionRegion(hTemp2, m_Region, hTemp2);
  644.         HXDestroyRegion(m_Region);
  645.         m_Region = NULL;
  646.         HXDestroyRegion(m_RegionForMouse);
  647.         m_RegionForMouse = NULL;
  648.     }
  649.     if (m_RegionWithoutChildren)
  650.     {
  651.         HXDestroyRegion(m_RegionWithoutChildren);
  652.         m_RegionWithoutChildren = NULL;
  653.     }
  654.     rectClientRect.left     = m_topleft.x;
  655.     rectClientRect.right    = m_topleft.x + m_size.cx;
  656.     rectClientRect.top      = m_topleft.y;
  657.     rectClientRect.bottom   = m_topleft.y + m_size.cy;
  658.     if (IsSiteVisible())
  659.     {
  660.         m_RegionWithoutChildren = Transition(m_topleft.x, m_topleft.y,
  661.                                              m_topleft.x + m_size.cx,
  662.                                              m_topleft.y + m_size.cy,
  663.                                              &m_TransitionBorderLines);
  664.         if (m_pParentSite)
  665.             m_pParentSite->BuildParnetClipping(m_RegionWithoutChildren,this);
  666.         // subtract all of my children from my clipping region
  667.         m_Region = HXCreateRectRegion(0,0,0,0);
  668.         HXUnionRegion(m_Region, m_RegionWithoutChildren, m_Region);
  669.         if (m_Region->numRects == 0)
  670.         {
  671.             retVal = FALSE;
  672.         }
  673.         else
  674.         {
  675.             pos = m_ChildrenInZOrder.GetHeadPosition();
  676.             while(pos)
  677.             {
  678.                 CHXBaseSite* pSite = (CHXBaseSite*) m_ChildrenInZOrder.GetNext(pos);
  679.                 if (pSite->IsSiteVisible())
  680.                 {
  681.                     pPosition = pSite->GetOrigin();
  682.                     memcpy(&size, &pSite->m_size, sizeof(size)); /* Flawfinder: ignore */
  683.                     hTemp = pSite->Transition(pPosition->x, pPosition->y,
  684.                                               pPosition->x + size.cx,
  685.                                               pPosition->y + size.cy);
  686.                     HXSubtractRegion(m_Region, hTemp, m_Region);
  687.                     HXDestroyRegion(hTemp);
  688.                     hTemp = NULL;
  689.                 }
  690.             }
  691.         }
  692.     }
  693.     else
  694.     {
  695.         m_RegionWithoutChildren = HXCreateRectRegion(0,0,0,0);
  696.         m_Region                = HXCreateRectRegion(0,0,0,0);
  697.     }
  698.     // check to see if every destination new region and the
  699.     // old region are the same.
  700.     if (hTemp2)
  701.     {
  702.         if (HXEqualRegion( m_Region, hTemp2)  &&
  703.             m_rectOldClientRect.left    == rectClientRect.left  &&
  704.             m_rectOldClientRect.right   == rectClientRect.right &&
  705.             m_rectOldClientRect.top     == rectClientRect.top   &&
  706.             m_rectOldClientRect.bottom  == rectClientRect.bottom)
  707.         {
  708.             bRepaintMessage = FALSE;
  709.         }
  710.         else
  711.         {
  712.             //We want to damage the old and new rects.
  713. //             HXxRect pTmp = { m_topleft.x,
  714. //                              m_topleft.y,
  715. //                              m_topleft.x+m_size.cx,
  716. //                              m_topleft.y+m_size.cy};
  717.             //XOR the old and new and damage it.
  718. //            HXXorRegion( hTemp2, m_Region, hTemp2 );
  719. //            m_pTopLevelSite->_RecursiveDamageRect( &pTmp );
  720.         }
  721.     }
  722.     memcpy(&m_rectOldClientRect, &rectClientRect, sizeof(m_rectOldClientRect)); /* Flawfinder: ignore */
  723.     HXDestroyRegion(hTemp2);
  724.     hTemp2 = NULL;
  725.     m_bRegionIsValid = TRUE;
  726.     ////////////////////////////////////////////////////////
  727.     //            BEGIN ALPHA BLENDING WORK               //
  728.     ////////////////////////////////////////////////////////
  729.     //for each sibling lowing in the Zorder than us, compute a
  730.     //alpha region for it to blend with.
  731.     //First, clean up the old.....
  732.     _EmptyBlenderList();
  733.     //Now make the new.......
  734.     //First, the parent is a special case....
  735.     if( m_pParentSite && IsSiteVisible() && _TakesPartInAlphaChain())
  736.     {
  737.         INT32 nZOrder   = 0;
  738.         INT32 nMyZOrder = m_lZOrder;
  739.         CHXBaseSite* pParent   = m_pParentSite;
  740.         HXxPoint*    pPosition = m_pParentSite->GetOrigin();
  741.         HXREGION*      pRegion   =
  742.             pParent->Transition( pPosition->x, pPosition->y,
  743.                                  pPosition->x + pParent->m_size.cx,
  744.                                  pPosition->y + pParent->m_size.cy);
  745.         if(pRegion->numRects != 0)
  746.         {
  747.             pos = m_pParentSite->m_ChildrenInZOrder.GetHeadPosition();
  748.             while(pos)
  749.             {
  750.                 CHXBaseSite* pSite = (CHXBaseSite*)m_pParentSite->m_ChildrenInZOrder.GetNext(pos);
  751.                 //All site before me in my parents list are of lower zorder by
  752.                 //default. We don't want to subtract ourselves.
  753.                 if( this == pSite )
  754.                 {
  755.                     break;
  756.                 }
  757.                 if(pSite->IsSiteVisible())
  758.                 {
  759.                     pPosition = pSite->GetOrigin();
  760.                     HXREGION* hTemp = pSite->Transition(pPosition->x, pPosition->y,
  761.                                                         pPosition->x + pSite->m_size.cx,
  762.                                                         pPosition->y + pSite->m_size.cy);
  763.                     HXSubtractRegion(pRegion, hTemp, pRegion);
  764.                     HXDestroyRegion(hTemp);
  765.                     hTemp = NULL;
  766.                 }
  767.             }
  768.         }
  769.         //pRegion now has the region we need to intersect with.
  770.         //XXXgfw, if you are seeing weird alpha problems try
  771.         //using this region instead of the transition one below.
  772. //          HXREGION* pMe = HXCreateRectRegion( m_topleft.x,
  773. //                                             m_topleft.y,
  774. //                                             m_size.cx, // !!! should be +m_topleft
  775. //                                             m_size.cy // !!! should be +m_topleft
  776. //                                             );
  777.         HXREGION* pMe = Transition(m_topleft.x, m_topleft.y,
  778.                                    m_topleft.x + m_size.cx,
  779.                                    m_topleft.y + m_size.cy);
  780.         HXIntersectRegion( pRegion, pMe, pRegion );
  781.         HXDestroyRegion( pMe );
  782.         //Don't delete the region if we save it in the map!
  783.         BOOL bRegionNeedsDeleting = TRUE;
  784.         if( !HXEmptyRegion(pRegion)  )
  785.         {
  786.             //Add it to our region list that we alpha blend with only
  787.             //if we are alpha blendable.
  788.             if( _TakesPartInAlphaChain() )
  789.             {
  790.                 // pRegion now contains our alpha blend region on our parent.
  791.                 // If our parent is a m_bSiteNeverBlts kind, then we will
  792.                 // can't alphablend with it, we need to see what alphablend
  793.                 // regions our parent has that intersect with us. Then, for
  794.                 // each one that does intersect us, we add it, and add
  795.                 // ourselves to that sites notifier list. We should NOT have
  796.                 // added our parent to that sites notifier list because it is
  797.                 // a m_bSiteNeverBlts.
  798.                 //
  799.                 // Terribly confusing what.
  800.                 // If you don't get it, listen to this:
  801.                 //   http://www.dangermouse.org/sounds/what.wav
  802.                 if( !pParent->m_bSiteNeverBlts)
  803.                 {
  804. #if defined(_DEBUG) && 0
  805.                     VerifyNoDups( m_AlphaBlendSites, pRegion );
  806. #endif
  807.                     m_AlphaBlendSites.SetAt( pParent, pRegion );
  808.                     int nCID = GETBITMAPCOLOR(&(pParent->m_pVideoSurface->m_bmiLastBlt));
  809.                     bRegionNeedsDeleting = FALSE;
  810.                     //Add ourselves to that site's notifier list if only if we
  811.                     //are not a m_bSiteNeverBlts.
  812.                     if( !m_bSiteNeverBlts)
  813.                         pParent->_AlphaBlendAddNotifier(this);
  814.                 }
  815.                 else
  816.                 {
  817.                     //OK, go through the parents alpha regions and intersect..
  818.                     CHXMapPtrToPtr::Iterator ii = pParent->m_AlphaBlendSites.Begin();
  819.                     for ( ; ii != pParent->m_AlphaBlendSites.End(); ++ii)
  820.                     {
  821.                         HXREGION* pTmpReg = HXCreateRegion();
  822.                         HXIntersectRegion( pRegion, (HXREGION*)*ii, pTmpReg );
  823.                         if( !HXEmptyRegion(pTmpReg) )
  824.                         {
  825.                             //Add this region and a notifier if we need it.
  826.                             CHXBaseSite* pTmpSite = (CHXBaseSite*) ii.get_key();
  827.                             // See we already have a alphablend region with that
  828.                             // site. If so, union the two.
  829.                             void* pOrig = NULL;
  830.                             if(m_AlphaBlendSites.Lookup((void*)pTmpSite, pOrig ) )
  831.                             {
  832.                                 //Must union it.
  833.                                 HXUnionRegion( pTmpReg, (HXREGION*)pOrig, pTmpReg );
  834.                                 HXDestroyRegion( (HXREGION*)pOrig );
  835.                             }
  836. #if defined(_DEBUG) && 0
  837.                             VerifyNoDups( m_AlphaBlendSites, pTmpReg );
  838. #endif
  839.                             m_AlphaBlendSites.SetAt( pTmpSite, pTmpReg );
  840.                             int nCID = GETBITMAPCOLOR(&(pTmpSite->m_pVideoSurface->m_bmiLastBlt));
  841.                             if( !m_bSiteNeverBlts )
  842.                                 pTmpSite->_AlphaBlendAddNotifier(this);
  843.                         }
  844.                         else
  845.                         {
  846.                             //just clean up an empty region that isn't added to our map.
  847.                             HXDestroyRegion( pTmpReg );
  848.                             pTmpReg=NULL;
  849.                         }
  850.                     }
  851.                 }
  852.             }
  853.             //XXXgfw maybe do an AddRef on the site????
  854.         }
  855.         if( bRegionNeedsDeleting )
  856.         {
  857.             //just clean up an empty region that isn't added to our map.
  858.             HXDestroyRegion(pRegion);
  859.             pRegion=NULL;
  860.         }
  861.         //Now do all the children.....
  862.         pos = m_pParentSite->m_ChildrenInZOrder.GetHeadPosition();
  863.         while(pos)
  864.         {
  865.             CHXBaseSite* pSite = (CHXBaseSite*)m_pParentSite->m_ChildrenInZOrder.GetNext(pos);
  866.             if( this == pSite )
  867.             {
  868.                 break;
  869.             }
  870.             pSite->AlphaBlendComputeSubRects(this);
  871.         }
  872.     }
  873.     // OK, here is some real fun. If, we are a m_bSiteNeverBlts type of
  874.     // site, then we must take our m_Region, intersect it with all of
  875.     // our alphablend sites, and then add that result back into the
  876.     // m_Region of the alphablend sibling. Because, since we aren't
  877.     // drawing, someone needs to draw that part of the screen.
  878.     if( m_bSiteNeverBlts )
  879.     {
  880.         CHXMapPtrToPtr::Iterator iter = m_AlphaBlendSites.Begin();
  881.         for ( ; iter != m_AlphaBlendSites.End(); ++iter)
  882.         {
  883.             HXREGION*   pTmpReg = HXCreateRegion();
  884.             HXREGION*   hTemp   = NULL;
  885.             HXxPoint* pPosition;
  886.             HXxSize   size;
  887.             HXREGION* pAlphaReg = (HXREGION*)*iter;
  888.             CHXBaseSite* pTmpSite = (CHXBaseSite*) iter.get_key();
  889.             //Now remove all higher order siblings from this alpha region.
  890.             HXUnionRegion( pTmpReg, pAlphaReg, pTmpReg );
  891.             if( m_pParentSite )
  892.                 m_pParentSite->_RemoveHigherOrderSiblings(pTmpReg, this );
  893.             // Get rid of all children of mine..
  894.             pos = m_ChildrenInZOrder.GetHeadPosition();
  895.             while(pos)
  896.             {
  897.                 CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  898.                 if(pSite->IsSiteVisible() )
  899.                 {
  900.                     memcpy(&size, &pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  901.                     pPosition = pSite->GetOrigin();
  902.                     hTemp = pSite->Transition(pPosition->x, pPosition->y,
  903.                                               pPosition->x + size.cx,
  904.                                               pPosition->y + size.cy);
  905.                     HXSubtractRegion(pTmpReg, hTemp, pTmpReg);
  906.                     HXDestroyRegion(hTemp);
  907.                     hTemp=NULL;
  908.                 }
  909.             }
  910.             if( !HXEmptyRegion(pTmpReg) )
  911.             {
  912.                 //Add this back into the sites m_Region.
  913.                 HXUnionRegion(pTmpSite->m_Region, pTmpReg, pTmpSite->m_Region);
  914.             }
  915.             HXDestroyRegion(pTmpReg);
  916.         }
  917.     }
  918.     ////////////////////////////////////////////////////////
  919.     //              END ALPHA BLENDING WORK               //
  920.     ////////////////////////////////////////////////////////
  921.     // Now copy our visual region into a mouse/event region.
  922.     m_RegionForMouse = HXCreateRegion();
  923.     HXUnionRegion( m_RegionForMouse, m_Region, m_RegionForMouse);
  924.     //If we have a parent site and a window then we must set our window
  925.     //rgn to that specified in m_hClip
  926.     m_topleft.x =0;
  927.     m_topleft.y =0;
  928.     GetAbsoluteCords(m_topleft);
  929.     if(bRepaintMessage )
  930.     {
  931.         InternalForceRedraw();
  932.         if (m_pVideoSurface)
  933.         {
  934.             m_pVideoSurface->FillColorKey();
  935.         }
  936.     }
  937.     SizeSliders();
  938.     _TLSUnlock();
  939.     return TRUE;
  940. }
  941. void CHXBaseSite::BuildParnetClipping( HXREGION* hClip, CHXBaseSite* pChild)
  942. {
  943.     HXREGION*      hTemp     = NULL;
  944.     HXxPoint*    pPosition = NULL;
  945.     HXxSize      size;
  946.     BOOL         bFound    = FALSE;
  947.     // subtract all of my children from my clipping region
  948.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  949.     while(pos)
  950.     {
  951.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  952.         //Keep in mind that all site before pChild have zorder less than
  953.         //pChild and all sites after have a higher zorder.
  954.         if( pChild == pSite )
  955.         {
  956.             bFound = TRUE;
  957.         }
  958.         if(bFound && pChild!=pSite && pSite->IsSiteVisible())
  959.         {
  960.             memcpy(&size, &pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  961.             pPosition = pSite->GetOrigin();
  962.             hTemp = pSite->Transition(pPosition->x, pPosition->y,
  963.                                       pPosition->x + size.cx,
  964.                                       pPosition->y + size.cy);
  965.             HXSubtractRegion(hClip, hTemp, hClip);
  966.             HXDestroyRegion(hTemp);
  967.             hTemp=NULL;
  968.         }
  969.     }
  970.     // now handle my clipping region
  971.     // if my region is valid use that ...
  972.     if (m_bRegionIsValid )
  973.     {
  974.         HXIntersectRegion(hClip, m_RegionWithoutChildren, hClip);
  975.     }
  976.     else
  977.     {
  978.         hTemp = Transition(m_topleft.x, m_topleft.y,
  979.                            m_topleft.x + m_size.cx,
  980.                            m_topleft.y + m_size.cy,
  981.                            &m_TransitionBorderLines);
  982.         HXIntersectRegion(hClip, hTemp, hClip);
  983.         HXDestroyRegion(hTemp);
  984.         hTemp=NULL;
  985.         if (m_pParentSite)
  986.             m_pParentSite->BuildParnetClipping(hClip,this);
  987.     }
  988. }
  989. BOOL CHXBaseSite::AreVideoControlsActive()
  990. {
  991.     if (m_pParentSite)
  992.     {
  993.         return m_pParentSite->AreVideoControlsActive();
  994.     }
  995.     return m_fBrightness    != DEF_BRIGHTNESS ||
  996.         m_fContrast      != DEF_CONTRAST   ||
  997.         m_fSharpness     != DEF_SHARPNESS  ||
  998.         m_fHue           != DEF_HUE        ||
  999.         m_fSaturation    != DEF_SATURATION;
  1000. }
  1001. BOOL CHXBaseSite::_BordersActive()
  1002. {
  1003.     return (m_TransitionBorderLines.m_nLines && m_nTransitionBorderWidth);
  1004. }
  1005. BOOL CHXBaseSite::_BlendedBordersActive()
  1006. {
  1007.     return (m_TransitionBorderLines.m_nLines &&
  1008.             m_nTransitionBorderWidth &&
  1009.             m_bTransitionBlendBorder &&
  1010.             m_nTransitionState < 1000);
  1011. }
  1012. BOOL CHXBaseSite::_FadeTransitionActive()
  1013. {
  1014.     return ( (m_fpTransitionEffect == Crossfade ||
  1015.               m_fpTransitionEffect == FadeToColor ||
  1016.               m_fpTransitionEffect == FadeFromColor)
  1017.              && m_nTransitionState<1000
  1018.              );
  1019. }
  1020. BOOL CHXBaseSite::_IsAlphaBlending()
  1021. {
  1022.     return _BordersActive() ||
  1023.         _FadeTransitionActive() ||
  1024.         _TakesPartInAlphaChain() ||
  1025.         m_AlphaBlendNotifiers.GetCount() != 0 ||
  1026.         m_AlphaBlendSites.GetCount() != 0;
  1027. }
  1028. BOOL CHXBaseSite::IsHigherZOrderTranstitionActive()
  1029. {
  1030.     BOOL bRet = FALSE;
  1031.     CHXMapPtrToPtr::Iterator iter = m_AlphaBlendNotifiers.Begin();
  1032.     for ( ; iter != m_AlphaBlendNotifiers.End(); ++iter)
  1033.     {
  1034.         CHXBaseSite* pSite = (CHXBaseSite*)*iter;
  1035.         if (pSite->m_fpTransitionEffect != DefaultTransition &&
  1036.             pSite->m_nTransitionState > 0 &&
  1037.             pSite->m_nTransitionState < 1000 &&
  1038.             GETBITMAPCOLOR(&pSite->m_pVideoSurface->m_bmiLastBlt) == CID_ARGB32)
  1039.         {
  1040.             bRet = TRUE;
  1041.             break;
  1042.         }
  1043.     }
  1044.     return bRet;
  1045. }
  1046. ////////////////////////////////////////////////////////
  1047. //            BEGIN ALPHA BLENDING WORK               //
  1048. ////////////////////////////////////////////////////////
  1049. void CHXBaseSite::_RemoveHigherOrderSiblings( HXREGION* hClip, CHXBaseSite* pChild)
  1050. {
  1051.     HXREGION*      hTemp     = NULL;
  1052.     HXxPoint*    pPosition = NULL;
  1053.     HXxSize      size;
  1054.     BOOL         bFound    = FALSE;
  1055.     // Get rid of all higher zorder siblings from this region.
  1056.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1057.     while(pos)
  1058.     {
  1059.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1060.         //Keep in mind that all site before pChild in this list are lower
  1061.         //zorder and all sites afer have higher zorders.
  1062.         if( pChild == pSite )
  1063.         {
  1064.             bFound = TRUE;
  1065.         }
  1066.         if(bFound && pChild!=pSite && pSite->IsSiteVisible() )
  1067.         {
  1068.             memcpy(&size, &pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  1069.             pPosition = pSite->GetOrigin();
  1070.             hTemp = pSite->Transition(pPosition->x, pPosition->y,
  1071.                                       pPosition->x + size.cx,
  1072.                                       pPosition->y + size.cy);
  1073.             HXSubtractRegion(hClip, hTemp, hClip);
  1074.             HXDestroyRegion(hTemp);
  1075.             hTemp=NULL;
  1076.         }
  1077.     }
  1078.     if( m_pParentSite )
  1079.         m_pParentSite->_RemoveHigherOrderSiblings( hClip, this );
  1080. }
  1081. void CHXBaseSite::AlphaBlendComputeSubRects(CHXBaseSite* pIgnoredSite)
  1082. {
  1083.     HXREGION*      hTemp     = NULL;
  1084.     HXxSize      size;
  1085.     HXxPoint*    pPosition = NULL;
  1086.     HXREGION*      pReturn   = NULL;
  1087.     LISTPOSITION pos       = NULL;
  1088.     HX_ASSERT( pIgnoredSite != this );
  1089.     if( pIgnoredSite == this )
  1090.         return;
  1091.     if( pIgnoredSite && !pIgnoredSite->_TakesPartInAlphaChain() )
  1092.         return;
  1093.     if(IsSiteVisible())
  1094.     {
  1095.         pReturn = Transition(m_topleft.x, m_topleft.y,
  1096.                              m_topleft.x + m_size.cx,
  1097.                              m_topleft.y + m_size.cy,
  1098.                              &m_TransitionBorderLines);
  1099.         if(m_pParentSite)
  1100.         {
  1101.             m_pParentSite->AlphaBlendBuildParnetClipping( pReturn, this, pIgnoredSite );
  1102.         }
  1103.         // subtract all of my children from my clipping region
  1104.         if( pReturn->numRects != 0 )
  1105.         {
  1106.             pos = m_ChildrenInZOrder.GetHeadPosition();
  1107.             while(pos)
  1108.             {
  1109.                 CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1110.                 if(pSite->IsSiteVisible())
  1111.                 {
  1112.                     pPosition = pSite->GetOrigin();
  1113.                     memcpy(&size, &pSite->m_size, sizeof(size)); /* Flawfinder: ignore */
  1114.                     hTemp = pSite->Transition(pPosition->x, pPosition->y,
  1115.                                               pPosition->x + size.cx,
  1116.                                               pPosition->y + size.cy);
  1117.                     HXSubtractRegion(pReturn, hTemp, pReturn);
  1118.                     HXDestroyRegion(hTemp);
  1119.                     hTemp = NULL;
  1120.                 }
  1121.             }
  1122.         }
  1123.     }
  1124.     //Now we have an alpha blend region. Add it to the master sites
  1125.     //map if we overlap it at all.
  1126.     BOOL regionNeedsDeleting = TRUE;
  1127.     if( pReturn && !HXEmptyRegion( pReturn ) )
  1128.     {
  1129.         HXxPoint* pPosition = pIgnoredSite->GetOrigin();
  1130.         HXxSize*  pSize     = &(pIgnoredSite->m_size);
  1131.         HXREGION*   pTmp = pIgnoredSite->Transition(pPosition->x,
  1132.                                                     pPosition->y,
  1133.                                                     pPosition->x+pSize->cx,
  1134.                                                     pPosition->y+pSize->cy);
  1135.         //We must remove any overlapping NON-ARGB regions. Higher order
  1136.         //siblings and chilren....
  1137.         pos = pIgnoredSite->m_ChildrenInZOrder.GetHeadPosition();
  1138.         while(pos)
  1139.         {
  1140.             CHXBaseSite* pSite2 =
  1141.                 (CHXBaseSite*)(pIgnoredSite->m_ChildrenInZOrder.GetNext(pos));
  1142.             if(pSite2->IsSiteVisible() && !pSite2->_IsAlphaBlending())
  1143.             {
  1144.                 pPosition = pSite2->GetOrigin();
  1145.                 memcpy(&size, &pSite2->m_size, sizeof(size)); /* Flawfinder: ignore */
  1146.                 hTemp = pSite2->Transition(pPosition->x, pPosition->y,
  1147.                                            pPosition->x + size.cx,
  1148.                                            pPosition->y + size.cy);
  1149.                 HXSubtractRegion(pReturn, hTemp, pReturn);
  1150.                 HXDestroyRegion(hTemp);
  1151.                 hTemp = NULL;
  1152.             }
  1153.         }
  1154.         HXIntersectRegion( pReturn, pTmp, pReturn );
  1155.         HXDestroyRegion( pTmp );
  1156.         if ( !HXEmptyRegion( pReturn ) )
  1157.         {
  1158.             //Add it to our region list that we alpha blend with only
  1159.             //if we are alpha blendable.
  1160.             if( pIgnoredSite && pIgnoredSite->_TakesPartInAlphaChain() )
  1161.             {
  1162.                 // pRetrun now contains our alpha blend region on
  1163.                 // ourselves.  If we are a m_bSiteNeverBlts kind, then we
  1164.                 // don't want the ignored site to alphablend with us, we
  1165.                 // need to see what alphablend regions we have that
  1166.                 // intersect with the ignored site. Then, for each one
  1167.                 // that does intersect, we add it, and add the ignored
  1168.                 // site to our notifier list. We should NOT have added
  1169.                 // ourselves to that sites notifier list because it is a
  1170.                 // m_bSiteNeverBlts.
  1171.                 //
  1172.                 // Terribly confusing what.
  1173.                 // If you don't get it, listen to this:
  1174.                 //   http://www.dangermouse.org/sounds/what.wav
  1175.                 if( !m_bSiteNeverBlts)
  1176.                 {
  1177.                     //Add this to our list of regions we alpha blend with.
  1178.                     //XXXgfw addref the site???
  1179. #if defined(_DEBUG) && 0
  1180.                     VerifyNoDups( pIgnoredSite->m_AlphaBlendSites, pReturn );
  1181. #endif
  1182.                     pIgnoredSite->m_AlphaBlendSites.SetAt( this, pReturn );
  1183.                     int nCID = GETBITMAPCOLOR(&(m_pVideoSurface->m_bmiLastBlt));
  1184.                     regionNeedsDeleting = FALSE;
  1185.                     //Add the ignored site to our site's notifier list. Do this
  1186.                     //only if the ignored site isn't m_bSiteNeverBlts type.
  1187.                     if( !(pIgnoredSite->m_bSiteNeverBlts) )
  1188.                         _AlphaBlendAddNotifier(pIgnoredSite);
  1189.                 }
  1190.                 else
  1191.                 {
  1192.                     //OK, go through the alpha regions and intersect..
  1193.                     CHXMapPtrToPtr::Iterator ii = m_AlphaBlendSites.Begin();
  1194.                     for ( ; ii != m_AlphaBlendSites.End(); ++ii)
  1195.                     {
  1196.                         HXREGION* pTmpReg = HXCreateRegion();
  1197.                         HXIntersectRegion( pReturn, (HXREGION*)*ii, pTmpReg );
  1198.                         if( !HXEmptyRegion(pTmpReg) )
  1199.                         {
  1200.                             //Add this region and a notifier if we need it.
  1201.                             CHXBaseSite* pTmpSite = (CHXBaseSite*) ii.get_key();
  1202.                             // See we already have a alphablend region with that
  1203.                             // site. If so, union the two.
  1204.                             void* pOrig = NULL;
  1205.                             if(pIgnoredSite->m_AlphaBlendSites.Lookup((void*)pTmpSite, pOrig ) )
  1206.                             {
  1207.                                 //Must union it.
  1208.                                 HXUnionRegion( pTmpReg, (HXREGION*)pOrig, pTmpReg );
  1209.                                 HXDestroyRegion( (HXREGION*)pOrig );
  1210.                             }
  1211. #if defined(_DEBUG) && 0
  1212.                             VerifyNoDups( pIgnoredSite->m_AlphaBlendSites, pTmpReg );
  1213. #endif
  1214.                             pIgnoredSite->m_AlphaBlendSites.SetAt( pTmpSite, pTmpReg );
  1215.                             int nCID = GETBITMAPCOLOR(&(pTmpSite->m_pVideoSurface->m_bmiLastBlt));
  1216.                             if( !pIgnoredSite->m_bSiteNeverBlts )
  1217.                                 _AlphaBlendAddNotifier(pIgnoredSite);
  1218.                         }
  1219.                         else
  1220.                         {
  1221.                             //just clean up an empty region that isn't added to our map.
  1222.                             HXDestroyRegion( pTmpReg );
  1223.                             pTmpReg=NULL;
  1224.                         }
  1225.                     }
  1226.                 }
  1227.             }
  1228.         }
  1229.     }
  1230.     if( pReturn && regionNeedsDeleting )
  1231.     {
  1232.         HXDestroyRegion(pReturn);
  1233.         pReturn=NULL;
  1234.     }
  1235.     //Now do all of our children too......
  1236.     pos = m_ChildrenInZOrder.GetHeadPosition();
  1237.     while(pos)
  1238.     {
  1239.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1240.         pSite->AlphaBlendComputeSubRects( pIgnoredSite );
  1241.     }
  1242. }
  1243. void CHXBaseSite::AlphaBlendBuildParnetClipping( HXREGION* hClip,
  1244.                                                  CHXBaseSite* pChild,
  1245.                                                  CHXBaseSite* pIgnoredSite
  1246.                                                  )
  1247. {
  1248.     HXREGION*      hTemp         = NULL;
  1249.     HXxPoint*    pPosition;
  1250.     HXxSize      size;
  1251.     BOOL         bIgnoreSiteIsSibling = FALSE;
  1252.     LISTPOSITION pos           = NULL;
  1253.     BOOL         bFoundChild   = FALSE;
  1254.     BOOL         bFoundIgnored = FALSE;
  1255.     //Is the ignored site a sibling of ours? If not, ignore its z
  1256.     //order.
  1257.     if( pIgnoredSite->m_pParentSite == this )
  1258.     {
  1259.         bIgnoreSiteIsSibling = TRUE;
  1260.     }
  1261.     // subtract all of my children from my clipping region
  1262.     pos = m_ChildrenInZOrder.GetHeadPosition();
  1263.     while(pos)
  1264.     {
  1265.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1266.         if( pSite == pChild )
  1267.         {
  1268.             //Now all sites in this list will be of higher Zorder
  1269.             bFoundChild = TRUE;
  1270.         }
  1271.         else if( pSite == pIgnoredSite )
  1272.         {
  1273.             //Now, all sites in this list will be higher than the
  1274.             //ignored.
  1275.             bFoundIgnored = TRUE;
  1276.         }
  1277.         if( bFoundChild && pSite!=pChild &&
  1278.             ((!bFoundIgnored ) || !bIgnoreSiteIsSibling) &&
  1279.             (pSite->IsSiteVisible())
  1280.             )
  1281.         {
  1282.             memcpy(&size, &pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  1283.             pPosition = pSite->GetOrigin();
  1284.             hTemp = pSite->Transition(pPosition->x, pPosition->y,
  1285.                                       pPosition->x + size.cx,
  1286.                                       pPosition->y + size.cy);
  1287.             HXSubtractRegion(hClip, hTemp, hClip);
  1288.             HXDestroyRegion(hTemp);
  1289.             hTemp=NULL;
  1290.         }
  1291.     }
  1292.     hTemp = Transition(m_topleft.x, m_topleft.y,
  1293.                        m_topleft.x + m_size.cx,
  1294.                        m_topleft.y + m_size.cy);
  1295.     HXIntersectRegion(hClip, hTemp, hClip);
  1296.     HXDestroyRegion(hTemp);
  1297.     hTemp=NULL;
  1298.     if (m_pParentSite)
  1299.         m_pParentSite->AlphaBlendBuildParnetClipping( (HXREGION*)hClip,
  1300.                                                       (CHXBaseSite*)this,
  1301.                                                       (CHXBaseSite*)pIgnoredSite);
  1302. }
  1303. ////////////////////////////////////////////////////////
  1304. //              END ALPHA BLENDING WORK               //
  1305. ////////////////////////////////////////////////////////
  1306. void CHXBaseSite::UpdateModes()
  1307. {
  1308.     INT32 nNumModes = 0;
  1309.     CModesDesc* pModesDesc = 0;
  1310.     m_pRootSurface->GetDisplayModes(pModesDesc, &nNumModes);
  1311.     pModesDesc = new CModesDesc[nNumModes ];
  1312.     m_pRootSurface->GetDisplayModes(pModesDesc, &nNumModes);
  1313.     for(INT32 i=0; i<nNumModes; i++)
  1314.     {
  1315.         if (pModesDesc[i].m_nWidth>= 320 && pModesDesc[i].m_nHeight>=200 && pModesDesc[i].m_nBitCount>=8)
  1316.         {
  1317.             if (!DoesPrefExist(pModesDesc[i].m_nWidth, pModesDesc[i].m_nHeight, pModesDesc[i].m_nBitCount))
  1318.             {
  1319.                 UpdatePrefs(pModesDesc[i].m_nWidth, pModesDesc[i].m_nHeight, pModesDesc[i].m_nBitCount, 0, FALSE, FALSE);
  1320.             }
  1321.         }
  1322.     }
  1323.     HX_VECTOR_DELETE(pModesDesc);
  1324. }
  1325. BOOL CHXBaseSite::DoesPrefExist(INT32 resolutionX, INT32 resolutionY, INT32 colorDepth)
  1326. {
  1327.     char         szNameBuffer[255]; /* Flawfinder: ignore */
  1328.     IHXBuffer*          pBuffer         = NULL;
  1329.     IHXPreferences*     pPreferences    = NULL;
  1330.     BOOL         bFound          = FALSE;
  1331.     if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences, (void**)&pPreferences))
  1332.     {
  1333.         sprintf(szNameBuffer, "%s\%s\%dx%dx%d", /* Flawfinder: ignore */
  1334.                 REGKEY_FULLSCREEN_DATA,
  1335.                 REGKEY_FULLSCREEN_AVAILIABLE_MODES,
  1336.                 resolutionX,
  1337.                 resolutionY,
  1338.                 colorDepth);
  1339.         if (HXR_OK == pPreferences->ReadPref(szNameBuffer, pBuffer))
  1340.         {
  1341.             bFound = TRUE;
  1342.             HX_RELEASE(pBuffer);
  1343.         }
  1344.     }
  1345.     HX_RELEASE(pPreferences);
  1346.     return bFound;
  1347. }
  1348. void CHXBaseSite::UpdatePrefs(INT32 resolutionX, INT32 resolutionY, INT32 colorDepth, ULONG32 ulBltTime, BOOL bPassed, BOOL bTested)
  1349. {
  1350.     char szNameBuffer[255]; /* Flawfinder: ignore */
  1351.     IHXBuffer* pBuffer = NULL;
  1352.     IHXPreferences*     pPreferences        = NULL;
  1353.     if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences, (void**)&pPreferences))
  1354.     {
  1355.         sprintf(szNameBuffer, "%s\%s\%dx%dx%d", /* Flawfinder: ignore */
  1356.                 REGKEY_FULLSCREEN_DATA,
  1357.                 REGKEY_FULLSCREEN_AVAILIABLE_MODES,
  1358.                 resolutionX,
  1359.                 resolutionY,
  1360.                 colorDepth);
  1361.         pBuffer = new CHXBuffer();
  1362.         pBuffer->AddRef();
  1363.         char szTempBuffer[255]; /* Flawfinder: ignore */
  1364.         strcpy(szTempBuffer, szNameBuffer); /* Flawfinder: ignore */
  1365.         strcat(szTempBuffer, "\"); /* Flawfinder: ignore */
  1366.         strcat(szTempBuffer, REGKEY_TESTED); /* Flawfinder: ignore */
  1367.         if (bTested)
  1368.         {
  1369.             pBuffer->Set((const unsigned char*) "1", 2);
  1370.         }
  1371.         else
  1372.         {
  1373.             pBuffer->Set((const unsigned char*) "0", 2);
  1374.         }
  1375.         pPreferences->WritePref(szTempBuffer, pBuffer);
  1376.         strcpy(szTempBuffer, szNameBuffer); /* Flawfinder: ignore */
  1377.         strcat(szTempBuffer, "\"); /* Flawfinder: ignore */
  1378.         strcat(szTempBuffer, REGKEY_BLT_TIME); /* Flawfinder: ignore */
  1379.         char szNumberBuffer[20]; /* Flawfinder: ignore */
  1380.         sprintf( szNumberBuffer, "%d", ulBltTime ); /* Flawfinder: ignore */
  1381.         //itoa(ulBltTime, szNumberBuffer, 10);
  1382.         pBuffer->Set((const unsigned char*) szNumberBuffer, strlen(szNumberBuffer)+1);
  1383.         pPreferences->WritePref(szTempBuffer, pBuffer);
  1384.         strcpy(szTempBuffer, szNameBuffer); /* Flawfinder: ignore */
  1385.         strcat(szTempBuffer, "\"); /* Flawfinder: ignore */
  1386.         strcat(szTempBuffer, REGKEY_PASS); /* Flawfinder: ignore */
  1387.         if (bPassed)
  1388.         {
  1389.             pBuffer->Set((const unsigned char*) "1", 2);
  1390.         }
  1391.         else
  1392.         {
  1393.             pBuffer->Set((const unsigned char*) "0", 2);
  1394.         }
  1395.         pPreferences->WritePref(szTempBuffer, pBuffer);
  1396.         HX_RELEASE(pBuffer);
  1397.     }
  1398.     HX_RELEASE(pPreferences);
  1399. }
  1400. void CHXBaseSite::ScheduleCallback(INT32 nWhichCallback,
  1401.                                    INT32 nMilliseconds,
  1402.                                    BOOL  bOverrideCompositionMode)
  1403. {
  1404.     HX_ASSERT(m_pTopLevelSite == this);
  1405.     if( IsCompositionMode() && nWhichCallback!=MOUSE && !bOverrideCompositionMode )
  1406.     {
  1407.         return;
  1408.     }
  1409.     switch (nWhichCallback)
  1410.     {
  1411.        case REPAINT:
  1412.            if (m_bProcessRepaint)
  1413.                return;
  1414.            m_bProcessRepaint = TRUE;
  1415.            break;
  1416.        case CLIP:
  1417.            if (m_bRecomputeClipScheduled)
  1418.                return;
  1419.            m_bRecomputeClipScheduled = TRUE;
  1420.            break;
  1421.        case REDRAW_ALL:
  1422.            if (m_bForceRedrawNeeded)
  1423.                return;
  1424.            m_bForceRedrawNeeded = TRUE;
  1425.            break;
  1426.        case MOUSE:
  1427.            if (m_CallbackHandle)
  1428.                return;
  1429.            break;
  1430.        case MOVE:
  1431.            _TLSLock();
  1432.            /*
  1433.             * Site moving used to take an X, Y parameter, but since we changed it to
  1434.             * go to GDI mode, that is no longer relevant.
  1435.             */
  1436.            SiteMoving(0, 0);
  1437.            m_nLastMoveTime = HX_GET_TICKCOUNT();
  1438.            ScheduleCallback(MOUSE, 100);
  1439.            _TLSUnlock();
  1440.            return;
  1441.        default:
  1442.            HX_ASSERT(0);
  1443.            break;
  1444.     }
  1445.     if (m_pScheduler)
  1446.     {
  1447.         if (m_CallbackHandle)
  1448.         {
  1449.             m_pScheduler->Remove(m_CallbackHandle);
  1450.             m_CallbackHandle = 0;
  1451.         }
  1452.         m_CallbackHandle = m_pScheduler->RelativeEnter(m_pCallback, nMilliseconds);
  1453.     }
  1454.     return;
  1455. }
  1456. CBaseRootSurface* CHXBaseSite::GetRootSurface()
  1457. {
  1458.     return m_pRootSurface;
  1459. }
  1460. BOOL CHXBaseSite::IsPointInClippingRegion(HXxPoint* pPoint)
  1461. {
  1462.     return ::HXPointInRegion( m_RegionForMouse, pPoint->x, pPoint->y );
  1463. }
  1464. void
  1465. CHXBaseSite::SiteNotMoving()
  1466. {
  1467. #if 1
  1468.     m_bMoving = FALSE;
  1469. #else
  1470.     m_pVideoSurface->ForceGDIMode(FALSE);
  1471. #endif
  1472.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1473.     while(pos)
  1474.     {
  1475.         CHXBaseSite* pChildSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1476.         pChildSite->SiteNotMoving();
  1477.     }
  1478. }
  1479. void CHXBaseSite::ColorConverterRequest(int CIDIn, int CIDOut, BOOL bFoundConverter)
  1480. {
  1481.     if (m_pTopLevelSite)
  1482.         m_pTopLevelSite->InternalColorConverterRequest(CIDIn, CIDOut, bFoundConverter, this);
  1483. }
  1484. void CHXBaseSite::InternalColorConverterRequest(int CIDIn, int CIDOut, BOOL bFoundConverter, CHXBaseSite* pSite)
  1485. {
  1486.     int* pCIDs;
  1487.     BOOL bSchedule = FALSE;
  1488.     IHXSite *pISite = (IHXSite*)pSite;
  1489.     if (!bFoundConverter)
  1490.     {
  1491.         /*
  1492.          *  1st wins. If there is already an upgrade request for this
  1493.          *  site, then add no more.
  1494.          */
  1495.         if (!m_upgradeMap.Lookup((void*) pISite, (void*&) pCIDs))
  1496.         {
  1497.             pCIDs = new int[2];
  1498.             pCIDs[0] = CIDIn;
  1499.             pCIDs[1] = CIDOut;
  1500.             m_upgradeMap.SetAt((void*)pISite, (void*)pCIDs);
  1501.             if (m_pScheduler)
  1502.             {
  1503.                 if (m_CallbackHandle)
  1504.                 {
  1505.                     m_pScheduler->Remove(m_CallbackHandle);
  1506.                     m_CallbackHandle = 0;
  1507.                 }
  1508.                 m_CallbackHandle = m_pScheduler->RelativeEnter(m_pCallback, 0);
  1509.             }
  1510.             m_bScheduleUpgrade = TRUE;
  1511.         }
  1512.     }
  1513.     else
  1514.     {
  1515.         if (m_upgradeMap.Lookup((void*) pISite, (void*&) pCIDs))
  1516.         {
  1517.             HX_DELETE(pCIDs);
  1518.             m_upgradeMap.Remove((void*) pISite);
  1519.             if (!m_upgradeMap.GetCount())
  1520.             {
  1521.                 m_bScheduleUpgrade = FALSE;
  1522.             }
  1523.         }
  1524.     }
  1525. }
  1526. void CHXBaseSite::ScheduleUpgrade()
  1527. {
  1528.     /*
  1529.      *  We currently take the head of the list and upgrade that request
  1530.      *  and forget about all of the rest within the list.
  1531.      */
  1532.     IHXSite* pSite = NULL;
  1533.     int* pCIDs;
  1534.     if (m_upgradeMap.GetCount())
  1535.     {
  1536.         POSITION pos = m_upgradeMap.GetStartPosition();
  1537.         m_upgradeMap.GetNextAssoc(pos, (void*&)pSite, (void*&) pCIDs);
  1538.         InternalScheduleUpgrade(pCIDs[0], pCIDs[1], pSite);
  1539.         HX_VECTOR_DELETE(pCIDs);
  1540.         while(pos)
  1541.         {
  1542.             m_upgradeMap.GetNextAssoc(pos, (void*&)pSite, (void*&) pCIDs);
  1543.             HX_VECTOR_DELETE(pCIDs);
  1544.         }
  1545.         m_upgradeMap.RemoveAll();
  1546.     }
  1547.     m_bScheduleUpgrade = FALSE;
  1548. }
  1549. void CHXBaseSite::InternalScheduleUpgrade(UINT32 CIDIn, UINT32 CIDOut, IHXSite* pSite)
  1550. {
  1551.     /*
  1552.      *  1st we have to find the player to which we are attached.
  1553.      *
  1554.      *  We will use two methods to find out who we are attached to.
  1555.      *  1.  We will QI for SiteManager2 and iterate over the sites to see
  1556.      *      if we are in the list.
  1557.      *  2.  If we have only one player we will use that one!
  1558.      *  3.  And we'll use the 1st player if we can't find anything.
  1559.      */
  1560.     IHXClientEngine*       pEngine         = NULL;
  1561.     IHXSite*               pIterationSite  = NULL;
  1562.     IHXBuffer*             pBuffer         = NULL;
  1563.     IUnknown*               pUnknown        = NULL;
  1564.     IHXSiteManager2*       pSiteManager2   = NULL;
  1565.     UINT16 nPlayerCount;
  1566.     UINT32 index;
  1567.     UINT32 index2;
  1568.     UINT32 nNumSites;
  1569.     m_pContext->QueryInterface(IID_IHXClientEngine, (void**)&pEngine);
  1570.     if (!pEngine)
  1571.         goto cleanup;
  1572.     nPlayerCount = pEngine->GetPlayerCount();
  1573.     /*
  1574.      *  Do we only have one player? If so, case solved!
  1575.      */
  1576.     if (nPlayerCount == 1)
  1577.     {
  1578.         pEngine->GetPlayer(0, pUnknown);
  1579.         goto playerFound;
  1580.     }
  1581.     else
  1582.     {
  1583.         for(index = 0; index< nPlayerCount; index++)
  1584.         {
  1585.             pEngine->GetPlayer((UINT16) index, pUnknown);
  1586.             pUnknown->QueryInterface(IID_IHXSiteManager2, (void**) &pSiteManager2);
  1587.             if (pSiteManager2)
  1588.             {
  1589.                 pSiteManager2->GetNumberOfSites(nNumSites);
  1590.                 for(index2 = 0; index2< nNumSites; index2++)
  1591.                 {
  1592.                     pSiteManager2->GetSiteAt(index2, pIterationSite);
  1593.                     if (pSite == pIterationSite)
  1594.                     {
  1595.                         /*
  1596.                          *  We have a winner
  1597.                          */
  1598.                         HX_RELEASE(pSiteManager2);
  1599.                         goto playerFound;
  1600.                     }
  1601.                 }
  1602.             }
  1603.             HX_RELEASE(pSiteManager2);
  1604.             HX_RELEASE(pUnknown);
  1605.         }
  1606.     }
  1607.     pEngine->GetPlayer(0, pUnknown);
  1608.   playerFound:
  1609.     // Auto download of color converter
  1610.     AddToAutoUpgradeCollection("colo", pUnknown);
  1611.   cleanup:
  1612.     HX_RELEASE(pUnknown);
  1613.     HX_RELEASE(pBuffer);
  1614.     HX_RELEASE(pEngine);
  1615. }
  1616. void CHXBaseSite::SetEvent(REF(HXxEvent) theEvent, ULONG32 event, void* window, void*   param1, void*   param2)
  1617. {
  1618.     theEvent.event       = event;
  1619.     theEvent.window = window;
  1620.     theEvent.param1 = param1;
  1621.     theEvent.param2 = param2;
  1622.     theEvent.result = 0;
  1623.     theEvent.handled = FALSE;
  1624. }
  1625. void CHXBaseSite::CheckDisplayMode(void* hdc)
  1626. {
  1627.     BOOL bCreatedDC = FALSE;
  1628.     if (m_pTopLevelSite == this && !zm_bInFullScreenTest)
  1629.     {
  1630.         if (!m_bSettingDisplayMode)
  1631.         {
  1632.             UINT16 newBitsPerPixel, newHozRes, newVertRes;
  1633.             _GetDeviceCaps(hdc, newBitsPerPixel, newHozRes, newVertRes);
  1634.             if (m_nOldBitsPerPixel != newBitsPerPixel || newHozRes != m_nOldHorzRes || newVertRes != m_nOldVertRes)
  1635.             {
  1636.                 m_nOldBitsPerPixel  = newBitsPerPixel;
  1637.                 m_nOldHorzRes           = newHozRes;
  1638.                 m_nOldVertRes           = newVertRes;
  1639.                 ChangeResolution();
  1640.             }
  1641.         }
  1642.     }
  1643. }
  1644. void CHXBaseSite::ChangeResolution()
  1645. {
  1646.     if( this==m_pTopLevelSite &&
  1647.         m_pRootSurface &&
  1648.         m_pRootSurface->_OptimizedSurfaceOpened())
  1649.     {
  1650.         DestroySurfaces();
  1651.         /// XXXAH Uhm, I think I should be chaning the resolution here ....
  1652.         _ReInitPrimarySurface();
  1653.         ReInitSurfaces();
  1654.     }
  1655. }
  1656. void
  1657. CHXBaseSite::DestroySurfaces()
  1658. {
  1659.     if (m_pVideoSurface)
  1660.     {
  1661.         m_pVideoSurface->DestroySurfaces();
  1662.     }
  1663.     if (m_pRootSurface)
  1664.     {
  1665.         m_pRootSurface->DestroySurfaces();
  1666.     }
  1667.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1668.     while(pos)
  1669.     {
  1670.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1671.         pSite->DestroySurfaces();
  1672.     }
  1673. }
  1674. void CHXBaseSite::LockBlitters()
  1675. {
  1676.     if (m_pVideoSurface)
  1677.     {
  1678.         m_pVideoSurface->_LockBlitter();
  1679.     }
  1680.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1681.     while(pos)
  1682.     {
  1683.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1684.         pSite->LockBlitters();
  1685.     }
  1686. }
  1687. void CHXBaseSite::UnlockBlitters()
  1688. {
  1689.     if (m_pVideoSurface)
  1690.     {
  1691.         m_pVideoSurface->_UnlockBlitter();
  1692.     }
  1693.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1694.     while(pos)
  1695.     {
  1696.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1697.         pSite->UnlockBlitters();
  1698.     }
  1699. }
  1700. void CHXBaseSite::FlushSurfaces()
  1701. {
  1702.     if (m_pVideoSurface)
  1703.     {
  1704.         m_pVideoSurface->_FlushSurfaces();
  1705.     }
  1706.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1707.     while(pos)
  1708.     {
  1709.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1710.         pSite->FlushSurfaces();
  1711.     }
  1712. }
  1713. void CHXBaseSite::DisableColorControls(float &fBrightness,
  1714.                                        float &fContrast,
  1715.                                        float &fSaturation,
  1716.                                        float &fHue)
  1717. {
  1718.     if (m_pParentSite)
  1719.     {
  1720.         m_pParentSite->DisableColorControls(fBrightness,
  1721.                                             fContrast,
  1722.                                             fSaturation,
  1723.                                             fHue);
  1724.         return;
  1725.     }
  1726.     m_fHue = 0;
  1727.     m_fSaturation = 0;
  1728.     m_fContrast = 0;
  1729.     m_fBrightness = 0;
  1730. }
  1731. void CHXBaseSite::EnableColorControls(float fBrightness,
  1732.                                       float fContrast,
  1733.                                       float fSaturation,
  1734.                                       float fHue)
  1735. {
  1736.     if (m_pParentSite)
  1737.     {
  1738.         m_pParentSite->EnableColorControls(fBrightness,
  1739.                                            fContrast,
  1740.                                            fSaturation,
  1741.                                            fHue);
  1742.         return;
  1743.     }
  1744.     m_fHue = fHue;
  1745.     m_fSaturation = fSaturation;
  1746.     m_fContrast = fContrast;
  1747.     m_fBrightness = fBrightness;
  1748. }
  1749. void CHXBaseSite::ReInitSurfaces()
  1750. {
  1751.     if (m_pVideoSurface)
  1752.     {
  1753.         m_pVideoSurface->ReInitSurfaces();
  1754.     }
  1755.     if (m_pRootSurface)
  1756.     {
  1757.         m_pRootSurface->ReInitSurfaces();
  1758.     }
  1759.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1760.     while(pos)
  1761.     {
  1762.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1763.         pSite->ReInitSurfaces();
  1764.     }
  1765. }
  1766. void CHXBaseSite::_EmptyBlenderList()
  1767. {
  1768.     if( m_pTopLevelSite && m_pTopLevelSite->m_pMutex  )
  1769.         _TLSLock();
  1770.     CHXMapPtrToPtr::Iterator iter = m_AlphaBlendSites.Begin();
  1771.     for ( ; iter != m_AlphaBlendSites.End(); ++iter)
  1772.     {
  1773.         HXREGION* pTmp = (HXREGION*)*iter;
  1774.         HXDestroyRegion( pTmp );
  1775.         pTmp = NULL;
  1776.     }
  1777.     m_AlphaBlendSites.RemoveAll();
  1778.     if( m_pTopLevelSite && m_pTopLevelSite->m_pMutex  )
  1779.         _TLSUnlock();
  1780. }
  1781. void CHXBaseSite::_EmptyNotifierList()
  1782. {
  1783.     if( m_pTopLevelSite && m_pTopLevelSite->m_pMutex )
  1784.         _TLSLock();
  1785.     m_bUsingList = FALSE;
  1786.     CHXMapPtrToPtr::Iterator iter = m_AlphaBlendNotifiers.Begin();
  1787.     for ( ; iter != m_AlphaBlendNotifiers.End(); ++iter)
  1788.     {
  1789.         CHXBaseSite* pSite = (CHXBaseSite*)*iter;
  1790.         HX_RELEASE( pSite );
  1791.     }
  1792.     m_AlphaBlendNotifiers.RemoveAll();
  1793.     m_bUsingList = FALSE;
  1794.     if( m_pTopLevelSite && m_pTopLevelSite->m_pMutex )
  1795.         _TLSUnlock();
  1796. }
  1797. void CHXBaseSite::_AlphaBlendAddNotifier(CHXBaseSite* it)
  1798. {
  1799.     if( m_pTopLevelSite && m_pTopLevelSite->m_pMutex )
  1800.         _TLSLock();
  1801.     m_bUsingList = FALSE;
  1802.     CHXBaseSite* pNotUsed = NULL;
  1803.     if( NULL==m_AlphaBlendNotifiers.Lookup( (void*)it) )
  1804.     {
  1805.         //Does not exist yet.
  1806.         it->AddRef();
  1807.         m_AlphaBlendNotifiers.SetAt( it, it );
  1808.     }
  1809.     m_bUsingList = FALSE;
  1810.     if( m_pTopLevelSite && m_pTopLevelSite->m_pMutex )
  1811.         _TLSUnlock();
  1812. }
  1813. void CHXBaseSite::_RemoveAllNotifiers()
  1814. {
  1815.     _EmptyNotifierList();
  1816.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1817.     while(pos)
  1818.     {
  1819.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1820.         pSite->_RemoveAllNotifiers();
  1821.     }
  1822. }
  1823. void CHXBaseSite::_RemoveAllYUVImageLists()
  1824. {
  1825.     m_pVideoSurface->_RemoveYUVImageLists();
  1826.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1827.     while(pos)
  1828.     {
  1829.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1830.         pSite->_RemoveAllYUVImageLists();
  1831.     }
  1832. }
  1833. //  #if defined(_CHECK_PERFORMANCE)
  1834. //  LONG32 g_nNumTimes = 0;
  1835. //  double g_fTotalTime = 0;
  1836. //  double g_fAverageTime = 0;
  1837. //  #endif
  1838. void CHXBaseSite::RecomputeClip()
  1839. {
  1840. //  #if defined(_CHECK_PERFORMANCE)
  1841. //     double frequency, startTime;
  1842. //     static LARGE_INTEGER QueryPerformanceCounterResult = {0,0};
  1843. //     static LARGE_INTEGER QueryPerformanceFrequencyResult = {0,0};
  1844. //     if (this == m_pTopLevelSite)
  1845. //     {
  1846. //        QueryPerformanceFrequency(&QueryPerformanceFrequencyResult);
  1847. //        frequency = ((double)QueryPerformanceFrequencyResult.LowPart + 4294967296.0*QueryPerformanceFrequencyResult.HighPart);
  1848. //        QueryPerformanceCounter(&QueryPerformanceCounterResult);
  1849. //        startTime = ((double)QueryPerformanceCounterResult.LowPart + 4294967296.0*QueryPerformanceCounterResult.HighPart)/frequency;
  1850. //     }
  1851. //  #endif
  1852.     if( IsCompositionLocked() )
  1853.     {
  1854.         return;
  1855.     }
  1856.     m_bRegionIsValid = FALSE;
  1857.     //Need to clean up the notifier list here....
  1858.     if( this==m_pTopLevelSite )
  1859.     {
  1860.         _RemoveAllNotifiers();
  1861.     }
  1862.     //If we are a YUV site, add ourselves to the list.
  1863.     int nCID = GETBITMAPCOLOR(&(m_pVideoSurface->m_bmiLastBlt));
  1864.     if( IsYUV(nCID) )
  1865.     {
  1866.         if( !zm_YUVSiteList.Find(this) )
  1867.         {
  1868.             zm_YUVSiteList.AddTail(this);
  1869.         }
  1870.     }
  1871.     // this recomputes our clipping rect.
  1872.     if( ComputeSubRects() )
  1873.     {
  1874.         //We need to do this in Z-Order. So, create a temp map
  1875.         //and use the zorder as key and the pSite pointer as value.
  1876.         LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1877.         while(pos)
  1878.         {
  1879.             CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1880.             pSite->RecomputeClip();
  1881.         }
  1882.     }
  1883.     // do we have video under transition?
  1884.     if( this==m_pTopLevelSite)
  1885.     {
  1886.         FindLinkedSites();
  1887.     }
  1888.     SetClipping();
  1889. //  #if defined(_CHECK_PERFORMANCE)
  1890. //     if (this == m_pTopLevelSite)
  1891. //     {
  1892. //        QueryPerformanceCounter(&QueryPerformanceCounterResult);
  1893. //        double endTime = ((double)QueryPerformanceCounterResult.LowPart + 4294967296.0*QueryPerformanceCounterResult.HighPart)/frequency;
  1894. //        if (endTime > startTime)
  1895. //        {
  1896. //           g_nNumTimes++;
  1897. //           g_fTotalTime += endTime - startTime;
  1898. //           g_fAverageTime = g_fTotalTime / (double) g_nNumTimes;
  1899. //        }
  1900. //        if( g_nNumTimes%50==0 )
  1901. //        {
  1902. //           FILE* pFP=fopen("c:\file.txt", "a+");
  1903. //           if( pFP )
  1904. //           {
  1905. //              fprintf( pFP, "ave: %f  num: %ld  tot: %fn",
  1906. //                       g_fAverageTime, g_nNumTimes, g_fTotalTime);
  1907. //              fclose( pFP );
  1908. //           }
  1909. //        }
  1910. //     }
  1911. //  #endif
  1912. }
  1913. void CHXBaseSite::FindLinkedSites()
  1914. {
  1915.     m_ListOfRealVideoSites.RemoveAll();
  1916.     m_bVideoUnderTransition = FALSE;
  1917.     FindVideoSites();
  1918.     if (m_bVideoUnderTransition && m_ListOfRealVideoSites.GetCount() > 1)
  1919.     {
  1920.         // find out which one (if any) has overlay.
  1921.         // note: we should make this work with more than one overlay in the future.
  1922.         CHXSimpleList::Iterator i = m_ListOfRealVideoSites.Begin();
  1923.         CHXBaseSite* pSite = NULL;
  1924.         CHXBaseSite* pLinkedSite = NULL;
  1925.         for(;i!=m_ListOfRealVideoSites.End(); ++i)
  1926.         {
  1927.             pSite = (CHXBaseSite*) *i;
  1928.             if (pSite->m_pVideoSurface->m_surfaceSize.cx != 0 && pSite->m_pVideoSurface->m_nBltMode == HX_OVERLAY_BLT)
  1929.             {
  1930.                 break;
  1931.             }
  1932.             pSite = NULL;
  1933.         }
  1934. #ifdef DEBUG_LINKING
  1935.     {
  1936.         char szbuff[255]; /* Flawfinder: ignore */
  1937.         sprintf(szbuff, "Under Transition Master Site = %pn", pSite); /* Flawfinder: ignore */
  1938.         OutputDebugString(szbuff);
  1939.     }
  1940. #endif
  1941.         // yup it looks like one of the sites has overlay.
  1942.         if (pSite)
  1943.         {
  1944.             i = m_ListOfRealVideoSites.Begin();
  1945.             for(;i!=m_ListOfRealVideoSites.End(); ++i)
  1946.             {
  1947.                 pLinkedSite = (CHXBaseSite*) *i;
  1948.                 if (pLinkedSite != pSite &&
  1949.                     pLinkedSite->m_topleft.x == pSite->m_topleft.x  &&
  1950.                     pLinkedSite->m_topleft.y == pSite->m_topleft.y  &&
  1951.                     pLinkedSite->m_size.cx   == pSite->m_size.cx    &&
  1952.                     pLinkedSite->m_size.cy   == pSite->m_size.cy
  1953.                     )
  1954.                 {
  1955.                     // we have a site on top of us. And it is at least partially visible.
  1956.                     pLinkedSite->m_pVideoSurface->LinkOverlay(pSite);
  1957.                     pSite->m_pVideoSurface->AddLinkedSite(pLinkedSite);
  1958.                     // of course we have to come up with some mechanisim to unlink the overlay.
  1959. #ifdef DEBUG_LINKING
  1960.                 {
  1961.                     char szbuff[255]; /* Flawfinder: ignore */
  1962.                     sprintf(szbuff, "Linking Site %p  Surface %p to Site %p n", pLinkedSite, pLinkedSite->m_pVideoSurface, pSite); /* Flawfinder: ignore */
  1963.                     OutputDebugString(szbuff);
  1964.                 }
  1965. #endif
  1966.                 }
  1967.                 else
  1968.                 {
  1969. #ifdef DEBUG_LINKING
  1970.                     if (pLinkedSite != pSite)
  1971.                     {
  1972.                         char szbuff[255]; /* Flawfinder: ignore */
  1973.                         sprintf(szbuff, "NO link (%d, %d, %d, %d) != (%d, %d, %d, %d)n", /* Flawfinder: ignore */
  1974.                                 pLinkedSite->m_topleft.x, pLinkedSite->m_topleft.y,
  1975.                                 pLinkedSite->m_size.cx, pLinkedSite->m_size.cy,
  1976.                                 pSite->m_topleft.x, pSite->m_topleft.y,
  1977.                                 pSite->m_size.cx, pSite->m_size.cy);
  1978.                         OutputDebugString(szbuff);
  1979.                     }
  1980. #endif
  1981.                 }
  1982.             }
  1983.         }
  1984.     }
  1985. }
  1986. void CHXBaseSite::SetClipping()
  1987. {
  1988.     if (m_pParentSite && m_pWindow && m_pWindow->window)
  1989.     {
  1990.         static CHXMapPtrToPtr z_map;
  1991.         int i;
  1992.         if (!z_map.Lookup(this, (void*&)i))
  1993.         {
  1994.             i= z_map.GetCount();
  1995.             z_map.SetAt(this, (void*&)i);
  1996.         }
  1997. #ifdef _DEBUG
  1998.         if (m_Region->numRects)
  1999.         {
  2000.             FILE* f = fopen("c:\blt.txt", "a+"); /* Flawfinder: ignore */
  2001.             fprintf(f, "index: %d this - %d  hwnd %d VISIBLE: %s (%d, %d, %d, %d)  NumBoxes: %d n", i, this,
  2002.                     m_pWindow->window, m_bIsVisible ? "TRUE" : "FALSE",
  2003.                     (INT32)m_topleft.x,
  2004.                     (INT32)m_topleft.y,
  2005.                     (INT32)m_size.cx,
  2006.                     (INT32)m_size.cy, m_Region->numRects);
  2007.             fclose(f);
  2008.         }
  2009. #endif
  2010.         //      *** HMW - Fix a windowed renderer window (HWND) positioning bug.
  2011.         //      The x and y positions was previously picked up from m_position, causing the child window to always be positioned at 0,0
  2012.         SafeMoveWindow((void*) m_pWindow->window,
  2013.                        (int)m_topleft.x,
  2014.                        (int)m_topleft.y,
  2015.                        (int)m_size.cx ,
  2016.                        (int)m_size.cy ,
  2017.                        m_bIsVisible);
  2018.         SafeSetWindowRgn(m_pWindow->window, m_Region, TRUE);
  2019.         // XXXAH This is all buggered up. Have to fix
  2020.     }
  2021.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2022.     while(pos)
  2023.     {
  2024.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2025.         pSite->SetClipping();
  2026.     }
  2027. }
  2028. void CHXBaseSite::FindVideoSites()
  2029. {
  2030. #ifdef DEBUG_LINKING
  2031.     {
  2032.         char szbuff[255]; /* Flawfinder: ignore */
  2033.         sprintf(szbuff, "FindVideoSites this = %ptRects: %dtCID=%dtblts= %sn", /* Flawfinder: ignore */
  2034.                 this,
  2035.                 m_Region->numRects,
  2036.                 m_pVideoSurface->m_nSrcCID,
  2037.                 !m_bSiteNeverBlts ? "TRUE":"FALSE");
  2038.         OutputDebugString(szbuff);
  2039.     }
  2040. #endif
  2041.     if( IsYUV(GETBITMAPCOLOR(&m_pVideoSurface->m_bmiLastBlt)))
  2042.     {
  2043.         if (! m_Region->numRects && !m_AlphaBlendNotifiers.GetCount())
  2044.         {
  2045. //            m_pVideoSurface->RelinquishOverlay();
  2046.         }
  2047.         else
  2048.         {
  2049.             if  ( !m_bSiteNeverBlts &&  !_BlendedBordersActive() && !_BordersActive())
  2050.             {
  2051.                 m_pTopLevelSite->m_ListOfRealVideoSites.AddTail(this);
  2052.                 if (m_fpTransitionEffect != DefaultTransition)
  2053.                 {
  2054.                     m_pTopLevelSite->m_bVideoUnderTransition = TRUE;
  2055.                 }
  2056.             }
  2057.         }
  2058.     }
  2059.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2060.     while(pos)
  2061.     {
  2062.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2063.         pSite->FindVideoSites();
  2064.     }
  2065. }
  2066. INT32 CHXBaseSite::GetTopMostSiteZOrder()
  2067. {
  2068.     INT32 nZorder = 0;
  2069.     CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetTail();
  2070.     if( pSite )
  2071.         pSite->GetZOrder(nZorder);
  2072.     return nZorder;
  2073. }
  2074. void CHXBaseSite::SetParentWindow(HXxWindow* pWindow)
  2075. {
  2076.     if (pWindow)
  2077.     {
  2078.         memcpy(&m_TopLevelWindow, pWindow, sizeof(HXxWindow)); /* Flawfinder: ignore */
  2079.     }
  2080.     else
  2081.     {
  2082.         memset(&m_TopLevelWindow, 0 , sizeof(HXxWindow));
  2083.     }
  2084.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2085.     while(pos)
  2086.     {
  2087.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2088.         pSite->SetParentWindow(pWindow);
  2089.     }
  2090. }
  2091. void CHXBaseSite::SetRootSurface(CBaseRootSurface* pSurface)
  2092. {
  2093.     HX_RELEASE(m_pRootSurface);
  2094.     m_pRootSurface = pSurface;
  2095.     if (m_pRootSurface)
  2096.     {
  2097.         m_pRootSurface->AddRef();
  2098.         // Enable/Disable optimized video
  2099.         IHXPreferences*    pPreferences    = NULL;
  2100.         IHXBuffer*         pBuffer         = NULL;
  2101.         if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  2102.         {
  2103.             if (pPreferences->ReadPref("UseWinDraw", pBuffer) == HXR_OK)
  2104.             {
  2105.                 BOOL bUseWindraw = ::atoi((char*) pBuffer->GetBuffer()) == 1;
  2106.                 if (bUseWindraw)
  2107.                     m_pRootSurface->_EnableHardwareAcceleration();
  2108.                 else
  2109.                     m_pRootSurface->_DisableHardwareAcceleration();
  2110.                 HX_RELEASE(pBuffer);
  2111.             }
  2112.             HX_RELEASE(pPreferences);
  2113.         }
  2114.     }
  2115.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2116.     while(pos)
  2117.     {
  2118.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2119.         pSite->SetRootSurface(pSurface);
  2120.     }
  2121. }
  2122. void CHXBaseSite::CheckColorSettings()
  2123. {
  2124. // NOTE 40 steps of granularity for color control parameters (based on
  2125. // below float to int precision; proper rounding is not essential)
  2126.     if (m_pParentSite)
  2127.     {
  2128.         m_pParentSite->CheckColorSettings();
  2129.         return;
  2130.     }
  2131.     float fCurrentBrightness;
  2132.     float fCurrentContrast;
  2133.     float fCurrentSaturation;
  2134.     float fCurrentHue;
  2135.     zm_pColorAcc->GetColorAdjustments(&fCurrentBrightness, &fCurrentContrast, &fCurrentSaturation, &fCurrentHue);
  2136.     if( (int)(fCurrentBrightness * 20.f) != (int)(m_fBrightness * 20.f) ||
  2137.         (int)(fCurrentContrast * 20.f) != (int)(m_fContrast * 20.f) ||
  2138.         (int)(fCurrentSaturation * 20.f) != (int)(m_fSaturation * 20.f) ||
  2139.         (int)(fCurrentHue * 20.f) != (int)(m_fHue * 20.f) )
  2140.     {
  2141.         // Adjust colors according to video control settings
  2142.         zm_pColorAcc->SetColorAdjustments(m_fBrightness,
  2143.                                           m_fContrast, m_fSaturation, m_fHue);
  2144.     }
  2145.     float   fCurrentSharpness;
  2146.     INT16   bInterpolate;
  2147.     zm_pColorAcc->GetSharpnessAdjustments(&fCurrentSharpness, &bInterpolate);
  2148.     if (fCurrentSharpness != m_fSharpness)
  2149.     {
  2150.         zm_pColorAcc->SetSharpnessAdjustments(m_fSharpness, FALSE);
  2151.     }
  2152. }
  2153. BOOL CHXBaseSite::SharpenImage(HXBitmapInfoHeader* pOptimizedFormat, UCHAR* pImageBits, REF(HXxRect) rSrcRect)
  2154. {
  2155.     if (m_pParentSite)
  2156.     {
  2157.         return m_pParentSite->SharpenImage(pOptimizedFormat, pImageBits, rSrcRect);
  2158.     }
  2159.     BOOL bDidSharpen = FALSE;
  2160.     if( zm_pColorAcc &&
  2161.         (m_fSharpness+1.0)>0.1 &&
  2162.         IsYUVPlanar(GETBITMAPCOLOR(pOptimizedFormat)) )
  2163.     {
  2164.         INT32 nSrcWidth = rSrcRect.right - rSrcRect.left;
  2165.         INT32 nSrcHeight = rSrcRect.bottom - rSrcRect.top;
  2166.         bDidSharpen = TRUE;
  2167.         INT32   ulSrcPitch = GETBITMAPPITCH(pOptimizedFormat);
  2168.         INT32   ulYOffset  = rSrcRect.top * ulSrcPitch + rSrcRect.left;
  2169.         UCHAR*  ySrc       = pImageBits + ulYOffset;
  2170.         //do edge enhancement if it is not already done once
  2171.         if(ySrc[0] != 1)
  2172.         {
  2173.             if(m_bModeSharpness)
  2174.             {
  2175.                 //Deblocking filter is ON
  2176.                 zm_pColorAcc->EnhanceUniform(ySrc,nSrcHeight,
  2177.                                              nSrcWidth,ulSrcPitch,m_fSharpness);
  2178.             }
  2179.             else
  2180.             {
  2181.                 //Deblocking filter is OFF
  2182.                 zm_pColorAcc->Enhance(ySrc,nSrcHeight,
  2183.                                       nSrcWidth,ulSrcPitch,m_fSharpness);
  2184.             }
  2185.         }
  2186.         else
  2187.         {
  2188.             //replicate pixel
  2189.             ySrc[0]=ySrc[1];
  2190.         }
  2191.     }
  2192.     return bDidSharpen;
  2193. }
  2194. void CHXBaseSite::SiteMoving(INT32 x, INT32 y)
  2195. {
  2196. #if 1
  2197.     m_bMoving = TRUE;
  2198.     m_pVideoSurface->UpdateDestRect(x,y);
  2199. #else
  2200.     //GDI mode is *way* too expensive if we have alphablended ARGB
  2201.     //content ontop of it. It just kills the whole system.  So, we
  2202.     //will stay in overlay mode in those cases.
  2203.     if( !m_pVideoSurface->m_bYUVBlending )
  2204.     {
  2205.         if( !m_pVideoSurface->ForceGDIMode(TRUE))
  2206.             m_pVideoSurface->UpdateDestRect(x,y);
  2207.     }
  2208.     else
  2209.     {
  2210.         m_pVideoSurface->UpdateDestRect(x,y);
  2211.     }
  2212. #endif
  2213.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2214.     while(pos)
  2215.     {
  2216.         CHXBaseSite* pChildSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2217.         pChildSite->SiteMoving(x,y);
  2218.     }
  2219.     if( this == m_pTopLevelSite )
  2220.     {
  2221.         FillColorKey();
  2222.         ScheduleCallback( REDRAW_ALL, 0 );
  2223.     }
  2224. }
  2225. void
  2226. CHXBaseSite::ResetOrigin()
  2227. {
  2228.     m_topleft.x =0;
  2229.     m_topleft.y =0;
  2230.     GetAbsoluteCords(m_topleft);
  2231.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2232.     while(pos)
  2233.     {
  2234.         CHXBaseSite* pChildSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2235.         pChildSite->ResetOrigin();
  2236.     }
  2237. }
  2238. void
  2239. CHXBaseSite::GetAbsoluteCords(REF(HXxPoint) point)
  2240. {
  2241.     point.x += m_position.x;
  2242.     point.y += m_position.y;
  2243.     if (m_pParentSite)
  2244.     {
  2245.         m_pParentSite->GetAbsoluteCords(point);
  2246.     }
  2247.     return;
  2248. }
  2249. void
  2250. CHXBaseSite::AboutToBlt()
  2251. {
  2252.     if (m_pTopLevelSite != this)
  2253.     {
  2254.         m_pTopLevelSite->AboutToBlt();
  2255.         return;
  2256.     }
  2257.     if (m_bAboutToBlt)
  2258.     {
  2259.         return;
  2260.     }
  2261.     m_bAboutToBlt = TRUE;
  2262.     if (m_bRecomputeClipScheduled)
  2263.     {
  2264.         if (m_CallbackHandle)
  2265.         {
  2266.             m_pScheduler->Remove(m_CallbackHandle);
  2267.             m_CallbackHandle = 0;
  2268.         }
  2269.         Func();
  2270.     }
  2271.     m_bAboutToBlt = FALSE;
  2272. }
  2273. void
  2274. CHXBaseSite::FillColorKey()
  2275. {
  2276.     m_pVideoSurface->FillColorKey();
  2277.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2278.     while(pos)
  2279.     {
  2280.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2281.         pSite->FillColorKey();
  2282.     }
  2283. }
  2284. BOOL
  2285. CHXBaseSite::SafeMoveWindow(void* hWnd, INT32 X, INT32 Y, INT32 nWidth, INT32 nHeight, BOOL bRepaint)
  2286. {
  2287.     if (_AtSystemTime())
  2288.     {
  2289.         m_pTopLevelSite->ExecutePendingTasks();
  2290.         return _MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint);
  2291.     }
  2292.     PendingTask* pPendingTask = new PendingTask(ONMOVEWINDOW, this, (void*) hWnd, (void*) X, (void*) Y, (void*) nWidth, (void*) nHeight, (void*) bRepaint);
  2293.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2294.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2295.     return TRUE;
  2296. }
  2297. BOOL
  2298. CHXBaseSite::SafeUpdateWindow(void* hWnd)
  2299. {
  2300.     if (_AtSystemTime())
  2301.     {
  2302.         m_pTopLevelSite->ExecutePendingTasks();
  2303.         return _UpdateWindow(hWnd);
  2304.     }
  2305.     PendingTask* pPendingTask = new PendingTask(ONUPDATEWINDOW, this, (void*) hWnd);
  2306.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2307.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2308.     return TRUE;
  2309. }
  2310. BOOL CHXBaseSite::SafeShowWindow(void* hWnd, INT32 nCmdShow)
  2311. {
  2312.     if (_AtSystemTime())
  2313.     {
  2314.         m_pTopLevelSite->ExecutePendingTasks();
  2315.         return _ShowWindow(hWnd, nCmdShow);
  2316.     }
  2317.     PendingTask* pPendingTask = new PendingTask(ONSHOWWINDOW, this, (void*) hWnd, (void*) nCmdShow);
  2318.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2319.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2320.     return TRUE;
  2321. }
  2322. BOOL CHXBaseSite::SafeSetWindowPos(void* hWnd, void* hWndInsertAfter, INT32 X, INT32 Y, INT32 cx, INT32 cy, UINT uFlags)
  2323. {
  2324.     if (_AtSystemTime())
  2325.     {
  2326.         m_pTopLevelSite->ExecutePendingTasks();
  2327.         BOOL ret = _SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
  2328.         return    ret;
  2329.     }
  2330.     PendingTask* pPendingTask = new PendingTask(ONSETWINDOWPOS, this, (void*) hWnd, (void*) hWndInsertAfter, (void*) X, (void*) Y, (void*) cx, (void*) cy, (void*) uFlags);
  2331.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2332.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2333.     return TRUE;
  2334. }
  2335. INT32 CHXBaseSite::SafeSetWindowRgn(void* hWnd, HXREGION* hRgn, BOOL bRedraw)
  2336. {
  2337.     if (_AtSystemTime())
  2338.     {
  2339.         m_pTopLevelSite->ExecutePendingTasks();
  2340.         return _SetWindowRgn(hWnd, hRgn, bRedraw);
  2341.     }
  2342.     // create a temp region
  2343.     HXREGION*      hTemp           = NULL;
  2344.     hTemp = HXCreateRectRegion(0,0,0,0);
  2345.     HXUnionRegion(hTemp, hRgn, hTemp);
  2346.     PendingTask* pPendingTask = new PendingTask(ONSETWINDOWREGION, this, (void*) hWnd, (void*) hTemp, (void*) bRedraw);
  2347.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2348.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2349.     return 1;
  2350. }
  2351. void CHXBaseSite::SafeSetXSliderRange(INT32 range)
  2352. {
  2353.     if (_AtSystemTime())
  2354.     {
  2355.         m_pTopLevelSite->ExecutePendingTasks();
  2356.         SetXSliderRange(range);
  2357.         return;
  2358.     }
  2359.     PendingTask* pPendingTask = new PendingTask(ONSETXSLIDER, this, (void*) range);
  2360.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2361.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2362. }
  2363. void CHXBaseSite::SafeSetYSliderRange(INT32 range)
  2364. {
  2365.     if (_AtSystemTime())
  2366.     {
  2367.         m_pTopLevelSite->ExecutePendingTasks();
  2368.         SetYSliderRange(range);
  2369.         return;
  2370.     }
  2371.     PendingTask* pPendingTask = new PendingTask(ONSETYSLIDER, this, (void*) range);
  2372.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2373.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2374. }
  2375. void CHXBaseSite::SafeSetFocus(HXxWindow* pWindow)
  2376. {
  2377.     if (_AtSystemTime())
  2378.     {
  2379.         m_pTopLevelSite->ExecutePendingTasks();
  2380.         _SetFocus(pWindow->window);
  2381.         return;
  2382.     }
  2383.     PendingTask* pPendingTask = new PendingTask(ONSETFOCUS, this, (void*) pWindow);
  2384.     m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
  2385.     m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
  2386. }
  2387. void
  2388. CHXBaseSite::ExecutePendingTasks()
  2389. {
  2390.     if (_AtSystemTime())
  2391.     {
  2392.         while(m_PendingTaskList.GetCount())
  2393.         {
  2394.             PendingTask* pPendingTask = (PendingTask*) m_PendingTaskList.RemoveHead();
  2395.             switch(pPendingTask->m_TaskType)
  2396.             {
  2397.                case ONMOVEWINDOW:
  2398.                    _MoveWindow(pPendingTask->m_ulArg1, (int) pPendingTask->m_ulArg2, (int) pPendingTask->m_ulArg3, (int) pPendingTask->m_ulArg4, (int) pPendingTask->m_ulArg5, (BOOL) (int) pPendingTask->m_ulArg6);
  2399.                    break;
  2400.                case ONUPDATEWINDOW:
  2401.                    _UpdateWindow(pPendingTask->m_ulArg1);
  2402.                    break;
  2403.                case ONSHOWWINDOW:
  2404.                    _ShowWindow(pPendingTask->m_ulArg1, (int) pPendingTask->m_ulArg2);
  2405.                    break;
  2406.                case ONSETWINDOWPOS:
  2407.                    _SetWindowPos(pPendingTask->m_ulArg1, pPendingTask->m_ulArg2, (int) pPendingTask->m_ulArg3, (int) pPendingTask->m_ulArg4, (int) pPendingTask->m_ulArg5, (int) pPendingTask->m_ulArg6, (UINT) pPendingTask->m_ulArg7);
  2408.                    break;
  2409.                case ONSETWINDOWREGION:
  2410.                    _SetWindowRgn( pPendingTask->m_ulArg1, (HXREGION*)pPendingTask->m_ulArg2, (BOOL) pPendingTask->m_ulArg3);
  2411.                    HXDestroyRegion((HXREGION*)pPendingTask->m_ulArg2);
  2412.                    break;
  2413.                case ONSETXSLIDER:
  2414.                    pPendingTask->m_pThis->SetXSliderRange((int)pPendingTask->m_ulArg1);
  2415.                    break;
  2416.                case ONSETYSLIDER:
  2417.                    pPendingTask->m_pThis->SetYSliderRange((int)pPendingTask->m_ulArg1);
  2418.                    break;
  2419.                case ONSETFOCUS:
  2420.                    pPendingTask->m_pThis->_SetFocus( pPendingTask->m_ulArg1);
  2421.                    break;
  2422.                case ONSETSIZE:
  2423.                    HXxSize size;
  2424.                    size.cx = (long)pPendingTask->m_ulArg1;
  2425.                    size.cy = (long)pPendingTask->m_ulArg2;
  2426.                    pPendingTask->m_pThis->_SafeSetSize(size);
  2427.                    break;
  2428.                case ONSETPOSITION:
  2429.                    HXxPoint position;
  2430.                    position.x = (long)pPendingTask->m_ulArg1;
  2431.                    position.y = (long)pPendingTask->m_ulArg2;
  2432.                    pPendingTask->m_pThis->_SafeSetPosition(position);
  2433.                    break;
  2434.                default:
  2435.                    HX_ASSERT(FALSE);
  2436.                    break;
  2437.             }
  2438.             HX_DELETE(pPendingTask);
  2439.         }
  2440.     }
  2441. }
  2442. void
  2443. CHXBaseSite::RemovePendingTasks(CHXBaseSite* pThis)
  2444. {
  2445.     LISTPOSITION pPos;
  2446.     pPos = m_PendingTaskList.GetHeadPosition();
  2447.     while(pPos)
  2448.     {
  2449.         PendingTask* pPendingTask = (PendingTask*) m_PendingTaskList.GetAt(pPos);
  2450.         if (pPendingTask->m_pThis == pThis)
  2451.         {
  2452.             pPos = m_PendingTaskList.RemoveAt(pPos);
  2453.             HX_DELETE(pPendingTask);
  2454.         }
  2455.         else
  2456.         {
  2457.             m_PendingTaskList.GetNext(pPos);
  2458.         }
  2459.     }
  2460. }
  2461. void CHXBaseSite::ResetUpdateOverlay()
  2462. {
  2463.     if (m_pVideoSurface)
  2464.     {
  2465.         m_pVideoSurface->ResetUpdateOverlay();
  2466.     }
  2467.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2468.     while(pos)
  2469.     {
  2470.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  2471.         pSite->ResetUpdateOverlay();
  2472.     }
  2473. }
  2474. HXREGION* CHXBaseSite::Transition(INT32 left, INT32 top, INT32 right, INT32 bottom, tranLines* lines)
  2475. {
  2476.     INT32   completeness = m_nTransitionState;
  2477.     if (lines)
  2478.         lines->Destroy();
  2479.     // if this is a default transition we don't ever want to invert it!
  2480.     if (m_fpTransitionEffect == DefaultTransition ||
  2481.         m_fpTransitionEffect == SlideFromLeft ||
  2482.         m_fpTransitionEffect == SlideFromBottom ||
  2483.         m_fpTransitionEffect == SlideFromRight ||
  2484.         m_fpTransitionEffect == SlideFromTop ||
  2485.         m_fpTransitionEffect == Crossfade ||
  2486.         m_fpTransitionEffect == FadeFromColor ||
  2487.         m_fpTransitionEffect == FadeToColor
  2488.         )
  2489.     {
  2490.         return m_fpTransitionEffect(left, top, right, bottom, completeness, NULL);
  2491.     }
  2492.     tranLines* tmpLines = (completeness > 0 && completeness < 1000) ? lines : NULL;
  2493.     HXREGION* retRGN = HXCreateRegion();
  2494.     double vSize = double(bottom - top) / double(m_nTransitionVertRepeat);
  2495.     double hSize = double(right - left) / double(m_nTransitionHorzRepeat);
  2496.     if (m_bTransitionReversed)
  2497.         completeness = 1000 - m_nTransitionState;
  2498.     for (int h = 0; h < m_nTransitionHorzRepeat; ++h)
  2499.     {
  2500.         for (int v = 0; v < m_nTransitionVertRepeat; ++v)
  2501.         {
  2502.             INT32 l = left + int(hSize * h);
  2503.             INT32 t = top + int(vSize * v);
  2504.             HXREGION* tmpRgn = m_fpTransitionEffect(l, t, int(l + hSize), int(t + vSize), completeness, tmpLines);
  2505.             HXCombineRgn( retRGN, retRGN, tmpRgn, HX_RGN_OR);
  2506.             HXDestroyRegion(tmpRgn);
  2507.         }
  2508.     }
  2509.     if (tmpLines)
  2510.         tmpLines->Clip(left, top, right - 1, bottom - 1);
  2511.     if (!(m_bTransitionTranIn ^ m_bTransitionReversed))
  2512.         retRGN = InvertRGN(retRGN, left, top, right, bottom);
  2513.     //Intersect with our rect.
  2514.     HXREGION* pMe = HXCreateRectRegion( m_topleft.x,
  2515.                                         m_topleft.y,
  2516.                                         m_size.cx,
  2517.                                         m_size.cy
  2518.                                         );
  2519.     HXIntersectRegion( retRGN, pMe, retRGN );
  2520.     HXDestroyRegion( pMe );
  2521.     return retRGN;
  2522. }
  2523. //Incoming coords are OS Winow relative....
  2524. void CHXBaseSite::_RecursiveDamageRect( HXxRect* dirtyRect, BOOL bForce )
  2525. {
  2526.     HXxRect rect = {0, 0, 0, 0};
  2527.     HXREGION* pReg = HXCreateRectRegion( dirtyRect->left,
  2528.                                          dirtyRect->top,
  2529.                                          dirtyRect->right-dirtyRect->left,
  2530.                                          dirtyRect->bottom-dirtyRect->top
  2531.                                          );
  2532.     //Find out what part intersects us.
  2533.     HXREGION* pTemp     = HXCreateRegion();
  2534.     HXxPoint*  pPosition = GetOrigin();
  2535.     if( m_Region && !bForce )
  2536.     {
  2537.         HXIntersectRegion( m_Region, pReg, pTemp );
  2538.     }
  2539.     else
  2540.     {
  2541.         HXZeroOutRegion( pTemp );
  2542.         HXUnionRegion( pTemp, pReg, pTemp );
  2543.     }
  2544.     if( !HXEmptyRegion(pTemp) )
  2545.     {
  2546.         HXUnionRegion(m_pDirtyRegion, pTemp, m_pDirtyRegion );
  2547.         //We must now verify our dirty region does not fall outside of our
  2548.         //real boundries. If the site is animated it can move in such a
  2549.         //way that we will get negative offsets once we turn the region to
  2550.         //site relative coordinates in the HX_SURFACE_UPDATE2 message.
  2551.         HXDestroyRegion( pTemp );
  2552.         pTemp  = Transition( pPosition->x, pPosition->y,
  2553.                              pPosition->x + m_size.cx,
  2554.                              pPosition->y + m_size.cy
  2555.                              );
  2556.         HXIntersectRegion( pTemp, m_pDirtyRegion, m_pDirtyRegion );
  2557.     }
  2558.     HXDestroyRegion( pTemp );
  2559.     HXDestroyRegion( pReg );
  2560.     CHXSimpleList::Iterator it = m_ChildrenInZOrder.Begin();
  2561.     while( it != m_ChildrenInZOrder.End() )
  2562.     {
  2563.         CHXBaseSite* pSite = (CHXBaseSite*)*it;
  2564.         if( pSite )
  2565.             pSite->_RecursiveDamageRect(dirtyRect, bForce);
  2566.         ++it;
  2567.     }
  2568. }
  2569. //Incoming coords are OS Winow relative....
  2570. void CHXBaseSite::ManageExposeEvents( HXxRect* dirtyRect )
  2571. {
  2572.     //We may not be the toplevel site if there is a windowed renderer
  2573.     //being used.
  2574.     _RecursiveDamageRect(dirtyRect);
  2575.     ResetUpdateOverlay();
  2576.     FillColorKey();
  2577.     m_pTopLevelSite->_ForceRedrawAll();
  2578. }
  2579. void CHXBaseSite::InternalForceRedraw()
  2580. {
  2581.     m_bSiteRefresh = TRUE;
  2582.     ForceRedraw();
  2583.     m_bSiteRefresh = FALSE;
  2584. }
  2585. ////////////////////////////////////////////////
  2586. //
  2587. //    basesite callback
  2588. //
  2589. ////////////////////////////////////////////////
  2590. BaseSiteCallback::BaseSiteCallback(CHXBaseSite* pSite) :
  2591.     m_lRefCount (0)
  2592.                                                        ,m_pSite(pSite)
  2593. {
  2594. }
  2595. BaseSiteCallback::~BaseSiteCallback()
  2596. {
  2597. }
  2598. STDMETHODIMP BaseSiteCallback::QueryInterface(REFIID riid, void** ppvObj)
  2599. {
  2600.     if (IsEqualIID(riid, IID_IHXCallback))
  2601.     {
  2602.         AddRef();
  2603.         *ppvObj = (IHXCallback*)this;
  2604.         return HXR_OK;
  2605.     }
  2606.     else if (IsEqualIID(riid, IID_IUnknown))
  2607.     {
  2608.         AddRef();
  2609.         *ppvObj = this;
  2610.         return HXR_OK;
  2611.     }
  2612.     *ppvObj = NULL;
  2613.     return HXR_NOINTERFACE;
  2614. }
  2615. STDMETHODIMP_(ULONG32) BaseSiteCallback::AddRef()
  2616. {
  2617.     return m_pSite->AddRef();
  2618. }
  2619. STDMETHODIMP_(ULONG32) BaseSiteCallback::Release()
  2620. {
  2621.     return m_pSite->Release();
  2622. }
  2623. STDMETHODIMP BaseSiteCallback::Func(void)
  2624. {
  2625.     if(m_pSite)
  2626.     {
  2627.         m_pSite->Func();
  2628.     }
  2629.     return HXR_OK;
  2630. }
  2631. ScrollSiteCallback::ScrollSiteCallback(CHXBaseSite* pSite) :
  2632.     m_lRefCount (0)
  2633.     ,m_pSite(pSite)
  2634. {
  2635. }
  2636. ScrollSiteCallback::~ScrollSiteCallback()
  2637. {
  2638. }
  2639. STDMETHODIMP ScrollSiteCallback::QueryInterface(REFIID riid, void** ppvObj)
  2640. {
  2641.     if (IsEqualIID(riid, IID_IHXCallback))
  2642.     {
  2643.         AddRef();
  2644.         *ppvObj = (IHXCallback*)this;
  2645.         return HXR_OK;
  2646.     }
  2647.     else if (IsEqualIID(riid, IID_IUnknown))
  2648.     {
  2649.         AddRef();
  2650.         *ppvObj = this;
  2651.         return HXR_OK;
  2652.     }
  2653.     *ppvObj = NULL;
  2654.     return HXR_NOINTERFACE;
  2655. }
  2656. STDMETHODIMP_(ULONG32) ScrollSiteCallback::AddRef()
  2657. {
  2658.     return m_pSite->AddRef();
  2659. }
  2660. STDMETHODIMP_(ULONG32) ScrollSiteCallback::Release()
  2661. {
  2662.     return m_pSite->Release();
  2663. }
  2664. STDMETHODIMP ScrollSiteCallback::Func(void)
  2665. {
  2666.     if(m_pSite)
  2667.     {
  2668.         m_pSite->FuncSizeSliders();
  2669.     }
  2670.     return HXR_OK;
  2671. }
  2672. STDMETHODIMP CHXBaseSite::LockComposition()
  2673. {
  2674.     if(m_pParentSite)
  2675.     {
  2676.         return m_pParentSite->LockComposition();
  2677.     }
  2678.     if( !m_bCompositionMode )
  2679.         return HXR_FAIL;
  2680.     m_bCompositionLocked = TRUE;
  2681.     return HXR_OK;
  2682. }
  2683. STDMETHODIMP CHXBaseSite::SetCompositionMode(BOOL OnOrOff )
  2684. {
  2685.     if(m_pParentSite)
  2686.     {
  2687.         return m_pParentSite->SetCompositionMode(OnOrOff);
  2688.     }
  2689.     m_bCompositionMode = OnOrOff;
  2690.     return HXR_OK;
  2691. }
  2692. STDMETHODIMP CHXBaseSite::UnlockComposition()
  2693. {
  2694.     HX_RESULT ret = HXR_OK;
  2695.     _TLSLock();
  2696.     if( m_pParentSite)
  2697.     {
  2698.         ret = m_pParentSite->UnlockComposition();
  2699.         _TLSUnlock();
  2700.         return ret;
  2701.     }
  2702.     if( !m_bCompositionMode )
  2703.     {
  2704.         _TLSUnlock();
  2705.         return HXR_FAIL;
  2706.     }
  2707.     m_bCompositionLocked = FALSE;
  2708.     //Do a recompute clip and redraw all.
  2709.     HX_ASSERT( m_pParentSite==NULL);
  2710.     HX_ASSERT( this == m_pTopLevelSite );
  2711.     m_bDisableForceRedraw = TRUE;
  2712.     RecomputeClip();
  2713.     m_bDisableForceRedraw = FALSE;
  2714.     _ForceRedrawAll();
  2715.     m_bCalledComputeClipFromTransition = FALSE;
  2716.     FillColorKey();
  2717.     _TLSUnlock();
  2718.     return HXR_OK;
  2719. }
  2720. STDMETHODIMP CHXBaseSite::BltComposition()
  2721. {
  2722.     HX_RESULT ret = HXR_OK;
  2723.     _TLSLock();
  2724.     if( m_pParentSite)
  2725.     {
  2726.         ret = m_pParentSite->BltComposition();
  2727.         _TLSUnlock();
  2728.         return ret;
  2729.     }
  2730.     //Tell the root surface to blt itself.
  2731. #if defined(_TEST_COMPOSITION)
  2732.  {
  2733.      char szBuff[256]; /* Flawfinder: ignore */
  2734.      sprintf( szBuff,"tick count: %lun", HX_GET_TICKCOUNT()); /* Flawfinder: ignore */
  2735.      _DumpString(szBuff);
  2736.  }
  2737. #endif
  2738.     if( m_pRootSurface )
  2739.         m_pRootSurface->BltComposition();
  2740.     _TLSUnlock();
  2741.     return HXR_OK;
  2742. }
  2743. STDMETHODIMP_(BOOL) CHXBaseSite::IsCompositionLocked()
  2744. {
  2745.     if( m_pParentSite)
  2746.     {
  2747.         return m_pParentSite->IsCompositionLocked();
  2748.     }
  2749.     return m_bCompositionLocked && m_bCompositionMode;
  2750. }
  2751. STDMETHODIMP_(BOOL) CHXBaseSite::IsCompositionMode()
  2752. {
  2753.     if( m_pParentSite)
  2754.     {
  2755.         return m_pParentSite->IsCompositionMode();
  2756.     }
  2757.     return m_bCompositionMode;
  2758. }
  2759. void CHXBaseSite::_TLSLock()
  2760. {
  2761.     if( m_pTopLevelSite)
  2762.     {
  2763.         if( this != m_pTopLevelSite )
  2764.             m_pTopLevelSite->_TLSLock();
  2765.         else
  2766.         {
  2767.             m_pMutex->Lock();
  2768.             InterlockedIncrement(&m_nTLSMutexLockCount);
  2769.             m_ulTLSMutexOwningThread = m_pDummyThread->GetCurrentThreadID();
  2770.         }
  2771.     }
  2772. }
  2773. void CHXBaseSite::_TLSUnlock()
  2774. {
  2775.     if( m_pTopLevelSite)
  2776.     {
  2777.         if( this != m_pTopLevelSite )
  2778.             m_pTopLevelSite->_TLSUnlock();
  2779.         else
  2780.         {
  2781.             HX_ASSERT(m_nTLSMutexLockCount>0);
  2782.             m_pMutex->Unlock();
  2783.             InterlockedDecrement(&m_nTLSMutexLockCount);
  2784.         }
  2785.     }
  2786. }
  2787. BOOL CHXBaseSite::_TLSIsLocked()
  2788. {
  2789.     if( m_pTopLevelSite)
  2790.     {
  2791.         if( this != m_pTopLevelSite )
  2792.             return m_pTopLevelSite->_TLSIsLocked();
  2793.         else
  2794.         {
  2795.             HX_ASSERT( m_nTLSMutexLockCount >=0 );
  2796.             return (m_ulTLSMutexOwningThread!=m_pDummyThread->GetCurrentThreadID() &&
  2797.                     m_nTLSMutexLockCount>0);
  2798.         }
  2799.     }
  2800.     HX_ASSERT("oops"==NULL);
  2801.     return FALSE;
  2802. }
  2803. HX_RESULT CHXBaseSite::SendSubRectMessages(BOOL bRet)
  2804. {
  2805.     if( m_pVideoSurface && IsYUV(GETBITMAPCOLOR( &m_pVideoSurface->m_bmiLastBlt)) )
  2806.     {
  2807.         m_bUserWantsSubRects = FALSE;
  2808.         return HXR_FAIL;
  2809.     }
  2810.     m_bUserWantsSubRects = bRet;
  2811.     m_bSiteScalingInfo   = TRUE;
  2812.     return HXR_OK;
  2813. }
  2814. //These are in SITE relative coords.
  2815. HX_RESULT CHXBaseSite::SubRectDamageRegion( HXxBoxRegion* pRegion )
  2816. {
  2817.     HXxRect rectTmp;
  2818.     if( !pRegion )
  2819.         return HXR_OK;
  2820.     HX_ASSERT( pRegion->rects );
  2821.     //Add each rect to our damage region.
  2822.     for( int i=0 ; i<pRegion->numRects ; i++ )
  2823.     {
  2824.         rectTmp.left   = pRegion->rects[i].x1;
  2825.         rectTmp.top    = pRegion->rects[i].y1;
  2826.         rectTmp.right  = pRegion->rects[i].x2;
  2827.         rectTmp.bottom = pRegion->rects[i].y2;
  2828.         DamageRect( rectTmp );
  2829.     }
  2830.     return HXR_OK;
  2831. }
  2832. ///////////////////////
  2833. // DEBUG METHODS
  2834. ///////////////////////
  2835. void CHXBaseSite::DisplaySiteData(const char *pszLeadIn)
  2836. {
  2837. #ifdef _DEBUG
  2838.     IHXBuffer* pBuf= NULL;
  2839.     char szBuff[256]; /* Flawfinder: ignore */
  2840.     if( m_pValues )
  2841.     {
  2842.         m_pValues->GetPropertyCString( "channel", pBuf );
  2843.         if( pBuf )
  2844.         {
  2845.             sprintf( szBuff, "%s -------------Site %p (%s)--------------n", pszLeadIn, this, (const char*)(pBuf->GetBuffer())); /* Flawfinder: ignore */
  2846.             _DumpString(szBuff);
  2847.             HX_RELEASE(pBuf);
  2848.         }
  2849.         else
  2850.         {
  2851.             sprintf( szBuff, "%s -------------Site %p --------------n", pszLeadIn, this); /* Flawfinder: ignore */
  2852.             _DumpString(szBuff);
  2853.         }
  2854.     }
  2855.     else
  2856.     {
  2857.         sprintf( szBuff, "%s -------------Site %p --------------n", pszLeadIn, this); /* Flawfinder: ignore */
  2858.         _DumpString(szBuff);
  2859.     }
  2860.     INT32 nCID = GETBITMAPCOLOR( &(m_pVideoSurface->m_bmiLastBlt) );
  2861.     sprintf( szBuff, "%s Size (%d, %d) zorder: %d  visible: %d BltCID:%d SurfaceCID:%d AlphaChain: %dn", /* Flawfinder: ignore */
  2862.              pszLeadIn, m_size.cx, m_size.cy, m_lZOrder, IsSiteVisible(),
  2863.              nCID, m_pVideoSurface->m_nSurfaceCID, _TakesPartInAlphaChain() );
  2864.     _DumpString(szBuff);
  2865.     sprintf( szBuff, "%s Bounding Rect (parent rel): (%d, %d) - (%d, %d)n", /* Flawfinder: ignore */
  2866.              pszLeadIn, m_position.x, m_position.y,
  2867.              m_position.x + m_size.cx, m_position.y+m_size.cy );
  2868.     _DumpString(szBuff);
  2869.     sprintf( szBuff, "%s Bounding Rect (absolulte ): (%d, %d) - (%d, %d)n", /* Flawfinder: ignore */
  2870.              pszLeadIn, m_topleft.x, m_topleft.y,
  2871.              m_topleft.x+m_size.cx, m_topleft.y+m_size.cy);
  2872.     _DumpString(szBuff);
  2873.     sprintf( szBuff, "%s Window: %p m_pUser: %p EventSensitivity: ", /* Flawfinder: ignore */
  2874.              pszLeadIn,
  2875.              m_pWindow?m_pWindow->window:0, m_pUser
  2876.              );
  2877.     _DumpString(szBuff);
  2878.     if( m_nEventSensitivity==SENSITIVITY_TRANSPARENT)
  2879.         sprintf(szBuff, "TRANSPARENTn"); /* Flawfinder: ignore */
  2880.     else if( m_nEventSensitivity==SENSITIVITY_OPAQUE)
  2881.         sprintf(szBuff, "OPAQUEn"); /* Flawfinder: ignore */
  2882.     else if( m_nEventSensitivity==SENSITIVITY_NOT_SET)
  2883.         sprintf(szBuff, "NOT_SETn"); /* Flawfinder: ignore */
  2884.     else
  2885.         sprintf(szBuff, "%dn", m_nEventSensitivity); /* Flawfinder: ignore */
  2886.     _DumpString(szBuff);
  2887.     sprintf( szBuff, "%s Alpha(blend:%d noti: %d) m_bSiteNeverBlts: %d YUVAImageList: %d ImageBlocks: %dn", /* Flawfinder: ignore */
  2888.              pszLeadIn,
  2889.              m_AlphaBlendSites.GetCount(),
  2890.              m_AlphaBlendNotifiers.GetCount(),
  2891.              m_bSiteNeverBlts,
  2892.              m_pVideoSurface->m_YUVAImageList.GetCount(),
  2893.              m_pVideoSurface->m_imageBlocks.GetCount()
  2894.              );
  2895.     _DumpString(szBuff);
  2896.     CHXMapPtrToPtr::Iterator iter = m_AlphaBlendSites.Begin();
  2897.     for ( ; iter != m_AlphaBlendSites.End(); ++iter)
  2898.     {
  2899.         HXREGION* pTmp = (HXREGION*)*iter;
  2900.         CHXBaseSite* pSite = (CHXBaseSite*) iter.get_key();
  2901.         sprintf( szBuff, "%s   %p  num rects: %dn", /* Flawfinder: ignore */
  2902.                  pszLeadIn,
  2903.                  pSite,
  2904.                  pTmp->numRects
  2905.                  );
  2906.         _DumpString(szBuff);
  2907. #if defined(_DUMP_REGION_RECTS) || 1
  2908.         for( int i=0 ; i<pTmp->numRects ; i++ )
  2909.         {
  2910.             sprintf( szBuff, "%s      %d (%d, %d)-(%d, %d)n", pszLeadIn, i, /* Flawfinder: ignore */
  2911.                      pTmp->rects[i].x1,
  2912.                      pTmp->rects[i].y1,
  2913.                      pTmp->rects[i].x2,
  2914.                      pTmp->rects[i].y2
  2915.                      );
  2916.             _DumpString( szBuff );
  2917.         }
  2918. #endif
  2919.     }
  2920.     if( m_fpTransitionEffect != DefaultTransition )
  2921.     {
  2922.         sprintf( szBuff, "%s Num Sub Rects: Region:%d  RegWC: %d  RegForMouse: %d m_fpTransitionEffect: %p(%d)n", /* Flawfinder: ignore */
  2923.                  pszLeadIn,
  2924.                  !m_Region?0:m_Region->numRects,
  2925.                  !m_RegionWithoutChildren?0:m_RegionWithoutChildren->numRects,
  2926.                  !m_RegionForMouse?0:m_RegionForMouse->numRects,
  2927.                  m_fpTransitionEffect,
  2928.                  m_nTransitionState
  2929.                  );
  2930.     }
  2931.     else
  2932.     {
  2933.         sprintf( szBuff, "%s Num Sub Rects: Region:%d  RegWC: %d  RegForMouse: %d m_fpTransitionEffect: DEFAULTn", /* Flawfinder: ignore */
  2934.                  pszLeadIn,
  2935.                  !m_Region?0:m_Region->numRects,
  2936.                  !m_RegionWithoutChildren?0:m_RegionWithoutChildren->numRects,
  2937.                  !m_RegionForMouse?0:m_RegionForMouse->numRects
  2938.                  );
  2939.     }
  2940.     _DumpString(szBuff);
  2941. #if defined(_DUMP_REGION_RECTS) || 1
  2942.     if( m_Region )
  2943.     {
  2944.         for( int i=0 ; i<m_Region->numRects ; i++ )
  2945.         {
  2946.             sprintf( szBuff, "%s   %d (%d, %d)-(%d, %d)n", pszLeadIn, i, /* Flawfinder: ignore */
  2947.                      m_Region->rects[i].x1,
  2948.                      m_Region->rects[i].y1,
  2949.                      m_Region->rects[i].x2,
  2950.                      m_Region->rects[i].y2
  2951.                      );
  2952.             _DumpString( szBuff );
  2953.         }
  2954.     }
  2955. #endif
  2956. #endif /* _DEBUG */
  2957. }
  2958. void CHXBaseSite::DisplayAllSiteData()
  2959. {
  2960. #ifdef _DEBUG
  2961.     CHXBaseSite* pTopSite = GetTopLevelSite();
  2962.     char szBuff[256]; /* Flawfinder: ignore */
  2963.     sprintf( szBuff, "************************************************n" ); /* Flawfinder: ignore */
  2964.     _DumpString(szBuff);
  2965.     sprintf( szBuff, "TOPLEVEL: Composition Mode: %s  Composition Locked: %s n", /* Flawfinder: ignore */
  2966.              pTopSite->IsCompositionMode()?"TRUE":"FALSE",
  2967.              pTopSite->IsCompositionLocked()?"TRUE":"FALSE"
  2968.              );
  2969.     _DumpString(szBuff);
  2970.     sprintf( szBuff, "************************************************n" ); /* Flawfinder: ignore */
  2971.     _DumpString(szBuff);
  2972.     pTopSite->DisplayChildSiteData("");
  2973.     sprintf( szBuff, "************************************************n" ); /* Flawfinder: ignore */
  2974.     _DumpString(szBuff);
  2975.     sprintf( szBuff, "************************************************n" ); /* Flawfinder: ignore */
  2976.     _DumpString(szBuff);
  2977.     sprintf( szBuff, "List of YUV Sitesn" ); /* Flawfinder: ignore */
  2978.     _DumpString(szBuff);
  2979.     CHXSimpleList::Iterator i = zm_YUVSiteList.Begin();
  2980.     while( i != zm_YUVSiteList.End() )
  2981.     {
  2982.         sprintf( szBuff, "%pn", *i ); /* Flawfinder: ignore */
  2983.         _DumpString(szBuff);
  2984.         ++i;
  2985.     }
  2986. #endif /* _DEBUG */
  2987. }
  2988. void CHXBaseSite::DisplayChildSiteData(const char *pszLeadIn)
  2989. {
  2990. #ifdef _DEBUG
  2991.     DisplaySiteData(pszLeadIn);
  2992.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  2993.     int nn=strlen(pszLeadIn)+10;
  2994.     char *pszTmp= new char[nn];
  2995.     memset(pszTmp, ' ', nn );
  2996.     pszTmp[nn-1]='';
  2997.     while(pos)
  2998.     {
  2999.         CHXBaseSite* pSite = (CHXBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  3000.         pSite->DisplayChildSiteData(pszTmp);
  3001.     }
  3002.     delete [] pszTmp;
  3003. #endif /* _DEBUG */
  3004. }
  3005. //Verify that we don't add any overlapping alphablend regions...
  3006. void CHXBaseSite::VerifyNoDups( CHXMapPtrToPtr& map, HXREGION* reg )
  3007. {
  3008. #ifdef _DEBUG
  3009.     //Loop through and see if reg is already in the map.
  3010.     CHXMapPtrToPtr::Iterator iter = map.Begin();
  3011.     for ( ; iter != map.End(); ++iter)
  3012.     {
  3013.         HXREGION* pSiteReg = (HXREGION*)*iter;
  3014.         HXREGION* pTmp = HXCreateRegion();
  3015.         HXIntersectRegion( pSiteReg, reg, pTmp );
  3016.         if( !HXEmptyRegion(pTmp) )
  3017.         {
  3018.             DisplayAllSiteData();
  3019.             HX_ASSERT( "Adding a duplicate region!" );
  3020.         }
  3021.         HXDestroyRegion(pTmp);
  3022.     }
  3023. #endif /* _DEBUG */
  3024. }
  3025. ///////////////////////
  3026. // DEBUG METHODS END END END
  3027. ///////////////////////