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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 // This class is not thread safe and thus all the methods of this class | 36 // This class is not thread safe and thus all the methods of this class |
37 // (except for ctor/dtor) ensure they're being run on a single thread. | 37 // (except for ctor/dtor) ensure they're being run on a single thread. |
38 class RenderingHelper { | 38 class RenderingHelper { |
39 public: | 39 public: |
40 // Interface for the content provider of the RenderingHelper. | 40 // Interface for the content provider of the RenderingHelper. |
41 class Client { | 41 class Client { |
42 public: | 42 public: |
43 // Callback to tell client to render the content. | 43 // Callback to tell client to render the content. |
44 virtual void RenderContent(RenderingHelper* helper) = 0; | 44 virtual void RenderContent(RenderingHelper* helper) = 0; |
45 | 45 |
| 46 // Callback to get the desired window size of the client. |
| 47 virtual const gfx::Size& GetWindowSize() = 0; |
46 protected: | 48 protected: |
47 virtual ~Client() {} | 49 virtual ~Client() {} |
48 }; | 50 }; |
49 | 51 |
50 RenderingHelper(); | 52 RenderingHelper(); |
51 ~RenderingHelper(); | 53 ~RenderingHelper(); |
52 | 54 |
53 // Create the render context and windows by the specified dimensions. | 55 // Create the render context and windows by the specified dimensions. |
54 void Initialize(const RenderingHelperParams& params, | 56 void Initialize(const RenderingHelperParams& params, |
55 base::WaitableEvent* done); | 57 base::WaitableEvent* done); |
56 | 58 |
57 // Undo the effects of Initialize() and signal |*done|. | 59 // Undo the effects of Initialize() and signal |*done|. |
58 void UnInitialize(base::WaitableEvent* done); | 60 void UnInitialize(base::WaitableEvent* done); |
59 | 61 |
60 // Return a newly-created GLES2 texture id rendering to a specific window, and | 62 // Return a newly-created GLES2 texture id of the specified size, and |
61 // signal |*done|. | 63 // signal |*done|. |
62 void CreateTexture(int window_id, | 64 void CreateTexture(uint32 texture_target, |
63 uint32 texture_target, | |
64 uint32* texture_id, | 65 uint32* texture_id, |
| 66 const gfx::Size& size, |
65 base::WaitableEvent* done); | 67 base::WaitableEvent* done); |
66 | 68 |
67 // Render thumbnail in the |texture_id| to the FBO buffer using target | 69 // Render thumbnail in the |texture_id| to the FBO buffer using target |
68 // |texture_target|. | 70 // |texture_target|. |
69 void RenderThumbnail(uint32 texture_target, uint32 texture_id); | 71 void RenderThumbnail(uint32 texture_target, uint32 texture_id); |
70 | 72 |
71 // Render |texture_id| to the current view port of the screen using target | 73 // Render |texture_id| to the current view port of the screen using target |
72 // |texture_target|. | 74 // |texture_target|. |
73 void RenderTexture(uint32 texture_target, uint32 texture_id); | 75 void RenderTexture(uint32 texture_target, uint32 texture_id); |
74 | 76 |
75 // Delete |texture_id|. | 77 // Delete |texture_id|. |
76 void DeleteTexture(uint32 texture_id); | 78 void DeleteTexture(uint32 texture_id); |
77 | 79 |
78 // Get the platform specific handle to the OpenGL display. | 80 // Get the platform specific handle to the OpenGL display. |
79 void* GetGLDisplay(); | 81 void* GetGLDisplay(); |
80 | 82 |
81 // Get the platform specific handle to the OpenGL context. | 83 // Get the platform specific handle to the OpenGL context. |
82 NativeContextType GetGLContext(); | 84 NativeContextType GetGLContext(); |
83 | 85 |
84 // Get rendered thumbnails as RGB. | 86 // Get rendered thumbnails as RGB. |
85 // Sets alpha_solid to true if the alpha channel is entirely 0xff. | 87 // Sets alpha_solid to true if the alpha channel is entirely 0xff. |
86 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | 88 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
87 bool* alpha_solid, | 89 bool* alpha_solid, |
88 base::WaitableEvent* done); | 90 base::WaitableEvent* done); |
89 | 91 |
90 private: | 92 private: |
91 void Clear(); | 93 void Clear(); |
92 | 94 |
93 void RenderContent(); | 95 void RenderContent(); |
| 96 |
| 97 void LayoutRenderingAreas(); |
| 98 |
94 base::RepeatingTimer<RenderingHelper> render_timer_; | 99 base::RepeatingTimer<RenderingHelper> render_timer_; |
95 base::MessageLoop* message_loop_; | 100 base::MessageLoop* message_loop_; |
96 std::vector<gfx::Size> frame_dimensions_; | |
97 | 101 |
98 NativeContextType gl_context_; | 102 NativeContextType gl_context_; |
99 std::map<uint32, int> texture_id_to_surface_index_; | |
100 | 103 |
101 #if defined(GL_VARIANT_EGL) | 104 #if defined(GL_VARIANT_EGL) |
102 EGLDisplay gl_display_; | 105 EGLDisplay gl_display_; |
103 EGLSurface gl_surface_; | 106 EGLSurface gl_surface_; |
104 #else | 107 #else |
105 XVisualInfo* x_visual_; | 108 XVisualInfo* x_visual_; |
106 #endif | 109 #endif |
107 | 110 |
108 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
109 HWND window_; | 112 HWND window_; |
110 #else | 113 #else |
111 Display* x_display_; | 114 Display* x_display_; |
112 Window x_window_; | 115 Window x_window_; |
113 #endif | 116 #endif |
114 | 117 |
| 118 gfx::Size screen_size_; |
| 119 |
115 // The rendering area of each window on the screen. | 120 // The rendering area of each window on the screen. |
116 std::vector<gfx::Rect> render_areas_; | 121 std::vector<gfx::Rect> render_areas_; |
117 | 122 |
118 std::vector<base::WeakPtr<Client> > clients_; | 123 std::vector<base::WeakPtr<Client> > clients_; |
119 | 124 |
120 bool render_as_thumbnails_; | 125 bool render_as_thumbnails_; |
121 int frame_count_; | 126 int frame_count_; |
122 GLuint thumbnails_fbo_id_; | 127 GLuint thumbnails_fbo_id_; |
123 GLuint thumbnails_texture_id_; | 128 GLuint thumbnails_texture_id_; |
124 gfx::Size thumbnails_fbo_size_; | 129 gfx::Size thumbnails_fbo_size_; |
125 gfx::Size thumbnail_size_; | 130 gfx::Size thumbnail_size_; |
126 GLuint program_; | 131 GLuint program_; |
127 base::TimeDelta frame_duration_; | 132 base::TimeDelta frame_duration_; |
128 | 133 |
129 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); | 134 DISALLOW_COPY_AND_ASSIGN(RenderingHelper); |
130 }; | 135 }; |
131 | 136 |
132 struct RenderingHelperParams { | 137 struct RenderingHelperParams { |
133 RenderingHelperParams(); | 138 RenderingHelperParams(); |
134 ~RenderingHelperParams(); | 139 ~RenderingHelperParams(); |
| 140 |
| 141 // The rendering FPS. |
135 int rendering_fps; | 142 int rendering_fps; |
136 | 143 |
| 144 // The clients who provide the content for rendering. |
137 std::vector<base::WeakPtr<RenderingHelper::Client> > clients; | 145 std::vector<base::WeakPtr<RenderingHelper::Client> > clients; |
138 int num_windows; | |
139 | 146 |
140 // Dimensions of window(s) created for displaying frames. In the | |
141 // case of thumbnail rendering, these won't match the frame dimensions. | |
142 std::vector<gfx::Size> window_dimensions; | |
143 // Dimensions of video frame texture(s). | |
144 std::vector<gfx::Size> frame_dimensions; | |
145 // Whether the frames are rendered as scaled thumbnails within a | 147 // Whether the frames are rendered as scaled thumbnails within a |
146 // larger FBO that is in turn rendered to the window. | 148 // larger FBO that is in turn rendered to the window. |
147 bool render_as_thumbnails; | 149 bool render_as_thumbnails; |
148 // The size of the FBO containing all visible thumbnails. | 150 // The size of the FBO containing all visible thumbnails. |
149 gfx::Size thumbnails_page_size; | 151 gfx::Size thumbnails_page_size; |
150 // The size of each thumbnail within the FBO. | 152 // The size of each thumbnail within the FBO. |
151 gfx::Size thumbnail_size; | 153 gfx::Size thumbnail_size; |
152 }; | 154 }; |
153 } // namespace content | 155 } // namespace content |
154 | 156 |
155 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | 157 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |
OLD | NEW |