blob: 729839c6a3009f33ad7cb2ca3664f5c2a2162977 [file] [log] [blame]
Jon Hjellee799bad2016-01-11 13:47:11 -08001/*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#import <Foundation/Foundation.h>
12#if TARGET_OS_IPHONE
13#import <GLKit/GLKit.h>
14#else
15#import <AppKit/NSOpenGL.h>
16#endif
17
18NS_ASSUME_NONNULL_BEGIN
19
20@class RTCVideoFrame;
21
22// RTCOpenGLVideoRenderer issues appropriate OpenGL commands to draw a frame to
23// the currently bound framebuffer. Supports OpenGL 3.2 and OpenGLES 2.0. OpenGL
24// framebuffer creation and management should be handled elsewhere using the
25// same context used to initialize this class.
26@interface RTCOpenGLVideoRenderer : NSObject
27
28// The last successfully drawn frame. Used to avoid drawing frames unnecessarily
29// hence saving battery life by reducing load.
30@property(nonatomic, readonly) RTCVideoFrame *lastDrawnFrame;
31
32#if TARGET_OS_IPHONE
33- (instancetype)initWithContext:(EAGLContext *)context
34 NS_DESIGNATED_INITIALIZER;
35#else
36- (instancetype)initWithContext:(NSOpenGLContext *)context
37 NS_DESIGNATED_INITIALIZER;
38#endif
39
40// Draws |frame| onto the currently bound OpenGL framebuffer. |setupGL| must be
41// called before this function will succeed.
42- (BOOL)drawFrame:(RTCVideoFrame *)frame;
43
44// The following methods are used to manage OpenGL resources. On iOS
45// applications should release resources when placed in background for use in
46// the foreground application. In fact, attempting to call OpenGLES commands
47// while in background will result in application termination.
48
49// Sets up the OpenGL state needed for rendering.
50- (void)setupGL;
51// Tears down the OpenGL state created by |setupGL|.
52- (void)teardownGL;
53
54- (instancetype)init NS_UNAVAILABLE;
55
56@end
57
58NS_ASSUME_NONNULL_END