PicturePlayer: use BStackOrHeapArray
Change-Id: I7908d8304276d14782bde5c2b8c089f3ca0138e2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2894 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
#include <PictureProtocol.h>
|
#include <PictureProtocol.h>
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
|
|
||||||
|
#include <StackOrHeapArray.h>
|
||||||
|
|
||||||
|
|
||||||
using BPrivate::PicturePlayer;
|
using BPrivate::PicturePlayer;
|
||||||
|
|
||||||
@@ -116,24 +118,15 @@ draw_polygon(void* _context, size_t numPoints, const BPoint _points[],
|
|||||||
{
|
{
|
||||||
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
|
||||||
// This is rather ugly but works for such a trivial class.
|
BStackOrHeapArray<BPoint, 200> points(numPoints);
|
||||||
const size_t kMaxStackCount = 200;
|
if (!points.IsValid())
|
||||||
char stackData[kMaxStackCount * sizeof(BPoint)];
|
return;
|
||||||
BPoint* points = (BPoint*)stackData;
|
|
||||||
if (numPoints > kMaxStackCount) {
|
|
||||||
points = (BPoint*)malloc(numPoints * sizeof(BPoint));
|
|
||||||
if (points == NULL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy((void*)points, _points, numPoints * sizeof(BPoint));
|
memcpy((void*)points, _points, numPoints * sizeof(BPoint));
|
||||||
|
|
||||||
((void (*)(void*, int32, BPoint*, bool))
|
((void (*)(void*, int32, BPoint*, bool))
|
||||||
context->function_table[fill ? 14 : 13])(context->user_data, numPoints,
|
context->function_table[fill ? 14 : 13])(context->user_data, numPoints,
|
||||||
points, isClosed);
|
points, isClosed);
|
||||||
|
|
||||||
if (numPoints > kMaxStackCount)
|
|
||||||
free(points);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -196,22 +189,14 @@ set_clipping_rects(void* _context, size_t numRects, const BRect _rects[])
|
|||||||
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
|
||||||
// This is rather ugly but works for such a trivial class.
|
// This is rather ugly but works for such a trivial class.
|
||||||
const size_t kMaxStackCount = 100;
|
BStackOrHeapArray<BRect, 100> rects(numRects);
|
||||||
char stackData[kMaxStackCount * sizeof(BRect)];
|
if (!rects.IsValid())
|
||||||
BRect* rects = (BRect*)stackData;
|
return;
|
||||||
if (numRects > kMaxStackCount) {
|
|
||||||
rects = (BRect*)malloc(numRects * sizeof(BRect));
|
|
||||||
if (rects == NULL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy((void*)rects, _rects, numRects * sizeof(BRect));
|
memcpy((void*)rects, _rects, numRects * sizeof(BRect));
|
||||||
|
|
||||||
((void (*)(void*, BRect*, uint32))context->function_table[20])(
|
((void (*)(void*, BRect*, uint32))context->function_table[20])(
|
||||||
context->user_data, rects, numRects);
|
context->user_data, rects, numRects);
|
||||||
|
|
||||||
if (numRects > kMaxStackCount)
|
|
||||||
free(rects);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user