Commit fa339037 authored by boliu@chromium.org's avatar boliu@chromium.org

cc: Update Main RendererCapabilities on DeferredInitialize

Also update caps on ReleaseGL. The updated RendererCapabilities
are posted back to the main thread. Main thread layers will
receive OnOutputSurfaceCreated (should be renamed to
OnRendererCapabilitiesChanged) when this happens. Note this
is also called on first renderer initialization.

BUG=332616

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251853 0039d316-1c4b-4281-b951-d872f2087c98
parent ade9f1af
...@@ -13,6 +13,7 @@ namespace cc { ...@@ -13,6 +13,7 @@ namespace cc {
class FakeLayerTreeHostImplClient : public LayerTreeHostImplClient { class FakeLayerTreeHostImplClient : public LayerTreeHostImplClient {
public: public:
// LayerTreeHostImplClient implementation. // LayerTreeHostImplClient implementation.
virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE {}
virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {}
virtual void DidSwapBuffersOnImplThread() OVERRIDE {} virtual void DidSwapBuffersOnImplThread() OVERRIDE {}
virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {}
......
...@@ -1744,6 +1744,7 @@ void LayerTreeHostImpl::CreateAndSetRenderer( ...@@ -1744,6 +1744,7 @@ void LayerTreeHostImpl::CreateAndSetRenderer(
active_tree_->set_needs_update_draw_properties(); active_tree_->set_needs_update_draw_properties();
if (pending_tree_) if (pending_tree_)
pending_tree_->set_needs_update_draw_properties(); pending_tree_->set_needs_update_draw_properties();
client_->UpdateRendererCapabilitiesOnImplThread();
} }
} }
......
...@@ -59,6 +59,7 @@ struct RendererCapabilitiesImpl; ...@@ -59,6 +59,7 @@ struct RendererCapabilitiesImpl;
// LayerTreeHost->Proxy callback interface. // LayerTreeHost->Proxy callback interface.
class LayerTreeHostImplClient { class LayerTreeHostImplClient {
public: public:
virtual void UpdateRendererCapabilitiesOnImplThread() = 0;
virtual void DidLoseOutputSurfaceOnImplThread() = 0; virtual void DidLoseOutputSurfaceOnImplThread() = 0;
virtual void DidSwapBuffersOnImplThread() = 0; virtual void DidSwapBuffersOnImplThread() = 0;
virtual void OnSwapBuffersCompleteOnImplThread() = 0; virtual void OnSwapBuffersCompleteOnImplThread() = 0;
......
...@@ -104,6 +104,7 @@ class LayerTreeHostImplTest : public testing::Test, ...@@ -104,6 +104,7 @@ class LayerTreeHostImplTest : public testing::Test,
virtual void TearDown() OVERRIDE {} virtual void TearDown() OVERRIDE {}
virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE {}
virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {}
virtual void DidSwapBuffersOnImplThread() OVERRIDE {} virtual void DidSwapBuffersOnImplThread() OVERRIDE {}
virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {}
...@@ -5247,9 +5248,14 @@ class LayerTreeHostImplTestDeferredInitialize : public LayerTreeHostImplTest { ...@@ -5247,9 +5248,14 @@ class LayerTreeHostImplTestDeferredInitialize : public LayerTreeHostImplTest {
offscreen_context_provider_ = TestContextProvider::Create(); offscreen_context_provider_ = TestContextProvider::Create();
} }
virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE {
did_update_renderer_capabilities_ = true;
}
FakeOutputSurface* output_surface_; FakeOutputSurface* output_surface_;
scoped_refptr<TestContextProvider> onscreen_context_provider_; scoped_refptr<TestContextProvider> onscreen_context_provider_;
scoped_refptr<TestContextProvider> offscreen_context_provider_; scoped_refptr<TestContextProvider> offscreen_context_provider_;
bool did_update_renderer_capabilities_;
}; };
...@@ -5261,20 +5267,24 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { ...@@ -5261,20 +5267,24 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) {
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
// DeferredInitialize and hardware draw. // DeferredInitialize and hardware draw.
did_update_renderer_capabilities_ = false;
EXPECT_TRUE(output_surface_->InitializeAndSetContext3d( EXPECT_TRUE(output_surface_->InitializeAndSetContext3d(
onscreen_context_provider_, offscreen_context_provider_)); onscreen_context_provider_, offscreen_context_provider_));
EXPECT_EQ(onscreen_context_provider_, EXPECT_EQ(onscreen_context_provider_,
host_impl_->output_surface()->context_provider()); host_impl_->output_surface()->context_provider());
EXPECT_EQ(offscreen_context_provider_, EXPECT_EQ(offscreen_context_provider_,
host_impl_->offscreen_context_provider()); host_impl_->offscreen_context_provider());
EXPECT_TRUE(did_update_renderer_capabilities_);
// Defer intialized GL draw. // Defer intialized GL draw.
DrawFrame(); DrawFrame();
// Revert back to software. // Revert back to software.
did_update_renderer_capabilities_ = false;
output_surface_->ReleaseGL(); output_surface_->ReleaseGL();
EXPECT_FALSE(host_impl_->output_surface()->context_provider()); EXPECT_FALSE(host_impl_->output_surface()->context_provider());
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
EXPECT_TRUE(did_update_renderer_capabilities_);
// Software draw again. // Software draw again.
DrawFrame(); DrawFrame();
...@@ -5292,15 +5302,20 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) { ...@@ -5292,15 +5302,20 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) {
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
// DeferredInitialize fails. // DeferredInitialize fails.
did_update_renderer_capabilities_ = false;
EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( EXPECT_FALSE(output_surface_->InitializeAndSetContext3d(
onscreen_context_provider_, offscreen_context_provider_)); onscreen_context_provider_, offscreen_context_provider_));
EXPECT_FALSE(host_impl_->output_surface()->context_provider()); EXPECT_FALSE(host_impl_->output_surface()->context_provider());
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
EXPECT_FALSE(did_update_renderer_capabilities_);
// Software draw again. // Software draw again.
DrawFrame(); DrawFrame();
} }
// TODO(boliu): After r239415, fails_OnscreenContext_1 and 2 are exactly the
// same as 0. They were supposed to test makeCurrent failing in the
// OutputSurface, LayerTreeHostImpl, and GLRenderer respectively.
TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) {
// Software draw. // Software draw.
DrawFrame(); DrawFrame();
...@@ -5312,10 +5327,12 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { ...@@ -5312,10 +5327,12 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) {
EXPECT_FALSE(host_impl_->output_surface()->context_provider()); EXPECT_FALSE(host_impl_->output_surface()->context_provider());
// DeferredInitialize fails. // DeferredInitialize fails.
did_update_renderer_capabilities_ = false;
EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( EXPECT_FALSE(output_surface_->InitializeAndSetContext3d(
onscreen_context_provider_, offscreen_context_provider_)); onscreen_context_provider_, offscreen_context_provider_));
EXPECT_FALSE(host_impl_->output_surface()->context_provider()); EXPECT_FALSE(host_impl_->output_surface()->context_provider());
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
EXPECT_FALSE(did_update_renderer_capabilities_);
} }
TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) {
...@@ -5328,10 +5345,12 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { ...@@ -5328,10 +5345,12 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) {
onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true);
// DeferredInitialize fails. // DeferredInitialize fails.
did_update_renderer_capabilities_ = false;
EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( EXPECT_FALSE(output_surface_->InitializeAndSetContext3d(
onscreen_context_provider_, offscreen_context_provider_)); onscreen_context_provider_, offscreen_context_provider_));
EXPECT_FALSE(host_impl_->output_surface()->context_provider()); EXPECT_FALSE(host_impl_->output_surface()->context_provider());
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
EXPECT_FALSE(did_update_renderer_capabilities_);
} }
TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) {
...@@ -5345,10 +5364,12 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { ...@@ -5345,10 +5364,12 @@ TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) {
onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true);
// DeferredInitialize fails. // DeferredInitialize fails.
did_update_renderer_capabilities_ = false;
EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( EXPECT_FALSE(output_surface_->InitializeAndSetContext3d(
onscreen_context_provider_, offscreen_context_provider_)); onscreen_context_provider_, offscreen_context_provider_));
EXPECT_FALSE(host_impl_->output_surface()->context_provider()); EXPECT_FALSE(host_impl_->output_surface()->context_provider());
EXPECT_FALSE(host_impl_->offscreen_context_provider()); EXPECT_FALSE(host_impl_->offscreen_context_provider());
EXPECT_FALSE(did_update_renderer_capabilities_);
} }
// Checks that we have a non-0 default allocation if we pass a context that // Checks that we have a non-0 default allocation if we pass a context that
......
...@@ -147,11 +147,7 @@ void SingleThreadProxy::CreateAndInitializeOutputSurface() { ...@@ -147,11 +147,7 @@ void SingleThreadProxy::CreateAndInitializeOutputSurface() {
DCHECK(output_surface); DCHECK(output_surface);
initialized = layer_tree_host_impl_->InitializeRenderer( initialized = layer_tree_host_impl_->InitializeRenderer(
output_surface.Pass()); output_surface.Pass());
if (initialized) { if (!initialized && offscreen_context_provider.get()) {
renderer_capabilities_for_main_thread_ =
layer_tree_host_impl_->GetRendererCapabilities()
.MainThreadCapabilities();
} else if (offscreen_context_provider.get()) {
offscreen_context_provider->VerifyContexts(); offscreen_context_provider->VerifyContexts();
offscreen_context_provider = NULL; offscreen_context_provider = NULL;
} }
...@@ -370,6 +366,12 @@ void SingleThreadProxy::SendManagedMemoryStats() { ...@@ -370,6 +366,12 @@ void SingleThreadProxy::SendManagedMemoryStats() {
bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
DCHECK(IsImplThread());
renderer_capabilities_for_main_thread_ =
layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
}
void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
// Cause a commit so we can notice the lost context. // Cause a commit so we can notice the lost context.
......
...@@ -54,6 +54,7 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { ...@@ -54,6 +54,7 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
virtual bool CommitPendingForTesting() OVERRIDE; virtual bool CommitPendingForTesting() OVERRIDE;
// LayerTreeHostImplClient implementation // LayerTreeHostImplClient implementation
virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE;
virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
virtual void DidSwapBuffersOnImplThread() OVERRIDE; virtual void DidSwapBuffersOnImplThread() OVERRIDE;
virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE; virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE;
......
...@@ -330,6 +330,11 @@ void ThreadProxy::DoCreateAndInitializeOutputSurface() { ...@@ -330,6 +330,11 @@ void ThreadProxy::DoCreateAndInitializeOutputSurface() {
OnOutputSurfaceInitializeAttempted(success, capabilities); OnOutputSurfaceInitializeAttempted(success, capabilities);
} }
void ThreadProxy::SetRendererCapabilitiesMainThreadCopy(
const RendererCapabilities& capabilities) {
main().renderer_capabilities_main_thread_copy = capabilities;
}
void ThreadProxy::OnOutputSurfaceInitializeAttempted( void ThreadProxy::OnOutputSurfaceInitializeAttempted(
bool success, bool success,
const RendererCapabilities& capabilities) { const RendererCapabilities& capabilities) {
...@@ -403,6 +408,17 @@ void ThreadProxy::SetNeedsCommit() { ...@@ -403,6 +408,17 @@ void ThreadProxy::SetNeedsCommit() {
SendCommitRequestToImplThreadIfNeeded(); SendCommitRequestToImplThreadIfNeeded();
} }
void ThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
DCHECK(IsImplThread());
Proxy::MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ThreadProxy::SetRendererCapabilitiesMainThreadCopy,
main_thread_weak_ptr_,
impl()
.layer_tree_host_impl->GetRendererCapabilities()
.MainThreadCapabilities()));
}
void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { void ThreadProxy::DidLoseOutputSurfaceOnImplThread() {
TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread");
DCHECK(IsImplThread()); DCHECK(IsImplThread());
......
...@@ -71,6 +71,7 @@ class ThreadProxy : public Proxy, ...@@ -71,6 +71,7 @@ class ThreadProxy : public Proxy,
virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting() OVERRIDE; virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting() OVERRIDE;
// LayerTreeHostImplClient implementation // LayerTreeHostImplClient implementation
virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE;
virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
virtual void DidSwapBuffersOnImplThread() OVERRIDE {} virtual void DidSwapBuffersOnImplThread() OVERRIDE {}
virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE; virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE;
...@@ -139,6 +140,8 @@ class ThreadProxy : public Proxy, ...@@ -139,6 +140,8 @@ class ThreadProxy : public Proxy,
}; };
// Called on main thread. // Called on main thread.
void SetRendererCapabilitiesMainThreadCopy(
const RendererCapabilities& capabilities);
void BeginMainFrame( void BeginMainFrame(
scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state);
void DidCommitAndDrawFrame(); void DidCommitAndDrawFrame();
......
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