BackingStoreDirect2D.cpp [plain text]
#include "config.h"
#include "BackingStore.h"
#include "ShareableBitmap.h"
#include "UpdateInfo.h"
#include "WebPageProxy.h"
#include <WebCore/BackingStoreBackendDirect2DImpl.h>
#include <WebCore/COMPtr.h>
#include <WebCore/Direct2DUtilities.h>
#include <WebCore/GraphicsContextImplDirect2D.h>
#include <WebCore/PlatformContextDirect2D.h>
#include <d2d1.h>
#include <d3d11_1.h>
#include <dxgi.h>
namespace WebKit {
using namespace WebCore;
std::unique_ptr<BackingStoreBackendDirect2D> BackingStore::createBackend()
{
return makeUnique<BackingStoreBackendDirect2DImpl>(m_size, m_deviceScaleFactor, m_webPageProxy.device());
}
void BackingStore::paint(DXConnections dxConnections, const IntRect& rect)
{
ASSERT(m_backend);
ASSERT(m_backend->size() == m_size);
COMPtr<ID3D11Resource> backBuffer;
HRESULT hr = dxConnections.backBuffer->QueryInterface(__uuidof(ID3D11Resource), reinterpret_cast<void**>(&backBuffer));
RELEASE_ASSERT(SUCCEEDED(hr));
COMPtr<ID3D11Resource> backingStore;
hr = m_backend->dxSurface()->QueryInterface(__uuidof(ID3D11Resource), reinterpret_cast<void**>(&backingStore));
RELEASE_ASSERT(SUCCEEDED(hr));
CD3D11_BOX srcBox(rect.x(), rect.y(), 0, rect.x() + rect.width(), rect.y() + rect.height(), 1);
dxConnections.immediateContext->CopySubresourceRegion1(backBuffer.get(), 0, rect.x(), rect.y(), 0, backingStore.get(), 0, &srcBox, D3D11_COPY_DISCARD);
}
void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo& updateInfo)
{
if (!m_backend)
m_backend = createBackend();
scroll(updateInfo.scrollRect, updateInfo.scrollOffset);
IntPoint updateRectBoundsLocation = updateInfo.updateRectBounds.location();
COMPtr<ID2D1Bitmap> deviceUpdateBitmap = bitmap->createDirect2DSurface(m_webPageProxy.device(), m_backend->renderTarget());
if (!deviceUpdateBitmap)
return;
#ifndef _NDEBUG
auto deviceBitmapSize = deviceUpdateBitmap->GetPixelSize();
ASSERT(deviceBitmapSize.width == updateInfo.updateRectBounds.width());
ASSERT(deviceBitmapSize.height == updateInfo.updateRectBounds.height());
#endif
for (const auto& updateRect : updateInfo.updateRects) {
auto currentRectLocation = IntSize(updateRect.x() - updateRectBoundsLocation.x(), updateRect.y() - updateRectBoundsLocation.y());
auto destRectLocation = IntSize(updateRect.x(), updateRect.y());
Direct2D::copyRectFromOneSurfaceToAnother(deviceUpdateBitmap.get(), m_backend->surface(), currentRectLocation, updateRect, destRectLocation);
}
}
void BackingStore::scroll(const IntRect& scrollRect, const IntSize& scrollOffset)
{
if (scrollOffset.isZero())
return;
ASSERT(m_backend);
m_backend->scroll(scrollRect, scrollOffset);
}
}