[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 5 | #include "cc/layers/texture_layer.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 6 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 11 | #include "base/callback.h" |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 12 | #include "base/location.h" |
| 13 | #include "base/single_thread_task_runner.h" |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 14 | #include "base/synchronization/waitable_event.h" |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 15 | #include "base/thread_task_runner_handle.h" |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 16 | #include "base/threading/thread.h" |
| 17 | #include "base/time/time.h" |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 18 | #include "cc/layers/solid_color_layer.h" |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 19 | #include "cc/layers/texture_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 20 | #include "cc/layers/texture_layer_impl.h" |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 21 | #include "cc/output/compositor_frame_ack.h" |
| 22 | #include "cc/output/context_provider.h" |
[email protected] | e00bab02 | 2013-08-19 00:42:45 | [diff] [blame] | 23 | #include "cc/resources/returned_resource.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 24 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 25 | #include "cc/test/fake_layer_tree_host_client.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 26 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 199b715e | 2013-08-13 05:18:34 | [diff] [blame] | 27 | #include "cc/test/fake_output_surface.h" |
[email protected] | 06d68d0 | 2013-04-19 18:46:21 | [diff] [blame] | 28 | #include "cc/test/layer_test_common.h" |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 29 | #include "cc/test/layer_tree_test.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 30 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | c2610b9f | 2013-10-31 06:54:59 | [diff] [blame] | 31 | #include "cc/test/test_web_graphics_context_3d.h" |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 32 | #include "cc/trees/blocking_task_runner.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 33 | #include "cc/trees/layer_tree_host.h" |
| 34 | #include "cc/trees/layer_tree_impl.h" |
| 35 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 36 | #include "gpu/GLES2/gl2extchromium.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 37 | #include "testing/gmock/include/gmock/gmock.h" |
| 38 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 39 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 40 | using ::testing::Mock; |
| 41 | using ::testing::_; |
| 42 | using ::testing::AtLeast; |
| 43 | using ::testing::AnyNumber; |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 44 | using ::testing::InvokeWithoutArgs; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 45 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 46 | namespace cc { |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 47 | namespace { |
| 48 | |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 49 | gpu::Mailbox MailboxFromChar(char value) { |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 50 | gpu::Mailbox mailbox; |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 51 | memset(mailbox.name, value, sizeof(mailbox.name)); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 52 | return mailbox; |
| 53 | } |
| 54 | |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 55 | class MockLayerTreeHost : public LayerTreeHost { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 56 | public: |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 57 | explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 58 | : LayerTreeHost(client, nullptr, nullptr, nullptr, LayerTreeSettings()) { |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 59 | InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(), |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 60 | nullptr); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 61 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 62 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 63 | MOCK_METHOD0(SetNeedsCommit, void()); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 64 | MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 65 | MOCK_METHOD0(StartRateLimiter, void()); |
| 66 | MOCK_METHOD0(StopRateLimiter, void()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 67 | }; |
| 68 | |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 69 | class FakeTextureLayerClient : public TextureLayerClient { |
| 70 | public: |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 71 | FakeTextureLayerClient() : mailbox_changed_(true) {} |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 72 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 73 | bool PrepareTextureMailbox( |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 74 | TextureMailbox* mailbox, |
| 75 | scoped_ptr<SingleReleaseCallback>* release_callback, |
mostynb | f68776d8 | 2014-10-06 18:07:37 | [diff] [blame] | 76 | bool use_shared_memory) override { |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 77 | if (!mailbox_changed_) |
| 78 | return false; |
| 79 | |
| 80 | *mailbox = mailbox_; |
| 81 | *release_callback = release_callback_.Pass(); |
| 82 | mailbox_changed_ = false; |
| 83 | return true; |
| 84 | } |
| 85 | |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 86 | void set_mailbox(const TextureMailbox& mailbox, |
| 87 | scoped_ptr<SingleReleaseCallback> release_callback) { |
| 88 | mailbox_ = mailbox; |
| 89 | release_callback_ = release_callback.Pass(); |
| 90 | mailbox_changed_ = true; |
| 91 | } |
| 92 | |
| 93 | private: |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 94 | TextureMailbox mailbox_; |
| 95 | scoped_ptr<SingleReleaseCallback> release_callback_; |
| 96 | bool mailbox_changed_; |
| 97 | DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
| 98 | }; |
| 99 | |
| 100 | class MockMailboxCallback { |
| 101 | public: |
| 102 | MOCK_METHOD3(Release, |
| 103 | void(const gpu::Mailbox& mailbox, |
| 104 | uint32 sync_point, |
| 105 | bool lost_resource)); |
| 106 | MOCK_METHOD3(Release2, |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 107 | void(SharedBitmap* shared_bitmap, |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 108 | uint32 sync_point, |
| 109 | bool lost_resource)); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 110 | MOCK_METHOD4(ReleaseImpl, |
| 111 | void(const gpu::Mailbox& mailbox, |
| 112 | uint32 sync_point, |
| 113 | bool lost_resource, |
| 114 | BlockingTaskRunner* main_thread_task_runner)); |
| 115 | MOCK_METHOD4(ReleaseImpl2, |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 116 | void(SharedBitmap* shared_bitmap, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 117 | uint32 sync_point, |
| 118 | bool lost_resource, |
| 119 | BlockingTaskRunner* main_thread_task_runner)); |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | struct CommonMailboxObjects { |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 123 | explicit CommonMailboxObjects(SharedBitmapManager* manager) |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 124 | : mailbox_name1_(MailboxFromChar('1')), |
| 125 | mailbox_name2_(MailboxFromChar('2')), |
| 126 | sync_point1_(1), |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 127 | sync_point2_(2) { |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 128 | release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
| 129 | base::Unretained(&mock_callback_), |
| 130 | mailbox_name1_); |
| 131 | release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
| 132 | base::Unretained(&mock_callback_), |
| 133 | mailbox_name2_); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 134 | release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, |
| 135 | base::Unretained(&mock_callback_), |
| 136 | mailbox_name1_); |
| 137 | release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, |
| 138 | base::Unretained(&mock_callback_), |
| 139 | mailbox_name2_); |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 140 | const uint32 arbitrary_target1 = GL_TEXTURE_2D; |
| 141 | const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; |
| 142 | mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); |
| 143 | mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); |
| 144 | gfx::Size size(128, 128); |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 145 | shared_bitmap_ = manager->AllocateSharedBitmap(size); |
| 146 | DCHECK(shared_bitmap_); |
| 147 | release_mailbox3_ = |
| 148 | base::Bind(&MockMailboxCallback::Release2, |
| 149 | base::Unretained(&mock_callback_), shared_bitmap_.get()); |
| 150 | release_mailbox3_impl_ = |
| 151 | base::Bind(&MockMailboxCallback::ReleaseImpl2, |
| 152 | base::Unretained(&mock_callback_), shared_bitmap_.get()); |
| 153 | mailbox3_ = TextureMailbox(shared_bitmap_.get(), size); |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | gpu::Mailbox mailbox_name1_; |
| 157 | gpu::Mailbox mailbox_name2_; |
| 158 | MockMailboxCallback mock_callback_; |
| 159 | ReleaseCallback release_mailbox1_; |
| 160 | ReleaseCallback release_mailbox2_; |
| 161 | ReleaseCallback release_mailbox3_; |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 162 | ReleaseCallbackImpl release_mailbox1_impl_; |
| 163 | ReleaseCallbackImpl release_mailbox2_impl_; |
| 164 | ReleaseCallbackImpl release_mailbox3_impl_; |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 165 | TextureMailbox mailbox1_; |
| 166 | TextureMailbox mailbox2_; |
| 167 | TextureMailbox mailbox3_; |
| 168 | uint32 sync_point1_; |
| 169 | uint32 sync_point2_; |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 170 | scoped_ptr<SharedBitmap> shared_bitmap_; |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 171 | }; |
| 172 | |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 173 | class TextureLayerTest : public testing::Test { |
| 174 | public: |
| 175 | TextureLayerTest() |
| 176 | : fake_client_( |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 177 | FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 178 | host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 179 | test_data_(&shared_bitmap_manager_) {} |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 180 | |
| 181 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 182 | void SetUp() override { |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 183 | layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 184 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 185 | layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); |
| 186 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 187 | } |
| 188 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 189 | void TearDown() override { |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 190 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 191 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 192 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 193 | layer_tree_host_->SetRootLayer(nullptr); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 194 | layer_tree_host_ = nullptr; |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 198 | FakeImplProxy proxy_; |
| 199 | FakeLayerTreeHostClient fake_client_; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 200 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 201 | TestTaskGraphRunner task_graph_runner_; |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 202 | FakeLayerTreeHostImpl host_impl_; |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 203 | CommonMailboxObjects test_data_; |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 204 | }; |
| 205 | |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 206 | TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 207 | scoped_refptr<TextureLayer> test_layer = |
| 208 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 80d42bd | 2013-08-30 19:13:45 | [diff] [blame] | 209 | EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 210 | |
| 211 | // Test properties that should call SetNeedsCommit. All properties need to |
| 212 | // be set to new values in order for SetNeedsCommit to be called. |
| 213 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); |
jackhou | 10c9af4 | 2014-12-04 05:24:44 | [diff] [blame] | 214 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true)); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 215 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( |
| 216 | gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); |
| 217 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( |
| 218 | 0.5f, 0.5f, 0.5f, 0.5f)); |
| 219 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); |
| 220 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | 1c10e23 | 2013-07-31 12:35:43 | [diff] [blame] | 223 | TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { |
| 224 | const gfx::Size layer_bounds(100, 100); |
| 225 | const gfx::Rect layer_rect(layer_bounds); |
| 226 | const Region layer_region(layer_rect); |
| 227 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 228 | scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 1c10e23 | 2013-07-31 12:35:43 | [diff] [blame] | 229 | layer->SetBounds(layer_bounds); |
| 230 | layer->draw_properties().visible_content_rect = layer_rect; |
| 231 | layer->SetBlendBackgroundColor(true); |
| 232 | |
| 233 | // Verify initial conditions. |
| 234 | EXPECT_FALSE(layer->contents_opaque()); |
| 235 | EXPECT_EQ(0u, layer->background_color()); |
| 236 | EXPECT_EQ(Region().ToString(), |
| 237 | layer->VisibleContentOpaqueRegion().ToString()); |
| 238 | |
| 239 | // Opaque background. |
| 240 | layer->SetBackgroundColor(SK_ColorWHITE); |
| 241 | EXPECT_EQ(layer_region.ToString(), |
| 242 | layer->VisibleContentOpaqueRegion().ToString()); |
| 243 | |
| 244 | // Transparent background. |
| 245 | layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); |
| 246 | EXPECT_EQ(Region().ToString(), |
| 247 | layer->VisibleContentOpaqueRegion().ToString()); |
| 248 | } |
| 249 | |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 250 | TEST_F(TextureLayerTest, RateLimiter) { |
| 251 | FakeTextureLayerClient client; |
| 252 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( |
| 253 | &client); |
| 254 | test_layer->SetIsDrawable(true); |
| 255 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 256 | layer_tree_host_->SetRootLayer(test_layer); |
| 257 | |
| 258 | // Don't rate limit until we invalidate. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 259 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 260 | test_layer->SetRateLimitContext(true); |
| 261 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 262 | |
| 263 | // Do rate limit after we invalidate. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 264 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 265 | test_layer->SetNeedsDisplay(); |
| 266 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 267 | |
| 268 | // Stop rate limiter when we don't want it any more. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 269 | EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 270 | test_layer->SetRateLimitContext(false); |
| 271 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 272 | |
| 273 | // Or we clear the client. |
| 274 | test_layer->SetRateLimitContext(true); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 275 | EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 276 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 277 | test_layer->ClearClient(); |
| 278 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 279 | |
| 280 | // Reset to a layer with a client, that started the rate limiter. |
| 281 | test_layer = TextureLayer::CreateForMailbox( |
| 282 | &client); |
| 283 | test_layer->SetIsDrawable(true); |
| 284 | test_layer->SetRateLimitContext(true); |
| 285 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 286 | layer_tree_host_->SetRootLayer(test_layer); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 287 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 288 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 289 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 290 | test_layer->SetNeedsDisplay(); |
| 291 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 292 | |
| 293 | // Stop rate limiter when we're removed from the tree. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 294 | EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
[email protected] | d72d9e0 | 2014-04-03 18:40:09 | [diff] [blame] | 295 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 296 | layer_tree_host_->SetRootLayer(nullptr); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 297 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 298 | } |
| 299 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 300 | class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 301 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 302 | using TextureLayer::TextureMailboxHolder::Create; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 303 | |
| 304 | protected: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 305 | ~TestMailboxHolder() override {} |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 306 | }; |
| 307 | |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 308 | class TextureLayerWithMailboxTest : public TextureLayerTest { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 309 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 310 | void TearDown() override { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 311 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 312 | EXPECT_CALL(test_data_.mock_callback_, |
| 313 | Release(test_data_.mailbox_name1_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 314 | test_data_.sync_point1_, |
| 315 | false)).Times(1); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 316 | TextureLayerTest::TearDown(); |
| 317 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 318 | }; |
| 319 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 320 | TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 321 | scoped_refptr<TextureLayer> test_layer = |
| 322 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 323 | ASSERT_TRUE(test_layer.get()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 324 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 325 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 326 | layer_tree_host_->SetRootLayer(test_layer); |
| 327 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 328 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 329 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 330 | test_layer->SetTextureMailbox( |
| 331 | test_data_.mailbox1_, |
| 332 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 333 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 334 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 335 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 336 | EXPECT_CALL(test_data_.mock_callback_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 337 | Release(test_data_.mailbox_name1_, |
| 338 | test_data_.sync_point1_, |
| 339 | false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 340 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 341 | test_layer->SetTextureMailbox( |
| 342 | test_data_.mailbox2_, |
| 343 | SingleReleaseCallback::Create(test_data_.release_mailbox2_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 344 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 345 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 346 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 347 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 348 | EXPECT_CALL(test_data_.mock_callback_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 349 | Release(test_data_.mailbox_name2_, |
| 350 | test_data_.sync_point2_, |
| 351 | false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 352 | .Times(1); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 353 | test_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 354 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 355 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 356 | |
[email protected] | 80d42bd | 2013-08-30 19:13:45 | [diff] [blame] | 357 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 358 | test_layer->SetTextureMailbox( |
| 359 | test_data_.mailbox3_, |
| 360 | SingleReleaseCallback::Create(test_data_.release_mailbox3_)); |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 361 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 362 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 363 | |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 364 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 365 | EXPECT_CALL(test_data_.mock_callback_, |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 366 | Release2(test_data_.shared_bitmap_.get(), 0, false)).Times(1); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 367 | test_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 368 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 369 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 370 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 371 | // Test destructor. |
| 372 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 373 | test_layer->SetTextureMailbox( |
| 374 | test_data_.mailbox1_, |
| 375 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | f9e8f45 | 2014-03-07 22:09:40 | [diff] [blame] | 378 | TEST_F(TextureLayerTest, SetTextureMailboxWithoutReleaseCallback) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 379 | scoped_refptr<TextureLayer> test_layer = |
| 380 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | f9e8f45 | 2014-03-07 22:09:40 | [diff] [blame] | 381 | ASSERT_TRUE(test_layer.get()); |
| 382 | |
| 383 | // These use the same gpu::Mailbox, but different sync points. |
| 384 | TextureMailbox mailbox1(MailboxFromChar('a'), GL_TEXTURE_2D, 1); |
| 385 | TextureMailbox mailbox2(MailboxFromChar('a'), GL_TEXTURE_2D, 2); |
| 386 | |
[email protected] | f9e8f45 | 2014-03-07 22:09:40 | [diff] [blame] | 387 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 388 | layer_tree_host_->SetRootLayer(test_layer); |
| 389 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 390 | |
| 391 | // Set the mailbox the first time. It should cause a commit. |
[email protected] | f9e8f45 | 2014-03-07 22:09:40 | [diff] [blame] | 392 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 393 | test_layer->SetTextureMailboxWithoutReleaseCallback(mailbox1); |
| 394 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 395 | |
| 396 | // Set the mailbox again with a new sync point, as the backing texture has |
| 397 | // been updated. It should cause a new commit. |
[email protected] | f9e8f45 | 2014-03-07 22:09:40 | [diff] [blame] | 398 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 399 | test_layer->SetTextureMailboxWithoutReleaseCallback(mailbox2); |
| 400 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 401 | } |
| 402 | |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 403 | class TextureLayerMailboxHolderTest : public TextureLayerTest { |
| 404 | public: |
| 405 | TextureLayerMailboxHolderTest() |
| 406 | : main_thread_("MAIN") { |
| 407 | main_thread_.Start(); |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 408 | main_thread_.message_loop()->task_runner()->PostTask( |
| 409 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::InitializeOnMain, |
| 410 | base::Unretained(this))); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 411 | Wait(main_thread_); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void Wait(const base::Thread& thread) { |
| 415 | bool manual_reset = false; |
| 416 | bool initially_signaled = false; |
| 417 | base::WaitableEvent event(manual_reset, initially_signaled); |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 418 | thread.message_loop()->task_runner()->PostTask( |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 419 | FROM_HERE, |
| 420 | base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 421 | event.Wait(); |
| 422 | } |
| 423 | |
| 424 | void CreateMainRef() { |
| 425 | main_ref_ = TestMailboxHolder::Create( |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 426 | test_data_.mailbox1_, |
| 427 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)).Pass(); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 428 | } |
| 429 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 430 | void ReleaseMainRef() { main_ref_ = nullptr; } |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 431 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 432 | void CreateImplRef(scoped_ptr<SingleReleaseCallbackImpl>* impl_ref) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 433 | *impl_ref = main_ref_->holder()->GetCallbackForImplThread(); |
| 434 | } |
| 435 | |
| 436 | void CapturePostTasksAndWait(base::WaitableEvent* begin_capture, |
| 437 | base::WaitableEvent* wait_for_capture, |
| 438 | base::WaitableEvent* stop_capture) { |
| 439 | begin_capture->Wait(); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 440 | BlockingTaskRunner::CapturePostTasks capture( |
| 441 | main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 442 | wait_for_capture->Signal(); |
| 443 | stop_capture->Wait(); |
| 444 | } |
| 445 | |
| 446 | protected: |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 447 | void InitializeOnMain() { |
| 448 | main_thread_task_runner_ = |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 449 | BlockingTaskRunner::Create(main_thread_.task_runner()); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 450 | } |
| 451 | |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 452 | scoped_ptr<TestMailboxHolder::MainThreadReference> |
| 453 | main_ref_; |
| 454 | base::Thread main_thread_; |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 455 | scoped_ptr<BlockingTaskRunner> main_thread_task_runner_; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 459 | scoped_refptr<TextureLayer> test_layer = |
| 460 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 461 | ASSERT_TRUE(test_layer.get()); |
| 462 | |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 463 | main_thread_.message_loop()->task_runner()->PostTask( |
| 464 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 465 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 466 | |
| 467 | Wait(main_thread_); |
| 468 | |
| 469 | // The texture layer is attached to compositor1, and passes a reference to its |
| 470 | // impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 471 | scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 472 | main_thread_.message_loop()->task_runner()->PostTask( |
| 473 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 474 | base::Unretained(this), &compositor1)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 475 | |
| 476 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 477 | // reference to its impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 478 | scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 479 | main_thread_.message_loop()->task_runner()->PostTask( |
| 480 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 481 | base::Unretained(this), &compositor2)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 482 | |
| 483 | Wait(main_thread_); |
| 484 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 485 | |
| 486 | // The compositors both destroy their impl trees before the main thread layer |
| 487 | // is destroyed. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 488 | compositor1->Run(100, false, main_thread_task_runner_.get()); |
| 489 | compositor2->Run(200, false, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 490 | |
| 491 | Wait(main_thread_); |
| 492 | |
| 493 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 494 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 495 | |
| 496 | // The main thread ref is the last one, so the mailbox is released back to the |
| 497 | // embedder, with the last sync point provided by the impl trees. |
| 498 | EXPECT_CALL(test_data_.mock_callback_, |
| 499 | Release(test_data_.mailbox_name1_, 200, false)).Times(1); |
| 500 | |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 501 | main_thread_.message_loop()->task_runner()->PostTask( |
| 502 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 503 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 504 | Wait(main_thread_); |
| 505 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 506 | } |
| 507 | |
| 508 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 509 | scoped_refptr<TextureLayer> test_layer = |
| 510 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 511 | ASSERT_TRUE(test_layer.get()); |
| 512 | |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 513 | main_thread_.message_loop()->task_runner()->PostTask( |
| 514 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 515 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 516 | |
| 517 | Wait(main_thread_); |
| 518 | |
| 519 | // The texture layer is attached to compositor1, and passes a reference to its |
| 520 | // impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 521 | scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 522 | main_thread_.message_loop()->task_runner()->PostTask( |
| 523 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 524 | base::Unretained(this), &compositor1)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 525 | |
| 526 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 527 | // reference to its impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 528 | scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 529 | main_thread_.message_loop()->task_runner()->PostTask( |
| 530 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 531 | base::Unretained(this), &compositor2)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 532 | |
| 533 | Wait(main_thread_); |
| 534 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 535 | |
| 536 | // One compositor destroys their impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 537 | compositor1->Run(100, false, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 538 | |
| 539 | // Then the main thread reference is destroyed. |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 540 | main_thread_.message_loop()->task_runner()->PostTask( |
| 541 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 542 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 543 | |
| 544 | Wait(main_thread_); |
| 545 | |
| 546 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 547 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 548 | |
| 549 | // The second impl reference is destroyed last, causing the mailbox to be |
| 550 | // released back to the embedder with the last sync point from the impl tree. |
| 551 | EXPECT_CALL(test_data_.mock_callback_, |
| 552 | Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
| 553 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 554 | compositor2->Run(200, true, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 555 | Wait(main_thread_); |
| 556 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 557 | } |
| 558 | |
| 559 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 560 | scoped_refptr<TextureLayer> test_layer = |
| 561 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 562 | ASSERT_TRUE(test_layer.get()); |
| 563 | |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 564 | main_thread_.message_loop()->task_runner()->PostTask( |
| 565 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 566 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 567 | |
| 568 | Wait(main_thread_); |
| 569 | |
| 570 | // The texture layer is attached to compositor1, and passes a reference to its |
| 571 | // impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 572 | scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 573 | main_thread_.message_loop()->task_runner()->PostTask( |
| 574 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 575 | base::Unretained(this), &compositor1)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 576 | |
| 577 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 578 | // reference to its impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 579 | scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 580 | main_thread_.message_loop()->task_runner()->PostTask( |
| 581 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 582 | base::Unretained(this), &compositor2)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 583 | |
| 584 | Wait(main_thread_); |
| 585 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 586 | |
| 587 | // The main thread reference is destroyed first. |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 588 | main_thread_.message_loop()->task_runner()->PostTask( |
| 589 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 590 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 591 | |
| 592 | // One compositor destroys their impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 593 | compositor2->Run(200, false, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 594 | |
| 595 | Wait(main_thread_); |
| 596 | |
| 597 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 598 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 599 | |
| 600 | // The second impl reference is destroyed last, causing the mailbox to be |
| 601 | // released back to the embedder with the last sync point from the impl tree. |
| 602 | EXPECT_CALL(test_data_.mock_callback_, |
| 603 | Release(test_data_.mailbox_name1_, 100, true)).Times(1); |
| 604 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 605 | compositor1->Run(100, true, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 606 | Wait(main_thread_); |
| 607 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 608 | } |
| 609 | |
| 610 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 611 | scoped_refptr<TextureLayer> test_layer = |
| 612 | TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 613 | ASSERT_TRUE(test_layer.get()); |
| 614 | |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 615 | main_thread_.message_loop()->task_runner()->PostTask( |
| 616 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 617 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 618 | |
| 619 | Wait(main_thread_); |
| 620 | |
| 621 | // The texture layer is attached to compositor1, and passes a reference to its |
| 622 | // impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 623 | scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 624 | main_thread_.message_loop()->task_runner()->PostTask( |
| 625 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 626 | base::Unretained(this), &compositor1)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 627 | |
| 628 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 629 | // reference to its impl tree. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 630 | scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 631 | main_thread_.message_loop()->task_runner()->PostTask( |
| 632 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 633 | base::Unretained(this), &compositor2)); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 634 | |
| 635 | Wait(main_thread_); |
| 636 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 637 | |
| 638 | // The main thread reference is destroyed first. |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 639 | main_thread_.message_loop()->task_runner()->PostTask( |
| 640 | FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 641 | base::Unretained(this))); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 642 | |
| 643 | EXPECT_CALL(test_data_.mock_callback_, |
| 644 | Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
| 645 | |
| 646 | bool manual_reset = false; |
| 647 | bool initially_signaled = false; |
| 648 | base::WaitableEvent begin_capture(manual_reset, initially_signaled); |
| 649 | base::WaitableEvent wait_for_capture(manual_reset, initially_signaled); |
| 650 | base::WaitableEvent stop_capture(manual_reset, initially_signaled); |
| 651 | |
| 652 | // Post a task to start capturing tasks on the main thread. This will block |
| 653 | // the main thread until we signal the |stop_capture| event. |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 654 | main_thread_.message_loop()->task_runner()->PostTask( |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 655 | FROM_HERE, |
| 656 | base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait, |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame^] | 657 | base::Unretained(this), &begin_capture, &wait_for_capture, |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 658 | &stop_capture)); |
| 659 | |
| 660 | // Before the main thread capturing starts, one compositor destroys their |
| 661 | // impl reference. Since capturing did not start, this gets post-tasked to |
| 662 | // the main thread. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 663 | compositor1->Run(100, false, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 664 | |
| 665 | // Start capturing on the main thread. |
| 666 | begin_capture.Signal(); |
| 667 | wait_for_capture.Wait(); |
| 668 | |
| 669 | // Meanwhile, the second compositor released its impl reference, but this task |
| 670 | // gets shortcutted directly to the main thread. This means the reference is |
| 671 | // released before compositor1, whose reference will be released later when |
| 672 | // the post-task is serviced. But since it was destroyed _on the impl thread_ |
| 673 | // last, its sync point values should be used. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 674 | compositor2->Run(200, true, main_thread_task_runner_.get()); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 675 | |
| 676 | stop_capture.Signal(); |
| 677 | Wait(main_thread_); |
| 678 | |
| 679 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 680 | } |
| 681 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 682 | class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 683 | public: |
| 684 | TextureLayerImplWithMailboxThreadedCallback() |
| 685 | : callback_count_(0), |
| 686 | commit_count_(0) {} |
| 687 | |
| 688 | // Make sure callback is received on main and doesn't block the impl thread. |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 689 | void ReleaseCallback(uint32 sync_point, bool lost_resource) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 690 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 691 | EXPECT_FALSE(lost_resource); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 692 | ++callback_count_; |
| 693 | } |
| 694 | |
| 695 | void SetMailbox(char mailbox_char) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 696 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 697 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 698 | base::Bind( |
| 699 | &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
| 700 | base::Unretained(this))); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 701 | layer_->SetTextureMailbox( |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 702 | TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 703 | callback.Pass()); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 704 | } |
| 705 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 706 | void BeginTest() override { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 707 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 708 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 709 | gfx::Size bounds(100, 100); |
| 710 | root_ = Layer::Create(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 711 | root_->SetBounds(bounds); |
| 712 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 713 | layer_ = TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 714 | layer_->SetIsDrawable(true); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 715 | layer_->SetBounds(bounds); |
| 716 | |
| 717 | root_->AddChild(layer_); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 718 | layer_tree_host()->SetRootLayer(root_); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 719 | layer_tree_host()->SetViewportSize(bounds); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 720 | SetMailbox('1'); |
| 721 | EXPECT_EQ(0, callback_count_); |
| 722 | |
| 723 | // Case #1: change mailbox before the commit. The old mailbox should be |
| 724 | // released immediately. |
| 725 | SetMailbox('2'); |
| 726 | EXPECT_EQ(1, callback_count_); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 727 | PostSetNeedsCommitToMainThread(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 728 | } |
| 729 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 730 | void DidCommit() override { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 731 | ++commit_count_; |
| 732 | switch (commit_count_) { |
| 733 | case 1: |
| 734 | // Case #2: change mailbox after the commit (and draw), where the |
| 735 | // layer draws. The old mailbox should be released during the next |
| 736 | // commit. |
| 737 | SetMailbox('3'); |
| 738 | EXPECT_EQ(1, callback_count_); |
| 739 | break; |
| 740 | case 2: |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 741 | EXPECT_EQ(2, callback_count_); |
| 742 | // Case #3: change mailbox when the layer doesn't draw. The old |
| 743 | // mailbox should be released during the next commit. |
| 744 | layer_->SetBounds(gfx::Size()); |
| 745 | SetMailbox('4'); |
| 746 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 747 | case 3: |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 748 | EXPECT_EQ(3, callback_count_); |
| 749 | // Case #4: release mailbox that was committed but never drawn. The |
| 750 | // old mailbox should be released during the next commit. |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 751 | layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 752 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 753 | case 4: |
| 754 | if (layer_tree_host()->settings().impl_side_painting) { |
| 755 | // With impl painting, the texture mailbox will still be on the impl |
| 756 | // thread when the commit finishes, because the layer is not drawble |
| 757 | // when it has no texture mailbox, and thus does not block the commit |
| 758 | // on activation. So, we wait for activation. |
| 759 | // TODO(danakj): fix this. crbug.com/277953 |
| 760 | layer_tree_host()->SetNeedsCommit(); |
| 761 | break; |
| 762 | } else { |
| 763 | ++commit_count_; |
| 764 | } |
| 765 | case 5: |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 766 | EXPECT_EQ(4, callback_count_); |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 767 | // Restore a mailbox for the next step. |
| 768 | SetMailbox('5'); |
| 769 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 770 | case 6: |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 771 | // Case #5: remove layer from tree. Callback should *not* be called, the |
| 772 | // mailbox is returned to the main thread. |
| 773 | EXPECT_EQ(4, callback_count_); |
| 774 | layer_->RemoveFromParent(); |
| 775 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 776 | case 7: |
| 777 | if (layer_tree_host()->settings().impl_side_painting) { |
| 778 | // With impl painting, the texture mailbox will still be on the impl |
| 779 | // thread when the commit finishes, because the layer is not around to |
| 780 | // block the commit on activation anymore. So, we wait for activation. |
| 781 | // TODO(danakj): fix this. crbug.com/277953 |
| 782 | layer_tree_host()->SetNeedsCommit(); |
| 783 | break; |
| 784 | } else { |
| 785 | ++commit_count_; |
| 786 | } |
| 787 | case 8: |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 788 | EXPECT_EQ(4, callback_count_); |
| 789 | // Resetting the mailbox will call the callback now. |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 790 | layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 791 | EXPECT_EQ(5, callback_count_); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 792 | EndTest(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 793 | break; |
| 794 | default: |
| 795 | NOTREACHED(); |
| 796 | break; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 797 | } |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 798 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 799 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 800 | void AfterTest() override {} |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 801 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 802 | private: |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 803 | base::ThreadChecker main_thread_; |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 804 | int callback_count_; |
| 805 | int commit_count_; |
| 806 | scoped_refptr<Layer> root_; |
| 807 | scoped_refptr<TextureLayer> layer_; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 808 | }; |
| 809 | |
[email protected] | 4145d17 | 2013-05-10 16:54:36 | [diff] [blame] | 810 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 811 | TextureLayerImplWithMailboxThreadedCallback); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 812 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 813 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 814 | class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
| 815 | protected: |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 816 | TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 817 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 818 | static void ReleaseCallback(uint32 sync_point, bool lost_resource) {} |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 819 | |
| 820 | void SetMailbox(char mailbox_char) { |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 821 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 822 | base::Bind( |
| 823 | &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 824 | layer_->SetTextureMailbox( |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 825 | TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 826 | callback.Pass()); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 827 | } |
| 828 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 829 | void BeginTest() override { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 830 | gfx::Size bounds(100, 100); |
| 831 | root_ = Layer::Create(); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 832 | root_->SetBounds(bounds); |
| 833 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 834 | layer_ = TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 835 | layer_->SetIsDrawable(true); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 836 | layer_->SetBounds(bounds); |
| 837 | |
| 838 | root_->AddChild(layer_); |
| 839 | layer_tree_host()->SetRootLayer(root_); |
| 840 | layer_tree_host()->SetViewportSize(bounds); |
| 841 | SetMailbox('1'); |
| 842 | |
| 843 | PostSetNeedsCommitToMainThread(); |
| 844 | } |
| 845 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 846 | void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 847 | ++activate_count_; |
| 848 | } |
| 849 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 850 | void DidCommit() override { |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 851 | switch (layer_tree_host()->source_frame_number()) { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 852 | case 1: |
| 853 | // The first mailbox has been activated. Set a new mailbox, and |
| 854 | // expect the next commit to finish *after* it is activated. |
| 855 | SetMailbox('2'); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 856 | break; |
| 857 | case 2: |
| 858 | // The second mailbox has been activated. Remove the layer from |
| 859 | // the tree to cause another commit/activation. The commit should |
| 860 | // finish *after* the layer is removed from the active tree. |
| 861 | layer_->RemoveFromParent(); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 862 | break; |
| 863 | case 3: |
| 864 | EndTest(); |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 869 | void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 870 | switch (host_impl->active_tree()->source_frame_number()) { |
[email protected] | b606106 | 2014-06-27 19:20:08 | [diff] [blame] | 871 | case 0: { |
| 872 | // The activate for the 1st mailbox should have happened before now. |
| 873 | EXPECT_EQ(1, activate_count_); |
| 874 | break; |
| 875 | } |
| 876 | case 1: { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 877 | // The activate for the 2nd mailbox should have happened before now. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 878 | EXPECT_EQ(2, activate_count_); |
| 879 | break; |
| 880 | } |
[email protected] | b606106 | 2014-06-27 19:20:08 | [diff] [blame] | 881 | case 2: { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 882 | // The activate to remove the layer should have happened before now. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 883 | EXPECT_EQ(3, activate_count_); |
| 884 | break; |
| 885 | } |
[email protected] | b606106 | 2014-06-27 19:20:08 | [diff] [blame] | 886 | case 3: { |
| 887 | NOTREACHED(); |
| 888 | break; |
| 889 | } |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 893 | void AfterTest() override {} |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 894 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 895 | int activate_count_; |
| 896 | scoped_refptr<Layer> root_; |
| 897 | scoped_refptr<TextureLayer> layer_; |
| 898 | }; |
| 899 | |
| 900 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 901 | TextureLayerMailboxIsActivatedDuringCommit); |
| 902 | |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 903 | class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 904 | protected: |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 905 | TextureLayerImplWithMailboxTest() |
| 906 | : fake_client_( |
| 907 | FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {} |
| 908 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 909 | void SetUp() override { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 910 | TextureLayerTest::SetUp(); |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 911 | layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 912 | EXPECT_TRUE(host_impl_.InitializeRenderer(FakeOutputSurface::Create3d())); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 913 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 914 | |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 915 | bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { |
| 916 | bool will_draw = layer->WillDraw( |
| 917 | mode, host_impl_.active_tree()->resource_provider()); |
| 918 | if (will_draw) |
| 919 | layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
| 920 | return will_draw; |
| 921 | } |
| 922 | |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 923 | FakeLayerTreeHostClient fake_client_; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 924 | }; |
| 925 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 926 | // Test conditions for results of TextureLayerImpl::WillDraw under |
| 927 | // different configurations of different mailbox, texture_id, and draw_mode. |
| 928 | TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 929 | EXPECT_CALL( |
| 930 | test_data_.mock_callback_, |
| 931 | ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 932 | .Times(AnyNumber()); |
| 933 | EXPECT_CALL(test_data_.mock_callback_, |
jbauman | 9015c8b | 2014-12-11 00:49:37 | [diff] [blame] | 934 | ReleaseImpl2(test_data_.shared_bitmap_.get(), 0, false, _)) |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 935 | .Times(AnyNumber()); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 936 | // Hardware mode. |
| 937 | { |
| 938 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 939 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 940 | impl_layer->SetTextureMailbox( |
| 941 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 942 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 943 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | { |
| 947 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 948 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 949 | impl_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 950 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
| 951 | } |
| 952 | |
| 953 | { |
| 954 | // Software resource. |
| 955 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 956 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 957 | impl_layer->SetTextureMailbox( |
| 958 | test_data_.mailbox3_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 959 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_)); |
[email protected] | 3e44d7a | 2013-07-30 00:03:10 | [diff] [blame] | 960 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 961 | } |
| 962 | |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 963 | // Software mode. |
| 964 | { |
| 965 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 966 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 967 | impl_layer->SetTextureMailbox( |
| 968 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 969 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 970 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 971 | } |
| 972 | |
| 973 | { |
| 974 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 975 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 976 | impl_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 977 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 978 | } |
| 979 | |
| 980 | { |
| 981 | // Software resource. |
| 982 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 983 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 984 | impl_layer->SetTextureMailbox( |
| 985 | test_data_.mailbox3_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 986 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 987 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 988 | } |
| 989 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 990 | // Resourceless software mode. |
| 991 | { |
| 992 | scoped_ptr<TextureLayerImpl> impl_layer = |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 993 | TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 994 | impl_layer->SetTextureMailbox( |
| 995 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 996 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 997 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 998 | } |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 999 | } |
| 1000 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1001 | TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { |
| 1002 | host_impl_.CreatePendingTree(); |
| 1003 | scoped_ptr<TextureLayerImpl> pending_layer; |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 1004 | pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1005 | ASSERT_TRUE(pending_layer); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1006 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1007 | scoped_ptr<LayerImpl> active_layer( |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1008 | pending_layer->CreateLayerImpl(host_impl_.active_tree())); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1009 | ASSERT_TRUE(active_layer); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1010 | |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1011 | pending_layer->SetTextureMailbox( |
| 1012 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1013 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1014 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1015 | // Test multiple commits without an activation. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1016 | EXPECT_CALL( |
| 1017 | test_data_.mock_callback_, |
| 1018 | ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1019 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1020 | pending_layer->SetTextureMailbox( |
| 1021 | test_data_.mailbox2_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1022 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1023 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1024 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1025 | // Test callback after activation. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1026 | pending_layer->PushPropertiesTo(active_layer.get()); |
| 1027 | active_layer->DidBecomeActive(); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1028 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1029 | EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1030 | pending_layer->SetTextureMailbox( |
| 1031 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1032 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1033 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1034 | |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1035 | EXPECT_CALL(test_data_.mock_callback_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1036 | ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1037 | pending_layer->PushPropertiesTo(active_layer.get()); |
| 1038 | active_layer->DidBecomeActive(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1039 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1040 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1041 | // Test resetting the mailbox. |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1042 | EXPECT_CALL(test_data_.mock_callback_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1043 | ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 1044 | pending_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1045 | pending_layer->PushPropertiesTo(active_layer.get()); |
| 1046 | active_layer->DidBecomeActive(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1047 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1048 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1049 | // Test destructor. |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1050 | EXPECT_CALL( |
| 1051 | test_data_.mock_callback_, |
| 1052 | ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1053 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1054 | pending_layer->SetTextureMailbox( |
| 1055 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1056 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1057 | } |
| 1058 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1059 | TEST_F(TextureLayerImplWithMailboxTest, |
| 1060 | TestDestructorCallbackOnCreatedResource) { |
| 1061 | scoped_ptr<TextureLayerImpl> impl_layer; |
[email protected] | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 1062 | impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1063 | ASSERT_TRUE(impl_layer); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1064 | |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1065 | EXPECT_CALL(test_data_.mock_callback_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1066 | ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1067 | impl_layer->SetTextureMailbox( |
| 1068 | test_data_.mailbox1_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1069 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1070 | impl_layer->DidBecomeActive(); |
| 1071 | EXPECT_TRUE(impl_layer->WillDraw( |
| 1072 | DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider())); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1073 | impl_layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 1074 | impl_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1075 | } |
| 1076 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1077 | TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) { |
| 1078 | ResourceProvider* provider = host_impl_.active_tree()->resource_provider(); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1079 | ResourceProvider::ResourceId id = provider->CreateResourceFromTextureMailbox( |
| 1080 | test_data_.mailbox1_, |
| 1081 | SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1082 | provider->AllocateForTesting(id); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1083 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1084 | // Transfer some resources to the parent. |
| 1085 | ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1086 | resource_ids_to_transfer.push_back(id); |
| 1087 | TransferableResourceArray list; |
| 1088 | provider->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1089 | EXPECT_TRUE(provider->InUseByConsumer(id)); |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1090 | EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1091 | provider->DeleteResource(id); |
| 1092 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1093 | EXPECT_CALL(test_data_.mock_callback_, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1094 | ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1); |
[email protected] | e00bab02 | 2013-08-19 00:42:45 | [diff] [blame] | 1095 | ReturnedResourceArray returned; |
| 1096 | TransferableResource::ReturnResources(list, &returned); |
| 1097 | provider->ReceiveReturnsFromParent(returned); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1098 | } |
| 1099 | |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1100 | // Checks that TextureLayer::Update does not cause an extra commit when setting |
| 1101 | // the texture mailbox. |
| 1102 | class TextureLayerNoExtraCommitForMailboxTest |
| 1103 | : public LayerTreeTest, |
| 1104 | public TextureLayerClient { |
| 1105 | public: |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1106 | // TextureLayerClient implementation. |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1107 | bool PrepareTextureMailbox( |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1108 | TextureMailbox* texture_mailbox, |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1109 | scoped_ptr<SingleReleaseCallback>* release_callback, |
mostynb | f68776d8 | 2014-10-06 18:07:37 | [diff] [blame] | 1110 | bool use_shared_memory) override { |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1111 | if (layer_tree_host()->source_frame_number() == 1) { |
[email protected] | 9f35bd2 | 2014-06-03 15:25:46 | [diff] [blame] | 1112 | // Once this has been committed, the mailbox will be released. |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1113 | *texture_mailbox = TextureMailbox(); |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1114 | return true; |
| 1115 | } |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1116 | |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 1117 | *texture_mailbox = TextureMailbox(MailboxFromChar('1'), GL_TEXTURE_2D, 0); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1118 | *release_callback = SingleReleaseCallback::Create( |
| 1119 | base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, |
| 1120 | base::Unretained(this))); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1121 | return true; |
| 1122 | } |
| 1123 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1124 | void MailboxReleased(uint32 sync_point, bool lost_resource) { |
[email protected] | 9f35bd2 | 2014-06-03 15:25:46 | [diff] [blame] | 1125 | // Source frame number during callback is the same as the source frame |
| 1126 | // on which it was released. |
| 1127 | EXPECT_EQ(1, layer_tree_host()->source_frame_number()); |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1128 | EndTest(); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1129 | } |
| 1130 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1131 | void SetupTree() override { |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1132 | scoped_refptr<Layer> root = Layer::Create(); |
| 1133 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1134 | root->SetIsDrawable(true); |
| 1135 | |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1136 | texture_layer_ = TextureLayer::CreateForMailbox(this); |
| 1137 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1138 | texture_layer_->SetIsDrawable(true); |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1139 | root->AddChild(texture_layer_); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1140 | |
| 1141 | layer_tree_host()->SetRootLayer(root); |
| 1142 | LayerTreeTest::SetupTree(); |
| 1143 | } |
| 1144 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1145 | void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1146 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1147 | void DidCommitAndDrawFrame() override { |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1148 | switch (layer_tree_host()->source_frame_number()) { |
| 1149 | case 1: |
[email protected] | 4ea293f7 | 2014-08-13 03:03:17 | [diff] [blame] | 1150 | EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting()); |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1151 | // Invalidate the texture layer to clear the mailbox before |
| 1152 | // ending the test. |
| 1153 | texture_layer_->SetNeedsDisplay(); |
| 1154 | break; |
| 1155 | case 2: |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1156 | break; |
| 1157 | default: |
| 1158 | NOTREACHED(); |
| 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1163 | void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1164 | ASSERT_TRUE(result); |
| 1165 | DelegatedFrameData* delegated_frame_data = |
| 1166 | output_surface()->last_sent_frame().delegated_frame_data.get(); |
| 1167 | if (!delegated_frame_data) |
| 1168 | return; |
| 1169 | |
| 1170 | // Return all resources immediately. |
| 1171 | TransferableResourceArray resources_to_return = |
| 1172 | output_surface()->resources_held_by_parent(); |
| 1173 | |
| 1174 | CompositorFrameAck ack; |
| 1175 | for (size_t i = 0; i < resources_to_return.size(); ++i) |
| 1176 | output_surface()->ReturnResource(resources_to_return[i].id, &ack); |
| 1177 | host_impl->ReclaimResources(&ack); |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1178 | } |
| 1179 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1180 | void AfterTest() override {} |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1181 | |
| 1182 | private: |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1183 | scoped_refptr<TextureLayer> texture_layer_; |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1184 | }; |
| 1185 | |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1186 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1187 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1188 | // Checks that changing a mailbox in the client for a TextureLayer that's |
| 1189 | // invisible correctly works and uses the new mailbox as soon as the layer |
| 1190 | // becomes visible (and returns the old one). |
| 1191 | class TextureLayerChangeInvisibleMailboxTest |
| 1192 | : public LayerTreeTest, |
| 1193 | public TextureLayerClient { |
| 1194 | public: |
| 1195 | TextureLayerChangeInvisibleMailboxTest() |
| 1196 | : mailbox_changed_(true), |
| 1197 | mailbox_returned_(0), |
| 1198 | prepare_called_(0), |
| 1199 | commit_count_(0) { |
| 1200 | mailbox_ = MakeMailbox('1'); |
| 1201 | } |
| 1202 | |
| 1203 | // TextureLayerClient implementation. |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1204 | bool PrepareTextureMailbox( |
[email protected] | e51444a | 2013-12-10 23:05:01 | [diff] [blame] | 1205 | TextureMailbox* mailbox, |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1206 | scoped_ptr<SingleReleaseCallback>* release_callback, |
mostynb | f68776d8 | 2014-10-06 18:07:37 | [diff] [blame] | 1207 | bool use_shared_memory) override { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1208 | ++prepare_called_; |
| 1209 | if (!mailbox_changed_) |
| 1210 | return false; |
| 1211 | *mailbox = mailbox_; |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1212 | *release_callback = SingleReleaseCallback::Create( |
| 1213 | base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, |
| 1214 | base::Unretained(this))); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1215 | return true; |
| 1216 | } |
| 1217 | |
| 1218 | TextureMailbox MakeMailbox(char name) { |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 1219 | return TextureMailbox(MailboxFromChar(name), GL_TEXTURE_2D, 0); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1220 | } |
| 1221 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1222 | void MailboxReleased(uint32 sync_point, bool lost_resource) { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1223 | ++mailbox_returned_; |
| 1224 | } |
| 1225 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1226 | void SetupTree() override { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1227 | scoped_refptr<Layer> root = Layer::Create(); |
| 1228 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1229 | root->SetIsDrawable(true); |
| 1230 | |
| 1231 | solid_layer_ = SolidColorLayer::Create(); |
| 1232 | solid_layer_->SetBounds(gfx::Size(10, 10)); |
| 1233 | solid_layer_->SetIsDrawable(true); |
| 1234 | solid_layer_->SetBackgroundColor(SK_ColorWHITE); |
| 1235 | root->AddChild(solid_layer_); |
| 1236 | |
| 1237 | parent_layer_ = Layer::Create(); |
| 1238 | parent_layer_->SetBounds(gfx::Size(10, 10)); |
| 1239 | parent_layer_->SetIsDrawable(true); |
| 1240 | root->AddChild(parent_layer_); |
| 1241 | |
| 1242 | texture_layer_ = TextureLayer::CreateForMailbox(this); |
| 1243 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1244 | texture_layer_->SetIsDrawable(true); |
| 1245 | parent_layer_->AddChild(texture_layer_); |
| 1246 | |
| 1247 | layer_tree_host()->SetRootLayer(root); |
| 1248 | LayerTreeTest::SetupTree(); |
| 1249 | } |
| 1250 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1251 | void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1252 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1253 | void DidCommitAndDrawFrame() override { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1254 | ++commit_count_; |
| 1255 | switch (commit_count_) { |
| 1256 | case 1: |
| 1257 | // We should have updated the layer, committing the texture. |
| 1258 | EXPECT_EQ(1, prepare_called_); |
| 1259 | // Make layer invisible. |
| 1260 | parent_layer_->SetOpacity(0.f); |
| 1261 | break; |
| 1262 | case 2: |
| 1263 | // Layer shouldn't have been updated. |
| 1264 | EXPECT_EQ(1, prepare_called_); |
| 1265 | // Change the texture. |
| 1266 | mailbox_ = MakeMailbox('2'); |
| 1267 | mailbox_changed_ = true; |
| 1268 | texture_layer_->SetNeedsDisplay(); |
| 1269 | // Force a change to make sure we draw a frame. |
| 1270 | solid_layer_->SetBackgroundColor(SK_ColorGRAY); |
| 1271 | break; |
| 1272 | case 3: |
| 1273 | // Layer shouldn't have been updated. |
| 1274 | EXPECT_EQ(1, prepare_called_); |
| 1275 | // So the old mailbox isn't returned yet. |
| 1276 | EXPECT_EQ(0, mailbox_returned_); |
| 1277 | // Make layer visible again. |
| 1278 | parent_layer_->SetOpacity(1.f); |
| 1279 | break; |
| 1280 | case 4: |
| 1281 | // Layer should have been updated. |
| 1282 | EXPECT_EQ(2, prepare_called_); |
| 1283 | // So the old mailbox should have been returned already. |
| 1284 | EXPECT_EQ(1, mailbox_returned_); |
| 1285 | texture_layer_->ClearClient(); |
| 1286 | break; |
| 1287 | case 5: |
| 1288 | EXPECT_EQ(2, mailbox_returned_); |
| 1289 | EndTest(); |
| 1290 | break; |
| 1291 | default: |
| 1292 | NOTREACHED(); |
| 1293 | break; |
| 1294 | } |
| 1295 | } |
| 1296 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1297 | void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1298 | ASSERT_TRUE(result); |
| 1299 | DelegatedFrameData* delegated_frame_data = |
| 1300 | output_surface()->last_sent_frame().delegated_frame_data.get(); |
| 1301 | if (!delegated_frame_data) |
| 1302 | return; |
| 1303 | |
| 1304 | // Return all resources immediately. |
| 1305 | TransferableResourceArray resources_to_return = |
| 1306 | output_surface()->resources_held_by_parent(); |
| 1307 | |
| 1308 | CompositorFrameAck ack; |
| 1309 | for (size_t i = 0; i < resources_to_return.size(); ++i) |
| 1310 | output_surface()->ReturnResource(resources_to_return[i].id, &ack); |
[email protected] | a7335e0b | 2013-09-18 09:34:51 | [diff] [blame] | 1311 | host_impl->ReclaimResources(&ack); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1312 | } |
| 1313 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1314 | void AfterTest() override {} |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1315 | |
| 1316 | private: |
| 1317 | scoped_refptr<SolidColorLayer> solid_layer_; |
| 1318 | scoped_refptr<Layer> parent_layer_; |
| 1319 | scoped_refptr<TextureLayer> texture_layer_; |
| 1320 | |
| 1321 | // Used on the main thread. |
| 1322 | bool mailbox_changed_; |
| 1323 | TextureMailbox mailbox_; |
| 1324 | int mailbox_returned_; |
| 1325 | int prepare_called_; |
| 1326 | int commit_count_; |
| 1327 | }; |
| 1328 | |
| 1329 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); |
| 1330 | |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1331 | // Test that TextureLayerImpl::ReleaseResources can be called which releases |
| 1332 | // the mailbox back to TextureLayerClient. |
| 1333 | class TextureLayerReleaseResourcesBase |
| 1334 | : public LayerTreeTest, |
| 1335 | public TextureLayerClient { |
| 1336 | public: |
| 1337 | // TextureLayerClient implementation. |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1338 | bool PrepareTextureMailbox( |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1339 | TextureMailbox* mailbox, |
| 1340 | scoped_ptr<SingleReleaseCallback>* release_callback, |
mostynb | f68776d8 | 2014-10-06 18:07:37 | [diff] [blame] | 1341 | bool use_shared_memory) override { |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 1342 | *mailbox = TextureMailbox(MailboxFromChar('1'), GL_TEXTURE_2D, 0); |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1343 | *release_callback = SingleReleaseCallback::Create( |
| 1344 | base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased, |
| 1345 | base::Unretained(this))); |
| 1346 | return true; |
| 1347 | } |
| 1348 | |
| 1349 | void MailboxReleased(unsigned sync_point, bool lost_resource) { |
| 1350 | mailbox_released_ = true; |
| 1351 | } |
| 1352 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1353 | void SetupTree() override { |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1354 | LayerTreeTest::SetupTree(); |
| 1355 | |
| 1356 | scoped_refptr<TextureLayer> texture_layer = |
| 1357 | TextureLayer::CreateForMailbox(this); |
| 1358 | texture_layer->SetBounds(gfx::Size(10, 10)); |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1359 | texture_layer->SetIsDrawable(true); |
| 1360 | |
| 1361 | layer_tree_host()->root_layer()->AddChild(texture_layer); |
| 1362 | } |
| 1363 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1364 | void BeginTest() override { |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1365 | mailbox_released_ = false; |
| 1366 | PostSetNeedsCommitToMainThread(); |
| 1367 | } |
| 1368 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1369 | void DidCommitAndDrawFrame() override { EndTest(); } |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1370 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1371 | void AfterTest() override { EXPECT_TRUE(mailbox_released_); } |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1372 | |
| 1373 | private: |
| 1374 | bool mailbox_released_; |
| 1375 | }; |
| 1376 | |
| 1377 | class TextureLayerReleaseResourcesAfterCommit |
| 1378 | : public TextureLayerReleaseResourcesBase { |
| 1379 | public: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1380 | void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1381 | LayerTreeImpl* tree = nullptr; |
danakj | 009cdfdf | 2015-02-17 22:35:14 | [diff] [blame] | 1382 | tree = host_impl->sync_tree(); |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1383 | tree->root_layer()->children()[0]->ReleaseResources(); |
| 1384 | } |
| 1385 | }; |
| 1386 | |
| 1387 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit); |
| 1388 | |
| 1389 | class TextureLayerReleaseResourcesAfterActivate |
| 1390 | : public TextureLayerReleaseResourcesBase { |
| 1391 | public: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1392 | void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1393 | host_impl->active_tree()->root_layer()->children()[0]->ReleaseResources(); |
| 1394 | } |
| 1395 | }; |
| 1396 | |
| 1397 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate); |
| 1398 | |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1399 | class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { |
| 1400 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1401 | void ReleaseCallback(uint32 sync_point, bool lost_resource) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1402 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1403 | EXPECT_FALSE(lost_resource); |
| 1404 | ++callback_count_; |
| 1405 | EndTest(); |
| 1406 | } |
| 1407 | |
| 1408 | void SetMailbox(char mailbox_char) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1409 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1410 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1411 | base::Bind( |
| 1412 | &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, |
| 1413 | base::Unretained(this))); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1414 | layer_->SetTextureMailbox( |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 1415 | TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1416 | callback.Pass()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1417 | } |
| 1418 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1419 | void SetupTree() override { |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1420 | gfx::Size bounds(100, 100); |
| 1421 | root_ = Layer::Create(); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1422 | root_->SetBounds(bounds); |
| 1423 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1424 | layer_ = TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1425 | layer_->SetIsDrawable(true); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1426 | layer_->SetBounds(bounds); |
| 1427 | |
| 1428 | root_->AddChild(layer_); |
| 1429 | layer_tree_host()->SetRootLayer(root_); |
| 1430 | layer_tree_host()->SetViewportSize(bounds); |
| 1431 | } |
| 1432 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1433 | void BeginTest() override { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1434 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 1435 | |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1436 | callback_count_ = 0; |
| 1437 | |
| 1438 | // Set the mailbox on the main thread. |
| 1439 | SetMailbox('1'); |
| 1440 | EXPECT_EQ(0, callback_count_); |
| 1441 | |
| 1442 | PostSetNeedsCommitToMainThread(); |
| 1443 | } |
| 1444 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1445 | void DidCommitAndDrawFrame() override { |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1446 | switch (layer_tree_host()->source_frame_number()) { |
| 1447 | case 1: |
| 1448 | // Delete the TextureLayer on the main thread while the mailbox is in |
| 1449 | // the impl tree. |
| 1450 | layer_->RemoveFromParent(); |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1451 | layer_ = nullptr; |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1452 | break; |
| 1453 | } |
| 1454 | } |
| 1455 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1456 | void AfterTest() override { EXPECT_EQ(1, callback_count_); } |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1457 | |
| 1458 | private: |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1459 | base::ThreadChecker main_thread_; |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1460 | int callback_count_; |
| 1461 | scoped_refptr<Layer> root_; |
| 1462 | scoped_refptr<TextureLayer> layer_; |
| 1463 | }; |
| 1464 | |
| 1465 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1466 | TextureLayerWithMailboxMainThreadDeleted); |
| 1467 | |
| 1468 | class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { |
| 1469 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1470 | void ReleaseCallback(uint32 sync_point, bool lost_resource) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1471 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1472 | EXPECT_FALSE(lost_resource); |
| 1473 | ++callback_count_; |
| 1474 | EndTest(); |
| 1475 | } |
| 1476 | |
| 1477 | void SetMailbox(char mailbox_char) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1478 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1479 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1480 | base::Bind( |
| 1481 | &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, |
| 1482 | base::Unretained(this))); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1483 | layer_->SetTextureMailbox( |
[email protected] | e0a4d73 | 2014-02-15 00:23:26 | [diff] [blame] | 1484 | TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1485 | callback.Pass()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1486 | } |
| 1487 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1488 | void SetupTree() override { |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1489 | gfx::Size bounds(100, 100); |
| 1490 | root_ = Layer::Create(); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1491 | root_->SetBounds(bounds); |
| 1492 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1493 | layer_ = TextureLayer::CreateForMailbox(nullptr); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1494 | layer_->SetIsDrawable(true); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1495 | layer_->SetBounds(bounds); |
| 1496 | |
| 1497 | root_->AddChild(layer_); |
| 1498 | layer_tree_host()->SetRootLayer(root_); |
| 1499 | layer_tree_host()->SetViewportSize(bounds); |
| 1500 | } |
| 1501 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1502 | void BeginTest() override { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1503 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 1504 | |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1505 | callback_count_ = 0; |
| 1506 | |
| 1507 | // Set the mailbox on the main thread. |
| 1508 | SetMailbox('1'); |
| 1509 | EXPECT_EQ(0, callback_count_); |
| 1510 | |
| 1511 | PostSetNeedsCommitToMainThread(); |
| 1512 | } |
| 1513 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1514 | void DidCommitAndDrawFrame() override { |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1515 | switch (layer_tree_host()->source_frame_number()) { |
| 1516 | case 1: |
| 1517 | // Remove the TextureLayer on the main thread while the mailbox is in |
| 1518 | // the impl tree, but don't delete the TextureLayer until after the impl |
| 1519 | // tree side is deleted. |
| 1520 | layer_->RemoveFromParent(); |
| 1521 | break; |
| 1522 | case 2: |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1523 | layer_ = nullptr; |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1524 | break; |
| 1525 | } |
| 1526 | } |
| 1527 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 1528 | void AfterTest() override { EXPECT_EQ(1, callback_count_); } |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1529 | |
| 1530 | private: |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 1531 | base::ThreadChecker main_thread_; |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 1532 | int callback_count_; |
| 1533 | scoped_refptr<Layer> root_; |
| 1534 | scoped_refptr<TextureLayer> layer_; |
| 1535 | }; |
| 1536 | |
| 1537 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1538 | TextureLayerWithMailboxImplThreadDeleted); |
| 1539 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 1540 | } // namespace |
| 1541 | } // namespace cc |