-
Notifications
You must be signed in to change notification settings - Fork 175
Use the existing image to initialize the GC in ImageGcDrawerWrapper #2238
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
Open
ShahzaibIbrahim
wants to merge
2
commits into
eclipse-platform:master
Choose a base branch
from
vi-eclipse:master-328
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1911,6 +1911,47 @@ protected final ImageHandle newImageHandle(ImageData data, int zoom) { | |
return init(data, zoom); | ||
} | ||
} | ||
|
||
protected final ImageHandle createBaseHandle(int zoom, int width, int height) { | ||
long handle = initBaseHandle(zoom, width, height); | ||
ImageHandle imageHandle = new ImageHandle(handle, zoom); | ||
zoomLevelToImageHandle.put(zoom, imageHandle); | ||
return imageHandle; | ||
} | ||
|
||
|
||
private long initBaseHandle(int zoom, int width, int height) { | ||
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | ||
int scaledWidth = DPIUtil.scaleUp (width, zoom); | ||
int scaledHeight = DPIUtil.scaleUp (height, zoom); | ||
long hDC = device.internal_new_GC(null); | ||
long newHandle = OS.CreateCompatibleBitmap(hDC, scaledWidth, scaledHeight); | ||
/* | ||
* Feature in Windows. CreateCompatibleBitmap() may fail | ||
* for large images. The fix is to create a DIB section | ||
* in that case. | ||
*/ | ||
if (newHandle == 0) { | ||
int bits = OS.GetDeviceCaps(hDC, OS.BITSPIXEL); | ||
int planes = OS.GetDeviceCaps(hDC, OS.PLANES); | ||
int depth = bits * planes; | ||
if (depth < 16) depth = 16; | ||
if (depth > 24) depth = 24; | ||
newHandle = createDIB(scaledWidth, scaledHeight, depth); | ||
} | ||
if (newHandle != 0) { | ||
long memDC = OS.CreateCompatibleDC(hDC); | ||
long hOldBitmap = OS.SelectObject(memDC, newHandle); | ||
OS.PatBlt(memDC, 0, 0, scaledWidth, scaledHeight, OS.PATCOPY); | ||
OS.SelectObject(memDC, hOldBitmap); | ||
OS.DeleteDC(memDC); | ||
} | ||
device.internal_dispose_GC(hDC, null); | ||
if (newHandle == 0) { | ||
SWT.error(SWT.ERROR_NO_HANDLES, null, device.getLastError()); | ||
} | ||
return newHandle; | ||
} | ||
} | ||
|
||
private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper { | ||
|
@@ -2121,59 +2162,22 @@ protected Rectangle getBounds(int zoom) { | |
@Override | ||
ImageData newImageData(int zoom) { | ||
if (zoomLevelToImageHandle.isEmpty()) { | ||
return createBaseHandle(zoom).getImageData(); | ||
baseZoom = zoom; | ||
return createBaseHandle(zoom, width, height).getImageData(); | ||
} | ||
return getScaledImageData(zoom); | ||
} | ||
|
||
@Override | ||
protected ImageHandle newImageHandle(int zoom) { | ||
if (zoomLevelToImageHandle.isEmpty()) { | ||
return createBaseHandle(zoom); | ||
baseZoom = zoom; | ||
return createBaseHandle(zoom, width, height); | ||
} | ||
return super.newImageHandle(zoom); | ||
} | ||
|
||
private ImageHandle createBaseHandle(int zoom) { | ||
long handle = initBaseHandle(zoom); | ||
baseZoom = zoom; | ||
ImageHandle imageHandle = new ImageHandle(handle, zoom); | ||
zoomLevelToImageHandle.put(zoom, imageHandle); | ||
return imageHandle; | ||
} | ||
|
||
private long initBaseHandle(int zoom) { | ||
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | ||
int scaledWidth = DPIUtil.scaleUp (width, zoom); | ||
int scaledHeight = DPIUtil.scaleUp (height, zoom); | ||
long hDC = device.internal_new_GC(null); | ||
long newHandle = OS.CreateCompatibleBitmap(hDC, scaledWidth, scaledHeight); | ||
/* | ||
* Feature in Windows. CreateCompatibleBitmap() may fail | ||
* for large images. The fix is to create a DIB section | ||
* in that case. | ||
*/ | ||
if (newHandle == 0) { | ||
int bits = OS.GetDeviceCaps(hDC, OS.BITSPIXEL); | ||
int planes = OS.GetDeviceCaps(hDC, OS.PLANES); | ||
int depth = bits * planes; | ||
if (depth < 16) depth = 16; | ||
if (depth > 24) depth = 24; | ||
newHandle = createDIB(scaledWidth, scaledHeight, depth); | ||
} | ||
if (newHandle != 0) { | ||
long memDC = OS.CreateCompatibleDC(hDC); | ||
long hOldBitmap = OS.SelectObject(memDC, newHandle); | ||
OS.PatBlt(memDC, 0, 0, scaledWidth, scaledHeight, OS.PATCOPY); | ||
OS.SelectObject(memDC, hOldBitmap); | ||
OS.DeleteDC(memDC); | ||
} | ||
device.internal_dispose_GC(hDC, null); | ||
if (newHandle == 0) { | ||
SWT.error(SWT.ERROR_NO_HANDLES, null, device.getLastError()); | ||
} | ||
return newHandle; | ||
} | ||
|
||
@Override | ||
AbstractImageProviderWrapper createCopy(Image image) { | ||
|
@@ -2541,28 +2545,29 @@ ImageData newImageData(int zoom) { | |
protected ImageHandle newImageHandle(int zoom) { | ||
currentZoom = zoom; | ||
int gcStyle = drawer.getGcStyle(); | ||
Image image; | ||
if ((gcStyle & SWT.TRANSPARENT) != 0) { | ||
int scaledHeight = DPIUtil.scaleUp(height, zoom); | ||
int scaledWidth = DPIUtil.scaleUp(width, zoom); | ||
/* Create a 24 bit image data with alpha channel */ | ||
final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000)); | ||
resultData.alphaData = new byte [scaledWidth * scaledHeight]; | ||
image = new Image(device, resultData, zoom); | ||
init(resultData, zoom); | ||
} else { | ||
image = new Image(device, width, height); | ||
} | ||
GC gc = new GC(new DrawableWrapper(image, zoom), gcStyle); | ||
createBaseHandle(zoom, width, height); | ||
}; | ||
GC gc = new GC(new DrawableWrapper(Image.this, zoom), gcStyle); | ||
try { | ||
gc.data.nativeZoom = zoom; | ||
drawer.drawOn(gc, width, height); | ||
ImageData imageData = image.getImageMetadata(zoom).getImageData(); | ||
ImageData imageData = Image.this.getImageMetadata(zoom).getImageData(); | ||
drawer.postProcess(imageData); | ||
ImageData newData = adaptImageDataIfDisabledOrGray(imageData); | ||
return init(newData, zoom); | ||
if(imageData.data != null) { | ||
zoomLevelToImageHandle.get(zoom).destroy(); | ||
init(imageData, zoom); | ||
} | ||
Comment on lines
+2562
to
+2567
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I want initialize the imageData only if postProcess is called. That's why I have a default implementation that nullify the imageData in order to know here if it was not implemented. I know it's not a clean solution and I am open to hear suggestion. My suggestions:
|
||
return zoomLevelToImageHandle.get(zoom); | ||
} finally { | ||
gc.dispose(); | ||
image.dispose(); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we then remove the
DrawableWrapper
and just call?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a scenario where it's needed when another GC can be called over this image from the outside. I am not 100% of the scenario but maybe @akoch-yatta can explain it bit better on why it was used in the first place.