Click here to Skip to main content
15,907,913 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem in creating project !!! Pin
Andrew Peace11-Aug-01 2:46
Andrew Peace11-Aug-01 2:46 
GeneralRe: Problem in creating project !!! Pin
Hadi Rezaee11-Aug-01 18:09
Hadi Rezaee11-Aug-01 18:09 
GeneralRe: Problem in creating project !!! Pin
Andrew Peace12-Aug-01 2:02
Andrew Peace12-Aug-01 2:02 
GeneralRe: Problem in creating project !!! Pin
Hadi Rezaee12-Aug-01 17:59
Hadi Rezaee12-Aug-01 17:59 
Generalhelp with dialog boxes Pin
aarong10-Aug-01 18:14
aarong10-Aug-01 18:14 
GeneralRe: help with dialog boxes Pin
10-Aug-01 22:48
suss10-Aug-01 22:48 
GeneralRe: help with dialog boxes Pin
Derek Lakin10-Aug-01 22:55
Derek Lakin10-Aug-01 22:55 
GeneralBitmap copy: speed question Pin
10-Aug-01 17:45
suss10-Aug-01 17:45 
Hi All!
I'm writing some control in C++/MFC. It is basically ready, and now I'm working on speed it up/optimization. I found that BitBlt operation consumes significant amount of time:
/* sorry I'm writing from my home computer with no C++ installed and no sources, so there may be error in function names/parameters - not relevant to problem.
*/
CToolBtnList::OnPaint()
{ dc = CPaintDC(this); // or something like this...

CRect rect;
GetClientRect(&rect);
CDC memDC;
memDC.CreateCompatibleDC(NULL);
// this one is needed because I want first create
// image on it piece by piece and then copy it to
// PaintDC
CBitmap bitmap, *poldbitmap;
bitmap.CreateCompatibleBitmap(&memDC, etc...);
poldbitmap = memDC.SelectObject(&bitmap);
....
DrawBackground(&memDC);
....
// here I'm calling another my function:
DrawButtonsArea(&memDC);
...
...
/* place 1*/
dc.BitBlt(....., &memDC, ...., SRCCOPY); // one-to-one copy

memDC.SelectObject(poldbitmap);
memDC.DeleteDC();
bitmap.DeleteObject();

}

CToolBtnList::DrawButtonsArea(CDC* pDC)
{ /* and here I'm doing another copy: this is essential,
because I need to have possibility to cut what I've drawn by specific area without affecting other areas
*/
// repeat all the same:
CRect rect;
GetClientRect(&rect);
CDC memDC;
memDC.CreateCompatibleDC(NULL);
// this one is needed because I want first create
// image on it piece by piece and then copy it to
// PaintDC
CBitmap bitmap, *poldbitmap;
bitmap.CreateCompatibleBitmap(&memDC, etc...);
poldbitmap = memDC.SelectObject(&bitmap);
/* place 2*/
memDc.BitBlt(....., pdc, ....,SRCCOPY); // one-to-one copy
....
....
/* place 3*/
pdc.BitBlt(..., &memDC, ..., SRCCOPY); // this is cutted copy - not one-to-one

}

I'm calling Invalidate() each time when mouse moves to specific location (another "button" inside of control).
On silly test to call Invalidate() each 100ms (which is quite reasonable in my case) I found that my thread consumes 30% of processor time (which is unreasonable).
If I'll take out that 3 places (so I'm doing all other work, just don't do that copying), it goes down to 0% or 1% - even with all (~20) animated GIFs fooling around in worker thread.
Next tests showed that BitBlt operation _to_ PaintDC eats about 6% of processor time, and BitBlt operation _from_ PaintDC to memoryDC eats 15%-20% of processor time (which I can't understand: this is the same function with almost exactly same amout of data).
In archives here I found ::CopyImage function and will try it Monday at work, but I still doubt it can improve performance.
I understand that DIB processing will be faster, but I need DC functions to draw (line, ellipse, etc), so it will not work. How else can I speed this section up?
I'll try eliminate first copy to memDC (in OnPaint function), but I'm afraid it will be flickering.
Any other suggestions? How can I _directly_ copy data from one bitmap to another in memory without going to DC, and do it most efficient way without using DIBs? (something like memcpy Smile | :) ).
Any help will be appreciated.

Oh, by the way, I've tried GetBitmapBits and SetBitmapBits, and also I've tried bitmap<->DIB conversion (GetDIBits and SetDIBitsToDevice) - absolutely same speed Frown | :(

SY-
Kosta.


Kosta - wolf alone.
GeneralCTreeCtrl Pin
10-Aug-01 17:28
suss10-Aug-01 17:28 
GeneralRe: CTreeCtrl Pin
Bret Faller13-Aug-01 8:08
Bret Faller13-Aug-01 8:08 
Question32/64/96bit integers? Pin
Kevin Power10-Aug-01 15:23
Kevin Power10-Aug-01 15:23 
AnswerRe: 32/64/96bit integers? Pin
Wolfram Steinke10-Aug-01 16:16
Wolfram Steinke10-Aug-01 16:16 
AnswerRe: 32/64/96bit integers? Pin
Mukkie10-Aug-01 21:48
Mukkie10-Aug-01 21:48 
GeneralInternet Explorer Pin
calebcohoon10-Aug-01 14:31
calebcohoon10-Aug-01 14:31 
GeneralRegSaveKey Pin
10-Aug-01 13:47
suss10-Aug-01 13:47 
GeneralGlobals from additional files Pin
10-Aug-01 12:47
suss10-Aug-01 12:47 
Questioncreate pointers to different classes??? Pin
Bob Bain10-Aug-01 11:34
Bob Bain10-Aug-01 11:34 
AnswerRe: create pointers to different classes??? Pin
Tim Deveaux11-Aug-01 5:48
Tim Deveaux11-Aug-01 5:48 
GeneralProblem with Splitter Wnd Pin
Francis B.10-Aug-01 11:06
Francis B.10-Aug-01 11:06 
GeneralRe: Problem with Splitter Wnd Pin
10-Aug-01 11:22
suss10-Aug-01 11:22 
GeneralNeed some help Pin
Brian V Shifrin10-Aug-01 10:42
Brian V Shifrin10-Aug-01 10:42 
GeneralRe: Need some help Pin
Carlos Antollini10-Aug-01 10:56
Carlos Antollini10-Aug-01 10:56 
GeneralDuh! Pin
Brian V Shifrin10-Aug-01 11:13
Brian V Shifrin10-Aug-01 11:13 
GeneralRe: Duh! Pin
#realJSOP10-Aug-01 11:23
professional#realJSOP10-Aug-01 11:23 
GeneralRe: Need some help Pin
Derek Waters12-Aug-01 14:08
Derek Waters12-Aug-01 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.