Gfx: Fix rendering issues in some cases

It seems that Direct2D does not expect the underlying pixel data of the render target to change outside of the target draw commands while the render target exists. As a result, Direct2D may in some cases overwrite changes to the pixel data. This change changes the render target to be (re)created for each batch of Direct2D drawing operations as a temporary solution. As a side effect, a DIB section is now used as the render target bitmap.
This commit is contained in:
Birunthan Mohanathas
2013-03-26 21:29:05 +02:00
parent 7f51273950
commit 5f03d7b235
8 changed files with 436 additions and 120 deletions

View File

@ -21,6 +21,7 @@
#include "Canvas.h"
#include "TextFormatD2D.h"
#include "WICBitmapDIB.h"
#include <string>
#include <GdiPlus.h>
#include <d2d1.h>
@ -75,24 +76,17 @@ private:
void DiscardDeviceResources();
void BeginTargetDraw();
bool BeginTargetDraw();
void EndTargetDraw();
ID2D1RenderTarget* m_Target;
ID2D1GdiInteropRenderTarget* m_InteropTarget;
IWICBitmap* m_Bitmap;
WICBitmapDIB m_Bitmap;
// GDI+ objects that share the pixel data of m_Bitmap.
Gdiplus::Graphics* m_GdipGraphics;
Gdiplus::Bitmap* m_GdipBitmap;
// If true, the BeginDraw() function of this class has been called and the matching EndDraw()
// has not been called yet.
bool m_BeginDrawCalled;
// If true, the BeginDraw() function of the render target has been called and the matching
// EndDraw() has not been called yet.
bool m_TargetBeginDrawCalled;
bool m_TextAntiAliasing;
static UINT c_Instances;
static ID2D1Factory* c_D2D;