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