* r27001 left some parameter checks which need to be ommited

for vector icons. Simplified the checks and moved them to
  where the old B_CMAP8 icon is retrieved. The bitmap is allowed
  to have another color space, in which case the icon data is
  converted (code was already in place).
* Added a NOTE comment to how the new B_GET_VECTOR_ICON ioctl
  knows about the correct buffer size for the icon data.
I've tested setting the desktop icon size to something else than
16x16 or 32x32 and it works fine now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27032 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-08-18 11:05:15 +00:00
parent 320bd2bd5a
commit aac7507616
+20 -15
View File
@@ -209,17 +209,6 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which)
if (device == NULL || icon == NULL)
return B_BAD_VALUE;
BRect rect;
if (which == B_MINI_ICON)
rect.Set(0, 0, 15, 15);
else if (which == B_LARGE_ICON)
rect.Set(0, 0, 31, 31);
else
return B_BAD_VALUE;
if (icon->Bounds() != rect)
return B_BAD_VALUE;
uint8* data;
size_t size;
type_code type;
@@ -230,11 +219,20 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which)
return status;
}
// Vector icon was not available, try old one
// Vector icon was not available, try old one, also checking the icon_size
// parameter
BRect rect;
if (which == B_MINI_ICON)
rect.Set(0, 0, 15, 15);
else if (which == B_LARGE_ICON)
rect.Set(0, 0, 31, 31);
else
return B_BAD_VALUE;
// check whether icon size and bitmap dimensions do match
if (icon->Bounds() != rect || icon->ColorSpace() != B_CMAP8)
return B_BAD_VALUE;
if (icon->Bounds() != rect)
return B_MISMATCHED_VALUES;
void* iconData = icon->Bits();
size_t iconSize = icon->BitsLength();
@@ -246,7 +244,7 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which)
return B_NO_MEMORY;
}
// get the icon
// get the icon, convert temporary data into bitmap if necessary
status = get_device_icon(device, iconData, which);
if (status == B_OK && iconData != icon->Bits())
icon->SetBits(iconData, iconSize, 0, B_CMAP8);
@@ -282,6 +280,12 @@ get_device_icon(const char *device, uint8** _data, size_t* _size,
// Getting the named icon failed, try vector icon next
// NOTE: The actual icon size is unknown as of yet. After the first call
// to B_GET_VECTOR_ICON, the actual size is known and the final buffer
// is allocated with the correct size. If the buffer needed to be
// larger, then the temporary buffer above will not yet contain the
// valid icon data. In that case, a second call to B_GET_VECTOR_ICON
// retrieves it into the final buffer.
uint8 data[8192];
device_icon iconData = {sizeof(data), data};
status_t status = ioctl(fd, B_GET_VECTOR_ICON, &iconData,
@@ -297,6 +301,7 @@ get_device_icon(const char *device, uint8** _data, size_t* _size,
if (status == B_OK) {
if (iconData.icon_size > (int32)sizeof(data)) {
// the stack buffer does not contain the data, see NOTE above
iconData.icon_data = *_data;
status = ioctl(fd, B_GET_VECTOR_ICON, &iconData,
sizeof(device_icon));