blob: a3b9b5c8c3e225019a7be8679348c386e20033fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#import "ContextUpdater.h"
#import <pthread.h>
#define VERBOSE_ON 1
#ifdef VERBOSE_ON
#define DBG_PRINT(...) NSLog(@ __VA_ARGS__)
// #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
#else
#define DBG_PRINT(...)
#endif
#ifndef CGL_VERSION_1_3
#warning this SDK doesn't support OpenGL profile
#endif
@implementation ContextUpdater
{
}
- (void) update:(NSNotification *)notification
{
pthread_mutex_lock(&resourceLock);
NSRect r = [view frame];
if(viewRect.origin.x != r.origin.x ||
viewRect.origin.y != r.origin.y ||
viewRect.size.width != r.size.width ||
viewRect.size.height != r.size.height) {
viewUpdated = TRUE;
viewRect = r;
}
pthread_mutex_unlock(&resourceLock);
}
- (BOOL) needsUpdate
{
BOOL r;
pthread_mutex_lock(&resourceLock);
r = viewUpdated;
viewUpdated = FALSE;
pthread_mutex_unlock(&resourceLock);
return r;
}
- (id) initWithContext:(NSOpenGLContext *)context view: (NSView *)nsView
{
DBG_PRINT("ContextUpdater::init.0 view %p, ctx %p\n", view, ctx);
pthread_mutex_init(&resourceLock, NULL); // fast non-recursive
ctx = context;
view = nsView;
[ctx retain];
[view retain];
viewRect = [view frame];
viewUpdated = TRUE;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:NSViewGlobalFrameDidChangeNotification object: view];
DBG_PRINT("ContextUpdater::init.X\n");
return [super init];
}
- (void) dealloc
{
DBG_PRINT("ContextUpdater::dealloc.0 view %p, ctx %p\n", view, ctx);
[[NSNotificationCenter defaultCenter] removeObserver:self];
[view release];
[ctx release];
pthread_mutex_destroy(&resourceLock);
DBG_PRINT("ContextUpdater::dealloc.X\n");
[super dealloc];
}
@end
|