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