Skip to content

Commit

Permalink
Some optimizations in subpic DirtyRect handling. Remove unnecessary (…
Browse files Browse the repository at this point in the history
…?) alignment in CDX9SubPic::Unlock().
  • Loading branch information
clsid2 committed Oct 23, 2022
1 parent dd59f0f commit bb9223e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
17 changes: 7 additions & 10 deletions src/SubPic/DX11SubPic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,15 @@ STDMETHODIMP CDX11SubPic::ClearDirtyRect()
return S_FALSE;
}

m_rcDirty.InflateRect(1, 1);
#ifdef _WIN64
const LONG a = 16 / sizeof(uint32_t) - 1;
m_rcDirty.left &= ~a;
m_rcDirty.right = (m_rcDirty.right + a) & ~a;
#endif
m_rcDirty.IntersectRect(m_rcDirty, CRect(0, 0, m_MemPic.w, m_MemPic.h));

uint32_t* ptr = m_MemPic.data.get() + m_MemPic.w * m_rcDirty.top + m_rcDirty.left;
const UINT dirtyW = m_rcDirty.Width();
UINT dirtyH = m_rcDirty.Height();
const DWORD color = m_bInvAlpha ? 0x00000000 : 0xFF000000;
const UINT w4 = m_rcDirty.Width() * 4;

while (dirtyH-- > 0) {
memsetd(ptr, m_bInvAlpha ? 0x00000000 : 0xFF000000, dirtyW * 4);
memsetd(ptr, color, w4);
ptr += m_MemPic.w;
}

Expand Down Expand Up @@ -277,7 +272,10 @@ STDMETHODIMP CDX11SubPic::Lock(SubPicDesc& spd)
STDMETHODIMP CDX11SubPic::Unlock(RECT* pDirtyRect)
{
if (pDirtyRect) {
m_rcDirty.IntersectRect(pDirtyRect, CRect(0, 0, m_size.cx, m_size.cy));
m_rcDirty = pDirtyRect;
if (!m_rcDirty.IsRectEmpty()) {
m_rcDirty.IntersectRect(m_rcDirty, CRect(0, 0, m_MemPic.w, m_MemPic.h));
}
} else {
m_rcDirty = CRect(CPoint(0, 0), m_size);
}
Expand Down Expand Up @@ -502,7 +500,6 @@ HRESULT CDX11SubPicAllocator::Render(const MemPic_t& memPic, const CRect& dirtyR

CRect copyRect(dirtyRect);
if (stretching) {
copyRect.InflateRect(1, 1);
RECT subpicRect = { 0, 0, memPic.w, memPic.h };
EXECUTE_ASSERT(copyRect.IntersectRect(copyRect, &subpicRect));
}
Expand Down
39 changes: 15 additions & 24 deletions src/SubPic/DX9SubPic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,31 @@ STDMETHODIMP CDX9SubPic::ClearDirtyRect()
return E_FAIL;
}

DWORD color = m_bInvAlpha ? 0x00000000 : 0xFF000000;
m_rcDirty.IntersectRect(m_rcDirty, CRect(0, 0, m_maxsize.cx, m_maxsize.cy));

SubPicDesc spd;
if (SUCCEEDED(Lock(spd))) {
int h = m_rcDirty.Height();

BYTE* ptr = spd.bits + spd.pitch * m_rcDirty.top + (m_rcDirty.left * spd.bpp >> 3);

if (spd.bpp == 16) {
const unsigned short color = m_bInvAlpha ? 0x00000000 : 0xFF000000;
const int w2 = m_rcDirty.Width() * 2;
while (h-- > 0) {
memsetw(ptr, (unsigned short)color, 2 * m_rcDirty.Width());
memsetw(ptr, color, w2);
ptr += spd.pitch;
}
} else if (spd.bpp == 32) {
const DWORD color = m_bInvAlpha ? 0x00000000 : 0xFF000000;
const int w4 = m_rcDirty.Width() * 4;
while (h-- > 0) {
memsetd(ptr, color, 4 * m_rcDirty.Width());
memsetd(ptr, color, w4);
ptr += spd.pitch;
}
}
/*
DWORD* ptr = (DWORD*)bm.bits;
DWORD* end = ptr + bm.h*bm.wBytes/4;
while (ptr < end) *ptr++ = color;
*/
Unlock(nullptr);
}

// HRESULT hr = pD3DDev->ColorFill(m_pSurface, m_rcDirty, color);

m_rcDirty.SetRectEmpty();

return S_OK;
Expand Down Expand Up @@ -208,24 +204,19 @@ STDMETHODIMP CDX9SubPic::Unlock(RECT* pDirtyRect)
m_pSurface->UnlockRect();

if (pDirtyRect) {
m_rcDirty = *pDirtyRect;
if (!((CRect*)pDirtyRect)->IsRectEmpty()) {
m_rcDirty.InflateRect(1, 1);
m_rcDirty.left &= ~127;
m_rcDirty.top &= ~63;
m_rcDirty.right = (m_rcDirty.right + 127) & ~127;
m_rcDirty.bottom = (m_rcDirty.bottom + 63) & ~63;
m_rcDirty &= CRect(CPoint(0, 0), m_size);
m_rcDirty = pDirtyRect;
if (!m_rcDirty.IsRectEmpty()) {
m_rcDirty.IntersectRect(m_rcDirty, CRect(0, 0, m_size.cx, m_size.cy));

CComPtr<IDirect3DTexture9> pTexture = (IDirect3DTexture9*)GetObject();
if (pTexture) {
pTexture->AddDirtyRect(&m_rcDirty);
}
}
} else {
m_rcDirty = CRect(CPoint(0, 0), m_size);
}

CComPtr<IDirect3DTexture9> pTexture = (IDirect3DTexture9*)GetObject();
if (pTexture && pDirtyRect && !((CRect*)pDirtyRect)->IsRectEmpty()) {
pTexture->AddDirtyRect(&m_rcDirty);
}

return S_OK;
}

Expand Down

0 comments on commit bb9223e

Please sign in to comment.