From 162a7f5f8e924eda0b7d7b99167882591926ad6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 28 Jul 2008 18:58:30 +0000 Subject: [PATCH] * 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 --- headers/os/interface/Bitmap.h | 173 +++++++++++--------- headers/os/interface/View.h | 13 ++ src/kits/interface/View.cpp | 42 ++++- src/servers/app/ServerPicture.cpp | 7 +- src/servers/app/ServerWindow.cpp | 33 ++-- src/servers/app/drawing/DrawingEngine.cpp | 22 +-- src/servers/app/drawing/DrawingEngine.h | 13 +- src/servers/app/drawing/Painter/Painter.cpp | 85 +++++----- src/servers/app/drawing/Painter/Painter.h | 3 +- 9 files changed, 228 insertions(+), 163 deletions(-) diff --git a/headers/os/interface/Bitmap.h b/headers/os/interface/Bitmap.h index d014231911..0e8d373de0 100644 --- a/headers/os/interface/Bitmap.h +++ b/headers/os/interface/Bitmap.h @@ -26,107 +26,124 @@ enum { B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, 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_RESERVE_OVERLAY_CHANNEL = 0x00000080, + // Haiku extensions: B_BITMAP_NO_SERVER_LINK = 0x00000100, - B_BITMAP_SCALE_BILINEAR = 0x00000200 - // TODO: Make this simply "SMOOTH_SCALE" and use - // better quality methods the faster the computer? + // Cheap to create, object will manage memory itself, + // no BApplication needs to run, but one can't draw such + // a BBitmap. }; #define B_ANY_BYTES_PER_ROW -1 class BBitmap : public BArchivable { - public: - BBitmap(BRect bounds, uint32 flags, color_space colorSpace, - int32 bytesPerRow = B_ANY_BYTES_PER_ROW, - screen_id screenID = B_MAIN_SCREEN_ID); - BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, - bool needsContiguous = false); - BBitmap(const BBitmap& source, uint32 flags); - BBitmap(const BBitmap& source); - BBitmap(const BBitmap *source, bool acceptsViews = false, - bool needsContiguous = false); - virtual ~BBitmap(); +public: + BBitmap(BRect bounds, uint32 flags, + color_space colorSpace, + int32 bytesPerRow = B_ANY_BYTES_PER_ROW, + screen_id screenID = B_MAIN_SCREEN_ID); + BBitmap(BRect bounds, color_space colorSpace, + bool acceptsViews = false, + bool needsContiguous = false); + BBitmap(const BBitmap& source, uint32 flags); + BBitmap(const BBitmap& source); + BBitmap(const BBitmap* source, + bool acceptsViews = false, + bool needsContiguous = false); + virtual ~BBitmap(); - // Archiving - BBitmap(BMessage *data); - static BArchivable *Instantiate(BMessage *data); - virtual status_t Archive(BMessage *data, bool deep = true) const; + // Archiving + BBitmap(BMessage* data); + static BArchivable* Instantiate(BMessage* data); + virtual status_t Archive(BMessage* data, bool deep = true) const; - status_t InitCheck() const; - bool IsValid() const; + status_t InitCheck() const; + bool IsValid() const; - status_t LockBits(uint32 *state = NULL); - void UnlockBits(); + status_t LockBits(uint32* state = NULL); + void UnlockBits(); - area_id Area() const; - void *Bits() const; - int32 BitsLength() const; - int32 BytesPerRow() const; - color_space ColorSpace() const; - BRect Bounds() const; - uint32 Flags() const; + area_id Area() const; + void* Bits() const; + int32 BitsLength() const; + int32 BytesPerRow() const; + color_space ColorSpace() const; + BRect Bounds() const; - void SetBits(const void *data, int32 length, int32 offset, - color_space colorSpace); + status_t SetDrawingFlags(uint32 flags); + uint32 Flags() 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); + void SetBits(const void* data, int32 length, + int32 offset, color_space colorSpace); - 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 - 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; + status_t GetOverlayRestrictions( + overlay_restrictions* restrictions) 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: - friend class BView; - friend class BApplication; - friend class BPrivate::BPrivateScreen; + BBitmap& operator=(const BBitmap& source); - virtual status_t Perform(perform_code d, void *arg); - virtual void _ReservedBitmap1(); - virtual void _ReservedBitmap2(); - virtual void _ReservedBitmap3(); +private: + friend class BView; + friend class BApplication; + friend class BPrivate::BPrivateScreen; - int32 _ServerToken() const; - void _InitObject(BRect bounds, color_space colorSpace, uint32 flags, - int32 bytesPerRow, screen_id screenID); - void _CleanUp(); - void _AssertPointer(); + virtual status_t Perform(perform_code d, void* arg); + virtual void _ReservedBitmap1(); + virtual void _ReservedBitmap2(); + virtual void _ReservedBitmap3(); - uint8 *fBasePointer; - int32 fSize; - color_space fColorSpace; - BRect fBounds; - int32 fBytesPerRow; - BWindow *fWindow; - int32 fServerToken; - int32 fAreaOffset; - uint8 unused; - area_id fArea; - area_id fServerArea; - uint32 fFlags; - status_t fInitError; + int32 _ServerToken() const; + void _InitObject(BRect bounds, + color_space colorSpace, uint32 flags, + int32 bytesPerRow, screen_id screenID); + void _CleanUp(); + void _AssertPointer(); + +private: + uint8* fBasePointer; + int32 fSize; + color_space fColorSpace; + BRect fBounds; + int32 fBytesPerRow; + BWindow* fWindow; + int32 fServerToken; + int32 fAreaOffset; + uint8 unused; + area_id fArea; + area_id fServerArea; + uint32 fFlags; + status_t fInitError; }; #endif // _BITMAP_H diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index 48ae7c9187..2f88339b8e 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -55,6 +55,13 @@ enum { 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 enum { B_FONT_FAMILY_AND_STYLE = 0x00000001, @@ -360,6 +367,9 @@ public: void CopyBits(BRect src, BRect dst); + void DrawBitmapAsync(const BBitmap* aBitmap, + BRect bitmapRect, BRect viewRect, + uint32 options); void DrawBitmapAsync(const BBitmap* aBitmap, BRect bitmapRect, BRect viewRect); void DrawBitmapAsync(const BBitmap* aBitmap, @@ -368,6 +378,9 @@ public: BPoint where); void DrawBitmapAsync(const BBitmap* aBitmap); + void DrawBitmap(const BBitmap* aBitmap, + BRect bitmapRect, BRect viewRect, + uint32 options); void DrawBitmap(const BBitmap* aBitmap, BRect bitmapRect, BRect viewRect); void DrawBitmap(const BBitmap* aBitmap, diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 7a66dd2e74..dc081c4a5f 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -2356,7 +2356,8 @@ BView::ConstrainClippingRegion(BRegion* region) 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 || !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->Attach(bitmap->_ServerToken()); + fOwner->fLink->Attach(options); fOwner->fLink->Attach(viewRect); fOwner->fLink->Attach(bitmapRect); @@ -2374,16 +2376,19 @@ BView::DrawBitmapAsync(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect) 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 -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 viewRect = bitmapRect.OffsetToCopy(where); + uint32 options = 0; fOwner->fLink->StartMessage(AS_VIEW_DRAW_BITMAP); fOwner->fLink->Attach(bitmap->_ServerToken()); + fOwner->fLink->Attach(options); fOwner->fLink->Attach(viewRect); fOwner->fLink->Attach(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 BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect) { if (fOwner) { - DrawBitmapAsync(bitmap, bitmapRect, viewRect); + DrawBitmapAsync(bitmap, bitmapRect, viewRect, 0); Sync(); } } @@ -2420,7 +2445,10 @@ BView::DrawBitmap(const BBitmap* bitmap, BRect bitmapRect, BRect viewRect) void 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); + } } diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 2ec9c0f86b..8197840da2 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -411,10 +411,10 @@ draw_string(View *view, const char *string, float deltaSpace, static void 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), - (color_space)pixelFormat, flags, bytesPerRow); + (color_space)pixelFormat, 0, bytesPerRow); if (!bitmap.IsValid()) return; @@ -423,7 +423,8 @@ draw_pixels(View *view, BRect src, BRect dest, int32 width, int32 height, view->ConvertToScreenForDrawing(&dest); - view->Window()->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest); + view->Window()->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest, + options); } diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 1adea2f396..9dafbb4328 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -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())); int32 bitmapToken; - BRect srcRect, dstRect; + uint32 options; + BRect bitmapRect; + BRect viewRect; link.Read(&bitmapToken); - link.Read(&dstRect); - link.Read(&srcRect); + link.Read(&options); + link.Read(&viewRect); + link.Read(&bitmapRect); ServerBitmap* bitmap = fServerApp->FindBitmap(bitmapToken); if (bitmap) { - fCurrentView->ConvertToScreenForDrawing(&dstRect); + fCurrentView->ConvertToScreenForDrawing(&viewRect); - drawingEngine->DrawBitmap(bitmap, srcRect, dstRect); + drawingEngine->DrawBitmap(bitmap, bitmapRect, viewRect, + options); } break; @@ -2688,20 +2692,23 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver &link) { int32 token; link.Read(&token); + + uint32 options; + link.Read(&options); + + BRect viewRect; + link.Read(&viewRect); - BRect destRect; - link.Read(&destRect); - - BRect sourceRect; - link.Read(&sourceRect); + BRect bitmapRect; + link.Read(&bitmapRect); ServerBitmap *bitmap = App()->FindBitmap(token); if (bitmap == NULL) break; - picture->WriteDrawBitmap(sourceRect, destRect, bitmap->Width(), bitmap->Height(), - bitmap->BytesPerRow(), bitmap->ColorSpace(), /*bitmap->Flags()*/0, - bitmap->Bits(), bitmap->BitsLength()); + picture->WriteDrawBitmap(bitmapRect, viewRect, bitmap->Width(), + bitmap->Height(), bitmap->BytesPerRow(), bitmap->ColorSpace(), + options, bitmap->Bits(), bitmap->BitsLength()); break; } diff --git a/src/servers/app/drawing/DrawingEngine.cpp b/src/servers/app/drawing/DrawingEngine.cpp index 0a520694e6..51105b8908 100644 --- a/src/servers/app/drawing/DrawingEngine.cpp +++ b/src/servers/app/drawing/DrawingEngine.cpp @@ -563,16 +563,16 @@ DrawingEngine::InvertRect(BRect r) // DrawBitmap void -DrawingEngine::DrawBitmap(ServerBitmap *bitmap, - const BRect &source, const BRect &dest) +DrawingEngine::DrawBitmap(ServerBitmap* bitmap, const BRect& bitmapRect, + const BRect& viewRect, uint32 options) { CRASH_IF_NOT_LOCKED - BRect clipped = fPainter->ClipRect(dest); + BRect clipped = fPainter->ClipRect(viewRect); if (clipped.IsValid()) { AutoFloatingOverlaysHider _(fGraphicsCard, clipped); - fPainter->DrawBitmap(bitmap, source, dest); + fPainter->DrawBitmap(bitmap, bitmapRect, viewRect, options); _CopyToFront(clipped); } @@ -580,7 +580,7 @@ DrawingEngine::DrawBitmap(ServerBitmap *bitmap, // DrawArc void -DrawingEngine::DrawArc(BRect r, const float &angle, const float &span, +DrawingEngine::DrawArc(BRect r, const float& angle, const float& span, bool filled) { CRASH_IF_NOT_LOCKED @@ -613,7 +613,7 @@ DrawingEngine::DrawArc(BRect r, const float &angle, const float &span, // DrawBezier void -DrawingEngine::DrawBezier(BPoint *pts, bool filled) +DrawingEngine::DrawBezier(BPoint* pts, bool filled) { CRASH_IF_NOT_LOCKED @@ -656,8 +656,8 @@ DrawingEngine::DrawEllipse(BRect r, bool filled) // DrawPolygon void -DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, - BRect bounds, bool filled, bool closed) +DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds, + bool filled, bool closed) { CRASH_IF_NOT_LOCKED @@ -677,7 +677,7 @@ DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, // #pragma mark - rgb_color void -DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color &color) +DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color& 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 // * it assumes a one pixel wide line void -DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end, - const rgb_color &color) +DrawingEngine::StrokeLine(const BPoint& start, const BPoint& end, + const rgb_color& color) { CRASH_IF_NOT_LOCKED diff --git a/src/servers/app/drawing/DrawingEngine.h b/src/servers/app/drawing/DrawingEngine.h index d3a59c27ed..479d7491f4 100644 --- a/src/servers/app/drawing/DrawingEngine.h +++ b/src/servers/app/drawing/DrawingEngine.h @@ -93,18 +93,19 @@ public: void InvertRect(BRect r); - void DrawBitmap(ServerBitmap *bitmap, - const BRect &source, const BRect &dest); + void DrawBitmap(ServerBitmap* bitmap, + const BRect& bitmapRect, const BRect& viewRect, + uint32 options = 0); // drawing primitives - void DrawArc(BRect r, const float &angle, - const float &span, bool filled); + void DrawArc(BRect r, const float& angle, + const float& span, bool filled); - void DrawBezier(BPoint *pts, bool filled); + void DrawBezier(BPoint* pts, 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); // these rgb_color versions are used internally by the server diff --git a/src/servers/app/drawing/Painter/Painter.cpp b/src/servers/app/drawing/Painter/Painter.cpp index f3256fa8c6..7455f6d69e 100644 --- a/src/servers/app/drawing/Painter/Painter.cpp +++ b/src/servers/app/drawing/Painter/Painter.cpp @@ -37,6 +37,8 @@ #include "DrawState.h" #include +#include + #include "DrawingMode.h" #include "PatternHandler.h" #include "RenderingBuffer.h" @@ -951,8 +953,8 @@ Painter::DrawEllipse(BRect r, bool fill) const // StrokeArc BRect -Painter::StrokeArc(BPoint center, float xRadius, float yRadius, - float angle, float span) const +Painter::StrokeArc(BPoint center, float xRadius, float yRadius, float angle, + float span) const { CHECK_CLIPPING @@ -971,8 +973,8 @@ Painter::StrokeArc(BPoint center, float xRadius, float yRadius, // FillArc BRect -Painter::FillArc(BPoint center, float xRadius, float yRadius, - float angle, float span) const +Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle, + float span) const { CHECK_CLIPPING @@ -1009,9 +1011,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, // DrawString BRect -Painter::DrawString(const char* utf8String, uint32 length, - BPoint baseLine, const escapement_delta* delta, - FontCacheReference* cacheReference) +Painter::DrawString(const char* utf8String, uint32 length, BPoint baseLine, + const escapement_delta* delta, FontCacheReference* cacheReference) { CHECK_CLIPPING @@ -1038,10 +1039,9 @@ Painter::DrawString(const char* utf8String, uint32 length, // BoundingBox BRect -Painter::BoundingBox(const char* utf8String, uint32 length, - BPoint baseLine, BPoint* penLocation, - const escapement_delta* delta, - FontCacheReference* cacheReference) const +Painter::BoundingBox(const char* utf8String, uint32 length, BPoint baseLine, + BPoint* penLocation, const escapement_delta* delta, + FontCacheReference* cacheReference) const { if (!fSubpixelPrecise) { baseLine.x = roundf(baseLine.x); @@ -1065,8 +1065,8 @@ Painter::StringWidth(const char* utf8String, uint32 length, // DrawBitmap BRect -Painter::DrawBitmap(const ServerBitmap* bitmap, - BRect bitmapRect, BRect viewRect) const +Painter::DrawBitmap(const ServerBitmap* bitmap, BRect bitmapRect, + BRect viewRect, uint32 options) const { CHECK_CLIPPING @@ -1087,13 +1087,11 @@ Painter::DrawBitmap(const ServerBitmap* bitmap, viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); agg::rendering_buffer srcBuffer; - srcBuffer.attach(bitmap->Bits(), - bitmap->Width(), - bitmap->Height(), - bitmap->BytesPerRow()); + srcBuffer.attach(bitmap->Bits(), bitmap->Width(), bitmap->Height(), + bitmap->BytesPerRow()); _DrawBitmap(srcBuffer, bitmap->ColorSpace(), actualBitmapRect, - bitmapRect, viewRect, bitmap->Flags()); + bitmapRect, viewRect, options); } return touched; } @@ -1351,7 +1349,7 @@ Painter::_TransparentMagicToAlpha(sourcePixel* buffer, uint32 width, void Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format, BRect actualBitmapRect, BRect bitmapRect, BRect viewRect, - uint32 bitmapFlags) const + uint32 options) const { if (!fValidClipping || !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, viewRect); 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) _DrawBitmapGeneric32(srcBuffer, xOffset, yOffset, xScale, yScale, viewRect, - bitmapFlags); + options); } #define DEBUG_DRAW_BITMAP 0 @@ -1530,9 +1528,8 @@ Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format, template void Painter::_DrawBitmapNoScale32(F copyRowFunction, uint32 bytesPerSourcePixel, - agg::rendering_buffer& srcBuffer, - int32 xOffset, int32 yOffset, - BRect viewRect) const + agg::rendering_buffer& srcBuffer, int32 xOffset, int32 yOffset, + BRect viewRect) const { // 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! @@ -1672,19 +1669,19 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer, // yWeights[dstHeight - 1].index, yWeights[dstHeight - 1].weight, // dstHeight); - int32 left = (int32)viewRect.left; - int32 top = (int32)viewRect.top; - int32 right = (int32)viewRect.right; - int32 bottom = (int32)viewRect.bottom; + const int32 left = (int32)viewRect.left; + const int32 top = (int32)viewRect.top; + const int32 right = (int32)viewRect.right; + const int32 bottom = (int32)viewRect.bottom; - uint32 dstBPR = fBuffer.stride(); - uint32 srcBPR = srcBuffer.stride(); + const uint32 dstBPR = fBuffer.stride(); + const uint32 srcBPR = srcBuffer.stride(); // iterate over clipping boxes fBaseRenderer.first_clip_box(); do { - int32 x1 = max_c(fBaseRenderer.xmin(), left); - int32 x2 = min_c(fBaseRenderer.xmax(), right); + const int32 x1 = max_c(fBaseRenderer.xmin(), left); + const int32 x2 = min_c(fBaseRenderer.xmax(), right); if (x1 > x2) continue; @@ -1698,8 +1695,8 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer, // x and y are needed as indeces into the wheight arrays, so the // offset into the target buffer needs to be compensated - int32 xIndexL = x1 - (int32)xOffset; - int32 xIndexR = x2 - (int32)xOffset; + const int32 xIndexL = x1 - (int32)xOffset; + const int32 xIndexR = x2 - (int32)xOffset; y1 -= (int32)yOffset; y2 -= (int32)yOffset; @@ -1708,13 +1705,13 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer, for (; y1 <= y2; y1++) { // cache the weight of the top and bottom row - uint16 wTop = yWeights[y1].weight; - uint16 wBottom = 255 - yWeights[y1].weight; + const uint16 wTop = yWeights[y1].weight; + const uint16 wBottom = 255 - yWeights[y1].weight; // 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 - uint8* d = dst; + register uint8* d = dst; for (int32 x = xIndexL; x <= xIndexR; x++) { const uint8* s = src + xWeights[x].index; @@ -1730,8 +1727,8 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer, } else { // Only the left and right pixels are interpolated, // since the top row has 100% weight. - uint16 wLeft = xWeights[x].weight; - uint16 wRight = 255 - xWeights[x].weight; + const uint16 wLeft = xWeights[x].weight; + const uint16 wRight = 255 - wLeft; d[0] = (s[0] * wLeft + s[4] * wRight) >> 8; d[1] = (s[1] * wLeft + s[5] * wRight) >> 8; d[2] = (s[2] * wLeft + s[6] * wRight) >> 8; @@ -1747,8 +1744,8 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer, } else { // calculate the weighted sum of all four interpolated // pixels - uint16 wLeft = xWeights[x].weight; - uint16 wRight = 255 - xWeights[x].weight; + const uint16 wLeft = xWeights[x].weight; + const uint16 wRight = 255 - wLeft; // left and right of top row uint32 t0 = (s[0] * wLeft + s[4] * wRight) * wTop; uint32 t1 = (s[1] * wLeft + s[5] * wRight) * wTop; @@ -1782,7 +1779,7 @@ Painter::_DrawBitmapBilinearCopy32(agg::rendering_buffer& srcBuffer, void Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer, double xOffset, double yOffset, double xScale, double yScale, - BRect viewRect, uint32 bitmapFlags) const + BRect viewRect, uint32 options) const { TRACE("Painter::_DrawBitmapGeneric32()\n"); TRACE(" offset: %.1f, %.1f\n", xOffset, yOffset); @@ -1836,7 +1833,7 @@ Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer, fRasterizer.reset(); fRasterizer.add_path(transformedPath); - if ((bitmapFlags & B_BITMAP_SCALE_BILINEAR) != 0) { + if ((options & B_FILTER_BITMAP_BILINEAR) != 0) { // image filter (bilinear) typedef agg::span_image_filter_rgba_bilinear< source_type, interpolator_type> span_gen_type; diff --git a/src/servers/app/drawing/Painter/Painter.h b/src/servers/app/drawing/Painter/Painter.h index 40e36779b7..00a39dbc9e 100644 --- a/src/servers/app/drawing/Painter/Painter.h +++ b/src/servers/app/drawing/Painter/Painter.h @@ -189,7 +189,8 @@ class Painter { // bitmaps BRect DrawBitmap( const ServerBitmap* bitmap, BRect bitmapRect, - BRect viewRect) const; + BRect viewRect, + uint32 options) const; // some convenience stuff BRect FillRegion( const BRegion* region) const;