Closed Bug 285054 Opened 19 years ago Closed 19 years ago

ConvertDDBtoDIB violates windows APIs

Categories

(Core Graveyard :: GFX: Win32, defect)

x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: Biesinger, Unassigned)

References

()

Details

Attachments

(1 file)

quoting
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_7gms.asp

"hbmp
    [in] Handle to the bitmap. This must be a compatible bitmap (DDB)."

"The bitmap identified by the hbmp parameter must not be selected into a device
context when the application calls this function."

This function does select the bitmap into a DC:
1661       oldbits = (HBITMAP)::SelectObject(memPrDC,mHBitmap);

Also, in many cases mHBitmap seems to be a DIB, as created by CreateDIBSection:
http://lxr.mozilla.org/seamonkey/source/gfx/src/windows/nsImageWin.cpp#1498
With regards to mHBitmap being a DIBSection, we really don't need to call
ConvertDDBtoDIB at all, if we didn't null out mImageBits and mImageSize.  I
think that should be another bug though.

As for the bug in question, the SelectObject has been in the code since May,
1999.  But you're right, it's incorrect according to the spec.  Looks like the
two SelectObject calls and the oldbits variable can be removed.
if we didn't delete and null out mImageBits, we'd take up twice the memory for
the images, wouldn't we?
When the DIB is created, we copy mImageBits into the "bits" pointer that the OS
gave us, and then clear mImageBits.  What I meant to say in Comment 1 was that
we can "delete [] mImageBits; mImageBits = bits;", leaving only 1 copy.
Blocks: 286236
Attachment #178215 - Flags: review?(cbiesinger)
Comment on attachment 178215 [details] [diff] [review]
Don't select bitmap into HDC

this still passes a DIB to GetDIBits sometimes, but ok...
Attachment #178215 - Flags: review?(cbiesinger) → review+
(In reply to comment #5)
> (From update of attachment 178215 [details] [diff] [review] [edit])
> this still passes a DIB to GetDIBits sometimes, but ok...

one bug at a time :)
Attachment #178215 - Flags: superreview?(tor)
Attachment #178215 - Flags: superreview?(tor) → superreview+
Checking in gfx/src/windows/nsImageWin.cpp;
/cvsroot/mozilla/gfx/src/windows/nsImageWin.cpp,v  <--  nsImageWin.cpp
new revision: 3.144; previous revision: 3.143
done
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Attachment #178215 - Flags: approval1.8b2?
Has this not actually landed? Why is it marked Fixed?
Comment on attachment 178215 [details] [diff] [review]
Don't select bitmap into HDC

sorry, I flagged approval1.8b2 request on the wrong bug.
Attachment #178215 - Flags: approval1.8b2?
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: