Skip to content
Open
Show file tree
Hide file tree
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 @@ -1506,8 +1506,8 @@ public void factoryReleased() {

@Override
public PlatformImage createPlatformImage(int w, int h) {
ByteBuffer bytebuf = ByteBuffer.allocate(w * h * 4);
return com.sun.prism.Image.fromByteBgraPreData(bytebuf, w, h);
IntBuffer buf = IntBuffer.allocate(w * h);
return com.sun.prism.Image.fromIntArgbPreData(buf, w, h);
Comment on lines +1509 to +1510
Copy link
Collaborator Author

@hjohn hjohn Nov 10, 2025

Choose a reason for hiding this comment

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

This seems to be no problem to change (an image heavy application still runs absolutely fine), but it is kind of a global change. If there are issues with this, we could make a specific method for writable images to use so we always get an int[] buffer that the software renderer expects.

As it is now, the renderer is writing directly into the underlying image storage, without any copies being made (which is nice and efficient).

Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious why the byte buffer was chosen initially.
Will IntBuffer be better on every platform?

Also, w * h might be negative if the product is greater than ~2B, though it will result in an IllegalArgumentException with a cryptic "capacity expected to be negative" message.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sun.javafx.util;

import java.lang.ref.Cleaner;
import java.lang.ref.Cleaner.Cleanable;

/**
* A module-wide Cleaner utility for registering cleanup actions on objects
* that become phantom-reachable. This class maintains a single shared
* {@link Cleaner} instance for the module, avoiding multiple daemon threads.
* <p>
* Usage example:
* <pre>
* FXCleaner.register(resource, () -> resource.dispose());
* </pre>
*/
public class FXCleaner {
private static final Cleaner CLEANER = Cleaner.create();

/**
* Registers a cleanup action to be run when {@code obj} becomes
* phantom-reachable.
*
* @param obj the object to monitor, cannot be {@code null}
* @param action the cleanup action to run, cannot be {@code null}
* @return a {@link Cleanable} that can be used to cancel the cleanup, never {@code null}
* @throws NullPointerException when any argument is {@code null}
*/
public static Cleanable register(Object obj, Runnable action) {
return CLEANER.register(obj, action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,4 @@ public static ThreadGroup getRootThreadGroup() {
}
return currentTG;
}

// JavaFX specific Cleaner for Marlin-FX:
// Module issue with jdk.internal.ref.Cleaner
private final static java.lang.ref.Cleaner cleaner
= java.lang.ref.Cleaner.create();

static java.lang.ref.Cleaner getCleaner() {
return cleaner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
package com.sun.marlin;

import static com.sun.marlin.MarlinConst.LOG_OFF_HEAP_MALLOC;

import com.sun.javafx.util.FXCleaner;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
Expand Down Expand Up @@ -79,7 +82,7 @@ final class OffHeapArray {

if (!global) {
// Register a cleaning function to ensure freeing off-heap memory:
MarlinUtils.getCleaner().register(parent, this::free);
FXCleaner.register(parent, this::free);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.sun.javafx.util.FXCleaner;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.MarlinUtils.logInfo;
import com.sun.marlin.stats.Histogram;
Expand Down Expand Up @@ -383,7 +385,7 @@ void add(final Object parent, final RendererStats stats) {
allStats.add(stats);

// Register a cleaning function to ensure removing dead entries:
MarlinUtils.getCleaner().register(parent, () -> remove(stats));
FXCleaner.register(parent, () -> remove(stats));
}

void remove(final RendererStats stats) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ class SWArgbPreTexture extends SWTexture {
private boolean hasAlpha = true;

SWArgbPreTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h) {
this(factory, wrapMode, w, h, null);
}

SWArgbPreTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h, int[] data) {
super(factory, wrapMode, w, h);
offset = 0;

this.allocated = data != null;
this.data = data;
}

SWArgbPreTexture(SWArgbPreTexture sharedTex, WrapMode altMode) {
Expand Down
Loading