Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is antialiasing is turned on. Disable antialiasing and the performance of Direct2D will be on par or faster than GDI. To do that after TDirect2DCanvas is created, make this call:</p> <pre><code> FD2DCanvas.RenderTarget.SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED); </code></pre> <p>TDirect2DCanvas is interface compatible where possible with TCanvas so it can be a drop in replacement with TCanvas, so some of the drawing routines are are a bit inefficient. For example, Polyline creates a geometry each time it is called and throws it away. To increase performance keeping the geometry around.</p> <p>Take a look at the implementation for TDirect2DCanvas.Polyline and hoist that out into your application for something like this:</p> <pre><code> procedure TForm2.CreateWnd; var i: Integer; HR: HRESULT; Sink: ID2D1GeometrySink; begin ... D2DFactory.CreatePathGeometry(FGeometry); HR := FGeometry.Open(Sink); try Sink.BeginFigure(D2D1PointF(FData[0].X + 0.5, FData[0].Y + 0.5), D2D1_FIGURE_BEGIN_HOLLOW); try for I := Low(FData) + 1 to High(FData) - 1 do Sink.AddLine(D2D1PointF(FData[I].X + 0.5, FData[I].Y + 0.5)); finally Sink.EndFigure(D2D1_FIGURE_END_OPEN); end; finally hr := Sink.Close; end; </code></pre> <p>And then draw it like so:</p> <pre><code> procedure TForm2.WMPaint(var Message: TWMPaint); begin FD2DCanvas.BeginDraw; FD2DCanvas.Pen.Color := clRed; FD2DCanvas.RenderTarget.DrawGeometry(FGeometry, FD2DCanvas.Pen.Brush.Handle); FD2DCanvas.EndDraw; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload