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 #include "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "cc/base/switches.h" | 18 #include "cc/base/switches.h" |
| 19 #include "cc/debug/fake_context_provider.h" |
19 #include "cc/input/input_handler.h" | 20 #include "cc/input/input_handler.h" |
20 #include "cc/layers/layer.h" | 21 #include "cc/layers/layer.h" |
21 #include "cc/output/context_provider.h" | 22 #include "cc/output/context_provider.h" |
22 #include "cc/output/output_surface.h" | 23 #include "cc/output/output_surface.h" |
23 #include "cc/trees/layer_tree_host.h" | 24 #include "cc/trees/layer_tree_host.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "ui/compositor/compositor_observer.h" | 26 #include "ui/compositor/compositor_observer.h" |
26 #include "ui/compositor/compositor_switches.h" | 27 #include "ui/compositor/compositor_switches.h" |
27 #include "ui/compositor/context_provider_from_context_factory.h" | |
28 #include "ui/compositor/dip_util.h" | 28 #include "ui/compositor/dip_util.h" |
29 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.h" |
30 #include "ui/compositor/reflector.h" | 30 #include "ui/compositor/reflector.h" |
31 #include "ui/compositor/test_web_graphics_context_3d.h" | 31 #include "ui/compositor/test_web_graphics_context_3d.h" |
32 #include "ui/gl/gl_context.h" | 32 #include "ui/gl/gl_context.h" |
33 #include "ui/gl/gl_implementation.h" | 33 #include "ui/gl/gl_implementation.h" |
34 #include "ui/gl/gl_surface.h" | 34 #include "ui/gl/gl_surface.h" |
35 #include "ui/gl/gl_switches.h" | 35 #include "ui/gl/gl_switches.h" |
| 36 #include "webkit/common/gpu/context_provider_in_process.h" |
36 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" | 37 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" |
37 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 38 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
38 | 39 |
39 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
40 #include "base/chromeos/chromeos_version.h" | 41 #include "base/chromeos/chromeos_version.h" |
41 #endif | 42 #endif |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 const double kDefaultRefreshRate = 60.0; | 46 const double kDefaultRefreshRate = 60.0; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (!gfx::GLSurface::InitializeOneOff() || | 102 if (!gfx::GLSurface::InitializeOneOff() || |
102 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 103 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
103 LOG(ERROR) << "Could not load the GL bindings"; | 104 LOG(ERROR) << "Could not load the GL bindings"; |
104 return false; | 105 return false; |
105 } | 106 } |
106 return true; | 107 return true; |
107 } | 108 } |
108 | 109 |
109 scoped_ptr<cc::OutputSurface> DefaultContextFactory::CreateOutputSurface( | 110 scoped_ptr<cc::OutputSurface> DefaultContextFactory::CreateOutputSurface( |
110 Compositor* compositor) { | 111 Compositor* compositor) { |
111 return make_scoped_ptr(new cc::OutputSurface( | 112 WebKit::WebGraphicsContext3D::Attributes attrs; |
112 CreateContextCommon(compositor, false))); | 113 attrs.depth = false; |
113 } | 114 attrs.stencil = false; |
| 115 attrs.antialias = false; |
| 116 attrs.shareResources = true; |
114 | 117 |
115 scoped_ptr<WebKit::WebGraphicsContext3D> | 118 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
116 DefaultContextFactory::CreateOffscreenContext() { | 119 scoped_ptr<WebKit::WebGraphicsContext3D> context( |
117 return CreateContextCommon(NULL, true); | 120 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( |
| 121 attrs, compositor->widget())); |
| 122 return make_scoped_ptr(new cc::OutputSurface(context.Pass())); |
118 } | 123 } |
119 | 124 |
120 scoped_refptr<Reflector> DefaultContextFactory::CreateReflector( | 125 scoped_refptr<Reflector> DefaultContextFactory::CreateReflector( |
121 Compositor* mirroed_compositor, | 126 Compositor* mirroed_compositor, |
122 Layer* mirroring_layer) { | 127 Layer* mirroring_layer) { |
123 return NULL; | 128 return NULL; |
124 } | 129 } |
125 | 130 |
126 void DefaultContextFactory::RemoveReflector( | 131 void DefaultContextFactory::RemoveReflector( |
127 scoped_refptr<Reflector> reflector) { | 132 scoped_refptr<Reflector> reflector) { |
128 } | 133 } |
129 | 134 |
130 scoped_refptr<cc::ContextProvider> | 135 scoped_refptr<cc::ContextProvider> |
131 DefaultContextFactory::OffscreenContextProviderForMainThread() { | 136 DefaultContextFactory::OffscreenContextProviderForMainThread() { |
132 if (!offscreen_contexts_main_thread_.get() || | 137 if (!offscreen_contexts_main_thread_.get() || |
133 !offscreen_contexts_main_thread_->DestroyedOnMainThread()) { | 138 !offscreen_contexts_main_thread_->DestroyedOnMainThread()) { |
134 offscreen_contexts_main_thread_ = | 139 offscreen_contexts_main_thread_ = |
135 ContextProviderFromContextFactory::CreateForOffscreen(this); | 140 webkit::gpu::ContextProviderInProcess::Create(); |
136 if (offscreen_contexts_main_thread_.get() && | 141 if (offscreen_contexts_main_thread_.get() && |
137 !offscreen_contexts_main_thread_->BindToCurrentThread()) | 142 !offscreen_contexts_main_thread_->BindToCurrentThread()) |
138 offscreen_contexts_main_thread_ = NULL; | 143 offscreen_contexts_main_thread_ = NULL; |
139 } | 144 } |
140 return offscreen_contexts_main_thread_; | 145 return offscreen_contexts_main_thread_; |
141 } | 146 } |
142 | 147 |
143 scoped_refptr<cc::ContextProvider> | 148 scoped_refptr<cc::ContextProvider> |
144 DefaultContextFactory::OffscreenContextProviderForCompositorThread() { | 149 DefaultContextFactory::OffscreenContextProviderForCompositorThread() { |
145 if (!offscreen_contexts_compositor_thread_.get() || | 150 if (!offscreen_contexts_compositor_thread_.get() || |
146 !offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { | 151 !offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { |
147 offscreen_contexts_compositor_thread_ = | 152 offscreen_contexts_compositor_thread_ = |
148 ContextProviderFromContextFactory::CreateForOffscreen(this); | 153 webkit::gpu::ContextProviderInProcess::Create(); |
149 } | 154 } |
150 return offscreen_contexts_compositor_thread_; | 155 return offscreen_contexts_compositor_thread_; |
151 } | 156 } |
152 | 157 |
153 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 158 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
154 } | 159 } |
155 | 160 |
156 bool DefaultContextFactory::DoesCreateTestContexts() { return false; } | 161 bool DefaultContextFactory::DoesCreateTestContexts() { return false; } |
157 | 162 |
158 scoped_ptr<WebKit::WebGraphicsContext3D> | |
159 DefaultContextFactory::CreateContextCommon(Compositor* compositor, | |
160 bool offscreen) { | |
161 DCHECK(offscreen || compositor); | |
162 WebKit::WebGraphicsContext3D::Attributes attrs; | |
163 attrs.depth = false; | |
164 attrs.stencil = false; | |
165 attrs.antialias = false; | |
166 attrs.shareResources = true; | |
167 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
168 if (offscreen) { | |
169 return WebGraphicsContext3DInProcessCommandBufferImpl:: | |
170 CreateOffscreenContext(attrs); | |
171 } | |
172 return WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | |
173 attrs, compositor->widget()); | |
174 } | |
175 | |
176 TestContextFactory::TestContextFactory() {} | 163 TestContextFactory::TestContextFactory() {} |
177 | 164 |
178 TestContextFactory::~TestContextFactory() {} | 165 TestContextFactory::~TestContextFactory() {} |
179 | 166 |
180 scoped_ptr<cc::OutputSurface> TestContextFactory::CreateOutputSurface( | 167 scoped_ptr<cc::OutputSurface> TestContextFactory::CreateOutputSurface( |
181 Compositor* compositor) { | 168 Compositor* compositor) { |
182 return make_scoped_ptr(new cc::OutputSurface(CreateOffscreenContext())); | 169 return make_scoped_ptr(new cc::OutputSurface(CreateOffscreenContext())); |
183 } | 170 } |
184 | 171 |
185 scoped_ptr<WebKit::WebGraphicsContext3D> | |
186 TestContextFactory::CreateOffscreenContext() { | |
187 scoped_ptr<ui::TestWebGraphicsContext3D> context( | |
188 new ui::TestWebGraphicsContext3D); | |
189 context->Initialize(); | |
190 return context.PassAs<WebKit::WebGraphicsContext3D>(); | |
191 } | |
192 | |
193 scoped_refptr<Reflector> TestContextFactory::CreateReflector( | 172 scoped_refptr<Reflector> TestContextFactory::CreateReflector( |
194 Compositor* mirrored_compositor, | 173 Compositor* mirrored_compositor, |
195 Layer* mirroring_layer) { | 174 Layer* mirroring_layer) { |
196 return new Reflector(); | 175 return new Reflector(); |
197 } | 176 } |
198 | 177 |
199 void TestContextFactory::RemoveReflector(scoped_refptr<Reflector> reflector) { | 178 void TestContextFactory::RemoveReflector(scoped_refptr<Reflector> reflector) { |
200 } | 179 } |
201 | 180 |
202 scoped_refptr<cc::ContextProvider> | 181 scoped_refptr<cc::ContextProvider> |
203 TestContextFactory::OffscreenContextProviderForMainThread() { | 182 TestContextFactory::OffscreenContextProviderForMainThread() { |
204 if (!offscreen_contexts_main_thread_.get() || | 183 if (!offscreen_contexts_main_thread_.get() || |
205 offscreen_contexts_main_thread_->DestroyedOnMainThread()) { | 184 offscreen_contexts_main_thread_->DestroyedOnMainThread()) { |
206 offscreen_contexts_main_thread_ = | 185 offscreen_contexts_main_thread_ = cc::FakeContextProvider::Create( |
207 ContextProviderFromContextFactory::CreateForOffscreen(this); | 186 base::Bind(&TestContextFactory::CreateOffscreenContext)); |
208 CHECK(offscreen_contexts_main_thread_->BindToCurrentThread()); | 187 CHECK(offscreen_contexts_main_thread_->BindToCurrentThread()); |
209 } | 188 } |
210 return offscreen_contexts_main_thread_; | 189 return offscreen_contexts_main_thread_; |
211 } | 190 } |
212 | 191 |
213 scoped_refptr<cc::ContextProvider> | 192 scoped_refptr<cc::ContextProvider> |
214 TestContextFactory::OffscreenContextProviderForCompositorThread() { | 193 TestContextFactory::OffscreenContextProviderForCompositorThread() { |
215 if (!offscreen_contexts_compositor_thread_.get() || | 194 if (!offscreen_contexts_compositor_thread_.get() || |
216 offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { | 195 offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { |
217 offscreen_contexts_compositor_thread_ = | 196 offscreen_contexts_compositor_thread_ = cc::FakeContextProvider::Create( |
218 ContextProviderFromContextFactory::CreateForOffscreen(this); | 197 base::Bind(&TestContextFactory::CreateOffscreenContext)); |
219 } | 198 } |
220 return offscreen_contexts_compositor_thread_; | 199 return offscreen_contexts_compositor_thread_; |
221 } | 200 } |
222 | 201 |
223 void TestContextFactory::RemoveCompositor(Compositor* compositor) { | 202 void TestContextFactory::RemoveCompositor(Compositor* compositor) { |
224 } | 203 } |
225 | 204 |
226 bool TestContextFactory::DoesCreateTestContexts() { return true; } | 205 bool TestContextFactory::DoesCreateTestContexts() { return true; } |
227 | 206 |
| 207 // static |
| 208 scoped_ptr<WebKit::WebGraphicsContext3D> |
| 209 TestContextFactory::CreateOffscreenContext() { |
| 210 scoped_ptr<ui::TestWebGraphicsContext3D> context( |
| 211 new ui::TestWebGraphicsContext3D); |
| 212 context->Initialize(); |
| 213 return context.PassAs<WebKit::WebGraphicsContext3D>(); |
| 214 } |
| 215 |
228 Texture::Texture(bool flipped, const gfx::Size& size, float device_scale_factor) | 216 Texture::Texture(bool flipped, const gfx::Size& size, float device_scale_factor) |
229 : size_(size), | 217 : size_(size), |
230 flipped_(flipped), | 218 flipped_(flipped), |
231 device_scale_factor_(device_scale_factor) { | 219 device_scale_factor_(device_scale_factor) { |
232 } | 220 } |
233 | 221 |
234 Texture::~Texture() { | 222 Texture::~Texture() { |
235 } | 223 } |
236 | 224 |
237 std::string Texture::Produce() { | 225 std::string Texture::Produce() { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 } | 768 } |
781 | 769 |
782 void Compositor::NotifyEnd() { | 770 void Compositor::NotifyEnd() { |
783 last_ended_frame_++; | 771 last_ended_frame_++; |
784 FOR_EACH_OBSERVER(CompositorObserver, | 772 FOR_EACH_OBSERVER(CompositorObserver, |
785 observer_list_, | 773 observer_list_, |
786 OnCompositingEnded(this)); | 774 OnCompositingEnded(this)); |
787 } | 775 } |
788 | 776 |
789 } // namespace ui | 777 } // namespace ui |
OLD | NEW |