[Vm-dev] [commit][3706] JMM work on full screen mode SK-44.
commits at squeakvm.org
commits at squeakvm.org
Sat May 7 02:54:07 UTC 2016
Revision: 3706
Author: johnmci
Date: 2016-05-06 19:54:05 -0700 (Fri, 06 May 2016)
Log Message:
-----------
JMM work on full screen mode SK-44. Issue was on a screen size change we have to wait for TheDisplay form to change before we can draw again, otherwise we show garbage, or cause a memory violation by running off the end of the squeak bitmap. There are three ways to resize, by resize the window, use of window max/min green dot, and fullscreen primitive. All have different execution paths
Modified Paths:
--------------
branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.h
branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.m
Modified: branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.h
===================================================================
--- branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.h 2016-05-07 01:29:48 UTC (rev 3705)
+++ branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.h 2016-05-07 02:54:05 UTC (rev 3706)
@@ -59,9 +59,7 @@
CGColorSpaceRef colorspace;
unsigned int* colorMap32;
BOOL clippyIsEmpty;
- BOOL fullScreenInProgress;
CGRect clippy;
- void* fullScreendispBitsIndex;
}
@property (nonatomic,assign) NSTrackingRectTag squeakTrackingRectForCursor;
@property (nonatomic,strong) keyBoardStrokeDetails* lastSeenKeyBoardStrokeDetails;
@@ -70,9 +68,8 @@
@property (nonatomic,assign) int dragCount;
@property (nonatomic,strong) NSMutableArray* dragItems;
@property (nonatomic,weak) sqSqueakOSXScreenAndWindow *windowLogic;
- at property (nonatomic,assign) BOOL fullScreenInProgress;
- at property (nonatomic,assign) void* fullScreendispBitsIndex;
+
- (void) initializeVariables;
- (void) fakeKeyDownUp: (NSEvent*) theEvent;
- (NSString*) dragFileNameStringAtIndex:(sqInt) index;
Modified: branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.m
===================================================================
--- branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.m 2016-05-07 01:29:48 UTC (rev 3705)
+++ branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.m 2016-05-07 02:54:05 UTC (rev 3706)
@@ -62,6 +62,12 @@
return [NSString stringWithCharacters: &character length: 1];
}
+ at interface sqSqueakOSXOpenGLView ()
+ at property (nonatomic, assign) NSRect lastFrameSize;
+ at property (nonatomic,assign) BOOL fullScreenInProgress;
+ at property (nonatomic,assign) void* fullScreendispBitsIndex;
+ at end
+
@implementation sqSqueakOSXOpenGLView
@synthesize squeakTrackingRectForCursor,lastSeenKeyBoardStrokeDetails,
lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,dragItems,windowLogic,fullScreenInProgress,fullScreendispBitsIndex;
@@ -79,12 +85,10 @@
- (id)initWithFrame:(NSRect)frameRect {
self = [self initWithFrame:frameRect pixelFormat:[[self class] defaultPixelFormat]];
-
[self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self setAutoresizesSubviews:YES];
[self initialize];
-
return self;
}
@@ -100,14 +104,23 @@
fullScreenInProgress = NO;
colorspace = CGColorSpaceCreateDeviceRGB();
[self initializeSqueakColorMap];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(didEnterFullScreen:) name:@"NSWindowDidEnterFullScreenNotification" object:nil];
+
}
+- (void) didEnterFullScreen: (NSNotification*) aNotification {
+ //NSLog(@"Notification didEnterFullScreen");
+ [self setupFullScreendispBitsIndex];
+ self.fullScreenInProgress = NO;
+}
+
- (void) initializeVariables {
}
- (void) dealloc {
free(colorMap32);
CGColorSpaceRelease(colorspace);
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
SUPERDEALLOC
}
@@ -137,15 +150,16 @@
}
- (void) viewWillStartLiveResize {
-// [self.window setShowsResizeIndicator: YES];
+ //NSLog(@"viewWillStartLiveResize");
+ self.fullScreenInProgress = YES;
[[NSCursor arrowCursor] set];
}
- (void) viewDidEndLiveResize {
-// [self.window setShowsResizeIndicator: NO];
+ //NSLog(@"viewDidEndLiveResize");
dispatch_async(dispatch_get_main_queue(), ^{
[((sqSqueakOSXApplication*) gDelegateApp.squeakApplication).squeakCursor set];
- });
+ });
}
@@ -166,18 +180,8 @@
firstDrawCompleted = YES;
return;
}
-
- if (self.fullScreenInProgress) {
- sqInt formObj = interpreterProxy->displayObject();
- sqInt formPtrOop = interpreterProxy->fetchPointerofObject(0, formObj);
- void* dispBitsIndex = interpreterProxy->firstIndexableField(formPtrOop);
- if (self.fullScreendispBitsIndex == dispBitsIndex) {
- return;
- }
- self.fullScreenInProgress = NO;
- }
-
- if (syncNeeded) {
+
+ if (syncNeeded) {
[self drawRect: NSRectFromCGRect(clippy)];
syncNeeded = NO;
clippyIsEmpty = YES;
@@ -187,6 +191,7 @@
}
if (!firstDrawCompleted) {
firstDrawCompleted = YES;
+ extern sqInt getFullScreenFlag(void);
if (getFullScreenFlag() == 0) {
[self.window makeKeyAndOrderFront: self];
}
@@ -196,6 +201,7 @@
-(void)setupOpenGL {
// CGL_MACRO_DECLARE_VARIABLES();
// Enable the multithreading
+ //NSLog(@"setupOpenGL runs");
CGLContextObj ctx = [[self openGLContext] CGLContextObj];
CGLEnable( ctx, kCGLCEMPEngine);
@@ -237,8 +243,22 @@
// CGL_MACRO_DECLARE_VARIABLES();
static void *previousLastBitsIndex=null;
- NSRect r=[self frame];
- if (!(previousLastBitsIndex == lastBitsIndex)) {
+ NSRect r = self.frame;
+
+ if (!NSEqualRects(_lastFrameSize,r)) {
+ //NSLog(@"old %f %f %f %f new %f %f %f %f",_lastFrameSize.origin.x,_lastFrameSize.origin.y,_lastFrameSize.size.width,_lastFrameSize.size.height,self.frame.origin.x,r.origin.y,r.size.width,r.size.height);
+ _lastFrameSize = r;
+ glPixelStorei( GL_UNPACK_ROW_LENGTH, r.size.width );
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ [[self openGLContext] update];
+ }
+
+ if (!(previousLastBitsIndex == lastBitsIndex)) {
+ //NSLog(@"previousLastBitsIndex %#010x changed to %#010x",previousLastBitsIndex,lastBitsIndex);
previousLastBitsIndex = lastBitsIndex;
glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_ARB, r.size.width*r.size.height*4,lastBitsIndex);
}
@@ -246,7 +266,7 @@
glViewport( subRect.origin.x,subRect.origin.y, subRect.size.width,subRect.size.height );
char *subimg = ((char*)lastBitsIndex) + (unsigned int)(subRect.origin.x + (r.size.height-subRect.origin.y-subRect.size.height)*r.size.width)*4;
glTexImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, subRect.size.width, subRect.size.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, subimg );
- // NSLog(@" draw %f %f %f %f",subRect.origin.x,subRect.origin.y,subRect.size.width,subRect.size.height);
+ //NSLog(@" glTexImage2D %f %f %f %f",subRect.origin.x,subRect.origin.y,subRect.size.width,subRect.size.height);
}
-(void)defineQuad:(NSRect)r
@@ -261,78 +281,37 @@
glEnd();
}
-- (void)update // moved or resized
-{
- NSRect rect;
- NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
-
- [super update];
-
- [[self openGLContext] makeCurrentContext];
-// CGL_MACRO_DECLARE_VARIABLES();
- [[self openGLContext] update];
-
- rect = [self bounds];
-
- glViewport(0, 0, rect.size.width, rect.size.height);
- glPixelStorei( GL_UNPACK_ROW_LENGTH, rect.size.width );
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- [self setNeedsDisplay:true];
-
- if (oldContext != nil) {
- [oldContext makeCurrentContext];
- }
+- (void) setupFullScreendispBitsIndex {
+ sqInt formObj = interpreterProxy->displayObject();
+ sqInt formPtrOop = interpreterProxy->fetchPointerofObject(0, formObj);
+ self.fullScreendispBitsIndex = interpreterProxy->firstIndexableField(formPtrOop);
}
-- (void)reshape // scrolled, moved or resized
+-(void)drawRect:(NSRect)rect
{
+ if (self.fullScreenInProgress) {
+ sqInt formObj = interpreterProxy->displayObject();
+ sqInt formPtrOop = interpreterProxy->fetchPointerofObject(0, formObj);
+ void* dispBitsIndex = interpreterProxy->firstIndexableField(formPtrOop);
+ if (self.fullScreendispBitsIndex == dispBitsIndex) {
+ [self clearScreen];
+ //NSLog(@"drawRect but fullScreenInProgress %f %f %f %f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
+ return;
+ }
+ self.fullScreenInProgress = NO;
+ }
+
+ //NSLog(@" draw %f %f %f %f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
- NSRect rect;
- [super reshape];
-
- [[self openGLContext] makeCurrentContext];
-// CGL_MACRO_DECLARE_VARIABLES();
- [[self openGLContext] update];
-
- rect = [self bounds];
-
- glViewport(0, 0, rect.size.width, rect.size.height);
- glPixelStorei( GL_UNPACK_ROW_LENGTH, rect.size.width );
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- [self setNeedsDisplay:true];
+ [self setupFullScreendispBitsIndex];
- if (oldContext != nil) {
- [oldContext makeCurrentContext];
- }
-}
-
--(void)drawRect:(NSRect)rect
-{
-// NSLog(@" draw %f %f %f %f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
- NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
- sqInt formObj = interpreterProxy->displayObject();
- sqInt formPtrOop = interpreterProxy->fetchPointerofObject(0, formObj);
- self.fullScreendispBitsIndex = interpreterProxy->firstIndexableField(formPtrOop);
-
- static int inited=NO;
if ( fullScreendispBitsIndex ) {
[[self openGLContext] makeCurrentContext];
- if (!inited) {
- [self setupOpenGL];
- inited=YES;
- }
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ [self setupOpenGL];
+ });
[self loadTexturesFrom:fullScreendispBitsIndex subRectangle: rect];
[self defineQuad:rect];
}
@@ -727,6 +706,17 @@
return YES;
}
+- (void) clearScreen {
+ NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
+ [self.openGLContext makeCurrentContext];
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glFlush();
+ if (oldContext != nil) {
+ [oldContext makeCurrentContext];
+ }
+
+}
+
- (void) ioSetFullScreen: (sqInt) fullScreen {
if ([self isInFullScreenMode] == YES && (fullScreen == 1))
More information about the Vm-dev
mailing list