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 #include "ui/gfx/compositor/compositor.h" | 5 #include "ui/gfx/compositor/compositor.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 public: | 23 public: |
24 explicit CompositorGL(gfx::AcceleratedWidget widget); | 24 explicit CompositorGL(gfx::AcceleratedWidget widget); |
25 | 25 |
26 private: | 26 private: |
27 // Overridden from Compositor. | 27 // Overridden from Compositor. |
28 virtual Texture* CreateTexture() OVERRIDE; | 28 virtual Texture* CreateTexture() OVERRIDE; |
29 virtual void NotifyStart() OVERRIDE; | 29 virtual void NotifyStart() OVERRIDE; |
30 virtual void NotifyEnd() OVERRIDE; | 30 virtual void NotifyEnd() OVERRIDE; |
31 | 31 |
32 // The GL context used for compositing. | 32 // The GL context used for compositing. |
| 33 scoped_ptr<gfx::GLSurface> gl_surface_; |
33 scoped_ptr<gfx::GLContext> gl_context_; | 34 scoped_ptr<gfx::GLContext> gl_context_; |
34 | 35 |
35 // Keep track of whether compositing has started or not. | 36 // Keep track of whether compositing has started or not. |
36 bool started_; | 37 bool started_; |
37 | 38 |
38 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | 39 DISALLOW_COPY_AND_ASSIGN(CompositorGL); |
39 }; | 40 }; |
40 | 41 |
41 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) | 42 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) |
42 : started_(false) { | 43 : started_(false) { |
43 scoped_ptr<gfx::GLSurface> surface( | 44 gl_surface_.reset(gfx::GLSurface::CreateViewGLSurface(widget)); |
44 gfx::GLSurface::CreateViewGLSurface(widget)); | 45 gl_context_.reset(gfx::GLContext::CreateGLContext(NULL)), |
45 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), NULL)), | |
46 } | 46 } |
47 | 47 |
48 Texture* CompositorGL::CreateTexture() { | 48 Texture* CompositorGL::CreateTexture() { |
49 return NULL; | 49 return NULL; |
50 } | 50 } |
51 | 51 |
52 void CompositorGL::NotifyStart() { | 52 void CompositorGL::NotifyStart() { |
53 started_ = true; | 53 started_ = true; |
54 gl_context_->MakeCurrent(); | 54 gl_context_->MakeCurrent(gl_surface_.get()); |
55 } | 55 } |
56 | 56 |
57 void CompositorGL::NotifyEnd() { | 57 void CompositorGL::NotifyEnd() { |
58 DCHECK(started_); | 58 DCHECK(started_); |
59 gl_context_->SwapBuffers(); | 59 gl_surface_->SwapBuffers(); |
60 started_ = false; | 60 started_ = false; |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 // static | 65 // static |
66 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 66 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
67 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) | 67 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) |
68 return new CompositorGL(widget); | 68 return new CompositorGL(widget); |
69 return NULL; | 69 return NULL; |
70 } | 70 } |
71 #else | 71 #else |
72 class CompositorGL : public Compositor { | 72 class CompositorGL : public Compositor { |
73 public: | 73 public: |
74 explicit CompositorGL(gfx::AcceleratedWidget widget); | 74 explicit CompositorGL(gfx::AcceleratedWidget widget); |
75 | 75 |
76 private: | 76 private: |
77 // Overridden from Compositor. | 77 // Overridden from Compositor. |
78 void NotifyStart() OVERRIDE; | 78 void NotifyStart() OVERRIDE; |
79 void NotifyEnd() OVERRIDE; | 79 void NotifyEnd() OVERRIDE; |
80 void DrawTextureWithTransform(TextureID txt, | 80 void DrawTextureWithTransform(TextureID txt, |
81 const ui::Transform& transform) OVERRIDE; | 81 const ui::Transform& transform) OVERRIDE; |
82 void SaveTransform() OVERRIDE; | 82 void SaveTransform() OVERRIDE; |
83 void RestoreTransform() OVERRIDE; | 83 void RestoreTransform() OVERRIDE; |
84 | 84 |
85 // The GL context used for compositing. | 85 // The GL context used for compositing. |
| 86 scoped_ptr<gfx::GLSurface> gl_surface_; |
86 scoped_ptr<gfx::GLContext> gl_context_; | 87 scoped_ptr<gfx::GLContext> gl_context_; |
87 | 88 |
88 // Keep track of whether compositing has started or not. | 89 // Keep track of whether compositing has started or not. |
89 bool started_; | 90 bool started_; |
90 | 91 |
91 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | 92 DISALLOW_COPY_AND_ASSIGN(CompositorGL); |
92 }; | 93 }; |
93 | 94 |
94 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) | 95 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) |
95 : started_(false) { | 96 : started_(false) { |
96 scoped_ptr<gfx::GLSurface> surface( | 97 gl_surface_.reset(gfx::GLSurface::CreateViewGLSurface(widget)); |
97 gfx::GLSurface::CreateViewGLSurface(widget)); | 98 gl_context_.reset(gfx::GLContext::CreateGLContext(NULL)); |
98 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), NULL)); | |
99 } | 99 } |
100 | 100 |
101 void CompositorGL::NotifyStart() { | 101 void CompositorGL::NotifyStart() { |
102 started_ = true; | 102 started_ = true; |
103 gl_context_->MakeCurrent(); | 103 gl_context_->MakeCurrent(gl_surface_.get()); |
104 } | 104 } |
105 | 105 |
106 void CompositorGL::NotifyEnd() { | 106 void CompositorGL::NotifyEnd() { |
107 DCHECK(started_); | 107 DCHECK(started_); |
108 gl_context_->SwapBuffers(); | 108 gl_surface_->SwapBuffers(); |
109 started_ = false; | 109 started_ = false; |
110 } | 110 } |
111 | 111 |
112 void CompositorGL::DrawTextureWithTransform(TextureID txt, | 112 void CompositorGL::DrawTextureWithTransform(TextureID txt, |
113 const ui::Transform& transform) { | 113 const ui::Transform& transform) { |
114 DCHECK(started_); | 114 DCHECK(started_); |
115 | 115 |
116 // TODO(wjmaclean): | 116 // TODO(wjmaclean): |
117 NOTIMPLEMENTED(); | 117 NOTIMPLEMENTED(); |
118 } | 118 } |
119 | 119 |
120 void CompositorGL::SaveTransform() { | 120 void CompositorGL::SaveTransform() { |
121 // TODO(sadrul): | 121 // TODO(sadrul): |
122 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
123 } | 123 } |
124 | 124 |
125 void CompositorGL::RestoreTransform() { | 125 void CompositorGL::RestoreTransform() { |
126 // TODO(sadrul): | 126 // TODO(sadrul): |
127 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
128 } | 128 } |
129 | 129 |
130 // static | 130 // static |
131 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 131 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
132 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) | 132 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) |
133 return new CompositorGL(widget); | 133 return new CompositorGL(widget); |
134 return NULL; | 134 return NULL; |
135 } | 135 } |
136 #endif | 136 #endif |
137 } // namespace ui | 137 } // namespace ui |
OLD | NEW |