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