views:

179

answers:

3

I'm getting ready to make a drawing application in Windows. I'm just wondering, do drawing programs have a memory bitmap which they lock, then set each pixel, then blit? I don't understand how Photoshop can move entire layers without lag or flicker without using hardware acceleration. Also in a program like Expression Design, I could have 200 shapes and move them around all at once with no lag. I'm really wondering how this can be done without GPU help. I don't think super efficient algorithms could justify that?

Thanks

+1  A: 

Certainly modern Photoshop uses GPU acceleration if available. Another possible tool is DMA. You may also find it helpful to read the source code of existing programs like GIMP.

Matthew Flaschen
But my question really was how it can do it without because it didn't used to have it.
Milo
DMA is not an another tool. It helps GPU to transfer data without using CPU.
Kirill V. Lyadvinsky
@Kirill, that's not true. DMA can be used without a GPU, and the CPU can initiate it.
Matthew Flaschen
I think there's a bit of misunderstanding here. What you're really talking about is bus mastering, not DMA (DMA has been obsolete for years).
Jerry Coffin
@Jerry, my understanding is that bus mastering is a form of DMA.
Matthew Flaschen
@Matthew: The reverse would be more accurate: DMA was a primitive form of bus-mastering. DMA was a fairly specific term referring to a specific technique that worked with ISA (and similar buses). On PCs it was pervasive in 8088/8086 machines, but used only for floppy disk transfers starting with the 286 (because the DMA controllers were then slower than CPU transfers, and even setting up the DMA controller to do a transfer usually took more time than doing the transfer without it).
Jerry Coffin
Huh, all of the platforms that I work on still call it 'DMA.' I will have to look up what "bus mastering" means, but in context we're setting up a buffer in memory with commands that the memory manager (hardware) is pointed at and told, "GO!". Then copies of that memory appears as if by magic wherever we told it to go.
dash-tom-bang
+1  A: 

Look at this question:

http://stackoverflow.com/questions/197948/reduce-flicker-with-gdi-and-c

All you can do about DC drawing without GPU is to reduce flickering. Anything else depends on the speed of filling your memory bitmap. And here you can use efficient algorithms, multithreading and whatever you need.

Eugene
Ok, so at the end of the day it's the speed that I can fill the memory bitmap, I think what I'll do then to get easy opacity is use OpenGL and just draw textures to quads. thanks
Milo
+1  A: 

Double (or more) buffering is the way it's done in games, where we're drawing a ton of crap into a "back" buffer while the "front" buffer is being displayed. Then when the draw is done, the buffers are swapped (a pointer swap, not copies!) and the process continues in the new front and back buffers.

Triple buffering offers another bonus, in that you can start drawing two-frames-from-now when next-frame is done, but without forcing a buffer swap in the middle of the screen refresh. Many games do the buffer swap in the middle of the refresh, but you can sometimes see it as visible artifacts (tearing) on the screen.

Anyway- for an app drawing bitmaps into a window, if you've got some "slow" operation, do it into a not-displayed buffer while presenting the displayed version to the rendering API, e.g. GDI. Let the system software handle all of the fancy updating.

dash-tom-bang
Thanks i'm already double buffering, it is a very useful technique!
Milo