| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
| 17 #include "ui/gl/gl_context.h" |
| 18 #include "ui/gl/gl_surface.h" |
| 17 | 19 |
| 18 namespace base { | 20 namespace base { |
| 19 class MessageLoop; | 21 class MessageLoop; |
| 20 class WaitableEvent; | 22 class WaitableEvent; |
| 21 } | 23 } |
| 22 | 24 |
| 23 #if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY) | |
| 24 #define GL_VARIANT_GLX 1 | |
| 25 typedef GLXContext NativeContextType; | |
| 26 #else | |
| 27 #define GL_VARIANT_EGL 1 | |
| 28 typedef EGLContext NativeContextType; | |
| 29 #endif | |
| 30 | |
| 31 namespace content { | 25 namespace content { |
| 32 | 26 |
| 33 struct RenderingHelperParams; | 27 struct RenderingHelperParams; |
| 34 | 28 |
| 35 // Creates and draws textures used by the video decoder. | 29 // Creates and draws textures used by the video decoder. |
| 36 // This class is not thread safe and thus all the methods of this class | 30 // 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. | 31 // (except for ctor/dtor) ensure they're being run on a single thread. |
| 38 class RenderingHelper { | 32 class RenderingHelper { |
| 39 public: | 33 public: |
| 40 // Interface for the content provider of the RenderingHelper. | 34 // Interface for the content provider of the RenderingHelper. |
| 41 class Client { | 35 class Client { |
| 42 public: | 36 public: |
| 43 // Callback to tell client to render the content. | 37 // Callback to tell client to render the content. |
| 44 virtual void RenderContent(RenderingHelper* helper) = 0; | 38 virtual void RenderContent(RenderingHelper* helper) = 0; |
| 45 | 39 |
| 46 // Callback to get the desired window size of the client. | 40 // Callback to get the desired window size of the client. |
| 47 virtual const gfx::Size& GetWindowSize() = 0; | 41 virtual const gfx::Size& GetWindowSize() = 0; |
| 48 | 42 |
| 49 protected: | 43 protected: |
| 50 virtual ~Client() {} | 44 virtual ~Client() {} |
| 51 }; | 45 }; |
| 52 | 46 |
| 53 RenderingHelper(); | 47 RenderingHelper(); |
| 54 ~RenderingHelper(); | 48 ~RenderingHelper(); |
| 55 | 49 |
| 50 static bool InitializeOneOff(); |
| 51 |
| 56 // Create the render context and windows by the specified dimensions. | 52 // Create the render context and windows by the specified dimensions. |
| 57 void Initialize(const RenderingHelperParams& params, | 53 void Initialize(const RenderingHelperParams& params, |
| 58 base::WaitableEvent* done); | 54 base::WaitableEvent* done); |
| 59 | 55 |
| 60 // Undo the effects of Initialize() and signal |*done|. | 56 // Undo the effects of Initialize() and signal |*done|. |
| 61 void UnInitialize(base::WaitableEvent* done); | 57 void UnInitialize(base::WaitableEvent* done); |
| 62 | 58 |
| 63 // Return a newly-created GLES2 texture id of the specified size, and | 59 // Return a newly-created GLES2 texture id of the specified size, and |
| 64 // signal |*done|. | 60 // signal |*done|. |
| 65 void CreateTexture(uint32 texture_target, | 61 void CreateTexture(uint32 texture_target, |
| 66 uint32* texture_id, | 62 uint32* texture_id, |
| 67 const gfx::Size& size, | 63 const gfx::Size& size, |
| 68 base::WaitableEvent* done); | 64 base::WaitableEvent* done); |
| 69 | 65 |
| 70 // Render thumbnail in the |texture_id| to the FBO buffer using target | 66 // Render thumbnail in the |texture_id| to the FBO buffer using target |
| 71 // |texture_target|. | 67 // |texture_target|. |
| 72 void RenderThumbnail(uint32 texture_target, uint32 texture_id); | 68 void RenderThumbnail(uint32 texture_target, uint32 texture_id); |
| 73 | 69 |
| 74 // Render |texture_id| to the current view port of the screen using target | 70 // Render |texture_id| to the current view port of the screen using target |
| 75 // |texture_target|. | 71 // |texture_target|. |
| 76 void RenderTexture(uint32 texture_target, uint32 texture_id); | 72 void RenderTexture(uint32 texture_target, uint32 texture_id); |
| 77 | 73 |
| 78 // Delete |texture_id|. | 74 // Delete |texture_id|. |
| 79 void DeleteTexture(uint32 texture_id); | 75 void DeleteTexture(uint32 texture_id); |
| 80 | 76 |
| 81 // Get the platform specific handle to the OpenGL display. | 77 // Get the platform specific handle to the OpenGL display. |
| 82 void* GetGLDisplay(); | 78 void* GetGLDisplay(); |
| 83 | 79 |
| 84 // Get the platform specific handle to the OpenGL context. | 80 // Get the platform specific handle to the OpenGL context. |
| 85 NativeContextType GetGLContext(); | 81 void* GetGLContext(); |
| 86 | 82 |
| 87 // Get rendered thumbnails as RGB. | 83 // Get rendered thumbnails as RGB. |
| 88 // Sets alpha_solid to true if the alpha channel is entirely 0xff. | 84 // Sets alpha_solid to true if the alpha channel is entirely 0xff. |
| 89 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | 85 void GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
| 90 bool* alpha_solid, | 86 bool* alpha_solid, |
| 91 base::WaitableEvent* done); | 87 base::WaitableEvent* done); |
| 92 | 88 |
| 93 private: | 89 private: |
| 94 void Clear(); | 90 void Clear(); |
| 95 | 91 |
| 96 void RenderContent(); | 92 void RenderContent(); |
| 97 | 93 |
| 98 void LayoutRenderingAreas(); | 94 void LayoutRenderingAreas(); |
| 99 | 95 |
| 100 // Timer to trigger the RenderContent() repeatly. | 96 // Timer to trigger the RenderContent() repeatly. |
| 101 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; | 97 scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; |
| 102 base::MessageLoop* message_loop_; | 98 base::MessageLoop* message_loop_; |
| 103 | 99 |
| 104 NativeContextType gl_context_; | 100 scoped_refptr<gfx::GLContext> gl_context_; |
| 101 scoped_refptr<gfx::GLSurface> gl_surface_; |
| 105 | 102 |
| 106 #if defined(GL_VARIANT_EGL) | 103 gfx::AcceleratedWidget window_; |
| 107 EGLDisplay gl_display_; | |
| 108 EGLSurface gl_surface_; | |
| 109 #else | |
| 110 XVisualInfo* x_visual_; | |
| 111 #endif | |
| 112 | |
| 113 #if defined(OS_WIN) | |
| 114 HWND window_; | |
| 115 #else | |
| 116 Display* x_display_; | |
| 117 Window x_window_; | |
| 118 #endif | |
| 119 | 104 |
| 120 gfx::Size screen_size_; | 105 gfx::Size screen_size_; |
| 121 | 106 |
| 122 // The rendering area of each window on the screen. | 107 // The rendering area of each window on the screen. |
| 123 std::vector<gfx::Rect> render_areas_; | 108 std::vector<gfx::Rect> render_areas_; |
| 124 | 109 |
| 125 std::vector<base::WeakPtr<Client> > clients_; | 110 std::vector<base::WeakPtr<Client> > clients_; |
| 126 | 111 |
| 127 bool render_as_thumbnails_; | 112 bool render_as_thumbnails_; |
| 128 int frame_count_; | 113 int frame_count_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 150 // larger FBO that is in turn rendered to the window. | 135 // larger FBO that is in turn rendered to the window. |
| 151 bool render_as_thumbnails; | 136 bool render_as_thumbnails; |
| 152 // The size of the FBO containing all visible thumbnails. | 137 // The size of the FBO containing all visible thumbnails. |
| 153 gfx::Size thumbnails_page_size; | 138 gfx::Size thumbnails_page_size; |
| 154 // The size of each thumbnail within the FBO. | 139 // The size of each thumbnail within the FBO. |
| 155 gfx::Size thumbnail_size; | 140 gfx::Size thumbnail_size; |
| 156 }; | 141 }; |
| 157 } // namespace content | 142 } // namespace content |
| 158 | 143 |
| 159 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ | 144 #endif // CONTENT_COMMON_GPU_MEDIA_RENDERING_HELPER_H_ |
| OLD | NEW |