1 /*
2  *  Copyright (c) 2013 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 #ifndef WEBRTC_MODULES_VIDEO_RENDER_IOS_VIDEO_RENDER_IOS_GLES20_H_
12 #define WEBRTC_MODULES_VIDEO_RENDER_IOS_VIDEO_RENDER_IOS_GLES20_H_
13 
14 #include <list>
15 #include <map>
16 
17 #include "webrtc/base/platform_thread.h"
18 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/modules/video_render/ios/video_render_ios_channel.h"
20 #include "webrtc/modules/video_render/ios/video_render_ios_view.h"
21 
22 namespace webrtc {
23 
24 class CriticalSectionWrapper;
25 class EventTimerWrapper;
26 
27 class VideoRenderIosGles20 {
28  public:
29   VideoRenderIosGles20(VideoRenderIosView* view,
30                        bool full_screen,
31                        int render_id);
32   virtual ~VideoRenderIosGles20();
33 
34   int Init();
35   VideoRenderIosChannel* CreateEaglChannel(int channel,
36                                            int z_order,
37                                            float left,
38                                            float top,
39                                            float right,
40                                            float bottom);
41   int DeleteEaglChannel(int channel);
42   bool HasChannel(int channel);
43   bool ScreenUpdateProcess();
44   int GetWindowRect(Rect& rect);  // NOLINT
45 
46   int GetScreenResolution(uint& screen_width, uint& screen_height);  // NOLINT
47   int SetStreamCropping(const uint stream_id,
48                         const float left,
49                         const float top,
50                         const float right,
51                         const float bottom);
52 
53   int ChangeWindow(void* new_window);
54   int StartRender();
55   int StopRender();
56 
57  protected:
58   static bool ScreenUpdateThreadProc(void* obj);
59 
60  private:
61   bool RenderOffScreenBuffers();
62   int SwapAndDisplayBuffers();
63 
64  private:
65   rtc::scoped_ptr<CriticalSectionWrapper> gles_crit_sec_;
66   EventTimerWrapper* screen_update_event_;
67   // TODO(pbos): Remove scoped_ptr and use member directly.
68   rtc::scoped_ptr<rtc::PlatformThread> screen_update_thread_;
69 
70   VideoRenderIosView* view_;
71   Rect window_rect_;
72   int window_width_;
73   int window_height_;
74   bool is_full_screen_;
75   GLint backing_width_;
76   GLint backing_height_;
77   GLuint view_renderbuffer_;
78   GLuint view_framebuffer_;
79   GLuint depth_renderbuffer_;
80   std::map<int, VideoRenderIosChannel*> agl_channels_;
81   std::multimap<int, int> z_order_to_channel_;
82   EAGLContext* gles_context_;
83   bool is_rendering_;
84 };
85 }  // namespace webrtc
86 
87 #endif  // WEBRTC_MODULES_VIDEO_RENDER_IOS_VIDEO_RENDER_IOS_GLES20_H_
88