Chromium Code Reviews| 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 <deque> | |
| 8 #include <map> | 9 #include <map> |
| 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 VideoFrame { |
|
Pawel Osciak
2014/08/14 04:48:23
Why not use media::VideoFrame?
Owen Lin
2014/08/14 09:20:41
The main reason is I don't know how to use it in o
Pawel Osciak
2014/08/15 05:45:15
Ok, texture_id is an issue (the other is not reall
| |
| 29 public: | |
| 30 uint32 texture_id() const { return texture_id_; } | |
| 31 uint32 texture_target() const { return texture_target_; } | |
| 32 | |
| 33 VideoFrame(uint32 texture_target, | |
| 34 uint32 texture_id, | |
| 35 const base::Closure& no_longer_needed_cb); | |
| 36 ~VideoFrame(); | |
| 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 designed size of each window. | |
|
Pawel Osciak
2014/08/14 04:48:23
s/designed//
Please explain this is used for the
Owen Lin
2014/08/14 09:20:41
Sorry, it should be "desired". We may resize the w
| |
| 52 std::vector<gfx::Size> window_sizes; | |
| 53 | |
| 54 // Whether the frames are rendered as scaled thumbnails within a | |
| 55 // larger FBO that is in turn rendered to the window. | |
| 56 bool render_as_thumbnails; | |
| 57 // The size of the FBO containing all visible thumbnails. | |
| 58 gfx::Size thumbnails_page_size; | |
| 59 // The size of each thumbnail within the FBO. | |
| 60 gfx::Size thumbnail_size; | |
| 61 }; | |
| 28 | 62 |
| 29 // Creates and draws textures used by the video decoder. | 63 // Creates and draws textures used by the video decoder. |
| 30 // This class is not thread safe and thus all the methods of this class | 64 // 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. | 65 // (except for ctor/dtor) ensure they're being run on a single thread. |
| 32 class RenderingHelper { | 66 class RenderingHelper { |
| 33 public: | 67 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 | 68 |
| 47 RenderingHelper(); | 69 RenderingHelper(); |
| 70 | |
|
Pawel Osciak
2014/08/14 04:48:23
Not needed.
Owen Lin
2014/08/14 09:20:41
Done.
| |
| 48 ~RenderingHelper(); | 71 ~RenderingHelper(); |
| 49 | 72 |
| 50 static bool InitializeOneOff(); | 73 static bool InitializeOneOff(); |
| 51 | 74 |
| 52 // Create the render context and windows by the specified dimensions. | 75 // Create the render context and windows by the specified dimensions. |
| 53 void Initialize(const RenderingHelperParams& params, | 76 void Initialize(const RenderingHelperParams& params, |
| 54 base::WaitableEvent* done); | 77 base::WaitableEvent* done); |
| 55 | 78 |
| 56 // Undo the effects of Initialize() and signal |*done|. | 79 // Undo the effects of Initialize() and signal |*done|. |
| 57 void UnInitialize(base::WaitableEvent* done); | 80 void UnInitialize(base::WaitableEvent* done); |
| 58 | 81 |
| 59 // Return a newly-created GLES2 texture id of the specified size, and | 82 // Return a newly-created GLES2 texture id of the specified size, and |
| 60 // signal |*done|. | 83 // signal |*done|. |
| 61 void CreateTexture(uint32 texture_target, | 84 void CreateTexture(uint32 texture_target, |
| 62 uint32* texture_id, | 85 uint32* texture_id, |
| 63 const gfx::Size& size, | 86 const gfx::Size& size, |
| 64 base::WaitableEvent* done); | 87 base::WaitableEvent* done); |
| 65 | 88 |
| 66 // Render thumbnail in the |texture_id| to the FBO buffer using target | 89 // Render thumbnail in the |texture_id| to the FBO buffer using target |
| 67 // |texture_target|. | 90 // |texture_target|. |
| 68 void RenderThumbnail(uint32 texture_target, uint32 texture_id); | 91 void RenderThumbnail(uint32 texture_target, uint32 texture_id); |
| 69 | 92 |
| 70 // Render |texture_id| to the current view port of the screen using target | 93 // Queues the VideoFrame for rendering. |
| 71 // |texture_target|. | 94 void QueueVideoFrame(size_t window_id, scoped_ptr<VideoFrame> video_frame); |
| 72 void RenderTexture(uint32 texture_target, uint32 texture_id); | 95 |
| 96 void ClearVideoFrames(size_t window_id); | |
|
Pawel Osciak
2014/08/14 04:48:23
Please document and rename to DropPendingFrames().
Owen Lin
2014/08/14 09:20:41
Done.
| |
| 73 | 97 |
| 74 // Delete |texture_id|. | 98 // Delete |texture_id|. |
| 75 void DeleteTexture(uint32 texture_id); | 99 void DeleteTexture(uint32 texture_id); |
| 76 | 100 |
| 77 // Get the platform specific handle to the OpenGL display. | 101 // Get the platform specific handle to the OpenGL display. |
| 78 void* GetGLDisplay(); | 102 void* GetGLDisplay(); |
| 79 | 103 |
| 80 // Get the platform specific handle to the OpenGL context. | 104 // Get the platform specific handle to the OpenGL context. |
| 81 void* GetGLContext(); | 105 void* GetGLContext(); |
| 82 | 106 |
| 83 // Get rendered thumbnails as RGB. | 107 // Get rendered thumbnails as RGB. |
| 84 // Sets alpha_solid to true if the alpha channel is entirely 0xff. | 108 // Sets alpha_solid to true if the alpha channel is entirely 0xff. |
| 85 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | 109 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
| 86 bool* alpha_solid, | 110 bool* alpha_solid, |
| 87 base::WaitableEvent* done); | 111 base::WaitableEvent* done); |
| 88 | 112 |
| 89 private: | 113 private: |
| 114 struct RenderingClient { | |
|
Pawel Osciak
2014/08/14 04:48:23
I think we should not call it a Client, because th
Owen Lin
2014/08/14 09:20:41
Done.
On 2014/08/14 04:48:23, Pawel Osciak wrote:
| |
| 115 gfx::Rect render_area; | |
|
Pawel Osciak
2014/08/14 04:48:23
Please documentation for all members.
Owen Lin
2014/08/14 09:20:41
Done.
| |
| 116 bool last_frame_rendered; | |
|
Pawel Osciak
2014/08/14 04:48:23
Isn't this equivalent to pending_frames.empty() ?
Owen Lin
2014/08/14 09:20:41
Why? do you mean pending_frames.size() == 1? We wi
Pawel Osciak
2014/08/15 05:45:15
Sorry, this was something that I forgot to remove
| |
| 117 base::Closure wait_rendering_cb; | |
| 118 std::deque<VideoFrame*> pending_frames; | |
|
Pawel Osciak
2014/08/14 04:48:23
Please keep scoped_refptrs here.
Owen Lin
2014/08/14 09:20:41
Done.
| |
| 119 | |
| 120 inline RenderingClient() : last_frame_rendered(false) {} | |
|
Pawel Osciak
2014/08/14 04:48:23
s/inline//
Owen Lin
2014/08/14 09:20:41
Done.
| |
| 121 }; | |
| 122 | |
| 90 void Clear(); | 123 void Clear(); |
| 91 | 124 |
| 92 void RenderContent(); | 125 void RenderContent(); |
| 93 | 126 |
| 94 void LayoutRenderingAreas(); | 127 void LayoutRenderingAreas(const std::vector<gfx::Size>& window_sizes); |
| 95 | 128 |
| 129 // Render |texture_id| to the current view port of the screen using target | |
| 130 // |texture_target|. | |
| 131 | |
|
Pawel Osciak
2014/08/14 04:48:23
Remove empty line please.
Owen Lin
2014/08/14 09:20:41
Done.
| |
| 132 void RenderTexture(uint32 texture_target, uint32 texture_id); | |
| 96 // Timer to trigger the RenderContent() repeatly. | 133 // Timer to trigger the RenderContent() repeatly. |
| 97 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; | 134 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; |
| 98 base::MessageLoop* message_loop_; | 135 base::MessageLoop* message_loop_; |
| 99 | 136 |
| 100 scoped_refptr<gfx::GLContext> gl_context_; | 137 scoped_refptr<gfx::GLContext> gl_context_; |
| 101 scoped_refptr<gfx::GLSurface> gl_surface_; | 138 scoped_refptr<gfx::GLSurface> gl_surface_; |
| 102 | 139 |
| 103 gfx::AcceleratedWidget window_; | 140 gfx::AcceleratedWidget window_; |
| 104 | 141 |
| 105 gfx::Size screen_size_; | 142 gfx::Size screen_size_; |
| 106 | 143 |
| 107 // The rendering area of each window on the screen. | 144 std::vector<RenderingClient> clients_; |
| 108 std::vector<gfx::Rect> render_areas_; | |
| 109 | |
| 110 std::vector<base::WeakPtr<Client> > clients_; | |
| 111 | 145 |
| 112 bool render_as_thumbnails_; | 146 bool render_as_thumbnails_; |
| 113 int frame_count_; | 147 int frame_count_; |
| 114 GLuint thumbnails_fbo_id_; | 148 GLuint thumbnails_fbo_id_; |
| 115 GLuint thumbnails_texture_id_; | 149 GLuint thumbnails_texture_id_; |
| 116 gfx::Size thumbnails_fbo_size_; | 150 gfx::Size thumbnails_fbo_size_; |
| 117 gfx::Size thumbnail_size_; | 151 gfx::Size thumbnail_size_; |
| 118 GLuint program_; | 152 GLuint program_; |
| 119 base::TimeDelta frame_duration_; | 153 base::TimeDelta frame_duration_; |
| 120 | 154 |
| 121 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); | 155 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); |
| 122 }; | 156 }; |
| 123 | 157 |
| 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 | 158 } // namespace content |
| 143 | 159 |
| 144 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | 160 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |
| OLD | NEW |