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

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

Issue 307963007: Removes ContextFactory::Get/SetInstance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix aura_bench Created 6 years, 6 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
« no previous file with comments | « ui/compositor/compositor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 17 matching lines...) Expand all
28 #include "ui/compositor/layer.h" 28 #include "ui/compositor/layer.h"
29 #include "ui/gfx/frame_time.h" 29 #include "ui/gfx/frame_time.h"
30 #include "ui/gl/gl_context.h" 30 #include "ui/gl/gl_context.h"
31 #include "ui/gl/gl_switches.h" 31 #include "ui/gl/gl_switches.h"
32 32
33 namespace { 33 namespace {
34 34
35 const double kDefaultRefreshRate = 60.0; 35 const double kDefaultRefreshRate = 60.0;
36 const double kTestRefreshRate = 200.0; 36 const double kTestRefreshRate = 200.0;
37 37
38 ui::ContextFactory* g_context_factory = NULL;
39
40 const int kCompositorLockTimeoutMs = 67; 38 const int kCompositorLockTimeoutMs = 67;
41 39
42 } // namespace 40 } // namespace
43 41
44 namespace ui { 42 namespace ui {
45 43
46 // static
47 ContextFactory* ContextFactory::GetInstance() {
48 DCHECK(g_context_factory);
49 return g_context_factory;
50 }
51
52 // static
53 void ContextFactory::SetInstance(ContextFactory* instance) {
54 DCHECK_NE(!!g_context_factory, !!instance);
55 g_context_factory = instance;
56 }
57
58 CompositorLock::CompositorLock(Compositor* compositor) 44 CompositorLock::CompositorLock(Compositor* compositor)
59 : compositor_(compositor) { 45 : compositor_(compositor) {
60 base::MessageLoop::current()->PostDelayedTask( 46 base::MessageLoop::current()->PostDelayedTask(
61 FROM_HERE, 47 FROM_HERE,
62 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), 48 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()),
63 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); 49 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
64 } 50 }
65 51
66 CompositorLock::~CompositorLock() { 52 CompositorLock::~CompositorLock() {
67 CancelLock(); 53 CancelLock();
68 } 54 }
69 55
70 void CompositorLock::CancelLock() { 56 void CompositorLock::CancelLock() {
71 if (!compositor_) 57 if (!compositor_)
72 return; 58 return;
73 compositor_->UnlockCompositor(); 59 compositor_->UnlockCompositor();
74 compositor_ = NULL; 60 compositor_ = NULL;
75 } 61 }
76 62
77 } // namespace ui 63 } // namespace ui
78 64
79 namespace { 65 namespace {
80 66
81 } // namespace 67 } // namespace
82 68
83 namespace ui { 69 namespace ui {
84 70
85 Compositor::Compositor(gfx::AcceleratedWidget widget)
86 : context_factory_(g_context_factory),
87 root_layer_(NULL),
88 widget_(widget),
89 compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()),
90 vsync_manager_(new CompositorVSyncManager()),
91 device_scale_factor_(0.0f),
92 last_started_frame_(0),
93 last_ended_frame_(0),
94 disable_schedule_composite_(false),
95 compositor_lock_(NULL),
96 defer_draw_scheduling_(false),
97 waiting_on_compositing_end_(false),
98 draw_on_compositing_end_(false),
99 swap_state_(SWAP_NONE),
100 schedule_draw_factory_(this) {
101 Init();
102 }
103
104 Compositor::Compositor(gfx::AcceleratedWidget widget, 71 Compositor::Compositor(gfx::AcceleratedWidget widget,
105 ui::ContextFactory* context_factory) 72 ui::ContextFactory* context_factory)
106 : context_factory_(context_factory), 73 : context_factory_(context_factory),
107 root_layer_(NULL), 74 root_layer_(NULL),
108 widget_(widget), 75 widget_(widget),
109 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), 76 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
110 vsync_manager_(new CompositorVSyncManager()), 77 vsync_manager_(new CompositorVSyncManager()),
111 device_scale_factor_(0.0f), 78 device_scale_factor_(0.0f),
112 last_started_frame_(0), 79 last_started_frame_(0),
113 last_ended_frame_(0), 80 last_ended_frame_(0),
114 disable_schedule_composite_(false), 81 disable_schedule_composite_(false),
115 compositor_lock_(NULL), 82 compositor_lock_(NULL),
116 defer_draw_scheduling_(false), 83 defer_draw_scheduling_(false),
117 waiting_on_compositing_end_(false), 84 waiting_on_compositing_end_(false),
118 draw_on_compositing_end_(false), 85 draw_on_compositing_end_(false),
119 swap_state_(SWAP_NONE), 86 swap_state_(SWAP_NONE),
120 schedule_draw_factory_(this) { 87 schedule_draw_factory_(this) {
121 Init();
122 }
123
124 // Yes, this is the wrong place. I'm leaving here to minimize diffs since this
125 // function will be nuked soonish.
126 void Compositor::Init() {
127 root_web_layer_ = cc::Layer::Create(); 88 root_web_layer_ = cc::Layer::Create();
128 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); 89 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
129 90
130 CommandLine* command_line = CommandLine::ForCurrentProcess(); 91 CommandLine* command_line = CommandLine::ForCurrentProcess();
131 92
132 cc::LayerTreeSettings settings; 93 cc::LayerTreeSettings settings;
133 settings.refresh_rate = 94 settings.refresh_rate =
134 context_factory_->DoesCreateTestContexts() 95 context_factory_->DoesCreateTestContexts()
135 ? kTestRefreshRate 96 ? kTestRefreshRate
136 : kDefaultRefreshRate; 97 : kDefaultRefreshRate;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // CompositorObservers to be notified before starting another 390 // CompositorObservers to be notified before starting another
430 // draw cycle. 391 // draw cycle.
431 ScheduleDraw(); 392 ScheduleDraw();
432 } 393 }
433 FOR_EACH_OBSERVER(CompositorObserver, 394 FOR_EACH_OBSERVER(CompositorObserver,
434 observer_list_, 395 observer_list_,
435 OnCompositingEnded(this)); 396 OnCompositingEnded(this));
436 } 397 }
437 398
438 } // namespace ui 399 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698