blob: 7041861014a506be70ed6e1e9415f79111a3e477 [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
tkchin9eeb6242016-04-27 01:54:20 -070018#import "WebRTC/RTCMacros.h"
tkchin8b577ed2016-04-19 10:04:41 -070019
Jon Hjellee799bad2016-01-11 13:47:11 -080020NS_ASSUME_NONNULL_BEGIN
21
22@class RTCVideoFrame;
23
24// RTCOpenGLVideoRenderer issues appropriate OpenGL commands to draw a frame to
25// the currently bound framebuffer. Supports OpenGL 3.2 and OpenGLES 2.0. OpenGL
26// framebuffer creation and management should be handled elsewhere using the
27// same context used to initialize this class.
tkchin8b577ed2016-04-19 10:04:41 -070028RTC_EXPORT
Jon Hjellee799bad2016-01-11 13:47:11 -080029@interface RTCOpenGLVideoRenderer : NSObject
30
31// The last successfully drawn frame. Used to avoid drawing frames unnecessarily
32// hence saving battery life by reducing load.
33@property(nonatomic, readonly) RTCVideoFrame *lastDrawnFrame;
34
35#if TARGET_OS_IPHONE
36- (instancetype)initWithContext:(EAGLContext *)context
37 NS_DESIGNATED_INITIALIZER;
38#else
39- (instancetype)initWithContext:(NSOpenGLContext *)context
40 NS_DESIGNATED_INITIALIZER;
41#endif
42
43// Draws |frame| onto the currently bound OpenGL framebuffer. |setupGL| must be
44// called before this function will succeed.
45- (BOOL)drawFrame:(RTCVideoFrame *)frame;
46
47// The following methods are used to manage OpenGL resources. On iOS
48// applications should release resources when placed in background for use in
49// the foreground application. In fact, attempting to call OpenGLES commands
50// while in background will result in application termination.
51
52// Sets up the OpenGL state needed for rendering.
53- (void)setupGL;
54// Tears down the OpenGL state created by |setupGL|.
55- (void)teardownGL;
56
57- (instancetype)init NS_UNAVAILABLE;
58
59@end
60
61NS_ASSUME_NONNULL_END