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 "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gl/gl_bindings.h"
17 #include "ui/gl/gl_context.h"
18 #include "ui/gl/gl_surface.h"
27 struct RenderingHelperParams;
29 // Creates and draws textures used by the video decoder.
30 // 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.
32 class RenderingHelper {
34 // Interface for the content provider of the RenderingHelper.
37 // Callback to tell client to render the content.
38 virtual void RenderContent(RenderingHelper* helper) = 0;
40 // Callback to get the desired window size of the client.
41 virtual const gfx::Size& GetWindowSize() = 0;
50 static bool InitializeOneOff();
52 // Create the render context and windows by the specified dimensions.
53 void Initialize(const RenderingHelperParams& params,
54 base::WaitableEvent* done);
56 // Undo the effects of Initialize() and signal |*done|.
57 void UnInitialize(base::WaitableEvent* done);
59 // Return a newly-created GLES2 texture id of the specified size, and
61 void CreateTexture(uint32 texture_target,
63 const gfx::Size& size,
64 base::WaitableEvent* done);
66 // Render thumbnail in the |texture_id| to the FBO buffer using target
68 void RenderThumbnail(uint32 texture_target, uint32 texture_id);
70 // Render |texture_id| to the current view port of the screen using target
72 void RenderTexture(uint32 texture_target, uint32 texture_id);
74 // Delete |texture_id|.
75 void DeleteTexture(uint32 texture_id);
77 // Get the platform specific handle to the OpenGL display.
80 // Get the platform specific handle to the OpenGL context.
83 // Get rendered thumbnails as RGB.
84 // Sets alpha_solid to true if the alpha channel is entirely 0xff.
85 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
87 base::WaitableEvent* done);
94 void LayoutRenderingAreas();
96 // Timer to trigger the RenderContent() repeatly.
97 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_;
98 base::MessageLoop* message_loop_;
100 scoped_refptr<gfx::GLContext> gl_context_;
101 scoped_refptr<gfx::GLSurface> gl_surface_;
103 gfx::AcceleratedWidget window_;
105 gfx::Size screen_size_;
107 // The rendering area of each window on the screen.
108 std::vector<gfx::Rect> render_areas_;
110 std::vector<base::WeakPtr<Client> > clients_;
112 bool render_as_thumbnails_;
114 GLuint thumbnails_fbo_id_;
115 GLuint thumbnails_texture_id_;
116 gfx::Size thumbnails_fbo_size_;
117 gfx::Size thumbnail_size_;
119 base::TimeDelta frame_duration_;
121 DISALLOW_COPY_AND_ASSIGN(RenderingHelper);
124 struct RenderingHelperParams {
125 RenderingHelperParams();
126 ~RenderingHelperParams();
128 // The rendering FPS.
131 // The clients who provide the content for rendering.
132 std::vector<base::WeakPtr<RenderingHelper::Client> > clients;
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;
142 } // namespace content
144 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_