Skip to content

GC.setClipping(path) doesn't paint on Linux when transformed #3120

@ptziegler

Description

@ptziegler

Describe the bug

This is an issue reported here: eclipse-gef/gef-classic#1044. Draw2D makes extensive use of the SWT Transform class to e.g. handle scrolling. When setClip(Path) is called, this transformation is ignored and areas are clipped that should be visible.

To Reproduce

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ClipGraphics2 {
    
    public static void main(String[] args) {
        Shell shell = new Shell();
        shell.setLayout(new FillLayout());
        shell.setSize(600, 300);
        
        Display display = shell.getDisplay();
        
        shell.addPaintListener(event -> {
        	GC gc = event.gc;
        	
        	Path p = new Path(display);
        	p.addRectangle(50, 350, 100, 100);
        	
        	Transform t = new Transform(display);
        	t.translate(0, -300);
        	
        	gc.setTransform(t);
        	
        	gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
        	gc.fillPath(p);
        	gc.setClipping(p);
        	gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        	gc.fillPath(p);
        	
        	p.dispose();
        	
        	gc.setTransform(null);
        	t.dispose();
        });
        
        shell.open();
        
        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}

Expected behavior

The rectangle should be painted green, but is painted red on Linux.

Screenshots

From the original GEF issue:

Screencast_20260305_201403.webm

The snippet:

Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS

Version since

This is a regression introduced with d7ce597 in response to Bug 531667 - [GTK3] Cannot draw Canvas with Control.print(GC). However, simply reverting the change to setClipping(Path) causes Bug531667_PaintListener_paints_despite_empty_GC_clipping to fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Linux/GTKHappens on LinuxbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions