OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 #include "ui/gl/gl_bindings.h" | 17 #include "ui/gl/gl_bindings.h" |
17 #include "ui/gl/gl_context.h" | 18 #include "ui/gl/gl_context.h" |
18 #include "ui/gl/gl_surface.h" | 19 #include "ui/gl/gl_surface.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class MessageLoop; | 22 class MessageLoop; |
22 class WaitableEvent; | 23 class WaitableEvent; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 | 27 |
27 struct RenderingHelperParams; | 28 class VideoFrameTexture : public base::RefCounted<VideoFrameTexture> { |
29 public: | |
30 uint32 texture_id() const { return texture_id_; } | |
31 uint32 texture_target() const { return texture_target_; } | |
32 | |
33 VideoFrameTexture(uint32 texture_target, | |
34 uint32 texture_id, | |
35 const base::Closure& no_longer_needed_cb); | |
36 ~VideoFrameTexture(); | |
37 | |
38 private: | |
39 uint32 texture_target_; | |
40 uint32 texture_id_; | |
41 base::Closure no_longer_needed_cb_; | |
42 }; | |
43 | |
44 struct RenderingHelperParams { | |
45 RenderingHelperParams(); | |
46 ~RenderingHelperParams(); | |
47 | |
48 // The rendering FPS. | |
49 int rendering_fps; | |
50 | |
51 // The desired size of each window. We play each stream in its own window | |
52 // on the screen. | |
53 std::vector<gfx::Size> window_sizes; | |
54 | |
55 // The members below are only used for the thumbnail mode where all frames | |
56 // are rendered in sequence onto one FBO for comparison/verification purposes. | |
57 | |
58 // Whether the frames are rendered as scaled thumbnails within a | |
59 // larger FBO that is in turn rendered to the window. | |
60 bool render_as_thumbnails; | |
61 // The size of the FBO containing all visible thumbnails. | |
62 gfx::Size thumbnails_page_size; | |
63 // The size of each thumbnail within the FBO. | |
64 gfx::Size thumbnail_size; | |
65 }; | |
28 | 66 |
29 // Creates and draws textures used by the video decoder. | 67 // Creates and draws textures used by the video decoder. |
30 // This class is not thread safe and thus all the methods of this class | 68 // This class is not thread safe and thus all the methods of this class |
31 // (except for ctor/dtor) ensure they're being run on a single thread. | 69 // (except for ctor/dtor) ensure they're being run on a single thread. |
32 class RenderingHelper { | 70 class RenderingHelper { |
33 public: | 71 public: |
34 // Interface for the content provider of the RenderingHelper. | |
35 class Client { | |
36 public: | |
37 // Callback to tell client to render the content. | |
38 virtual void RenderContent(RenderingHelper* helper) = 0; | |
39 | |
40 // Callback to get the desired window size of the client. | |
41 virtual const gfx::Size& GetWindowSize() = 0; | |
42 | |
43 protected: | |
44 virtual ~Client() {} | |
45 }; | |
46 | 72 |
47 RenderingHelper(); | 73 RenderingHelper(); |
48 ~RenderingHelper(); | 74 ~RenderingHelper(); |
49 | 75 |
50 static bool InitializeOneOff(); | 76 static bool InitializeOneOff(); |
51 | 77 |
52 // Create the render context and windows by the specified dimensions. | 78 // Create the render context and windows by the specified dimensions. |
53 void Initialize(const RenderingHelperParams& params, | 79 void Initialize(const RenderingHelperParams& params, |
54 base::WaitableEvent* done); | 80 base::WaitableEvent* done); |
55 | 81 |
56 // Undo the effects of Initialize() and signal |*done|. | 82 // Undo the effects of Initialize() and signal |*done|. |
57 void UnInitialize(base::WaitableEvent* done); | 83 void UnInitialize(base::WaitableEvent* done); |
58 | 84 |
59 // Return a newly-created GLES2 texture id of the specified size, and | 85 // Return a newly-created GLES2 texture id of the specified size, and |
60 // signal |*done|. | 86 // signal |*done|. |
61 void CreateTexture(uint32 texture_target, | 87 void CreateTexture(uint32 texture_target, |
62 uint32* texture_id, | 88 uint32* texture_id, |
63 const gfx::Size& size, | 89 const gfx::Size& size, |
64 base::WaitableEvent* done); | 90 base::WaitableEvent* done); |
65 | 91 |
66 // Render thumbnail in the |texture_id| to the FBO buffer using target | 92 // Render thumbnail in the |texture_id| to the FBO buffer using target |
67 // |texture_target|. | 93 // |texture_target|. |
68 void RenderThumbnail(uint32 texture_target, uint32 texture_id); | 94 void RenderThumbnail(uint32 texture_target, uint32 texture_id); |
69 | 95 |
70 // Render |texture_id| to the current view port of the screen using target | 96 // Queues the video_frame for rendering. |
Pawel Osciak
2014/08/20 10:26:26
Nit: |video_frame|
Owen Lin
2014/08/21 03:45:18
Done.
| |
71 // |texture_target|. | 97 void QueueVideoFrame(size_t window_id, |
72 void RenderTexture(uint32 texture_target, uint32 texture_id); | 98 scoped_refptr<VideoFrameTexture> video_frame); |
99 | |
100 // Drops all the pending video frames of the specified window. | |
101 void DropPendingFrames(size_t window_id); | |
73 | 102 |
74 // Delete |texture_id|. | 103 // Delete |texture_id|. |
75 void DeleteTexture(uint32 texture_id); | 104 void DeleteTexture(uint32 texture_id); |
76 | 105 |
77 // Get the platform specific handle to the OpenGL display. | 106 // Get the platform specific handle to the OpenGL display. |
78 void* GetGLDisplay(); | 107 void* GetGLDisplay(); |
79 | 108 |
80 // Get the platform specific handle to the OpenGL context. | 109 // Get the platform specific handle to the OpenGL context. |
81 void* GetGLContext(); | 110 void* GetGLContext(); |
82 | 111 |
83 // Get rendered thumbnails as RGB. | 112 // Get rendered thumbnails as RGB. |
84 // Sets alpha_solid to true if the alpha channel is entirely 0xff. | 113 // Sets alpha_solid to true if the alpha channel is entirely 0xff. |
85 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | 114 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
86 bool* alpha_solid, | 115 bool* alpha_solid, |
87 base::WaitableEvent* done); | 116 base::WaitableEvent* done); |
88 | 117 |
89 private: | 118 private: |
119 struct RenderedVideo { | |
120 // The rect on the screen where the video will be rendered. | |
121 gfx::Rect render_area; | |
122 | |
123 // True if the oldest (and the only one) frame in pending_frames has | |
Pawel Osciak
2014/08/20 10:26:26
Sorry, actually it should be the newest, my bad. B
Owen Lin
2014/08/21 03:45:18
Done.
| |
124 // been rendered. We keep the last remaining frame in pending_frames even | |
Pawel Osciak
2014/08/20 10:26:26
s/even/even after/
Owen Lin
2014/08/21 03:45:18
Done.
| |
125 // it has been rendered, so that we have something to display if the | |
126 // client is falling behind on providing us with new frames during | |
127 // timer-driven playback. | |
128 bool last_frame_rendered; | |
129 | |
130 // The video frames pending for rendering. | |
131 std::queue<scoped_refptr<VideoFrameTexture> > pending_frames; | |
132 | |
133 RenderedVideo() : last_frame_rendered(false) {} | |
134 }; | |
135 | |
90 void Clear(); | 136 void Clear(); |
91 | 137 |
92 void RenderContent(); | 138 void RenderContent(); |
93 | 139 |
94 void LayoutRenderingAreas(); | 140 void LayoutRenderingAreas(const std::vector<gfx::Size>& window_sizes); |
141 | |
142 // Render |texture_id| to the current view port of the screen using target | |
143 // |texture_target|. | |
144 void RenderTexture(uint32 texture_target, uint32 texture_id); | |
95 | 145 |
96 // Timer to trigger the RenderContent() repeatly. | 146 // Timer to trigger the RenderContent() repeatly. |
97 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; | 147 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; |
98 base::MessageLoop* message_loop_; | 148 base::MessageLoop* message_loop_; |
99 | 149 |
100 scoped_refptr<gfx::GLContext> gl_context_; | 150 scoped_refptr<gfx::GLContext> gl_context_; |
101 scoped_refptr<gfx::GLSurface> gl_surface_; | 151 scoped_refptr<gfx::GLSurface> gl_surface_; |
102 | 152 |
103 gfx::AcceleratedWidget window_; | 153 gfx::AcceleratedWidget window_; |
104 | 154 |
105 gfx::Size screen_size_; | 155 gfx::Size screen_size_; |
106 | 156 |
107 // The rendering area of each window on the screen. | 157 std::vector<RenderedVideo> videos_; |
108 std::vector<gfx::Rect> render_areas_; | |
109 | |
110 std::vector<base::WeakPtr<Client> > clients_; | |
111 | 158 |
112 bool render_as_thumbnails_; | 159 bool render_as_thumbnails_; |
113 int frame_count_; | 160 int frame_count_; |
114 GLuint thumbnails_fbo_id_; | 161 GLuint thumbnails_fbo_id_; |
115 GLuint thumbnails_texture_id_; | 162 GLuint thumbnails_texture_id_; |
116 gfx::Size thumbnails_fbo_size_; | 163 gfx::Size thumbnails_fbo_size_; |
117 gfx::Size thumbnail_size_; | 164 gfx::Size thumbnail_size_; |
118 GLuint program_; | 165 GLuint program_; |
119 base::TimeDelta frame_duration_; | 166 base::TimeDelta frame_duration_; |
120 | 167 |
121 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); | 168 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); |
122 }; | 169 }; |
123 | 170 |
124 struct RenderingHelperParams { | |
125 RenderingHelperParams(); | |
126 ~RenderingHelperParams(); | |
127 | |
128 // The rendering FPS. | |
129 int rendering_fps; | |
130 | |
131 // The clients who provide the content for rendering. | |
132 std::vector<base::WeakPtr<RenderingHelper::Client> > clients; | |
133 | |
134 // Whether the frames are rendered as scaled thumbnails within a | |
135 // larger FBO that is in turn rendered to the window. | |
136 bool render_as_thumbnails; | |
137 // The size of the FBO containing all visible thumbnails. | |
138 gfx::Size thumbnails_page_size; | |
139 // The size of each thumbnail within the FBO. | |
140 gfx::Size thumbnail_size; | |
141 }; | |
142 } // namespace content | 171 } // namespace content |
143 | 172 |
144 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | 173 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |
OLD | NEW |