* Implemented new BView drawing functions DrawBitmap[Async](

const BBitmap* bitmap, BRect bitmapRect, BRect viewRect, uint32 options).
  Only option so far is B_FILTER_BITMAP_BILINEAR.
* BView::DrawBitmap[Async](const BBitmap* bitmap, BRect viewRect) was accessing
  the bitmap pointer without checking it. Would therefore crash when passing
  NULL, unlike the other methods.
* The BPicture code already reserved room for the BBitmap flags, but did not
  store the actual flags and neiter use them for anything. Since the bitmap
  data is stored anyways, the bitmap creation flags do not matter. So I reused
  this for the new bitmap drawing options.
* Rewrote Bitmap.h and removed the B_BITMAP_SCALE_BILINEAR flag again.
* Tried to optimize Painter::_DrawBitmapBilinearCopy32() a little by giving
  the compiler better hints. There seems to be a marginal, possibly imagined
  speed increase < 0.05 ms. ;-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26665 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-07-28 18:58:30 +00:00
parent 42ed4fd712
commit 162a7f5f8e
9 changed files with 228 additions and 163 deletions
+95 -78
View File
@@ -26,107 +26,124 @@ enum {
B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA,
B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED,
B_BITMAP_IS_OFFSCREEN = 0x00000020, B_BITMAP_IS_OFFSCREEN = 0x00000020,
// Offscreen but non-overlay bitmaps are not supported on Haiku,
// but appearantly never were on BeOS either! The accelerant API
// would need to be extended to so that the app_server can ask
// the graphics driver to reserve memory for a bitmap and for this
// to make any sense, an accelerated blit from this memory into
// the framebuffer needs to be added to the API as well.
B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN, B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN,
B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080, B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080,
// Haiku extensions: // Haiku extensions:
B_BITMAP_NO_SERVER_LINK = 0x00000100, B_BITMAP_NO_SERVER_LINK = 0x00000100,
B_BITMAP_SCALE_BILINEAR = 0x00000200 // Cheap to create, object will manage memory itself,
// TODO: Make this simply "SMOOTH_SCALE" and use // no BApplication needs to run, but one can't draw such
// better quality methods the faster the computer? // a BBitmap.
}; };
#define B_ANY_BYTES_PER_ROW -1 #define B_ANY_BYTES_PER_ROW -1
class BBitmap : public BArchivable { class BBitmap : public BArchivable {
public: public:
BBitmap(BRect bounds, uint32 flags, color_space colorSpace, BBitmap(BRect bounds, uint32 flags,
int32 bytesPerRow = B_ANY_BYTES_PER_ROW, color_space colorSpace,
screen_id screenID = B_MAIN_SCREEN_ID); int32 bytesPerRow = B_ANY_BYTES_PER_ROW,
BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, screen_id screenID = B_MAIN_SCREEN_ID);
bool needsContiguous = false); BBitmap(BRect bounds, color_space colorSpace,
BBitmap(const BBitmap& source, uint32 flags); bool acceptsViews = false,
BBitmap(const BBitmap& source); bool needsContiguous = false);
BBitmap(const BBitmap *source, bool acceptsViews = false, BBitmap(const BBitmap& source, uint32 flags);
bool needsContiguous = false); BBitmap(const BBitmap& source);
virtual ~BBitmap(); BBitmap(const BBitmap* source,
bool acceptsViews = false,
bool needsContiguous = false);
virtual ~BBitmap();
// Archiving // Archiving
BBitmap(BMessage *data); BBitmap(BMessage* data);
static BArchivable *Instantiate(BMessage *data); static BArchivable* Instantiate(BMessage* data);
virtual status_t Archive(BMessage *data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;
status_t InitCheck() const; status_t InitCheck() const;
bool IsValid() const; bool IsValid() const;
status_t LockBits(uint32 *state = NULL); status_t LockBits(uint32* state = NULL);
void UnlockBits(); void UnlockBits();
area_id Area() const; area_id Area() const;
void *Bits() const; void* Bits() const;
int32 BitsLength() const; int32 BitsLength() const;
int32 BytesPerRow() const; int32 BytesPerRow() const;
color_space ColorSpace() const; color_space ColorSpace() const;
BRect Bounds() const; BRect Bounds() const;
uint32 Flags() const;
void SetBits(const void *data, int32 length, int32 offset, status_t SetDrawingFlags(uint32 flags);
color_space colorSpace); uint32 Flags() const;
// not part of the R5 API void SetBits(const void* data, int32 length,
status_t ImportBits(const void *data, int32 length, int32 bpr, int32 offset, color_space colorSpace);
int32 offset, color_space colorSpace);
status_t ImportBits(const void *data, int32 length, int32 bpr,
color_space colorSpace, BPoint from, BPoint to,
int32 width, int32 height);
status_t ImportBits(const BBitmap *bitmap);
status_t ImportBits(const BBitmap *bitmap, BPoint from, BPoint to,
int32 width, int32 height);
status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const; // not part of the R5 API
status_t ImportBits(const void* data, int32 length,
int32 bpr, int32 offset,
color_space colorSpace);
status_t ImportBits(const void* data, int32 length,
int32 bpr, color_space colorSpace,
BPoint from, BPoint to, int32 width,
int32 height);
status_t ImportBits(const BBitmap* bitmap);
status_t ImportBits(const BBitmap* bitmap, BPoint from,
BPoint to, int32 width, int32 height);
// to mimic a BWindow status_t GetOverlayRestrictions(
virtual void AddChild(BView *view); overlay_restrictions* restrictions) const;
virtual bool RemoveChild(BView *view);
int32 CountChildren() const;
BView *ChildAt(int32 index) const;
BView *FindView(const char *viewName) const;
BView *FindView(BPoint point) const;
bool Lock();
void Unlock();
bool IsLocked() const;
BBitmap& operator=(const BBitmap& source); // to mimic a BWindow
virtual void AddChild(BView* view);
virtual bool RemoveChild(BView* view);
int32 CountChildren() const;
BView* ChildAt(int32 index) const;
BView* FindView(const char* viewName) const;
BView* FindView(BPoint point) const;
bool Lock();
void Unlock();
bool IsLocked() const;
private: BBitmap& operator=(const BBitmap& source);
friend class BView;
friend class BApplication;
friend class BPrivate::BPrivateScreen;
virtual status_t Perform(perform_code d, void *arg); private:
virtual void _ReservedBitmap1(); friend class BView;
virtual void _ReservedBitmap2(); friend class BApplication;
virtual void _ReservedBitmap3(); friend class BPrivate::BPrivateScreen;
int32 _ServerToken() const; virtual status_t Perform(perform_code d, void* arg);
void _InitObject(BRect bounds, color_space colorSpace, uint32 flags, virtual void _ReservedBitmap1();
int32 bytesPerRow, screen_id screenID); virtual void _ReservedBitmap2();
void _CleanUp(); virtual void _ReservedBitmap3();
void _AssertPointer();
uint8 *fBasePointer; int32 _ServerToken() const;
int32 fSize; void _InitObject(BRect bounds,
color_space fColorSpace; color_space colorSpace, uint32 flags,
BRect fBounds; int32 bytesPerRow, screen_id screenID);
int32 fBytesPerRow; void _CleanUp();
BWindow *fWindow; void _AssertPointer();
int32 fServerToken;
int32 fAreaOffset; private:
uint8 unused; uint8* fBasePointer;
area_id fArea; int32 fSize;
area_id fServerArea; color_space fColorSpace;
uint32 fFlags; BRect fBounds;
status_t fInitError; int32 fBytesPerRow;
BWindow* fWindow;
int32 fServerToken;
int32 fAreaOffset;
uint8 unused;
area_id fArea;
area_id fServerArea;
uint32 fFlags;
status_t fInitError;
}; };
#endif // _BITMAP_H #endif // _BITMAP_H
+13
View File
@@ -55,6 +55,13 @@ enum {
B_TRACK_RECT_CORNER B_TRACK_RECT_CORNER
}; };
// bitmap drawing options
enum {
B_FILTER_BITMAP_BILINEAR = 0x00000001,
// TODO: Make this simply "SMOOTH_SCALE" and use
// better quality methods the faster the computer?
};
// set font mask // set font mask
enum { enum {
B_FONT_FAMILY_AND_STYLE = 0x00000001, B_FONT_FAMILY_AND_STYLE = 0x00000001,
@@ -360,6 +367,9 @@ public:
void CopyBits(BRect src, BRect dst); void CopyBits(BRect src, BRect dst);
void DrawBitmapAsync(const BBitmap* aBitmap,
BRect bitmapRect, BRect viewRect,
uint32 options);
void DrawBitmapAsync(const BBitmap* aBitmap, void DrawBitmapAsync(const BBitmap* aBitmap,
BRect bitmapRect, BRect viewRect); BRect bitmapRect, BRect viewRect);
void DrawBitmapAsync(const BBitmap* aBitmap, void DrawBitmapAsync(const BBitmap* aBitmap,
@@ -368,6 +378,9 @@ public:
BPoint where); BPoint where);
void DrawBitmapAsync(const BBitmap* aBitmap); void DrawBitmapAsync(const BBitmap* aBitmap);
void DrawBitmap(const BBitmap* aBitmap,
BRect bitmapRect, BRect viewRect,
uint32 options);
void DrawBitmap(const BBitmap* aBitmap, void DrawBitmap(const BBitmap* aBitmap,
BRect bitmapRect, BRect viewRect); BRect bitmapRect, BRect viewRect);
void DrawBitmap(const BBitmap* aBitmap, void DrawBitmap(const BBitmap* aBitmap,
+35 -7
View File
@@ -2356,7 +2356,8 @@ BView::ConstrainClippingRegion(BRegion* region)
void void
BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect) BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect,
uint32 options)
{ {
if (bitmap == NULL || fOwner == NULL if (bitmap == NULL || fOwner == NULL
|| !bitmapRect.IsValid() || !viewRect.IsValid()) || !bitmapRect.IsValid() || !viewRect.IsValid())
@@ -2366,6 +2367,7 @@ BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect)
fOwner->fLink->StartMessage(AS_VIEW_DRAW_BITMAP); fOwner->fLink->StartMessage(AS_VIEW_DRAW_BITMAP);
fOwner->fLink->Attach<int32>(bitmap->_ServerToken()); fOwner->fLink->Attach<int32>(bitmap->_ServerToken());
fOwner->fLink->Attach<uint32>(options);
fOwner->fLink->Attach<BRect>(viewRect); fOwner->fLink->Attach<BRect>(viewRect);
fOwner->fLink->Attach<BRect>(bitmapRect); fOwner->fLink->Attach<BRect>(bitmapRect);
@@ -2374,16 +2376,19 @@ BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect)
void void
BView::DrawBitmapAsync(const BBitmap* bitmap, BRect viewRect) BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect)
{ {
DrawBitmapAsync(bitmap, bitmap->Bounds().OffsetToCopy(B_ORIGIN), viewRect); DrawBitmapAsync(bitmap, bitmapRect, viewRect, 0);
} }
void void
BView::DrawBitmapAsync(const BBitmap* bitmap) BView::DrawBitmapAsync(const BBitmap* bitmap, BRect viewRect)
{ {
DrawBitmapAsync(bitmap, PenLocation()); if (bitmap && fOwner) {
DrawBitmapAsync(bitmap, bitmap->Bounds().OffsetToCopy(B_ORIGIN),
viewRect, 0);
}
} }
@@ -2397,9 +2402,11 @@ BView::DrawBitmapAsync(const BBitmap* bitmap, BPoint where)
BRect bitmapRect = bitmap->Bounds().OffsetToCopy(B_ORIGIN); BRect bitmapRect = bitmap->Bounds().OffsetToCopy(B_ORIGIN);
BRect viewRect = bitmapRect.OffsetToCopy(where); BRect viewRect = bitmapRect.OffsetToCopy(where);
uint32 options = 0;
fOwner->fLink->StartMessage(AS_VIEW_DRAW_BITMAP); fOwner->fLink->StartMessage(AS_VIEW_DRAW_BITMAP);
fOwner->fLink->Attach<int32>(bitmap->_ServerToken()); fOwner->fLink->Attach<int32>(bitmap->_ServerToken());
fOwner->fLink->Attach<uint32>(options);
fOwner->fLink->Attach<BRect>(viewRect); fOwner->fLink->Attach<BRect>(viewRect);
fOwner->fLink->Attach<BRect>(bitmapRect); fOwner->fLink->Attach<BRect>(bitmapRect);
@@ -2407,11 +2414,29 @@ BView::DrawBitmapAsync(const BBitmap* bitmap, BPoint where)
} }
void
BView::DrawBitmapAsync(const BBitmap* bitmap)
{
DrawBitmapAsync(bitmap, PenLocation());
}
void
BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect,
uint32 options)
{
if (fOwner) {
DrawBitmapAsync(bitmap, bitmapRect, viewRect, options);
Sync();
}
}
void void
BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect) BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect)
{ {
if (fOwner) { if (fOwner) {
DrawBitmapAsync(bitmap, bitmapRect, viewRect); DrawBitmapAsync(bitmap, bitmapRect, viewRect, 0);
Sync(); Sync();
} }
} }
@@ -2420,7 +2445,10 @@ BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect)
void void
BView::DrawBitmap(const BBitmap* bitmap, BRect viewRect) BView::DrawBitmap(const BBitmap* bitmap, BRect viewRect)
{ {
DrawBitmap(bitmap, bitmap->Bounds().OffsetToCopy(B_ORIGIN), viewRect); if (bitmap && fOwner) {
DrawBitmap(bitmap, bitmap->Bounds().OffsetToCopy(B_ORIGIN), viewRect,
0);
}
} }
+4 -3
View File
@@ -411,10 +411,10 @@ draw_string(View *view, const char *string, float deltaSpace,
static void static void
draw_pixels(View *view, BRect src, BRect dest, int32 width, int32 height, draw_pixels(View *view, BRect src, BRect dest, int32 width, int32 height,
int32 bytesPerRow, int32 pixelFormat, int32 flags, const void *data) int32 bytesPerRow, int32 pixelFormat, int32 options, const void *data)
{ {
UtilityBitmap bitmap(BRect(0, 0, width - 1, height - 1), UtilityBitmap bitmap(BRect(0, 0, width - 1, height - 1),
(color_space)pixelFormat, flags, bytesPerRow); (color_space)pixelFormat, 0, bytesPerRow);
if (!bitmap.IsValid()) if (!bitmap.IsValid())
return; return;
@@ -423,7 +423,8 @@ draw_pixels(View *view, BRect src, BRect dest, int32 width, int32 height,
view->ConvertToScreenForDrawing(&dest); view->ConvertToScreenForDrawing(&dest);
view->Window()->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest); view->Window()->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest,
options);
} }
+19 -12
View File
@@ -2105,17 +2105,21 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li
{ {
DTRACE(("ServerWindow %s: Message AS_VIEW_DRAW_BITMAP: View name: %s\n", fTitle, fCurrentView->Name())); DTRACE(("ServerWindow %s: Message AS_VIEW_DRAW_BITMAP: View name: %s\n", fTitle, fCurrentView->Name()));
int32 bitmapToken; int32 bitmapToken;
BRect srcRect, dstRect; uint32 options;
BRect bitmapRect;
BRect viewRect;
link.Read<int32>(&bitmapToken); link.Read<int32>(&bitmapToken);
link.Read<BRect>(&dstRect); link.Read<uint32>(&options);
link.Read<BRect>(&srcRect); link.Read<BRect>(&viewRect);
link.Read<BRect>(&bitmapRect);
ServerBitmap* bitmap = fServerApp->FindBitmap(bitmapToken); ServerBitmap* bitmap = fServerApp->FindBitmap(bitmapToken);
if (bitmap) { if (bitmap) {
fCurrentView->ConvertToScreenForDrawing(&dstRect); fCurrentView->ConvertToScreenForDrawing(&viewRect);
drawingEngine->DrawBitmap(bitmap, srcRect, dstRect); drawingEngine->DrawBitmap(bitmap, bitmapRect, viewRect,
options);
} }
break; break;
@@ -2689,19 +2693,22 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver &link)
int32 token; int32 token;
link.Read<int32>(&token); link.Read<int32>(&token);
BRect destRect; uint32 options;
link.Read<BRect>(&destRect); link.Read<uint32>(&options);
BRect sourceRect; BRect viewRect;
link.Read<BRect>(&sourceRect); link.Read<BRect>(&viewRect);
BRect bitmapRect;
link.Read<BRect>(&bitmapRect);
ServerBitmap *bitmap = App()->FindBitmap(token); ServerBitmap *bitmap = App()->FindBitmap(token);
if (bitmap == NULL) if (bitmap == NULL)
break; break;
picture->WriteDrawBitmap(sourceRect, destRect, bitmap->Width(), bitmap->Height(), picture->WriteDrawBitmap(bitmapRect, viewRect, bitmap->Width(),
bitmap->BytesPerRow(), bitmap->ColorSpace(), /*bitmap->Flags()*/0, bitmap->Height(), bitmap->BytesPerRow(), bitmap->ColorSpace(),
bitmap->Bits(), bitmap->BitsLength()); options, bitmap->Bits(), bitmap->BitsLength());
break; break;
} }
+11 -11
View File
@@ -563,16 +563,16 @@ DrawingEngine::InvertRect(BRect r)
// DrawBitmap // DrawBitmap
void void
DrawingEngine::DrawBitmap(ServerBitmap *bitmap, DrawingEngine::DrawBitmap(ServerBitmap* bitmap, const BRect& bitmapRect,
const BRect &source, const BRect &dest) const BRect& viewRect, uint32 options)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
BRect clipped = fPainter->ClipRect(dest); BRect clipped = fPainter->ClipRect(viewRect);
if (clipped.IsValid()) { if (clipped.IsValid()) {
AutoFloatingOverlaysHider _(fGraphicsCard, clipped); AutoFloatingOverlaysHider _(fGraphicsCard, clipped);
fPainter->DrawBitmap(bitmap, source, dest); fPainter->DrawBitmap(bitmap, bitmapRect, viewRect, options);
_CopyToFront(clipped); _CopyToFront(clipped);
} }
@@ -580,7 +580,7 @@ DrawingEngine::DrawBitmap(ServerBitmap *bitmap,
// DrawArc // DrawArc
void void
DrawingEngine::DrawArc(BRect r, const float &angle, const float &span, DrawingEngine::DrawArc(BRect r, const float& angle, const float& span,
bool filled) bool filled)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
@@ -613,7 +613,7 @@ DrawingEngine::DrawArc(BRect r, const float &angle, const float &span,
// DrawBezier // DrawBezier
void void
DrawingEngine::DrawBezier(BPoint *pts, bool filled) DrawingEngine::DrawBezier(BPoint* pts, bool filled)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
@@ -656,8 +656,8 @@ DrawingEngine::DrawEllipse(BRect r, bool filled)
// DrawPolygon // DrawPolygon
void void
DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds,
BRect bounds, bool filled, bool closed) bool filled, bool closed)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
@@ -677,7 +677,7 @@ DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts,
// #pragma mark - rgb_color // #pragma mark - rgb_color
void void
DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color &color) DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color& color)
{ {
StrokeLine(pt, pt, color); StrokeLine(pt, pt, color);
} }
@@ -687,8 +687,8 @@ DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color &color)
// * this function is only used by Decorators // * this function is only used by Decorators
// * it assumes a one pixel wide line // * it assumes a one pixel wide line
void void
DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end, DrawingEngine::StrokeLine(const BPoint& start, const BPoint& end,
const rgb_color &color) const rgb_color& color)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
+7 -6
View File
@@ -93,18 +93,19 @@ public:
void InvertRect(BRect r); void InvertRect(BRect r);
void DrawBitmap(ServerBitmap *bitmap, void DrawBitmap(ServerBitmap* bitmap,
const BRect &source, const BRect &dest); const BRect& bitmapRect, const BRect& viewRect,
uint32 options = 0);
// drawing primitives // drawing primitives
void DrawArc(BRect r, const float &angle, void DrawArc(BRect r, const float& angle,
const float &span, bool filled); const float& span, bool filled);
void DrawBezier(BPoint *pts, bool filled); void DrawBezier(BPoint* pts, bool filled);
void DrawEllipse(BRect r, bool filled); void DrawEllipse(BRect r, bool filled);
void DrawPolygon(BPoint *ptlist, int32 numpts, void DrawPolygon(BPoint* ptlist, int32 numpts,
BRect bounds, bool filled, bool closed); BRect bounds, bool filled, bool closed);
// these rgb_color versions are used internally by the server // these rgb_color versions are used internally by the server
+41 -44
View File
@@ -37,6 +37,8 @@
#include "DrawState.h" #include "DrawState.h"
#include <AutoDeleter.h> #include <AutoDeleter.h>
#include <View.h>
#include "DrawingMode.h" #include "DrawingMode.h"
#include "PatternHandler.h" #include "PatternHandler.h"
#include "RenderingBuffer.h" #include "RenderingBuffer.h"
@@ -951,8 +953,8 @@ Painter::DrawEllipse(BRect r, bool fill) const
// StrokeArc // StrokeArc
BRect BRect
Painter::StrokeArc(BPoint center, float xRadius, float yRadius, Painter::StrokeArc(BPoint center, float xRadius, float yRadius, float angle,
float angle, float span) const float span) const
{ {
CHECK_CLIPPING CHECK_CLIPPING
@@ -971,8 +973,8 @@ Painter::StrokeArc(BPoint center, float xRadius, float yRadius,
// FillArc // FillArc
BRect BRect
Painter::FillArc(BPoint center, float xRadius, float yRadius, Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
float angle, float span) const float span) const
{ {
CHECK_CLIPPING CHECK_CLIPPING
@@ -1009,9 +1011,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius,
// DrawString // DrawString
BRect BRect
Painter::DrawString(const char* utf8String, uint32 length, Painter::DrawString(const char* utf8String, uint32 length, BPoint baseLine,
BPoint baseLine, const escapement_delta* delta, const escapement_delta* delta, FontCacheReference* cacheReference)
FontCacheReference* cacheReference)
{ {
CHECK_CLIPPING CHECK_CLIPPING
@@ -1038,10 +1039,9 @@ Painter::DrawString(const char* utf8String, uint32 length,
// BoundingBox // BoundingBox
BRect BRect
Painter::BoundingBox(const char* utf8String, uint32 length, Painter::BoundingBox(const char* utf8String, uint32 length, BPoint baseLine,
BPoint baseLine, BPoint* penLocation, BPoint* penLocation, const escapement_delta* delta,
const escapement_delta* delta, FontCacheReference* cacheReference) const
FontCacheReference* cacheReference) const
{ {
if (!fSubpixelPrecise) { if (!fSubpixelPrecise) {
baseLine.x = roundf(baseLine.x); baseLine.x = roundf(baseLine.x);
@@ -1065,8 +1065,8 @@ Painter::StringWidth(const char* utf8String, uint32 length,
// DrawBitmap // DrawBitmap
BRect BRect
Painter::DrawBitmap(const ServerBitmap* bitmap, Painter::DrawBitmap(const ServerBitmap* bitmap, BRect bitmapRect,
BRect bitmapRect, BRect viewRect) const BRect viewRect, uint32 options) const
{ {
CHECK_CLIPPING CHECK_CLIPPING
@@ -1087,13 +1087,11 @@ Painter::DrawBitmap(const ServerBitmap* bitmap,
viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); viewRect.left, viewRect.top, viewRect.right, viewRect.bottom);
agg::rendering_buffer srcBuffer; agg::rendering_buffer srcBuffer;
srcBuffer.attach(bitmap->Bits(), srcBuffer.attach(bitmap->Bits(), bitmap->Width(), bitmap->Height(),
bitmap->Width(), bitmap->BytesPerRow());
bitmap->Height(),
bitmap->BytesPerRow());
_DrawBitmap(srcBuffer, bitmap->ColorSpace(), actualBitmapRect, _DrawBitmap(srcBuffer, bitmap->ColorSpace(), actualBitmapRect,
bitmapRect, viewRect, bitmap->Flags()); bitmapRect, viewRect, options);
} }
return touched; return touched;
} }
@@ -1351,7 +1349,7 @@ Painter::_TransparentMagicToAlpha(sourcePixel* buffer, uint32 width,
void void
Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format, Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format,
BRect actualBitmapRect, BRect bitmapRect, BRect viewRect, BRect actualBitmapRect, BRect bitmapRect, BRect viewRect,
uint32 bitmapFlags) const uint32 options) const
{ {
if (!fValidClipping if (!fValidClipping
|| !bitmapRect.IsValid() || !bitmapRect.Intersects(actualBitmapRect) || !bitmapRect.IsValid() || !bitmapRect.Intersects(actualBitmapRect)
@@ -1513,7 +1511,7 @@ Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format,
} }
} }
if (fDrawingMode == B_OP_COPY && (bitmapFlags & B_BITMAP_SCALE_BILINEAR)) { if (fDrawingMode == B_OP_COPY && (options & B_FILTER_BITMAP_BILINEAR)) {
_DrawBitmapBilinearCopy32(srcBuffer, xOffset, yOffset, xScale, yScale, _DrawBitmapBilinearCopy32(srcBuffer, xOffset, yOffset, xScale, yScale,
viewRect); viewRect);
return; return;
@@ -1521,7 +1519,7 @@ Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format,
// for all other cases (non-optimized drawing mode or scaled drawing) // for all other cases (non-optimized drawing mode or scaled drawing)
_DrawBitmapGeneric32(srcBuffer, xOffset, yOffset, xScale, yScale, viewRect, _DrawBitmapGeneric32(srcBuffer, xOffset, yOffset, xScale, yScale, viewRect,
bitmapFlags); options);
} }
#define DEBUG_DRAW_BITMAP 0 #define DEBUG_DRAW_BITMAP 0
@@ -1530,9 +1528,8 @@ Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format,
template <class F> template <class F>
void void
Painter::_DrawBitmapNoScale32(F copyRowFunction, uint32 bytesPerSourcePixel, Painter::_DrawBitmapNoScale32(F copyRowFunction, uint32 bytesPerSourcePixel,
agg::rendering_buffer& srcBuffer, agg::rendering_buffer& srcBuffer, int32 xOffset, int32 yOffset,
int32 xOffset, int32 yOffset, BRect viewRect) const
BRect viewRect) const
{ {
// NOTE: this would crash if viewRect was large enough to read outside the // NOTE: this would crash if viewRect was large enough to read outside the
// bitmap, so make sure this is not the case before calling this function! // bitmap, so make sure this is not the case before calling this function!
@@ -1672,19 +1669,19 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer,
// yWeights[dstHeight - 1].index, yWeights[dstHeight - 1].weight, // yWeights[dstHeight - 1].index, yWeights[dstHeight - 1].weight,
// dstHeight); // dstHeight);
int32 left = (int32)viewRect.left; const int32 left = (int32)viewRect.left;
int32 top = (int32)viewRect.top; const int32 top = (int32)viewRect.top;
int32 right = (int32)viewRect.right; const int32 right = (int32)viewRect.right;
int32 bottom = (int32)viewRect.bottom; const int32 bottom = (int32)viewRect.bottom;
uint32 dstBPR = fBuffer.stride(); const uint32 dstBPR = fBuffer.stride();
uint32 srcBPR = srcBuffer.stride(); const uint32 srcBPR = srcBuffer.stride();
// iterate over clipping boxes // iterate over clipping boxes
fBaseRenderer.first_clip_box(); fBaseRenderer.first_clip_box();
do { do {
int32 x1 = max_c(fBaseRenderer.xmin(), left); const int32 x1 = max_c(fBaseRenderer.xmin(), left);
int32 x2 = min_c(fBaseRenderer.xmax(), right); const int32 x2 = min_c(fBaseRenderer.xmax(), right);
if (x1 > x2) if (x1 > x2)
continue; continue;
@@ -1698,8 +1695,8 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer,
// x and y are needed as indeces into the wheight arrays, so the // x and y are needed as indeces into the wheight arrays, so the
// offset into the target buffer needs to be compensated // offset into the target buffer needs to be compensated
int32 xIndexL = x1 - (int32)xOffset; const int32 xIndexL = x1 - (int32)xOffset;
int32 xIndexR = x2 - (int32)xOffset; const int32 xIndexR = x2 - (int32)xOffset;
y1 -= (int32)yOffset; y1 -= (int32)yOffset;
y2 -= (int32)yOffset; y2 -= (int32)yOffset;
@@ -1708,13 +1705,13 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer,
for (; y1 <= y2; y1++) { for (; y1 <= y2; y1++) {
// cache the weight of the top and bottom row // cache the weight of the top and bottom row
uint16 wTop = yWeights[y1].weight; const uint16 wTop = yWeights[y1].weight;
uint16 wBottom = 255 - yWeights[y1].weight; const uint16 wBottom = 255 - yWeights[y1].weight;
// buffer offset into source (top row) // buffer offset into source (top row)
const uint8* src = srcBuffer.row_ptr(yWeights[y1].index); register const uint8* src = srcBuffer.row_ptr(yWeights[y1].index);
// buffer handle for destination to be incremented per pixel // buffer handle for destination to be incremented per pixel
uint8* d = dst; register uint8* d = dst;
for (int32 x = xIndexL; x <= xIndexR; x++) { for (int32 x = xIndexL; x <= xIndexR; x++) {
const uint8* s = src + xWeights[x].index; const uint8* s = src + xWeights[x].index;
@@ -1730,8 +1727,8 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer,
} else { } else {
// Only the left and right pixels are interpolated, // Only the left and right pixels are interpolated,
// since the top row has 100% weight. // since the top row has 100% weight.
uint16 wLeft = xWeights[x].weight; const uint16 wLeft = xWeights[x].weight;
uint16 wRight = 255 - xWeights[x].weight; const uint16 wRight = 255 - wLeft;
d[0] = (s[0] * wLeft + s[4] * wRight) >> 8; d[0] = (s[0] * wLeft + s[4] * wRight) >> 8;
d[1] = (s[1] * wLeft + s[5] * wRight) >> 8; d[1] = (s[1] * wLeft + s[5] * wRight) >> 8;
d[2] = (s[2] * wLeft + s[6] * wRight) >> 8; d[2] = (s[2] * wLeft + s[6] * wRight) >> 8;
@@ -1747,8 +1744,8 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer,
} else { } else {
// calculate the weighted sum of all four interpolated // calculate the weighted sum of all four interpolated
// pixels // pixels
uint16 wLeft = xWeights[x].weight; const uint16 wLeft = xWeights[x].weight;
uint16 wRight = 255 - xWeights[x].weight; const uint16 wRight = 255 - wLeft;
// left and right of top row // left and right of top row
uint32 t0 = (s[0] * wLeft + s[4] * wRight) * wTop; uint32 t0 = (s[0] * wLeft + s[4] * wRight) * wTop;
uint32 t1 = (s[1] * wLeft + s[5] * wRight) * wTop; uint32 t1 = (s[1] * wLeft + s[5] * wRight) * wTop;
@@ -1782,7 +1779,7 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer,
void void
Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer, Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer,
double xOffset, double yOffset, double xScale, double yScale, double xOffset, double yOffset, double xScale, double yScale,
BRect viewRect, uint32 bitmapFlags) const BRect viewRect, uint32 options) const
{ {
TRACE("Painter::_DrawBitmapGeneric32()\n"); TRACE("Painter::_DrawBitmapGeneric32()\n");
TRACE(" offset: %.1f, %.1f\n", xOffset, yOffset); TRACE(" offset: %.1f, %.1f\n", xOffset, yOffset);
@@ -1836,7 +1833,7 @@ Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer,
fRasterizer.reset(); fRasterizer.reset();
fRasterizer.add_path(transformedPath); fRasterizer.add_path(transformedPath);
if ((bitmapFlags & B_BITMAP_SCALE_BILINEAR) != 0) { if ((options & B_FILTER_BITMAP_BILINEAR) != 0) {
// image filter (bilinear) // image filter (bilinear)
typedef agg::span_image_filter_rgba_bilinear< typedef agg::span_image_filter_rgba_bilinear<
source_type, interpolator_type> span_gen_type; source_type, interpolator_type> span_gen_type;
+2 -1
View File
@@ -189,7 +189,8 @@ class Painter {
// bitmaps // bitmaps
BRect DrawBitmap( const ServerBitmap* bitmap, BRect DrawBitmap( const ServerBitmap* bitmap,
BRect bitmapRect, BRect bitmapRect,
BRect viewRect) const; BRect viewRect,
uint32 options) const;
// some convenience stuff // some convenience stuff
BRect FillRegion( const BRegion* region) const; BRect FillRegion( const BRegion* region) const;