Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ui/gfx/compositor/compositor_gl.h

Issue 7552039: Vend common GL context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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,
78 const gfx::Size& surface_size) OVERRIDE;
37 79
38 virtual void Draw(const ui::TextureDrawParams& params, 80 virtual void Draw(const ui::TextureDrawParams& params,
39 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; 81 const gfx::Rect& clip_bounds_in_texture,
82 const gfx::Size& surface_size) OVERRIDE;
40 83
41 protected: 84 protected:
42 TextureGL(CompositorGL* compositor, const gfx::Size& size); 85 explicit TextureGL(const gfx::Size& size);
43 virtual ~TextureGL(); 86 virtual ~TextureGL();
44 87
45 // Actually draws the texture. 88 // Actually draws the texture.
46 // Only the region defined by draw_bounds will be drawn. 89 // Only the region defined by draw_bounds will be drawn.
47 void DrawInternal(const TextureProgramGL& program, 90 void DrawInternal(const TextureProgramGL& program,
48 const ui::TextureDrawParams& params, 91 const ui::TextureDrawParams& params,
49 const gfx::Rect& clip_bounds_in_texture); 92 const gfx::Rect& clip_bounds_in_texture,
93 const gfx::Size& surface_size);
50 94
51 unsigned int texture_id_; 95 unsigned int texture_id_;
52 gfx::Size size_; 96 gfx::Size size_;
53 CompositorGL* compositor_;
54 97
55 private: 98 private:
56 DISALLOW_COPY_AND_ASSIGN(TextureGL); 99 DISALLOW_COPY_AND_ASSIGN(TextureGL);
57 }; 100 };
58 101
59 class COMPOSITOR_EXPORT CompositorGL : public Compositor { 102 class COMPOSITOR_EXPORT CompositorGL : public Compositor {
60 public: 103 public:
61 CompositorGL(gfx::AcceleratedWidget widget, const gfx::Size& size); 104 CompositorGL(gfx::AcceleratedWidget widget, const gfx::Size& size);
62 virtual ~CompositorGL(); 105 virtual ~CompositorGL();
63 106
64 void MakeCurrent(); 107 void MakeCurrent();
65 gfx::Size GetSize(); 108 gfx::Size GetSize();
66 109
67 TextureProgramGL* program_no_swizzle();
68 TextureProgramGL* program_swizzle();
69
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; 117 virtual void OnWidgetSizeChanged(const gfx::Size& size) OVERRIDE;
78 118
79 // The GL context used for compositing. 119 // The GL context used for compositing.
80 scoped_refptr<gfx::GLSurface> gl_surface_; 120 scoped_refptr<gfx::GLSurface> gl_surface_;
81 scoped_refptr<gfx::GLContext> gl_context_; 121 scoped_refptr<gfx::GLContext> gl_context_;
82 122
83 gfx::Size size_;
84
85 // Keep track of whether compositing has started or not. 123 // Keep track of whether compositing has started or not.
86 bool started_; 124 bool started_;
87 125
88 DISALLOW_COPY_AND_ASSIGN(CompositorGL); 126 DISALLOW_COPY_AND_ASSIGN(CompositorGL);
89 }; 127 };
90 128
91 } // namespace ui 129 } // namespace ui
92 130
93 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_ 131 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698