Skip to content

Replace usages of new Image(device, width, height) #2178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1581,14 +1581,25 @@ LRESULT WM_PAINT (long wParam, long lParam) {
GC paintGC = null;
Image image = null;
if ((style & (SWT.DOUBLE_BUFFERED | SWT.TRANSPARENT)) != 0) {
image = new Image (display, width, height);
paintGC = gc;
gc = new GC (image, paintGC.getStyle() & SWT.RIGHT_TO_LEFT);
GCData gcData = gc.getGCData ();
gcData.uiState = data.uiState;
gc.setForeground (getForeground ());
gc.setBackground (getBackground ());
gc.setFont (getFont ());
int originalStyle = gc.getStyle();
ImageGcDrawer drawer = new ImageGcDrawer() {
@Override
public void drawOn(GC gc, int iWidth, int iHeight) {
GCData gcData = gc.getGCData ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks wrong in Eclipse (not in GH though)

gcData.uiState = data.uiState;
gc.setForeground (getForeground ());
gc.setBackground (getBackground ());
gc.setFont (getFont ());
}

@Override
public int getGcStyle() {
return originalStyle & SWT.RIGHT_TO_LEFT;
}
};
image = new Image (display, drawer, width, height);
gc = new GC(image, originalStyle & SWT.RIGHT_TO_LEFT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that this works as expected? You now initialize the GC inside the ImageGcDrawer and then create a new one that is used throughout the rest of the method, which does not adhere to the settings inside ImageGcDrawer. At least, it would be my expectation that those two GCs behave completely independent. In my understanding, the code you move inside the ImageGcDrawer now equals to a no-op, doesn't it?

if ((style & SWT.TRANSPARENT) != 0) {
OS.BitBlt (gc.handle, 0, 0, width, height, paintGC.handle, ps.left, ps.top, OS.SRCCOPY);
}
Expand All @@ -1598,6 +1609,16 @@ LRESULT WM_PAINT (long wParam, long lParam) {
OS.SetMetaRgn (gc.handle);
OS.SetWindowOrgEx (gc.handle, ps.left, ps.top, null);
OS.SetBrushOrgEx (gc.handle, ps.left, ps.top, null);

if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
/* This code is intentionally commented because it may be slow to copy bits from the screen */
//newPaintGC.copyArea (image, ps.left, ps.top);
} else {
RECT rect = new RECT ();
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
drawBackground (gc.handle, rect);
}

Comment on lines +1612 to +1621
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why duplicate this code?

Suggested change
if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
/* This code is intentionally commented because it may be slow to copy bits from the screen */
//newPaintGC.copyArea (image, ps.left, ps.top);
} else {
RECT rect = new RECT ();
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
drawBackground (gc.handle, rect);
}

if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
/* This code is intentionally commented because it may be slow to copy bits from the screen */
//paintGC.copyArea (image, ps.left, ps.top);
Expand Down Expand Up @@ -1642,10 +1663,10 @@ LRESULT WM_PAINT (long wParam, long lParam) {
GCData gcData = gc.getGCData ();
if (gcData.focusDrawn && !isDisposed ()) updateUIState ();
}
gc.dispose();
if (!isDisposed ()) {
paintGC.drawImage (image, DPIUtil.scaleDown(ps.left, zoom), DPIUtil.scaleDown(ps.top, zoom));
}
gc.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change, it's unnecessary now that you instantiated gc again and it only adds noise to the PR.

image.dispose ();
gc = paintGC;
}
Expand Down
Loading