OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 - (id)initWithTitle:(NSString *)title width:(int)width height:(int)height { | 37 - (id)initWithTitle:(NSString *)title width:(int)width height:(int)height { |
38 if (self = [super init]) { | 38 if (self = [super init]) { |
39 title_ = title; | 39 title_ = title; |
40 width_ = width; | 40 width_ = width; |
41 height_ = height; | 41 height_ = height; |
42 } | 42 } |
43 return self; | 43 return self; |
44 } | 44 } |
45 | 45 |
46 - (void)dealloc { | |
47 [window_ release]; | |
48 [super dealloc]; | |
49 } | |
50 | |
51 - (void)createWindow:(NSObject *)ignored { | 46 - (void)createWindow:(NSObject *)ignored { |
52 NSInteger xOrigin = nextXOrigin_; | 47 NSInteger xOrigin = nextXOrigin_; |
53 NSRect screenFrame = [[NSScreen mainScreen] frame]; | 48 NSRect screenFrame = [[NSScreen mainScreen] frame]; |
54 if (nextXOrigin_ + width_ < screenFrame.size.width) { | 49 if (nextXOrigin_ + width_ < screenFrame.size.width) { |
55 nextXOrigin_ += width_; | 50 nextXOrigin_ += width_; |
56 } else { | 51 } else { |
57 xOrigin = 0; | 52 xOrigin = 0; |
58 nextXOrigin_ = 0; | 53 nextXOrigin_ = 0; |
59 nextYOrigin_ += height_; | 54 nextYOrigin_ += height_; |
60 } | 55 } |
61 if (nextYOrigin_ + height_ > screenFrame.size.height) { | 56 if (nextYOrigin_ + height_ > screenFrame.size.height) { |
62 xOrigin = 0; | 57 xOrigin = 0; |
63 nextXOrigin_ = 0; | 58 nextXOrigin_ = 0; |
64 nextYOrigin_ = 0; | 59 nextYOrigin_ = 0; |
65 } | 60 } |
66 NSInteger yOrigin = nextYOrigin_; | 61 NSInteger yOrigin = nextYOrigin_; |
67 NSRect windowFrame = NSMakeRect(xOrigin, yOrigin, width_, height_); | 62 NSRect windowFrame = NSMakeRect(xOrigin, yOrigin, width_, height_); |
68 window_ = [[NSWindow alloc] initWithContentRect:windowFrame | 63 window_ = [[NSWindow alloc] initWithContentRect:windowFrame |
69 styleMask:NSTitledWindowMask | 64 styleMask:NSTitledWindowMask |
70 backing:NSBackingStoreBuffered | 65 backing:NSBackingStoreBuffered |
71 defer:NO]; | 66 defer:NO]; |
72 | 67 |
73 NSRect viewFrame = NSMakeRect(0, 0, width_, height_); | 68 NSRect viewFrame = NSMakeRect(0, 0, width_, height_); |
74 NSOpenGLView *view = [[[NSOpenGLView alloc] initWithFrame:viewFrame | 69 NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:viewFrame |
75 pixelFormat:nil] autorelease]; | 70 pixelFormat:nil]; |
76 context_ = [view openGLContext]; | 71 context_ = [view openGLContext]; |
77 | 72 |
78 [[window_ contentView] addSubview:view]; | 73 [[window_ contentView] addSubview:view]; |
79 [window_ setTitle:title_]; | 74 [window_ setTitle:title_]; |
80 [window_ makeKeyAndOrderFront:NSApp]; | 75 [window_ makeKeyAndOrderFront:NSApp]; |
81 } | 76 } |
82 | 77 |
83 - (void)makeCurrentContext { | 78 - (void)makeCurrentContext { |
84 [context_ makeCurrentContext]; | 79 [context_ makeCurrentContext]; |
85 } | 80 } |
(...skipping 12 matching lines...) Expand all Loading... |
98 return NULL; | 93 return NULL; |
99 } | 94 } |
100 return renderer; | 95 return renderer; |
101 } | 96 } |
102 | 97 |
103 MacRenderer::MacRenderer() | 98 MacRenderer::MacRenderer() |
104 : window_(NULL) {} | 99 : window_(NULL) {} |
105 | 100 |
106 MacRenderer::~MacRenderer() { | 101 MacRenderer::~MacRenderer() { |
107 GlRenderer::Destroy(); | 102 GlRenderer::Destroy(); |
108 [window_ release]; | |
109 } | 103 } |
110 | 104 |
111 bool MacRenderer::Init(const char* window_title, int width, int height) { | 105 bool MacRenderer::Init(const char* window_title, int width, int height) { |
112 window_ = [[CocoaWindow alloc] | 106 window_ = [[CocoaWindow alloc] |
113 initWithTitle:[NSString stringWithUTF8String:window_title] | 107 initWithTitle:[NSString stringWithUTF8String:window_title] |
114 width:width | 108 width:width |
115 height:height]; | 109 height:height]; |
116 if (!window_) | 110 if (!window_) |
117 return false; | 111 return false; |
118 [window_ performSelectorOnMainThread:@selector(createWindow:) | 112 [window_ performSelectorOnMainThread:@selector(createWindow:) |
119 withObject:nil | 113 withObject:nil |
120 waitUntilDone:YES]; | 114 waitUntilDone:YES]; |
121 | 115 |
122 [window_ makeCurrentContext]; | 116 [window_ makeCurrentContext]; |
123 GlRenderer::Init(); | 117 GlRenderer::Init(); |
124 GlRenderer::ResizeViewport(width, height); | 118 GlRenderer::ResizeViewport(width, height); |
125 return true; | 119 return true; |
126 } | 120 } |
127 | 121 |
128 void MacRenderer::OnFrame(const VideoFrame& frame) { | 122 void MacRenderer::OnFrame(const VideoFrame& frame) { |
129 [window_ makeCurrentContext]; | 123 [window_ makeCurrentContext]; |
130 GlRenderer::OnFrame(frame); | 124 GlRenderer::OnFrame(frame); |
131 } | 125 } |
132 | 126 |
133 } // test | 127 } // test |
134 } // webrtc | 128 } // webrtc |
OLD | NEW |