[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; |
| 40 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 41 | namespace cc { |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 42 | namespace { |
| 43 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 44 | gpu::Mailbox MailboxFromString(const std::string& string) { |
| 45 | gpu::Mailbox mailbox; |
| 46 | mailbox.SetName(reinterpret_cast<const int8*>(string.data())); |
| 47 | return mailbox; |
| 48 | } |
| 49 | |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 50 | class MockLayerTreeHost : public LayerTreeHost { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 51 | public: |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 52 | explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
[email protected] | a7f3568 | 2013-10-22 23:05:57 | [diff] [blame] | 53 | : LayerTreeHost(client, NULL, LayerTreeSettings()) { |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 54 | InitializeSingleThreaded(client); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 55 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 56 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 57 | MOCK_METHOD0(AcquireLayerTextures, void()); |
| 58 | MOCK_METHOD0(SetNeedsCommit, void()); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 59 | MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 60 | MOCK_METHOD0(StartRateLimiter, void()); |
| 61 | MOCK_METHOD0(StopRateLimiter, void()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 62 | }; |
| 63 | |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 64 | class TextureLayerTest : public testing::Test { |
| 65 | public: |
| 66 | TextureLayerTest() |
| 67 | : fake_client_( |
| 68 | FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), |
| 69 | host_impl_(&proxy_) {} |
| 70 | |
| 71 | protected: |
| 72 | virtual void SetUp() { |
| 73 | layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
| 74 | } |
| 75 | |
| 76 | virtual void TearDown() { |
| 77 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 78 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
| 79 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 80 | |
| 81 | layer_tree_host_->SetRootLayer(NULL); |
| 82 | layer_tree_host_.reset(); |
| 83 | } |
| 84 | |
| 85 | scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 86 | FakeImplProxy proxy_; |
| 87 | FakeLayerTreeHostClient fake_client_; |
| 88 | FakeLayerTreeHostImpl host_impl_; |
| 89 | }; |
| 90 | |
| 91 | TEST_F(TextureLayerTest, SyncImplWhenChangingTextureId) { |
| 92 | scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); |
| 93 | ASSERT_TRUE(test_layer.get()); |
| 94 | |
| 95 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
| 96 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 97 | layer_tree_host_->SetRootLayer(test_layer); |
| 98 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 99 | EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); |
| 100 | |
| 101 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 102 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 103 | test_layer->SetTextureId(1); |
| 104 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 105 | |
| 106 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
| 107 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 108 | test_layer->SetTextureId(2); |
| 109 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 110 | |
| 111 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
| 112 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 113 | test_layer->SetTextureId(0); |
| 114 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 115 | } |
| 116 | |
| 117 | TEST_F(TextureLayerTest, SyncImplWhenDrawing) { |
| 118 | gfx::RectF dirty_rect(0.f, 0.f, 1.f, 1.f); |
| 119 | |
| 120 | scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); |
| 121 | ASSERT_TRUE(test_layer.get()); |
| 122 | scoped_ptr<TextureLayerImpl> impl_layer; |
| 123 | impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
| 124 | ASSERT_TRUE(impl_layer); |
| 125 | |
| 126 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
| 127 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 128 | layer_tree_host_->SetRootLayer(test_layer); |
| 129 | test_layer->SetTextureId(1); |
| 130 | test_layer->SetIsDrawable(true); |
| 131 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 132 | EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); |
| 133 | |
| 134 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); |
| 135 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 136 | test_layer->WillModifyTexture(); |
| 137 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 138 | |
| 139 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 140 | EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 141 | test_layer->SetNeedsDisplayRect(dirty_rect); |
| 142 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 143 | |
| 144 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 145 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); |
| 146 | test_layer->PushPropertiesTo(impl_layer.get()); // fake commit |
| 147 | test_layer->SetIsDrawable(false); |
| 148 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 149 | |
| 150 | // Verify that non-drawable layers don't signal the compositor, |
| 151 | // except for the first draw after last commit, which must acquire |
| 152 | // the texture. |
| 153 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); |
| 154 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 155 | test_layer->WillModifyTexture(); |
| 156 | test_layer->SetNeedsDisplayRect(dirty_rect); |
| 157 | test_layer->PushPropertiesTo(impl_layer.get()); // fake commit |
| 158 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 159 | |
| 160 | // Second draw with layer in non-drawable state: no texture |
| 161 | // acquisition. |
| 162 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 163 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 164 | test_layer->WillModifyTexture(); |
| 165 | test_layer->SetNeedsDisplayRect(dirty_rect); |
| 166 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 167 | } |
| 168 | |
| 169 | TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { |
| 170 | scoped_refptr<Layer> root_layer = Layer::Create(); |
| 171 | ASSERT_TRUE(root_layer.get()); |
| 172 | scoped_refptr<Layer> child_layer = Layer::Create(); |
| 173 | ASSERT_TRUE(child_layer.get()); |
| 174 | root_layer->AddChild(child_layer); |
| 175 | scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); |
| 176 | ASSERT_TRUE(test_layer.get()); |
| 177 | test_layer->SetTextureId(0); |
| 178 | child_layer->AddChild(test_layer); |
| 179 | |
| 180 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
| 181 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 182 | layer_tree_host_->SetRootLayer(root_layer); |
| 183 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 184 | |
| 185 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 186 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 187 | test_layer->RemoveFromParent(); |
| 188 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 189 | |
| 190 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 191 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 192 | child_layer->AddChild(test_layer); |
| 193 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 194 | |
| 195 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 196 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 197 | test_layer->SetTextureId(1); |
| 198 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 199 | |
| 200 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
| 201 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 202 | test_layer->RemoveFromParent(); |
| 203 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 204 | } |
| 205 | |
| 206 | TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
| 207 | scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); |
[email protected] | 80d42bd | 2013-08-30 19:13:45 | [diff] [blame] | 208 | EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 209 | |
| 210 | // Test properties that should call SetNeedsCommit. All properties need to |
| 211 | // be set to new values in order for SetNeedsCommit to be called. |
| 212 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); |
| 213 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( |
| 214 | gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); |
| 215 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( |
| 216 | 0.5f, 0.5f, 0.5f, 0.5f)); |
| 217 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); |
| 218 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); |
| 219 | EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1)); |
| 220 | |
| 221 | // Calling SetTextureId can call AcquireLayerTextures. |
| 222 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
| 223 | } |
| 224 | |
[email protected] | 1c10e23 | 2013-07-31 12:35:43 | [diff] [blame] | 225 | TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { |
| 226 | const gfx::Size layer_bounds(100, 100); |
| 227 | const gfx::Rect layer_rect(layer_bounds); |
| 228 | const Region layer_region(layer_rect); |
| 229 | |
| 230 | scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL); |
| 231 | layer->SetBounds(layer_bounds); |
| 232 | layer->draw_properties().visible_content_rect = layer_rect; |
| 233 | layer->SetBlendBackgroundColor(true); |
| 234 | |
| 235 | // Verify initial conditions. |
| 236 | EXPECT_FALSE(layer->contents_opaque()); |
| 237 | EXPECT_EQ(0u, layer->background_color()); |
| 238 | EXPECT_EQ(Region().ToString(), |
| 239 | layer->VisibleContentOpaqueRegion().ToString()); |
| 240 | |
| 241 | // Opaque background. |
| 242 | layer->SetBackgroundColor(SK_ColorWHITE); |
| 243 | EXPECT_EQ(layer_region.ToString(), |
| 244 | layer->VisibleContentOpaqueRegion().ToString()); |
| 245 | |
| 246 | // Transparent background. |
| 247 | layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); |
| 248 | EXPECT_EQ(Region().ToString(), |
| 249 | layer->VisibleContentOpaqueRegion().ToString()); |
| 250 | } |
| 251 | |
[email protected] | 2f52981 | 2013-07-12 01:58:39 | [diff] [blame] | 252 | class FakeTextureLayerClient : public TextureLayerClient { |
| 253 | public: |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 254 | FakeTextureLayerClient() {} |
[email protected] | 2f52981 | 2013-07-12 01:58:39 | [diff] [blame] | 255 | |
| 256 | virtual unsigned PrepareTexture() OVERRIDE { |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 257 | return 0; |
[email protected] | 2f52981 | 2013-07-12 01:58:39 | [diff] [blame] | 258 | } |
| 259 | |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 260 | virtual bool PrepareTextureMailbox( |
| 261 | TextureMailbox* mailbox, |
| 262 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 263 | bool use_shared_memory) OVERRIDE { |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 264 | *mailbox = TextureMailbox(); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 265 | *release_callback = scoped_ptr<SingleReleaseCallback>(); |
[email protected] | 2f52981 | 2013-07-12 01:58:39 | [diff] [blame] | 266 | return true; |
| 267 | } |
| 268 | |
| 269 | private: |
[email protected] | 2f52981 | 2013-07-12 01:58:39 | [diff] [blame] | 270 | DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
| 271 | }; |
| 272 | |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 273 | TEST_F(TextureLayerTest, RateLimiter) { |
| 274 | FakeTextureLayerClient client; |
| 275 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( |
| 276 | &client); |
| 277 | test_layer->SetIsDrawable(true); |
| 278 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 279 | layer_tree_host_->SetRootLayer(test_layer); |
| 280 | |
| 281 | // Don't rate limit until we invalidate. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 282 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 283 | test_layer->SetRateLimitContext(true); |
| 284 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 285 | |
| 286 | // Do rate limit after we invalidate. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 287 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 288 | test_layer->SetNeedsDisplay(); |
| 289 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 290 | |
| 291 | // Stop rate limiter when we don't want it any more. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 292 | EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 293 | test_layer->SetRateLimitContext(false); |
| 294 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 295 | |
| 296 | // Or we clear the client. |
| 297 | test_layer->SetRateLimitContext(true); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 298 | EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 299 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 300 | test_layer->ClearClient(); |
| 301 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 302 | |
| 303 | // Reset to a layer with a client, that started the rate limiter. |
| 304 | test_layer = TextureLayer::CreateForMailbox( |
| 305 | &client); |
| 306 | test_layer->SetIsDrawable(true); |
| 307 | test_layer->SetRateLimitContext(true); |
| 308 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 309 | layer_tree_host_->SetRootLayer(test_layer); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 310 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 311 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 312 | EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 313 | test_layer->SetNeedsDisplay(); |
| 314 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 315 | |
| 316 | // Stop rate limiter when we're removed from the tree. |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 317 | EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
[email protected] | 31d4df8 | 2013-07-18 10:17:22 | [diff] [blame] | 318 | layer_tree_host_->SetRootLayer(NULL); |
| 319 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 320 | } |
| 321 | |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 322 | class MockMailboxCallback { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 323 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 324 | MOCK_METHOD3(Release, |
| 325 | void(const std::string& mailbox, |
| 326 | uint32 sync_point, |
| 327 | bool lost_resource)); |
| 328 | MOCK_METHOD3(Release2, |
| 329 | void(base::SharedMemory* shared_memory, |
| 330 | uint32 sync_point, |
| 331 | bool lost_resource)); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | struct CommonMailboxObjects { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 335 | CommonMailboxObjects() |
| 336 | : mailbox_name1_(64, '1'), |
| 337 | mailbox_name2_(64, '2'), |
| 338 | sync_point1_(1), |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 339 | sync_point2_(2), |
| 340 | shared_memory_(new base::SharedMemory) { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 341 | release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
| 342 | base::Unretained(&mock_callback_), |
| 343 | mailbox_name1_); |
| 344 | release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
| 345 | base::Unretained(&mock_callback_), |
| 346 | mailbox_name2_); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 347 | const uint32 arbitrary_target1 = 1; |
| 348 | const uint32 arbitrary_target2 = 2; |
| 349 | mailbox1_ = TextureMailbox( |
| 350 | MailboxFromString(mailbox_name1_), arbitrary_target1, sync_point1_); |
| 351 | mailbox2_ = TextureMailbox( |
| 352 | MailboxFromString(mailbox_name2_), arbitrary_target2, sync_point2_); |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 353 | gfx::Size size(128, 128); |
| 354 | EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); |
| 355 | release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, |
| 356 | base::Unretained(&mock_callback_), |
| 357 | shared_memory_.get()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 358 | mailbox3_ = TextureMailbox(shared_memory_.get(), size); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 359 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 360 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 361 | std::string mailbox_name1_; |
| 362 | std::string mailbox_name2_; |
| 363 | MockMailboxCallback mock_callback_; |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 364 | ReleaseCallback release_mailbox1_; |
| 365 | ReleaseCallback release_mailbox2_; |
| 366 | ReleaseCallback release_mailbox3_; |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 367 | TextureMailbox mailbox1_; |
| 368 | TextureMailbox mailbox2_; |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 369 | TextureMailbox mailbox3_; |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 370 | uint32 sync_point1_; |
| 371 | uint32 sync_point2_; |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 372 | scoped_ptr<base::SharedMemory> shared_memory_; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 373 | }; |
| 374 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 375 | class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 376 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 377 | using TextureLayer::TextureMailboxHolder::Create; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 378 | |
| 379 | protected: |
| 380 | virtual ~TestMailboxHolder() {} |
| 381 | }; |
| 382 | |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 383 | class TextureLayerWithMailboxTest : public TextureLayerTest { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 384 | protected: |
| 385 | virtual void TearDown() { |
| 386 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 387 | EXPECT_CALL(test_data_.mock_callback_, |
| 388 | Release(test_data_.mailbox_name1_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 389 | test_data_.sync_point1_, |
| 390 | false)).Times(1); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 391 | TextureLayerTest::TearDown(); |
| 392 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 393 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 394 | CommonMailboxObjects test_data_; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 395 | }; |
| 396 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 397 | TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { |
[email protected] | e8e4ae23 | 2013-04-12 00:26:01 | [diff] [blame] | 398 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 399 | ASSERT_TRUE(test_layer.get()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 400 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 401 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 402 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 403 | layer_tree_host_->SetRootLayer(test_layer); |
| 404 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 405 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 406 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 407 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 408 | test_layer->SetTextureMailbox( |
| 409 | test_data_.mailbox1_, |
| 410 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 411 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 412 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 413 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 414 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 415 | EXPECT_CALL(test_data_.mock_callback_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 416 | Release(test_data_.mailbox_name1_, |
| 417 | test_data_.sync_point1_, |
| 418 | false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 419 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 420 | test_layer->SetTextureMailbox( |
| 421 | test_data_.mailbox2_, |
| 422 | SingleReleaseCallback::Create(test_data_.release_mailbox2_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 423 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 424 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 425 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 426 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 427 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 428 | EXPECT_CALL(test_data_.mock_callback_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 429 | Release(test_data_.mailbox_name2_, |
| 430 | test_data_.sync_point2_, |
| 431 | false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 432 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 433 | test_layer->SetTextureMailbox(TextureMailbox(), |
| 434 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 435 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 436 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 437 | |
[email protected] | 80d42bd | 2013-08-30 19:13:45 | [diff] [blame] | 438 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 439 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 440 | test_layer->SetTextureMailbox( |
| 441 | test_data_.mailbox3_, |
| 442 | SingleReleaseCallback::Create(test_data_.release_mailbox3_)); |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 443 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 444 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 445 | |
| 446 | EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 447 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 448 | EXPECT_CALL(test_data_.mock_callback_, |
| 449 | Release2(test_data_.shared_memory_.get(), |
| 450 | 0, false)) |
| 451 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 452 | test_layer->SetTextureMailbox(TextureMailbox(), |
| 453 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 454 | Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 455 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 456 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 457 | // Test destructor. |
| 458 | EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 459 | test_layer->SetTextureMailbox( |
| 460 | test_data_.mailbox1_, |
| 461 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 464 | class TextureLayerMailboxHolderTest : public TextureLayerTest { |
| 465 | public: |
| 466 | TextureLayerMailboxHolderTest() |
| 467 | : main_thread_("MAIN") { |
| 468 | main_thread_.Start(); |
| 469 | } |
| 470 | |
| 471 | void Wait(const base::Thread& thread) { |
| 472 | bool manual_reset = false; |
| 473 | bool initially_signaled = false; |
| 474 | base::WaitableEvent event(manual_reset, initially_signaled); |
| 475 | thread.message_loop()->PostTask( |
| 476 | FROM_HERE, |
| 477 | base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 478 | event.Wait(); |
| 479 | } |
| 480 | |
| 481 | void CreateMainRef() { |
| 482 | main_ref_ = TestMailboxHolder::Create( |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 483 | test_data_.mailbox1_, |
| 484 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)).Pass(); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | void ReleaseMainRef() { |
| 488 | main_ref_.reset(); |
| 489 | } |
| 490 | |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 491 | void CreateImplRef(scoped_ptr<SingleReleaseCallback>* impl_ref) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 492 | *impl_ref = main_ref_->holder()->GetCallbackForImplThread(); |
| 493 | } |
| 494 | |
| 495 | void CapturePostTasksAndWait(base::WaitableEvent* begin_capture, |
| 496 | base::WaitableEvent* wait_for_capture, |
| 497 | base::WaitableEvent* stop_capture) { |
| 498 | begin_capture->Wait(); |
| 499 | BlockingTaskRunner::CapturePostTasks capture; |
| 500 | wait_for_capture->Signal(); |
| 501 | stop_capture->Wait(); |
| 502 | } |
| 503 | |
| 504 | protected: |
| 505 | scoped_ptr<TestMailboxHolder::MainThreadReference> |
| 506 | main_ref_; |
| 507 | base::Thread main_thread_; |
| 508 | CommonMailboxObjects test_data_; |
| 509 | }; |
| 510 | |
| 511 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { |
| 512 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 513 | ASSERT_TRUE(test_layer.get()); |
| 514 | |
| 515 | main_thread_.message_loop()->PostTask( |
| 516 | FROM_HERE, |
| 517 | base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 518 | base::Unretained(this))); |
| 519 | |
| 520 | Wait(main_thread_); |
| 521 | |
| 522 | // The texture layer is attached to compositor1, and passes a reference to its |
| 523 | // impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 524 | scoped_ptr<SingleReleaseCallback> compositor1; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 525 | main_thread_.message_loop()->PostTask( |
| 526 | FROM_HERE, |
| 527 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 528 | base::Unretained(this), |
| 529 | &compositor1)); |
| 530 | |
| 531 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 532 | // reference to its impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 533 | scoped_ptr<SingleReleaseCallback> compositor2; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 534 | main_thread_.message_loop()->PostTask( |
| 535 | FROM_HERE, |
| 536 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 537 | base::Unretained(this), |
| 538 | &compositor2)); |
| 539 | |
| 540 | Wait(main_thread_); |
| 541 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 542 | |
| 543 | // The compositors both destroy their impl trees before the main thread layer |
| 544 | // is destroyed. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 545 | compositor1->Run(100, false); |
| 546 | compositor2->Run(200, false); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 547 | |
| 548 | Wait(main_thread_); |
| 549 | |
| 550 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 551 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 552 | |
| 553 | // The main thread ref is the last one, so the mailbox is released back to the |
| 554 | // embedder, with the last sync point provided by the impl trees. |
| 555 | EXPECT_CALL(test_data_.mock_callback_, |
| 556 | Release(test_data_.mailbox_name1_, 200, false)).Times(1); |
| 557 | |
| 558 | main_thread_.message_loop()->PostTask( |
| 559 | FROM_HERE, |
| 560 | base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 561 | base::Unretained(this))); |
| 562 | Wait(main_thread_); |
| 563 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 564 | } |
| 565 | |
| 566 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) { |
| 567 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 568 | ASSERT_TRUE(test_layer.get()); |
| 569 | |
| 570 | main_thread_.message_loop()->PostTask( |
| 571 | FROM_HERE, |
| 572 | base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 573 | base::Unretained(this))); |
| 574 | |
| 575 | Wait(main_thread_); |
| 576 | |
| 577 | // The texture layer is attached to compositor1, and passes a reference to its |
| 578 | // impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 579 | scoped_ptr<SingleReleaseCallback> compositor1; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 580 | main_thread_.message_loop()->PostTask( |
| 581 | FROM_HERE, |
| 582 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 583 | base::Unretained(this), |
| 584 | &compositor1)); |
| 585 | |
| 586 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 587 | // reference to its impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 588 | scoped_ptr<SingleReleaseCallback> compositor2; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 589 | main_thread_.message_loop()->PostTask( |
| 590 | FROM_HERE, |
| 591 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 592 | base::Unretained(this), |
| 593 | &compositor2)); |
| 594 | |
| 595 | Wait(main_thread_); |
| 596 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 597 | |
| 598 | // One compositor destroys their impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 599 | compositor1->Run(100, false); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 600 | |
| 601 | // Then the main thread reference is destroyed. |
| 602 | main_thread_.message_loop()->PostTask( |
| 603 | FROM_HERE, |
| 604 | base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 605 | base::Unretained(this))); |
| 606 | |
| 607 | Wait(main_thread_); |
| 608 | |
| 609 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 610 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 611 | |
| 612 | // The second impl reference is destroyed last, causing the mailbox to be |
| 613 | // released back to the embedder with the last sync point from the impl tree. |
| 614 | EXPECT_CALL(test_data_.mock_callback_, |
| 615 | Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
| 616 | |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 617 | compositor2->Run(200, true); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 618 | Wait(main_thread_); |
| 619 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 620 | } |
| 621 | |
| 622 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { |
| 623 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 624 | ASSERT_TRUE(test_layer.get()); |
| 625 | |
| 626 | main_thread_.message_loop()->PostTask( |
| 627 | FROM_HERE, |
| 628 | base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 629 | base::Unretained(this))); |
| 630 | |
| 631 | Wait(main_thread_); |
| 632 | |
| 633 | // The texture layer is attached to compositor1, and passes a reference to its |
| 634 | // impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 635 | scoped_ptr<SingleReleaseCallback> compositor1; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 636 | main_thread_.message_loop()->PostTask( |
| 637 | FROM_HERE, |
| 638 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 639 | base::Unretained(this), |
| 640 | &compositor1)); |
| 641 | |
| 642 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 643 | // reference to its impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 644 | scoped_ptr<SingleReleaseCallback> compositor2; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 645 | main_thread_.message_loop()->PostTask( |
| 646 | FROM_HERE, |
| 647 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 648 | base::Unretained(this), |
| 649 | &compositor2)); |
| 650 | |
| 651 | Wait(main_thread_); |
| 652 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 653 | |
| 654 | // The main thread reference is destroyed first. |
| 655 | main_thread_.message_loop()->PostTask( |
| 656 | FROM_HERE, |
| 657 | base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 658 | base::Unretained(this))); |
| 659 | |
| 660 | // One compositor destroys their impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 661 | compositor2->Run(200, false); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 662 | |
| 663 | Wait(main_thread_); |
| 664 | |
| 665 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 666 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 667 | |
| 668 | // The second impl reference is destroyed last, causing the mailbox to be |
| 669 | // released back to the embedder with the last sync point from the impl tree. |
| 670 | EXPECT_CALL(test_data_.mock_callback_, |
| 671 | Release(test_data_.mailbox_name1_, 100, true)).Times(1); |
| 672 | |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 673 | compositor1->Run(100, true); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 674 | Wait(main_thread_); |
| 675 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 676 | } |
| 677 | |
| 678 | TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { |
| 679 | scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 680 | ASSERT_TRUE(test_layer.get()); |
| 681 | |
| 682 | main_thread_.message_loop()->PostTask( |
| 683 | FROM_HERE, |
| 684 | base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 685 | base::Unretained(this))); |
| 686 | |
| 687 | Wait(main_thread_); |
| 688 | |
| 689 | // The texture layer is attached to compositor1, and passes a reference to its |
| 690 | // impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 691 | scoped_ptr<SingleReleaseCallback> compositor1; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 692 | main_thread_.message_loop()->PostTask( |
| 693 | FROM_HERE, |
| 694 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 695 | base::Unretained(this), |
| 696 | &compositor1)); |
| 697 | |
| 698 | // Then the texture layer is removed and attached to compositor2, and passes a |
| 699 | // reference to its impl tree. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 700 | scoped_ptr<SingleReleaseCallback> compositor2; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 701 | main_thread_.message_loop()->PostTask( |
| 702 | FROM_HERE, |
| 703 | base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 704 | base::Unretained(this), |
| 705 | &compositor2)); |
| 706 | |
| 707 | Wait(main_thread_); |
| 708 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 709 | |
| 710 | // The main thread reference is destroyed first. |
| 711 | main_thread_.message_loop()->PostTask( |
| 712 | FROM_HERE, |
| 713 | base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 714 | base::Unretained(this))); |
| 715 | |
| 716 | EXPECT_CALL(test_data_.mock_callback_, |
| 717 | Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
| 718 | |
| 719 | bool manual_reset = false; |
| 720 | bool initially_signaled = false; |
| 721 | base::WaitableEvent begin_capture(manual_reset, initially_signaled); |
| 722 | base::WaitableEvent wait_for_capture(manual_reset, initially_signaled); |
| 723 | base::WaitableEvent stop_capture(manual_reset, initially_signaled); |
| 724 | |
| 725 | // Post a task to start capturing tasks on the main thread. This will block |
| 726 | // the main thread until we signal the |stop_capture| event. |
| 727 | main_thread_.message_loop()->PostTask( |
| 728 | FROM_HERE, |
| 729 | base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait, |
| 730 | base::Unretained(this), |
| 731 | &begin_capture, |
| 732 | &wait_for_capture, |
| 733 | &stop_capture)); |
| 734 | |
| 735 | // Before the main thread capturing starts, one compositor destroys their |
| 736 | // impl reference. Since capturing did not start, this gets post-tasked to |
| 737 | // the main thread. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 738 | compositor1->Run(100, false); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 739 | |
| 740 | // Start capturing on the main thread. |
| 741 | begin_capture.Signal(); |
| 742 | wait_for_capture.Wait(); |
| 743 | |
| 744 | // Meanwhile, the second compositor released its impl reference, but this task |
| 745 | // gets shortcutted directly to the main thread. This means the reference is |
| 746 | // released before compositor1, whose reference will be released later when |
| 747 | // the post-task is serviced. But since it was destroyed _on the impl thread_ |
| 748 | // last, its sync point values should be used. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 749 | compositor2->Run(200, true); |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 750 | |
| 751 | stop_capture.Signal(); |
| 752 | Wait(main_thread_); |
| 753 | |
| 754 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 755 | } |
| 756 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 757 | class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 758 | public: |
| 759 | TextureLayerImplWithMailboxThreadedCallback() |
| 760 | : callback_count_(0), |
| 761 | commit_count_(0) {} |
| 762 | |
| 763 | // 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] | 764 | void ReleaseCallback(uint32 sync_point, bool lost_resource) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 765 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 766 | EXPECT_FALSE(lost_resource); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 767 | ++callback_count_; |
| 768 | } |
| 769 | |
| 770 | void SetMailbox(char mailbox_char) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 771 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 772 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 773 | base::Bind( |
| 774 | &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
| 775 | base::Unretained(this))); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 776 | layer_->SetTextureMailbox( |
| 777 | TextureMailbox( |
| 778 | MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 779 | callback.Pass()); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 780 | } |
| 781 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 782 | virtual void BeginTest() OVERRIDE { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 783 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 784 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 785 | gfx::Size bounds(100, 100); |
| 786 | root_ = Layer::Create(); |
| 787 | root_->SetAnchorPoint(gfx::PointF()); |
| 788 | root_->SetBounds(bounds); |
| 789 | |
[email protected] | e8e4ae23 | 2013-04-12 00:26:01 | [diff] [blame] | 790 | layer_ = TextureLayer::CreateForMailbox(NULL); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 791 | layer_->SetIsDrawable(true); |
| 792 | layer_->SetAnchorPoint(gfx::PointF()); |
| 793 | layer_->SetBounds(bounds); |
| 794 | |
| 795 | root_->AddChild(layer_); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 796 | layer_tree_host()->SetRootLayer(root_); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 797 | layer_tree_host()->SetViewportSize(bounds); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 798 | SetMailbox('1'); |
| 799 | EXPECT_EQ(0, callback_count_); |
| 800 | |
| 801 | // Case #1: change mailbox before the commit. The old mailbox should be |
| 802 | // released immediately. |
| 803 | SetMailbox('2'); |
| 804 | EXPECT_EQ(1, callback_count_); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 805 | PostSetNeedsCommitToMainThread(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 806 | } |
| 807 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 808 | virtual void DidCommit() OVERRIDE { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 809 | ++commit_count_; |
| 810 | switch (commit_count_) { |
| 811 | case 1: |
| 812 | // Case #2: change mailbox after the commit (and draw), where the |
| 813 | // layer draws. The old mailbox should be released during the next |
| 814 | // commit. |
| 815 | SetMailbox('3'); |
| 816 | EXPECT_EQ(1, callback_count_); |
| 817 | break; |
| 818 | case 2: |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 819 | EXPECT_EQ(2, callback_count_); |
| 820 | // Case #3: change mailbox when the layer doesn't draw. The old |
| 821 | // mailbox should be released during the next commit. |
| 822 | layer_->SetBounds(gfx::Size()); |
| 823 | SetMailbox('4'); |
| 824 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 825 | case 3: |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 826 | EXPECT_EQ(3, callback_count_); |
| 827 | // Case #4: release mailbox that was committed but never drawn. The |
| 828 | // old mailbox should be released during the next commit. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 829 | layer_->SetTextureMailbox(TextureMailbox(), |
| 830 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 831 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 832 | case 4: |
| 833 | if (layer_tree_host()->settings().impl_side_painting) { |
| 834 | // With impl painting, the texture mailbox will still be on the impl |
| 835 | // thread when the commit finishes, because the layer is not drawble |
| 836 | // when it has no texture mailbox, and thus does not block the commit |
| 837 | // on activation. So, we wait for activation. |
| 838 | // TODO(danakj): fix this. crbug.com/277953 |
| 839 | layer_tree_host()->SetNeedsCommit(); |
| 840 | break; |
| 841 | } else { |
| 842 | ++commit_count_; |
| 843 | } |
| 844 | case 5: |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 845 | EXPECT_EQ(4, callback_count_); |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 846 | // Restore a mailbox for the next step. |
| 847 | SetMailbox('5'); |
| 848 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 849 | case 6: |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 850 | // Case #5: remove layer from tree. Callback should *not* be called, the |
| 851 | // mailbox is returned to the main thread. |
| 852 | EXPECT_EQ(4, callback_count_); |
| 853 | layer_->RemoveFromParent(); |
| 854 | break; |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 855 | case 7: |
| 856 | if (layer_tree_host()->settings().impl_side_painting) { |
| 857 | // With impl painting, the texture mailbox will still be on the impl |
| 858 | // thread when the commit finishes, because the layer is not around to |
| 859 | // block the commit on activation anymore. So, we wait for activation. |
| 860 | // TODO(danakj): fix this. crbug.com/277953 |
| 861 | layer_tree_host()->SetNeedsCommit(); |
| 862 | break; |
| 863 | } else { |
| 864 | ++commit_count_; |
| 865 | } |
| 866 | case 8: |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 867 | EXPECT_EQ(4, callback_count_); |
| 868 | // Resetting the mailbox will call the callback now. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 869 | layer_->SetTextureMailbox(TextureMailbox(), |
| 870 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | 7096acc | 2013-06-18 21:12:43 | [diff] [blame] | 871 | EXPECT_EQ(5, callback_count_); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 872 | EndTest(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 873 | break; |
| 874 | default: |
| 875 | NOTREACHED(); |
| 876 | break; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 877 | } |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 878 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 879 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 880 | virtual void AfterTest() OVERRIDE {} |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 881 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 882 | private: |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 883 | base::ThreadChecker main_thread_; |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 884 | int callback_count_; |
| 885 | int commit_count_; |
| 886 | scoped_refptr<Layer> root_; |
| 887 | scoped_refptr<TextureLayer> layer_; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 888 | }; |
| 889 | |
[email protected] | 4145d17 | 2013-05-10 16:54:36 | [diff] [blame] | 890 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 891 | TextureLayerImplWithMailboxThreadedCallback); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 892 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 893 | |
| 894 | class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, |
| 895 | public TextureLayerClient { |
| 896 | protected: |
| 897 | TextureLayerNoMailboxIsActivatedDuringCommit() |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 898 | : texture_(0u), activate_count_(0) {} |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 899 | |
| 900 | virtual void BeginTest() OVERRIDE { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 901 | gfx::Size bounds(100, 100); |
| 902 | root_ = Layer::Create(); |
| 903 | root_->SetAnchorPoint(gfx::PointF()); |
| 904 | root_->SetBounds(bounds); |
| 905 | |
| 906 | layer_ = TextureLayer::Create(this); |
| 907 | layer_->SetIsDrawable(true); |
| 908 | layer_->SetAnchorPoint(gfx::PointF()); |
| 909 | layer_->SetBounds(bounds); |
| 910 | |
| 911 | root_->AddChild(layer_); |
| 912 | layer_tree_host()->SetRootLayer(root_); |
| 913 | layer_tree_host()->SetViewportSize(bounds); |
| 914 | |
| 915 | PostSetNeedsCommitToMainThread(); |
| 916 | } |
| 917 | |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 918 | virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 919 | OVERRIDE { |
| 920 | scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 921 | texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 922 | return FakeOutputSurface::Create3d(provider); |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 923 | } |
| 924 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 925 | // TextureLayerClient implementation. |
| 926 | virtual unsigned PrepareTexture() OVERRIDE { |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 927 | return texture_; |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 928 | } |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 929 | virtual bool PrepareTextureMailbox( |
| 930 | TextureMailbox* mailbox, |
| 931 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 932 | bool use_shared_memory) OVERRIDE { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 933 | return false; |
| 934 | } |
| 935 | |
| 936 | virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 937 | ++activate_count_; |
| 938 | } |
| 939 | |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 940 | virtual void DidCommit() OVERRIDE { |
| 941 | switch (layer_tree_host()->source_frame_number()) { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 942 | case 1: |
| 943 | // The first texture has been activated. Invalidate the layer so it |
| 944 | // grabs a new texture id from the client. |
| 945 | layer_->SetNeedsDisplay(); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 946 | break; |
| 947 | case 2: |
| 948 | // The second mailbox has been activated. Remove the layer from |
| 949 | // the tree to cause another commit/activation. The commit should |
| 950 | // finish *after* the layer is removed from the active tree. |
| 951 | layer_->RemoveFromParent(); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 952 | break; |
| 953 | case 3: |
| 954 | EndTest(); |
| 955 | break; |
| 956 | } |
| 957 | } |
| 958 | |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 959 | virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 960 | switch (host_impl->active_tree()->source_frame_number()) { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 961 | case 2: { |
| 962 | // The activate for the 2nd texture should have happened before now. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 963 | EXPECT_EQ(2, activate_count_); |
| 964 | break; |
| 965 | } |
| 966 | case 3: { |
| 967 | // The activate to remove the layer should have happened before now. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 968 | EXPECT_EQ(3, activate_count_); |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 974 | virtual void AfterTest() OVERRIDE {} |
| 975 | |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 976 | unsigned texture_; |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 977 | int activate_count_; |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 978 | scoped_refptr<Layer> root_; |
| 979 | scoped_refptr<TextureLayer> layer_; |
| 980 | }; |
| 981 | |
| 982 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 983 | TextureLayerNoMailboxIsActivatedDuringCommit); |
| 984 | |
| 985 | class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
| 986 | protected: |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 987 | TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 988 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 989 | static void ReleaseCallback(uint32 sync_point, bool lost_resource) {} |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 990 | |
| 991 | void SetMailbox(char mailbox_char) { |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 992 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 993 | base::Bind( |
| 994 | &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 995 | layer_->SetTextureMailbox( |
| 996 | TextureMailbox( |
| 997 | MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 998 | callback.Pass()); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | virtual void BeginTest() OVERRIDE { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1002 | gfx::Size bounds(100, 100); |
| 1003 | root_ = Layer::Create(); |
| 1004 | root_->SetAnchorPoint(gfx::PointF()); |
| 1005 | root_->SetBounds(bounds); |
| 1006 | |
| 1007 | layer_ = TextureLayer::CreateForMailbox(NULL); |
| 1008 | layer_->SetIsDrawable(true); |
| 1009 | layer_->SetAnchorPoint(gfx::PointF()); |
| 1010 | layer_->SetBounds(bounds); |
| 1011 | |
| 1012 | root_->AddChild(layer_); |
| 1013 | layer_tree_host()->SetRootLayer(root_); |
| 1014 | layer_tree_host()->SetViewportSize(bounds); |
| 1015 | SetMailbox('1'); |
| 1016 | |
| 1017 | PostSetNeedsCommitToMainThread(); |
| 1018 | } |
| 1019 | |
| 1020 | virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1021 | ++activate_count_; |
| 1022 | } |
| 1023 | |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 1024 | virtual void DidCommit() OVERRIDE { |
| 1025 | switch (layer_tree_host()->source_frame_number()) { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1026 | case 1: |
| 1027 | // The first mailbox has been activated. Set a new mailbox, and |
| 1028 | // expect the next commit to finish *after* it is activated. |
| 1029 | SetMailbox('2'); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1030 | break; |
| 1031 | case 2: |
| 1032 | // The second mailbox has been activated. Remove the layer from |
| 1033 | // the tree to cause another commit/activation. The commit should |
| 1034 | // finish *after* the layer is removed from the active tree. |
| 1035 | layer_->RemoveFromParent(); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1036 | break; |
| 1037 | case 3: |
| 1038 | EndTest(); |
| 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | |
[email protected] | 98ea818e | 2014-01-24 10:22:08 | [diff] [blame] | 1043 | virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1044 | switch (host_impl->active_tree()->source_frame_number()) { |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1045 | case 2: { |
| 1046 | // The activate for the 2nd mailbox should have happened before now. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1047 | EXPECT_EQ(2, activate_count_); |
| 1048 | break; |
| 1049 | } |
| 1050 | case 3: { |
| 1051 | // The activate to remove the layer should have happened before now. |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1052 | EXPECT_EQ(3, activate_count_); |
| 1053 | break; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | virtual void AfterTest() OVERRIDE {} |
| 1060 | |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 1061 | int activate_count_; |
| 1062 | scoped_refptr<Layer> root_; |
| 1063 | scoped_refptr<TextureLayer> layer_; |
| 1064 | }; |
| 1065 | |
| 1066 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1067 | TextureLayerMailboxIsActivatedDuringCommit); |
| 1068 | |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1069 | class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1070 | protected: |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 1071 | TextureLayerImplWithMailboxTest() |
| 1072 | : fake_client_( |
| 1073 | FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {} |
| 1074 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1075 | virtual void SetUp() { |
| 1076 | TextureLayerTest::SetUp(); |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 1077 | layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1078 | EXPECT_TRUE(host_impl_.InitializeRenderer( |
| 1079 | FakeOutputSurface::Create3d().PassAs<OutputSurface>())); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1080 | } |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1081 | |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1082 | bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { |
| 1083 | bool will_draw = layer->WillDraw( |
| 1084 | mode, host_impl_.active_tree()->resource_provider()); |
| 1085 | if (will_draw) |
| 1086 | layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
| 1087 | return will_draw; |
| 1088 | } |
| 1089 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1090 | CommonMailboxObjects test_data_; |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 1091 | FakeLayerTreeHostClient fake_client_; |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1092 | }; |
| 1093 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1094 | // Test conditions for results of TextureLayerImpl::WillDraw under |
| 1095 | // different configurations of different mailbox, texture_id, and draw_mode. |
| 1096 | TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1097 | EXPECT_CALL(test_data_.mock_callback_, |
| 1098 | Release(test_data_.mailbox_name1_, |
| 1099 | test_data_.sync_point1_, |
| 1100 | false)) |
| 1101 | .Times(AnyNumber()); |
| 1102 | EXPECT_CALL(test_data_.mock_callback_, |
| 1103 | Release2(test_data_.shared_memory_.get(), 0, false)) |
| 1104 | .Times(AnyNumber()); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1105 | // Hardware mode. |
| 1106 | { |
| 1107 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1108 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1109 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1110 | impl_layer->SetTextureMailbox( |
| 1111 | test_data_.mailbox1_, |
| 1112 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1113 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | { |
| 1117 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1118 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1119 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1120 | impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1121 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1122 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
| 1123 | } |
| 1124 | |
| 1125 | { |
| 1126 | // Software resource. |
| 1127 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1128 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1129 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1130 | impl_layer->SetTextureMailbox( |
| 1131 | test_data_.mailbox3_, |
| 1132 | SingleReleaseCallback::Create(test_data_.release_mailbox3_)); |
[email protected] | 3e44d7a | 2013-07-30 00:03:10 | [diff] [blame] | 1133 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | { |
| 1137 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1138 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1139 | impl_layer->SetDrawsContent(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1140 | ContextProvider* context_provider = |
| 1141 | host_impl_.output_surface()->context_provider(); |
[email protected] | 1dff796 | 2014-01-10 12:05:03 | [diff] [blame] | 1142 | GLuint texture = 0; |
| 1143 | context_provider->ContextGL()->GenTextures(1, &texture); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1144 | impl_layer->SetTextureId(texture); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1145 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | { |
| 1149 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1150 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1151 | impl_layer->SetDrawsContent(true); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1152 | impl_layer->SetTextureId(0); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1153 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
| 1154 | } |
| 1155 | |
| 1156 | // Software mode. |
| 1157 | { |
| 1158 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1159 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1160 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1161 | impl_layer->SetTextureMailbox( |
| 1162 | test_data_.mailbox1_, |
| 1163 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1164 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 1165 | } |
| 1166 | |
| 1167 | { |
| 1168 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1169 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1170 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1171 | impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1172 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1173 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 1174 | } |
| 1175 | |
| 1176 | { |
| 1177 | // Software resource. |
| 1178 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1179 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1180 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1181 | impl_layer->SetTextureMailbox( |
| 1182 | test_data_.mailbox3_, |
| 1183 | SingleReleaseCallback::Create(test_data_.release_mailbox3_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1184 | EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 1185 | } |
| 1186 | |
| 1187 | { |
| 1188 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1189 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1190 | impl_layer->SetDrawsContent(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1191 | ContextProvider* context_provider = |
| 1192 | host_impl_.output_surface()->context_provider(); |
[email protected] | 1dff796 | 2014-01-10 12:05:03 | [diff] [blame] | 1193 | GLuint texture = 0; |
| 1194 | context_provider->ContextGL()->GenTextures(1, &texture); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1195 | impl_layer->SetTextureId(texture); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1196 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 1197 | } |
| 1198 | |
| 1199 | { |
| 1200 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1201 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1202 | impl_layer->SetDrawsContent(true); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1203 | impl_layer->SetTextureId(0); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1204 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | // Resourceless software mode. |
| 1208 | { |
| 1209 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1210 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1211 | impl_layer->SetDrawsContent(true); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1212 | impl_layer->SetTextureMailbox( |
| 1213 | test_data_.mailbox1_, |
| 1214 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1215 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | { |
| 1219 | scoped_ptr<TextureLayerImpl> impl_layer = |
| 1220 | TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1221 | impl_layer->SetDrawsContent(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1222 | ContextProvider* context_provider = |
| 1223 | host_impl_.output_surface()->context_provider(); |
[email protected] | 1dff796 | 2014-01-10 12:05:03 | [diff] [blame] | 1224 | GLuint texture = 0; |
| 1225 | context_provider->ContextGL()->GenTextures(1, &texture); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1226 | impl_layer->SetTextureId(texture); |
[email protected] | 0ec335c4 | 2013-07-04 06:17:08 | [diff] [blame] | 1227 | EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1231 | TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { |
| 1232 | host_impl_.CreatePendingTree(); |
| 1233 | scoped_ptr<TextureLayerImpl> pending_layer; |
| 1234 | pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1, true); |
| 1235 | ASSERT_TRUE(pending_layer); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1236 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1237 | scoped_ptr<LayerImpl> active_layer( |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1238 | pending_layer->CreateLayerImpl(host_impl_.active_tree())); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1239 | ASSERT_TRUE(active_layer); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1240 | |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1241 | pending_layer->SetTextureMailbox( |
| 1242 | test_data_.mailbox1_, |
| 1243 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1244 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1245 | // Test multiple commits without an activation. |
| 1246 | EXPECT_CALL(test_data_.mock_callback_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1247 | Release(test_data_.mailbox_name1_, |
| 1248 | test_data_.sync_point1_, |
| 1249 | false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1250 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1251 | pending_layer->SetTextureMailbox( |
| 1252 | test_data_.mailbox2_, |
| 1253 | SingleReleaseCallback::Create(test_data_.release_mailbox2_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1254 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1255 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1256 | // Test callback after activation. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1257 | pending_layer->PushPropertiesTo(active_layer.get()); |
| 1258 | active_layer->DidBecomeActive(); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1259 | |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1260 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1261 | pending_layer->SetTextureMailbox( |
| 1262 | test_data_.mailbox1_, |
| 1263 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1264 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | 421e84f | 2013-02-22 03:27:15 | [diff] [blame] | 1265 | |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1266 | EXPECT_CALL(test_data_.mock_callback_, |
| 1267 | Release(test_data_.mailbox_name2_, _, false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1268 | .Times(1); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1269 | pending_layer->PushPropertiesTo(active_layer.get()); |
| 1270 | active_layer->DidBecomeActive(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1271 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1272 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1273 | // Test resetting the mailbox. |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1274 | EXPECT_CALL(test_data_.mock_callback_, |
| 1275 | Release(test_data_.mailbox_name1_, _, false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1276 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1277 | pending_layer->SetTextureMailbox(TextureMailbox(), |
| 1278 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1279 | pending_layer->PushPropertiesTo(active_layer.get()); |
| 1280 | active_layer->DidBecomeActive(); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1281 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1282 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1283 | // Test destructor. |
| 1284 | EXPECT_CALL(test_data_.mock_callback_, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1285 | Release(test_data_.mailbox_name1_, |
| 1286 | test_data_.sync_point1_, |
| 1287 | false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1288 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1289 | pending_layer->SetTextureMailbox( |
| 1290 | test_data_.mailbox1_, |
| 1291 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1292 | } |
| 1293 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1294 | TEST_F(TextureLayerImplWithMailboxTest, |
| 1295 | TestDestructorCallbackOnCreatedResource) { |
| 1296 | scoped_ptr<TextureLayerImpl> impl_layer; |
| 1297 | impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
| 1298 | ASSERT_TRUE(impl_layer); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1299 | |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1300 | EXPECT_CALL(test_data_.mock_callback_, |
| 1301 | Release(test_data_.mailbox_name1_, _, false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1302 | .Times(1); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1303 | impl_layer->SetTextureMailbox( |
| 1304 | test_data_.mailbox1_, |
| 1305 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 1306 | impl_layer->SetDrawsContent(true); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 1307 | impl_layer->DidBecomeActive(); |
| 1308 | EXPECT_TRUE(impl_layer->WillDraw( |
| 1309 | DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider())); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1310 | impl_layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1311 | impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1312 | scoped_ptr<SingleReleaseCallback>()); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1313 | } |
| 1314 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1315 | TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) { |
| 1316 | ResourceProvider* provider = host_impl_.active_tree()->resource_provider(); |
| 1317 | ResourceProvider::ResourceId id = |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1318 | provider->CreateResourceFromTextureMailbox( |
| 1319 | test_data_.mailbox1_, |
| 1320 | SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1321 | provider->AllocateForTesting(id); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1322 | |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1323 | // Transfer some resources to the parent. |
| 1324 | ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1325 | resource_ids_to_transfer.push_back(id); |
| 1326 | TransferableResourceArray list; |
| 1327 | provider->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1328 | EXPECT_TRUE(provider->InUseByConsumer(id)); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1329 | EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1330 | provider->DeleteResource(id); |
| 1331 | Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1332 | EXPECT_CALL(test_data_.mock_callback_, |
| 1333 | Release(test_data_.mailbox_name1_, _, false)) |
[email protected] | 28571b04 | 2013-03-14 07:59:15 | [diff] [blame] | 1334 | .Times(1); |
[email protected] | e00bab02 | 2013-08-19 00:42:45 | [diff] [blame] | 1335 | ReturnedResourceArray returned; |
| 1336 | TransferableResource::ReturnResources(list, &returned); |
| 1337 | provider->ReceiveReturnsFromParent(returned); |
[email protected] | de44a15 | 2013-01-08 15:28:46 | [diff] [blame] | 1338 | } |
| 1339 | |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1340 | // Check that ClearClient correctly clears the state so that the impl side |
| 1341 | // doesn't try to use a texture that could have been destroyed. |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1342 | class TextureLayerClientTest |
| 1343 | : public LayerTreeTest, |
| 1344 | public TextureLayerClient { |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1345 | public: |
| 1346 | TextureLayerClientTest() |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1347 | : texture_(0), |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1348 | commit_count_(0), |
| 1349 | expected_used_textures_on_draw_(0), |
| 1350 | expected_used_textures_on_commit_(0) {} |
| 1351 | |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1352 | virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 1353 | OVERRIDE { |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1354 | scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 1355 | texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1356 | return FakeOutputSurface::Create3d(provider); |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1357 | } |
| 1358 | |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1359 | virtual unsigned PrepareTexture() OVERRIDE { return texture_; } |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1360 | |
[email protected] | 2541d1a | 2013-07-10 07:33:27 | [diff] [blame] | 1361 | virtual bool PrepareTextureMailbox( |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1362 | TextureMailbox* mailbox, |
| 1363 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1364 | bool use_shared_memory) OVERRIDE { |
[email protected] | e8e4ae23 | 2013-04-12 00:26:01 | [diff] [blame] | 1365 | return false; |
| 1366 | } |
| 1367 | |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1368 | virtual void SetupTree() OVERRIDE { |
| 1369 | scoped_refptr<Layer> root = Layer::Create(); |
| 1370 | root->SetBounds(gfx::Size(10, 10)); |
| 1371 | root->SetAnchorPoint(gfx::PointF()); |
| 1372 | root->SetIsDrawable(true); |
| 1373 | |
| 1374 | texture_layer_ = TextureLayer::Create(this); |
| 1375 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
| 1376 | texture_layer_->SetAnchorPoint(gfx::PointF()); |
| 1377 | texture_layer_->SetIsDrawable(true); |
| 1378 | root->AddChild(texture_layer_); |
| 1379 | |
| 1380 | layer_tree_host()->SetRootLayer(root); |
| 1381 | LayerTreeTest::SetupTree(); |
| 1382 | { |
| 1383 | base::AutoLock lock(lock_); |
| 1384 | expected_used_textures_on_commit_ = 1; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | virtual void BeginTest() OVERRIDE { |
| 1389 | PostSetNeedsCommitToMainThread(); |
| 1390 | } |
| 1391 | |
| 1392 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1393 | ++commit_count_; |
| 1394 | switch (commit_count_) { |
| 1395 | case 1: |
| 1396 | texture_layer_->ClearClient(); |
| 1397 | texture_layer_->SetNeedsDisplay(); |
| 1398 | { |
| 1399 | base::AutoLock lock(lock_); |
| 1400 | expected_used_textures_on_commit_ = 0; |
| 1401 | } |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1402 | break; |
| 1403 | case 2: |
| 1404 | EndTest(); |
| 1405 | break; |
| 1406 | default: |
| 1407 | NOTREACHED(); |
| 1408 | break; |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1413 | base::AutoLock lock(lock_); |
| 1414 | expected_used_textures_on_draw_ = expected_used_textures_on_commit_; |
| 1415 | } |
| 1416 | |
[email protected] | 7ddfe7e8 | 2014-01-30 07:22:11 | [diff] [blame] | 1417 | virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
| 1418 | LayerTreeHostImpl* host_impl, |
| 1419 | LayerTreeHostImpl::FrameData* frame_data, |
| 1420 | DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1421 | ContextForImplThread(host_impl)->ResetUsedTextures(); |
[email protected] | 7ddfe7e8 | 2014-01-30 07:22:11 | [diff] [blame] | 1422 | return DrawSwapReadbackResult::DRAW_SUCCESS; |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1426 | bool result) OVERRIDE { |
| 1427 | ASSERT_TRUE(result); |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1428 | EXPECT_EQ(expected_used_textures_on_draw_, |
| 1429 | ContextForImplThread(host_impl)->NumUsedTextures()); |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | virtual void AfterTest() OVERRIDE {} |
| 1433 | |
| 1434 | private: |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1435 | TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { |
[email protected] | 1dff796 | 2014-01-10 12:05:03 | [diff] [blame] | 1436 | return static_cast<TestContextProvider*>( |
| 1437 | host_impl->output_surface()->context_provider().get())->TestContext3d(); |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1438 | } |
| 1439 | |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1440 | scoped_refptr<TextureLayer> texture_layer_; |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1441 | unsigned texture_; |
| 1442 | int commit_count_; |
| 1443 | |
| 1444 | // Used only on thread. |
| 1445 | unsigned expected_used_textures_on_draw_; |
| 1446 | |
| 1447 | // Used on either thread, protected by lock_. |
| 1448 | base::Lock lock_; |
| 1449 | unsigned expected_used_textures_on_commit_; |
| 1450 | }; |
| 1451 | |
[email protected] | 4145d17 | 2013-05-10 16:54:36 | [diff] [blame] | 1452 | // The TextureLayerClient does not use mailboxes, so can't use a delegating |
| 1453 | // renderer. |
| 1454 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); |
[email protected] | 97d519fb | 2013-03-29 02:27:54 | [diff] [blame] | 1455 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1456 | |
| 1457 | // Checks that changing a texture in the client for a TextureLayer that's |
| 1458 | // invisible correctly works without drawing a deleted texture. See |
| 1459 | // crbug.com/266628 |
| 1460 | class TextureLayerChangeInvisibleTest |
| 1461 | : public LayerTreeTest, |
| 1462 | public TextureLayerClient { |
| 1463 | public: |
| 1464 | TextureLayerChangeInvisibleTest() |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1465 | : texture_(0u), |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1466 | prepare_called_(0), |
| 1467 | commit_count_(0), |
| 1468 | expected_texture_on_draw_(0) {} |
| 1469 | |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1470 | virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1471 | OVERRIDE { |
| 1472 | scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 1473 | texture_ = provider->UnboundTestContext3d()->createExternalTexture(); |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1474 | return FakeOutputSurface::Create3d(provider); |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1475 | } |
| 1476 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1477 | // TextureLayerClient implementation. |
| 1478 | virtual unsigned PrepareTexture() OVERRIDE { |
| 1479 | ++prepare_called_; |
| 1480 | return texture_; |
| 1481 | } |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1482 | virtual bool PrepareTextureMailbox( |
[email protected] | e51444a | 2013-12-10 23:05:01 | [diff] [blame] | 1483 | TextureMailbox* mailbox, |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1484 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1485 | bool use_shared_memory) OVERRIDE { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1486 | return false; |
| 1487 | } |
| 1488 | |
| 1489 | virtual void SetupTree() OVERRIDE { |
| 1490 | scoped_refptr<Layer> root = Layer::Create(); |
| 1491 | root->SetBounds(gfx::Size(10, 10)); |
| 1492 | root->SetAnchorPoint(gfx::PointF()); |
| 1493 | root->SetIsDrawable(true); |
| 1494 | |
| 1495 | solid_layer_ = SolidColorLayer::Create(); |
| 1496 | solid_layer_->SetBounds(gfx::Size(10, 10)); |
| 1497 | solid_layer_->SetIsDrawable(true); |
| 1498 | solid_layer_->SetBackgroundColor(SK_ColorWHITE); |
| 1499 | root->AddChild(solid_layer_); |
| 1500 | |
| 1501 | parent_layer_ = Layer::Create(); |
| 1502 | parent_layer_->SetBounds(gfx::Size(10, 10)); |
| 1503 | parent_layer_->SetIsDrawable(true); |
| 1504 | root->AddChild(parent_layer_); |
| 1505 | |
| 1506 | texture_layer_ = TextureLayer::Create(this); |
| 1507 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
| 1508 | texture_layer_->SetAnchorPoint(gfx::PointF()); |
| 1509 | texture_layer_->SetIsDrawable(true); |
| 1510 | parent_layer_->AddChild(texture_layer_); |
| 1511 | |
| 1512 | layer_tree_host()->SetRootLayer(root); |
| 1513 | LayerTreeTest::SetupTree(); |
| 1514 | } |
| 1515 | |
| 1516 | virtual void BeginTest() OVERRIDE { |
| 1517 | PostSetNeedsCommitToMainThread(); |
| 1518 | } |
| 1519 | |
| 1520 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1521 | ++commit_count_; |
| 1522 | switch (commit_count_) { |
| 1523 | case 1: |
| 1524 | // We should have updated the layer, committing the texture. |
| 1525 | EXPECT_EQ(1, prepare_called_); |
| 1526 | // Make layer invisible. |
| 1527 | parent_layer_->SetOpacity(0.f); |
| 1528 | break; |
| 1529 | case 2: { |
| 1530 | // Layer shouldn't have been updated. |
| 1531 | EXPECT_EQ(1, prepare_called_); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1532 | texture_layer_->SetNeedsDisplay(); |
| 1533 | // Force a change to make sure we draw a frame. |
| 1534 | solid_layer_->SetBackgroundColor(SK_ColorGRAY); |
| 1535 | break; |
| 1536 | } |
| 1537 | case 3: |
| 1538 | EXPECT_EQ(1, prepare_called_); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1539 | // Make layer visible again. |
| 1540 | parent_layer_->SetOpacity(1.f); |
| 1541 | break; |
| 1542 | case 4: { |
| 1543 | // Layer should have been updated. |
| 1544 | EXPECT_EQ(2, prepare_called_); |
| 1545 | texture_layer_->ClearClient(); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1546 | texture_ = 0; |
| 1547 | break; |
| 1548 | } |
| 1549 | case 5: |
| 1550 | EndTest(); |
| 1551 | break; |
| 1552 | default: |
| 1553 | NOTREACHED(); |
| 1554 | break; |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1559 | ASSERT_TRUE(proxy()->IsMainThreadBlocked()); |
| 1560 | // This is the only texture that can be drawn this frame. |
| 1561 | expected_texture_on_draw_ = texture_; |
| 1562 | } |
| 1563 | |
[email protected] | 7ddfe7e8 | 2014-01-30 07:22:11 | [diff] [blame] | 1564 | virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
| 1565 | LayerTreeHostImpl* host_impl, |
| 1566 | LayerTreeHostImpl::FrameData* frame_data, |
| 1567 | DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1568 | ContextForImplThread(host_impl)->ResetUsedTextures(); |
[email protected] | 7ddfe7e8 | 2014-01-30 07:22:11 | [diff] [blame] | 1569 | return DrawSwapReadbackResult::DRAW_SUCCESS; |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1573 | bool result) OVERRIDE { |
| 1574 | ASSERT_TRUE(result); |
| 1575 | TestWebGraphicsContext3D* context = ContextForImplThread(host_impl); |
| 1576 | int used_textures = context->NumUsedTextures(); |
| 1577 | switch (host_impl->active_tree()->source_frame_number()) { |
| 1578 | case 0: |
| 1579 | EXPECT_EQ(1, used_textures); |
| 1580 | EXPECT_TRUE(context->UsedTexture(expected_texture_on_draw_)); |
| 1581 | break; |
| 1582 | case 1: |
| 1583 | case 2: |
| 1584 | EXPECT_EQ(0, used_textures); |
| 1585 | break; |
| 1586 | case 3: |
| 1587 | EXPECT_EQ(1, used_textures); |
| 1588 | EXPECT_TRUE(context->UsedTexture(expected_texture_on_draw_)); |
| 1589 | break; |
| 1590 | default: |
| 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | virtual void AfterTest() OVERRIDE {} |
| 1596 | |
| 1597 | private: |
| 1598 | TestWebGraphicsContext3D* ContextForImplThread(LayerTreeHostImpl* host_impl) { |
[email protected] | 1dff796 | 2014-01-10 12:05:03 | [diff] [blame] | 1599 | return static_cast<TestContextProvider*>( |
| 1600 | host_impl->output_surface()->context_provider().get())->TestContext3d(); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | scoped_refptr<SolidColorLayer> solid_layer_; |
| 1604 | scoped_refptr<Layer> parent_layer_; |
| 1605 | scoped_refptr<TextureLayer> texture_layer_; |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1606 | |
| 1607 | // Used on the main thread, and on the impl thread while the main thread is |
| 1608 | // blocked. |
| 1609 | unsigned texture_; |
| 1610 | |
| 1611 | // Used on the main thread. |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1612 | int prepare_called_; |
| 1613 | int commit_count_; |
| 1614 | |
| 1615 | // Used on the compositor thread. |
| 1616 | unsigned expected_texture_on_draw_; |
| 1617 | }; |
| 1618 | |
| 1619 | // The TextureLayerChangeInvisibleTest does not use mailboxes, so can't use a |
| 1620 | // delegating renderer. |
| 1621 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerChangeInvisibleTest); |
| 1622 | |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1623 | // Checks that TextureLayer::Update does not cause an extra commit when setting |
| 1624 | // the texture mailbox. |
| 1625 | class TextureLayerNoExtraCommitForMailboxTest |
| 1626 | : public LayerTreeTest, |
| 1627 | public TextureLayerClient { |
| 1628 | public: |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1629 | // TextureLayerClient implementation. |
| 1630 | virtual unsigned PrepareTexture() OVERRIDE { |
| 1631 | NOTREACHED(); |
| 1632 | return 0; |
| 1633 | } |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1634 | virtual bool PrepareTextureMailbox( |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1635 | TextureMailbox* texture_mailbox, |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1636 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1637 | bool use_shared_memory) OVERRIDE { |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1638 | if (layer_tree_host()->source_frame_number() == 1) { |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1639 | *texture_mailbox = TextureMailbox(); |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1640 | return true; |
| 1641 | } |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1642 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1643 | *texture_mailbox = TextureMailbox( |
| 1644 | MailboxFromString(std::string(64, '1')), GL_TEXTURE_2D, 0); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1645 | *release_callback = SingleReleaseCallback::Create( |
| 1646 | base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, |
| 1647 | base::Unretained(this))); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1648 | return true; |
| 1649 | } |
| 1650 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1651 | void MailboxReleased(uint32 sync_point, bool lost_resource) { |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1652 | EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
| 1653 | EndTest(); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | virtual void SetupTree() OVERRIDE { |
| 1657 | scoped_refptr<Layer> root = Layer::Create(); |
| 1658 | root->SetBounds(gfx::Size(10, 10)); |
| 1659 | root->SetAnchorPoint(gfx::PointF()); |
| 1660 | root->SetIsDrawable(true); |
| 1661 | |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1662 | texture_layer_ = TextureLayer::CreateForMailbox(this); |
| 1663 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
| 1664 | texture_layer_->SetAnchorPoint(gfx::PointF()); |
| 1665 | texture_layer_->SetIsDrawable(true); |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1666 | root->AddChild(texture_layer_); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1667 | |
| 1668 | layer_tree_host()->SetRootLayer(root); |
| 1669 | LayerTreeTest::SetupTree(); |
| 1670 | } |
| 1671 | |
| 1672 | virtual void BeginTest() OVERRIDE { |
| 1673 | PostSetNeedsCommitToMainThread(); |
| 1674 | } |
| 1675 | |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1676 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1677 | switch (layer_tree_host()->source_frame_number()) { |
| 1678 | case 1: |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1679 | EXPECT_FALSE(proxy()->CommitPendingForTesting()); |
| 1680 | // Invalidate the texture layer to clear the mailbox before |
| 1681 | // ending the test. |
| 1682 | texture_layer_->SetNeedsDisplay(); |
| 1683 | break; |
| 1684 | case 2: |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1685 | break; |
| 1686 | default: |
| 1687 | NOTREACHED(); |
| 1688 | break; |
| 1689 | } |
| 1690 | } |
| 1691 | |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1692 | virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1693 | bool result) OVERRIDE { |
| 1694 | ASSERT_TRUE(result); |
| 1695 | DelegatedFrameData* delegated_frame_data = |
| 1696 | output_surface()->last_sent_frame().delegated_frame_data.get(); |
| 1697 | if (!delegated_frame_data) |
| 1698 | return; |
| 1699 | |
| 1700 | // Return all resources immediately. |
| 1701 | TransferableResourceArray resources_to_return = |
| 1702 | output_surface()->resources_held_by_parent(); |
| 1703 | |
| 1704 | CompositorFrameAck ack; |
| 1705 | for (size_t i = 0; i < resources_to_return.size(); ++i) |
| 1706 | output_surface()->ReturnResource(resources_to_return[i].id, &ack); |
| 1707 | host_impl->ReclaimResources(&ack); |
| 1708 | host_impl->OnSwapBuffersComplete(); |
| 1709 | } |
| 1710 | |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1711 | virtual void AfterTest() OVERRIDE {} |
| 1712 | |
| 1713 | private: |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1714 | scoped_refptr<TextureLayer> texture_layer_; |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1715 | }; |
| 1716 | |
[email protected] | cce34bd | 2013-12-02 23:24:45 | [diff] [blame] | 1717 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest); |
[email protected] | 4bad8b6 | 2013-10-24 01:27:29 | [diff] [blame] | 1718 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1719 | // Checks that changing a mailbox in the client for a TextureLayer that's |
| 1720 | // invisible correctly works and uses the new mailbox as soon as the layer |
| 1721 | // becomes visible (and returns the old one). |
| 1722 | class TextureLayerChangeInvisibleMailboxTest |
| 1723 | : public LayerTreeTest, |
| 1724 | public TextureLayerClient { |
| 1725 | public: |
| 1726 | TextureLayerChangeInvisibleMailboxTest() |
| 1727 | : mailbox_changed_(true), |
| 1728 | mailbox_returned_(0), |
| 1729 | prepare_called_(0), |
| 1730 | commit_count_(0) { |
| 1731 | mailbox_ = MakeMailbox('1'); |
| 1732 | } |
| 1733 | |
| 1734 | // TextureLayerClient implementation. |
| 1735 | virtual unsigned PrepareTexture() OVERRIDE { |
| 1736 | NOTREACHED(); |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1740 | virtual bool PrepareTextureMailbox( |
[email protected] | e51444a | 2013-12-10 23:05:01 | [diff] [blame] | 1741 | TextureMailbox* mailbox, |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1742 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1743 | bool use_shared_memory) OVERRIDE { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1744 | ++prepare_called_; |
| 1745 | if (!mailbox_changed_) |
| 1746 | return false; |
| 1747 | *mailbox = mailbox_; |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1748 | *release_callback = SingleReleaseCallback::Create( |
| 1749 | base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, |
| 1750 | base::Unretained(this))); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1751 | return true; |
| 1752 | } |
| 1753 | |
| 1754 | TextureMailbox MakeMailbox(char name) { |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1755 | return TextureMailbox( |
| 1756 | MailboxFromString(std::string(64, name)), GL_TEXTURE_2D, 0); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1757 | } |
| 1758 | |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1759 | void MailboxReleased(uint32 sync_point, bool lost_resource) { |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1760 | ++mailbox_returned_; |
| 1761 | } |
| 1762 | |
| 1763 | virtual void SetupTree() OVERRIDE { |
| 1764 | scoped_refptr<Layer> root = Layer::Create(); |
| 1765 | root->SetBounds(gfx::Size(10, 10)); |
| 1766 | root->SetAnchorPoint(gfx::PointF()); |
| 1767 | root->SetIsDrawable(true); |
| 1768 | |
| 1769 | solid_layer_ = SolidColorLayer::Create(); |
| 1770 | solid_layer_->SetBounds(gfx::Size(10, 10)); |
| 1771 | solid_layer_->SetIsDrawable(true); |
| 1772 | solid_layer_->SetBackgroundColor(SK_ColorWHITE); |
| 1773 | root->AddChild(solid_layer_); |
| 1774 | |
| 1775 | parent_layer_ = Layer::Create(); |
| 1776 | parent_layer_->SetBounds(gfx::Size(10, 10)); |
| 1777 | parent_layer_->SetIsDrawable(true); |
| 1778 | root->AddChild(parent_layer_); |
| 1779 | |
| 1780 | texture_layer_ = TextureLayer::CreateForMailbox(this); |
| 1781 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
| 1782 | texture_layer_->SetAnchorPoint(gfx::PointF()); |
| 1783 | texture_layer_->SetIsDrawable(true); |
| 1784 | parent_layer_->AddChild(texture_layer_); |
| 1785 | |
| 1786 | layer_tree_host()->SetRootLayer(root); |
| 1787 | LayerTreeTest::SetupTree(); |
| 1788 | } |
| 1789 | |
| 1790 | virtual void BeginTest() OVERRIDE { |
| 1791 | PostSetNeedsCommitToMainThread(); |
| 1792 | } |
| 1793 | |
| 1794 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1795 | ++commit_count_; |
| 1796 | switch (commit_count_) { |
| 1797 | case 1: |
| 1798 | // We should have updated the layer, committing the texture. |
| 1799 | EXPECT_EQ(1, prepare_called_); |
| 1800 | // Make layer invisible. |
| 1801 | parent_layer_->SetOpacity(0.f); |
| 1802 | break; |
| 1803 | case 2: |
| 1804 | // Layer shouldn't have been updated. |
| 1805 | EXPECT_EQ(1, prepare_called_); |
| 1806 | // Change the texture. |
| 1807 | mailbox_ = MakeMailbox('2'); |
| 1808 | mailbox_changed_ = true; |
| 1809 | texture_layer_->SetNeedsDisplay(); |
| 1810 | // Force a change to make sure we draw a frame. |
| 1811 | solid_layer_->SetBackgroundColor(SK_ColorGRAY); |
| 1812 | break; |
| 1813 | case 3: |
| 1814 | // Layer shouldn't have been updated. |
| 1815 | EXPECT_EQ(1, prepare_called_); |
| 1816 | // So the old mailbox isn't returned yet. |
| 1817 | EXPECT_EQ(0, mailbox_returned_); |
| 1818 | // Make layer visible again. |
| 1819 | parent_layer_->SetOpacity(1.f); |
| 1820 | break; |
| 1821 | case 4: |
| 1822 | // Layer should have been updated. |
| 1823 | EXPECT_EQ(2, prepare_called_); |
| 1824 | // So the old mailbox should have been returned already. |
| 1825 | EXPECT_EQ(1, mailbox_returned_); |
| 1826 | texture_layer_->ClearClient(); |
| 1827 | break; |
| 1828 | case 5: |
| 1829 | EXPECT_EQ(2, mailbox_returned_); |
| 1830 | EndTest(); |
| 1831 | break; |
| 1832 | default: |
| 1833 | NOTREACHED(); |
| 1834 | break; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1839 | bool result) OVERRIDE { |
| 1840 | ASSERT_TRUE(result); |
| 1841 | DelegatedFrameData* delegated_frame_data = |
| 1842 | output_surface()->last_sent_frame().delegated_frame_data.get(); |
| 1843 | if (!delegated_frame_data) |
| 1844 | return; |
| 1845 | |
| 1846 | // Return all resources immediately. |
| 1847 | TransferableResourceArray resources_to_return = |
| 1848 | output_surface()->resources_held_by_parent(); |
| 1849 | |
| 1850 | CompositorFrameAck ack; |
| 1851 | for (size_t i = 0; i < resources_to_return.size(); ++i) |
| 1852 | output_surface()->ReturnResource(resources_to_return[i].id, &ack); |
[email protected] | a7335e0b | 2013-09-18 09:34:51 | [diff] [blame] | 1853 | host_impl->ReclaimResources(&ack); |
| 1854 | host_impl->OnSwapBuffersComplete(); |
[email protected] | b04264f9 | 2013-09-13 23:37:29 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | virtual void AfterTest() OVERRIDE {} |
| 1858 | |
| 1859 | private: |
| 1860 | scoped_refptr<SolidColorLayer> solid_layer_; |
| 1861 | scoped_refptr<Layer> parent_layer_; |
| 1862 | scoped_refptr<TextureLayer> texture_layer_; |
| 1863 | |
| 1864 | // Used on the main thread. |
| 1865 | bool mailbox_changed_; |
| 1866 | TextureMailbox mailbox_; |
| 1867 | int mailbox_returned_; |
| 1868 | int prepare_called_; |
| 1869 | int commit_count_; |
| 1870 | }; |
| 1871 | |
| 1872 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); |
| 1873 | |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1874 | // Test that TextureLayerImpl::ReleaseResources can be called which releases |
| 1875 | // the mailbox back to TextureLayerClient. |
| 1876 | class TextureLayerReleaseResourcesBase |
| 1877 | : public LayerTreeTest, |
| 1878 | public TextureLayerClient { |
| 1879 | public: |
| 1880 | // TextureLayerClient implementation. |
| 1881 | virtual unsigned PrepareTexture() OVERRIDE { |
| 1882 | NOTREACHED(); |
| 1883 | return 0; |
| 1884 | } |
| 1885 | virtual bool PrepareTextureMailbox( |
| 1886 | TextureMailbox* mailbox, |
| 1887 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1888 | bool use_shared_memory) OVERRIDE { |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 1889 | *mailbox = TextureMailbox( |
| 1890 | MailboxFromString(std::string(64, '1')), GL_TEXTURE_2D, 0); |
[email protected] | 0d7fb30 | 2014-01-23 21:30:47 | [diff] [blame] | 1891 | *release_callback = SingleReleaseCallback::Create( |
| 1892 | base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased, |
| 1893 | base::Unretained(this))); |
| 1894 | return true; |
| 1895 | } |
| 1896 | |
| 1897 | void MailboxReleased(unsigned sync_point, bool lost_resource) { |
| 1898 | mailbox_released_ = true; |
| 1899 | } |
| 1900 | |
| 1901 | virtual void SetupTree() OVERRIDE { |
| 1902 | LayerTreeTest::SetupTree(); |
| 1903 | |
| 1904 | scoped_refptr<TextureLayer> texture_layer = |
| 1905 | TextureLayer::CreateForMailbox(this); |
| 1906 | texture_layer->SetBounds(gfx::Size(10, 10)); |
| 1907 | texture_layer->SetAnchorPoint(gfx::PointF()); |
| 1908 | texture_layer->SetIsDrawable(true); |
| 1909 | |
| 1910 | layer_tree_host()->root_layer()->AddChild(texture_layer); |
| 1911 | } |
| 1912 | |
| 1913 | virtual void BeginTest() OVERRIDE { |
| 1914 | mailbox_released_ = false; |
| 1915 | PostSetNeedsCommitToMainThread(); |
| 1916 | } |
| 1917 | |
| 1918 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1919 | EndTest(); |
| 1920 | } |
| 1921 | |
| 1922 | virtual void AfterTest() OVERRIDE { |
| 1923 | EXPECT_TRUE(mailbox_released_); |
| 1924 | } |
| 1925 | |
| 1926 | private: |
| 1927 | bool mailbox_released_; |
| 1928 | }; |
| 1929 | |
| 1930 | class TextureLayerReleaseResourcesAfterCommit |
| 1931 | : public TextureLayerReleaseResourcesBase { |
| 1932 | public: |
| 1933 | virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1934 | LayerTreeImpl* tree = NULL; |
| 1935 | if (host_impl->settings().impl_side_painting) |
| 1936 | tree = host_impl->pending_tree(); |
| 1937 | else |
| 1938 | tree = host_impl->active_tree(); |
| 1939 | tree->root_layer()->children()[0]->ReleaseResources(); |
| 1940 | } |
| 1941 | }; |
| 1942 | |
| 1943 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit); |
| 1944 | |
| 1945 | class TextureLayerReleaseResourcesAfterActivate |
| 1946 | : public TextureLayerReleaseResourcesBase { |
| 1947 | public: |
| 1948 | virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1949 | host_impl->active_tree()->root_layer()->children()[0]->ReleaseResources(); |
| 1950 | } |
| 1951 | }; |
| 1952 | |
| 1953 | SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate); |
| 1954 | |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 1955 | // Test recovering from a lost context. |
| 1956 | class TextureLayerLostContextTest |
| 1957 | : public LayerTreeTest, |
| 1958 | public TextureLayerClient { |
| 1959 | public: |
| 1960 | TextureLayerLostContextTest() |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1961 | : context_lost_(false), |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 1962 | draw_count_(0) {} |
| 1963 | |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1964 | virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 1965 | OVERRIDE { |
[email protected] | a636693 | 2014-02-05 20:12:47 | [diff] [blame^] | 1966 | return FakeOutputSurface::Create3d(); |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 1967 | } |
| 1968 | |
[email protected] | 171cbb3 | 2013-07-11 03:51:19 | [diff] [blame] | 1969 | virtual unsigned PrepareTexture() OVERRIDE { |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 1970 | if (draw_count_ == 0) |
| 1971 | context_lost_ = true; |
| 1972 | if (context_lost_) |
| 1973 | return 0u; |
| 1974 | return 1u; |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | virtual bool PrepareTextureMailbox( |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 1978 | TextureMailbox* mailbox, |
| 1979 | scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1980 | bool use_shared_memory) OVERRIDE { |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 1981 | return false; |
| 1982 | } |
| 1983 | |
| 1984 | virtual void SetupTree() OVERRIDE { |
| 1985 | scoped_refptr<Layer> root = Layer::Create(); |
| 1986 | root->SetBounds(gfx::Size(10, 10)); |
| 1987 | root->SetIsDrawable(true); |
| 1988 | |
| 1989 | texture_layer_ = TextureLayer::Create(this); |
| 1990 | texture_layer_->SetBounds(gfx::Size(10, 10)); |
| 1991 | texture_layer_->SetIsDrawable(true); |
| 1992 | root->AddChild(texture_layer_); |
| 1993 | |
| 1994 | layer_tree_host()->SetRootLayer(root); |
| 1995 | LayerTreeTest::SetupTree(); |
| 1996 | } |
| 1997 | |
| 1998 | virtual void BeginTest() OVERRIDE { |
| 1999 | PostSetNeedsCommitToMainThread(); |
| 2000 | } |
| 2001 | |
[email protected] | 7ddfe7e8 | 2014-01-30 07:22:11 | [diff] [blame] | 2002 | virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
| 2003 | LayerTreeHostImpl* host_impl, |
| 2004 | LayerTreeHostImpl::FrameData* frame_data, |
| 2005 | DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 2006 | LayerImpl* root = host_impl->RootLayer(); |
| 2007 | TextureLayerImpl* texture_layer = |
| 2008 | static_cast<TextureLayerImpl*>(root->children()[0]); |
| 2009 | if (++draw_count_ == 1) |
| 2010 | EXPECT_EQ(0u, texture_layer->texture_id()); |
| 2011 | else |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 2012 | EXPECT_EQ(1u, texture_layer->texture_id()); |
[email protected] | 7ddfe7e8 | 2014-01-30 07:22:11 | [diff] [blame] | 2013 | return DrawSwapReadbackResult::DRAW_SUCCESS; |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 2017 | EndTest(); |
| 2018 | } |
| 2019 | |
| 2020 | virtual void AfterTest() OVERRIDE {} |
| 2021 | |
| 2022 | private: |
| 2023 | scoped_refptr<TextureLayer> texture_layer_; |
[email protected] | f5931d4 | 2013-11-06 19:44:57 | [diff] [blame] | 2024 | bool context_lost_; |
[email protected] | 0bf5a20 | 2013-07-10 14:50:54 | [diff] [blame] | 2025 | int draw_count_; |
| 2026 | }; |
| 2027 | |
| 2028 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); |
| 2029 | |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2030 | class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { |
| 2031 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 2032 | void ReleaseCallback(uint32 sync_point, bool lost_resource) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2033 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2034 | EXPECT_FALSE(lost_resource); |
| 2035 | ++callback_count_; |
| 2036 | EndTest(); |
| 2037 | } |
| 2038 | |
| 2039 | void SetMailbox(char mailbox_char) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2040 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 2041 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2042 | base::Bind( |
| 2043 | &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, |
| 2044 | base::Unretained(this))); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 2045 | layer_->SetTextureMailbox( |
| 2046 | TextureMailbox( |
| 2047 | MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 2048 | callback.Pass()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | virtual void SetupTree() OVERRIDE { |
| 2052 | gfx::Size bounds(100, 100); |
| 2053 | root_ = Layer::Create(); |
| 2054 | root_->SetAnchorPoint(gfx::PointF()); |
| 2055 | root_->SetBounds(bounds); |
| 2056 | |
| 2057 | layer_ = TextureLayer::CreateForMailbox(NULL); |
| 2058 | layer_->SetIsDrawable(true); |
| 2059 | layer_->SetAnchorPoint(gfx::PointF()); |
| 2060 | layer_->SetBounds(bounds); |
| 2061 | |
| 2062 | root_->AddChild(layer_); |
| 2063 | layer_tree_host()->SetRootLayer(root_); |
| 2064 | layer_tree_host()->SetViewportSize(bounds); |
| 2065 | } |
| 2066 | |
| 2067 | virtual void BeginTest() OVERRIDE { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2068 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 2069 | |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2070 | callback_count_ = 0; |
| 2071 | |
| 2072 | // Set the mailbox on the main thread. |
| 2073 | SetMailbox('1'); |
| 2074 | EXPECT_EQ(0, callback_count_); |
| 2075 | |
| 2076 | PostSetNeedsCommitToMainThread(); |
| 2077 | } |
| 2078 | |
| 2079 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 2080 | switch (layer_tree_host()->source_frame_number()) { |
| 2081 | case 1: |
| 2082 | // Delete the TextureLayer on the main thread while the mailbox is in |
| 2083 | // the impl tree. |
| 2084 | layer_->RemoveFromParent(); |
| 2085 | layer_ = NULL; |
| 2086 | break; |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | virtual void AfterTest() OVERRIDE { |
| 2091 | EXPECT_EQ(1, callback_count_); |
| 2092 | } |
| 2093 | |
| 2094 | private: |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2095 | base::ThreadChecker main_thread_; |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2096 | int callback_count_; |
| 2097 | scoped_refptr<Layer> root_; |
| 2098 | scoped_refptr<TextureLayer> layer_; |
| 2099 | }; |
| 2100 | |
| 2101 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 2102 | TextureLayerWithMailboxMainThreadDeleted); |
| 2103 | |
| 2104 | class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { |
| 2105 | public: |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 2106 | void ReleaseCallback(uint32 sync_point, bool lost_resource) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2107 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2108 | EXPECT_FALSE(lost_resource); |
| 2109 | ++callback_count_; |
| 2110 | EndTest(); |
| 2111 | } |
| 2112 | |
| 2113 | void SetMailbox(char mailbox_char) { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2114 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 2115 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2116 | base::Bind( |
| 2117 | &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, |
| 2118 | base::Unretained(this))); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 2119 | layer_->SetTextureMailbox( |
| 2120 | TextureMailbox( |
| 2121 | MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 2122 | callback.Pass()); |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | virtual void SetupTree() OVERRIDE { |
| 2126 | gfx::Size bounds(100, 100); |
| 2127 | root_ = Layer::Create(); |
| 2128 | root_->SetAnchorPoint(gfx::PointF()); |
| 2129 | root_->SetBounds(bounds); |
| 2130 | |
| 2131 | layer_ = TextureLayer::CreateForMailbox(NULL); |
| 2132 | layer_->SetIsDrawable(true); |
| 2133 | layer_->SetAnchorPoint(gfx::PointF()); |
| 2134 | layer_->SetBounds(bounds); |
| 2135 | |
| 2136 | root_->AddChild(layer_); |
| 2137 | layer_tree_host()->SetRootLayer(root_); |
| 2138 | layer_tree_host()->SetViewportSize(bounds); |
| 2139 | } |
| 2140 | |
| 2141 | virtual void BeginTest() OVERRIDE { |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2142 | EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 2143 | |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2144 | callback_count_ = 0; |
| 2145 | |
| 2146 | // Set the mailbox on the main thread. |
| 2147 | SetMailbox('1'); |
| 2148 | EXPECT_EQ(0, callback_count_); |
| 2149 | |
| 2150 | PostSetNeedsCommitToMainThread(); |
| 2151 | } |
| 2152 | |
| 2153 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 2154 | switch (layer_tree_host()->source_frame_number()) { |
| 2155 | case 1: |
| 2156 | // Remove the TextureLayer on the main thread while the mailbox is in |
| 2157 | // the impl tree, but don't delete the TextureLayer until after the impl |
| 2158 | // tree side is deleted. |
| 2159 | layer_->RemoveFromParent(); |
| 2160 | break; |
| 2161 | case 2: |
| 2162 | layer_ = NULL; |
| 2163 | break; |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | virtual void AfterTest() OVERRIDE { |
| 2168 | EXPECT_EQ(1, callback_count_); |
| 2169 | } |
| 2170 | |
| 2171 | private: |
[email protected] | 9794fb3 | 2013-08-29 09:49:59 | [diff] [blame] | 2172 | base::ThreadChecker main_thread_; |
[email protected] | 9c2bd82 | 2013-07-26 12:30:17 | [diff] [blame] | 2173 | int callback_count_; |
| 2174 | scoped_refptr<Layer> root_; |
| 2175 | scoped_refptr<TextureLayer> layer_; |
| 2176 | }; |
| 2177 | |
| 2178 | SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 2179 | TextureLayerWithMailboxImplThreadDeleted); |
| 2180 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 2181 | } // namespace |
| 2182 | } // namespace cc |