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.
5 #ifndef CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_
6 #define CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_
11 #include "base/basictypes.h"
12 #include "ui/gfx/size.h"
13 #include "ui/gl/gl_bindings.h"
20 #if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
21 #define GL_VARIANT_GLX 1
22 typedef GLXContext NativeContextType;
24 #define GL_VARIANT_EGL 1
25 typedef EGLContext NativeContextType;
30 struct RenderingHelperParams {
31 RenderingHelperParams();
32 ~RenderingHelperParams();
34 bool suppress_swap_to_display;
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;
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 {
58 // Create the render context and windows by the specified dimensions.
59 void Initialize(const RenderingHelperParams& params,
60 base::WaitableEvent* done);
62 // Undo the effects of Initialize() and signal |*done|.
63 void UnInitialize(base::WaitableEvent* done);
65 // Return a newly-created GLES2 texture id rendering to a specific window, and
67 void CreateTexture(int window_id,
68 uint32 texture_target,
70 base::WaitableEvent* done);
72 // Render |texture_id| to the screen.
73 void RenderTexture(uint32 texture_id);
75 // Delete |texture_id|.
76 void DeleteTexture(uint32 texture_id);
78 // Get the platform specific handle to the OpenGL context.
81 // Get the platform specific handle to the OpenGL display.
84 // Get rendered thumbnails as RGB.
85 // Sets alpha_solid to true if the alpha channel is entirely 0xff.
86 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
88 base::WaitableEvent* done);
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);
97 base::MessageLoop* message_loop_;
98 std::vector<gfx::Size> window_dimensions_;
99 std::vector<gfx::Size> frame_dimensions_;
101 NativeContextType gl_context_;
102 std::map<uint32, int> texture_id_to_surface_index_;
104 #if defined(GL_VARIANT_EGL)
105 EGLDisplay gl_display_;
106 std::vector<EGLSurface> gl_surfaces_;
108 XVisualInfo* x_visual_;
112 std::vector<HWND> windows_;
115 std::vector<Window> x_windows_;
118 bool render_as_thumbnails_;
120 GLuint thumbnails_fbo_id_;
121 GLuint thumbnails_texture_id_;
122 gfx::Size thumbnails_fbo_size_;
123 gfx::Size thumbnail_size_;
126 DISALLOW_COPY_AND_ASSIGN(RenderingHelper);
129 } // namespace content
131 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_