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