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 {
namespace ui {
Compositor::Compositor(gfx::AcceleratedWidget widget)
: root_layer_(NULL),
: context_factory_(g_context_factory),
root_layer_(NULL),
widget_(widget),
compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()),
vsync_manager_(new CompositorVSyncManager()),
......@@ -97,6 +98,32 @@ Compositor::Compositor(gfx::AcceleratedWidget widget)
draw_on_compositing_end_(false),
swap_state_(SWAP_NONE),
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_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
......@@ -104,7 +131,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget)
cc::LayerTreeSettings settings;
settings.refresh_rate =
ContextFactory::GetInstance()->DoesCreateTestContexts()
context_factory_->DoesCreateTestContexts()
? kTestRefreshRate
: kDefaultRefreshRate;
settings.main_frame_before_draw_enabled = false;
......@@ -149,12 +176,12 @@ Compositor::Compositor(gfx::AcceleratedWidget widget)
if (compositor_thread_loop_) {
host_ = cc::LayerTreeHost::CreateThreaded(
this,
g_context_factory->GetSharedBitmapManager(),
context_factory_->GetSharedBitmapManager(),
settings,
compositor_thread_loop_);
} else {
host_ = cc::LayerTreeHost::CreateSingleThreaded(
this, this, g_context_factory->GetSharedBitmapManager(), settings);
this, this, context_factory_->GetSharedBitmapManager(), settings);
}
UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
base::TimeTicks::Now() - before_create);
......@@ -175,7 +202,7 @@ Compositor::~Compositor() {
// down any contexts that the |host_| may rely upon.
host_.reset();
ContextFactory::GetInstance()->RemoveCompositor(this);
context_factory_->RemoveCompositor(this);
}
void Compositor::ScheduleDraw() {
......@@ -300,7 +327,7 @@ void Compositor::Layout() {
}
scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) {
return ContextFactory::GetInstance()->CreateOutputSurface(this, fallback);
return context_factory_->CreateOutputSurface(this, fallback);
}
void Compositor::DidCommit() {
......
......@@ -136,9 +136,15 @@ class COMPOSITOR_EXPORT Compositor
: NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
public:
// This is deprecated, and will be removed shortly.
// TODO(sky): remove this.
explicit Compositor(gfx::AcceleratedWidget widget);
Compositor(gfx::AcceleratedWidget widget,
ui::ContextFactory* context_factory);
virtual ~Compositor();
ui::ContextFactory* context_factory() { return context_factory_; }
// Schedules a redraw of the layer tree associated with this compositor.
void ScheduleDraw();
......@@ -248,6 +254,11 @@ class COMPOSITOR_EXPORT Compositor
friend class base::RefCounted<Compositor>;
friend class CompositorLock;
// Called from both constructors. It's temporary while we have both
// constructors.
// TODO(sky): nuke this.
void Init();
// Called by CompositorLock.
void UnlockCompositor();
......@@ -259,6 +270,8 @@ class COMPOSITOR_EXPORT Compositor
gfx::Size size_;
ui::ContextFactory* context_factory_;
// The root of the Layer tree drawn by this compositor.
Layer* root_layer_;
......
......@@ -90,10 +90,12 @@ class LayerWithRealCompositorTest : public testing::Test {
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
bool enable_pixel_output = true;
ui::ContextFactory* context_factory =
InitializeContextFactoryForTests(enable_pixel_output);
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();
}
......@@ -397,10 +399,12 @@ class LayerWithDelegateTest : public testing::Test {
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
InitializeContextFactoryForTests(enable_pixel_output);
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();
}
......
......@@ -21,7 +21,7 @@ static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL;
namespace ui {
// static
void InitializeContextFactoryForTests(bool enable_pixel_output) {
ui::ContextFactory* InitializeContextFactoryForTests(bool enable_pixel_output) {
DCHECK(!g_implicit_factory) <<
"ContextFactory for tests already initialized.";
CommandLine* command_line = CommandLine::ForCurrentProcess();
......@@ -31,6 +31,7 @@ void InitializeContextFactoryForTests(bool enable_pixel_output) {
g_disable_null_draw = new gfx::DisableNullDrawGLBindings;
g_implicit_factory = new InProcessContextFactory();
ContextFactory::SetInstance(g_implicit_factory);
return g_implicit_factory;
}
void TerminateContextFactoryForTests() {
......
......@@ -4,13 +4,17 @@
namespace ui {
class ContextFactory;
// Set up the compositor ContextFactory for a test environment. Unit tests
// that do not have a full content environment need to call this before
// initializing the Compositor.
// Some tests expect pixel output, and they should pass true for
// |enable_pixel_output|. Most unit tests should pass false. Once this has been
// 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();
} // namespace ui
......@@ -12,13 +12,15 @@ class Rect;
namespace ui {
class Compositor;
class ContextFactory;
class TestCompositorHost {
public:
virtual ~TestCompositorHost() {}
// 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.
virtual void Show() = 0;
......
......@@ -81,7 +81,8 @@ class AppKitHost : public FoundationHost {
class TestCompositorHostMac : public TestCompositorHost,
public AppKitHost {
public:
TestCompositorHostMac(const gfx::Rect& bounds);
TestCompositorHostMac(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
virtual ~TestCompositorHostMac();
private:
......@@ -90,6 +91,9 @@ class TestCompositorHostMac : public TestCompositorHost,
virtual ui::Compositor* GetCompositor() OVERRIDE;
gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
scoped_ptr<ui::Compositor> compositor_;
// Owned. Released when window is closed.
......@@ -98,8 +102,10 @@ class TestCompositorHostMac : public TestCompositorHost,
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostMac);
};
TestCompositorHostMac::TestCompositorHostMac(const gfx::Rect& bounds)
: bounds_(bounds), window_(nil) {
TestCompositorHostMac::TestCompositorHostMac(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds), context_factory_(context_factory), window_(nil) {
}
TestCompositorHostMac::~TestCompositorHostMac() {
......@@ -124,7 +130,7 @@ void TestCompositorHostMac::Show() {
defer:NO];
base::scoped_nsobject<AcceleratedTestView> view(
[[AcceleratedTestView alloc] init]);
compositor_.reset(new ui::Compositor(view));
compositor_.reset(new ui::Compositor(view, context_factory_));
compositor_->SetScaleAndSize(1.0f, bounds_.size());
[view setCompositor:compositor_.get()];
[window_ setContentView:view];
......@@ -136,8 +142,10 @@ ui::Compositor* TestCompositorHostMac::GetCompositor() {
}
// static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
return new TestCompositorHostMac(bounds);
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostMac(bounds, context_factory);
}
} // namespace ui
......@@ -18,7 +18,8 @@ namespace ui {
class TestCompositorHostOzone : public TestCompositorHost {
public:
TestCompositorHostOzone(const gfx::Rect& bounds);
TestCompositorHostOzone(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
virtual ~TestCompositorHostOzone();
private:
......@@ -30,13 +31,18 @@ class TestCompositorHostOzone : public TestCompositorHost {
gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
scoped_ptr<ui::Compositor> compositor_;
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone);
};
TestCompositorHostOzone::TestCompositorHostOzone(const gfx::Rect& bounds)
: bounds_(bounds) {}
TestCompositorHostOzone::TestCompositorHostOzone(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds),
context_factory_(context_factory) {}
TestCompositorHostOzone::~TestCompositorHostOzone() {}
......@@ -48,7 +54,7 @@ void TestCompositorHostOzone::Show() {
// with a non-0 widget.
// TODO(rjkroege): Use a "real" ozone widget when it is
// 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());
}
......@@ -62,8 +68,10 @@ void TestCompositorHostOzone::Draw() {
}
// static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
return new TestCompositorHostOzone(bounds);
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostOzone(bounds, context_factory);
}
} // namespace ui
......@@ -14,9 +14,10 @@ namespace ui {
class TestCompositorHostWin : public TestCompositorHost,
public gfx::WindowImpl {
public:
TestCompositorHostWin(const gfx::Rect& bounds) {
TestCompositorHostWin(const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
Init(NULL, bounds);
compositor_.reset(new ui::Compositor(hwnd()));
compositor_.reset(new ui::Compositor(hwnd(), context_factory));
compositor_->SetScaleAndSize(1.0f, GetSize());
}
......@@ -53,8 +54,10 @@ class TestCompositorHostWin : public TestCompositorHost,
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostWin);
};
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
return new TestCompositorHostWin(bounds);
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostWin(bounds, context_factory);
}
} // namespace ui
......@@ -21,7 +21,8 @@ namespace ui {
class TestCompositorHostX11 : public TestCompositorHost {
public:
TestCompositorHostX11(const gfx::Rect& bounds);
TestCompositorHostX11(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
virtual ~TestCompositorHostX11();
private:
......@@ -33,6 +34,8 @@ class TestCompositorHostX11 : public TestCompositorHost {
gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
scoped_ptr<ui::Compositor> compositor_;
XID window_;
......@@ -40,8 +43,11 @@ class TestCompositorHostX11 : public TestCompositorHost {
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11);
};
TestCompositorHostX11::TestCompositorHostX11(const gfx::Rect& bounds)
: bounds_(bounds) {
TestCompositorHostX11::TestCompositorHostX11(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds),
context_factory_(context_factory) {
}
TestCompositorHostX11::~TestCompositorHostX11() {
......@@ -69,7 +75,7 @@ void TestCompositorHostX11::Show() {
if (event.type == MapNotify && event.xmap.window == window_)
break;
}
compositor_.reset(new ui::Compositor(window_));
compositor_.reset(new ui::Compositor(window_, context_factory_));
compositor_->SetScaleAndSize(1.0f, bounds_.size());
}
......@@ -83,8 +89,10 @@ void TestCompositorHostX11::Draw() {
}
// static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
return new TestCompositorHostX11(bounds);
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostX11(bounds, context_factory);
}
} // 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