Tk Source Code

Check-in [b78b2657]
Login
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make setFrameSize a tiny bit more efficient.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | cgimage_with_crossing
Files: files | file ages | folders
SHA3-256: b78b26572000ee4127b83e4584bc2752476b815b09dfb05de797a435e0ffd7ef
User & Date: culler 2024-06-22 02:29:26
Context
2024-06-22
04:35
Even small speedups cause test failures. check-in: ff074276 user: culler tags: cgimage_with_crossing
02:29
Make setFrameSize a tiny bit more efficient. check-in: b78b2657 user: culler tags: cgimage_with_crossing
2024-06-19
21:29
Remove duplicate calls to reset the cgimage backing layer. check-in: b7d0a5b9 user: culler tags: cgimage_with_crossing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXWindowEvent.c.

978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003
}

- (BOOL) wantsUpdateLayer
{
    return YES;
}
- (void) updateLayer {
    CGContextRef ctx = self.tkLayerBitmapContext;

    if (ctx) {
	/*
	 * Create a CGImage by copying (probably using copy-on-write) the
	 * bitmap data of the CGBitmapContext that we have been using for
	 * drawing.  Then render that CGImage into the CALayer of this view by
	 * assigning a reference to the CGImage to the contents property of the
	 * layer. This will cause all drawing done since the last call to this
	 * function to become visible.
	 */

	CGImageRef newImg = CGBitmapContextCreateImage(ctx);
	self.layer.contents = (__bridge id) newImg;
	CGImageRelease(newImg); // will quickly leak memory if this is missing
	[self clearTkDirtyRect];
    }
}

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070







|

|








>
|







978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
}

- (BOOL) wantsUpdateLayer
{
    return YES;
}
- (void) updateLayer {
    CGContextRef context = self.tkLayerBitmapContext;

    if (context) {
	/*
	 * Create a CGImage by copying (probably using copy-on-write) the
	 * bitmap data of the CGBitmapContext that we have been using for
	 * drawing.  Then render that CGImage into the CALayer of this view by
	 * assigning a reference to the CGImage to the contents property of the
	 * layer. This will cause all drawing done since the last call to this
	 * function to become visible.
	 */

	CGImageRef newImg = CGBitmapContextCreateImage(context);
	self.layer.contents = (__bridge id) newImg;
	CGImageRelease(newImg); // will quickly leak memory if this is missing
	[self clearTkDirtyRect];
    }
}

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
1028
1029
1030
1031
1032
1033
1034

1035




1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
{
    _tkNeedsDisplay = NO;
    _tkDirtyRect = NSZeroRect;
}

-(void) setFrameSize: (NSSize)newsize
{

    [super setFrameSize: newsize];




    NSWindow *w = [self window];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    Tk_Window tkwin = (Tk_Window)winPtr;

    if (winPtr) {
	unsigned int width = (unsigned int)newsize.width;
	unsigned int height=(unsigned int)newsize.height;
	void *oldArg;
    	Tk_RestrictProc *oldProc;

	/*
	 * This function can be re-entered.  So we need to make sure we don't
	 * clobber any AutoreleasePool set up by the caller.
	 */

	[NSApp _lockAutoreleasePool];

	 /*
	  * Generate and handle a ConfigureNotify event for the new size.
	  */

	TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height,
		TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
    	oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg);
	while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {}
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);


	/*
	 * Update Tk's window data for the new size.
	 */
	
	if ([w respondsToSelector: @selector (tkLayoutChanged)]) {
	    [(TKWindow *)w tkLayoutChanged];
	}

	/*
	 * Reset the cgimage layer and redraw the entire content view.
	 */

	[self viewDidChangeBackingProperties];

	/*
	 * In live resize we seem to need to draw a second time to
	 * avoid artifacts.
	 */
	
	if ([self inLiveResize]) {
	    [self generateExposeEvents:self.bounds];
	}

	/*
	 * Finally, unlock the main autoreleasePool.
	 */

	[NSApp _unlockAutoreleasePool];

    }

    /*
     * Schedule a redisplay of the view.
     */

    [self setNeedsDisplay:YES];

}

/*
 * Core method of this class: generates expose events for redrawing.  The
 * expose events are immediately removed from the Tcl event loop and processed.
 * This causes drawing procedures to be scheduled as idle events.  Then all
 * pending idle events are processed so the drawing will actually take place.







>

>
>
>
>





|
|




|



















|














|













|



<







1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
{
    _tkNeedsDisplay = NO;
    _tkDirtyRect = NSZeroRect;
}

-(void) setFrameSize: (NSSize)newsize
{
    NSSize oldsize = self.bounds.size;
    [super setFrameSize: newsize];
    if (newsize.width == 1 && newsize.height == 1 ||
	oldsize.width == 0 && oldsize.height == 0) {
	return;
    }
    NSWindow *w = [self window];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    Tk_Window tkwin = (Tk_Window)winPtr;

    if (winPtr) {
	unsigned int width = (unsigned int) newsize.width;
	unsigned int height= (unsigned int) newsize.height;
	void *oldArg;
    	Tk_RestrictProc *oldProc;

	/*
	 * This function can be re-entered, so we need to make sure we don't
	 * clobber any AutoreleasePool set up by the caller.
	 */

	[NSApp _lockAutoreleasePool];

	 /*
	  * Generate and handle a ConfigureNotify event for the new size.
	  */

	TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height,
		TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
    	oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg);
	while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {}
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);


	/*
	 * Update Tk's window data for the new size.
	 */

	if ([w respondsToSelector: @selector (tkLayoutChanged)]) {
	    [(TKWindow *)w tkLayoutChanged];
	}

	/*
	 * Reset the cgimage layer and redraw the entire content view.
	 */

	[self viewDidChangeBackingProperties];

	/*
	 * In live resize we seem to need to draw a second time to
	 * avoid artifacts.
	 */

	if ([self inLiveResize]) {
	    [self generateExposeEvents:self.bounds];
	}

	/*
	 * Finally, unlock the main autoreleasePool.
	 */

	[NSApp _unlockAutoreleasePool];

    }

    /*
     * Request a call to updateLayer.
     */

    [self setNeedsDisplay:YES];

}

/*
 * Core method of this class: generates expose events for redrawing.  The
 * expose events are immediately removed from the Tcl event loop and processed.
 * This causes drawing procedures to be scheduled as idle events.  Then all
 * pending idle events are processed so the drawing will actually take place.