Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 8 | #include <map> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "base/basictypes.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include "ui/gfx/size.h" |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 13 | #include "ui/gl/gl_bindings.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | |
| 15 | namespace base { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 16 | class MessageLoop; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 17 | class WaitableEvent; |
| 18 | } |
| 19 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 20 | #if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY) |
| 21 | #define GL_VARIANT_GLX 1 |
| 22 | typedef GLXContext NativeContextType; |
| 23 | #else |
| 24 | #define GL_VARIANT_EGL 1 |
| 25 | typedef EGLContext NativeContextType; |
| 26 | #endif |
| 27 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 28 | namespace content { |
| 29 | |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 30 | struct RenderingHelperParams { |
| 31 | RenderingHelperParams(); |
| 32 | ~RenderingHelperParams(); |
| 33 | |
| 34 | bool suppress_swap_to_display; |
| 35 | int num_windows; |
| 36 | // Dimensions of window(s) created for displaying frames. In the |
| 37 | // case of thumbnail rendering, these won't match the frame dimensions. |
| 38 | std::vector<gfx::Size> window_dimensions; |
| 39 | // Dimensions of video frame texture(s). |
| 40 | std::vector<gfx::Size> frame_dimensions; |
| 41 | // Whether the frames are rendered as scaled thumbnails within a |
| 42 | // larger FBO that is in turn rendered to the window. |
| 43 | bool render_as_thumbnails; |
| 44 | // The size of the FBO containing all visible thumbnails. |
| 45 | gfx::Size thumbnails_page_size; |
| 46 | // The size of each thumbnail within the FBO. |
| 47 | gfx::Size thumbnail_size; |
| 48 | }; |
| 49 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 50 | // Creates and draws textures used by the video decoder. |
| 51 | // This class is not thread safe and thus all the methods of this class |
| 52 | // (except for ctor/dtor) ensure they're being run on a single thread. |
| 53 | class RenderingHelper { |
| 54 | public: |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 55 | RenderingHelper(); |
| 56 | ~RenderingHelper(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 57 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 58 | // Create the render context and windows by the specified dimensions. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 59 | void Initialize(const RenderingHelperParams& params, |
| 60 | base::WaitableEvent* done); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 61 | |
| 62 | // Undo the effects of Initialize() and signal |*done|. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 63 | void UnInitialize(base::WaitableEvent* done); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 64 | |
| 65 | // Return a newly-created GLES2 texture id rendering to a specific window, and |
| 66 | // signal |*done|. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 67 | void CreateTexture(int window_id, |
| 68 | uint32 texture_target, |
| 69 | uint32* texture_id, |
| 70 | base::WaitableEvent* done); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 71 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 72 | // Render |texture_id| to the screen. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 73 | void RenderTexture(uint32 texture_id); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 74 | |
| 75 | // Delete |texture_id|. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 76 | void DeleteTexture(uint32 texture_id); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 77 | |
| 78 | // Get the platform specific handle to the OpenGL context. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 79 | void* GetGLContext(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 80 | |
| 81 | // Get the platform specific handle to the OpenGL display. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 82 | void* GetGLDisplay(); |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 83 | |
| 84 | // Get rendered thumbnails as RGB. |
| 85 | // Sets alpha_solid to true if the alpha channel is entirely 0xff. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 86 | void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
| 87 | bool* alpha_solid, |
| 88 | base::WaitableEvent* done); |
| 89 | |
| 90 | private: |
| 91 | void Clear(); |
| 92 | |
| 93 | // Make window_id's surface current w/ the GL context, or release the context |
| 94 | // if |window_id < 0|. |
| 95 | void MakeCurrent(int window_id); |
| 96 | |
| 97 | base::MessageLoop* message_loop_; |
| 98 | std::vector<gfx::Size> window_dimensions_; |
| 99 | std::vector<gfx::Size> frame_dimensions_; |
| 100 | |
| 101 | NativeContextType gl_context_; |
| 102 | std::map<uint32, int> texture_id_to_surface_index_; |
| 103 | |
| 104 | #if defined(GL_VARIANT_EGL) |
| 105 | EGLDisplay gl_display_; |
| 106 | std::vector<EGLSurface> gl_surfaces_; |
| 107 | #else |
| 108 | XVisualInfo* x_visual_; |
| 109 | #endif |
| 110 | |
| 111 | #if defined(OS_WIN) |
| 112 | std::vector<HWND> windows_; |
| 113 | #else |
| 114 | Display* x_display_; |
| 115 | std::vector<Window> x_windows_; |
| 116 | #endif |
| 117 | |
| 118 | bool render_as_thumbnails_; |
| 119 | int frame_count_; |
| 120 | GLuint thumbnails_fbo_id_; |
| 121 | GLuint thumbnails_texture_id_; |
| 122 | gfx::Size thumbnails_fbo_size_; |
| 123 | gfx::Size thumbnail_size_; |
| 124 | GLuint program_; |
| 125 | |
| 126 | DISALLOW_COPY_AND_ASSIGN(RenderingHelper); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } // namespace content |
| 130 | |
| 131 | #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |