Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: content/common/gpu/media/rendering_helper.h

Issue 462413004: rendering_helper - Refactoring - remove the Client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix one more compiling error Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/common/gpu/media/rendering_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
37 private:
38 friend class base::RefCounted<VideoFrameTexture>;
39
40 uint32 texture_target_;
41 uint32 texture_id_;
42 base::Closure no_longer_needed_cb_;
43
44 ~VideoFrameTexture();
45 };
46
47 struct RenderingHelperParams {
48 RenderingHelperParams();
49 ~RenderingHelperParams();
50
51 // The rendering FPS.
52 int rendering_fps;
53
54 // The desired size of each window. We play each stream in its own window
55 // on the screen.
56 std::vector<gfx::Size> window_sizes;
57
58 // The members below are only used for the thumbnail mode where all frames
59 // are rendered in sequence onto one FBO for comparison/verification purposes.
60
61 // Whether the frames are rendered as scaled thumbnails within a
62 // larger FBO that is in turn rendered to the window.
63 bool render_as_thumbnails;
64 // The size of the FBO containing all visible thumbnails.
65 gfx::Size thumbnails_page_size;
66 // The size of each thumbnail within the FBO.
67 gfx::Size thumbnail_size;
68 };
28 69
29 // Creates and draws textures used by the video decoder. 70 // Creates and draws textures used by the video decoder.
30 // This class is not thread safe and thus all the methods of this class 71 // 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. 72 // (except for ctor/dtor) ensure they're being run on a single thread.
32 class RenderingHelper { 73 class RenderingHelper {
33 public: 74 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 75
47 RenderingHelper(); 76 RenderingHelper();
48 ~RenderingHelper(); 77 ~RenderingHelper();
49 78
50 static bool InitializeOneOff(); 79 static bool InitializeOneOff();
51 80
52 // Create the render context and windows by the specified dimensions. 81 // Create the render context and windows by the specified dimensions.
53 void Initialize(const RenderingHelperParams& params, 82 void Initialize(const RenderingHelperParams& params,
54 base::WaitableEvent* done); 83 base::WaitableEvent* done);
55 84
56 // Undo the effects of Initialize() and signal |*done|. 85 // Undo the effects of Initialize() and signal |*done|.
57 void UnInitialize(base::WaitableEvent* done); 86 void UnInitialize(base::WaitableEvent* done);
58 87
59 // Return a newly-created GLES2 texture id of the specified size, and 88 // Return a newly-created GLES2 texture id of the specified size, and
60 // signal |*done|. 89 // signal |*done|.
61 void CreateTexture(uint32 texture_target, 90 void CreateTexture(uint32 texture_target,
62 uint32* texture_id, 91 uint32* texture_id,
63 const gfx::Size& size, 92 const gfx::Size& size,
64 base::WaitableEvent* done); 93 base::WaitableEvent* done);
65 94
66 // Render thumbnail in the |texture_id| to the FBO buffer using target 95 // Render thumbnail in the |texture_id| to the FBO buffer using target
67 // |texture_target|. 96 // |texture_target|.
68 void RenderThumbnail(uint32 texture_target, uint32 texture_id); 97 void RenderThumbnail(uint32 texture_target, uint32 texture_id);
69 98
70 // Render |texture_id| to the current view port of the screen using target 99 // Queues the |video_frame| for rendering.
71 // |texture_target|. 100 void QueueVideoFrame(size_t window_id,
72 void RenderTexture(uint32 texture_target, uint32 texture_id); 101 scoped_refptr<VideoFrameTexture> video_frame);
102
103 // Drops all the pending video frames of the specified window.
104 void DropPendingFrames(size_t window_id);
73 105
74 // Delete |texture_id|. 106 // Delete |texture_id|.
75 void DeleteTexture(uint32 texture_id); 107 void DeleteTexture(uint32 texture_id);
76 108
77 // Get the platform specific handle to the OpenGL display. 109 // Get the platform specific handle to the OpenGL display.
78 void* GetGLDisplay(); 110 void* GetGLDisplay();
79 111
80 // Get the platform specific handle to the OpenGL context. 112 // Get the platform specific handle to the OpenGL context.
81 void* GetGLContext(); 113 void* GetGLContext();
82 114
83 // Get rendered thumbnails as RGB. 115 // Get rendered thumbnails as RGB.
84 // Sets alpha_solid to true if the alpha channel is entirely 0xff. 116 // Sets alpha_solid to true if the alpha channel is entirely 0xff.
85 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, 117 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
86 bool* alpha_solid, 118 bool* alpha_solid,
87 base::WaitableEvent* done); 119 base::WaitableEvent* done);
88 120
89 private: 121 private:
122 struct RenderedVideo {
123 // The rect on the screen where the video will be rendered.
124 gfx::Rect render_area;
125
126 // True if the last (and the only one) frame in pending_frames has
127 // been rendered. We keep the last remaining frame in pending_frames even
128 // after it has been rendered, so that we have something to display if the
129 // client is falling behind on providing us with new frames during
130 // timer-driven playback.
131 bool last_frame_rendered;
132
133 // The video frames pending for rendering.
134 std::queue<scoped_refptr<VideoFrameTexture> > pending_frames;
135
136 RenderedVideo();
137 ~RenderedVideo();
138 };
139
90 void Clear(); 140 void Clear();
91 141
92 void RenderContent(); 142 void RenderContent();
93 143
94 void LayoutRenderingAreas(); 144 void LayoutRenderingAreas(const std::vector<gfx::Size>& window_sizes);
145
146 // Render |texture_id| to the current view port of the screen using target
147 // |texture_target|.
148 void RenderTexture(uint32 texture_target, uint32 texture_id);
95 149
96 // Timer to trigger the RenderContent() repeatly. 150 // Timer to trigger the RenderContent() repeatly.
97 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; 151 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_;
98 base::MessageLoop* message_loop_; 152 base::MessageLoop* message_loop_;
99 153
100 scoped_refptr<gfx::GLContext> gl_context_; 154 scoped_refptr<gfx::GLContext> gl_context_;
101 scoped_refptr<gfx::GLSurface> gl_surface_; 155 scoped_refptr<gfx::GLSurface> gl_surface_;
102 156
103 gfx::AcceleratedWidget window_; 157 gfx::AcceleratedWidget window_;
104 158
105 gfx::Size screen_size_; 159 gfx::Size screen_size_;
106 160
107 // The rendering area of each window on the screen. 161 std::vector<RenderedVideo> videos_;
108 std::vector<gfx::Rect> render_areas_;
109
110 std::vector<base::WeakPtr<Client> > clients_;
111 162
112 bool render_as_thumbnails_; 163 bool render_as_thumbnails_;
113 int frame_count_; 164 int frame_count_;
114 GLuint thumbnails_fbo_id_; 165 GLuint thumbnails_fbo_id_;
115 GLuint thumbnails_texture_id_; 166 GLuint thumbnails_texture_id_;
116 gfx::Size thumbnails_fbo_size_; 167 gfx::Size thumbnails_fbo_size_;
117 gfx::Size thumbnail_size_; 168 gfx::Size thumbnail_size_;
118 GLuint program_; 169 GLuint program_;
119 base::TimeDelta frame_duration_; 170 base::TimeDelta frame_duration_;
120 171
121 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); 172 DISALLOW_COPY_AND_ASSIGN(RenderingHelper);
122 }; 173 };
123 174
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 175 } // namespace content
143 176
144 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ 177 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/media/rendering_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698