Skip to content
Snippets Groups Projects
Commit 2d28bb9f authored by Roman Katerinenko's avatar Roman Katerinenko
Browse files

Implement some device functions

parent e87f927b
Branches
No related tags found
No related merge requests found
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.library.grDevices;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.r.library.graphics.core.GraphicsEngineImpl;
import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
import com.oracle.truffle.r.runtime.data.RNull;
public class DevicesCCalls {
public static final class C_DevOff extends RExternalBuiltinNode {
@Override
@TruffleBoundary
public Object call(RArgsValuesAndNames args) {
Object firstArgument = args.getArgument(0);
int deviceIndex = castInt(castVector(firstArgument));
GraphicsEngineImpl.getInstance().killGraphicsDeviceByIndex(deviceIndex);
return RNull.instance;
}
}
public static final class C_DevCur extends RExternalBuiltinNode {
@Override
@TruffleBoundary
public Object call(RArgsValuesAndNames args) {
return GraphicsEngineImpl.getInstance().getCurrentGraphicsDeviceIndex();
}
}
}
......@@ -62,4 +62,8 @@ public interface GraphicsEngine {
void setCurrentGraphicsDeviceClipRect(double x1, double y1, double x2, double y2);
void drawPolyline(Coordinates coordinates, DrawingParameters drawingParameters);
void killGraphicsDeviceByIndex(int graphicsDeviceIndex);
int getCurrentGraphicsDeviceIndex();
}
......@@ -22,12 +22,13 @@
*/
package com.oracle.truffle.r.library.graphics.core;
import com.oracle.truffle.r.library.graphics.core.geometry.Coordinates;
import com.oracle.truffle.r.library.grDevices.NullGraphicsDevice;
import com.oracle.truffle.r.library.grDevices.fastrgd.FastRGraphicsDevice;
import com.oracle.truffle.r.library.graphics.core.geometry.Coordinates;
import com.oracle.truffle.r.runtime.Utils;
import static com.oracle.truffle.r.library.graphics.core.GraphicsEvent.*;
import static com.oracle.truffle.r.library.graphics.core.GraphicsEvent.GE_FINAL_STATE;
import static com.oracle.truffle.r.library.graphics.core.GraphicsEvent.GE_INIT_STATE;
// todo implement 'active' devices array from devices.c
public final class GraphicsEngineImpl implements GraphicsEngine {
......@@ -46,7 +47,7 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
private int graphicsSystemsAmount = 0;
private int devicesAmountWithoutNullDevice = 0;
private GraphicsDevice currentGraphicsDevice = NullGraphicsDevice.getInstance();
private CurrentGraphicsDevice currentGraphicsDevice = new CurrentGraphicsDevice(NullGraphicsDevice.getInstance(), NULL_GRAPHICS_DEVICE_INDEX);
public static GraphicsEngine getInstance() {
return instance;
......@@ -131,7 +132,7 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
}
graphicsDevices[index] = newGraphicsDevice;
devicesAmountWithoutNullDevice++;
currentGraphicsDevice = newGraphicsDevice;
currentGraphicsDevice = new CurrentGraphicsDevice(newGraphicsDevice, index);
notifyEachGraphicsSystem(newGraphicsDevice, GE_INIT_STATE);
newGraphicsDevice.activate();
}
......@@ -150,7 +151,10 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
throw new NullPointerException("Graphics device to unregister is null");
}
doUnregisterGraphicsDevice(deviceToUnregister);
makeItCurrent(getGraphicsDeviceNextTo(deviceToUnregister));
GraphicsDevice nextGraphicsDevice = getGraphicsDeviceNextTo(deviceToUnregister);
int index = findElementIndexInArray(nextGraphicsDevice, graphicsDevices);
currentGraphicsDevice = new CurrentGraphicsDevice(nextGraphicsDevice, index);
nextGraphicsDevice.activate();
// todo Interesting that in GNUR a GraphicsSystem is not notified when a GraphicsDevice is
// killed
}
......@@ -163,15 +167,10 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
}
graphicsDevices[index] = null;
devicesAmountWithoutNullDevice--;
currentGraphicsDevice = getNullGraphicsDevice();
currentGraphicsDevice = new CurrentGraphicsDevice(getNullGraphicsDevice(), NULL_GRAPHICS_DEVICE_INDEX);
deviceToUnregister.close();
}
private void makeItCurrent(GraphicsDevice newCurrentGraphicsDevice) {
currentGraphicsDevice = newCurrentGraphicsDevice;
currentGraphicsDevice.activate();
}
public int getGraphicsDevicesAmount() {
return devicesAmountWithoutNullDevice;
}
......@@ -180,6 +179,10 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
return devicesAmountWithoutNullDevice == 0;
}
public int getCurrentGraphicsDeviceIndex() {
return currentGraphicsDevice.graphicsDeviceIndex;
}
public GraphicsDevice getCurrentGraphicsDevice() {
if (isNullDeviceIsCurrent()) {
try {
......@@ -189,7 +192,7 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
e.printStackTrace();
}
}
return currentGraphicsDevice;
return currentGraphicsDevice.graphicsDevice;
}
private boolean isNullDeviceIsCurrent() {
......@@ -287,6 +290,21 @@ public final class GraphicsEngineImpl implements GraphicsEngine {
getCurrentGraphicsDevice().drawPolyline(coordinates, drawingParameters);
}
@Override
public void killGraphicsDeviceByIndex(int graphicsDeviceIndex) {
// todo TBD
}
private class CurrentGraphicsDevice {
private final GraphicsDevice graphicsDevice;
private final int graphicsDeviceIndex;
private CurrentGraphicsDevice(GraphicsDevice graphicsDevice, int graphicsDeviceIndex) {
this.graphicsDevice = graphicsDevice;
this.graphicsDeviceIndex = graphicsDeviceIndex;
}
}
private enum SearchDirection {
FORWARD,
BACKWARD
......
......@@ -13,6 +13,7 @@ package com.oracle.truffle.r.nodes.builtin.base.foreign;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.utilities.*;
import com.oracle.truffle.r.library.grDevices.DevicesCCalls;
import com.oracle.truffle.r.library.graphics.GraphicsCCalls.C_Par;
import com.oracle.truffle.r.library.graphics.GraphicsCCalls.C_PlotXY;
import com.oracle.truffle.r.library.methods.MethodsListDispatchFactory.R_M_setPrimitiveMethodsNodeGen;
......@@ -219,6 +220,10 @@ public class ForeignFunctions {
@Override
protected RExternalBuiltinNode lookupBuiltin(RList f) {
switch (lookupName(f)) {
case "devoff":
return new DevicesCCalls.C_DevOff();
case "devcur":
return new DevicesCCalls.C_DevCur();
case "countfields":
return new CountFields();
case "readtablehead":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment