Skip to content

Commit bebb263

Browse files
Merge pull request #30191 from QuLogic/simplify-marker
Simplify RendererAgg::draw_markers buffers
2 parents 5539d12 + f5851da commit bebb263

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

src/_backend_agg.h

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cmath>
1212
#include <algorithm>
1313
#include <functional>
14+
#include <vector>
1415

1516
#include "agg_alpha_mask_u8.h"
1617
#include "agg_conv_curve.h"
@@ -102,8 +103,6 @@ class BufferRegion
102103
int stride;
103104
};
104105

105-
#define MARKER_CACHE_SIZE 512
106-
107106
// the renderer
108107
class RendererAgg
109108
{
@@ -539,22 +538,14 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
539538
rendererBase.reset_clipping(true);
540539
agg::rect_i marker_size(0x7FFFFFFF, 0x7FFFFFFF, -0x7FFFFFFF, -0x7FFFFFFF);
541540

542-
agg::int8u staticFillCache[MARKER_CACHE_SIZE];
543-
agg::int8u staticStrokeCache[MARKER_CACHE_SIZE];
544-
agg::int8u *fillCache = staticFillCache;
545-
agg::int8u *strokeCache = staticStrokeCache;
546-
547541
try
548542
{
549-
unsigned fillSize = 0;
543+
std::vector<agg::int8u> fillBuffer;
550544
if (face.first) {
551545
theRasterizer.add_path(marker_path_curve);
552546
agg::render_scanlines(theRasterizer, slineP8, scanlines);
553-
fillSize = scanlines.byte_size();
554-
if (fillSize >= MARKER_CACHE_SIZE) {
555-
fillCache = new agg::int8u[fillSize];
556-
}
557-
scanlines.serialize(fillCache);
547+
fillBuffer.resize(scanlines.byte_size());
548+
scanlines.serialize(fillBuffer.data());
558549
marker_size = agg::rect_i(scanlines.min_x(),
559550
scanlines.min_y(),
560551
scanlines.max_x(),
@@ -569,11 +560,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
569560
theRasterizer.reset();
570561
theRasterizer.add_path(stroke);
571562
agg::render_scanlines(theRasterizer, slineP8, scanlines);
572-
unsigned strokeSize = scanlines.byte_size();
573-
if (strokeSize >= MARKER_CACHE_SIZE) {
574-
strokeCache = new agg::int8u[strokeSize];
575-
}
576-
scanlines.serialize(strokeCache);
563+
std::vector<agg::int8u> strokeBuffer(scanlines.byte_size());
564+
scanlines.serialize(strokeBuffer.data());
577565
marker_size = agg::rect_i(std::min(marker_size.x1, scanlines.min_x()),
578566
std::min(marker_size.y1, scanlines.min_y()),
579567
std::max(marker_size.x2, scanlines.max_x()),
@@ -619,11 +607,11 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
619607

620608
if (face.first) {
621609
ren.color(face.second);
622-
sa.init(fillCache, fillSize, x, y);
610+
sa.init(fillBuffer.data(), fillBuffer.size(), x, y);
623611
agg::render_scanlines(sa, sl, ren);
624612
}
625613
ren.color(gc.color);
626-
sa.init(strokeCache, strokeSize, x, y);
614+
sa.init(strokeBuffer.data(), strokeBuffer.size(), x, y);
627615
agg::render_scanlines(sa, sl, ren);
628616
}
629617
} else {
@@ -647,32 +635,23 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
647635

648636
if (face.first) {
649637
rendererAA.color(face.second);
650-
sa.init(fillCache, fillSize, x, y);
638+
sa.init(fillBuffer.data(), fillBuffer.size(), x, y);
651639
agg::render_scanlines(sa, sl, rendererAA);
652640
}
653641

654642
rendererAA.color(gc.color);
655-
sa.init(strokeCache, strokeSize, x, y);
643+
sa.init(strokeBuffer.data(), strokeBuffer.size(), x, y);
656644
agg::render_scanlines(sa, sl, rendererAA);
657645
}
658646
}
659647
}
660648
catch (...)
661649
{
662-
if (fillCache != staticFillCache)
663-
delete[] fillCache;
664-
if (strokeCache != staticStrokeCache)
665-
delete[] strokeCache;
666650
theRasterizer.reset_clipping();
667651
rendererBase.reset_clipping(true);
668652
throw;
669653
}
670654

671-
if (fillCache != staticFillCache)
672-
delete[] fillCache;
673-
if (strokeCache != staticStrokeCache)
674-
delete[] strokeCache;
675-
676655
theRasterizer.reset_clipping();
677656
rendererBase.reset_clipping(true);
678657
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy