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