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