* Handle clearing to white on the client. This also makes sure that bitmaps are

cleared which have no app_server link (B_BITMAP_NO_SERVER_LINK).
* Check the allocation of the BWindow in BBitmap for view accepting bitmaps.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24344 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-03-10 10:51:56 +00:00
parent 9de993d155
commit 417889ced8
2 changed files with 26 additions and 21 deletions

View File

@ -949,12 +949,13 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
if (!bounds.IsValid() || !bitmaps_support_space(colorSpace, NULL)) {
error = B_BAD_VALUE;
} else {
// bounds is in floats and might be valid but much larger than what we can handle
// the size could not be expressed in int32
// bounds is in floats and might be valid but much larger than what we
// can handle the size could not be expressed in int32
double realSize = bounds.Width() * bounds.Height();
if (realSize > (double)(INT_MAX / 4)) {
fprintf(stderr, "bitmap bounds is much too large: BRect(%.1f, %.1f, %.1f, %.1f)\n",
bounds.left, bounds.top, bounds.right, bounds.bottom);
fprintf(stderr, "bitmap bounds is much too large: "
"BRect(%.1f, %.1f, %.1f, %.1f)\n",
bounds.left, bounds.top, bounds.right, bounds.bottom);
error = B_BAD_VALUE;
}
}
@ -1052,16 +1053,28 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
}
fInitError = error;
// TODO: on success, handle clearing to white if the flags say so. Needs to be
// dependent on color space.
if (fInitError == B_OK) {
if (flags & B_BITMAP_ACCEPTS_VIEWS) {
fWindow = new BWindow(Bounds(), fServerToken);
// A BWindow starts life locked and is unlocked
// in Show(), but this window is never shown and
// it's message loop is never started.
fWindow->Unlock();
fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken);
if (fWindow) {
// A BWindow starts life locked and is unlocked
// in Show(), but this window is never shown and
// it's message loop is never started.
fWindow->Unlock();
} else
fInitError = B_NO_MEMORY;
}
// clear to white if the flags say so.
if (flags & (B_BITMAP_CLEAR_TO_WHITE | B_BITMAP_ACCEPTS_VIEWS)) {
if (fColorSpace == B_CMAP8) {
// "255" is the "transparent magic" index for B_CMAP8 bitmaps
// use the correct index for "white"
memset(fBasePointer, 65, fSize);
} else {
// should work for most colorspaces
memset(fBasePointer, 0xff, fSize);
}
}
}
}

View File

@ -188,16 +188,8 @@ BitmapManager::CreateBitmap(ClientMemoryAllocator* allocator,
if (success) {
bitmap->fBuffer = buffer;
bitmap->fToken = gTokenSpace.NewToken(kBitmapToken, bitmap);
if (flags & (B_BITMAP_CLEAR_TO_WHITE | B_BITMAP_ACCEPTS_VIEWS)) {
if (space == B_CMAP8) {
// "255" is the "transparent magic" index for B_CMAP8 bitmaps
memset(bitmap->Bits(), 65, bitmap->BitsLength());
} else {
// should work for most colorspaces
memset(bitmap->Bits(), 0xff, bitmap->BitsLength());
}
}
// NOTE: the client handles clearing to white in case the flags
// indicate this is needed
} else {
// Allocation failed for buffer or bitmap list
delete bitmap;