OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2011 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 #include "webrtc/engine_configurations.h" | |
12 | |
13 #if defined(CARBON_RENDERING) | |
14 | |
15 #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_ | |
16 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_ | |
17 | |
18 #include "webrtc/base/platform_thread.h" | |
19 #include "webrtc/modules/video_render/video_render_defines.h" | |
20 | |
21 #define NEW_HIVIEW_PARENT_EVENT_HANDLER 1 | |
22 #define NEW_HIVIEW_EVENT_HANDLER 1 | |
23 #define USE_STRUCT_RGN | |
24 | |
25 #include <AGL/agl.h> | |
26 #include <Carbon/Carbon.h> | |
27 #include <OpenGL/OpenGL.h> | |
28 #include <OpenGL/glext.h> | |
29 #include <OpenGL/glu.h> | |
30 #include <list> | |
31 #include <map> | |
32 #include <memory> | |
33 | |
34 class VideoRenderAGL; | |
35 | |
36 namespace webrtc { | |
37 class CriticalSectionWrapper; | |
38 class EventWrapper; | |
39 | |
40 class VideoChannelAGL : public VideoRenderCallback { | |
41 public: | |
42 | |
43 VideoChannelAGL(AGLContext& aglContext, int iId, VideoRenderAGL* owner); | |
44 virtual ~VideoChannelAGL(); | |
45 virtual int FrameSizeChange(int width, int height, int numberOfStreams); | |
46 virtual int DeliverFrame(const VideoFrame& videoFrame); | |
47 virtual int UpdateSize(int width, int height); | |
48 int SetStreamSettings(int streamId, float startWidth, float startHeight, | |
49 float stopWidth, float stopHeight); | |
50 int SetStreamCropSettings(int streamId, float startWidth, float startHeight, | |
51 float stopWidth, float stopHeight); | |
52 int RenderOffScreenBuffer(); | |
53 int IsUpdated(bool& isUpdated); | |
54 virtual int UpdateStretchSize(int stretchHeight, int stretchWidth); | |
55 virtual int32_t RenderFrame(const uint32_t streamId, VideoFrame& videoFrame); | |
56 | |
57 private: | |
58 | |
59 AGLContext _aglContext; | |
60 int _id; | |
61 VideoRenderAGL* _owner; | |
62 int _width; | |
63 int _height; | |
64 int _stretchedWidth; | |
65 int _stretchedHeight; | |
66 float _startHeight; | |
67 float _startWidth; | |
68 float _stopWidth; | |
69 float _stopHeight; | |
70 int _xOldWidth; | |
71 int _yOldHeight; | |
72 int _oldStretchedHeight; | |
73 int _oldStretchedWidth; | |
74 unsigned char* _buffer; | |
75 size_t _bufferSize; | |
76 size_t _incomingBufferSize; | |
77 bool _bufferIsUpdated; | |
78 bool _sizeInitialized; | |
79 int _numberOfStreams; | |
80 bool _bVideoSizeStartedChanging; | |
81 GLenum _pixelFormat; | |
82 GLenum _pixelDataType; | |
83 unsigned int _texture; | |
84 }; | |
85 | |
86 class VideoRenderAGL { | |
87 public: | |
88 VideoRenderAGL(WindowRef windowRef, bool fullscreen, int iId); | |
89 VideoRenderAGL(HIViewRef windowRef, bool fullscreen, int iId); | |
90 ~VideoRenderAGL(); | |
91 | |
92 int Init(); | |
93 VideoChannelAGL* CreateAGLChannel(int channel, int zOrder, float startWidth, | |
94 float startHeight, float stopWidth, | |
95 float stopHeight); | |
96 VideoChannelAGL* ConfigureAGLChannel(int channel, int zOrder, | |
97 float startWidth, float startHeight, | |
98 float stopWidth, float stopHeight); | |
99 int DeleteAGLChannel(int channel); | |
100 int DeleteAllAGLChannels(); | |
101 int StopThread(); | |
102 bool IsFullScreen(); | |
103 bool HasChannels(); | |
104 bool HasChannel(int channel); | |
105 int GetChannels(std::list<int>& channelList); | |
106 void LockAGLCntx(); | |
107 void UnlockAGLCntx(); | |
108 | |
109 static int GetOpenGLVersion(int& aglMajor, int& aglMinor); | |
110 | |
111 // ********** new module functions ************ // | |
112 int ChangeWindow(void* newWindowRef); | |
113 int32_t StartRender(); | |
114 int32_t StopRender(); | |
115 int32_t DeleteAGLChannel(const uint32_t streamID); | |
116 int32_t GetChannelProperties(const uint16_t streamId, uint32_t& zOrder, | |
117 float& left, float& top, float& right, | |
118 float& bottom); | |
119 | |
120 protected: | |
121 static bool ScreenUpdateThreadProc(void* obj); | |
122 bool ScreenUpdateProcess(); | |
123 int GetWindowRect(Rect& rect); | |
124 | |
125 private: | |
126 int CreateMixingContext(); | |
127 int RenderOffScreenBuffers(); | |
128 int SwapAndDisplayBuffers(); | |
129 int UpdateClipping(); | |
130 int CalculateVisibleRegion(ControlRef control, RgnHandle& visibleRgn, | |
131 bool clipChildren); | |
132 bool CheckValidRegion(RgnHandle rHandle); | |
133 void ParentWindowResized(WindowRef window); | |
134 | |
135 // Carbon GUI event handlers | |
136 static pascal OSStatus sHandleWindowResized( | |
137 EventHandlerCallRef nextHandler, EventRef theEvent, void* userData); | |
138 static pascal OSStatus sHandleHiViewResized( | |
139 EventHandlerCallRef nextHandler, EventRef theEvent, void* userData); | |
140 | |
141 HIViewRef _hiviewRef; | |
142 WindowRef _windowRef; | |
143 bool _fullScreen; | |
144 int _id; | |
145 webrtc::CriticalSectionWrapper& _renderCritSec; | |
146 // TODO(pbos): Remove unique_ptr and use PlatformThread directly. | |
147 std::unique_ptr<rtc::PlatformThread> _screenUpdateThread; | |
148 webrtc::EventWrapper* _screenUpdateEvent; | |
149 bool _isHIViewRef; | |
150 AGLContext _aglContext; | |
151 int _windowWidth; | |
152 int _windowHeight; | |
153 int _lastWindowWidth; | |
154 int _lastWindowHeight; | |
155 int _lastHiViewWidth; | |
156 int _lastHiViewHeight; | |
157 int _currentParentWindowHeight; | |
158 int _currentParentWindowWidth; | |
159 Rect _currentParentWindowBounds; | |
160 bool _windowHasResized; | |
161 Rect _lastParentWindowBounds; | |
162 Rect _currentHIViewBounds; | |
163 Rect _lastHIViewBounds; | |
164 Rect _windowRect; | |
165 std::map<int, VideoChannelAGL*> _aglChannels; | |
166 std::multimap<int, int> _zOrderToChannel; | |
167 EventHandlerRef _hiviewEventHandlerRef; | |
168 EventHandlerRef _windowEventHandlerRef; | |
169 HIRect _currentViewBounds; | |
170 HIRect _lastViewBounds; | |
171 bool _renderingIsPaused; | |
172 }; | |
173 | |
174 } // namespace webrtc | |
175 | |
176 #endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_ | |
177 | |
178 #endif // CARBON_RENDERING | |
OLD | NEW |