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