* Some style cleanups, no functional change.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31759 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-07-26 11:25:14 +00:00
parent 40265acfb3
commit 63c07622f6
4 changed files with 201 additions and 201 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2008, Haiku, Inc. * Copyright 2007-2009, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -17,12 +17,8 @@ namespace BPrivate {
bool get_mode_parameter(uint32 mode, int32& width, int32& height, bool get_mode_parameter(uint32 mode, int32& width, int32& height,
uint32& colorSpace); uint32& colorSpace);
int32 get_bytes_per_row(color_space colorSpace, int32 width); int32 get_bytes_per_row(color_space colorSpace, int32 width);
} // namespace BPrivate } // namespace BPrivate

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku Inc. * Copyright 2001-2009, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -14,11 +14,16 @@
contain bitmap data. contain bitmap data.
*/ */
#include "ColorConversion.h" #include <Bitmap.h>
#include "BitmapPrivate.h"
#include <algorithm>
#include <limits.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Application.h> #include <Application.h>
#include <Bitmap.h>
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
#include <Locker.h> #include <Locker.h>
#include <View.h> #include <View.h>
@ -29,18 +34,13 @@
#include <ServerMemoryAllocator.h> #include <ServerMemoryAllocator.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
#include <algorithm> #include "ColorConversion.h"
#include <limits.h> #include "BitmapPrivate.h"
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace BPrivate; using namespace BPrivate;
// get_raw_bytes_per_row
/*! \brief Returns the number of bytes per row needed to store the actual /*! \brief Returns the number of bytes per row needed to store the actual
bitmap data (not including any padding) given a color space and a bitmap data (not including any padding) given a color space and a
row width. row width.
@ -49,8 +49,7 @@ using namespace BPrivate;
\return The number of bytes per row needed to store data for a row, or \return The number of bytes per row needed to store data for a row, or
0, if the color space is not supported. 0, if the color space is not supported.
*/ */
static inline static inline int32
int32
get_raw_bytes_per_row(color_space colorSpace, int32 width) get_raw_bytes_per_row(color_space colorSpace, int32 width)
{ {
int32 bpr = 0; int32 bpr = 0;
@ -101,7 +100,9 @@ get_raw_bytes_per_row(color_space colorSpace, int32 width)
return bpr; return bpr;
} }
// get_bytes_per_row
namespace BPrivate {
/*! \brief Returns the number of bytes per row needed to store the bitmap /*! \brief Returns the number of bytes per row needed to store the bitmap
data (including any padding) given a color space and a row width. data (including any padding) given a color space and a row width.
\param colorSpace The color space. \param colorSpace The color space.
@ -109,8 +110,6 @@ get_raw_bytes_per_row(color_space colorSpace, int32 width)
\return The number of bytes per row needed to store data for a row, or \return The number of bytes per row needed to store data for a row, or
0, if the color space is not supported. 0, if the color space is not supported.
*/ */
namespace BPrivate {
int32 int32
get_bytes_per_row(color_space colorSpace, int32 width) get_bytes_per_row(color_space colorSpace, int32 width)
{ {
@ -120,7 +119,8 @@ get_bytes_per_row(color_space colorSpace, int32 width)
return bpr; return bpr;
} }
} } // namespace BPrivate
// #pragma mark - // #pragma mark -
@ -136,7 +136,8 @@ get_bytes_per_row(color_space colorSpace, int32 width)
*/ */
BBitmap::BBitmap(BRect bounds, uint32 flags, color_space colorSpace, BBitmap::BBitmap(BRect bounds, uint32 flags, color_space colorSpace,
int32 bytesPerRow, screen_id screenID) int32 bytesPerRow, screen_id screenID)
: fBasePointer(NULL), :
fBasePointer(NULL),
fSize(0), fSize(0),
fColorSpace(B_NO_COLOR_SPACE), fColorSpace(B_NO_COLOR_SPACE),
fBounds(0, 0, -1, -1), fBounds(0, 0, -1, -1),
@ -152,7 +153,7 @@ BBitmap::BBitmap(BRect bounds, uint32 flags, color_space colorSpace,
_InitObject(bounds, colorSpace, flags, bytesPerRow, screenID); _InitObject(bounds, colorSpace, flags, bytesPerRow, screenID);
} }
// constructor
/*! \brief Creates and initializes a BBitmap. /*! \brief Creates and initializes a BBitmap.
\param bounds The bitmap dimensions. \param bounds The bitmap dimensions.
\param colorSpace The bitmap's color space. \param colorSpace The bitmap's color space.
@ -164,7 +165,8 @@ BBitmap::BBitmap(BRect bounds, uint32 flags, color_space colorSpace,
*/ */
BBitmap::BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews, BBitmap::BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews,
bool needsContiguous) bool needsContiguous)
: fBasePointer(NULL), :
fBasePointer(NULL),
fSize(0), fSize(0),
fColorSpace(B_NO_COLOR_SPACE), fColorSpace(B_NO_COLOR_SPACE),
fBounds(0, 0, -1, -1), fBounds(0, 0, -1, -1),
@ -181,10 +183,9 @@ BBitmap::BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews,
| (needsContiguous ? B_BITMAP_IS_CONTIGUOUS : 0); | (needsContiguous ? B_BITMAP_IS_CONTIGUOUS : 0);
_InitObject(bounds, colorSpace, flags, B_ANY_BYTES_PER_ROW, _InitObject(bounds, colorSpace, flags, B_ANY_BYTES_PER_ROW,
B_MAIN_SCREEN_ID); B_MAIN_SCREEN_ID);
} }
// constructor
/*! \brief Creates a BBitmap as a clone of another bitmap. /*! \brief Creates a BBitmap as a clone of another bitmap.
\param source The source bitmap. \param source The source bitmap.
\param acceptsViews \c true, if the bitmap shall accept BViews, i.e. if \param acceptsViews \c true, if the bitmap shall accept BViews, i.e. if
@ -193,9 +194,9 @@ BBitmap::BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews,
\param needsContiguous If \c true a physically contiguous chunk of memory \param needsContiguous If \c true a physically contiguous chunk of memory
will be allocated. will be allocated.
*/ */
BBitmap::BBitmap(const BBitmap *source, bool acceptsViews, BBitmap::BBitmap(const BBitmap* source, bool acceptsViews, bool needsContiguous)
bool needsContiguous) :
: fBasePointer(NULL), fBasePointer(NULL),
fSize(0), fSize(0),
fColorSpace(B_NO_COLOR_SPACE), fColorSpace(B_NO_COLOR_SPACE),
fBounds(0, 0, -1, -1), fBounds(0, 0, -1, -1),
@ -213,8 +214,10 @@ BBitmap::BBitmap(const BBitmap *source, bool acceptsViews,
| (needsContiguous ? B_BITMAP_IS_CONTIGUOUS : 0); | (needsContiguous ? B_BITMAP_IS_CONTIGUOUS : 0);
_InitObject(source->Bounds(), source->ColorSpace(), flags, _InitObject(source->Bounds(), source->ColorSpace(), flags,
source->BytesPerRow(), B_MAIN_SCREEN_ID); source->BytesPerRow(), B_MAIN_SCREEN_ID);
if (InitCheck() == B_OK) if (InitCheck() == B_OK) {
memcpy(Bits(), source->Bits(), min_c(BitsLength(), source->BitsLength())); memcpy(Bits(), source->Bits(), min_c(BitsLength(),
source->BitsLength()));
}
} }
} }
@ -248,12 +251,13 @@ BBitmap::~BBitmap()
_CleanUp(); _CleanUp();
} }
// unarchiving constructor
/*! \brief Unarchives a bitmap from a BMessage. /*! \brief Unarchives a bitmap from a BMessage.
\param data The archive. \param data The archive.
*/ */
BBitmap::BBitmap(BMessage *data) BBitmap::BBitmap(BMessage* data)
: BArchivable(data), :
BArchivable(data),
fBasePointer(NULL), fBasePointer(NULL),
fSize(0), fSize(0),
fColorSpace(B_NO_COLOR_SPACE), fColorSpace(B_NO_COLOR_SPACE),
@ -296,7 +300,7 @@ BBitmap::BBitmap(BMessage *data)
if (InitCheck() == B_OK) { if (InitCheck() == B_OK) {
ssize_t size; ssize_t size;
const void *buffer; const void* buffer;
if (data->FindData("_data", B_RAW_TYPE, &buffer, &size) == B_OK) { if (data->FindData("_data", B_RAW_TYPE, &buffer, &size) == B_OK) {
if (size == BitsLength()) { if (size == BitsLength()) {
_AssertPointer(); _AssertPointer();
@ -305,25 +309,26 @@ BBitmap::BBitmap(BMessage *data)
} }
} }
if (fFlags & B_BITMAP_ACCEPTS_VIEWS) { if ((fFlags & B_BITMAP_ACCEPTS_VIEWS) != 0) {
BMessage message; BMessage message;
int32 i = 0; int32 i = 0;
while (data->FindMessage("_views", i++, &message) == B_OK) { while (data->FindMessage("_views", i++, &message) == B_OK) {
if (BView *view = dynamic_cast<BView *>(instantiate_object(&message))) if (BView* view
= dynamic_cast<BView*>(instantiate_object(&message)))
AddChild(view); AddChild(view);
} }
} }
} }
// Instantiate
/*! \brief Instantiates a BBitmap from an archive. /*! \brief Instantiates a BBitmap from an archive.
\param data The archive. \param data The archive.
\return A bitmap reconstructed from the archive or \c NULL, if an error \return A bitmap reconstructed from the archive or \c NULL, if an error
occured. occured.
*/ */
BArchivable * BArchivable*
BBitmap::Instantiate(BMessage *data) BBitmap::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "BBitmap")) if (validate_instantiation(data, "BBitmap"))
return new BBitmap(data); return new BBitmap(data);
@ -331,7 +336,7 @@ BBitmap::Instantiate(BMessage *data)
return NULL; return NULL;
} }
// Archive
/*! \brief Archives the BBitmap object. /*! \brief Archives the BBitmap object.
\param data The archive. \param data The archive.
\param deep \c true, if child object shall be archived as well, \c false \param deep \c true, if child object shall be archived as well, \c false
@ -339,7 +344,7 @@ BBitmap::Instantiate(BMessage *data)
\return \c B_OK, if everything went fine, an error code otherwise. \return \c B_OK, if everything went fine, an error code otherwise.
*/ */
status_t status_t
BBitmap::Archive(BMessage *data, bool deep) const BBitmap::Archive(BMessage* data, bool deep) const
{ {
status_t ret = BArchivable::Archive(data, deep); status_t ret = BArchivable::Archive(data, deep);
@ -356,7 +361,7 @@ BBitmap::Archive(BMessage *data, bool deep) const
ret = data->AddInt32("_rowbytes", fBytesPerRow); ret = data->AddInt32("_rowbytes", fBytesPerRow);
if (ret == B_OK && deep) { if (ret == B_OK && deep) {
if (fFlags & B_BITMAP_ACCEPTS_VIEWS) { if ((fFlags & B_BITMAP_ACCEPTS_VIEWS) != 0) {
BMessage views; BMessage views;
for (int32 i = 0; i < CountChildren(); i++) { for (int32 i = 0; i < CountChildren(); i++) {
if (ChildAt(i)->Archive(&views, deep)) if (ChildAt(i)->Archive(&views, deep))
@ -371,7 +376,7 @@ BBitmap::Archive(BMessage *data, bool deep) const
// the data even if B_BITMAP_ACCEPTS_VIEWS is set (as opposed to // the data even if B_BITMAP_ACCEPTS_VIEWS is set (as opposed to
// the BeBook) // the BeBook)
if (ret == B_OK) { if (ret == B_OK) {
const_cast<BBitmap *>(this)->_AssertPointer(); const_cast<BBitmap*>(this)->_AssertPointer();
ret = data->AddData("_data", B_RAW_TYPE, fBasePointer, fSize); ret = data->AddData("_data", B_RAW_TYPE, fBasePointer, fSize);
} }
} }
@ -379,7 +384,7 @@ BBitmap::Archive(BMessage *data, bool deep) const
return ret; return ret;
} }
// InitCheck
/*! \brief Returns the result from the construction. /*! \brief Returns the result from the construction.
\return \c B_OK, if the object is properly initialized, an error code \return \c B_OK, if the object is properly initialized, an error code
otherwise. otherwise.
@ -390,7 +395,7 @@ BBitmap::InitCheck() const
return fInitError; return fInitError;
} }
// IsValid
/*! \brief Returns whether or not the BBitmap object is valid. /*! \brief Returns whether or not the BBitmap object is valid.
\return \c true, if the object is properly initialized, \c false otherwise. \return \c true, if the object is properly initialized, \c false otherwise.
*/ */
@ -401,8 +406,7 @@ BBitmap::IsValid() const
} }
/*! /*! \brief Locks the bitmap bits so that they cannot be relocated.
\brief Locks the bitmap bits so that they cannot be relocated.
This is currently only used for overlay bitmaps - whenever you This is currently only used for overlay bitmaps - whenever you
need to access their Bits(), you have to lock them first. need to access their Bits(), you have to lock them first.
@ -411,12 +415,12 @@ BBitmap::IsValid() const
and clobbering memory that doesn't belong you. and clobbering memory that doesn't belong you.
*/ */
status_t status_t
BBitmap::LockBits(uint32 *state) BBitmap::LockBits(uint32* state)
{ {
// TODO: how do we fill the "state"? // TODO: how do we fill the "state"?
// It would be more or less useful to report what kind of bitmap // It would be more or less useful to report what kind of bitmap
// we got (ie. overlay, placeholder, or non-overlay) // we got (ie. overlay, placeholder, or non-overlay)
if (fFlags & B_BITMAP_WILL_OVERLAY) { if ((fFlags & B_BITMAP_WILL_OVERLAY) != 0) {
overlay_client_data* data = (overlay_client_data*)fBasePointer; overlay_client_data* data = (overlay_client_data*)fBasePointer;
status_t status; status_t status;
@ -441,8 +445,7 @@ BBitmap::LockBits(uint32 *state)
} }
/*! /*! \brief Unlocks the bitmap's buffer again.
\brief Unlocks the bitmap's buffer again.
Counterpart to LockBits(), see there for comments. Counterpart to LockBits(), see there for comments.
*/ */
void void
@ -462,7 +465,7 @@ BBitmap::UnlockBits()
area_id area_id
BBitmap::Area() const BBitmap::Area() const
{ {
const_cast<BBitmap *>(this)->_AssertPointer(); const_cast<BBitmap*>(this)->_AssertPointer();
return fArea; return fArea;
} }
@ -470,12 +473,12 @@ BBitmap::Area() const
/*! \brief Returns the pointer to the bitmap data. /*! \brief Returns the pointer to the bitmap data.
\return The pointer to the bitmap data. \return The pointer to the bitmap data.
*/ */
void * void*
BBitmap::Bits() const BBitmap::Bits() const
{ {
const_cast<BBitmap *>(this)->_AssertPointer(); const_cast<BBitmap*>(this)->_AssertPointer();
if (fFlags & B_BITMAP_WILL_OVERLAY) { if ((fFlags & B_BITMAP_WILL_OVERLAY) != 0) {
overlay_client_data* data = (overlay_client_data*)fBasePointer; overlay_client_data* data = (overlay_client_data*)fBasePointer;
return data->buffer; return data->buffer;
} }
@ -483,7 +486,7 @@ BBitmap::Bits() const
return (void*)fBasePointer; return (void*)fBasePointer;
} }
// BitsLength
/*! \brief Returns the size of the bitmap data. /*! \brief Returns the size of the bitmap data.
\return The size of the bitmap data. \return The size of the bitmap data.
*/ */
@ -493,7 +496,7 @@ BBitmap::BitsLength() const
return fSize; return fSize;
} }
// BytesPerRow
/*! \brief Returns the number of bytes used to store a row of bitmap data. /*! \brief Returns the number of bytes used to store a row of bitmap data.
\return The number of bytes used to store a row of bitmap data. \return The number of bytes used to store a row of bitmap data.
*/ */
@ -503,7 +506,7 @@ BBitmap::BytesPerRow() const
return fBytesPerRow; return fBytesPerRow;
} }
// ColorSpace
/*! \brief Returns the bitmap's color space. /*! \brief Returns the bitmap's color space.
\return The bitmap's color space. \return The bitmap's color space.
*/ */
@ -513,7 +516,7 @@ BBitmap::ColorSpace() const
return fColorSpace; return fColorSpace;
} }
// Bounds
/*! \brief Returns the bitmap's dimensions. /*! \brief Returns the bitmap's dimensions.
\return The bitmap's dimensions. \return The bitmap's dimensions.
*/ */
@ -523,7 +526,7 @@ BBitmap::Bounds() const
return fBounds; return fBounds;
} }
// Flags
/*! \brief Returns the bitmap's creating flags. /*! \brief Returns the bitmap's creating flags.
This method informs about which flags have been used to create the This method informs about which flags have been used to create the
@ -539,7 +542,6 @@ BBitmap::Flags() const
} }
// SetBits
/*! \brief Assigns data to the bitmap. /*! \brief Assigns data to the bitmap.
Data are directly written into the bitmap's data buffer, being converted Data are directly written into the bitmap's data buffer, being converted
@ -565,7 +567,7 @@ BBitmap::Flags() const
\param colorSpace Color space of the source data. \param colorSpace Color space of the source data.
*/ */
void void
BBitmap::SetBits(const void *data, int32 length, int32 offset, BBitmap::SetBits(const void* data, int32 length, int32 offset,
color_space colorSpace) color_space colorSpace)
{ {
status_t error = (InitCheck() == B_OK ? B_OK : B_NO_INIT); status_t error = (InitCheck() == B_OK ? B_OK : B_NO_INIT);
@ -578,21 +580,22 @@ BBitmap::SetBits(const void *data, int32 length, int32 offset,
int32 inBPR = -1; int32 inBPR = -1;
// tweaks to mimic R5 behavior // tweaks to mimic R5 behavior
if (error == B_OK) { if (error == B_OK) {
// B_RGB32 means actually unpadded B_RGB24_BIG
if (colorSpace == B_RGB32) { if (colorSpace == B_RGB32) {
// B_RGB32 means actually unpadded B_RGB24_BIG
colorSpace = B_RGB24_BIG; colorSpace = B_RGB24_BIG;
inBPR = width * 3; inBPR = width * 3;
} else if (colorSpace == B_CMAP8 && fColorSpace != B_CMAP8) {
// If in color space is B_CMAP8, but the bitmap's is another one, // If in color space is B_CMAP8, but the bitmap's is another one,
// ignore source data row padding. // ignore source data row padding.
} else if (colorSpace == B_CMAP8 && fColorSpace != B_CMAP8)
inBPR = width; inBPR = width;
} }
}
// call the sane method, which does the actual work // call the sane method, which does the actual work
if (error == B_OK) if (error == B_OK)
error = ImportBits(data, length, inBPR, offset, colorSpace); error = ImportBits(data, length, inBPR, offset, colorSpace);
} }
// ImportBits
/*! \brief Assigns data to the bitmap. /*! \brief Assigns data to the bitmap.
Data are directly written into the bitmap's data buffer, being converted Data are directly written into the bitmap's data buffer, being converted
@ -618,7 +621,7 @@ BBitmap::SetBits(const void *data, int32 length, int32 offset,
unsupported \a colorSpace. unsupported \a colorSpace.
*/ */
status_t status_t
BBitmap::ImportBits(const void *data, int32 length, int32 bpr, int32 offset, BBitmap::ImportBits(const void* data, int32 length, int32 bpr, int32 offset,
color_space colorSpace) color_space colorSpace)
{ {
_AssertPointer(); _AssertPointer();
@ -666,7 +669,7 @@ BBitmap::ImportBits(const void *data, int32 length, int32 bpr, int32 offset,
\a colorSpace or invalid width/height. \a colorSpace or invalid width/height.
*/ */
status_t status_t
BBitmap::ImportBits(const void *data, int32 length, int32 bpr, BBitmap::ImportBits(const void* data, int32 length, int32 bpr,
color_space colorSpace, BPoint from, BPoint to, int32 width, int32 height) color_space colorSpace, BPoint from, BPoint to, int32 width, int32 height)
{ {
_AssertPointer(); _AssertPointer();
@ -704,7 +707,7 @@ BBitmap::ImportBits(const void *data, int32 length, int32 bpr,
or the conversion from or to one of the color spaces is not supported. or the conversion from or to one of the color spaces is not supported.
*/ */
status_t status_t
BBitmap::ImportBits(const BBitmap *bitmap) BBitmap::ImportBits(const BBitmap* bitmap)
{ {
if (InitCheck() != B_OK) if (InitCheck() != B_OK)
return B_NO_INIT; return B_NO_INIT;
@ -737,7 +740,7 @@ BBitmap::ImportBits(const BBitmap *bitmap)
the color spaces is not supported, or invalid width/height. the color spaces is not supported, or invalid width/height.
*/ */
status_t status_t
BBitmap::ImportBits(const BBitmap *bitmap, BPoint from, BPoint to, int32 width, BBitmap::ImportBits(const BBitmap* bitmap, BPoint from, BPoint to, int32 width,
int32 height) int32 height)
{ {
if (InitCheck() != B_OK) if (InitCheck() != B_OK)
@ -754,7 +757,7 @@ BBitmap::ImportBits(const BBitmap *bitmap, BPoint from, BPoint to, int32 width,
/*! \brief Returns the overlay_restrictions structure for this bitmap /*! \brief Returns the overlay_restrictions structure for this bitmap
*/ */
status_t status_t
BBitmap::GetOverlayRestrictions(overlay_restrictions *restrictions) const BBitmap::GetOverlayRestrictions(overlay_restrictions* restrictions) const
{ {
if ((fFlags & B_BITMAP_WILL_OVERLAY) == 0) if ((fFlags & B_BITMAP_WILL_OVERLAY) == 0)
return B_BAD_TYPE; return B_BAD_TYPE;
@ -781,23 +784,23 @@ BBitmap::GetOverlayRestrictions(overlay_restrictions *restrictions) const
\param view The view to be added. \param view The view to be added.
*/ */
void void
BBitmap::AddChild(BView *view) BBitmap::AddChild(BView* view)
{ {
if (fWindow != NULL) if (fWindow != NULL)
fWindow->AddChild(view); fWindow->AddChild(view);
} }
// RemoveChild
/*! \brief Removes a BView from the bitmap's view hierarchy. /*! \brief Removes a BView from the bitmap's view hierarchy.
\param view The view to be removed. \param view The view to be removed.
*/ */
bool bool
BBitmap::RemoveChild(BView *view) BBitmap::RemoveChild(BView* view)
{ {
return fWindow != NULL ? fWindow->RemoveChild(view) : false; return fWindow != NULL ? fWindow->RemoveChild(view) : false;
} }
// CountChildren
/*! \brief Returns the number of BViews currently belonging to the bitmap. /*! \brief Returns the number of BViews currently belonging to the bitmap.
\return The number of BViews currently belonging to the bitmap. \return The number of BViews currently belonging to the bitmap.
*/ */
@ -807,7 +810,7 @@ BBitmap::CountChildren() const
return fWindow != NULL ? fWindow->CountChildren() : 0; return fWindow != NULL ? fWindow->CountChildren() : 0;
} }
// ChildAt
/*! \brief Returns the BView at a certain index in the bitmap's list of views. /*! \brief Returns the BView at a certain index in the bitmap's list of views.
\param index The index of the BView to be returned. \param index The index of the BView to be returned.
\return The BView at index \a index or \c NULL, if the index is out of \return The BView at index \a index or \c NULL, if the index is out of
@ -819,31 +822,31 @@ BBitmap::ChildAt(int32 index) const
return fWindow != NULL ? fWindow->ChildAt(index) : NULL; return fWindow != NULL ? fWindow->ChildAt(index) : NULL;
} }
// FindView
/*! \brief Returns a bitmap's BView with a certain name. /*! \brief Returns a bitmap's BView with a certain name.
\param name The name of the BView to be returned. \param name The name of the BView to be returned.
\return The BView with the name \a name or \c NULL, if the bitmap doesn't \return The BView with the name \a name or \c NULL, if the bitmap doesn't
know a view with that name. know a view with that name.
*/ */
BView* BView*
BBitmap::FindView(const char *viewName) const BBitmap::FindView(const char* viewName) const
{ {
return fWindow != NULL ? fWindow->FindView(viewName) : NULL; return fWindow != NULL ? fWindow->FindView(viewName) : NULL;
} }
// FindView
/*! \brief Returns a bitmap's BView at a certain location. /*! \brief Returns a bitmap's BView at a certain location.
\param point The location. \param point The location.
\return The BView with located at \a point or \c NULL, if the bitmap \return The BView with located at \a point or \c NULL, if the bitmap
doesn't know a view at this location. doesn't know a view at this location.
*/ */
BView * BView*
BBitmap::FindView(BPoint point) const BBitmap::FindView(BPoint point) const
{ {
return fWindow != NULL ? fWindow->FindView(point) : NULL; return fWindow != NULL ? fWindow->FindView(point) : NULL;
} }
// Lock
/*! \brief Locks the off-screen window that belongs to the bitmap. /*! \brief Locks the off-screen window that belongs to the bitmap.
The bitmap must accept views, if locking should work. The bitmap must accept views, if locking should work.
@ -857,7 +860,7 @@ BBitmap::Lock()
return fWindow != NULL ? fWindow->Lock() : false; return fWindow != NULL ? fWindow->Lock() : false;
} }
// Unlock
/*! \brief Unlocks the off-screen window that belongs to the bitmap. /*! \brief Unlocks the off-screen window that belongs to the bitmap.
The bitmap must accept views, if locking should work. The bitmap must accept views, if locking should work.
@ -869,7 +872,7 @@ BBitmap::Unlock()
fWindow->Unlock(); fWindow->Unlock();
} }
// IsLocked
/*! \brief Returns whether or not the bitmap's off-screen window is locked. /*! \brief Returns whether or not the bitmap's off-screen window is locked.
The bitmap must accept views, if locking should work. The bitmap must accept views, if locking should work.
@ -883,7 +886,7 @@ BBitmap::IsLocked() const
} }
BBitmap & BBitmap&
BBitmap::operator=(const BBitmap& source) BBitmap::operator=(const BBitmap& source)
{ {
_CleanUp(); _CleanUp();
@ -902,7 +905,7 @@ BBitmap::operator=(const BBitmap& source)
status_t status_t
BBitmap::Perform(perform_code d, void *arg) BBitmap::Perform(perform_code d, void* arg)
{ {
return BArchivable::Perform(d, arg); return BArchivable::Perform(d, arg);
} }
@ -917,7 +920,7 @@ void BBitmap::_ReservedBitmap3() {}
// get_shared_pointer // get_shared_pointer
/*! \brief ??? /*! \brief ???
*/ */
char * char*
BBitmap::get_shared_pointer() const BBitmap::get_shared_pointer() const
{ {
return NULL; // not implemented return NULL; // not implemented
@ -1026,17 +1029,20 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
BPrivate::ServerMemoryAllocator* allocator BPrivate::ServerMemoryAllocator* allocator
= BApplication::Private::ServerAllocator(); = BApplication::Private::ServerAllocator();
if (allocationFlags & kNewAllocatorArea) if (allocationFlags & kNewAllocatorArea) {
error = allocator->AddArea(fServerArea, fArea, fBasePointer); error = allocator->AddArea(fServerArea, fArea,
else { fBasePointer);
error = allocator->AreaAndBaseFor(fServerArea, fArea, fBasePointer); } else {
error = allocator->AreaAndBaseFor(fServerArea, fArea,
fBasePointer);
if (error == B_OK) if (error == B_OK)
fBasePointer += fAreaOffset; fBasePointer += fAreaOffset;
} }
if (allocationFlags & kFramebuffer) { if ((allocationFlags & kFramebuffer) != 0) {
// the base pointer will now point to an overlay_client_data structure // The base pointer will now point to an overlay_client_data
// bytes per row might be modified to match hardware constraints // structure bytes per row might be modified to match
// hardware constraints
link.Read<int32>(&bytesPerRow); link.Read<int32>(&bytesPerRow);
size = bytesPerRow * (bounds.IntegerHeight() + 1); size = bytesPerRow * (bounds.IntegerHeight() + 1);
} }
@ -1081,7 +1087,8 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
// TODO: Creating an offscreen window with a non32 bit bitmap // TODO: Creating an offscreen window with a non32 bit bitmap
// copies the current content of the bitmap to a back buffer. // copies the current content of the bitmap to a back buffer.
// So at this point the bitmap has to be already cleared to white. // So at this point the bitmap has to be already cleared to white.
// Better move the above code to the server so the problem looks more clear. // Better move the above code to the server so the problem looks more
// clear.
if (flags & B_BITMAP_ACCEPTS_VIEWS) { if (flags & B_BITMAP_ACCEPTS_VIEWS) {
fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken); fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken);
if (fWindow) { if (fWindow) {
@ -1096,8 +1103,7 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
} }
/*! /*! \brief Cleans up any memory allocated by the bitmap and
\brief Cleans up any memory allocated by the bitmap and
informs the server to do so as well (if needed). informs the server to do so as well (if needed).
*/ */
void void
@ -1106,7 +1112,7 @@ BBitmap::_CleanUp()
if (fBasePointer == NULL) if (fBasePointer == NULL)
return; return;
if (fFlags & B_BITMAP_NO_SERVER_LINK) { if ((fFlags & B_BITMAP_NO_SERVER_LINK) != 0) {
free(fBasePointer); free(fBasePointer);
} else { } else {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
@ -1132,10 +1138,10 @@ BBitmap::_AssertPointer()
{ {
if (fBasePointer == NULL && fServerArea >= B_OK && fAreaOffset == -1) { if (fBasePointer == NULL && fServerArea >= B_OK && fAreaOffset == -1) {
// We lazily clone our own areas - if the bitmap is part of the usual // We lazily clone our own areas - if the bitmap is part of the usual
// server memory area, or is a B_BITMAP_NO_SERVER_LINK bitmap, it already // server memory area, or is a B_BITMAP_NO_SERVER_LINK bitmap, it
// has its data. // already has its data.
fArea = clone_area("shared bitmap area", (void **)&fBasePointer, B_ANY_ADDRESS, fArea = clone_area("shared bitmap area", (void**)&fBasePointer,
B_READ_AREA | B_WRITE_AREA, fServerArea); B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, fServerArea);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. * Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -24,14 +24,15 @@
using std::nothrow; using std::nothrow;
using namespace BPrivate; using namespace BPrivate;
/*! /*!
A word about memory housekeeping and why it's implemented this way: A word about memory housekeeping and why it's implemented this way:
The reason why this looks so complicated is to optimize the most common The reason why this looks so complicated is to optimize the most common
path (bitmap creation from the application), and don't cause any further path (bitmap creation from the application), and don't cause any further
memory allocations for maintaining memory in that case. memory allocations for maintaining memory in that case.
If a bitmap was allocated this way, both, the fAllocator and fAllocationCookie If a bitmap was allocated this way, both, the fAllocator and
members are used. fAllocationCookie members are used.
For overlays, the allocator only allocates a small piece of client memory For overlays, the allocator only allocates a small piece of client memory
for use with the overlay_client_data structure - the actual buffer will be for use with the overlay_client_data structure - the actual buffer will be
@ -48,9 +49,10 @@ using namespace BPrivate;
\param rect Size of the bitmap. \param rect Size of the bitmap.
\param space Color space of the bitmap \param space Color space of the bitmap
\param flags Various bitmap flags to tweak the bitmap as defined in Bitmap.h \param flags Various bitmap flags to tweak the bitmap as defined in Bitmap.h
\param bytesperline Number of bytes in each row. -1 implies the default value. Any \param bytesperline Number of bytes in each row. -1 implies the default
value less than the the default will less than the default will be overridden, but any value value. Any value less than the the default will less than the default
greater than the default will result in the number of bytes specified. will be overridden, but any value greater than the default will result
in the number of bytes specified.
\param screen Screen assigned to the bitmap. \param screen Screen assigned to the bitmap.
*/ */
ServerBitmap::ServerBitmap(BRect rect, color_space space, uint32 flags, ServerBitmap::ServerBitmap(BRect rect, color_space space, uint32 flags,
@ -135,8 +137,7 @@ ServerBitmap::_Release()
} }
/*! /*! \brief Internal function used by subclasses
\brief Internal function used by subclasses
Subclasses should call this so the buffer can automagically Subclasses should call this so the buffer can automagically
be allocated on the heap. be allocated on the heap.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. * Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -21,8 +21,7 @@ class Overlay;
class ServerApp; class ServerApp;
/*! /*! \class ServerBitmap ServerBitmap.h
\class ServerBitmap ServerBitmap.h
\brief Bitmap class used inside the server. \brief Bitmap class used inside the server.
This class is not directly allocated or freed. Instead, it is This class is not directly allocated or freed. Instead, it is
@ -93,12 +92,10 @@ protected:
ServerBitmap(const ServerBitmap* bmp); ServerBitmap(const ServerBitmap* bmp);
virtual ~ServerBitmap(); virtual ~ServerBitmap();
bool _Release(); bool _Release();
void _AllocateBuffer(); void _AllocateBuffer();
ClientMemoryAllocator* fAllocator; ClientMemoryAllocator* fAllocator;
void* fAllocationCookie; void* fAllocationCookie;
::Overlay* fOverlay; ::Overlay* fOverlay;
@ -126,11 +123,11 @@ class UtilityBitmap : public ServerBitmap {
uint32 width, uint32 height, uint32 width, uint32 height,
color_space format); color_space format);
virtual ~UtilityBitmap(); virtual ~UtilityBitmap();
}; };
// ShallowCopy (only for server bitmaps)
//! (only for server bitmaps)
void void
ServerBitmap::ShallowCopy(const ServerBitmap* from) ServerBitmap::ShallowCopy(const ServerBitmap* from)
{ {