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

Side by Side Diff: ui/compositor/compositor.cc

Issue 11415089: ui/compositor: use cc/ directly instead of webkit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 8 years, 1 month 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) 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/threading/thread.h"
13 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
15 #include "cc/input_handler.h"
16 #include "cc/layer.h"
17 #include "cc/layer_tree_host.h"
18 #include "cc/thread_impl.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h" 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h"
19 #include "ui/compositor/compositor_observer.h" 21 #include "ui/compositor/compositor_observer.h"
20 #include "ui/compositor/compositor_switches.h" 22 #include "ui/compositor/compositor_switches.h"
21 #include "ui/compositor/dip_util.h" 23 #include "ui/compositor/dip_util.h"
22 #include "ui/compositor/layer.h" 24 #include "ui/compositor/layer.h"
23 #include "ui/compositor/test_web_graphics_context_3d.h" 25 #include "ui/compositor/test_web_graphics_context_3d.h"
24 #include "ui/gl/gl_context.h" 26 #include "ui/gl/gl_context.h"
25 #include "ui/gl/gl_implementation.h" 27 #include "ui/gl/gl_implementation.h"
26 #include "ui/gl/gl_surface.h" 28 #include "ui/gl/gl_surface.h"
27 #include "ui/gl/gl_switches.h" 29 #include "ui/gl/gl_switches.h"
28 #include "webkit/glue/webthread_impl.h"
29 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" 30 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
30 31
31 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
32 #include "base/chromeos/chromeos_version.h" 33 #include "base/chromeos/chromeos_version.h"
33 #endif 34 #endif
34 35
35 namespace { 36 namespace {
36 37
37 const double kDefaultRefreshRate = 60.0; 38 const double kDefaultRefreshRate = 60.0;
38 const double kTestRefreshRate = 100.0; 39 const double kTestRefreshRate = 100.0;
39 40
40 enum SwapType { 41 enum SwapType {
41 DRAW_SWAP, 42 DRAW_SWAP,
42 READPIXELS_SWAP, 43 READPIXELS_SWAP,
43 }; 44 };
44 45
45 webkit_glue::WebThreadImpl* g_compositor_thread = NULL; 46 base::Thread* g_compositor_thread = NULL;
46 47
47 bool test_compositor_enabled = false; 48 bool test_compositor_enabled = false;
48 49
49 ui::ContextFactory* g_context_factory = NULL; 50 ui::ContextFactory* g_context_factory = NULL;
50 51
51 const int kCompositorLockTimeoutMs = 67; 52 const int kCompositorLockTimeoutMs = 67;
52 53
53 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. 54 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface.
54 class WebGraphicsContextToOutputSurfaceAdapter 55 class WebGraphicsContextToOutputSurfaceAdapter
55 : public WebKit::WebCompositorOutputSurface { 56 : public WebKit::WebCompositorOutputSurface {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 gfx::AcceleratedWidget widget) 288 gfx::AcceleratedWidget widget)
288 : delegate_(delegate), 289 : delegate_(delegate),
289 root_layer_(NULL), 290 root_layer_(NULL),
290 widget_(widget), 291 widget_(widget),
291 posted_swaps_(new PostedSwapQueue()), 292 posted_swaps_(new PostedSwapQueue()),
292 device_scale_factor_(0.0f), 293 device_scale_factor_(0.0f),
293 last_started_frame_(0), 294 last_started_frame_(0),
294 last_ended_frame_(0), 295 last_ended_frame_(0),
295 disable_schedule_composite_(false), 296 disable_schedule_composite_(false),
296 compositor_lock_(NULL) { 297 compositor_lock_(NULL) {
297 WebKit::WebCompositorSupport* compositor_support = 298 root_web_layer_ = cc::Layer::create();
298 WebKit::Platform::current()->compositorSupport(); 299 root_web_layer_->setAnchorPoint(gfx::PointF(0.f, 0.f));
299 root_web_layer_.reset(compositor_support->createLayer()); 300
300 WebKit::WebLayerTreeView::Settings settings;
301 CommandLine* command_line = CommandLine::ForCurrentProcess(); 301 CommandLine* command_line = CommandLine::ForCurrentProcess();
302 settings.showFPSCounter = 302 cc::LayerTreeSettings settings;
303 command_line->HasSwitch(switches::kUIShowFPSCounter);
304 settings.showPlatformLayerTree = 303 settings.showPlatformLayerTree =
305 command_line->HasSwitch(switches::kUIShowLayerTree); 304 command_line->HasSwitch(switches::kUIShowLayerTree);
306 settings.refreshRate = 305 settings.refreshRate =
307 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; 306 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate;
308 settings.showDebugBorders = 307 settings.showDebugBorders =
309 command_line->HasSwitch(switches::kUIShowLayerBorders); 308 command_line->HasSwitch(switches::kUIShowLayerBorders);
310 settings.partialSwapEnabled = 309 settings.partialSwapEnabled =
311 command_line->HasSwitch(switches::kUIEnablePartialSwap); 310 command_line->HasSwitch(switches::kUIEnablePartialSwap);
312 settings.perTilePaintingEnabled = 311 settings.perTilePaintingEnabled =
313 command_line->HasSwitch(switches::kUIEnablePerTilePainting); 312 command_line->HasSwitch(switches::kUIEnablePerTilePainting);
314 313
315 root_web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); 314 scoped_ptr<cc::Thread> thread;
316 host_.reset(compositor_support->createLayerTreeView(this, *root_web_layer_, 315 if (g_compositor_thread) {
317 settings)); 316 thread = cc::ThreadImpl::createForDifferentThread(
317 g_compositor_thread->message_loop_proxy());
318 }
319
320 host_ = cc::LayerTreeHost::create(this, settings, thread.Pass());
321 host_->setShowFPSCounter(
322 command_line->HasSwitch(switches::kUIShowFPSCounter));
323 host_->setRootLayer(root_web_layer_);
318 host_->setSurfaceReady(); 324 host_->setSurfaceReady();
319 } 325 }
320 326
321 Compositor::~Compositor() { 327 Compositor::~Compositor() {
322 CancelCompositorLock(); 328 CancelCompositorLock();
323 DCHECK(!compositor_lock_); 329 DCHECK(!compositor_lock_);
324 330
325 // Don't call |CompositorDelegate::ScheduleDraw| from this point. 331 // Don't call |CompositorDelegate::ScheduleDraw| from this point.
326 delegate_ = NULL; 332 delegate_ = NULL;
327 if (root_layer_) 333 if (root_layer_)
328 root_layer_->SetCompositor(NULL); 334 root_layer_->SetCompositor(NULL);
329 335
330 // Stop all outstanding draws before telling the ContextFactory to tear 336 // Stop all outstanding draws before telling the ContextFactory to tear
331 // down any contexts that the |host_| may rely upon. 337 // down any contexts that the |host_| may rely upon.
332 host_.reset(); 338 host_.reset();
333 339
334 if (!test_compositor_enabled) 340 if (!test_compositor_enabled)
335 ContextFactory::GetInstance()->RemoveCompositor(this); 341 ContextFactory::GetInstance()->RemoveCompositor(this);
336 } 342 }
337 343
338 void Compositor::Initialize(bool use_thread) { 344 void Compositor::Initialize(bool use_thread) {
339 WebKit::WebCompositorSupport* compositor_support = 345 if (use_thread) {
340 WebKit::Platform::current()->compositorSupport(); 346 g_compositor_thread = new base::Thread("Browser Compositor");
341 if (use_thread) 347 g_compositor_thread->Start();
342 g_compositor_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); 348 }
343 compositor_support->initialize(g_compositor_thread);
344 } 349 }
345 350
346 void Compositor::Terminate() { 351 void Compositor::Terminate() {
347 WebKit::Platform::current()->compositorSupport()->shutdown();
348 if (g_compositor_thread) { 352 if (g_compositor_thread) {
353 g_compositor_thread->Stop();
349 delete g_compositor_thread; 354 delete g_compositor_thread;
350 g_compositor_thread = NULL; 355 g_compositor_thread = NULL;
351 } 356 }
352 } 357 }
353 358
354 void Compositor::ScheduleDraw() { 359 void Compositor::ScheduleDraw() {
355 if (g_compositor_thread) 360 if (g_compositor_thread)
356 host_->composite(); 361 host_->composite();
357 else if (delegate_) 362 else if (delegate_)
358 delegate_->ScheduleDraw(); 363 delegate_->ScheduleDraw();
359 } 364 }
360 365
361 void Compositor::SetRootLayer(Layer* root_layer) { 366 void Compositor::SetRootLayer(Layer* root_layer) {
362 if (root_layer_ == root_layer) 367 if (root_layer_ == root_layer)
363 return; 368 return;
364 if (root_layer_) 369 if (root_layer_)
365 root_layer_->SetCompositor(NULL); 370 root_layer_->SetCompositor(NULL);
366 root_layer_ = root_layer; 371 root_layer_ = root_layer;
367 if (root_layer_ && !root_layer_->GetCompositor()) 372 if (root_layer_ && !root_layer_->GetCompositor())
368 root_layer_->SetCompositor(this); 373 root_layer_->SetCompositor(this);
369 root_web_layer_->removeAllChildren(); 374 root_web_layer_->removeAllChildren();
370 if (root_layer_) 375 if (root_layer_)
371 root_web_layer_->addChild(root_layer_->web_layer()); 376 root_web_layer_->addChild(root_layer_->cc_layer());
372 } 377 }
373 378
374 void Compositor::SetHostHasTransparentBackground( 379 void Compositor::SetHostHasTransparentBackground(
375 bool host_has_transparent_background) { 380 bool host_has_transparent_background) {
376 host_->setHasTransparentBackground(host_has_transparent_background); 381 host_->setHasTransparentBackground(host_has_transparent_background);
377 } 382 }
378 383
379 void Compositor::Draw(bool force_clear) { 384 void Compositor::Draw(bool force_clear) {
380 DCHECK(!g_compositor_thread); 385 DCHECK(!g_compositor_thread);
381 386
(...skipping 29 matching lines...) Expand all
411 CancelCompositorLock(); 416 CancelCompositorLock();
412 PendingSwap pending_swap(READPIXELS_SWAP, posted_swaps_.get()); 417 PendingSwap pending_swap(READPIXELS_SWAP, posted_swaps_.get());
413 return host_->compositeAndReadback(pixels, bounds_in_pixel); 418 return host_->compositeAndReadback(pixels, bounds_in_pixel);
414 } 419 }
415 420
416 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { 421 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
417 DCHECK_GT(scale, 0); 422 DCHECK_GT(scale, 0);
418 if (size_in_pixel.IsEmpty() || scale <= 0) 423 if (size_in_pixel.IsEmpty() || scale <= 0)
419 return; 424 return;
420 size_ = size_in_pixel; 425 size_ = size_in_pixel;
421 host_->setViewportSize(size_in_pixel); 426 host_->setViewportSize(size_in_pixel, size_in_pixel);
422 root_web_layer_->setBounds(size_in_pixel); 427 root_web_layer_->setBounds(size_in_pixel);
423 428
424 if (device_scale_factor_ != scale) { 429 if (device_scale_factor_ != scale) {
425 device_scale_factor_ = scale; 430 device_scale_factor_ = scale;
426 if (root_layer_) 431 if (root_layer_)
427 root_layer_->OnDeviceScaleFactorChanged(scale); 432 root_layer_->OnDeviceScaleFactorChanged(scale);
428 } 433 }
429 } 434 }
430 435
431 void Compositor::AddObserver(CompositorObserver* observer) { 436 void Compositor::AddObserver(CompositorObserver* observer) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (posted_swaps_->NextPostedSwap() == DRAW_SWAP) 468 if (posted_swaps_->NextPostedSwap() == DRAW_SWAP)
464 NotifyEnd(); 469 NotifyEnd();
465 posted_swaps_->EndSwap(); 470 posted_swaps_->EndSwap();
466 } 471 }
467 472
468 FOR_EACH_OBSERVER(CompositorObserver, 473 FOR_EACH_OBSERVER(CompositorObserver,
469 observer_list_, 474 observer_list_,
470 OnCompositingAborted(this)); 475 OnCompositingAborted(this));
471 } 476 }
472 477
473 void Compositor::updateAnimations(double frameBeginTime) { 478 void Compositor::willBeginFrame() {
479 }
480
481 void Compositor::didBeginFrame() {
482 }
483
484 void Compositor::animate(double frameBeginTime) {
474 } 485 }
475 486
476 void Compositor::layout() { 487 void Compositor::layout() {
477 // We're sending damage that will be addressed during this composite 488 // We're sending damage that will be addressed during this composite
478 // cycle, so we don't need to schedule another composite to address it. 489 // cycle, so we don't need to schedule another composite to address it.
479 disable_schedule_composite_ = true; 490 disable_schedule_composite_ = true;
480 if (root_layer_) 491 if (root_layer_)
481 root_layer_->SendDamagedRects(); 492 root_layer_->SendDamagedRects();
482 disable_schedule_composite_ = false; 493 disable_schedule_composite_ = false;
483 } 494 }
484 495
485 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, 496 void Compositor::applyScrollAndScale(gfx::Vector2d scrollDelta,
486 float scaleFactor) { 497 float pageScale) {
487 } 498 }
488 499
489 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() { 500 scoped_ptr<WebKit::WebCompositorOutputSurface>
501 Compositor::createOutputSurface() {
490 if (test_compositor_enabled) { 502 if (test_compositor_enabled) {
491 ui::TestWebGraphicsContext3D* test_context = 503 ui::TestWebGraphicsContext3D* test_context =
492 new ui::TestWebGraphicsContext3D(); 504 new ui::TestWebGraphicsContext3D();
493 test_context->Initialize(); 505 test_context->Initialize();
494 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); 506 return scoped_ptr<WebKit::WebCompositorOutputSurface>(
507 new WebGraphicsContextToOutputSurfaceAdapter(test_context));
495 } else { 508 } else {
496 return ContextFactory::GetInstance()->CreateOutputSurface(this); 509 return scoped_ptr<WebKit::WebCompositorOutputSurface>(
510 ContextFactory::GetInstance()->CreateOutputSurface(this));
497 } 511 }
498 } 512 }
499 513
500 void Compositor::didRecreateOutputSurface(bool success) { 514 void Compositor::didRecreateOutputSurface(bool success) {
501 } 515 }
502 516
517 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() {
518 return scoped_ptr<cc::InputHandler>();
519 }
520
521 void Compositor::willCommit() {
522 }
523
503 void Compositor::didCommit() { 524 void Compositor::didCommit() {
504 DCHECK(!IsLocked()); 525 DCHECK(!IsLocked());
505 FOR_EACH_OBSERVER(CompositorObserver, 526 FOR_EACH_OBSERVER(CompositorObserver,
506 observer_list_, 527 observer_list_,
507 OnCompositingDidCommit(this)); 528 OnCompositingDidCommit(this));
508 } 529 }
509 530
510 void Compositor::didCommitAndDrawFrame() { 531 void Compositor::didCommitAndDrawFrame() {
511 FOR_EACH_OBSERVER(CompositorObserver, 532 FOR_EACH_OBSERVER(CompositorObserver,
512 observer_list_, 533 observer_list_,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 593
573 COMPOSITOR_EXPORT void DisableTestCompositor() { 594 COMPOSITOR_EXPORT void DisableTestCompositor() {
574 test_compositor_enabled = false; 595 test_compositor_enabled = false;
575 } 596 }
576 597
577 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { 598 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() {
578 return test_compositor_enabled; 599 return test_compositor_enabled;
579 } 600 }
580 601
581 } // namespace ui 602 } // namespace ui
OLDNEW
« cc/proxy.h ('K') | « ui/compositor/compositor.h ('k') | ui/compositor/compositor.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698