| 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/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "cc/font_atlas.h" | 16 #include "cc/font_atlas.h" |
| 17 #include "cc/input_handler.h" | 17 #include "cc/input_handler.h" |
| 18 #include "cc/layer.h" | 18 #include "cc/layer.h" |
| 19 #include "cc/layer_tree_host.h" | 19 #include "cc/layer_tree_host.h" |
| 20 #include "cc/output_surface.h" | 20 #include "cc/output_surface.h" |
| 21 #include "cc/thread_impl.h" | 21 #include "cc/thread_impl.h" |
| 22 #include "skia/ext/refptr.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "third_party/skia/include/gpu/GrContext.h" |
| 25 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 23 #include "ui/compositor/compositor_observer.h" | 26 #include "ui/compositor/compositor_observer.h" |
| 24 #include "ui/compositor/compositor_switches.h" | 27 #include "ui/compositor/compositor_switches.h" |
| 25 #include "ui/compositor/dip_util.h" | 28 #include "ui/compositor/dip_util.h" |
| 26 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.h" |
| 27 #include "ui/compositor/test_web_graphics_context_3d.h" | 30 #include "ui/compositor/test_web_graphics_context_3d.h" |
| 28 #include "ui/gl/gl_context.h" | 31 #include "ui/gl/gl_context.h" |
| 29 #include "ui/gl/gl_implementation.h" | 32 #include "ui/gl/gl_implementation.h" |
| 30 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
| 31 #include "ui/gl/gl_switches.h" | 34 #include "ui/gl/gl_switches.h" |
| 32 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" | 35 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( | 159 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( |
| 157 Compositor* compositor) { | 160 Compositor* compositor) { |
| 158 return new WebGraphicsContextToOutputSurfaceAdapter( | 161 return new WebGraphicsContextToOutputSurfaceAdapter( |
| 159 CreateContextCommon(compositor, false)); | 162 CreateContextCommon(compositor, false)); |
| 160 } | 163 } |
| 161 | 164 |
| 162 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 165 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
| 163 return CreateContextCommon(NULL, true); | 166 return CreateContextCommon(NULL, true); |
| 164 } | 167 } |
| 165 | 168 |
| 169 WebKit::WebGraphicsContext3D* DefaultContextFactory:: |
| 170 CreateOrGetOffscreenSkiaContextForMainThread() { |
| 171 CreateOrGetOffscreenContextCommon( |
| 172 &offscreen_skia_context_main_thread_, |
| 173 &offscreen_skia_gr_context_main_thread_); |
| 174 return offscreen_skia_context_main_thread_.get(); |
| 175 } |
| 176 |
| 177 WebKit::WebGraphicsContext3D* DefaultContextFactory:: |
| 178 CreateOrGetOffscreenSkiaContextForCompositorThread() { |
| 179 CreateOrGetOffscreenContextCommon( |
| 180 &offscreen_skia_context_compositor_thread_, |
| 181 &offscreen_skia_gr_context_compositor_thread_); |
| 182 return offscreen_skia_context_compositor_thread_.get(); |
| 183 } |
| 184 |
| 185 GrContext* DefaultContextFactory:: |
| 186 CreateOrGetOffscreenSkiaGrContextForMainThread() { |
| 187 CreateOrGetOffscreenSkiaContextForMainThread(); |
| 188 if (!offscreen_skia_context_main_thread_) |
| 189 return NULL; |
| 190 |
| 191 if (!offscreen_skia_gr_context_main_thread_) { |
| 192 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef( |
| 193 offscreen_skia_context_main_thread_->createGrGLInterface()); |
| 194 offscreen_skia_gr_context_main_thread_ = skia::AdoptRef(GrContext::Create( |
| 195 kOpenGL_Shaders_GrEngine, |
| 196 reinterpret_cast<GrPlatform3DContext>(interface.get()))); |
| 197 } |
| 198 return offscreen_skia_gr_context_main_thread_.get(); |
| 199 } |
| 200 |
| 201 GrContext* DefaultContextFactory:: |
| 202 CreateOrGetOffscreenSkiaGrContextForCompositorThread() { |
| 203 CreateOrGetOffscreenSkiaContextForCompositorThread(); |
| 204 if (!offscreen_skia_context_compositor_thread_) |
| 205 return NULL; |
| 206 |
| 207 if (!offscreen_skia_gr_context_compositor_thread_) { |
| 208 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef( |
| 209 offscreen_skia_context_compositor_thread_->createGrGLInterface()); |
| 210 offscreen_skia_gr_context_compositor_thread_ = |
| 211 skia::AdoptRef(GrContext::Create( |
| 212 kOpenGL_Shaders_GrEngine, |
| 213 reinterpret_cast<GrPlatform3DContext>(interface.get()))); |
| 214 } |
| 215 return offscreen_skia_gr_context_compositor_thread_.get(); |
| 216 } |
| 217 |
| 166 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 218 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
| 167 } | 219 } |
| 168 | 220 |
| 169 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 221 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
| 170 Compositor* compositor, | 222 Compositor* compositor, |
| 171 bool offscreen) { | 223 bool offscreen) { |
| 172 DCHECK(offscreen || compositor); | 224 DCHECK(offscreen || compositor); |
| 173 WebKit::WebGraphicsContext3D::Attributes attrs; | 225 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 174 attrs.depth = false; | 226 attrs.depth = false; |
| 175 attrs.stencil = false; | 227 attrs.stencil = false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 188 if (!offscreen) { | 240 if (!offscreen) { |
| 189 context->makeContextCurrent(); | 241 context->makeContextCurrent(); |
| 190 gfx::GLContext* gl_context = gfx::GLContext::GetCurrent(); | 242 gfx::GLContext* gl_context = gfx::GLContext::GetCurrent(); |
| 191 bool vsync = !command_line->HasSwitch(switches::kDisableGpuVsync); | 243 bool vsync = !command_line->HasSwitch(switches::kDisableGpuVsync); |
| 192 gl_context->SetSwapInterval(vsync ? 1 : 0); | 244 gl_context->SetSwapInterval(vsync ? 1 : 0); |
| 193 gl_context->ReleaseCurrent(NULL); | 245 gl_context->ReleaseCurrent(NULL); |
| 194 } | 246 } |
| 195 return context; | 247 return context; |
| 196 } | 248 } |
| 197 | 249 |
| 250 void DefaultContextFactory::CreateOrGetOffscreenContextCommon( |
| 251 scoped_ptr<WebKit::WebGraphicsContext3D>* context3d, |
| 252 skia::RefPtr<GrContext>* gr_context) { |
| 253 if ((*context3d)) { |
| 254 if (!(*context3d)->makeContextCurrent() || |
| 255 (*context3d)->getGraphicsResetStatusARB()) { |
| 256 if ((*gr_context)) |
| 257 (*gr_context)->contextDestroyed(); |
| 258 gr_context->clear(); |
| 259 context3d->reset(); |
| 260 } |
| 261 } |
| 262 |
| 263 if (!(*context3d)) |
| 264 (*context3d) = make_scoped_ptr(CreateOffscreenContext()); |
| 265 } |
| 266 |
| 198 Texture::Texture(bool flipped, const gfx::Size& size, float device_scale_factor) | 267 Texture::Texture(bool flipped, const gfx::Size& size, float device_scale_factor) |
| 199 : size_(size), | 268 : size_(size), |
| 200 flipped_(flipped), | 269 flipped_(flipped), |
| 201 device_scale_factor_(device_scale_factor) { | 270 device_scale_factor_(device_scale_factor) { |
| 202 } | 271 } |
| 203 | 272 |
| 204 Texture::~Texture() { | 273 Texture::~Texture() { |
| 205 } | 274 } |
| 206 | 275 |
| 207 std::string Texture::Produce() { | 276 std::string Texture::Produce() { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); | 583 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); |
| 515 } else { | 584 } else { |
| 516 return scoped_ptr<cc::OutputSurface>( | 585 return scoped_ptr<cc::OutputSurface>( |
| 517 ContextFactory::GetInstance()->CreateOutputSurface(this)); | 586 ContextFactory::GetInstance()->CreateOutputSurface(this)); |
| 518 } | 587 } |
| 519 } | 588 } |
| 520 | 589 |
| 521 void Compositor::didRecreateOutputSurface(bool success) { | 590 void Compositor::didRecreateOutputSurface(bool success) { |
| 522 } | 591 } |
| 523 | 592 |
| 593 WebKit::WebGraphicsContext3D* |
| 594 Compositor::createOrGetOffscreenContext3dForMainThread() { |
| 595 return ContextFactory::GetInstance()-> |
| 596 CreateOrGetOffscreenSkiaContextForMainThread(); |
| 597 } |
| 598 |
| 599 WebKit::WebGraphicsContext3D* |
| 600 Compositor::createOrGetOffscreenContext3dForCompositorThread() { |
| 601 return ContextFactory::GetInstance()-> |
| 602 CreateOrGetOffscreenSkiaContextForCompositorThread(); |
| 603 } |
| 604 |
| 605 GrContext* Compositor::createOrGetOffscreenGrContextForMainThread() { |
| 606 return ContextFactory::GetInstance()-> |
| 607 CreateOrGetOffscreenSkiaGrContextForMainThread(); |
| 608 } |
| 609 |
| 610 GrContext* Compositor::createOrGetOffscreenGrContextForCompositorThread() { |
| 611 return ContextFactory::GetInstance()-> |
| 612 CreateOrGetOffscreenSkiaGrContextForCompositorThread(); |
| 613 } |
| 614 |
| 524 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { | 615 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { |
| 525 return scoped_ptr<cc::InputHandler>(); | 616 return scoped_ptr<cc::InputHandler>(); |
| 526 } | 617 } |
| 527 | 618 |
| 528 void Compositor::willCommit() { | 619 void Compositor::willCommit() { |
| 529 } | 620 } |
| 530 | 621 |
| 531 void Compositor::didCommit() { | 622 void Compositor::didCommit() { |
| 532 DCHECK(!IsLocked()); | 623 DCHECK(!IsLocked()); |
| 533 FOR_EACH_OBSERVER(CompositorObserver, | 624 FOR_EACH_OBSERVER(CompositorObserver, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 695 |
| 605 COMPOSITOR_EXPORT void DisableTestCompositor() { | 696 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 606 g_test_compositor_enabled = false; | 697 g_test_compositor_enabled = false; |
| 607 } | 698 } |
| 608 | 699 |
| 609 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 700 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 610 return g_test_compositor_enabled; | 701 return g_test_compositor_enabled; |
| 611 } | 702 } |
| 612 | 703 |
| 613 } // namespace ui | 704 } // namespace ui |
| OLD | NEW |