Skip to content
Snippets Groups Projects
Commit 6fec8876 authored by Stepan Sindelar's avatar Stepan Sindelar
Browse files

[GR-2798] FastR Grid: window resizing improvements.

parents 6c3678f5 46cdb99b
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ import java.util.List;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.api.vm.PolyglotEngine.Value;
import com.oracle.truffle.r.nodes.builtin.base.Quit;
import com.oracle.truffle.r.runtime.ExitException;
import com.oracle.truffle.r.runtime.JumpToTopLevelException;
......@@ -223,11 +224,15 @@ public class RCommand {
String continuePrompt = getContinuePrompt();
StringBuffer sb = new StringBuffer(input);
Source source = RSource.fromTextInternal(sb.toString(), RSource.Internal.SHELL_INPUT);
boolean hasExecutor = RContext.getInstance().hasExecutor();
while (true) {
lastStatus = 0;
try {
try {
vm.eval(source).get();
Value val = vm.eval(source);
if (hasExecutor) {
val.get();
}
// checked exceptions are wrapped in RuntimeExceptions
} catch (RuntimeException e) {
if (e.getCause() instanceof com.oracle.truffle.api.vm.IncompleteSourceException) {
......
......@@ -43,15 +43,30 @@ public final class WindowDevice {
public static GridDevice createWindowDevice(int width, int height) {
JFrameDevice frameDevice = JFrameDevice.create(width, height);
frameDevice.setResizeListener(() -> {
RContext.getInstance().schedule(() -> {
GridContext.getContext().evalInternalRFunction("redrawAll");
});
});
if (RContext.getInstance().hasExecutor()) {
frameDevice.setResizeListener(WindowDevice::redrawAll);
} else {
noSchedulingSupportWarning();
}
return new BufferedJFrameDevice(frameDevice);
}
public static RError awtNotSupported() {
throw RError.error(RError.NO_CALLER, Message.GENERIC, "AWT based grid devices are not supported.");
}
private static void redrawAll() {
RContext ctx = RContext.getInstance();
if (ctx.hasExecutor()) {
// to be robust we re-check the executor availability
ctx.schedule(() -> {
GridContext.getContext().evalInternalRFunction("redrawAll");
});
}
}
private static void noSchedulingSupportWarning() {
// Note: the PolyglotEngine was not built with an Executor
RError.warning(RError.NO_CALLER, Message.GENERIC, "Grid cannot resize the drawings. If you resize the window, the content will be lost.");
}
}
......@@ -822,15 +822,17 @@ public final class RContext extends com.oracle.truffle.api.ExecutionContext impl
return info.getEnv();
}
public boolean hasExecutor() {
return info.executor != null;
}
/**
* Allows another thread to schedule some code to be run in this context's thread. The action is
* ignored if the current context does not support such scheduling, i.e. the polyglot engine was
* not created with an executor.
* Allows another thread to schedule some code to be run in this context's thread. The action
* can be scheduled only if PolyglotEngine was created with an Executor.
*/
public void schedule(Runnable action) {
if (info.executor != null) {
info.executor.execute(action);
}
assert hasExecutor() : "Cannot run RContext#schedule() when there is no executor.";
info.executor.execute(action);
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment