Skip to content

Commit 3d21fc9

Browse files
committed
Possible fix for swapped red and blue channels in browser views
1 parent c20d2ad commit 3d21fc9

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

Client/cefweb/CWebView.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,40 @@ void CWebView::UpdateTexture()
219219
// Update changed state
220220
m_RenderData.changed = false;
221221

222-
if (m_RenderData.dirtyRects.size() > 0 && m_RenderData.dirtyRects[0].width == m_RenderData.width && m_RenderData.dirtyRects[0].height == m_RenderData.height)
222+
if (m_pWebBrowserRenderItem->m_IsARGB)
223223
{
224-
// Update whole texture
225-
memcpy(surfaceData, sourceData, m_RenderData.width * m_RenderData.height * 4);
224+
if (m_RenderData.dirtyRects.size() > 0 && m_RenderData.dirtyRects[0].width == m_RenderData.width && m_RenderData.dirtyRects[0].height == m_RenderData.height)
225+
{
226+
// Update whole texture
227+
memcpy(surfaceData, sourceData, m_RenderData.width * m_RenderData.height * 4);
228+
}
229+
else
230+
{
231+
// Update dirty rects
232+
for (auto& rect : m_RenderData.dirtyRects)
233+
{
234+
for (int y = rect.y; y < rect.y + rect.height; ++y)
235+
{
236+
int index = y * pitch + rect.x * 4;
237+
memcpy(&surfaceData[index], &sourceData[index], rect.width * 4);
238+
}
239+
}
240+
}
226241
}
227242
else
228243
{
229-
// Update dirty rects
230244
for (auto& rect : m_RenderData.dirtyRects)
231245
{
232246
for (int y = rect.y; y < rect.y + rect.height; ++y)
233247
{
234-
int index = y * pitch + rect.x * 4;
235-
memcpy(&surfaceData[index], &sourceData[index], rect.width * 4);
248+
for (int x = rect.x; x < rect.x + rect.width; ++x)
249+
{
250+
int index = y * pitch + x * 4;
251+
const uint32_t sourcePixel = *reinterpret_cast<const std::uint32_t*>(&sourceData[index]);
252+
253+
// Convert ABGR to ARGB
254+
*reinterpret_cast<std::uint32_t*>(&surfaceData[index]) = (sourcePixel & 0xFF00FF00) | ((sourcePixel & 0x00FF0000) >> 16) | ((sourcePixel & 0x000000FF) << 16);
255+
}
236256
}
237257
}
238258
}
@@ -247,10 +267,24 @@ void CWebView::UpdateTexture()
247267
auto popupPitch = m_RenderData.popupRect.width * 4;
248268
for (int y = 0; y < m_RenderData.popupRect.height; ++y)
249269
{
250-
int sourceIndex = y * popupPitch;
251-
int destIndex = (y + m_RenderData.popupRect.y) * pitch + m_RenderData.popupRect.x * 4;
270+
if (m_pWebBrowserRenderItem->m_IsARGB)
271+
{
272+
int sourceIndex = y * popupPitch;
273+
int destIndex = (y + m_RenderData.popupRect.y) * pitch + m_RenderData.popupRect.x * 4;
252274

253-
memcpy(&surfaceData[destIndex], &m_RenderData.popupBuffer[sourceIndex], popupPitch);
275+
memcpy(&surfaceData[destIndex], &m_RenderData.popupBuffer[sourceIndex], popupPitch);
276+
}
277+
else
278+
{
279+
for (int x = 0; x < m_RenderData.popupRect.width; ++x)
280+
{
281+
int sourceIndex = y * popupPitch + x * 4;
282+
int destIndex = (y + m_RenderData.popupRect.y) * pitch + (m_RenderData.popupRect.x + x) * 4;
283+
const uint32_t sourcePixel = *reinterpret_cast<const std::uint32_t*>(&m_RenderData.popupBuffer[sourceIndex]);
284+
285+
*reinterpret_cast<std::uint32_t*>(&surfaceData[destIndex]) = (sourcePixel & 0xFF00FF00) | ((sourcePixel & 0x00FF0000) >> 16) | ((sourcePixel & 0x000000FF) << 16);
286+
}
287+
}
254288
}
255289
}
256290

Client/core/Graphics/CRenderItem.WebBrowser.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ void CWebBrowserItem::CreateUnderlyingData ()
9494
assert ( !m_pD3DRenderTargetSurface );
9595
assert ( !m_pD3DTexture );
9696

97-
D3DXCreateTexture ( m_pDevice, m_uiSizeX, m_uiSizeY, 1, 0, D3DFMT_A8B8G8R8, D3DPOOL_MANAGED, (IDirect3DTexture9**)&m_pD3DTexture );
97+
// Check if ABGR format is supported
98+
D3DFORMAT textureFormat = D3DFMT_A8R8G8B8;
99+
UINT numMipLevels = 1;
100+
D3DXCheckTextureRequirements(m_pDevice, &m_uiSizeX, &m_uiSizeY, &numMipLevels, 0, &textureFormat, D3DPOOL_MANAGED);
101+
m_IsARGB = textureFormat == D3DFMT_A8R8G8B8;
102+
103+
if (!m_IsARGB)
104+
AddReportLog(9700, "ARGB format not supported", 1);
105+
106+
// Create texture
107+
D3DXCreateTexture(m_pDevice, m_uiSizeX, m_uiSizeY, numMipLevels, 0, textureFormat, D3DPOOL_MANAGED, (IDirect3DTexture9**)&m_pD3DTexture);
98108

99109
// Check texture created
100110
if ( !m_pD3DTexture )

Client/sdk/core/CRenderItemManagerInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,5 @@ class CWebBrowserItem : public CTextureItem
542542
virtual void Resize (const CVector2D& size);
543543

544544
IDirect3DSurface9* m_pD3DRenderTargetSurface;
545+
bool m_IsARGB = true;
545546
};

0 commit comments

Comments
 (0)