* 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:
parent
9de993d155
commit
417889ced8
@ -949,12 +949,13 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
|
|||||||
if (!bounds.IsValid() || !bitmaps_support_space(colorSpace, NULL)) {
|
if (!bounds.IsValid() || !bitmaps_support_space(colorSpace, NULL)) {
|
||||||
error = B_BAD_VALUE;
|
error = B_BAD_VALUE;
|
||||||
} else {
|
} else {
|
||||||
// bounds is in floats and might be valid but much larger than what we can handle
|
// bounds is in floats and might be valid but much larger than what we
|
||||||
// the size could not be expressed in int32
|
// can handle the size could not be expressed in int32
|
||||||
double realSize = bounds.Width() * bounds.Height();
|
double realSize = bounds.Width() * bounds.Height();
|
||||||
if (realSize > (double)(INT_MAX / 4)) {
|
if (realSize > (double)(INT_MAX / 4)) {
|
||||||
fprintf(stderr, "bitmap bounds is much too large: BRect(%.1f, %.1f, %.1f, %.1f)\n",
|
fprintf(stderr, "bitmap bounds is much too large: "
|
||||||
bounds.left, bounds.top, bounds.right, bounds.bottom);
|
"BRect(%.1f, %.1f, %.1f, %.1f)\n",
|
||||||
|
bounds.left, bounds.top, bounds.right, bounds.bottom);
|
||||||
error = B_BAD_VALUE;
|
error = B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1052,16 +1053,28 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fInitError = error;
|
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 (fInitError == B_OK) {
|
||||||
if (flags & B_BITMAP_ACCEPTS_VIEWS) {
|
if (flags & B_BITMAP_ACCEPTS_VIEWS) {
|
||||||
fWindow = new BWindow(Bounds(), fServerToken);
|
fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken);
|
||||||
// A BWindow starts life locked and is unlocked
|
if (fWindow) {
|
||||||
// in Show(), but this window is never shown and
|
// A BWindow starts life locked and is unlocked
|
||||||
// it's message loop is never started.
|
// in Show(), but this window is never shown and
|
||||||
fWindow->Unlock();
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,16 +188,8 @@ BitmapManager::CreateBitmap(ClientMemoryAllocator* allocator,
|
|||||||
if (success) {
|
if (success) {
|
||||||
bitmap->fBuffer = buffer;
|
bitmap->fBuffer = buffer;
|
||||||
bitmap->fToken = gTokenSpace.NewToken(kBitmapToken, bitmap);
|
bitmap->fToken = gTokenSpace.NewToken(kBitmapToken, bitmap);
|
||||||
|
// NOTE: the client handles clearing to white in case the flags
|
||||||
if (flags & (B_BITMAP_CLEAR_TO_WHITE | B_BITMAP_ACCEPTS_VIEWS)) {
|
// indicate this is needed
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Allocation failed for buffer or bitmap list
|
// Allocation failed for buffer or bitmap list
|
||||||
delete bitmap;
|
delete bitmap;
|
||||||
|
Loading…
Reference in New Issue
Block a user