J'ai fait des tests sans le debug.
En 2D on dessine des points et pas en vector.
Gdi (2D) utilise l'accélération matériel et pas Gdi+ si essai sous windows
J'ai écris ceci directement en Gdi+ et j'ai affiché un requester pour le résultat.
Code : Tout sélectionner
Procedure Gdip_Drawing()
Define .i
Protected X=gGridSpace, *token, *gfx, HDC_CanvasGadget.i, *pen, Y, time
Protected Dim Elements.f(1) ;// 2 éléments
gCurrentTime=ElapsedMilliseconds()
;// initialisation de Gdi+
*token = Gdiplus_New()
HDC_CanvasGadget = StartDrawing(CanvasOutput(#MainCanvas))
;// création du graphique GDi+
GdipCreateFromHDC(HDC_CanvasGadget, @*gfx)
; Eraze the canvas
;// couleur du graphics (jaune)
GdipGraphicsClear(*gfx, $FBFFFACD)
;// pen de 1 pixel de largeur couleur noir
GdipCreatePen1($FF000000, 1, #UnitPixel, @*pen)
;// 1er élément ce qui est dessiné en noir par le pen valeur 1 x largeur pen soit un point 1x1 pixel
Elements(0) = 1
;// 2eme élément l'espace soit (gGridSpace-1) x largeur pen soit un espace de gGridSpace-1 pixels
Elements(1) = gGridSpace-1
;// application de la forme pointillée au pen liée au tableau
GdipSetPenDashArray(*Pen, @Elements(), 2)
;// position en Y inférieur (en bas canvas)
y = GadgetHeight(#MainCanvas) -1
;// x à l'origine
X = gGridSpace
While X < gCanvasW
GdipDrawLineI(*gfx, *pen, x, gGridSpace, x, Y)
X + gGridSpace
Wend
StopDrawing()
GdipDeletePen(*Pen)
GdipDeleteGraphics(*gfx)
GdiplusShutdown(*token)
time = ElapsedMilliseconds()-gCurrentTime
MessageRequester("Time ellapsed", "Gdi+ : " +Str(time), 16)
EndProcedure
Il y a des variations parfois importantes sur les résultats si effectués plusieurs fois de suite
Essai sans debugger, win7 pro x64 (Portable 5 ans d'âge), PB 5.40 LTS x64
2D : 28
Gdi+ 59
Vector : 328
c'est plus de 10 fois sur mon PC pour vector (?)
Les essais sont encore plus lent en 32 bits pour vector et Gdi+, c'est très stable pour 2D
voici mon code d'essai complet
Code : Tout sélectionner
EnableExplicit
Enumeration
#MainForm
#MainArea
#MainCanvas
#BtWithVector
#BtWithDrawing
#BtWithGdiplus
EndEnumeration
Global gCanvasW=2000,gCanvasH=2000,gGridSpace=10,gCurrentTime
Procedure VectorDrawing()
Protected X.d=gGridSpace, time
gCurrentTime=ElapsedMilliseconds()
StartVectorDrawing(CanvasVectorOutput(#MainCanvas))
; Eraze the canvas
VectorSourceColor($FBCDFAFF)
FillVectorOutput()
While X < gCanvasW
MovePathCursor(X,0)
AddPathLine(X, gCanvasH)
X+gGridSpace
Wend
VectorSourceColor($FB13458B)
DotPath(1,gGridSpace)
; DotPath(1,gGridSpace,#PB_Path_RoundEnd)
StopVectorDrawing()
time = ElapsedMilliseconds()-gCurrentTime
MessageRequester("Time ellapsed", "VectorDrawing : " +Str(time), 16)
EndProcedure
Procedure NormalDrawing()
Protected X=gGridSpace,Y=gGridSpace, time
gCurrentTime=ElapsedMilliseconds()
StartDrawing(CanvasOutput(#MainCanvas)) :
; Eraze the canvas
Box(0,0,gCanvasW,gCanvasH,$FBCDFAFF)
While X < gCanvasW
Y=gGridSpace
While Y<gCanvasH
Plot(X,Y,$FB13458B)
Y+gGridSpace
Wend
X+gGridSpace
Wend
StopDrawing()
time = ElapsedMilliseconds()-gCurrentTime
MessageRequester("Time ellapsed", "NormalDrawing : " +Str(time), 16)
EndProcedure
Structure GdiplusStartupInput Align #PB_Structure_AlignC ;{
GdiPlusVersion.l
*DebugEventCallback
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure ;}
Enumeration
#UnitWorld ;// 0 -- World coordinate (non-physical unit)
#UnitDisplay ;// 1 -- Variable -- for PageTransform only
#UnitPixel ;// 2 -- Each unit is one device pixel.
#UnitPoint ;// 3 -- Each unit is a printer's point or 1/72 inch.
#UnitInch ;// 4 -- Each unit is 1 inch.
#UnitDocument ;// 5 -- Each unit is 1/300 inch.
#UnitMillimeter ;// 6 -- Each unit is 1 millimeter.
EndEnumeration
Import "gdiplus.lib"
;{
GdipCreateFromHDC(dc.i, *graphics)
GdipGraphicsClear(*graphics, color.l)
GdipCreatePen1(color, width.f, unit.i, *pen)
GdipSetPenDashArray(*pen, *dash, count.l)
GdipDrawLineI(*graphics, *pen, x1.l, y1.l, x2.l, y2.l)
GdipDeletePen(*Pen)
GdipDeleteGraphics(*gfx)
GdiplusShutdown(*token)
GdiplusStartup(*token, *input, *output)
;}
EndImport
Procedure.i Gdiplus_New(version = 1, *hEventCB = #Null, Codecs = #False, bgThread = #False)
Protected *token, input.GdiplusStartupInput
With input
\GdiPlusVersion = version
; \DebugEventCallback = *hEventCB
; \SuppressExternalCodecs = Codecs
; \SuppressBackgroundThread = bgThread
EndWith
GdiplusStartup(@*token, @input, #Null)
ProcedureReturn *token
EndProcedure
Procedure Gdip_Drawing()
Define .i
Protected X=gGridSpace, *token, *gfx, HDC_CanvasGadget.i, *pen, Y, time
Protected Dim Elements.f(1) ;// 2 éléments
gCurrentTime=ElapsedMilliseconds()
;// initialisation de Gdi+
*token = Gdiplus_New()
HDC_CanvasGadget = StartDrawing(CanvasOutput(#MainCanvas))
;// création du graphique GDi+
GdipCreateFromHDC(HDC_CanvasGadget, @*gfx)
; Eraze the canvas
;// couleur du graphics (jaune)
GdipGraphicsClear(*gfx, $FBFFFACD)
;// pen de 1 pixel de largeur couleur noir
GdipCreatePen1($FF000000, 1, #UnitPixel, @*pen)
;// 1er élément ce qui est dessiné en noir par le pen valeur 1 x largeur pen soit un point 1x1 pixel
Elements(0) = 1
;// 2eme élément l'espace soit gGridSpace x largeur pen soit un espace de gGridSpace pixels
Elements(1) = gGridSpace-1
;// application de la forme pointillé au pen lié au tableau
GdipSetPenDashArray(*Pen, @Elements(), 2)
;// position en Y inférieur (en bas canvas)
y = GadgetHeight(#MainCanvas) -1
;// x à l'origine
X = gGridSpace
While X < gCanvasW
GdipDrawLineI(*gfx, *pen, x, gGridSpace, x, Y)
X + gGridSpace
Wend
StopDrawing()
GdipDeletePen(*Pen)
GdipDeleteGraphics(*gfx)
GdiplusShutdown(*token)
time = ElapsedMilliseconds()-gCurrentTime
MessageRequester("Time ellapsed", "Gdi+ : " +Str(time), 16)
EndProcedure
OpenWindow(0,0,0,800,600,"teste",#PB_Window_Maximize|#PB_Window_SystemMenu)
ButtonGadget(#BtWithVector,10,10,180,30,"Avec Vector")
BindGadgetEvent(#BtWithVector,@VectorDrawing())
ButtonGadget(#BtWithDrawing,200,10,180,30,"Avec 2D drawing")
BindGadgetEvent(#BtWithDrawing,@NormalDrawing())
ButtonGadget(#BtWithGdiplus,390,10,180,30,"Avec Gdi+")
BindGadgetEvent(#BtWithGdiplus,@Gdip_Drawing())
ScrollAreaGadget(#MainArea,0,40,WindowWidth(#MainForm),WindowHeight(#MainForm),gCanvasW,gCanvasH)
CanvasGadget(#MainCanvas,0,0,gCanvasW,gCanvasH)
Repeat
If WaitWindowEvent()=#PB_Event_CloseWindow
End
EndIf
ForEver