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