Skip to content

[win32] Move of unified code from Wrapper to Image #2069

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

Merged
Merged
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 @@ -98,6 +98,11 @@ public final class Image extends Resource implements Drawable {
*/
private boolean isInitialized;

/**
* this field is used to mark destroyed images
*/
private boolean isDestroyed;

/**
* specifies the transparent pixel
*/
Expand Down Expand Up @@ -999,7 +1004,7 @@ public static void drawScaled(GC gc, Image original, int width, int height, floa
void destroy () {
device.deregisterResourceWithZoomSupport(this);
if (memGC != null) memGC.dispose();
this.imageProvider.destroy();
this.isDestroyed = true;
destroyHandle();
memGC = null;
}
Expand Down Expand Up @@ -1225,7 +1230,10 @@ public ImageData getImageData() {
*/
public ImageData getImageData (int zoom) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return imageProvider.getImageData(zoom);
if (zoomLevelToImageHandle.containsKey(zoom)) {
return zoomLevelToImageHandle.get(zoom).getImageData();
}
return this.imageProvider.newImageData(zoom);
}


Expand Down Expand Up @@ -1762,7 +1770,7 @@ public void internal_dispose_GC (long hDC, GCData data) {
*/
@Override
public boolean isDisposed() {
return this.imageProvider.isDisposed();
return !isInitialized || isDestroyed;
}

/**
Expand Down Expand Up @@ -1846,17 +1854,9 @@ public static Image win32_new(Device device, int type, long handle, int nativeZo
}

private abstract class AbstractImageProviderWrapper {
private boolean isDestroyed;

protected abstract Rectangle getBounds(int zoom);

protected final ImageData getImageData(int zoom) {
if (zoomLevelToImageHandle.containsKey(zoom)) {
return zoomLevelToImageHandle.get(zoom).getImageData();
}
return newImageData(zoom);
}

abstract ImageData newImageData(int zoom);

abstract AbstractImageProviderWrapper createCopy(Image image);
Expand Down Expand Up @@ -1888,14 +1888,6 @@ protected final ImageHandle newImageHandle(ImageData data, int zoom) {
return init(data, zoom);
}
}

protected boolean isDisposed() {
return !isInitialized || isDestroyed;
}

protected void destroy() {
this.isDestroyed = true;
}
}

private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper {
Expand Down Expand Up @@ -1940,7 +1932,7 @@ private abstract class ImageFromImageDataProviderWrapper extends AbstractImagePr
void initImage() {
// As the init call configured some Image attributes (e.g. type)
// it must be called
getImageData(100);
newImageData(100);
}

@Override
Expand Down
Loading