I'm playing with BitBlt, turning upside down the desktop with a copy into memory and back reversed in hdc using BitBlt function.

I've seen that in a 133mhz pc with 16 mb ram this method is very slow. I think that it's becouse te memory allocation for the desktop space is very slow.
But a screen saver do the same effect much faster.

So, i was wondering if i can get the memory address of the video device context to write the pixels directly, instade of use everytime BitBlt.

if some help, thx
Posted on 2001-08-28 15:03:58 by Bit7
I dont think you can directly use memory of a HDC, even if its possible it will be a very bad habbit and OS version dependant,

better use SETDIBits and GetDIBits or much better use DirectX to get a pointer to video memory, but the KEY is NOT to READ from video memory because this is too much slow, read it ONCE into a memory array and then do your FX into that memory, at the end Blit or copy it on SCREEN..

Besides on a P133 what screen rezolution do you use? because 800x600x32bits can be TOO MUCH bandwidth for a P133

Calculate how much memory you will have to move at each frame and think if your machine is able to do it....
Posted on 2001-08-29 21:44:23 by BogdanOntanu
about capturing hdc in memory, i would try the chance to ask another thing:

My DESKTOP EFFECT is very slow.
to capturing the desktop i'm doing this,



; let's capturing the desktop
call GetDesktopWindow
call GetDC, eax
mov hdcScreen,eax
call CreateCompatibleDC, hdcScreen
mov Deskdc,eax
call CreateCompatibleBitmap, hdcScreen, 1024, 768
call SelectObject, Deskdc, eax

mov bmpinfo.bmiHeader.biSize, SIZE bmiHeader
mov eax,ScreenWidth
mov bmpinfo.bmiHeader.biWidth, eax
mov eax,ScreenHeight
mov bmpinfo.bmiHeader.biHeight, eax
mov bmpinfo.bmiHeader.biPlanes, 1
mov bmpinfo.bmiHeader.biBitCount, 32
mov bmpinfo.bmiHeader.biCompression, BI_RGB
mov bmpinfo.bmiHeader.biSizeImage, 0
mov bmpinfo.bmiHeader.biXPelsPerMeter, 0
mov bmpinfo.bmiHeader.biYPelsPerMeter, 0
mov bmpinfo.bmiHeader.biClrUsed, 0
mov bmpinfo.bmiHeader.biClrImportant, 0

call CreateDIBSection, Deskdc, offset bmpinfo, DIB_RGB_COLORS, offset bmpPointer,\
NULL, NULL
mov hBMPMEM, eax
call SelectObject, Deskdc, hBMPMEM
call BitBlt, Deskdc, 0, 0, 1024, 768, hdcScreen, 0, 0, SRCCOPY


Then i perform a GlobalAlloc to reserve the space where to put my modified bitmap. From there then i copy it to desktop again.

Am i goin wrong in something (i now the answer is YES) ? Have you any suggestion on how to improove the speed ?

THX
Posted on 2001-08-30 06:50:57 by Bit7
I know there is a way to write directly to hdc as if it were a DX surface. I can't remember how, but I can find out again. Is this what you're looking for?
Posted on 2001-08-31 01:41:35 by Kenny
Now that I think about it, I think all you need is:



invoke GetDC, hWnd
mov hDC, eax

push esi
ASSUME esi: PTR hDC
.LOOP
mov [esi], 00FF0000h ; Make the screen RED! (I think I'm using the brackets correctly here...)
add esi, 4
.UNTIL esi >= (1024*768)
ASSUME esi : nothing
pop esi



I haven't tried this code, so it's probably won't compile and I also cannot garentee this code is the actual way to do it :P Good Luck :) Oh, and if this code doesn't work, there is a large chance you will be trashing memory :alright:

edit: infinite loop...
Posted on 2001-08-31 02:28:13 by Kenny
Kenny,

it was just what i'm looking for.
Between today,satutrda and sunday i will try it.

THX
Bye !
Posted on 2001-08-31 09:38:28 by Bit7
lemme know how it works though, and I forgot a few things:

Remember to call getdesktopwindow before getdc. Remember after the loop to release the dc by invoking releasedc.
Posted on 2001-09-01 00:24:14 by Kenny
kenny,
sorry but it doesn't work.

the syntax
ASSUME esi : PTR hdc
give me a compiler error.
Posted on 2001-09-01 10:48:56 by Bit7
Hmm... I don't think you need those assume's at all, no structures are used or anything. It's just good habbit to tell the compiler what data type esi is supposed to be, but as I said I don't think it's required here.

Good luck!
Posted on 2001-09-01 10:56:04 by Qweerdy
try it without spaces.

ASSUME esi:PTR hDC
Posted on 2001-09-01 12:30:58 by Kenny
It should be HDC, ie all caps.

Although this is very much a HLL thing. If you use assume esi:PTR DWORD at least you know what size you're dealing with and to the compile its the same thing since somewhere in the include files is written HDC equ DWORD
Posted on 2001-09-01 13:05:09 by Eóin
Kenny,

noway, compiler always give error also using the syntax you suggest.

In any case i've optimized my code. Now it's faster.

If you look the attached stupid program, keys 5,6,7,8 and 9 do some stupid effects with the desktop. Now it's faster and for the moment i think is enough.

But if you find some working code to write directly to hdc it would be gret for me.

Thanks Kenny,
Thanks all :)

Angelo
Posted on 2001-09-01 14:59:16 by Bit7
That's the last time I run your stuff :alright:

I have an eye sore for a desktop now... lol
Posted on 2001-09-01 15:11:07 by Kenny
Very nice gadget.
Seems to me we will be programming jokes from now on.
I love it. lol for rest of the day.
Keep your sense of humor.
Posted on 2001-09-01 20:19:01 by forge
I just reloaded my desktop scheme 'kenny' and it was fine, so no big dea; I just had to give him a hard time :)

Good job :)
Posted on 2001-09-01 23:02:46 by Kenny