Skip to content
Open
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 @@ -154,14 +154,19 @@ InternalImageHandle getOrCreate(int zoom, Supplier<DestroyableImageHandle> creat
return null;
}

DestroyableImageHandle imageHandle = (DestroyableImageHandle) get(zoom);
if (imageHandle != null) {
return imageHandle;
DestroyableImageHandle registeredimageHandle = (DestroyableImageHandle) get(zoom);
if (registeredimageHandle != null) {
return registeredimageHandle;
}

imageHandle = creator.get();
zoomLevelToImageHandle.put(zoom, imageHandle);
return imageHandle;
return executeOnHandle(zoom, optHandle -> {
if (optHandle .isPresent()) {
return optHandle .get();
}
DestroyableImageHandle imagehandle = creator.get();
zoomLevelToImageHandle.put(zoom, imagehandle);
return imagehandle;
});
}

boolean contains(int zoom) {
Expand All @@ -181,15 +186,24 @@ Set<Integer> getAllZooms() {
}

void destroyHandles(Predicate<Integer> filter) {
Iterator<Entry<Integer, DestroyableImageHandle>> it = zoomLevelToImageHandle.entrySet().iterator();
while (it.hasNext()) {
Entry<Integer, DestroyableImageHandle> zoomToHandle = it.next();
if (filter.test(zoomToHandle.getKey())) {
DestroyableImageHandle imageHandle = zoomToHandle.getValue();
it.remove();
zoomLevelToImageHandle.remove(imageHandle.zoom, imageHandle);
imageHandle.destroy();
executeOnHandle(0, __ -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds semantically incorrect. You do not execute anything on a handle for zoom 0, but you want somehow miuse that method to synchronize on the handler. You would either have to iterate over the keys on perform an executeOnHandle for each each to process, or you should just synchronize the call here.

Iterator<Entry<Integer, DestroyableImageHandle>> it = zoomLevelToImageHandle.entrySet().iterator();
while (it.hasNext()) {
Entry<Integer, DestroyableImageHandle> zoomToHandle = it.next();
if (filter.test(zoomToHandle.getKey())) {
DestroyableImageHandle imageHandle = zoomToHandle.getValue();
it.remove();
zoomLevelToImageHandle.remove(imageHandle.zoom, imageHandle);
imageHandle.destroy();
}
}
return null;
});
}

<R> R executeOnHandle(int zoom, Function<Optional<InternalImageHandle>,R> execution) {
synchronized (this) {
return execution.apply(Optional.ofNullable(get(100)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return execution.apply(Optional.ofNullable(get(100)));
return execution.apply(Optional.ofNullable(get(zoom)));

}
}

Expand Down Expand Up @@ -1304,8 +1318,8 @@ public Rectangle getBounds() {

Rectangle getBounds(int zoom) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (imageHandleManager.contains(zoom)) {
ImageHandle imageMetadata = imageHandleManager.get(zoom);
ImageHandle imageMetadata = imageHandleManager.get(zoom);
if (imageMetadata != null) {
Rectangle rectangle = new Rectangle(0, 0, imageMetadata.width, imageMetadata.height);
return Win32DPIUtils.scaleBounds(rectangle, zoom, imageMetadata.zoom);
}
Expand Down Expand Up @@ -1388,7 +1402,12 @@ public ImageData getImageData (int zoom) {
return imageHandle.getImageData();
}

return this.imageProvider.newImageData(zoom);
return imageHandleManager.executeOnHandle(zoom, obtainedImageHandle -> {
if (obtainedImageHandle.isPresent()) {
return obtainedImageHandle.get().getImageData();
}
return this.imageProvider.newImageData(zoom);
});
}

/**
Expand Down
Loading