Fixed drawing on wxMemoryDC with Direct2DRenderer.

32bpp wxBitmaps selected into wxMemoryDC can represent either 0RGB or ARGB bitmaps and hence there is necessary to instruct renderer how to interpret 32bpp contents while creating a wxGraphicsContext. wxBitmap::HasAlpha() flag is used for these purposes and its value is passed to wxD2DContext ctor (wxD2DContext is used internally as a backend D2D component) and next used to configure physical renderer created with ID2D1Factory::CreateDCRenderTarget.

Closes #17465.
This commit is contained in:
Artur Wieczorek
2016-03-28 21:22:06 +02:00
parent 7c4145490e
commit e07aa294a4

View File

@@ -2671,8 +2671,8 @@ private:
class wxD2DDCRenderTargetResourceHolder : public wxD2DRenderTargetResourceHolder
{
public:
wxD2DDCRenderTargetResourceHolder(ID2D1Factory* factory, HDC hdc, const wxSize dcSize) :
m_factory(factory), m_hdc(hdc)
wxD2DDCRenderTargetResourceHolder(ID2D1Factory* factory, HDC hdc, const wxSize dcSize, bool hasAlpha) :
m_factory(factory), m_hdc(hdc), m_hasAlpha(hasAlpha)
{
m_dcSize.left = 0;
m_dcSize.top = 0;
@@ -2683,10 +2683,13 @@ public:
protected:
void DoAcquireResource()
{
D2D1_ALPHA_MODE alphaMode = m_hasAlpha ?
D2D1_ALPHA_MODE_PREMULTIPLIED : D2D1_ALPHA_MODE_IGNORE;
wxCOMPtr<ID2D1DCRenderTarget> renderTarget;
D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties = D2D1::RenderTargetProperties(
D2D1_RENDER_TARGET_TYPE_DEFAULT,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED));
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, alphaMode));
HRESULT hr = m_factory->CreateDCRenderTarget(
&renderTargetProperties,
@@ -2703,6 +2706,7 @@ private:
ID2D1Factory* m_factory;
HDC m_hdc;
RECT m_dcSize;
bool m_hasAlpha;
};
// The null context has no state of its own and does nothing.
@@ -2802,7 +2806,8 @@ class wxD2DContext : public wxGraphicsContext, wxD2DResourceManager
public:
wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, HWND hwnd);
wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, HDC hdc, const wxSize& dcSize);
wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, HDC hdc, const wxSize& dcSize,
bool hasAlpha = false);
#if wxUSE_IMAGE
wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, wxImage& image);
@@ -2948,9 +2953,9 @@ wxD2DContext::wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dF
Init();
}
wxD2DContext::wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, HDC hdc, const wxSize& dcSize) :
wxD2DContext::wxD2DContext(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, HDC hdc, const wxSize& dcSize, bool hasAlpha) :
wxGraphicsContext(renderer), m_direct2dFactory(direct2dFactory),
m_renderTargetHolder(new wxD2DDCRenderTargetResourceHolder(direct2dFactory, hdc, dcSize))
m_renderTargetHolder(new wxD2DDCRenderTargetResourceHolder(direct2dFactory, hdc, dcSize, hasAlpha))
{
Init();
}
@@ -3621,7 +3626,10 @@ wxGraphicsContext* wxD2DRenderer::CreateContext(const wxMemoryDC& dc)
int width, height;
dc.GetSize(&width, &height);
return new wxD2DContext(this, m_direct2dFactory, dc.GetHDC(), wxSize(width, height));
wxBitmap bmp = dc.GetSelectedBitmap();
wxASSERT_MSG( bmp.IsOk(), wxS("Should select a bitmap before creating wxGraphicsContext") );
return new wxD2DContext(this, m_direct2dFactory, dc.GetHDC(), wxSize(width, height), bmp.HasAlpha());
}
#if wxUSE_PRINTING_ARCHITECTURE