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