Robinson
Robinson

Reputation: 10132

Direct2d ID2D1HwndRenderTarget->GetSize() returns zero

I've noticed that calling GetSize() on ID2D1HwndRenderTarget returns 0,0 if this call is made after a BeginDraw() call. It returns the correct value otherwise.

Is this "normal" behaviour? I haven't seen it documented in any examples. I did spend a few hours scratching my head over this.

Upvotes: 2

Views: 265

Answers (1)

Peter Kostov
Peter Kostov

Reputation: 951

This is a normal behaviour.

In your case, the method returns its const defined return value.

virtual D2D1_SIZE_F GetSize() const = 0;

Most probably, the method fails inside, because the render target could not be "acquired" inside a BeginDraw/EndDraw loop.

BeginDraw and EndDraw are used to indicate that a render target is in use by the Direct2D system. Different implementations of ID2D1RenderTarget might behave differently when BeginDraw is called. An ID2D1BitmapRenderTarget may be locked between BeginDraw/EndDraw calls, a DXGI surface render target might be acquired on BeginDraw and released on EndDraw, while an ID2D1HwndRenderTarget may begin batching at BeginDraw and may present on EndDraw, for example.

Remarks section: ID2D1RenderTarget::BeginDraw method

Upvotes: 3

Related Questions