Commit 5195fc58 authored by robliao@chromium.org's avatar robliao@chromium.org

Revert 238458 "cc: Defer first OutputSurface creation until clie..."

Reason: Candidate for Mac 10.6 and 10.7 Break - IOSurfaceReuse

> cc: Defer first OutputSurface creation until client is ready
> 
> Remove the |first_output_surface| which was not used before
> the client signals ready.
> This allows the client to wait before creating a graphics context
> until the gpu thread and client channel are set up.
> 
> BUG=270179
> R=danakj@chromium.org, jamesr@chromium.org, jochen@chromium.org
> 
> Review URL: https://codereview.chromium.org/85693007

TBR=sievers@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238470 0039d316-1c4b-4281-b951-d872f2087c98
parent a5a59489
......@@ -38,7 +38,7 @@ class FakeProxy : public Proxy {
virtual void MainThreadHasStoppedFlinging() OVERRIDE {}
virtual bool BeginMainFrameRequested() const OVERRIDE;
virtual bool CommitRequested() const OVERRIDE;
virtual void Start() OVERRIDE {}
virtual void Start(scoped_ptr<OutputSurface> first_output_surface) OVERRIDE {}
virtual void Stop() OVERRIDE {}
virtual void ForceSerializeOnSwapBuffers() OVERRIDE {}
virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
......
......@@ -288,10 +288,12 @@ class LayerTreeHostForTesting : public LayerTreeHost {
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
new LayerTreeHostForTesting(test_hooks, client, settings));
bool success;
if (impl_task_runner.get())
layer_tree_host->InitializeThreaded(impl_task_runner);
success = layer_tree_host->InitializeThreaded(impl_task_runner);
else
layer_tree_host->InitializeSingleThreaded(client);
success = layer_tree_host->InitializeSingleThreaded(client);
EXPECT_TRUE(success);
return layer_tree_host.Pass();
}
......@@ -456,10 +458,6 @@ void LayerTreeTest::PostSetNextCommitForcesRedrawToMainThread() {
main_thread_weak_ptr_));
}
void LayerTreeTest::WillBeginTest() {
layer_tree_host_->SetLayerTreeHostClientReady();
}
void LayerTreeTest::DoBeginTest() {
client_ = LayerTreeHostClientForTesting::Create(this);
......@@ -474,7 +472,7 @@ void LayerTreeTest::DoBeginTest() {
started_ = true;
beginning_ = true;
SetupTree();
WillBeginTest();
layer_tree_host_->SetLayerTreeHostClientReady();
BeginTest();
beginning_ = false;
if (end_when_begin_returns_)
......
......@@ -103,6 +103,10 @@ class LayerTreeTest : public testing::Test, public TestHooks {
public:
virtual ~LayerTreeTest();
virtual void AfterTest() = 0;
virtual void BeginTest() = 0;
virtual void SetupTree();
virtual void EndTest();
void EndTestAfterDelay(int delay_milliseconds);
......@@ -143,11 +147,6 @@ class LayerTreeTest : public testing::Test, public TestHooks {
void DispatchComposite();
void DispatchDidAddAnimation();
virtual void AfterTest() = 0;
virtual void WillBeginTest();
virtual void BeginTest() = 0;
virtual void SetupTree();
virtual void RunTest(bool threaded,
bool delegating_renderer,
bool impl_side_painting);
......
......@@ -70,7 +70,8 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded(
DCHECK(impl_task_runner);
scoped_ptr<LayerTreeHost> layer_tree_host(
new LayerTreeHost(client, manager, settings));
layer_tree_host->InitializeThreaded(impl_task_runner);
if (!layer_tree_host->InitializeThreaded(impl_task_runner))
return scoped_ptr<LayerTreeHost>();
return layer_tree_host.Pass();
}
......@@ -81,7 +82,8 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded(
const LayerTreeSettings& settings) {
scoped_ptr<LayerTreeHost> layer_tree_host(
new LayerTreeHost(client, manager, settings));
layer_tree_host->InitializeSingleThreaded(single_thread_client);
if (!layer_tree_host->InitializeSingleThreaded(single_thread_client))
return scoped_ptr<LayerTreeHost>();
return layer_tree_host.Pass();
}
......@@ -124,25 +126,31 @@ LayerTreeHost::LayerTreeHost(
debug_state_.RecordRenderingStats());
}
void LayerTreeHost::InitializeThreaded(
bool LayerTreeHost::InitializeThreaded(
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
InitializeProxy(ThreadProxy::Create(this, impl_task_runner));
return InitializeProxy(ThreadProxy::Create(this, impl_task_runner));
}
void LayerTreeHost::InitializeSingleThreaded(
bool LayerTreeHost::InitializeSingleThreaded(
LayerTreeHostSingleThreadClient* single_thread_client) {
InitializeProxy(SingleThreadProxy::Create(this, single_thread_client));
return InitializeProxy(
SingleThreadProxy::Create(this, single_thread_client));
}
void LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) {
InitializeProxy(proxy_for_testing.Pass());
bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) {
return InitializeProxy(proxy_for_testing.Pass());
}
void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) {
bool LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) {
TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
scoped_ptr<OutputSurface> output_surface(CreateOutputSurface());
if (!output_surface)
return false;
proxy_ = proxy.Pass();
proxy_->Start();
proxy_->Start(output_surface.Pass());
return true;
}
LayerTreeHost::~LayerTreeHost() {
......
......@@ -295,11 +295,11 @@ class CC_EXPORT LayerTreeHost {
LayerTreeHost(LayerTreeHostClient* client,
SharedBitmapManager* manager,
const LayerTreeSettings& settings);
void InitializeThreaded(
bool InitializeThreaded(
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
void InitializeSingleThreaded(
bool InitializeSingleThreaded(
LayerTreeHostSingleThreadClient* single_thread_client);
void InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing);
bool InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing);
void SetOutputSurfaceLostForTesting(bool is_lost) {
output_surface_lost_ = is_lost;
}
......@@ -307,7 +307,7 @@ class CC_EXPORT LayerTreeHost {
MicroBenchmarkController micro_benchmark_controller_;
private:
void InitializeProxy(scoped_ptr<Proxy> proxy);
bool InitializeProxy(scoped_ptr<Proxy> proxy);
void PaintLayerContents(
const RenderSurfaceLayerList& render_surface_layer_list,
......
......@@ -2308,7 +2308,7 @@ class LayerTreeHostWithProxy : public LayerTreeHost {
scoped_ptr<FakeProxy> proxy)
: LayerTreeHost(client, NULL, settings) {
proxy->SetLayerTreeHost(this);
InitializeForTesting(proxy.PassAs<Proxy>());
EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>()));
}
};
......
......@@ -409,37 +409,6 @@ class LayerTreeHostContextTestLostContextSucceeds
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds);
class LayerTreeHostClientNotReadyDoesNotCreateOutputSurface
: public LayerTreeHostContextTest {
public:
LayerTreeHostClientNotReadyDoesNotCreateOutputSurface()
: LayerTreeHostContextTest() {}
virtual void WillBeginTest() OVERRIDE {
// Override and do not signal SetLayerTreeHostClientReady.
}
virtual void BeginTest() OVERRIDE {
PostSetNeedsCommitToMainThread();
EndTest();
}
virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
OVERRIDE {
EXPECT_TRUE(false);
return scoped_ptr<OutputSurface>();
}
virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
EXPECT_TRUE(false);
}
virtual void AfterTest() OVERRIDE {
}
};
MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface);
class LayerTreeHostContextTestLostContextSucceedsWithContent
: public LayerTreeHostContextTestLostContextSucceeds {
public:
......@@ -558,97 +527,6 @@ TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent,
RunTest(true, false, false);
}
class LayerTreeHostContextTestCreateOutputSurfaceFails
: public LayerTreeHostContextTest {
public:
// Run a test that initially fails OutputSurface creation |times_to_fail|
// times. If |expect_fallback_attempt| is |true|, an attempt to create a
// fallback/software OutputSurface is expected to occur.
LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail,
bool expect_fallback_attempt,
bool expect_to_give_up)
: times_to_fail_(times_to_fail),
expect_fallback_attempt_(expect_fallback_attempt),
expect_to_give_up_(expect_to_give_up),
did_attempt_fallback_(false),
times_initialized_(0) {}
virtual void BeginTest() OVERRIDE {
times_to_fail_create_ = times_to_fail_;
PostSetNeedsCommitToMainThread();
}
virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
OVERRIDE {
scoped_ptr<OutputSurface> surface =
LayerTreeHostContextTest::CreateOutputSurface(fallback);
if (surface)
EXPECT_EQ(times_to_fail_, times_create_failed_);
did_attempt_fallback_ = fallback;
return surface.Pass();
}
virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
if (succeeded)
times_initialized_++;
else
EndTest();
}
virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
EndTest();
}
virtual void AfterTest() OVERRIDE {
EXPECT_EQ(times_to_fail_, times_create_failed_);
EXPECT_EQ(expect_to_give_up_, times_initialized_ == 0);
EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_);
}
private:
int times_to_fail_;
bool expect_fallback_attempt_;
bool expect_to_give_up_;
bool did_attempt_fallback_;
int times_initialized_;
};
class LayerTreeHostContextTestCreateOutputSurfaceFailsOnce
: public LayerTreeHostContextTestCreateOutputSurfaceFails {
public:
LayerTreeHostContextTestCreateOutputSurfaceFailsOnce()
: LayerTreeHostContextTestCreateOutputSurfaceFails(1, false, false) {}
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostContextTestCreateOutputSurfaceFailsOnce);
// After 4 failures we expect an attempt to create a fallback/software
// OutputSurface.
class LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback
: public LayerTreeHostContextTestCreateOutputSurfaceFails {
public:
LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback()
: LayerTreeHostContextTestCreateOutputSurfaceFails(4, true, false) {}
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback);
// If we fail that often, we should be giving up cleanly.
class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless
: public LayerTreeHostContextTestCreateOutputSurfaceFails {
public:
LayerTreeHostContextTestCreateOutputSurfaceIsHopeless()
: LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {}
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostContextTestCreateOutputSurfaceIsHopeless);
class LayerTreeHostContextTestOffscreenContextFails
: public LayerTreeHostContextTest {
public:
......@@ -1407,11 +1285,7 @@ class LayerTreeHostContextTestDontUseLostResources
virtual scoped_ptr<OutputSurface> CreateOutputSurface(
bool fallback) OVERRIDE {
// This will get called twice:
// First when we create the initial output surface...
if (layer_tree_host()->source_frame_number() > 0) {
// ... and then again after we forced the context to be lost on the third
// frame. Verify this assumption here.
if (layer_tree_host()) {
lost_context_ = true;
EXPECT_EQ(layer_tree_host()->source_frame_number(), 3);
}
......@@ -1887,6 +1761,43 @@ class LayerTreeHostContextTestFailsToCreateSurface
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostContextTestFailsToCreateSurface);
// Not reusing LayerTreeTest because it expects creating LTH to always succeed.
class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface
: public testing::Test,
public FakeLayerTreeHostClient {
public:
LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface()
: FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {}
// FakeLayerTreeHostClient implementation.
virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
OVERRIDE {
return scoped_ptr<OutputSurface>();
}
void RunTest(bool threaded,
bool delegating_renderer,
bool impl_side_painting) {
LayerTreeSettings settings;
settings.impl_side_painting = impl_side_painting;
if (threaded) {
scoped_ptr<base::Thread> impl_thread(new base::Thread("LayerTreeTest"));
ASSERT_TRUE(impl_thread->Start());
ASSERT_TRUE(impl_thread->message_loop_proxy().get());
scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded(
this, NULL, settings, impl_thread->message_loop_proxy());
EXPECT_FALSE(layer_tree_host);
} else {
scoped_ptr<LayerTreeHost> layer_tree_host =
LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
EXPECT_FALSE(layer_tree_host);
}
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface);
class UIResourceLostTest : public LayerTreeHostContextTest {
public:
UIResourceLostTest() : time_step_(0) {}
......
......@@ -84,7 +84,7 @@ class CC_EXPORT Proxy {
virtual bool BeginMainFrameRequested() const = 0;
// Must be called before using the proxy.
virtual void Start() = 0;
virtual void Start(scoped_ptr<OutputSurface> first_output_surface) = 0;
virtual void Stop() = 0; // Must be called before deleting the proxy.
// Forces 3D commands on all contexts to wait for all previous SwapBuffers
......
......@@ -44,9 +44,11 @@ SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host,
<< "Threaded compositing must be enabled to use impl-side painting.";
}
void SingleThreadProxy::Start() {
void SingleThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) {
DCHECK(first_output_surface);
DebugScopedSetImplThread impl(this);
layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
first_output_surface_ = first_output_surface.Pass();
}
SingleThreadProxy::~SingleThreadProxy() {
......@@ -111,8 +113,9 @@ void SingleThreadProxy::CreateAndInitializeOutputSurface() {
"cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
DCHECK(Proxy::IsMainThread());
scoped_ptr<OutputSurface> output_surface =
layer_tree_host_->CreateOutputSurface();
scoped_ptr<OutputSurface> output_surface = first_output_surface_.Pass();
if (!output_surface)
output_surface = layer_tree_host_->CreateOutputSurface();
if (!output_surface) {
OnOutputSurfaceInitializeAttempted(false);
return;
......
......@@ -44,7 +44,7 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
virtual bool CommitRequested() const OVERRIDE;
virtual bool BeginMainFrameRequested() const OVERRIDE;
virtual void MainThreadHasStoppedFlinging() OVERRIDE {}
virtual void Start() OVERRIDE;
virtual void Start(scoped_ptr<OutputSurface> first_output_surface) OVERRIDE;
virtual void Stop() OVERRIDE;
virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
virtual void AcquireLayerTextures() OVERRIDE {}
......@@ -108,6 +108,10 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
LayerTreeHostSingleThreadClient* client_;
bool created_offscreen_context_provider_;
// Holds the first output surface passed from Start. Should not be used for
// anything else.
scoped_ptr<OutputSurface> first_output_surface_;
// Used on the Thread, but checked on main thread during
// initialization/shutdown.
scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
......
......@@ -267,8 +267,9 @@ void ThreadProxy::DoCreateAndInitializeOutputSurface() {
TRACE_EVENT0("cc", "ThreadProxy::DoCreateAndInitializeOutputSurface");
DCHECK(IsMainThread());
scoped_ptr<OutputSurface> output_surface =
layer_tree_host()->CreateOutputSurface();
scoped_ptr<OutputSurface> output_surface = first_output_surface_.Pass();
if (!output_surface)
output_surface = layer_tree_host()->CreateOutputSurface();
RendererCapabilities capabilities;
bool success = !!output_surface;
......@@ -641,9 +642,10 @@ ThreadProxy::contents_texture_manager_on_impl_thread() {
return contents_texture_manager_unsafe_;
}
void ThreadProxy::Start() {
void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) {
DCHECK(IsMainThread());
DCHECK(Proxy::HasImplThread());
DCHECK(first_output_surface);
// Create LayerTreeHostImpl.
DebugScopedSetMainThreadBlocked main_thread_blocked(this);
......@@ -656,6 +658,7 @@ void ThreadProxy::Start() {
completion.Wait();
main_thread_weak_ptr_ = weak_factory_.GetWeakPtr();
first_output_surface_ = first_output_surface.Pass();
started_ = true;
}
......
......@@ -58,7 +58,7 @@ class ThreadProxy : public Proxy,
virtual bool CommitRequested() const OVERRIDE;
virtual bool BeginMainFrameRequested() const OVERRIDE;
virtual void MainThreadHasStoppedFlinging() OVERRIDE;
virtual void Start() OVERRIDE;
virtual void Start(scoped_ptr<OutputSurface> first_output_surface) OVERRIDE;
virtual void Stop() OVERRIDE;
virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
virtual void AcquireLayerTextures() OVERRIDE;
......@@ -224,6 +224,9 @@ class ThreadProxy : public Proxy,
bool manage_tiles_pending_;
// Weak pointer to use when posting tasks to the impl thread.
base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_;
// Holds the first output surface passed from Start. Should not be used for
// anything else.
scoped_ptr<OutputSurface> first_output_surface_;
// Accessed on the main thread, or when main thread is blocked.
bool commit_waits_for_activation_;
......
......@@ -279,7 +279,8 @@ scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
}
#endif
compositor->Initialize(settings);
if (!compositor->Initialize(settings))
return scoped_ptr<RenderWidgetCompositor>();
return compositor.Pass();
}
......@@ -386,7 +387,7 @@ bool RenderWidgetCompositor::ScheduleMicroBenchmark(
return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback);
}
void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
bool RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy =
RenderThreadImpl::current()->compositor_message_loop_proxy();
if (compositor_message_loop_proxy.get()) {
......@@ -396,7 +397,7 @@ void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
this, this, NULL, settings);
}
DCHECK(layer_tree_host_);
return layer_tree_host_;
}
void RenderWidgetCompositor::setSurfaceReady() {
......
......@@ -137,7 +137,7 @@ class RenderWidgetCompositor : public blink::WebLayerTreeView,
private:
RenderWidgetCompositor(RenderWidget* widget, bool threaded);
void Initialize(cc::LayerTreeSettings settings);
bool Initialize(cc::LayerTreeSettings settings);
bool threaded_;
bool suppress_schedule_composite_;
......
......@@ -303,7 +303,8 @@ TestWebKitPlatformSupport::createLayerTreeViewForTesting() {
scoped_ptr<WebLayerTreeViewImplForTesting> view(
new WebLayerTreeViewImplForTesting());
view->Initialize();
if (!view->Initialize())
return NULL;
return view.release();
}
......
......@@ -36,7 +36,7 @@ WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
void WebLayerTreeViewImplForTesting::Initialize() {
bool WebLayerTreeViewImplForTesting::Initialize() {
cc::LayerTreeSettings settings;
// For web contents, layer transforms should scale up the contents of layers
......@@ -47,7 +47,9 @@ void WebLayerTreeViewImplForTesting::Initialize() {
settings.accelerated_animation_enabled = true;
layer_tree_host_ =
cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
DCHECK(layer_tree_host_);
if (!layer_tree_host_)
return false;
return true;
}
void WebLayerTreeViewImplForTesting::setSurfaceReady() {
......
......@@ -26,7 +26,7 @@ class WebLayerTreeViewImplForTesting
WebLayerTreeViewImplForTesting();
virtual ~WebLayerTreeViewImplForTesting();
void Initialize();
bool Initialize();
// blink::WebLayerTreeView implementation.
virtual void setSurfaceReady();
......
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