OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ | 5 #ifndef UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ |
6 #define UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ | 6 #define UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" |
| 12 #include "base/memory/ref_counted.h" |
11 #include "ui/gfx/compositor/compositor.h" | 13 #include "ui/gfx/compositor/compositor.h" |
12 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
13 | 15 |
14 namespace gfx { | 16 namespace gfx { |
15 class GLContext; | 17 class GLContext; |
16 class GLSurface; | 18 class GLSurface; |
17 class Rect; | 19 class Rect; |
18 } | 20 } |
19 | 21 |
20 namespace ui { | 22 namespace ui { |
21 | 23 |
22 class CompositorGL; | 24 class CompositorGL; |
23 class TextureProgramGL; | 25 class TextureProgramGL; |
24 | 26 |
| 27 // We share resources (such as shaders) between different Compositors via |
| 28 // GLContext sharing so that we only have to create/destroy them once. |
| 29 class COMPOSITOR_EXPORT SharedResources { |
| 30 public: |
| 31 static SharedResources* GetInstance(); |
| 32 |
| 33 bool MakeSharedContextCurrent(); |
| 34 |
| 35 // Creates a context that shares the resources hosted by this singleton. |
| 36 scoped_refptr<gfx::GLContext> CreateContext(gfx::GLSurface* surface); |
| 37 |
| 38 ui::TextureProgramGL* program_no_swizzle() { |
| 39 return program_no_swizzle_.get(); |
| 40 } |
| 41 |
| 42 ui::TextureProgramGL* program_swizzle() { |
| 43 return program_swizzle_.get(); |
| 44 } |
| 45 |
| 46 private: |
| 47 friend struct DefaultSingletonTraits<SharedResources>; |
| 48 |
| 49 SharedResources(); |
| 50 virtual ~SharedResources(); |
| 51 |
| 52 bool Initialize(); |
| 53 void Destroy(); |
| 54 |
| 55 bool initialized_; |
| 56 |
| 57 scoped_refptr<gfx::GLContext> context_; |
| 58 scoped_refptr<gfx::GLSurface> surface_; |
| 59 |
| 60 scoped_ptr<ui::TextureProgramGL> program_swizzle_; |
| 61 scoped_ptr<ui::TextureProgramGL> program_no_swizzle_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(SharedResources); |
| 64 }; |
| 65 |
25 class COMPOSITOR_EXPORT TextureGL : public Texture { | 66 class COMPOSITOR_EXPORT TextureGL : public Texture { |
26 public: | 67 public: |
27 explicit TextureGL(CompositorGL* compositor); | 68 TextureGL(); |
28 | 69 |
29 virtual void SetCanvas(const SkCanvas& canvas, | 70 virtual void SetCanvas(const SkCanvas& canvas, |
30 const gfx::Point& origin, | 71 const gfx::Point& origin, |
31 const gfx::Size& overall_size) OVERRIDE; | 72 const gfx::Size& overall_size) OVERRIDE; |
32 | 73 |
33 // Draws the texture. | 74 // Draws the texture. |
34 // TODO(pkotwicz) merge these two methods into one, this method currently | 75 // TODO(pkotwicz) merge these two methods into one, this method currently |
35 // doesn't make sense in the context of windows | 76 // doesn't make sense in the context of windows |
36 virtual void Draw(const ui::TextureDrawParams& params) OVERRIDE; | 77 virtual void Draw(const ui::TextureDrawParams& params) OVERRIDE; |
37 | 78 |
38 virtual void Draw(const ui::TextureDrawParams& params, | 79 virtual void Draw(const ui::TextureDrawParams& params, |
39 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; | 80 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; |
40 | 81 |
41 protected: | 82 protected: |
42 TextureGL(CompositorGL* compositor, const gfx::Size& size); | 83 explicit TextureGL(const gfx::Size& size); |
43 virtual ~TextureGL(); | 84 virtual ~TextureGL(); |
44 | 85 |
45 // Actually draws the texture. | 86 // Actually draws the texture. |
46 // Only the region defined by draw_bounds will be drawn. | 87 // Only the region defined by draw_bounds will be drawn. |
47 void DrawInternal(const TextureProgramGL& program, | 88 void DrawInternal(const TextureProgramGL& program, |
48 const ui::TextureDrawParams& params, | 89 const ui::TextureDrawParams& params, |
49 const gfx::Rect& clip_bounds_in_texture); | 90 const gfx::Rect& clip_bounds_in_texture); |
50 | 91 |
51 unsigned int texture_id_; | 92 unsigned int texture_id_; |
52 gfx::Size size_; | 93 gfx::Size size_; |
53 CompositorGL* compositor_; | |
54 | 94 |
55 private: | 95 private: |
56 DISALLOW_COPY_AND_ASSIGN(TextureGL); | 96 DISALLOW_COPY_AND_ASSIGN(TextureGL); |
57 }; | 97 }; |
58 | 98 |
59 class COMPOSITOR_EXPORT CompositorGL : public Compositor { | 99 class COMPOSITOR_EXPORT CompositorGL : public Compositor { |
60 public: | 100 public: |
61 CompositorGL(gfx::AcceleratedWidget widget, const gfx::Size& size); | 101 CompositorGL(gfx::AcceleratedWidget widget, const gfx::Size& size); |
62 virtual ~CompositorGL(); | 102 virtual ~CompositorGL(); |
63 | 103 |
64 void MakeCurrent(); | 104 void MakeCurrent(); |
65 gfx::Size GetSize(); | 105 gfx::Size GetSize(); |
66 | 106 |
67 TextureProgramGL* program_no_swizzle(); | 107 protected: |
68 TextureProgramGL* program_swizzle(); | 108 virtual void OnWidgetSizeChanged() OVERRIDE; |
69 | 109 |
70 private: | 110 private: |
71 // Overridden from Compositor. | 111 // Overridden from Compositor. |
72 virtual Texture* CreateTexture() OVERRIDE; | 112 virtual Texture* CreateTexture() OVERRIDE; |
73 virtual void NotifyStart() OVERRIDE; | 113 virtual void NotifyStart() OVERRIDE; |
74 virtual void NotifyEnd() OVERRIDE; | 114 virtual void NotifyEnd() OVERRIDE; |
75 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; | 115 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; |
76 virtual void SchedulePaint() OVERRIDE; | 116 virtual void SchedulePaint() OVERRIDE; |
77 virtual void OnWidgetSizeChanged(const gfx::Size& size) OVERRIDE; | |
78 | 117 |
79 // The GL context used for compositing. | 118 // The GL context used for compositing. |
80 scoped_refptr<gfx::GLSurface> gl_surface_; | 119 scoped_refptr<gfx::GLSurface> gl_surface_; |
81 scoped_refptr<gfx::GLContext> gl_context_; | 120 scoped_refptr<gfx::GLContext> gl_context_; |
82 | 121 |
83 gfx::Size size_; | |
84 | |
85 // Keep track of whether compositing has started or not. | 122 // Keep track of whether compositing has started or not. |
86 bool started_; | 123 bool started_; |
87 | 124 |
88 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | 125 DISALLOW_COPY_AND_ASSIGN(CompositorGL); |
89 }; | 126 }; |
90 | 127 |
91 } // namespace ui | 128 } // namespace ui |
92 | 129 |
93 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ | 130 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ |
OLD | NEW |