Skip to content

Commit 124ec08

Browse files
committed
CTabFolderRenderer: Reuse Region objects in drawBackground()
Reduce native resource allocation and disposal churn by reusing clippingRegion and shapeRegion fields in drawBackground. See #3219
1 parent ee1713a commit 124ec08

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class CTabFolderRenderer {
3535
Color fillColor;
3636

3737
private Font chevronFont = null;
38+
private Region clippingRegion = null;
39+
private Region shapeRegion = null;
3840

3941
static final RGB CLOSE_FILL = new RGB(240, 64, 64);
4042

@@ -398,6 +400,16 @@ protected void dispose() {
398400
chevronFont.dispose();
399401
chevronFont = null;
400402
}
403+
404+
if (clippingRegion != null) {
405+
clippingRegion.dispose();
406+
clippingRegion = null;
407+
}
408+
409+
if (shapeRegion != null) {
410+
shapeRegion.dispose();
411+
shapeRegion = null;
412+
}
401413
}
402414

403415
/**
@@ -499,14 +511,16 @@ void drawBackground(GC gc, int[] shape, boolean selected) {
499511
}
500512

501513
void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Color defaultBackground, Image image, Color[] colors, int[] percents, boolean vertical) {
502-
Region clipping = null, region = null;
514+
Region clipping = null;
503515
if (shape != null) {
504-
clipping = new Region();
516+
if (clippingRegion == null) clippingRegion = new Region();
517+
if (shapeRegion == null) shapeRegion = new Region();
518+
clipping = clippingRegion;
505519
gc.getClipping(clipping);
506-
region = new Region();
507-
region.add(shape);
508-
region.intersect(clipping);
509-
gc.setClipping(region);
520+
shapeRegion.subtract(shapeRegion);
521+
shapeRegion.add(shape);
522+
shapeRegion.intersect(clipping);
523+
gc.setClipping(shapeRegion);
510524
}
511525
if (image != null) {
512526
// draw the background image in shape
@@ -589,8 +603,6 @@ void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Col
589603
}
590604
if (shape != null) {
591605
gc.setClipping(clipping);
592-
clipping.dispose();
593-
region.dispose();
594606
}
595607
}
596608

0 commit comments

Comments
 (0)