ChunkedUpdateDrawingAreaProxyWin.cpp [plain text]
#include "config.h"
#include "ChunkedUpdateDrawingAreaProxy.h"
#include "UpdateChunk.h"
#include "WebProcessProxy.h"
#include "WebView.h"
#include <WebCore/BitmapInfo.h>
using namespace WebCore;
namespace WebKit {
WebPageProxy* ChunkedUpdateDrawingAreaProxy::page() const
{
return m_webView->page();
}
void ChunkedUpdateDrawingAreaProxy::ensureBackingStore()
{
if (m_backingStoreBitmap)
return;
BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(size());
void* pixels = 0;
m_backingStoreBitmap = adoptPtr(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0));
if (!m_backingStoreDC) {
HDC screenDC = ::GetDC(0);
m_backingStoreDC = adoptPtr(::CreateCompatibleDC(screenDC));
::ReleaseDC(0, screenDC);
}
::SelectObject(m_backingStoreDC.get(), m_backingStoreBitmap.get());
}
void ChunkedUpdateDrawingAreaProxy::invalidateBackingStore()
{
m_backingStoreBitmap.clear();
}
bool ChunkedUpdateDrawingAreaProxy::platformPaint(const IntRect& rect, HDC hdc)
{
if (!m_backingStoreBitmap)
return false;
::BitBlt(hdc, rect.x(), rect.y(), rect.width(), rect.height(), m_backingStoreDC.get(), rect.x(), rect.y(), SRCCOPY);
return true;
}
void ChunkedUpdateDrawingAreaProxy::drawUpdateChunkIntoBackingStore(UpdateChunk* updateChunk)
{
ensureBackingStore();
OwnPtr<HDC> updateChunkBitmapDC = adoptPtr(::CreateCompatibleDC(m_backingStoreDC.get()));
BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(updateChunk->rect().size());
HANDLE updateChunkHandle;
BOOL result = ::DuplicateHandle(m_webView->page()->process()->processIdentifier(), updateChunk->memory(),
::GetCurrentProcess(), &updateChunkHandle, STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE, false, DUPLICATE_CLOSE_SOURCE);
void* pixels = 0;
OwnPtr<HBITMAP> hBitmap = adoptPtr(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &pixels, updateChunkHandle, 0));
::SelectObject(updateChunkBitmapDC.get(), hBitmap.get());
::BitBlt(m_backingStoreDC.get(), updateChunk->rect().x(), updateChunk->rect().y(), updateChunk->rect().width(), updateChunk->rect().height(), updateChunkBitmapDC.get(), 0, 0, SRCCOPY);
::CloseHandle(updateChunkHandle);
RECT rect = updateChunk->rect();
::InvalidateRect(m_webView->window(), &rect, false);
}
}