OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <map> | |
12 #include <queue> | |
13 #include <vector> | |
14 | |
15 #include "base/cancelable_callback.h" | |
16 #include "base/macros.h" | |
17 #include "base/time/time.h" | |
18 #include "build/build_config.h" | |
19 #include "ui/gfx/geometry/rect.h" | |
20 #include "ui/gfx/geometry/size.h" | |
21 #include "ui/gl/gl_bindings.h" | |
22 #include "ui/gl/gl_context.h" | |
23 #include "ui/gl/gl_surface.h" | |
24 | |
25 namespace base { | |
26 class MessageLoop; | |
27 class WaitableEvent; | |
28 } | |
29 | |
30 namespace ui { | |
31 class DisplayConfigurator; | |
32 } | |
33 | |
34 namespace content { | |
35 | |
36 class VideoFrameTexture : public base::RefCounted<VideoFrameTexture> { | |
37 public: | |
38 uint32_t texture_id() const { return texture_id_; } | |
39 uint32_t texture_target() const { return texture_target_; } | |
40 | |
41 VideoFrameTexture(uint32_t texture_target, | |
42 uint32_t texture_id, | |
43 const base::Closure& no_longer_needed_cb); | |
44 | |
45 private: | |
46 friend class base::RefCounted<VideoFrameTexture>; | |
47 | |
48 uint32_t texture_target_; | |
49 uint32_t texture_id_; | |
50 base::Closure no_longer_needed_cb_; | |
51 | |
52 ~VideoFrameTexture(); | |
53 }; | |
54 | |
55 struct RenderingHelperParams { | |
56 RenderingHelperParams(); | |
57 RenderingHelperParams(const RenderingHelperParams& other); | |
58 ~RenderingHelperParams(); | |
59 | |
60 // The rendering FPS. | |
61 int rendering_fps; | |
62 | |
63 // The number of empty frames rendered when the rendering helper is | |
64 // initialized. | |
65 int warm_up_iterations; | |
66 | |
67 // The desired size of each window. We play each stream in its own window | |
68 // on the screen. | |
69 std::vector<gfx::Size> window_sizes; | |
70 | |
71 // The members below are only used for the thumbnail mode where all frames | |
72 // are rendered in sequence onto one FBO for comparison/verification purposes. | |
73 | |
74 // Whether the frames are rendered as scaled thumbnails within a | |
75 // larger FBO that is in turn rendered to the window. | |
76 bool render_as_thumbnails; | |
77 // The size of the FBO containing all visible thumbnails. | |
78 gfx::Size thumbnails_page_size; | |
79 // The size of each thumbnail within the FBO. | |
80 gfx::Size thumbnail_size; | |
81 }; | |
82 | |
83 // Creates and draws textures used by the video decoder. | |
84 // This class is not thread safe and thus all the methods of this class | |
85 // (except for ctor/dtor) ensure they're being run on a single thread. | |
86 class RenderingHelper { | |
87 public: | |
88 | |
89 RenderingHelper(); | |
90 ~RenderingHelper(); | |
91 | |
92 // Initialize GL. This method must be called on the rendering | |
93 // thread. | |
94 static void InitializeOneOff(base::WaitableEvent* done); | |
95 | |
96 // Setup the platform window to display test results. This method | |
97 // must be called on the main thread. | |
98 void Setup(); | |
99 | |
100 // Tear down the platform window. This method must be called on the | |
101 // main thread. | |
102 void TearDown(); | |
103 | |
104 // Create the render context and windows by the specified | |
105 // dimensions. This method must be called on the rendering thread. | |
106 void Initialize(const RenderingHelperParams& params, | |
107 base::WaitableEvent* done); | |
108 | |
109 // Undo the effects of Initialize() and signal |*done|. This method | |
110 // must be called on the rendering thread. | |
111 void UnInitialize(base::WaitableEvent* done); | |
112 | |
113 // Return a newly-created GLES2 texture id of the specified size, and | |
114 // signal |*done|. | |
115 void CreateTexture(uint32_t texture_target, | |
116 uint32_t* texture_id, | |
117 const gfx::Size& size, | |
118 base::WaitableEvent* done); | |
119 | |
120 // Render thumbnail in the |texture_id| to the FBO buffer using target | |
121 // |texture_target|. | |
122 void RenderThumbnail(uint32_t texture_target, uint32_t texture_id); | |
123 | |
124 // Queues the |video_frame| for rendering. | |
125 void QueueVideoFrame(size_t window_id, | |
126 scoped_refptr<VideoFrameTexture> video_frame); | |
127 | |
128 // Flushes the pending frames. Notify the rendering_helper there won't be | |
129 // more video frames. | |
130 void Flush(size_t window_id); | |
131 | |
132 // Delete |texture_id|. | |
133 void DeleteTexture(uint32_t texture_id); | |
134 | |
135 // Get the platform specific handle to the OpenGL display. | |
136 void* GetGLDisplay(); | |
137 | |
138 // Get the GL context. | |
139 gfx::GLContext* GetGLContext(); | |
140 | |
141 // Get rendered thumbnails as RGB. | |
142 // Sets alpha_solid to true if the alpha channel is entirely 0xff. | |
143 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | |
144 bool* alpha_solid, | |
145 base::WaitableEvent* done); | |
146 | |
147 private: | |
148 struct RenderedVideo { | |
149 // The rect on the screen where the video will be rendered. | |
150 gfx::Rect render_area; | |
151 | |
152 // True if there won't be any new video frames comming. | |
153 bool is_flushing; | |
154 | |
155 // The number of frames need to be dropped to catch up the rendering. We | |
156 // always keep the last remaining frame in pending_frames even after it | |
157 // has been rendered, so that we have something to display if the client | |
158 // is falling behind on providing us with new frames during timer-driven | |
159 // playback. | |
160 int frames_to_drop; | |
161 | |
162 // The video frames pending for rendering. | |
163 std::queue<scoped_refptr<VideoFrameTexture> > pending_frames; | |
164 | |
165 RenderedVideo(); | |
166 RenderedVideo(const RenderedVideo& other); | |
167 ~RenderedVideo(); | |
168 }; | |
169 | |
170 void Clear(); | |
171 | |
172 void RenderContent(); | |
173 | |
174 void WarmUpRendering(int warm_up_iterations); | |
175 | |
176 void LayoutRenderingAreas(const std::vector<gfx::Size>& window_sizes); | |
177 | |
178 void UpdateVSyncParameters(base::WaitableEvent* done, | |
179 const base::TimeTicks timebase, | |
180 const base::TimeDelta interval); | |
181 | |
182 void DropOneFrameForAllVideos(); | |
183 void ScheduleNextRenderContent(); | |
184 | |
185 // Render |texture_id| to the current view port of the screen using target | |
186 // |texture_target|. | |
187 void RenderTexture(uint32_t texture_target, uint32_t texture_id); | |
188 | |
189 base::MessageLoop* message_loop_; | |
190 | |
191 scoped_refptr<gfx::GLContext> gl_context_; | |
192 scoped_refptr<gfx::GLSurface> gl_surface_; | |
193 | |
194 #if defined(USE_OZONE) | |
195 class StubOzoneDelegate; | |
196 std::unique_ptr<StubOzoneDelegate> platform_window_delegate_; | |
197 | |
198 #if defined(OS_CHROMEOS) | |
199 std::unique_ptr<ui::DisplayConfigurator> display_configurator_; | |
200 #endif | |
201 #endif | |
202 | |
203 bool ignore_vsync_; | |
204 | |
205 gfx::AcceleratedWidget window_; | |
206 | |
207 gfx::Size screen_size_; | |
208 | |
209 std::vector<RenderedVideo> videos_; | |
210 | |
211 bool render_as_thumbnails_; | |
212 int frame_count_; | |
213 GLuint thumbnails_fbo_id_; | |
214 GLuint thumbnails_texture_id_; | |
215 gfx::Size thumbnails_fbo_size_; | |
216 gfx::Size thumbnail_size_; | |
217 GLuint program_; | |
218 base::TimeDelta frame_duration_; | |
219 base::TimeTicks scheduled_render_time_; | |
220 base::CancelableClosure render_task_; | |
221 base::TimeTicks vsync_timebase_; | |
222 base::TimeDelta vsync_interval_; | |
223 | |
224 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); | |
225 }; | |
226 | |
227 } // namespace content | |
228 | |
229 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | |
OLD | NEW |