Commit 1aa84911 authored by vollick's avatar vollick Committed by Commit bot

Don't let unittests access LTH from the impl thread.

This causes racy sadness.

BUG=235188

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

Cr-Commit-Position: refs/heads/master@{#321398}
parent da3b0006
......@@ -878,4 +878,13 @@ void LayerTreeTest::DestroyLayerTreeHost() {
layer_tree_host_ = nullptr;
}
LayerTreeHost* LayerTreeTest::layer_tree_host() {
// We check for a null proxy here as we sometimes ask for the layer tree host
// when the proxy does not exist, often for checking settings after a test has
// completed. For example, LTHPixelResourceTest::RunPixelResourceTest. See
// elsewhere in this file for other examples.
DCHECK(!proxy() || proxy()->IsMainThread() || proxy()->IsMainThreadBlocked());
return layer_tree_host_.get();
}
} // namespace cc
......@@ -198,7 +198,7 @@ class LayerTreeTest : public testing::Test, public TestHooks {
bool TestEnded() const { return ended_; }
LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
LayerTreeHost* layer_tree_host();
bool delegating_renderer() const { return delegating_renderer_; }
FakeOutputSurface* output_surface() { return output_surface_; }
int LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl) const;
......
......@@ -70,7 +70,17 @@ using testing::Mock;
namespace cc {
namespace {
class LayerTreeHostTest : public LayerTreeTest {};
class LayerTreeHostTest : public LayerTreeTest {
public:
LayerTreeHostTest() : contents_texture_manager_(nullptr) {}
void DidInitializeOutputSurface() override {
contents_texture_manager_ = layer_tree_host()->contents_texture_manager();
}
protected:
PrioritizedResourceManager* contents_texture_manager_;
};
// Test if the LTHI receives ReadyToActivate notifications from the TileManager
// when no raster tasks get scheduled.
......@@ -1463,7 +1473,7 @@ class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest {
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
ASSERT_EQ(0u, impl->settings().max_partial_texture_updates);
TestWebGraphicsContext3D* context = TestContext();
......@@ -1542,7 +1552,7 @@ class LayerTreeHostTestDelegatingRendererAtomicCommit
: public LayerTreeHostTestDirectRendererAtomicCommit {
public:
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
ASSERT_EQ(0u, impl->settings().max_partial_texture_updates);
TestWebGraphicsContext3D* context = TestContext();
......@@ -1659,7 +1669,7 @@ class LayerTreeHostTestAtomicCommitWithPartialUpdate
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates);
ASSERT_EQ(1u, impl->settings().max_partial_texture_updates);
TestWebGraphicsContext3D* context = TestContext();
......@@ -2383,12 +2393,10 @@ class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted
bool visible) override {
if (visible) {
// One backing should remain unevicted.
EXPECT_EQ(
100u * 100u * 4u * 1u,
layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
EXPECT_EQ(100u * 100u * 4u * 1u,
contents_texture_manager_->MemoryUseBytes());
} else {
EXPECT_EQ(
0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
EXPECT_EQ(0u, contents_texture_manager_->MemoryUseBytes());
}
// Make sure that contents textures are marked as having been
......@@ -2403,9 +2411,9 @@ class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted
switch (num_commits_) {
case 1:
// All three backings should have memory.
EXPECT_EQ(
100u * 100u * 4u * 3u,
layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
EXPECT_EQ(100u * 100u * 4u * 3u,
contents_texture_manager_->MemoryUseBytes());
// Set a new policy that will kick out 1 of the 3 resources.
// Because a resource was evicted, a commit will be kicked off.
host_impl->SetMemoryPolicy(
......@@ -2415,9 +2423,8 @@ class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted
break;
case 2:
// Only two backings should have memory.
EXPECT_EQ(
100u * 100u * 4u * 2u,
layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
EXPECT_EQ(100u * 100u * 4u * 2u,
contents_texture_manager_->MemoryUseBytes());
// Become backgrounded, which will cause 1 more resource to be
// evicted.
PostSetVisibleToMainThread(false);
......@@ -3246,12 +3253,12 @@ class LayerTreeHostTestUIResource : public LayerTreeHostTest {
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
if (!layer_tree_host()->settings().impl_side_painting)
if (!impl->settings().impl_side_painting)
PerformTest(impl);
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
if (layer_tree_host()->settings().impl_side_painting)
if (impl->settings().impl_side_painting)
PerformTest(impl);
}
......
......@@ -110,7 +110,7 @@ class LayerTreeHostContextTest : public LayerTreeTest {
// Only valid for single-threaded impl-side painting, which activates
// immediately and will try to draw again when content has finished.
DCHECK(!host_impl->proxy()->HasImplThread());
DCHECK(layer_tree_host()->settings().impl_side_painting);
DCHECK(host_impl->settings().impl_side_painting);
return draw_result;
}
EXPECT_EQ(DRAW_SUCCESS, draw_result);
......@@ -883,7 +883,7 @@ class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest {
FakeContentLayerImpl* child_content = NULL;
FakeContentLayerImpl* grandchild_content = NULL;
if (layer_tree_host()->settings().impl_side_painting) {
if (host_impl->settings().impl_side_painting) {
root_picture = static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->root_layer());
child_picture =
......@@ -903,7 +903,7 @@ class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest {
++num_commits_;
switch (num_commits_) {
case 1:
if (layer_tree_host()->settings().impl_side_painting) {
if (host_impl->settings().impl_side_painting) {
EXPECT_EQ(0u, root_picture->release_resources_count());
EXPECT_EQ(0u, child_picture->release_resources_count());
EXPECT_EQ(0u, grandchild_picture->release_resources_count());
......@@ -918,7 +918,7 @@ class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest {
times_to_fail_create_ = 1;
break;
case 2:
if (layer_tree_host()->settings().impl_side_painting) {
if (host_impl->settings().impl_side_painting) {
EXPECT_TRUE(root_picture->release_resources_count());
EXPECT_TRUE(child_picture->release_resources_count());
EXPECT_TRUE(grandchild_picture->release_resources_count());
......@@ -1327,7 +1327,7 @@ class UIResourceLostTestSimple : public UIResourceLostTest {
virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0;
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
if (!layer_tree_host()->settings().impl_side_painting) {
if (!impl->settings().impl_side_painting) {
StepCompleteOnImplThread(impl);
PostStepCompleteToMainThread();
++time_step_;
......@@ -1335,7 +1335,7 @@ class UIResourceLostTestSimple : public UIResourceLostTest {
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
if (layer_tree_host()->settings().impl_side_painting) {
if (impl->settings().impl_side_painting) {
StepCompleteOnImplThread(impl);
PostStepCompleteToMainThread();
++time_step_;
......
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