Commit 4183bf09 authored by sky@chromium.org's avatar sky@chromium.org

Temporarily adds another constructor to Compositor

I'm doing this to avoid a gargantuan patch (see
https://codereview.chromium.org/273073002/ for how out of control
everything is right now).

BUG=none
TEST=none
R=piman@chromium.org

Review URL: https://codereview.chromium.org/285373012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271245 0039d316-1c4b-4281-b951-d872f2087c98
parent d01d5bb3
...@@ -83,7 +83,8 @@ namespace { ...@@ -83,7 +83,8 @@ namespace {
namespace ui { namespace ui {
Compositor::Compositor(gfx::AcceleratedWidget widget) Compositor::Compositor(gfx::AcceleratedWidget widget)
: root_layer_(NULL), : context_factory_(g_context_factory),
root_layer_(NULL),
widget_(widget), widget_(widget),
compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()), compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()),
vsync_manager_(new CompositorVSyncManager()), vsync_manager_(new CompositorVSyncManager()),
...@@ -97,6 +98,32 @@ Compositor::Compositor(gfx::AcceleratedWidget widget) ...@@ -97,6 +98,32 @@ Compositor::Compositor(gfx::AcceleratedWidget widget)
draw_on_compositing_end_(false), draw_on_compositing_end_(false),
swap_state_(SWAP_NONE), swap_state_(SWAP_NONE),
schedule_draw_factory_(this) { schedule_draw_factory_(this) {
Init();
}
Compositor::Compositor(gfx::AcceleratedWidget widget,
ui::ContextFactory* context_factory)
: context_factory_(context_factory),
root_layer_(NULL),
widget_(widget),
compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
vsync_manager_(new CompositorVSyncManager()),
device_scale_factor_(0.0f),
last_started_frame_(0),
last_ended_frame_(0),
disable_schedule_composite_(false),
compositor_lock_(NULL),
defer_draw_scheduling_(false),
waiting_on_compositing_end_(false),
draw_on_compositing_end_(false),
swap_state_(SWAP_NONE),
schedule_draw_factory_(this) {
Init();
}
// Yes, this is the wrong place. I'm leaving here to minimize diffs since this
// function will be nuked soonish.
void Compositor::Init() {
root_web_layer_ = cc::Layer::Create(); root_web_layer_ = cc::Layer::Create();
root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
...@@ -104,7 +131,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget) ...@@ -104,7 +131,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget)
cc::LayerTreeSettings settings; cc::LayerTreeSettings settings;
settings.refresh_rate = settings.refresh_rate =
ContextFactory::GetInstance()->DoesCreateTestContexts() context_factory_->DoesCreateTestContexts()
? kTestRefreshRate ? kTestRefreshRate
: kDefaultRefreshRate; : kDefaultRefreshRate;
settings.main_frame_before_draw_enabled = false; settings.main_frame_before_draw_enabled = false;
...@@ -149,12 +176,12 @@ Compositor::Compositor(gfx::AcceleratedWidget widget) ...@@ -149,12 +176,12 @@ Compositor::Compositor(gfx::AcceleratedWidget widget)
if (compositor_thread_loop_) { if (compositor_thread_loop_) {
host_ = cc::LayerTreeHost::CreateThreaded( host_ = cc::LayerTreeHost::CreateThreaded(
this, this,
g_context_factory->GetSharedBitmapManager(), context_factory_->GetSharedBitmapManager(),
settings, settings,
compositor_thread_loop_); compositor_thread_loop_);
} else { } else {
host_ = cc::LayerTreeHost::CreateSingleThreaded( host_ = cc::LayerTreeHost::CreateSingleThreaded(
this, this, g_context_factory->GetSharedBitmapManager(), settings); this, this, context_factory_->GetSharedBitmapManager(), settings);
} }
UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
base::TimeTicks::Now() - before_create); base::TimeTicks::Now() - before_create);
...@@ -175,7 +202,7 @@ Compositor::~Compositor() { ...@@ -175,7 +202,7 @@ Compositor::~Compositor() {
// down any contexts that the |host_| may rely upon. // down any contexts that the |host_| may rely upon.
host_.reset(); host_.reset();
ContextFactory::GetInstance()->RemoveCompositor(this); context_factory_->RemoveCompositor(this);
} }
void Compositor::ScheduleDraw() { void Compositor::ScheduleDraw() {
...@@ -300,7 +327,7 @@ void Compositor::Layout() { ...@@ -300,7 +327,7 @@ void Compositor::Layout() {
} }
scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) {
return ContextFactory::GetInstance()->CreateOutputSurface(this, fallback); return context_factory_->CreateOutputSurface(this, fallback);
} }
void Compositor::DidCommit() { void Compositor::DidCommit() {
......
...@@ -136,9 +136,15 @@ class COMPOSITOR_EXPORT Compositor ...@@ -136,9 +136,15 @@ class COMPOSITOR_EXPORT Compositor
: NON_EXPORTED_BASE(public cc::LayerTreeHostClient), : NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
public: public:
// This is deprecated, and will be removed shortly.
// TODO(sky): remove this.
explicit Compositor(gfx::AcceleratedWidget widget); explicit Compositor(gfx::AcceleratedWidget widget);
Compositor(gfx::AcceleratedWidget widget,
ui::ContextFactory* context_factory);
virtual ~Compositor(); virtual ~Compositor();
ui::ContextFactory* context_factory() { return context_factory_; }
// Schedules a redraw of the layer tree associated with this compositor. // Schedules a redraw of the layer tree associated with this compositor.
void ScheduleDraw(); void ScheduleDraw();
...@@ -248,6 +254,11 @@ class COMPOSITOR_EXPORT Compositor ...@@ -248,6 +254,11 @@ class COMPOSITOR_EXPORT Compositor
friend class base::RefCounted<Compositor>; friend class base::RefCounted<Compositor>;
friend class CompositorLock; friend class CompositorLock;
// Called from both constructors. It's temporary while we have both
// constructors.
// TODO(sky): nuke this.
void Init();
// Called by CompositorLock. // Called by CompositorLock.
void UnlockCompositor(); void UnlockCompositor();
...@@ -259,6 +270,8 @@ class COMPOSITOR_EXPORT Compositor ...@@ -259,6 +270,8 @@ class COMPOSITOR_EXPORT Compositor
gfx::Size size_; gfx::Size size_;
ui::ContextFactory* context_factory_;
// The root of the Layer tree drawn by this compositor. // The root of the Layer tree drawn by this compositor.
Layer* root_layer_; Layer* root_layer_;
......
...@@ -90,10 +90,12 @@ class LayerWithRealCompositorTest : public testing::Test { ...@@ -90,10 +90,12 @@ class LayerWithRealCompositorTest : public testing::Test {
// Overridden from testing::Test: // Overridden from testing::Test:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
bool enable_pixel_output = true; bool enable_pixel_output = true;
ui::ContextFactory* context_factory =
InitializeContextFactoryForTests(enable_pixel_output); InitializeContextFactoryForTests(enable_pixel_output);
const gfx::Rect host_bounds(10, 10, 500, 500); const gfx::Rect host_bounds(10, 10, 500, 500);
compositor_host_.reset(TestCompositorHost::Create(host_bounds)); compositor_host_.reset(TestCompositorHost::Create(
host_bounds, context_factory));
compositor_host_->Show(); compositor_host_->Show();
} }
...@@ -397,10 +399,12 @@ class LayerWithDelegateTest : public testing::Test { ...@@ -397,10 +399,12 @@ class LayerWithDelegateTest : public testing::Test {
// Overridden from testing::Test: // Overridden from testing::Test:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
InitializeContextFactoryForTests(enable_pixel_output); InitializeContextFactoryForTests(enable_pixel_output);
const gfx::Rect host_bounds(1000, 1000); const gfx::Rect host_bounds(1000, 1000);
compositor_host_.reset(TestCompositorHost::Create(host_bounds)); compositor_host_.reset(TestCompositorHost::Create(host_bounds,
context_factory));
compositor_host_->Show(); compositor_host_->Show();
} }
......
...@@ -21,7 +21,7 @@ static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL; ...@@ -21,7 +21,7 @@ static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL;
namespace ui { namespace ui {
// static // static
void InitializeContextFactoryForTests(bool enable_pixel_output) { ui::ContextFactory* InitializeContextFactoryForTests(bool enable_pixel_output) {
DCHECK(!g_implicit_factory) << DCHECK(!g_implicit_factory) <<
"ContextFactory for tests already initialized."; "ContextFactory for tests already initialized.";
CommandLine* command_line = CommandLine::ForCurrentProcess(); CommandLine* command_line = CommandLine::ForCurrentProcess();
...@@ -31,6 +31,7 @@ void InitializeContextFactoryForTests(bool enable_pixel_output) { ...@@ -31,6 +31,7 @@ void InitializeContextFactoryForTests(bool enable_pixel_output) {
g_disable_null_draw = new gfx::DisableNullDrawGLBindings; g_disable_null_draw = new gfx::DisableNullDrawGLBindings;
g_implicit_factory = new InProcessContextFactory(); g_implicit_factory = new InProcessContextFactory();
ContextFactory::SetInstance(g_implicit_factory); ContextFactory::SetInstance(g_implicit_factory);
return g_implicit_factory;
} }
void TerminateContextFactoryForTests() { void TerminateContextFactoryForTests() {
......
...@@ -4,13 +4,17 @@ ...@@ -4,13 +4,17 @@
namespace ui { namespace ui {
class ContextFactory;
// Set up the compositor ContextFactory for a test environment. Unit tests // Set up the compositor ContextFactory for a test environment. Unit tests
// that do not have a full content environment need to call this before // that do not have a full content environment need to call this before
// initializing the Compositor. // initializing the Compositor.
// Some tests expect pixel output, and they should pass true for // Some tests expect pixel output, and they should pass true for
// |enable_pixel_output|. Most unit tests should pass false. Once this has been // |enable_pixel_output|. Most unit tests should pass false. Once this has been
// called, the caller must call TerminateContextFactoryForTests() to clean up. // called, the caller must call TerminateContextFactoryForTests() to clean up.
void InitializeContextFactoryForTests(bool enable_pixel_output); // TODO(sky): this should return a scoped_ptr and then nuke
// TerminateContextFactoryForTests().
ui::ContextFactory* InitializeContextFactoryForTests(bool enable_pixel_output);
void TerminateContextFactoryForTests(); void TerminateContextFactoryForTests();
} // namespace ui } // namespace ui
...@@ -12,13 +12,15 @@ class Rect; ...@@ -12,13 +12,15 @@ class Rect;
namespace ui { namespace ui {
class Compositor; class Compositor;
class ContextFactory;
class TestCompositorHost { class TestCompositorHost {
public: public:
virtual ~TestCompositorHost() {} virtual ~TestCompositorHost() {}
// Creates a new TestCompositorHost. The caller owns the returned value. // Creates a new TestCompositorHost. The caller owns the returned value.
static TestCompositorHost* Create(const gfx::Rect& bounds); static TestCompositorHost* Create(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
// Shows the TestCompositorHost. // Shows the TestCompositorHost.
virtual void Show() = 0; virtual void Show() = 0;
......
...@@ -81,7 +81,8 @@ class AppKitHost : public FoundationHost { ...@@ -81,7 +81,8 @@ class AppKitHost : public FoundationHost {
class TestCompositorHostMac : public TestCompositorHost, class TestCompositorHostMac : public TestCompositorHost,
public AppKitHost { public AppKitHost {
public: public:
TestCompositorHostMac(const gfx::Rect& bounds); TestCompositorHostMac(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
virtual ~TestCompositorHostMac(); virtual ~TestCompositorHostMac();
private: private:
...@@ -90,6 +91,9 @@ class TestCompositorHostMac : public TestCompositorHost, ...@@ -90,6 +91,9 @@ class TestCompositorHostMac : public TestCompositorHost,
virtual ui::Compositor* GetCompositor() OVERRIDE; virtual ui::Compositor* GetCompositor() OVERRIDE;
gfx::Rect bounds_; gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
scoped_ptr<ui::Compositor> compositor_; scoped_ptr<ui::Compositor> compositor_;
// Owned. Released when window is closed. // Owned. Released when window is closed.
...@@ -98,8 +102,10 @@ class TestCompositorHostMac : public TestCompositorHost, ...@@ -98,8 +102,10 @@ class TestCompositorHostMac : public TestCompositorHost,
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostMac); DISALLOW_COPY_AND_ASSIGN(TestCompositorHostMac);
}; };
TestCompositorHostMac::TestCompositorHostMac(const gfx::Rect& bounds) TestCompositorHostMac::TestCompositorHostMac(
: bounds_(bounds), window_(nil) { const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds), context_factory_(context_factory), window_(nil) {
} }
TestCompositorHostMac::~TestCompositorHostMac() { TestCompositorHostMac::~TestCompositorHostMac() {
...@@ -124,7 +130,7 @@ void TestCompositorHostMac::Show() { ...@@ -124,7 +130,7 @@ void TestCompositorHostMac::Show() {
defer:NO]; defer:NO];
base::scoped_nsobject<AcceleratedTestView> view( base::scoped_nsobject<AcceleratedTestView> view(
[[AcceleratedTestView alloc] init]); [[AcceleratedTestView alloc] init]);
compositor_.reset(new ui::Compositor(view)); compositor_.reset(new ui::Compositor(view, context_factory_));
compositor_->SetScaleAndSize(1.0f, bounds_.size()); compositor_->SetScaleAndSize(1.0f, bounds_.size());
[view setCompositor:compositor_.get()]; [view setCompositor:compositor_.get()];
[window_ setContentView:view]; [window_ setContentView:view];
...@@ -136,8 +142,10 @@ ui::Compositor* TestCompositorHostMac::GetCompositor() { ...@@ -136,8 +142,10 @@ ui::Compositor* TestCompositorHostMac::GetCompositor() {
} }
// static // static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { TestCompositorHost* TestCompositorHost::Create(
return new TestCompositorHostMac(bounds); const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostMac(bounds, context_factory);
} }
} // namespace ui } // namespace ui
...@@ -18,7 +18,8 @@ namespace ui { ...@@ -18,7 +18,8 @@ namespace ui {
class TestCompositorHostOzone : public TestCompositorHost { class TestCompositorHostOzone : public TestCompositorHost {
public: public:
TestCompositorHostOzone(const gfx::Rect& bounds); TestCompositorHostOzone(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
virtual ~TestCompositorHostOzone(); virtual ~TestCompositorHostOzone();
private: private:
...@@ -30,13 +31,18 @@ class TestCompositorHostOzone : public TestCompositorHost { ...@@ -30,13 +31,18 @@ class TestCompositorHostOzone : public TestCompositorHost {
gfx::Rect bounds_; gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
scoped_ptr<ui::Compositor> compositor_; scoped_ptr<ui::Compositor> compositor_;
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone); DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone);
}; };
TestCompositorHostOzone::TestCompositorHostOzone(const gfx::Rect& bounds) TestCompositorHostOzone::TestCompositorHostOzone(
: bounds_(bounds) {} const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds),
context_factory_(context_factory) {}
TestCompositorHostOzone::~TestCompositorHostOzone() {} TestCompositorHostOzone::~TestCompositorHostOzone() {}
...@@ -48,7 +54,7 @@ void TestCompositorHostOzone::Show() { ...@@ -48,7 +54,7 @@ void TestCompositorHostOzone::Show() {
// with a non-0 widget. // with a non-0 widget.
// TODO(rjkroege): Use a "real" ozone widget when it is // TODO(rjkroege): Use a "real" ozone widget when it is
// available: http://crbug.com/255128 // available: http://crbug.com/255128
compositor_.reset(new ui::Compositor(1)); compositor_.reset(new ui::Compositor(1, context_factory_));
compositor_->SetScaleAndSize(1.0f, bounds_.size()); compositor_->SetScaleAndSize(1.0f, bounds_.size());
} }
...@@ -62,8 +68,10 @@ void TestCompositorHostOzone::Draw() { ...@@ -62,8 +68,10 @@ void TestCompositorHostOzone::Draw() {
} }
// static // static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { TestCompositorHost* TestCompositorHost::Create(
return new TestCompositorHostOzone(bounds); const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostOzone(bounds, context_factory);
} }
} // namespace ui } // namespace ui
...@@ -14,9 +14,10 @@ namespace ui { ...@@ -14,9 +14,10 @@ namespace ui {
class TestCompositorHostWin : public TestCompositorHost, class TestCompositorHostWin : public TestCompositorHost,
public gfx::WindowImpl { public gfx::WindowImpl {
public: public:
TestCompositorHostWin(const gfx::Rect& bounds) { TestCompositorHostWin(const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
Init(NULL, bounds); Init(NULL, bounds);
compositor_.reset(new ui::Compositor(hwnd())); compositor_.reset(new ui::Compositor(hwnd(), context_factory));
compositor_->SetScaleAndSize(1.0f, GetSize()); compositor_->SetScaleAndSize(1.0f, GetSize());
} }
...@@ -53,8 +54,10 @@ class TestCompositorHostWin : public TestCompositorHost, ...@@ -53,8 +54,10 @@ class TestCompositorHostWin : public TestCompositorHost,
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostWin); DISALLOW_COPY_AND_ASSIGN(TestCompositorHostWin);
}; };
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { TestCompositorHost* TestCompositorHost::Create(
return new TestCompositorHostWin(bounds); const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostWin(bounds, context_factory);
} }
} // namespace ui } // namespace ui
...@@ -21,7 +21,8 @@ namespace ui { ...@@ -21,7 +21,8 @@ namespace ui {
class TestCompositorHostX11 : public TestCompositorHost { class TestCompositorHostX11 : public TestCompositorHost {
public: public:
TestCompositorHostX11(const gfx::Rect& bounds); TestCompositorHostX11(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
virtual ~TestCompositorHostX11(); virtual ~TestCompositorHostX11();
private: private:
...@@ -33,6 +34,8 @@ class TestCompositorHostX11 : public TestCompositorHost { ...@@ -33,6 +34,8 @@ class TestCompositorHostX11 : public TestCompositorHost {
gfx::Rect bounds_; gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
scoped_ptr<ui::Compositor> compositor_; scoped_ptr<ui::Compositor> compositor_;
XID window_; XID window_;
...@@ -40,8 +43,11 @@ class TestCompositorHostX11 : public TestCompositorHost { ...@@ -40,8 +43,11 @@ class TestCompositorHostX11 : public TestCompositorHost {
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11); DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11);
}; };
TestCompositorHostX11::TestCompositorHostX11(const gfx::Rect& bounds) TestCompositorHostX11::TestCompositorHostX11(
: bounds_(bounds) { const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds),
context_factory_(context_factory) {
} }
TestCompositorHostX11::~TestCompositorHostX11() { TestCompositorHostX11::~TestCompositorHostX11() {
...@@ -69,7 +75,7 @@ void TestCompositorHostX11::Show() { ...@@ -69,7 +75,7 @@ void TestCompositorHostX11::Show() {
if (event.type == MapNotify && event.xmap.window == window_) if (event.type == MapNotify && event.xmap.window == window_)
break; break;
} }
compositor_.reset(new ui::Compositor(window_)); compositor_.reset(new ui::Compositor(window_, context_factory_));
compositor_->SetScaleAndSize(1.0f, bounds_.size()); compositor_->SetScaleAndSize(1.0f, bounds_.size());
} }
...@@ -83,8 +89,10 @@ void TestCompositorHostX11::Draw() { ...@@ -83,8 +89,10 @@ void TestCompositorHostX11::Draw() {
} }
// static // static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { TestCompositorHost* TestCompositorHost::Create(
return new TestCompositorHostX11(bounds); const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostX11(bounds, context_factory);
} }
} // namespace ui } // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment