CanvasGadget - faster double buffering
Posted: Sat Sep 01, 2012 9:50 am
The CanvasGadget copies the image content on StopDrawing(), and preserves the old image.
The PB help example:
Because the image content is preserved/copied, the double buffer switching in StopDrawing()
is very slow. The bigger the Canvas, the slower the copying/switching.
Maybe an optional command or flag could be introduced, so the buffers are just switched
without preserving/copying the content?
If I always draw new content onto the whole drawing area, I do not need the old content
to be preserved (custom gadgets and displays).
The double buffer switching should be much faster without copying/preserving on every StopDrawing() (1920x1200 Pixels for example).
Maybe a flag for CanvasOutput() could be added:
Or an attribute for the CanvasGadget to change the default behavior:
The PB help example:
Code: Select all
If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
If StartDrawing(CanvasOutput(0))
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
StopDrawing()
EndIf
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
is very slow. The bigger the Canvas, the slower the copying/switching.
Maybe an optional command or flag could be introduced, so the buffers are just switched
without preserving/copying the content?
If I always draw new content onto the whole drawing area, I do not need the old content
to be preserved (custom gadgets and displays).
The double buffer switching should be much faster without copying/preserving on every StopDrawing() (1920x1200 Pixels for example).
Maybe a flag for CanvasOutput() could be added:
Code: Select all
If StartDrawing(CanvasOutput(0,#PB_Canvas_DoNotPreserveBuffer))
Code: Select all
SetGadgetAttribute(#Canvas,#PB_Canvas_CopyBackBuffer, #True ) ; DEFAULT
SetGadgetAttribute(#Canvas,#PB_Canvas_CopyBackBuffer, #False)