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