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