blob: 998c6291e3b13e612b3a0908286e3eee16a23dc0 [file] [log] [blame]
[email protected]c0dd24c2012-08-30 23:25:271// 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]cc3cfaa2013-03-18 09:05:525#include "cc/layers/texture_layer.h"
[email protected]c0dd24c2012-08-30 23:25:276
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8#include <stdint.h>
9
[email protected]b04264f92013-09-13 23:37:2910#include <algorithm>
[email protected]de44a152013-01-08 15:28:4611#include <string>
12
[email protected]b04264f92013-09-13 23:37:2913#include "base/bind.h"
[email protected]de44a152013-01-08 15:28:4614#include "base/callback.h"
skyostil0fd1dad2015-04-13 20:11:4815#include "base/location.h"
avi02a4d172015-12-21 06:14:3616#include "base/macros.h"
danakj60bc3bc2016-04-09 00:24:4817#include "base/memory/ptr_util.h"
skyostil0fd1dad2015-04-13 20:11:4818#include "base/single_thread_task_runner.h"
danakj3c3973b2015-08-25 21:50:1819#include "base/synchronization/lock.h"
[email protected]9794fb32013-08-29 09:49:5920#include "base/synchronization/waitable_event.h"
[email protected]74b43cc2013-08-30 06:29:2721#include "base/threading/thread.h"
gab39cb4ed72016-05-11 17:45:1922#include "base/threading/thread_task_runner_handle.h"
[email protected]74b43cc2013-08-30 06:29:2723#include "base/time/time.h"
loysoab32ee72016-06-08 03:33:1824#include "cc/animation/animation_host.h"
[email protected]b04264f92013-09-13 23:37:2925#include "cc/layers/solid_color_layer.h"
[email protected]97d519fb2013-03-29 02:27:5426#include "cc/layers/texture_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5227#include "cc/layers/texture_layer_impl.h"
[email protected]b04264f92013-09-13 23:37:2928#include "cc/output/context_provider.h"
[email protected]e00bab022013-08-19 00:42:4529#include "cc/resources/returned_resource.h"
danakj1120f4c2016-09-15 02:05:3230#include "cc/test/fake_compositor_frame_sink.h"
khushalsagarb64b360d2015-10-21 19:25:1631#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]101441ce2012-10-16 01:45:0332#include "cc/test/fake_layer_tree_host_client.h"
[email protected]586d51ed2012-12-07 20:31:4533#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]06d68d02013-04-19 18:46:2134#include "cc/test/layer_test_common.h"
[email protected]e216fef02013-03-20 22:56:1035#include "cc/test/layer_tree_test.h"
danakjffc181a2016-07-22 22:48:4336#include "cc/test/stub_layer_tree_host_single_thread_client.h"
danakj1120f4c2016-09-15 02:05:3237#include "cc/test/test_compositor_frame_sink.h"
reveman34b7a1522015-03-23 20:27:4738#include "cc/test/test_task_graph_runner.h"
[email protected]c2610b9f2013-10-31 06:54:5939#include "cc/test/test_web_graphics_context_3d.h"
[email protected]9794fb32013-08-29 09:49:5940#include "cc/trees/blocking_task_runner.h"
khushalsagare0e4486e2017-01-25 03:15:0341#include "cc/trees/layer_tree_host.h"
[email protected]556fd292013-03-18 08:03:0442#include "cc/trees/layer_tree_impl.h"
43#include "cc/trees/single_thread_proxy.h"
[email protected]0bf5a202013-07-10 14:50:5444#include "gpu/GLES2/gl2extchromium.h"
[email protected]7f0c53db2012-10-02 00:23:1845#include "testing/gmock/include/gmock/gmock.h"
46#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2747
[email protected]c0dd24c2012-08-30 23:25:2748using ::testing::Mock;
49using ::testing::_;
50using ::testing::AtLeast;
51using ::testing::AnyNumber;
[email protected]d72d9e02014-04-03 18:40:0952using ::testing::InvokeWithoutArgs;
[email protected]c0dd24c2012-08-30 23:25:2753
[email protected]ba565742012-11-10 09:29:4854namespace cc {
[email protected]c0dd24c2012-08-30 23:25:2755namespace {
56
[email protected]e0a4d732014-02-15 00:23:2657gpu::Mailbox MailboxFromChar(char value) {
[email protected]df41e252014-02-03 23:39:5058 gpu::Mailbox mailbox;
[email protected]e0a4d732014-02-15 00:23:2659 memset(mailbox.name, value, sizeof(mailbox.name));
[email protected]df41e252014-02-03 23:39:5060 return mailbox;
61}
62
dyen398dd0142016-01-21 22:05:5663gpu::SyncToken SyncTokenFromUInt(uint32_t value) {
lukasza2573ce7d2016-02-16 19:17:2264 return gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0,
65 gpu::CommandBufferId::FromUnsafeValue(0x123), value);
dyen398dd0142016-01-21 22:05:5666}
67
khushalsagare0e4486e2017-01-25 03:15:0368class MockLayerTreeHost : public LayerTreeHost {
[email protected]28571b042013-03-14 07:59:1569 public:
danakj60bc3bc2016-04-09 00:24:4870 static std::unique_ptr<MockLayerTreeHost> Create(
danakjcf610582015-06-16 22:48:5671 FakeLayerTreeHostClient* client,
loyso2cb3f32f2016-11-08 07:08:3472 TaskGraphRunner* task_graph_runner,
73 MutatorHost* mutator_host) {
khushalsagare0e4486e2017-01-25 03:15:0374 LayerTreeHost::InitParams params;
sadrul6780f3da2015-05-11 17:01:5275 params.client = client;
danakjcf610582015-06-16 22:48:5676 params.task_graph_runner = task_graph_runner;
loyso2cb3f32f2016-11-08 07:08:3477 params.mutator_host = mutator_host;
sadrul6780f3da2015-05-11 17:01:5278 LayerTreeSettings settings;
jaydasika853306a2016-07-29 19:28:3479 settings.verify_clip_tree_calculations = true;
sadrul6780f3da2015-05-11 17:01:5280 params.settings = &settings;
danakjffc181a2016-07-22 22:48:4381 return base::WrapUnique(new MockLayerTreeHost(&params));
[email protected]28571b042013-03-14 07:59:1582 }
[email protected]c0dd24c2012-08-30 23:25:2783
[email protected]28571b042013-03-14 07:59:1584 MOCK_METHOD0(SetNeedsCommit, void());
[email protected]3519b872013-07-30 07:17:5085 MOCK_METHOD0(SetNeedsUpdateLayers, void());
[email protected]aeeb3372013-11-05 14:05:5486 MOCK_METHOD0(StartRateLimiter, void());
87 MOCK_METHOD0(StopRateLimiter, void());
sadrul6780f3da2015-05-11 17:01:5288
89 private:
khushalsagare0e4486e2017-01-25 03:15:0390 explicit MockLayerTreeHost(LayerTreeHost::InitParams* params)
91 : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) {
danakjffc181a2016-07-22 22:48:4392 InitializeSingleThreaded(&single_thread_client_,
enne2b0ad682016-09-21 01:44:4793 base::ThreadTaskRunnerHandle::Get());
sadrul6780f3da2015-05-11 17:01:5294 }
danakjffc181a2016-07-22 22:48:4395
96 StubLayerTreeHostSingleThreadClient single_thread_client_;
[email protected]c0dd24c2012-08-30 23:25:2797};
98
[email protected]d72d9e02014-04-03 18:40:0999class FakeTextureLayerClient : public TextureLayerClient {
100 public:
[email protected]17e08432014-04-10 00:41:11101 FakeTextureLayerClient() : mailbox_changed_(true) {}
[email protected]d72d9e02014-04-03 18:40:09102
dcheng716bedf2014-10-21 09:51:08103 bool PrepareTextureMailbox(
[email protected]d72d9e02014-04-03 18:40:09104 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:06105 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]d72d9e02014-04-03 18:40:09106 if (!mailbox_changed_)
107 return false;
108
109 *mailbox = mailbox_;
danakja04855a2015-11-18 20:39:10110 *release_callback = std::move(release_callback_);
[email protected]d72d9e02014-04-03 18:40:09111 mailbox_changed_ = false;
112 return true;
113 }
114
[email protected]d72d9e02014-04-03 18:40:09115 void set_mailbox(const TextureMailbox& mailbox,
danakj60bc3bc2016-04-09 00:24:48116 std::unique_ptr<SingleReleaseCallback> release_callback) {
[email protected]d72d9e02014-04-03 18:40:09117 mailbox_ = mailbox;
danakja04855a2015-11-18 20:39:10118 release_callback_ = std::move(release_callback);
[email protected]d72d9e02014-04-03 18:40:09119 mailbox_changed_ = true;
120 }
121
122 private:
[email protected]d72d9e02014-04-03 18:40:09123 TextureMailbox mailbox_;
danakj60bc3bc2016-04-09 00:24:48124 std::unique_ptr<SingleReleaseCallback> release_callback_;
[email protected]d72d9e02014-04-03 18:40:09125 bool mailbox_changed_;
126 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient);
127};
128
129class MockMailboxCallback {
130 public:
131 MOCK_METHOD3(Release,
132 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04133 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09134 bool lost_resource));
135 MOCK_METHOD3(Release2,
jbauman9015c8b2014-12-11 00:49:37136 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04137 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09138 bool lost_resource));
skyostil3976a3f2014-09-04 22:07:23139 MOCK_METHOD4(ReleaseImpl,
140 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04141 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23142 bool lost_resource,
143 BlockingTaskRunner* main_thread_task_runner));
144 MOCK_METHOD4(ReleaseImpl2,
jbauman9015c8b2014-12-11 00:49:37145 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04146 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23147 bool lost_resource,
148 BlockingTaskRunner* main_thread_task_runner));
[email protected]d72d9e02014-04-03 18:40:09149};
150
151struct CommonMailboxObjects {
jbauman9015c8b2014-12-11 00:49:37152 explicit CommonMailboxObjects(SharedBitmapManager* manager)
[email protected]d72d9e02014-04-03 18:40:09153 : mailbox_name1_(MailboxFromChar('1')),
154 mailbox_name2_(MailboxFromChar('2')),
lukasza2573ce7d2016-02-16 19:17:22155 sync_token1_(gpu::CommandBufferNamespace::GPU_IO,
156 123,
157 gpu::CommandBufferId::FromUnsafeValue(0x234),
158 1),
159 sync_token2_(gpu::CommandBufferNamespace::GPU_IO,
160 123,
161 gpu::CommandBufferId::FromUnsafeValue(0x234),
162 2) {
[email protected]d72d9e02014-04-03 18:40:09163 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
164 base::Unretained(&mock_callback_),
165 mailbox_name1_);
166 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
167 base::Unretained(&mock_callback_),
168 mailbox_name2_);
skyostil3976a3f2014-09-04 22:07:23169 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
170 base::Unretained(&mock_callback_),
171 mailbox_name1_);
172 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
173 base::Unretained(&mock_callback_),
174 mailbox_name2_);
avi02a4d172015-12-21 06:14:36175 const uint32_t arbitrary_target1 = GL_TEXTURE_2D;
176 const uint32_t arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
dyencc16ed4d2015-11-03 20:03:04177 mailbox1_ = TextureMailbox(mailbox_name1_, sync_token1_, arbitrary_target1);
178 mailbox2_ = TextureMailbox(mailbox_name2_, sync_token2_, arbitrary_target2);
[email protected]d72d9e02014-04-03 18:40:09179 gfx::Size size(128, 128);
jbauman9015c8b2014-12-11 00:49:37180 shared_bitmap_ = manager->AllocateSharedBitmap(size);
181 DCHECK(shared_bitmap_);
182 release_mailbox3_ =
183 base::Bind(&MockMailboxCallback::Release2,
184 base::Unretained(&mock_callback_), shared_bitmap_.get());
185 release_mailbox3_impl_ =
186 base::Bind(&MockMailboxCallback::ReleaseImpl2,
187 base::Unretained(&mock_callback_), shared_bitmap_.get());
188 mailbox3_ = TextureMailbox(shared_bitmap_.get(), size);
[email protected]d72d9e02014-04-03 18:40:09189 }
190
191 gpu::Mailbox mailbox_name1_;
192 gpu::Mailbox mailbox_name2_;
193 MockMailboxCallback mock_callback_;
194 ReleaseCallback release_mailbox1_;
195 ReleaseCallback release_mailbox2_;
196 ReleaseCallback release_mailbox3_;
skyostil3976a3f2014-09-04 22:07:23197 ReleaseCallbackImpl release_mailbox1_impl_;
198 ReleaseCallbackImpl release_mailbox2_impl_;
199 ReleaseCallbackImpl release_mailbox3_impl_;
[email protected]d72d9e02014-04-03 18:40:09200 TextureMailbox mailbox1_;
201 TextureMailbox mailbox2_;
202 TextureMailbox mailbox3_;
dyencc16ed4d2015-11-03 20:03:04203 gpu::SyncToken sync_token1_;
204 gpu::SyncToken sync_token2_;
danakj60bc3bc2016-04-09 00:24:48205 std::unique_ptr<SharedBitmap> shared_bitmap_;
[email protected]d72d9e02014-04-03 18:40:09206};
207
[email protected]31d4df82013-07-18 10:17:22208class TextureLayerTest : public testing::Test {
209 public:
210 TextureLayerTest()
danakj1120f4c2016-09-15 02:05:32211 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()),
khushalsagarb64b360d2015-10-21 19:25:16212 host_impl_(&task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:16213 &task_graph_runner_),
jbauman9015c8b2014-12-11 00:49:37214 test_data_(&shared_bitmap_manager_) {}
[email protected]31d4df82013-07-18 10:17:22215
216 protected:
dcheng93a52eb2014-12-23 02:14:23217 void SetUp() override {
loyso2cb3f32f2016-11-08 07:08:34218 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
219 layer_tree_host_ = MockLayerTreeHost::Create(
220 &fake_client_, &task_graph_runner_, animation_host_.get());
[email protected]d72d9e02014-04-03 18:40:09221 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagarb69ba9452017-01-27 22:20:07222 layer_tree_host_->SetViewportSize(gfx::Size(10, 10));
[email protected]d72d9e02014-04-03 18:40:09223 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22224 }
225
dcheng93a52eb2014-12-23 02:14:23226 void TearDown() override {
[email protected]31d4df82013-07-18 10:17:22227 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22228 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
229
loyso2cb3f32f2016-11-08 07:08:34230 animation_host_->SetMutatorHostClient(nullptr);
khushalsagarb69ba9452017-01-27 22:20:07231 layer_tree_host_->SetRootLayer(nullptr);
danakjf446a072014-09-27 21:55:48232 layer_tree_host_ = nullptr;
loyso2cb3f32f2016-11-08 07:08:34233 animation_host_ = nullptr;
[email protected]31d4df82013-07-18 10:17:22234 }
235
danakj60bc3bc2016-04-09 00:24:48236 std::unique_ptr<MockLayerTreeHost> layer_tree_host_;
loyso2cb3f32f2016-11-08 07:08:34237 std::unique_ptr<AnimationHost> animation_host_;
khushalsagarb64b360d2015-10-21 19:25:16238 FakeImplTaskRunnerProvider task_runner_provider_;
[email protected]31d4df82013-07-18 10:17:22239 FakeLayerTreeHostClient fake_client_;
[email protected]4e2eb352014-03-20 17:25:45240 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:47241 TestTaskGraphRunner task_graph_runner_;
danakj1120f4c2016-09-15 02:05:32242 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_;
[email protected]31d4df82013-07-18 10:17:22243 FakeLayerTreeHostImpl host_impl_;
jbauman9015c8b2014-12-11 00:49:37244 CommonMailboxObjects test_data_;
[email protected]31d4df82013-07-18 10:17:22245};
246
[email protected]31d4df82013-07-18 10:17:22247TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
kulkarni.a4015690f12014-10-10 13:50:06248 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31249 TextureLayer::CreateForMailbox(nullptr);
khushalsagarb69ba9452017-01-27 22:20:07250 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer));
[email protected]31d4df82013-07-18 10:17:22251
252 // Test properties that should call SetNeedsCommit. All properties need to
253 // be set to new values in order for SetNeedsCommit to be called.
254 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
jackhou10c9af42014-12-04 05:24:44255 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
[email protected]31d4df82013-07-18 10:17:22256 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
257 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
258 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
259 0.5f, 0.5f, 0.5f, 0.5f));
260 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
261 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true));
[email protected]31d4df82013-07-18 10:17:22262}
263
[email protected]df41e252014-02-03 23:39:50264class TestMailboxHolder : public TextureLayer::TextureMailboxHolder {
[email protected]9794fb32013-08-29 09:49:59265 public:
[email protected]df41e252014-02-03 23:39:50266 using TextureLayer::TextureMailboxHolder::Create;
[email protected]9794fb32013-08-29 09:49:59267
268 protected:
dcheng716bedf2014-10-21 09:51:08269 ~TestMailboxHolder() override {}
[email protected]9794fb32013-08-29 09:49:59270};
271
[email protected]de44a152013-01-08 15:28:46272class TextureLayerWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15273 protected:
dcheng93a52eb2014-12-23 02:14:23274 void TearDown() override {
[email protected]28571b042013-03-14 07:59:15275 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
dyencc16ed4d2015-11-03 20:03:04276 EXPECT_CALL(
277 test_data_.mock_callback_,
278 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
279 .Times(1);
[email protected]28571b042013-03-14 07:59:15280 TextureLayerTest::TearDown();
281 }
[email protected]de44a152013-01-08 15:28:46282};
283
[email protected]28571b042013-03-14 07:59:15284TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
kulkarni.a4015690f12014-10-10 13:50:06285 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31286 TextureLayer::CreateForMailbox(nullptr);
[email protected]22898ed2013-06-01 04:52:30287 ASSERT_TRUE(test_layer.get());
[email protected]de44a152013-01-08 15:28:46288
[email protected]28571b042013-03-14 07:59:15289 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagarb69ba9452017-01-27 22:20:07290 layer_tree_host_->SetRootLayer(test_layer);
[email protected]28571b042013-03-14 07:59:15291 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46292
[email protected]28571b042013-03-14 07:59:15293 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16294 test_layer->SetTextureMailbox(
295 test_data_.mailbox1_,
296 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]28571b042013-03-14 07:59:15297 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46298
[email protected]28571b042013-03-14 07:59:15299 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04300 EXPECT_CALL(
301 test_data_.mock_callback_,
302 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
[email protected]28571b042013-03-14 07:59:15303 .Times(1);
[email protected]9260757f2013-09-17 01:24:16304 test_layer->SetTextureMailbox(
305 test_data_.mailbox2_,
306 SingleReleaseCallback::Create(test_data_.release_mailbox2_));
[email protected]28571b042013-03-14 07:59:15307 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
308 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46309
[email protected]28571b042013-03-14 07:59:15310 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04311 EXPECT_CALL(
312 test_data_.mock_callback_,
313 Release(test_data_.mailbox_name2_, test_data_.sync_token2_, false))
[email protected]28571b042013-03-14 07:59:15314 .Times(1);
danakj968153f32014-10-15 22:52:16315 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]28571b042013-03-14 07:59:15316 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
317 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46318
[email protected]80d42bd2013-08-30 19:13:45319 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16320 test_layer->SetTextureMailbox(
321 test_data_.mailbox3_,
322 SingleReleaseCallback::Create(test_data_.release_mailbox3_));
[email protected]42f40a52013-06-08 04:38:51323 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
324 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
325
[email protected]42f40a52013-06-08 04:38:51326 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
327 EXPECT_CALL(test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04328 Release2(test_data_.shared_bitmap_.get(), _, false))
329 .Times(1);
danakj968153f32014-10-15 22:52:16330 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]42f40a52013-06-08 04:38:51331 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
332 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
333
[email protected]28571b042013-03-14 07:59:15334 // Test destructor.
335 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16336 test_layer->SetTextureMailbox(
337 test_data_.mailbox1_,
338 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]de44a152013-01-08 15:28:46339}
340
[email protected]9794fb32013-08-29 09:49:59341class TextureLayerMailboxHolderTest : public TextureLayerTest {
342 public:
343 TextureLayerMailboxHolderTest()
344 : main_thread_("MAIN") {
345 main_thread_.Start();
fdoray70df5a92016-06-22 21:13:59346 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48347 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::InitializeOnMain,
348 base::Unretained(this)));
skyostil3976a3f2014-09-04 22:07:23349 Wait(main_thread_);
[email protected]9794fb32013-08-29 09:49:59350 }
351
352 void Wait(const base::Thread& thread) {
gabcca53112016-06-08 20:13:28353 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
354 base::WaitableEvent::InitialState::NOT_SIGNALED);
fdoray70df5a92016-06-22 21:13:59355 thread.task_runner()->PostTask(
[email protected]9794fb32013-08-29 09:49:59356 FROM_HERE,
357 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
358 event.Wait();
359 }
360
361 void CreateMainRef() {
362 main_ref_ = TestMailboxHolder::Create(
[email protected]9260757f2013-09-17 01:24:16363 test_data_.mailbox1_,
danakja5a05ba02015-11-20 20:14:21364 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]9794fb32013-08-29 09:49:59365 }
366
danakjf446a072014-09-27 21:55:48367 void ReleaseMainRef() { main_ref_ = nullptr; }
[email protected]9794fb32013-08-29 09:49:59368
danakj60bc3bc2016-04-09 00:24:48369 void CreateImplRef(std::unique_ptr<SingleReleaseCallbackImpl>* impl_ref) {
[email protected]9794fb32013-08-29 09:49:59370 *impl_ref = main_ref_->holder()->GetCallbackForImplThread();
371 }
372
373 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture,
374 base::WaitableEvent* wait_for_capture,
375 base::WaitableEvent* stop_capture) {
376 begin_capture->Wait();
skyostil3976a3f2014-09-04 22:07:23377 BlockingTaskRunner::CapturePostTasks capture(
378 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59379 wait_for_capture->Signal();
380 stop_capture->Wait();
381 }
382
383 protected:
skyostil3976a3f2014-09-04 22:07:23384 void InitializeOnMain() {
385 main_thread_task_runner_ =
skyostil0fd1dad2015-04-13 20:11:48386 BlockingTaskRunner::Create(main_thread_.task_runner());
skyostil3976a3f2014-09-04 22:07:23387 }
388
danakj60bc3bc2016-04-09 00:24:48389 std::unique_ptr<TestMailboxHolder::MainThreadReference> main_ref_;
[email protected]9794fb32013-08-29 09:49:59390 base::Thread main_thread_;
danakj60bc3bc2016-04-09 00:24:48391 std::unique_ptr<BlockingTaskRunner> main_thread_task_runner_;
[email protected]9794fb32013-08-29 09:49:59392};
393
394TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) {
kulkarni.a4015690f12014-10-10 13:50:06395 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31396 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59397 ASSERT_TRUE(test_layer.get());
398
fdoray70df5a92016-06-22 21:13:59399 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48400 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
401 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59402
403 Wait(main_thread_);
404
405 // The texture layer is attached to compositor1, and passes a reference to its
406 // impl tree.
danakj60bc3bc2016-04-09 00:24:48407 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59408 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48409 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
410 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59411
412 // Then the texture layer is removed and attached to compositor2, and passes a
413 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48414 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59415 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48416 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
417 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59418
419 Wait(main_thread_);
420 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
421
422 // The compositors both destroy their impl trees before the main thread layer
423 // is destroyed.
dyen398dd0142016-01-21 22:05:56424 compositor1->Run(SyncTokenFromUInt(100), false,
425 main_thread_task_runner_.get());
426 compositor2->Run(SyncTokenFromUInt(200), false,
427 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59428
429 Wait(main_thread_);
430
431 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
432 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
433
434 // The main thread ref is the last one, so the mailbox is released back to the
435 // embedder, with the last sync point provided by the impl trees.
436 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56437 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), false))
dyencc16ed4d2015-11-03 20:03:04438 .Times(1);
[email protected]9794fb32013-08-29 09:49:59439
fdoray70df5a92016-06-22 21:13:59440 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48441 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
442 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59443 Wait(main_thread_);
444 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
445}
446
447TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) {
kulkarni.a4015690f12014-10-10 13:50:06448 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31449 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59450 ASSERT_TRUE(test_layer.get());
451
fdoray70df5a92016-06-22 21:13:59452 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48453 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
454 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59455
456 Wait(main_thread_);
457
458 // The texture layer is attached to compositor1, and passes a reference to its
459 // impl tree.
danakj60bc3bc2016-04-09 00:24:48460 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59461 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48462 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
463 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59464
465 // Then the texture layer is removed and attached to compositor2, and passes a
466 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48467 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59468 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48469 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
470 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59471
472 Wait(main_thread_);
473 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
474
475 // One compositor destroys their impl tree.
dyen398dd0142016-01-21 22:05:56476 compositor1->Run(SyncTokenFromUInt(100), false,
477 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59478
479 // Then the main thread reference is destroyed.
fdoray70df5a92016-06-22 21:13:59480 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48481 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
482 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59483
484 Wait(main_thread_);
485
486 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
487 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
488
489 // The second impl reference is destroyed last, causing the mailbox to be
490 // released back to the embedder with the last sync point from the impl tree.
491 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56492 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
dyencc16ed4d2015-11-03 20:03:04493 .Times(1);
[email protected]9794fb32013-08-29 09:49:59494
dyen398dd0142016-01-21 22:05:56495 compositor2->Run(SyncTokenFromUInt(200), true,
496 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59497 Wait(main_thread_);
498 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
499}
500
501TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {
kulkarni.a4015690f12014-10-10 13:50:06502 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31503 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59504 ASSERT_TRUE(test_layer.get());
505
fdoray70df5a92016-06-22 21:13:59506 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48507 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
508 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59509
510 Wait(main_thread_);
511
512 // The texture layer is attached to compositor1, and passes a reference to its
513 // impl tree.
danakj60bc3bc2016-04-09 00:24:48514 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59515 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48516 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
517 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59518
519 // Then the texture layer is removed and attached to compositor2, and passes a
520 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48521 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59522 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48523 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
524 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59525
526 Wait(main_thread_);
527 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
528
529 // The main thread reference is destroyed first.
fdoray70df5a92016-06-22 21:13:59530 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48531 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
532 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59533
534 // One compositor destroys their impl tree.
dyen398dd0142016-01-21 22:05:56535 compositor2->Run(SyncTokenFromUInt(200), false,
536 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59537
538 Wait(main_thread_);
539
540 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
541 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
542
543 // The second impl reference is destroyed last, causing the mailbox to be
544 // released back to the embedder with the last sync point from the impl tree.
545 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56546 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(100), true))
dyencc16ed4d2015-11-03 20:03:04547 .Times(1);
[email protected]9794fb32013-08-29 09:49:59548
dyen398dd0142016-01-21 22:05:56549 compositor1->Run(SyncTokenFromUInt(100), true,
550 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59551 Wait(main_thread_);
552 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
553}
554
555TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) {
kulkarni.a4015690f12014-10-10 13:50:06556 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31557 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59558 ASSERT_TRUE(test_layer.get());
559
fdoray70df5a92016-06-22 21:13:59560 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48561 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
562 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59563
564 Wait(main_thread_);
565
566 // The texture layer is attached to compositor1, and passes a reference to its
567 // impl tree.
danakj60bc3bc2016-04-09 00:24:48568 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59569 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48570 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
571 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59572
573 // Then the texture layer is removed and attached to compositor2, and passes a
574 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48575 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59576 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48577 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
578 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59579
580 Wait(main_thread_);
581 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
582
583 // The main thread reference is destroyed first.
fdoray70df5a92016-06-22 21:13:59584 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48585 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
586 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59587
588 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56589 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
dyencc16ed4d2015-11-03 20:03:04590 .Times(1);
[email protected]9794fb32013-08-29 09:49:59591
gabcca53112016-06-08 20:13:28592 base::WaitableEvent begin_capture(
593 base::WaitableEvent::ResetPolicy::AUTOMATIC,
594 base::WaitableEvent::InitialState::NOT_SIGNALED);
595 base::WaitableEvent wait_for_capture(
596 base::WaitableEvent::ResetPolicy::AUTOMATIC,
597 base::WaitableEvent::InitialState::NOT_SIGNALED);
598 base::WaitableEvent stop_capture(
599 base::WaitableEvent::ResetPolicy::AUTOMATIC,
600 base::WaitableEvent::InitialState::NOT_SIGNALED);
[email protected]9794fb32013-08-29 09:49:59601
602 // Post a task to start capturing tasks on the main thread. This will block
603 // the main thread until we signal the |stop_capture| event.
fdoray70df5a92016-06-22 21:13:59604 main_thread_.task_runner()->PostTask(
[email protected]9794fb32013-08-29 09:49:59605 FROM_HERE,
606 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait,
skyostil0fd1dad2015-04-13 20:11:48607 base::Unretained(this), &begin_capture, &wait_for_capture,
[email protected]9794fb32013-08-29 09:49:59608 &stop_capture));
609
610 // Before the main thread capturing starts, one compositor destroys their
611 // impl reference. Since capturing did not start, this gets post-tasked to
612 // the main thread.
dyen398dd0142016-01-21 22:05:56613 compositor1->Run(SyncTokenFromUInt(100), false,
614 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59615
616 // Start capturing on the main thread.
617 begin_capture.Signal();
618 wait_for_capture.Wait();
619
620 // Meanwhile, the second compositor released its impl reference, but this task
621 // gets shortcutted directly to the main thread. This means the reference is
622 // released before compositor1, whose reference will be released later when
623 // the post-task is serviced. But since it was destroyed _on the impl thread_
624 // last, its sync point values should be used.
dyen398dd0142016-01-21 22:05:56625 compositor2->Run(SyncTokenFromUInt(200), true,
626 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59627
628 stop_capture.Signal();
629 Wait(main_thread_);
630
631 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
632}
633
[email protected]e216fef02013-03-20 22:56:10634class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {
[email protected]28571b042013-03-14 07:59:15635 public:
danakj014316e2016-08-04 18:40:26636 TextureLayerImplWithMailboxThreadedCallback() = default;
637
danakj1120f4c2016-09-15 02:05:32638 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink(
danakj014316e2016-08-04 18:40:26639 scoped_refptr<ContextProvider> compositor_context_provider,
640 scoped_refptr<ContextProvider> worker_context_provider) override {
641 bool synchronous_composite =
642 !HasImplThread() &&
khushalsagarcebe4942016-09-07 23:27:01643 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler;
ericrk4b443522017-01-13 22:54:24644 // Allow relaim resources for this test so that mailboxes in the display
645 // will be returned inside the commit that replaces them.
646 bool force_disable_reclaim_resources = false;
danakj1120f4c2016-09-15 02:05:32647 return base::MakeUnique<TestCompositorFrameSink>(
danakj014316e2016-08-04 18:40:26648 compositor_context_provider, std::move(worker_context_provider),
danakj014316e2016-08-04 18:40:26649 shared_bitmap_manager(), gpu_memory_buffer_manager(),
khushalsagarcebe4942016-09-07 23:27:01650 layer_tree_host()->GetSettings().renderer_settings,
ericrk4b443522017-01-13 22:54:24651 ImplThreadTaskRunner(), synchronous_composite,
652 force_disable_reclaim_resources);
danakj014316e2016-08-04 18:40:26653 }
[email protected]28571b042013-03-14 07:59:15654
ericrkad5923812017-01-25 23:26:12655 void AdvanceTestCase() {
656 ++test_case_;
657 switch (test_case_) {
658 case 1:
659 // Case #1: change mailbox before the commit. The old mailbox should be
660 // released immediately.
661 SetMailbox('2');
662 EXPECT_EQ(1, callback_count_);
663 PostSetNeedsCommitToMainThread();
664
665 // Case 2 does not rely on callbacks to advance.
666 pending_callback_ = false;
667 break;
668 case 2:
669 // Case #2: change mailbox after the commit (and draw), where the
670 // layer draws. The old mailbox should be released during the next
671 // commit.
672 SetMailbox('3');
673 EXPECT_EQ(1, callback_count_);
674
675 // Cases 3-5 rely on a callback to advance.
676 pending_callback_ = true;
677 break;
678 case 3:
679 EXPECT_EQ(2, callback_count_);
680 // Case #3: change mailbox when the layer doesn't draw. The old
681 // mailbox should be released during the next commit.
682 layer_->SetBounds(gfx::Size());
683 SetMailbox('4');
684 break;
685 case 4:
686 EXPECT_EQ(3, callback_count_);
687 // Case #4: release mailbox that was committed but never drawn. The
688 // old mailbox should be released during the next commit.
689 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
690 break;
691 case 5:
692 EXPECT_EQ(4, callback_count_);
693 // Restore a mailbox for the next step.
694 SetMailbox('5');
695
696 // Cases 6 and 7 do not rely on callbacks to advance.
697 pending_callback_ = false;
698 break;
699 case 6:
700 // Case #5: remove layer from tree. Callback should *not* be called, the
701 // mailbox is returned to the main thread.
702 EXPECT_EQ(4, callback_count_);
703 layer_->RemoveFromParent();
704 break;
705 case 7:
706 EXPECT_EQ(4, callback_count_);
707 // Resetting the mailbox will call the callback now.
708 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
709 EXPECT_EQ(5, callback_count_);
710 EndTest();
711 break;
712 default:
713 NOTREACHED();
714 break;
715 }
716 }
717
[email protected]28571b042013-03-14 07:59:15718 // Make sure callback is received on main and doesn't block the impl thread.
danakj014316e2016-08-04 18:40:26719 void ReleaseCallback(char mailbox_char,
720 const gpu::SyncToken& sync_token,
721 bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:59722 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]7ba3ca72013-04-11 06:37:25723 EXPECT_FALSE(lost_resource);
[email protected]28571b042013-03-14 07:59:15724 ++callback_count_;
ericrkad5923812017-01-25 23:26:12725
726 // If we are waiting on a callback, advance now.
727 if (pending_callback_)
728 AdvanceTestCase();
[email protected]28571b042013-03-14 07:59:15729 }
730
731 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:59732 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:48733 std::unique_ptr<SingleReleaseCallback> callback =
734 SingleReleaseCallback::Create(base::Bind(
[email protected]28571b042013-03-14 07:59:15735 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback,
danakj014316e2016-08-04 18:40:26736 base::Unretained(this), mailbox_char));
dyene5db881b2016-03-01 19:47:03737 layer_->SetTextureMailbox(
738 TextureMailbox(MailboxFromChar(mailbox_char),
739 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
740 GL_TEXTURE_2D),
741 std::move(callback));
danakj014316e2016-08-04 18:40:26742 // Damage the layer so we send a new frame with the new mailbox to the
743 // Display compositor.
744 layer_->SetNeedsDisplay();
[email protected]28571b042013-03-14 07:59:15745 }
746
dcheng716bedf2014-10-21 09:51:08747 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:59748 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
749
[email protected]28571b042013-03-14 07:59:15750 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31751 root_ = Layer::Create();
[email protected]28571b042013-03-14 07:59:15752 root_->SetBounds(bounds);
753
loyso0940d412016-03-14 01:30:31754 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]28571b042013-03-14 07:59:15755 layer_->SetIsDrawable(true);
[email protected]28571b042013-03-14 07:59:15756 layer_->SetBounds(bounds);
757
758 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:07759 layer_tree_host()->SetRootLayer(root_);
760 layer_tree_host()->SetViewportSize(bounds);
[email protected]28571b042013-03-14 07:59:15761 SetMailbox('1');
762 EXPECT_EQ(0, callback_count_);
763
ericrkad5923812017-01-25 23:26:12764 // Setup is complete - advance to test case 1.
765 AdvanceTestCase();
[email protected]28571b042013-03-14 07:59:15766 }
767
dcheng716bedf2014-10-21 09:51:08768 void DidCommit() override {
ericrkad5923812017-01-25 23:26:12769 // If we are not waiting on a callback, advance now.
770 if (!pending_callback_)
771 AdvanceTestCase();
[email protected]28571b042013-03-14 07:59:15772 }
[email protected]de44a152013-01-08 15:28:46773
dcheng716bedf2014-10-21 09:51:08774 void AfterTest() override {}
[email protected]de44a152013-01-08 15:28:46775
[email protected]28571b042013-03-14 07:59:15776 private:
[email protected]9794fb32013-08-29 09:49:59777 base::ThreadChecker main_thread_;
danakj014316e2016-08-04 18:40:26778 int callback_count_ = 0;
ericrkad5923812017-01-25 23:26:12779 int test_case_ = 0;
780 // Whether we are waiting on a callback to advance the test case.
781 bool pending_callback_ = false;
[email protected]28571b042013-03-14 07:59:15782 scoped_refptr<Layer> root_;
783 scoped_refptr<TextureLayer> layer_;
[email protected]de44a152013-01-08 15:28:46784};
785
danakj0943a112016-08-11 00:33:46786SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
[email protected]74b43cc2013-08-30 06:29:27787
[email protected]74b43cc2013-08-30 06:29:27788class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest {
789 protected:
[email protected]98ea818e2014-01-24 10:22:08790 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {}
[email protected]74b43cc2013-08-30 06:29:27791
dyene5db881b2016-03-01 19:47:03792 static void ReleaseCallback(const gpu::SyncToken& original_sync_token,
793 const gpu::SyncToken& release_sync_token,
dyencc16ed4d2015-11-03 20:03:04794 bool lost_resource) {}
[email protected]74b43cc2013-08-30 06:29:27795
796 void SetMailbox(char mailbox_char) {
dyene5db881b2016-03-01 19:47:03797 const gpu::SyncToken sync_token =
798 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char));
danakj60bc3bc2016-04-09 00:24:48799 std::unique_ptr<SingleReleaseCallback> callback =
800 SingleReleaseCallback::Create(base::Bind(
801 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback,
802 sync_token));
dyencc16ed4d2015-11-03 20:03:04803 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char),
dyene5db881b2016-03-01 19:47:03804 sync_token, GL_TEXTURE_2D),
danakja04855a2015-11-18 20:39:10805 std::move(callback));
[email protected]74b43cc2013-08-30 06:29:27806 }
807
dcheng716bedf2014-10-21 09:51:08808 void BeginTest() override {
[email protected]74b43cc2013-08-30 06:29:27809 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31810 root_ = Layer::Create();
[email protected]74b43cc2013-08-30 06:29:27811 root_->SetBounds(bounds);
812
loyso0940d412016-03-14 01:30:31813 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]74b43cc2013-08-30 06:29:27814 layer_->SetIsDrawable(true);
[email protected]74b43cc2013-08-30 06:29:27815 layer_->SetBounds(bounds);
816
817 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:07818 layer_tree_host()->SetRootLayer(root_);
819 layer_tree_host()->SetViewportSize(bounds);
[email protected]74b43cc2013-08-30 06:29:27820 SetMailbox('1');
821
822 PostSetNeedsCommitToMainThread();
823 }
824
dcheng716bedf2014-10-21 09:51:08825 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
danakj3c3973b2015-08-25 21:50:18826 base::AutoLock lock(activate_count_lock_);
[email protected]74b43cc2013-08-30 06:29:27827 ++activate_count_;
828 }
829
dcheng716bedf2014-10-21 09:51:08830 void DidCommit() override {
danakj3c3973b2015-08-25 21:50:18831 // The first frame doesn't cause anything to be returned so it does not
832 // need to wait for activation.
khushalsagarcebe4942016-09-07 23:27:01833 if (layer_tree_host()->SourceFrameNumber() > 1) {
danakj3c3973b2015-08-25 21:50:18834 base::AutoLock lock(activate_count_lock_);
835 // The activate happened before commit is done on the main side.
khushalsagarcebe4942016-09-07 23:27:01836 EXPECT_EQ(activate_count_, layer_tree_host()->SourceFrameNumber());
danakj3c3973b2015-08-25 21:50:18837 }
838
khushalsagarcebe4942016-09-07 23:27:01839 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]74b43cc2013-08-30 06:29:27840 case 1:
841 // The first mailbox has been activated. Set a new mailbox, and
842 // expect the next commit to finish *after* it is activated.
843 SetMailbox('2');
[email protected]74b43cc2013-08-30 06:29:27844 break;
845 case 2:
846 // The second mailbox has been activated. Remove the layer from
847 // the tree to cause another commit/activation. The commit should
848 // finish *after* the layer is removed from the active tree.
849 layer_->RemoveFromParent();
[email protected]74b43cc2013-08-30 06:29:27850 break;
851 case 3:
852 EndTest();
853 break;
854 }
855 }
856
dcheng716bedf2014-10-21 09:51:08857 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
danakj3c3973b2015-08-25 21:50:18858 // The activate didn't happen before commit is done on the impl side (but it
859 // should happen before the main thread is done).
860 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number());
[email protected]74b43cc2013-08-30 06:29:27861 }
862
dcheng716bedf2014-10-21 09:51:08863 void AfterTest() override {}
[email protected]74b43cc2013-08-30 06:29:27864
danakj3c3973b2015-08-25 21:50:18865 base::Lock activate_count_lock_;
[email protected]74b43cc2013-08-30 06:29:27866 int activate_count_;
867 scoped_refptr<Layer> root_;
868 scoped_refptr<TextureLayer> layer_;
869};
870
tsergeantf41fd0f2016-09-29 00:20:39871// Flaky on windows and linux. https://crbug.com/641613
872#if !defined(OS_WIN) && !defined(OS_LINUX)
danakj0943a112016-08-11 00:33:46873SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
dgroganf22b7692016-08-30 23:24:08874#endif
[email protected]74b43cc2013-08-30 06:29:27875
[email protected]de44a152013-01-08 15:28:46876class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15877 protected:
dcheng93a52eb2014-12-23 02:14:23878 void SetUp() override {
[email protected]28571b042013-03-14 07:59:15879 TextureLayerTest::SetUp();
loyso2cb3f32f2016-11-08 07:08:34880 layer_tree_host_ = MockLayerTreeHost::Create(
881 &fake_client_, &task_graph_runner_, animation_host_.get());
sievers71c62dd52015-10-07 01:44:39882 host_impl_.SetVisible(true);
danakj1120f4c2016-09-15 02:05:32883 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get()));
[email protected]28571b042013-03-14 07:59:15884 }
[email protected]de44a152013-01-08 15:28:46885
[email protected]0ec335c42013-07-04 06:17:08886 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
887 bool will_draw = layer->WillDraw(
888 mode, host_impl_.active_tree()->resource_provider());
889 if (will_draw)
890 layer->DidDraw(host_impl_.active_tree()->resource_provider());
891 return will_draw;
892 }
893
[email protected]408b5e22013-03-19 09:48:09894 FakeLayerTreeHostClient fake_client_;
[email protected]de44a152013-01-08 15:28:46895};
896
[email protected]ffbb2212013-06-02 23:47:59897// Test conditions for results of TextureLayerImpl::WillDraw under
898// different configurations of different mailbox, texture_id, and draw_mode.
899TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
skyostil3976a3f2014-09-04 22:07:23900 EXPECT_CALL(
901 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04902 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]0ec335c42013-07-04 06:17:08903 .Times(AnyNumber());
dyencc16ed4d2015-11-03 20:03:04904 EXPECT_CALL(
905 test_data_.mock_callback_,
906 ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _))
[email protected]0ec335c42013-07-04 06:17:08907 .Times(AnyNumber());
[email protected]ffbb2212013-06-02 23:47:59908 // Hardware mode.
909 {
danakj60bc3bc2016-04-09 00:24:48910 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11911 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16912 impl_layer->SetTextureMailbox(
913 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23914 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08915 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59916 }
917
918 {
danakj60bc3bc2016-04-09 00:24:48919 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11920 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16921 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08922 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
923 }
924
925 {
926 // Software resource.
danakj60bc3bc2016-04-09 00:24:48927 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11928 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16929 impl_layer->SetTextureMailbox(
930 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23931 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]3e44d7a2013-07-30 00:03:10932 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59933 }
934
[email protected]0ec335c42013-07-04 06:17:08935 // Software mode.
936 {
danakj60bc3bc2016-04-09 00:24:48937 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11938 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16939 impl_layer->SetTextureMailbox(
940 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23941 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08942 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
943 }
944
945 {
danakj60bc3bc2016-04-09 00:24:48946 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11947 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16948 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08949 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
950 }
951
952 {
953 // Software resource.
danakj60bc3bc2016-04-09 00:24:48954 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11955 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16956 impl_layer->SetTextureMailbox(
957 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23958 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]0ec335c42013-07-04 06:17:08959 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
960 }
961
[email protected]ffbb2212013-06-02 23:47:59962 // Resourceless software mode.
963 {
danakj60bc3bc2016-04-09 00:24:48964 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11965 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16966 impl_layer->SetTextureMailbox(
967 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23968 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08969 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
[email protected]ffbb2212013-06-02 23:47:59970 }
[email protected]ffbb2212013-06-02 23:47:59971}
972
[email protected]28571b042013-03-14 07:59:15973TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
974 host_impl_.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:48975 std::unique_ptr<TextureLayerImpl> pending_layer;
[email protected]17e08432014-04-10 00:41:11976 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1);
[email protected]28571b042013-03-14 07:59:15977 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46978
danakj60bc3bc2016-04-09 00:24:48979 std::unique_ptr<LayerImpl> active_layer(
[email protected]28571b042013-03-14 07:59:15980 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
[email protected]ed511b8d2013-03-25 03:29:29981 ASSERT_TRUE(active_layer);
[email protected]de44a152013-01-08 15:28:46982
[email protected]9260757f2013-09-17 01:24:16983 pending_layer->SetTextureMailbox(
984 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23985 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]421e84f2013-02-22 03:27:15986
[email protected]28571b042013-03-14 07:59:15987 // Test multiple commits without an activation.
skyostil3976a3f2014-09-04 22:07:23988 EXPECT_CALL(
989 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04990 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:15991 .Times(1);
[email protected]9260757f2013-09-17 01:24:16992 pending_layer->SetTextureMailbox(
993 test_data_.mailbox2_,
skyostil3976a3f2014-09-04 22:07:23994 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_));
[email protected]28571b042013-03-14 07:59:15995 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15996
[email protected]28571b042013-03-14 07:59:15997 // Test callback after activation.
[email protected]ed511b8d2013-03-25 03:29:29998 pending_layer->PushPropertiesTo(active_layer.get());
999 active_layer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:151000
skyostil3976a3f2014-09-04 22:07:231001 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]9260757f2013-09-17 01:24:161002 pending_layer->SetTextureMailbox(
1003 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231004 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151005 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:151006
[email protected]7ba3ca72013-04-11 06:37:251007 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231008 ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1);
[email protected]ed511b8d2013-03-25 03:29:291009 pending_layer->PushPropertiesTo(active_layer.get());
1010 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:151011 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:461012
[email protected]28571b042013-03-14 07:59:151013 // Test resetting the mailbox.
[email protected]7ba3ca72013-04-11 06:37:251014 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231015 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
danakj968153f32014-10-15 22:52:161016 pending_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]ed511b8d2013-03-25 03:29:291017 pending_layer->PushPropertiesTo(active_layer.get());
1018 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:151019 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:461020
[email protected]28571b042013-03-14 07:59:151021 // Test destructor.
skyostil3976a3f2014-09-04 22:07:231022 EXPECT_CALL(
1023 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:041024 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:151025 .Times(1);
[email protected]9260757f2013-09-17 01:24:161026 pending_layer->SetTextureMailbox(
1027 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231028 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]de44a152013-01-08 15:28:461029}
1030
[email protected]28571b042013-03-14 07:59:151031TEST_F(TextureLayerImplWithMailboxTest,
1032 TestDestructorCallbackOnCreatedResource) {
danakj60bc3bc2016-04-09 00:24:481033 std::unique_ptr<TextureLayerImpl> impl_layer;
[email protected]17e08432014-04-10 00:41:111034 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]28571b042013-03-14 07:59:151035 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:461036
[email protected]7ba3ca72013-04-11 06:37:251037 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231038 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]9260757f2013-09-17 01:24:161039 impl_layer->SetTextureMailbox(
1040 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231041 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]ffbb2212013-06-02 23:47:591042 impl_layer->DidBecomeActive();
1043 EXPECT_TRUE(impl_layer->WillDraw(
1044 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider()));
[email protected]28571b042013-03-14 07:59:151045 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
danakj968153f32014-10-15 22:52:161046 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]de44a152013-01-08 15:28:461047}
1048
[email protected]28571b042013-03-14 07:59:151049TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
1050 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
jbaumanbbd425e2015-05-19 00:33:351051 ResourceId id = provider->CreateResourceFromTextureMailbox(
skyostil3976a3f2014-09-04 22:07:231052 test_data_.mailbox1_,
1053 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151054 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:461055
[email protected]28571b042013-03-14 07:59:151056 // Transfer some resources to the parent.
1057 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1058 resource_ids_to_transfer.push_back(id);
1059 TransferableResourceArray list;
1060 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
1061 EXPECT_TRUE(provider->InUseByConsumer(id));
skyostil3976a3f2014-09-04 22:07:231062 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]28571b042013-03-14 07:59:151063 provider->DeleteResource(id);
1064 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]7ba3ca72013-04-11 06:37:251065 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231066 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]e00bab022013-08-19 00:42:451067 ReturnedResourceArray returned;
1068 TransferableResource::ReturnResources(list, &returned);
1069 provider->ReceiveReturnsFromParent(returned);
[email protected]de44a152013-01-08 15:28:461070}
1071
[email protected]4bad8b62013-10-24 01:27:291072// Checks that TextureLayer::Update does not cause an extra commit when setting
1073// the texture mailbox.
1074class TextureLayerNoExtraCommitForMailboxTest
1075 : public LayerTreeTest,
1076 public TextureLayerClient {
1077 public:
[email protected]4bad8b62013-10-24 01:27:291078 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081079 bool PrepareTextureMailbox(
[email protected]df41e252014-02-03 23:39:501080 TextureMailbox* texture_mailbox,
danakj4d0dd802016-08-23 22:10:061081 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
khushalsagarcebe4942016-09-07 23:27:011082 if (layer_tree_host()->SourceFrameNumber() == 1) {
[email protected]9f35bd22014-06-03 15:25:461083 // Once this has been committed, the mailbox will be released.
[email protected]df41e252014-02-03 23:39:501084 *texture_mailbox = TextureMailbox();
[email protected]cce34bd2013-12-02 23:24:451085 return true;
1086 }
[email protected]4bad8b62013-10-24 01:27:291087
dyene5db881b2016-03-01 19:47:031088 *texture_mailbox = TextureMailbox(MailboxFromChar('1'),
1089 SyncTokenFromUInt(0x123), GL_TEXTURE_2D);
[email protected]4bad8b62013-10-24 01:27:291090 *release_callback = SingleReleaseCallback::Create(
1091 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased,
1092 base::Unretained(this)));
[email protected]4bad8b62013-10-24 01:27:291093 return true;
1094 }
1095
dyencc16ed4d2015-11-03 20:03:041096 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031097 EXPECT_TRUE(sync_token.HasData());
[email protected]cce34bd2013-12-02 23:24:451098 EndTest();
[email protected]4bad8b62013-10-24 01:27:291099 }
1100
dcheng716bedf2014-10-21 09:51:081101 void SetupTree() override {
loyso0940d412016-03-14 01:30:311102 scoped_refptr<Layer> root = Layer::Create();
[email protected]4bad8b62013-10-24 01:27:291103 root->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291104 root->SetIsDrawable(true);
1105
loyso0940d412016-03-14 01:30:311106 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]4bad8b62013-10-24 01:27:291107 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291108 texture_layer_->SetIsDrawable(true);
[email protected]0d7fb302014-01-23 21:30:471109 root->AddChild(texture_layer_);
[email protected]4bad8b62013-10-24 01:27:291110
khushalsagarb69ba9452017-01-27 22:20:071111 layer_tree_host()->SetRootLayer(root);
[email protected]4bad8b62013-10-24 01:27:291112 LayerTreeTest::SetupTree();
1113 }
1114
dcheng716bedf2014-10-21 09:51:081115 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]4bad8b62013-10-24 01:27:291116
dcheng716bedf2014-10-21 09:51:081117 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011118 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]4bad8b62013-10-24 01:27:291119 case 1:
[email protected]4ea293f72014-08-13 03:03:171120 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
[email protected]cce34bd2013-12-02 23:24:451121 // Invalidate the texture layer to clear the mailbox before
1122 // ending the test.
1123 texture_layer_->SetNeedsDisplay();
1124 break;
1125 case 2:
[email protected]4bad8b62013-10-24 01:27:291126 break;
1127 default:
1128 NOTREACHED();
1129 break;
1130 }
1131 }
1132
dcheng716bedf2014-10-21 09:51:081133 void AfterTest() override {}
[email protected]4bad8b62013-10-24 01:27:291134
1135 private:
[email protected]4bad8b62013-10-24 01:27:291136 scoped_refptr<TextureLayer> texture_layer_;
[email protected]4bad8b62013-10-24 01:27:291137};
1138
[email protected]cce34bd2013-12-02 23:24:451139SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);
[email protected]4bad8b62013-10-24 01:27:291140
[email protected]b04264f92013-09-13 23:37:291141// Checks that changing a mailbox in the client for a TextureLayer that's
1142// invisible correctly works and uses the new mailbox as soon as the layer
1143// becomes visible (and returns the old one).
1144class TextureLayerChangeInvisibleMailboxTest
1145 : public LayerTreeTest,
1146 public TextureLayerClient {
1147 public:
1148 TextureLayerChangeInvisibleMailboxTest()
1149 : mailbox_changed_(true),
1150 mailbox_returned_(0),
1151 prepare_called_(0),
1152 commit_count_(0) {
1153 mailbox_ = MakeMailbox('1');
1154 }
1155
1156 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081157 bool PrepareTextureMailbox(
[email protected]e51444a2013-12-10 23:05:011158 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061159 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]b04264f92013-09-13 23:37:291160 ++prepare_called_;
1161 if (!mailbox_changed_)
1162 return false;
1163 *mailbox = mailbox_;
[email protected]9260757f2013-09-17 01:24:161164 *release_callback = SingleReleaseCallback::Create(
1165 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased,
1166 base::Unretained(this)));
[email protected]b04264f92013-09-13 23:37:291167 return true;
1168 }
1169
1170 TextureMailbox MakeMailbox(char name) {
dyene5db881b2016-03-01 19:47:031171 return TextureMailbox(MailboxFromChar(name),
1172 SyncTokenFromUInt(static_cast<uint32_t>(name)),
dyencc16ed4d2015-11-03 20:03:041173 GL_TEXTURE_2D);
[email protected]b04264f92013-09-13 23:37:291174 }
1175
dyencc16ed4d2015-11-03 20:03:041176 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031177 EXPECT_TRUE(sync_token.HasData());
[email protected]b04264f92013-09-13 23:37:291178 ++mailbox_returned_;
1179 }
1180
dcheng716bedf2014-10-21 09:51:081181 void SetupTree() override {
loyso0940d412016-03-14 01:30:311182 scoped_refptr<Layer> root = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291183 root->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291184 root->SetIsDrawable(true);
1185
loyso0940d412016-03-14 01:30:311186 solid_layer_ = SolidColorLayer::Create();
[email protected]b04264f92013-09-13 23:37:291187 solid_layer_->SetBounds(gfx::Size(10, 10));
1188 solid_layer_->SetIsDrawable(true);
1189 solid_layer_->SetBackgroundColor(SK_ColorWHITE);
1190 root->AddChild(solid_layer_);
1191
loyso0940d412016-03-14 01:30:311192 parent_layer_ = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291193 parent_layer_->SetBounds(gfx::Size(10, 10));
1194 parent_layer_->SetIsDrawable(true);
1195 root->AddChild(parent_layer_);
1196
loyso0940d412016-03-14 01:30:311197 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]b04264f92013-09-13 23:37:291198 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291199 texture_layer_->SetIsDrawable(true);
1200 parent_layer_->AddChild(texture_layer_);
1201
khushalsagarb69ba9452017-01-27 22:20:071202 layer_tree_host()->SetRootLayer(root);
[email protected]b04264f92013-09-13 23:37:291203 LayerTreeTest::SetupTree();
1204 }
1205
dcheng716bedf2014-10-21 09:51:081206 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]b04264f92013-09-13 23:37:291207
dcheng716bedf2014-10-21 09:51:081208 void DidCommitAndDrawFrame() override {
[email protected]b04264f92013-09-13 23:37:291209 ++commit_count_;
1210 switch (commit_count_) {
1211 case 1:
1212 // We should have updated the layer, committing the texture.
1213 EXPECT_EQ(1, prepare_called_);
1214 // Make layer invisible.
1215 parent_layer_->SetOpacity(0.f);
1216 break;
1217 case 2:
1218 // Layer shouldn't have been updated.
1219 EXPECT_EQ(1, prepare_called_);
1220 // Change the texture.
1221 mailbox_ = MakeMailbox('2');
1222 mailbox_changed_ = true;
1223 texture_layer_->SetNeedsDisplay();
1224 // Force a change to make sure we draw a frame.
1225 solid_layer_->SetBackgroundColor(SK_ColorGRAY);
1226 break;
1227 case 3:
1228 // Layer shouldn't have been updated.
1229 EXPECT_EQ(1, prepare_called_);
1230 // So the old mailbox isn't returned yet.
1231 EXPECT_EQ(0, mailbox_returned_);
1232 // Make layer visible again.
jaydasikacf223762016-05-16 23:02:091233 parent_layer_->SetOpacity(0.9f);
[email protected]b04264f92013-09-13 23:37:291234 break;
1235 case 4:
1236 // Layer should have been updated.
1237 EXPECT_EQ(2, prepare_called_);
1238 // So the old mailbox should have been returned already.
1239 EXPECT_EQ(1, mailbox_returned_);
1240 texture_layer_->ClearClient();
1241 break;
1242 case 5:
1243 EXPECT_EQ(2, mailbox_returned_);
1244 EndTest();
1245 break;
1246 default:
1247 NOTREACHED();
1248 break;
1249 }
1250 }
1251
dcheng716bedf2014-10-21 09:51:081252 void AfterTest() override {}
[email protected]b04264f92013-09-13 23:37:291253
1254 private:
1255 scoped_refptr<SolidColorLayer> solid_layer_;
1256 scoped_refptr<Layer> parent_layer_;
1257 scoped_refptr<TextureLayer> texture_layer_;
1258
1259 // Used on the main thread.
1260 bool mailbox_changed_;
1261 TextureMailbox mailbox_;
1262 int mailbox_returned_;
1263 int prepare_called_;
1264 int commit_count_;
1265};
1266
1267SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
1268
[email protected]0d7fb302014-01-23 21:30:471269// Test that TextureLayerImpl::ReleaseResources can be called which releases
1270// the mailbox back to TextureLayerClient.
1271class TextureLayerReleaseResourcesBase
1272 : public LayerTreeTest,
1273 public TextureLayerClient {
1274 public:
1275 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081276 bool PrepareTextureMailbox(
[email protected]0d7fb302014-01-23 21:30:471277 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061278 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
dyene5db881b2016-03-01 19:47:031279 *mailbox = TextureMailbox(MailboxFromChar('1'), SyncTokenFromUInt(1),
1280 GL_TEXTURE_2D);
[email protected]0d7fb302014-01-23 21:30:471281 *release_callback = SingleReleaseCallback::Create(
1282 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased,
1283 base::Unretained(this)));
1284 return true;
1285 }
1286
dyencc16ed4d2015-11-03 20:03:041287 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]0d7fb302014-01-23 21:30:471288 mailbox_released_ = true;
1289 }
1290
dcheng716bedf2014-10-21 09:51:081291 void SetupTree() override {
[email protected]0d7fb302014-01-23 21:30:471292 LayerTreeTest::SetupTree();
1293
1294 scoped_refptr<TextureLayer> texture_layer =
loyso0940d412016-03-14 01:30:311295 TextureLayer::CreateForMailbox(this);
[email protected]0d7fb302014-01-23 21:30:471296 texture_layer->SetBounds(gfx::Size(10, 10));
[email protected]0d7fb302014-01-23 21:30:471297 texture_layer->SetIsDrawable(true);
1298
khushalsagarb69ba9452017-01-27 22:20:071299 layer_tree_host()->root_layer()->AddChild(texture_layer);
jaydasikabd6f15a2016-04-21 19:45:371300 texture_layer_id_ = texture_layer->id();
[email protected]0d7fb302014-01-23 21:30:471301 }
1302
dcheng716bedf2014-10-21 09:51:081303 void BeginTest() override {
[email protected]0d7fb302014-01-23 21:30:471304 mailbox_released_ = false;
1305 PostSetNeedsCommitToMainThread();
1306 }
1307
dcheng716bedf2014-10-21 09:51:081308 void DidCommitAndDrawFrame() override { EndTest(); }
[email protected]0d7fb302014-01-23 21:30:471309
dcheng716bedf2014-10-21 09:51:081310 void AfterTest() override { EXPECT_TRUE(mailbox_released_); }
[email protected]0d7fb302014-01-23 21:30:471311
jaydasikabd6f15a2016-04-21 19:45:371312 protected:
1313 int texture_layer_id_;
1314
[email protected]0d7fb302014-01-23 21:30:471315 private:
1316 bool mailbox_released_;
1317};
1318
1319class TextureLayerReleaseResourcesAfterCommit
1320 : public TextureLayerReleaseResourcesBase {
1321 public:
dcheng716bedf2014-10-21 09:51:081322 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
kulkarni.a4015690f12014-10-10 13:50:061323 LayerTreeImpl* tree = nullptr;
danakj009cdfdf2015-02-17 22:35:141324 tree = host_impl->sync_tree();
jaydasikabd6f15a2016-04-21 19:45:371325 tree->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471326 }
1327};
1328
1329SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);
1330
1331class TextureLayerReleaseResourcesAfterActivate
1332 : public TextureLayerReleaseResourcesBase {
1333 public:
dcheng716bedf2014-10-21 09:51:081334 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
jaydasikabd6f15a2016-04-21 19:45:371335 host_impl->active_tree()->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471336 }
1337};
1338
1339SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);
1340
[email protected]9c2bd822013-07-26 12:30:171341class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest {
1342 public:
dyencc16ed4d2015-11-03 20:03:041343 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591344 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171345 EXPECT_FALSE(lost_resource);
1346 ++callback_count_;
1347 EndTest();
1348 }
1349
1350 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591351 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481352 std::unique_ptr<SingleReleaseCallback> callback =
1353 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171354 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback,
1355 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031356 layer_->SetTextureMailbox(
1357 TextureMailbox(MailboxFromChar(mailbox_char),
1358 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1359 GL_TEXTURE_2D),
1360 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171361 }
1362
dcheng716bedf2014-10-21 09:51:081363 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171364 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311365 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171366 root_->SetBounds(bounds);
1367
loyso0940d412016-03-14 01:30:311368 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171369 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171370 layer_->SetBounds(bounds);
1371
1372 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:071373 layer_tree_host()->SetRootLayer(root_);
1374 layer_tree_host()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171375 }
1376
dcheng716bedf2014-10-21 09:51:081377 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591378 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1379
[email protected]9c2bd822013-07-26 12:30:171380 callback_count_ = 0;
1381
1382 // Set the mailbox on the main thread.
1383 SetMailbox('1');
1384 EXPECT_EQ(0, callback_count_);
1385
1386 PostSetNeedsCommitToMainThread();
1387 }
1388
dcheng716bedf2014-10-21 09:51:081389 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011390 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171391 case 1:
1392 // Delete the TextureLayer on the main thread while the mailbox is in
1393 // the impl tree.
1394 layer_->RemoveFromParent();
kulkarni.a4015690f12014-10-10 13:50:061395 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171396 break;
1397 }
1398 }
1399
dcheng716bedf2014-10-21 09:51:081400 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171401
1402 private:
[email protected]9794fb32013-08-29 09:49:591403 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171404 int callback_count_;
1405 scoped_refptr<Layer> root_;
1406 scoped_refptr<TextureLayer> layer_;
1407};
1408
danakj0943a112016-08-11 00:33:461409SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxMainThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171410
1411class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest {
1412 public:
dyencc16ed4d2015-11-03 20:03:041413 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591414 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171415 EXPECT_FALSE(lost_resource);
1416 ++callback_count_;
1417 EndTest();
1418 }
1419
1420 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591421 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481422 std::unique_ptr<SingleReleaseCallback> callback =
1423 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171424 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback,
1425 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031426 layer_->SetTextureMailbox(
1427 TextureMailbox(MailboxFromChar(mailbox_char),
1428 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1429 GL_TEXTURE_2D),
1430 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171431 }
1432
dcheng716bedf2014-10-21 09:51:081433 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171434 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311435 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171436 root_->SetBounds(bounds);
1437
loyso0940d412016-03-14 01:30:311438 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171439 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171440 layer_->SetBounds(bounds);
1441
1442 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:071443 layer_tree_host()->SetRootLayer(root_);
1444 layer_tree_host()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171445 }
1446
dcheng716bedf2014-10-21 09:51:081447 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591448 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1449
[email protected]9c2bd822013-07-26 12:30:171450 callback_count_ = 0;
1451
1452 // Set the mailbox on the main thread.
1453 SetMailbox('1');
1454 EXPECT_EQ(0, callback_count_);
1455
1456 PostSetNeedsCommitToMainThread();
1457 }
1458
dcheng716bedf2014-10-21 09:51:081459 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011460 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171461 case 1:
1462 // Remove the TextureLayer on the main thread while the mailbox is in
1463 // the impl tree, but don't delete the TextureLayer until after the impl
1464 // tree side is deleted.
1465 layer_->RemoveFromParent();
1466 break;
1467 case 2:
kulkarni.a4015690f12014-10-10 13:50:061468 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171469 break;
1470 }
1471 }
1472
dcheng716bedf2014-10-21 09:51:081473 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171474
1475 private:
[email protected]9794fb32013-08-29 09:49:591476 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171477 int callback_count_;
1478 scoped_refptr<Layer> root_;
1479 scoped_refptr<TextureLayer> layer_;
1480};
1481
danakj0943a112016-08-11 00:33:461482SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171483
[email protected]ba565742012-11-10 09:29:481484} // namespace
1485} // namespace cc