summaryrefslogtreecommitdiffstats
path: root/generic/tkTest.c
diff options
context:
space:
mode:
authorculler <culler>2020-07-21 18:36:38 (GMT)
committerculler <culler>2020-07-21 18:36:38 (GMT)
commit76864c8a9ccb1c3400b2482b6d3c8f9d0d1101f9 (patch)
treeea0f912c0c4f357be200b9303e3dde515c8d210b /generic/tkTest.c
parentc160fe8bd880807117acc15040f8f4116ec85418 (diff)
downloadtk-76864c8a9ccb1c3400b2482b6d3c8f9d0d1101f9.zip
tk-76864c8a9ccb1c3400b2482b6d3c8f9d0d1101f9.tar.gz
tk-76864c8a9ccb1c3400b2482b6d3c8f9d0d1101f9.tar.bz2
Improve image testing on macOS.
Diffstat (limited to 'generic/tkTest.c')
-rw-r--r--generic/tkTest.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/generic/tkTest.c b/generic/tkTest.c
index e80f488..c22e649 100644
--- a/generic/tkTest.c
+++ b/generic/tkTest.c
@@ -71,6 +71,8 @@ typedef struct TImageInstance {
TImageMaster *masterPtr; /* Pointer to master for image. */
XColor *fg; /* Foreground color for drawing in image. */
GC gc; /* Graphics context for drawing in image. */
+ Bool displayFailed; /* macOS display attempted out of drawRect. */
+ char buffer[200 + TCL_INTEGER_SPACE * 6]; /* message to log on display. */
} TImageInstance;
/*
@@ -1517,6 +1519,7 @@ ImageGet(
instPtr->fg = Tk_GetColor(timPtr->interp, tkwin, "#ff0000");
gcValues.foreground = instPtr->fg->pixel;
instPtr->gc = Tk_GetGC(tkwin, GCForeground, &gcValues);
+ instPtr->displayFailed = False;
return instPtr;
}
@@ -1551,41 +1554,50 @@ ImageDisplay(
* imageX and imageY. */
{
TImageInstance *instPtr = (TImageInstance *) clientData;
- char buffer[200 + TCL_INTEGER_SPACE * 6];
/*
* The purpose of the test image type is to track the calls to an image
- * display proc and record the parameters passed in each call. On macOS
- * a display proc must be run inside of the drawRect method of an NSView
- * in order for the graphics operations to have any effect. To deal with
+ * display proc and record the parameters passed in each call. On macOS a
+ * display proc must be run inside of the drawRect method of an NSView in
+ * order for the graphics operations to have any effect. To deal with
* this, whenever a display proc is called outside of any drawRect method
- * it schedules a redraw of the NSView by calling [view setNeedsDisplay:YES].
- * This will trigger a later call to the view's drawRect method which will
- * run the display proc a second time.
+ * it schedules a redraw of the NSView.
*
- * This complicates testing, since it can result in more calls to the display
- * proc than are expected by the test. It can also result in an inconsistent
- * number of calls unless the test waits until the call to drawRect actually
- * occurs before validating its results.
- *
- * In an attempt to work around this, this display proc only logs those
- * calls which occur within a drawRect method. This means that tests must
- * be written so as to ensure that the drawRect method is run before
- * results are validated. In practice it usually suffices to run update
- * idletasks (to run the display proc the first time) followed by update
- * (to run the display proc in drawRect).
- *
- * This also has the consequence that the image changed command will log
- * different results on Aqua than on other systems, because when the image
- * is redisplayed in the drawRect method the entire image will be drawn,
- * not just the changed portion. Tests must account for this.
+ * In an attempt to work around this, each image instance maintains it own
+ * copy of the log message which gets written on the first call to the
+ * display proc. This usually means that the message created on macOS is
+ * the same as that created on other platforms. However it is possible
+ * for the messages to differ for other reasons, namely differences in
+ * how damage regions are computed.
*/
if (LOG_DISPLAY(drawable)) {
- sprintf(buffer, "%s display %d %d %d %d",
- instPtr->masterPtr->imageName, imageX, imageY, width, height);
+ if (instPtr->displayFailed == False) {
+
+ /*
+ * Drawing is possible on the first call to DisplayImage.
+ * Log the message.
+ */
+
+ sprintf(instPtr->buffer, "%s display %d %d %d %d",
+ instPtr->masterPtr->imageName, imageX, imageY, width, height);
+ }
Tcl_SetVar2(instPtr->masterPtr->interp, instPtr->masterPtr->varName,
- NULL, buffer, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
+ NULL, instPtr->buffer,
+ TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
+ instPtr->displayFailed = False;
+ } else {
+
+ /*
+ * Drawing is not possible on the first call to DisplayImage.
+ * Save the message, but do not log it until the actual display.
+ */
+
+ if (instPtr->displayFailed == False) {
+ sprintf(instPtr->buffer, "%s display %d %d %d %d",
+ instPtr->masterPtr->imageName, imageX, imageY, width, height);
+ }
+ instPtr->displayFailed = True;
}
if (width > (instPtr->masterPtr->width - imageX)) {
width = instPtr->masterPtr->width - imageX;