summaryrefslogtreecommitdiff
path: root/psi/idisp.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2020-06-04 19:27:15 +0100
committerRobin Watts <Robin.Watts@artifex.com>2020-06-25 00:19:12 +0100
commit4438e3e5bc4dfc9e46fc86d86d912171ec582a4e (patch)
treec2cbc61774320346337f2311876f4bc9de46d011 /psi/idisp.c
parent7e427246abb151cde9154783775acfaa776b502e (diff)
downloadghostpdl-4438e3e5bc4dfc9e46fc86d86d912171ec582a4e.tar.gz
Rework display device "DisplayHandle" passing.
Add gsapi_{,de}register_callout API. This allows integrators to register handlers for "callouts" from gs devices. The first example of such a callout is the display device. Previously, this has relied on the gsapi_set_display_callback API to pass a pointer to a structure into the core, from where it was hackily poked into the display device structure. Instead, we now have the display device "callout" to registered handlers to get the structure and the handle to use. The legacy API is maintained by the API level implementing a handler to return the display callback in response to the devices callout. The code to do the 'poking' of the display device has therefore been removed, and replaced by code that checks to see if an opened device needs reopening after init, if so, opens/closes it.
Diffstat (limited to 'psi/idisp.c')
-rw-r--r--psi/idisp.c70
1 files changed, 18 insertions, 52 deletions
diff --git a/psi/idisp.c b/psi/idisp.c
index d1efcbc16..ab8d070cd 100644
--- a/psi/idisp.c
+++ b/psi/idisp.c
@@ -47,70 +47,36 @@
#include "gsequivc.h"
#include "gdevdsp.h"
#include "gdevdsp2.h"
+#include "gxgstate.h"
+#include "gxdevsop.h"
int
-display_set_callback(gs_main_instance *minst, display_callback *callback)
+reopen_device_if_required(gs_main_instance *minst)
{
i_ctx_t *i_ctx_p;
- bool was_open;
int code;
- int exit_code = 0;
- os_ptr op;
gx_device *dev;
- gx_device_display *ddev;
-
- /* If display device exists, copy prototype if needed and return
- * device true
- * If it doesn't exist, return
- * false
- */
- const char getdisplay[] =
- "devicedict /display known dup { /display finddevice exch } if";
- code = gs_main_run_string(minst, getdisplay, 0, &exit_code,
- &minst->error_object);
- if (code < 0)
- return code;
i_ctx_p = minst->i_ctx_p; /* run_string may change i_ctx_p if GC */
- op = osp;
- check_type(*op, t_boolean);
- if (op->value.boolval) {
- /* display device was included in Ghostscript so we need
- * to set the callback structure pointer within it.
- * If the device is already open, close it before
- * setting callback, then reopen it.
- */
- check_read_type(op[-1], t_device);
- if (op[-1].value.pdevice == NULL)
- /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */
- return_error(gs_error_undefined);
-
- dev = op[-1].value.pdevice;
+ dev = gs_currentdevice_inline(i_ctx_p->pgs);
+ if (dev == NULL)
+ /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */
+ return_error(gs_error_undefined);
- was_open = dev->is_open;
- if (was_open) {
- code = gs_closedevice(dev);
- if (code < 0)
- return code;
- }
+ if (!dev->is_open)
+ return 0;
- ddev = (gx_device_display *) dev;
+ if (dev_proc(dev, dev_spec_op)(dev, gxdso_reopen_after_init, NULL, 0) != 1)
+ return 0;
- /* Deal with the case where we subclassed the device before we got here */
- while (ddev->child)
- ddev = (gx_device_display *)ddev->child;
-
- ddev->callback = callback;
+ code = gs_closedevice(dev);
+ if (code < 0)
+ return code;
- if (was_open) {
- code = gs_opendevice(dev);
- if (code < 0) {
- dmprintf(dev->memory, "**** Unable to open the display device, quitting.\n");
- return code;
- }
- }
- pop(1); /* device */
+ code = gs_opendevice(dev);
+ if (code < 0) {
+ dmprintf(dev->memory, "**** Unable to reopen the device, quitting.\n");
+ return code;
}
- pop(1); /* boolean */
return 0;
}