Skip to content

Commit 9a50c68

Browse files
committed
Proof of concept drawing context for WritableImage
1 parent bf76ed2 commit 9a50c68

File tree

11 files changed

+1604
-18
lines changed

11 files changed

+1604
-18
lines changed

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,8 @@ public void factoryReleased() {
15061506

15071507
@Override
15081508
public PlatformImage createPlatformImage(int w, int h) {
1509-
ByteBuffer bytebuf = ByteBuffer.allocate(w * h * 4);
1510-
return com.sun.prism.Image.fromByteBgraPreData(bytebuf, w, h);
1509+
IntBuffer buf = IntBuffer.allocate(w * h);
1510+
return com.sun.prism.Image.fromIntArgbPreData(buf, w, h);
15111511
}
15121512

15131513
@Override
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.sun.javafx.util;
2+
3+
import java.lang.ref.Cleaner;
4+
import java.lang.ref.Cleaner.Cleanable;
5+
6+
/**
7+
* A module-wide Cleaner utility for registering cleanup actions on objects
8+
* that become phantom-reachable. This class maintains a single shared
9+
* {@link Cleaner} instance for the module, avoiding multiple daemon threads.
10+
* <p>
11+
* Usage example:
12+
* <pre>
13+
* FXCleaner.register(resource, () -> resource.dispose());
14+
* </pre>
15+
*/
16+
public class FXCleaner {
17+
private static final Cleaner CLEANER = Cleaner.create();
18+
19+
/**
20+
* Registers a cleanup action to be run when {@code obj} becomes
21+
* phantom-reachable.
22+
*
23+
* @param obj the object to monitor, cannot be {@code null}
24+
* @param action the cleanup action to run, cannot be {@code null}
25+
* @return a {@link Cleanable} that can be used to cancel the cleanup, never {@code null}
26+
* @throws NullPointerException when any argument is {@code null}
27+
*/
28+
public static Cleanable register(Object obj, Runnable action) {
29+
return CLEANER.register(obj, action);
30+
}
31+
}

modules/javafx.graphics/src/main/java/com/sun/marlin/MarlinUtils.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,4 @@ public static ThreadGroup getRootThreadGroup() {
7777
}
7878
return currentTG;
7979
}
80-
81-
// JavaFX specific Cleaner for Marlin-FX:
82-
// Module issue with jdk.internal.ref.Cleaner
83-
private final static java.lang.ref.Cleaner cleaner
84-
= java.lang.ref.Cleaner.create();
85-
86-
static java.lang.ref.Cleaner getCleaner() {
87-
return cleaner;
88-
}
8980
}

modules/javafx.graphics/src/main/java/com/sun/marlin/OffHeapArray.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
package com.sun.marlin;
2727

2828
import static com.sun.marlin.MarlinConst.LOG_OFF_HEAP_MALLOC;
29+
30+
import com.sun.javafx.util.FXCleaner;
31+
2932
import java.lang.foreign.Arena;
3033
import java.lang.foreign.MemorySegment;
3134
import java.lang.foreign.ValueLayout;
@@ -79,7 +82,7 @@ final class OffHeapArray {
7982

8083
if (!global) {
8184
// Register a cleaning function to ensure freeing off-heap memory:
82-
MarlinUtils.getCleaner().register(parent, this::free);
85+
FXCleaner.register(parent, this::free);
8386
}
8487
}
8588

modules/javafx.graphics/src/main/java/com/sun/marlin/RendererStats.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Timer;
2929
import java.util.TimerTask;
3030
import java.util.concurrent.ConcurrentLinkedQueue;
31+
32+
import com.sun.javafx.util.FXCleaner;
3133
import com.sun.marlin.ArrayCacheConst.CacheStats;
3234
import static com.sun.marlin.MarlinUtils.logInfo;
3335
import com.sun.marlin.stats.Histogram;
@@ -383,7 +385,7 @@ void add(final Object parent, final RendererStats stats) {
383385
allStats.add(stats);
384386

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

389391
void remove(final RendererStats stats) {

modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWArgbPreTexture.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ class SWArgbPreTexture extends SWTexture {
4545
private boolean hasAlpha = true;
4646

4747
SWArgbPreTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h) {
48+
this(factory, wrapMode, w, h, null);
49+
}
50+
51+
SWArgbPreTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h, int[] data) {
4852
super(factory, wrapMode, w, h);
49-
offset = 0;
53+
54+
this.allocated = data != null;
55+
this.data = data;
5056
}
5157

5258
SWArgbPreTexture(SWArgbPreTexture sharedTex, WrapMode altMode) {

0 commit comments

Comments
 (0)