📄 dirtyrect.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
// File: DirtyRect.cpp
//
// Dirty Rectangle driver used for UI updating in TV Out mode.
//
//------------------------------------------------------------------------------
#include "precomp.h"
DirtyRect::DirtyRect(DWORD dwWidth, DWORD dwHeight, DWORD dwRegionWidth, DWORD dwRegionHeight) :
m_dwWidth(dwWidth),
m_dwHeight(dwHeight),
m_dwRegionWidth(dwRegionWidth),
m_dwRegionHeight(dwRegionHeight)
{
// width and height must be evenly divisible by region size
DEBUGCHK(dwWidth % dwRegionWidth == 0);
DEBUGCHK(dwHeight % dwRegionHeight == 0);
m_dwRegionCount = (m_dwWidth / m_dwRegionWidth) * (m_dwHeight / m_dwRegionHeight);
m_pDirty = new BOOL[m_dwRegionCount];
m_dwNumDirtyRegions = 0;
// Build table of rectangles
m_pRects = new RECT[m_dwRegionCount];
int currentRow, currentCol;
DWORD index;
int rows = m_dwHeight / m_dwRegionHeight;
int cols = m_dwWidth / m_dwRegionWidth;
// for each row
for(currentRow = 0; currentRow < rows; currentRow++)
{
for(currentCol = 0; currentCol < cols; currentCol++)
{
index = currentRow*cols + currentCol;
DEBUGCHK(index < m_dwRegionCount);
// Create rectangle
m_pRects[index].top = currentRow * m_dwRegionHeight;
m_pRects[index].bottom = (currentRow + 1) * m_dwRegionHeight - 1;
m_pRects[index].left = currentCol * m_dwRegionWidth;
m_pRects[index].right = (currentCol + 1) * m_dwRegionWidth - 1;
}
}
DEBUGCHK(m_pDirty != NULL);
}
DirtyRect::~DirtyRect()
{
if(m_pDirty != NULL)
delete[] m_pDirty;
}
void DirtyRect::SetDirtyRegion(LPRECT prect)
{
int row,col;
DWORD index;
// mark updated regions
int startrow = prect->top / m_dwRegionHeight;
int startcol = prect->left / m_dwRegionWidth;
int endrow = (prect->bottom - 1) / m_dwRegionHeight;
int endcol = (prect->right - 1) / m_dwRegionWidth;
// for each row
for(row = startrow; row <= endrow; row++)
{
for(col = startcol; col <= endcol; col++)
{
index = row*(m_dwWidth / m_dwRegionWidth) + col;
//DEBUGCHK(index < m_dwRegionCount);
if (index < m_dwRegionCount && m_pDirty[index] != TRUE)
{
m_pDirty[index] = TRUE;
m_dwNumDirtyRegions++;
}
}
}
}
UINT32 DirtyRect::GetNumDirtyRegions()
{
return m_dwNumDirtyRegions;
}
void DirtyRect::GetDirtyRegions(LPRECT prects, UINT32 numDirtyRegions)
{
int regionsAdded = 0;
UINT32 i;
if (numDirtyRegions < 1)
{
return;
}
// for each row
for(i = 0; i < m_dwRegionCount; i++)
{
if (m_pDirty[i] == TRUE)
{
prects[regionsAdded] = m_pRects[i];
regionsAdded++;
// Now that we have grabbed the dirty region, reset
// the dirty flag
m_pDirty[i] = FALSE;
if (regionsAdded == numDirtyRegions)
{
// We have grabbed all of the regions requested
m_dwNumDirtyRegions = 0;
return;
}
}
}
}
void DirtyRect::Reset()
{
m_dwNumDirtyRegions = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -