blob: a13964af827ea53715e443860747817dc3d107c1 [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;
79 params.settings = &settings;
danakjffc181a2016-07-22 22:48:4380 return base::WrapUnique(new MockLayerTreeHost(&params));
[email protected]28571b042013-03-14 07:59:1581 }
[email protected]c0dd24c2012-08-30 23:25:2782
[email protected]28571b042013-03-14 07:59:1583 MOCK_METHOD0(SetNeedsCommit, void());
[email protected]3519b872013-07-30 07:17:5084 MOCK_METHOD0(SetNeedsUpdateLayers, void());
[email protected]aeeb3372013-11-05 14:05:5485 MOCK_METHOD0(StartRateLimiter, void());
86 MOCK_METHOD0(StopRateLimiter, void());
sadrul6780f3da2015-05-11 17:01:5287
88 private:
khushalsagare0e4486e2017-01-25 03:15:0389 explicit MockLayerTreeHost(LayerTreeHost::InitParams* params)
90 : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) {
danakjffc181a2016-07-22 22:48:4391 InitializeSingleThreaded(&single_thread_client_,
enne2b0ad682016-09-21 01:44:4792 base::ThreadTaskRunnerHandle::Get());
sadrul6780f3da2015-05-11 17:01:5293 }
danakjffc181a2016-07-22 22:48:4394
95 StubLayerTreeHostSingleThreadClient single_thread_client_;
[email protected]c0dd24c2012-08-30 23:25:2796};
97
[email protected]d72d9e02014-04-03 18:40:0998class FakeTextureLayerClient : public TextureLayerClient {
99 public:
[email protected]17e08432014-04-10 00:41:11100 FakeTextureLayerClient() : mailbox_changed_(true) {}
[email protected]d72d9e02014-04-03 18:40:09101
dcheng716bedf2014-10-21 09:51:08102 bool PrepareTextureMailbox(
[email protected]d72d9e02014-04-03 18:40:09103 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:06104 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]d72d9e02014-04-03 18:40:09105 if (!mailbox_changed_)
106 return false;
107
108 *mailbox = mailbox_;
danakja04855a2015-11-18 20:39:10109 *release_callback = std::move(release_callback_);
[email protected]d72d9e02014-04-03 18:40:09110 mailbox_changed_ = false;
111 return true;
112 }
113
[email protected]d72d9e02014-04-03 18:40:09114 void set_mailbox(const TextureMailbox& mailbox,
danakj60bc3bc2016-04-09 00:24:48115 std::unique_ptr<SingleReleaseCallback> release_callback) {
[email protected]d72d9e02014-04-03 18:40:09116 mailbox_ = mailbox;
danakja04855a2015-11-18 20:39:10117 release_callback_ = std::move(release_callback);
[email protected]d72d9e02014-04-03 18:40:09118 mailbox_changed_ = true;
119 }
120
121 private:
[email protected]d72d9e02014-04-03 18:40:09122 TextureMailbox mailbox_;
danakj60bc3bc2016-04-09 00:24:48123 std::unique_ptr<SingleReleaseCallback> release_callback_;
[email protected]d72d9e02014-04-03 18:40:09124 bool mailbox_changed_;
125 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient);
126};
127
128class MockMailboxCallback {
129 public:
130 MOCK_METHOD3(Release,
131 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04132 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09133 bool lost_resource));
134 MOCK_METHOD3(Release2,
jbauman9015c8b2014-12-11 00:49:37135 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04136 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09137 bool lost_resource));
skyostil3976a3f2014-09-04 22:07:23138 MOCK_METHOD4(ReleaseImpl,
139 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04140 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23141 bool lost_resource,
142 BlockingTaskRunner* main_thread_task_runner));
143 MOCK_METHOD4(ReleaseImpl2,
jbauman9015c8b2014-12-11 00:49:37144 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04145 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23146 bool lost_resource,
147 BlockingTaskRunner* main_thread_task_runner));
[email protected]d72d9e02014-04-03 18:40:09148};
149
150struct CommonMailboxObjects {
jbauman9015c8b2014-12-11 00:49:37151 explicit CommonMailboxObjects(SharedBitmapManager* manager)
[email protected]d72d9e02014-04-03 18:40:09152 : mailbox_name1_(MailboxFromChar('1')),
153 mailbox_name2_(MailboxFromChar('2')),
lukasza2573ce7d2016-02-16 19:17:22154 sync_token1_(gpu::CommandBufferNamespace::GPU_IO,
155 123,
156 gpu::CommandBufferId::FromUnsafeValue(0x234),
157 1),
158 sync_token2_(gpu::CommandBufferNamespace::GPU_IO,
159 123,
160 gpu::CommandBufferId::FromUnsafeValue(0x234),
161 2) {
[email protected]d72d9e02014-04-03 18:40:09162 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
163 base::Unretained(&mock_callback_),
164 mailbox_name1_);
165 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
166 base::Unretained(&mock_callback_),
167 mailbox_name2_);
skyostil3976a3f2014-09-04 22:07:23168 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
169 base::Unretained(&mock_callback_),
170 mailbox_name1_);
171 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
172 base::Unretained(&mock_callback_),
173 mailbox_name2_);
avi02a4d172015-12-21 06:14:36174 const uint32_t arbitrary_target1 = GL_TEXTURE_2D;
175 const uint32_t arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
dyencc16ed4d2015-11-03 20:03:04176 mailbox1_ = TextureMailbox(mailbox_name1_, sync_token1_, arbitrary_target1);
177 mailbox2_ = TextureMailbox(mailbox_name2_, sync_token2_, arbitrary_target2);
[email protected]d72d9e02014-04-03 18:40:09178 gfx::Size size(128, 128);
jbauman9015c8b2014-12-11 00:49:37179 shared_bitmap_ = manager->AllocateSharedBitmap(size);
180 DCHECK(shared_bitmap_);
181 release_mailbox3_ =
182 base::Bind(&MockMailboxCallback::Release2,
183 base::Unretained(&mock_callback_), shared_bitmap_.get());
184 release_mailbox3_impl_ =
185 base::Bind(&MockMailboxCallback::ReleaseImpl2,
186 base::Unretained(&mock_callback_), shared_bitmap_.get());
187 mailbox3_ = TextureMailbox(shared_bitmap_.get(), size);
[email protected]d72d9e02014-04-03 18:40:09188 }
189
190 gpu::Mailbox mailbox_name1_;
191 gpu::Mailbox mailbox_name2_;
192 MockMailboxCallback mock_callback_;
193 ReleaseCallback release_mailbox1_;
194 ReleaseCallback release_mailbox2_;
195 ReleaseCallback release_mailbox3_;
skyostil3976a3f2014-09-04 22:07:23196 ReleaseCallbackImpl release_mailbox1_impl_;
197 ReleaseCallbackImpl release_mailbox2_impl_;
198 ReleaseCallbackImpl release_mailbox3_impl_;
[email protected]d72d9e02014-04-03 18:40:09199 TextureMailbox mailbox1_;
200 TextureMailbox mailbox2_;
201 TextureMailbox mailbox3_;
dyencc16ed4d2015-11-03 20:03:04202 gpu::SyncToken sync_token1_;
203 gpu::SyncToken sync_token2_;
danakj60bc3bc2016-04-09 00:24:48204 std::unique_ptr<SharedBitmap> shared_bitmap_;
[email protected]d72d9e02014-04-03 18:40:09205};
206
[email protected]31d4df82013-07-18 10:17:22207class TextureLayerTest : public testing::Test {
208 public:
209 TextureLayerTest()
danakj1120f4c2016-09-15 02:05:32210 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()),
khushalsagarb64b360d2015-10-21 19:25:16211 host_impl_(&task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:16212 &task_graph_runner_),
jbauman9015c8b2014-12-11 00:49:37213 test_data_(&shared_bitmap_manager_) {}
[email protected]31d4df82013-07-18 10:17:22214
215 protected:
dcheng93a52eb2014-12-23 02:14:23216 void SetUp() override {
loyso2cb3f32f2016-11-08 07:08:34217 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
218 layer_tree_host_ = MockLayerTreeHost::Create(
219 &fake_client_, &task_graph_runner_, animation_host_.get());
[email protected]d72d9e02014-04-03 18:40:09220 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagarb69ba9452017-01-27 22:20:07221 layer_tree_host_->SetViewportSize(gfx::Size(10, 10));
[email protected]d72d9e02014-04-03 18:40:09222 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22223 }
224
dcheng93a52eb2014-12-23 02:14:23225 void TearDown() override {
[email protected]31d4df82013-07-18 10:17:22226 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22227 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
228
loyso2cb3f32f2016-11-08 07:08:34229 animation_host_->SetMutatorHostClient(nullptr);
khushalsagarb69ba9452017-01-27 22:20:07230 layer_tree_host_->SetRootLayer(nullptr);
danakjf446a072014-09-27 21:55:48231 layer_tree_host_ = nullptr;
loyso2cb3f32f2016-11-08 07:08:34232 animation_host_ = nullptr;
[email protected]31d4df82013-07-18 10:17:22233 }
234
danakj60bc3bc2016-04-09 00:24:48235 std::unique_ptr<MockLayerTreeHost> layer_tree_host_;
loyso2cb3f32f2016-11-08 07:08:34236 std::unique_ptr<AnimationHost> animation_host_;
khushalsagarb64b360d2015-10-21 19:25:16237 FakeImplTaskRunnerProvider task_runner_provider_;
[email protected]31d4df82013-07-18 10:17:22238 FakeLayerTreeHostClient fake_client_;
[email protected]4e2eb352014-03-20 17:25:45239 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:47240 TestTaskGraphRunner task_graph_runner_;
danakj1120f4c2016-09-15 02:05:32241 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_;
[email protected]31d4df82013-07-18 10:17:22242 FakeLayerTreeHostImpl host_impl_;
jbauman9015c8b2014-12-11 00:49:37243 CommonMailboxObjects test_data_;
[email protected]31d4df82013-07-18 10:17:22244};
245
[email protected]31d4df82013-07-18 10:17:22246TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
kulkarni.a4015690f12014-10-10 13:50:06247 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31248 TextureLayer::CreateForMailbox(nullptr);
khushalsagarb69ba9452017-01-27 22:20:07249 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer));
[email protected]31d4df82013-07-18 10:17:22250
251 // Test properties that should call SetNeedsCommit. All properties need to
252 // be set to new values in order for SetNeedsCommit to be called.
253 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
jackhou10c9af42014-12-04 05:24:44254 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
[email protected]31d4df82013-07-18 10:17:22255 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
256 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
257 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
258 0.5f, 0.5f, 0.5f, 0.5f));
259 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
260 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true));
[email protected]31d4df82013-07-18 10:17:22261}
262
[email protected]df41e252014-02-03 23:39:50263class TestMailboxHolder : public TextureLayer::TextureMailboxHolder {
[email protected]9794fb32013-08-29 09:49:59264 public:
[email protected]df41e252014-02-03 23:39:50265 using TextureLayer::TextureMailboxHolder::Create;
[email protected]9794fb32013-08-29 09:49:59266
267 protected:
dcheng716bedf2014-10-21 09:51:08268 ~TestMailboxHolder() override {}
[email protected]9794fb32013-08-29 09:49:59269};
270
[email protected]de44a152013-01-08 15:28:46271class TextureLayerWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15272 protected:
dcheng93a52eb2014-12-23 02:14:23273 void TearDown() override {
[email protected]28571b042013-03-14 07:59:15274 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
dyencc16ed4d2015-11-03 20:03:04275 EXPECT_CALL(
276 test_data_.mock_callback_,
277 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
278 .Times(1);
[email protected]28571b042013-03-14 07:59:15279 TextureLayerTest::TearDown();
280 }
[email protected]de44a152013-01-08 15:28:46281};
282
[email protected]28571b042013-03-14 07:59:15283TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
kulkarni.a4015690f12014-10-10 13:50:06284 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31285 TextureLayer::CreateForMailbox(nullptr);
[email protected]22898ed2013-06-01 04:52:30286 ASSERT_TRUE(test_layer.get());
[email protected]de44a152013-01-08 15:28:46287
[email protected]28571b042013-03-14 07:59:15288 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagarb69ba9452017-01-27 22:20:07289 layer_tree_host_->SetRootLayer(test_layer);
[email protected]28571b042013-03-14 07:59:15290 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46291
[email protected]28571b042013-03-14 07:59:15292 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16293 test_layer->SetTextureMailbox(
294 test_data_.mailbox1_,
295 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]28571b042013-03-14 07:59:15296 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46297
[email protected]28571b042013-03-14 07:59:15298 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04299 EXPECT_CALL(
300 test_data_.mock_callback_,
301 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
[email protected]28571b042013-03-14 07:59:15302 .Times(1);
[email protected]9260757f2013-09-17 01:24:16303 test_layer->SetTextureMailbox(
304 test_data_.mailbox2_,
305 SingleReleaseCallback::Create(test_data_.release_mailbox2_));
[email protected]28571b042013-03-14 07:59:15306 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
307 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46308
[email protected]28571b042013-03-14 07:59:15309 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04310 EXPECT_CALL(
311 test_data_.mock_callback_,
312 Release(test_data_.mailbox_name2_, test_data_.sync_token2_, false))
[email protected]28571b042013-03-14 07:59:15313 .Times(1);
danakj968153f32014-10-15 22:52:16314 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]28571b042013-03-14 07:59:15315 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
316 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46317
[email protected]80d42bd2013-08-30 19:13:45318 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16319 test_layer->SetTextureMailbox(
320 test_data_.mailbox3_,
321 SingleReleaseCallback::Create(test_data_.release_mailbox3_));
[email protected]42f40a52013-06-08 04:38:51322 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
323 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
324
[email protected]42f40a52013-06-08 04:38:51325 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
326 EXPECT_CALL(test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04327 Release2(test_data_.shared_bitmap_.get(), _, false))
328 .Times(1);
danakj968153f32014-10-15 22:52:16329 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]42f40a52013-06-08 04:38:51330 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
331 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
332
[email protected]28571b042013-03-14 07:59:15333 // Test destructor.
334 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16335 test_layer->SetTextureMailbox(
336 test_data_.mailbox1_,
337 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]de44a152013-01-08 15:28:46338}
339
[email protected]9794fb32013-08-29 09:49:59340class TextureLayerMailboxHolderTest : public TextureLayerTest {
341 public:
342 TextureLayerMailboxHolderTest()
343 : main_thread_("MAIN") {
344 main_thread_.Start();
fdoray70df5a92016-06-22 21:13:59345 main_thread_.task_runner()->PostTask(
tzik4604bb52017-04-13 21:50:22346 FROM_HERE,
347 base::BindOnce(&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,
tzik4604bb52017-04-13 21:50:22357 base::BindOnce(&base::WaitableEvent::Signal, base::Unretained(&event)));
[email protected]9794fb32013-08-29 09:49:59358 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(
tzik4604bb52017-04-13 21:50:22400 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22409 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22416 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22441 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22453 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22462 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22469 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22481 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22507 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22516 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22523 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22531 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22561 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22570 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22577 FROM_HERE, base::BindOnce(&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(
tzik4604bb52017-04-13 21:50:22585 FROM_HERE, base::BindOnce(&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,
tzik4604bb52017-04-13 21:50:22606 base::BindOnce(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait,
607 base::Unretained(this), &begin_capture, &wait_for_capture,
608 &stop_capture));
[email protected]9794fb32013-08-29 09:49:59609
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 {
staraz60f32e22017-05-04 20:04:53641 constexpr bool kDisableDisplayVsync = false;
danakj014316e2016-08-04 18:40:26642 bool synchronous_composite =
643 !HasImplThread() &&
khushalsagarcebe4942016-09-07 23:27:01644 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler;
danakj1120f4c2016-09-15 02:05:32645 return base::MakeUnique<TestCompositorFrameSink>(
danakj014316e2016-08-04 18:40:26646 compositor_context_provider, std::move(worker_context_provider),
danakj014316e2016-08-04 18:40:26647 shared_bitmap_manager(), gpu_memory_buffer_manager(),
khushalsagarcebe4942016-09-07 23:27:01648 layer_tree_host()->GetSettings().renderer_settings,
staraz60f32e22017-05-04 20:04:53649 ImplThreadTaskRunner(), synchronous_composite, kDisableDisplayVsync);
danakj014316e2016-08-04 18:40:26650 }
[email protected]28571b042013-03-14 07:59:15651
ericrkad5923812017-01-25 23:26:12652 void AdvanceTestCase() {
653 ++test_case_;
654 switch (test_case_) {
655 case 1:
656 // Case #1: change mailbox before the commit. The old mailbox should be
657 // released immediately.
658 SetMailbox('2');
659 EXPECT_EQ(1, callback_count_);
660 PostSetNeedsCommitToMainThread();
661
662 // Case 2 does not rely on callbacks to advance.
663 pending_callback_ = false;
664 break;
665 case 2:
666 // Case #2: change mailbox after the commit (and draw), where the
667 // layer draws. The old mailbox should be released during the next
668 // commit.
669 SetMailbox('3');
670 EXPECT_EQ(1, callback_count_);
671
672 // Cases 3-5 rely on a callback to advance.
673 pending_callback_ = true;
674 break;
675 case 3:
676 EXPECT_EQ(2, callback_count_);
677 // Case #3: change mailbox when the layer doesn't draw. The old
678 // mailbox should be released during the next commit.
679 layer_->SetBounds(gfx::Size());
680 SetMailbox('4');
681 break;
682 case 4:
683 EXPECT_EQ(3, callback_count_);
684 // Case #4: release mailbox that was committed but never drawn. The
685 // old mailbox should be released during the next commit.
686 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
687 break;
688 case 5:
689 EXPECT_EQ(4, callback_count_);
690 // Restore a mailbox for the next step.
691 SetMailbox('5');
692
693 // Cases 6 and 7 do not rely on callbacks to advance.
694 pending_callback_ = false;
695 break;
696 case 6:
697 // Case #5: remove layer from tree. Callback should *not* be called, the
698 // mailbox is returned to the main thread.
699 EXPECT_EQ(4, callback_count_);
700 layer_->RemoveFromParent();
701 break;
702 case 7:
703 EXPECT_EQ(4, callback_count_);
704 // Resetting the mailbox will call the callback now.
705 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
706 EXPECT_EQ(5, callback_count_);
707 EndTest();
708 break;
709 default:
710 NOTREACHED();
711 break;
712 }
713 }
714
[email protected]28571b042013-03-14 07:59:15715 // Make sure callback is received on main and doesn't block the impl thread.
danakj014316e2016-08-04 18:40:26716 void ReleaseCallback(char mailbox_char,
717 const gpu::SyncToken& sync_token,
718 bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:59719 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]7ba3ca72013-04-11 06:37:25720 EXPECT_FALSE(lost_resource);
[email protected]28571b042013-03-14 07:59:15721 ++callback_count_;
ericrkad5923812017-01-25 23:26:12722
723 // If we are waiting on a callback, advance now.
724 if (pending_callback_)
725 AdvanceTestCase();
[email protected]28571b042013-03-14 07:59:15726 }
727
728 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:59729 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:48730 std::unique_ptr<SingleReleaseCallback> callback =
731 SingleReleaseCallback::Create(base::Bind(
[email protected]28571b042013-03-14 07:59:15732 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback,
danakj014316e2016-08-04 18:40:26733 base::Unretained(this), mailbox_char));
dyene5db881b2016-03-01 19:47:03734 layer_->SetTextureMailbox(
735 TextureMailbox(MailboxFromChar(mailbox_char),
736 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
737 GL_TEXTURE_2D),
738 std::move(callback));
danakj014316e2016-08-04 18:40:26739 // Damage the layer so we send a new frame with the new mailbox to the
740 // Display compositor.
741 layer_->SetNeedsDisplay();
[email protected]28571b042013-03-14 07:59:15742 }
743
dcheng716bedf2014-10-21 09:51:08744 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:59745 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
746
[email protected]28571b042013-03-14 07:59:15747 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31748 root_ = Layer::Create();
[email protected]28571b042013-03-14 07:59:15749 root_->SetBounds(bounds);
750
loyso0940d412016-03-14 01:30:31751 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]28571b042013-03-14 07:59:15752 layer_->SetIsDrawable(true);
[email protected]28571b042013-03-14 07:59:15753 layer_->SetBounds(bounds);
754
755 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:07756 layer_tree_host()->SetRootLayer(root_);
757 layer_tree_host()->SetViewportSize(bounds);
[email protected]28571b042013-03-14 07:59:15758 SetMailbox('1');
759 EXPECT_EQ(0, callback_count_);
760
ericrkad5923812017-01-25 23:26:12761 // Setup is complete - advance to test case 1.
762 AdvanceTestCase();
[email protected]28571b042013-03-14 07:59:15763 }
764
dcheng716bedf2014-10-21 09:51:08765 void DidCommit() override {
ericrkad5923812017-01-25 23:26:12766 // If we are not waiting on a callback, advance now.
767 if (!pending_callback_)
768 AdvanceTestCase();
[email protected]28571b042013-03-14 07:59:15769 }
[email protected]de44a152013-01-08 15:28:46770
dcheng716bedf2014-10-21 09:51:08771 void AfterTest() override {}
[email protected]de44a152013-01-08 15:28:46772
[email protected]28571b042013-03-14 07:59:15773 private:
[email protected]9794fb32013-08-29 09:49:59774 base::ThreadChecker main_thread_;
danakj014316e2016-08-04 18:40:26775 int callback_count_ = 0;
ericrkad5923812017-01-25 23:26:12776 int test_case_ = 0;
777 // Whether we are waiting on a callback to advance the test case.
778 bool pending_callback_ = false;
[email protected]28571b042013-03-14 07:59:15779 scoped_refptr<Layer> root_;
780 scoped_refptr<TextureLayer> layer_;
[email protected]de44a152013-01-08 15:28:46781};
782
danakj0943a112016-08-11 00:33:46783SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
[email protected]74b43cc2013-08-30 06:29:27784
[email protected]74b43cc2013-08-30 06:29:27785class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest {
786 protected:
samans0834fe042017-03-03 17:03:22787 void ReleaseCallback(const gpu::SyncToken& original_sync_token,
788 const gpu::SyncToken& release_sync_token,
789 bool lost_resource) {
790 released_count_++;
791 switch (released_count_) {
792 case 1:
793 break;
794 case 2:
795 EXPECT_EQ(3, layer_tree_host()->SourceFrameNumber());
796 EndTest();
797 break;
798 default:
799 NOTREACHED();
800 }
801 }
[email protected]74b43cc2013-08-30 06:29:27802
803 void SetMailbox(char mailbox_char) {
dyene5db881b2016-03-01 19:47:03804 const gpu::SyncToken sync_token =
805 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char));
danakj60bc3bc2016-04-09 00:24:48806 std::unique_ptr<SingleReleaseCallback> callback =
807 SingleReleaseCallback::Create(base::Bind(
808 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback,
samans0834fe042017-03-03 17:03:22809 base::Unretained(this), sync_token));
dyencc16ed4d2015-11-03 20:03:04810 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char),
dyene5db881b2016-03-01 19:47:03811 sync_token, GL_TEXTURE_2D),
danakja04855a2015-11-18 20:39:10812 std::move(callback));
[email protected]74b43cc2013-08-30 06:29:27813 }
814
dcheng716bedf2014-10-21 09:51:08815 void BeginTest() override {
[email protected]74b43cc2013-08-30 06:29:27816 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31817 root_ = Layer::Create();
[email protected]74b43cc2013-08-30 06:29:27818 root_->SetBounds(bounds);
819
loyso0940d412016-03-14 01:30:31820 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]74b43cc2013-08-30 06:29:27821 layer_->SetIsDrawable(true);
[email protected]74b43cc2013-08-30 06:29:27822 layer_->SetBounds(bounds);
823
824 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:07825 layer_tree_host()->SetRootLayer(root_);
826 layer_tree_host()->SetViewportSize(bounds);
[email protected]74b43cc2013-08-30 06:29:27827 SetMailbox('1');
828
829 PostSetNeedsCommitToMainThread();
830 }
831
dcheng716bedf2014-10-21 09:51:08832 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
danakj3c3973b2015-08-25 21:50:18833 base::AutoLock lock(activate_count_lock_);
[email protected]74b43cc2013-08-30 06:29:27834 ++activate_count_;
835 }
836
dcheng716bedf2014-10-21 09:51:08837 void DidCommit() override {
danakj3c3973b2015-08-25 21:50:18838 // The first frame doesn't cause anything to be returned so it does not
839 // need to wait for activation.
khushalsagarcebe4942016-09-07 23:27:01840 if (layer_tree_host()->SourceFrameNumber() > 1) {
danakj3c3973b2015-08-25 21:50:18841 base::AutoLock lock(activate_count_lock_);
842 // The activate happened before commit is done on the main side.
khushalsagarcebe4942016-09-07 23:27:01843 EXPECT_EQ(activate_count_, layer_tree_host()->SourceFrameNumber());
danakj3c3973b2015-08-25 21:50:18844 }
845
khushalsagarcebe4942016-09-07 23:27:01846 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]74b43cc2013-08-30 06:29:27847 case 1:
848 // The first mailbox has been activated. Set a new mailbox, and
849 // expect the next commit to finish *after* it is activated.
850 SetMailbox('2');
[email protected]74b43cc2013-08-30 06:29:27851 break;
852 case 2:
853 // The second mailbox has been activated. Remove the layer from
854 // the tree to cause another commit/activation. The commit should
855 // finish *after* the layer is removed from the active tree.
856 layer_->RemoveFromParent();
[email protected]74b43cc2013-08-30 06:29:27857 break;
858 case 3:
samans0834fe042017-03-03 17:03:22859 // This ensures all texture mailboxes are released before the end of the
860 // test.
861 layer_->ClearClient();
[email protected]74b43cc2013-08-30 06:29:27862 break;
samans0834fe042017-03-03 17:03:22863 default:
864 NOTREACHED();
[email protected]74b43cc2013-08-30 06:29:27865 }
866 }
867
dcheng716bedf2014-10-21 09:51:08868 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
danakj3c3973b2015-08-25 21:50:18869 // The activate didn't happen before commit is done on the impl side (but it
870 // should happen before the main thread is done).
871 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number());
[email protected]74b43cc2013-08-30 06:29:27872 }
873
dcheng716bedf2014-10-21 09:51:08874 void AfterTest() override {}
[email protected]74b43cc2013-08-30 06:29:27875
danakj3c3973b2015-08-25 21:50:18876 base::Lock activate_count_lock_;
samans0834fe042017-03-03 17:03:22877 int activate_count_ = 0;
[email protected]74b43cc2013-08-30 06:29:27878 scoped_refptr<Layer> root_;
879 scoped_refptr<TextureLayer> layer_;
samans0834fe042017-03-03 17:03:22880 int released_count_ = 0;
[email protected]74b43cc2013-08-30 06:29:27881};
882
danakj0943a112016-08-11 00:33:46883SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
[email protected]74b43cc2013-08-30 06:29:27884
[email protected]de44a152013-01-08 15:28:46885class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15886 protected:
dcheng93a52eb2014-12-23 02:14:23887 void SetUp() override {
[email protected]28571b042013-03-14 07:59:15888 TextureLayerTest::SetUp();
loyso2cb3f32f2016-11-08 07:08:34889 layer_tree_host_ = MockLayerTreeHost::Create(
890 &fake_client_, &task_graph_runner_, animation_host_.get());
sievers71c62dd52015-10-07 01:44:39891 host_impl_.SetVisible(true);
danakj1120f4c2016-09-15 02:05:32892 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get()));
[email protected]28571b042013-03-14 07:59:15893 }
[email protected]de44a152013-01-08 15:28:46894
[email protected]0ec335c42013-07-04 06:17:08895 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
896 bool will_draw = layer->WillDraw(
897 mode, host_impl_.active_tree()->resource_provider());
898 if (will_draw)
899 layer->DidDraw(host_impl_.active_tree()->resource_provider());
900 return will_draw;
901 }
902
[email protected]408b5e22013-03-19 09:48:09903 FakeLayerTreeHostClient fake_client_;
[email protected]de44a152013-01-08 15:28:46904};
905
[email protected]ffbb2212013-06-02 23:47:59906// Test conditions for results of TextureLayerImpl::WillDraw under
907// different configurations of different mailbox, texture_id, and draw_mode.
908TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
skyostil3976a3f2014-09-04 22:07:23909 EXPECT_CALL(
910 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04911 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]0ec335c42013-07-04 06:17:08912 .Times(AnyNumber());
dyencc16ed4d2015-11-03 20:03:04913 EXPECT_CALL(
914 test_data_.mock_callback_,
915 ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _))
[email protected]0ec335c42013-07-04 06:17:08916 .Times(AnyNumber());
[email protected]ffbb2212013-06-02 23:47:59917 // Hardware mode.
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);
[email protected]9260757f2013-09-17 01:24:16921 impl_layer->SetTextureMailbox(
922 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23923 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08924 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59925 }
926
927 {
danakj60bc3bc2016-04-09 00:24:48928 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11929 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16930 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08931 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
932 }
933
934 {
935 // Software resource.
danakj60bc3bc2016-04-09 00:24:48936 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11937 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16938 impl_layer->SetTextureMailbox(
939 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23940 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]3e44d7a2013-07-30 00:03:10941 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59942 }
943
[email protected]0ec335c42013-07-04 06:17:08944 // Software mode.
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);
[email protected]9260757f2013-09-17 01:24:16948 impl_layer->SetTextureMailbox(
949 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23950 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08951 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
952 }
953
954 {
danakj60bc3bc2016-04-09 00:24:48955 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11956 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16957 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08958 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
959 }
960
961 {
962 // Software resource.
danakj60bc3bc2016-04-09 00:24:48963 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11964 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16965 impl_layer->SetTextureMailbox(
966 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23967 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]0ec335c42013-07-04 06:17:08968 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
969 }
970
[email protected]ffbb2212013-06-02 23:47:59971 // Resourceless software mode.
972 {
danakj60bc3bc2016-04-09 00:24:48973 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11974 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16975 impl_layer->SetTextureMailbox(
976 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23977 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08978 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
[email protected]ffbb2212013-06-02 23:47:59979 }
[email protected]ffbb2212013-06-02 23:47:59980}
981
[email protected]28571b042013-03-14 07:59:15982TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
983 host_impl_.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:48984 std::unique_ptr<TextureLayerImpl> pending_layer;
[email protected]17e08432014-04-10 00:41:11985 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1);
[email protected]28571b042013-03-14 07:59:15986 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46987
danakj60bc3bc2016-04-09 00:24:48988 std::unique_ptr<LayerImpl> active_layer(
[email protected]28571b042013-03-14 07:59:15989 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
[email protected]ed511b8d2013-03-25 03:29:29990 ASSERT_TRUE(active_layer);
[email protected]de44a152013-01-08 15:28:46991
[email protected]9260757f2013-09-17 01:24:16992 pending_layer->SetTextureMailbox(
993 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23994 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]421e84f2013-02-22 03:27:15995
[email protected]28571b042013-03-14 07:59:15996 // Test multiple commits without an activation.
skyostil3976a3f2014-09-04 22:07:23997 EXPECT_CALL(
998 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04999 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:151000 .Times(1);
[email protected]9260757f2013-09-17 01:24:161001 pending_layer->SetTextureMailbox(
1002 test_data_.mailbox2_,
skyostil3976a3f2014-09-04 22:07:231003 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_));
[email protected]28571b042013-03-14 07:59:151004 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:151005
[email protected]28571b042013-03-14 07:59:151006 // Test callback after activation.
[email protected]ed511b8d2013-03-25 03:29:291007 pending_layer->PushPropertiesTo(active_layer.get());
1008 active_layer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:151009
skyostil3976a3f2014-09-04 22:07:231010 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]9260757f2013-09-17 01:24:161011 pending_layer->SetTextureMailbox(
1012 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231013 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151014 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:151015
[email protected]7ba3ca72013-04-11 06:37:251016 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231017 ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1);
[email protected]ed511b8d2013-03-25 03:29:291018 pending_layer->PushPropertiesTo(active_layer.get());
1019 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:151020 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:461021
[email protected]28571b042013-03-14 07:59:151022 // Test resetting the mailbox.
[email protected]7ba3ca72013-04-11 06:37:251023 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231024 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
danakj968153f32014-10-15 22:52:161025 pending_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]ed511b8d2013-03-25 03:29:291026 pending_layer->PushPropertiesTo(active_layer.get());
1027 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:151028 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:461029
[email protected]28571b042013-03-14 07:59:151030 // Test destructor.
skyostil3976a3f2014-09-04 22:07:231031 EXPECT_CALL(
1032 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:041033 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:151034 .Times(1);
[email protected]9260757f2013-09-17 01:24:161035 pending_layer->SetTextureMailbox(
1036 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231037 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]de44a152013-01-08 15:28:461038}
1039
[email protected]28571b042013-03-14 07:59:151040TEST_F(TextureLayerImplWithMailboxTest,
1041 TestDestructorCallbackOnCreatedResource) {
danakj60bc3bc2016-04-09 00:24:481042 std::unique_ptr<TextureLayerImpl> impl_layer;
[email protected]17e08432014-04-10 00:41:111043 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]28571b042013-03-14 07:59:151044 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:461045
[email protected]7ba3ca72013-04-11 06:37:251046 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231047 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]9260757f2013-09-17 01:24:161048 impl_layer->SetTextureMailbox(
1049 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231050 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]ffbb2212013-06-02 23:47:591051 impl_layer->DidBecomeActive();
1052 EXPECT_TRUE(impl_layer->WillDraw(
1053 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider()));
[email protected]28571b042013-03-14 07:59:151054 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
danakj968153f32014-10-15 22:52:161055 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]de44a152013-01-08 15:28:461056}
1057
[email protected]28571b042013-03-14 07:59:151058TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
1059 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
jbaumanbbd425e2015-05-19 00:33:351060 ResourceId id = provider->CreateResourceFromTextureMailbox(
skyostil3976a3f2014-09-04 22:07:231061 test_data_.mailbox1_,
1062 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151063 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:461064
[email protected]28571b042013-03-14 07:59:151065 // Transfer some resources to the parent.
1066 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1067 resource_ids_to_transfer.push_back(id);
1068 TransferableResourceArray list;
1069 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
1070 EXPECT_TRUE(provider->InUseByConsumer(id));
skyostil3976a3f2014-09-04 22:07:231071 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]28571b042013-03-14 07:59:151072 provider->DeleteResource(id);
1073 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]7ba3ca72013-04-11 06:37:251074 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231075 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]e00bab022013-08-19 00:42:451076 ReturnedResourceArray returned;
1077 TransferableResource::ReturnResources(list, &returned);
1078 provider->ReceiveReturnsFromParent(returned);
[email protected]de44a152013-01-08 15:28:461079}
1080
[email protected]4bad8b62013-10-24 01:27:291081// Checks that TextureLayer::Update does not cause an extra commit when setting
1082// the texture mailbox.
1083class TextureLayerNoExtraCommitForMailboxTest
1084 : public LayerTreeTest,
1085 public TextureLayerClient {
1086 public:
[email protected]4bad8b62013-10-24 01:27:291087 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081088 bool PrepareTextureMailbox(
[email protected]df41e252014-02-03 23:39:501089 TextureMailbox* texture_mailbox,
danakj4d0dd802016-08-23 22:10:061090 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
khushalsagarcebe4942016-09-07 23:27:011091 if (layer_tree_host()->SourceFrameNumber() == 1) {
[email protected]9f35bd22014-06-03 15:25:461092 // Once this has been committed, the mailbox will be released.
[email protected]df41e252014-02-03 23:39:501093 *texture_mailbox = TextureMailbox();
[email protected]cce34bd2013-12-02 23:24:451094 return true;
1095 }
[email protected]4bad8b62013-10-24 01:27:291096
dyene5db881b2016-03-01 19:47:031097 *texture_mailbox = TextureMailbox(MailboxFromChar('1'),
1098 SyncTokenFromUInt(0x123), GL_TEXTURE_2D);
[email protected]4bad8b62013-10-24 01:27:291099 *release_callback = SingleReleaseCallback::Create(
1100 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased,
1101 base::Unretained(this)));
[email protected]4bad8b62013-10-24 01:27:291102 return true;
1103 }
1104
dyencc16ed4d2015-11-03 20:03:041105 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031106 EXPECT_TRUE(sync_token.HasData());
[email protected]cce34bd2013-12-02 23:24:451107 EndTest();
[email protected]4bad8b62013-10-24 01:27:291108 }
1109
dcheng716bedf2014-10-21 09:51:081110 void SetupTree() override {
loyso0940d412016-03-14 01:30:311111 scoped_refptr<Layer> root = Layer::Create();
[email protected]4bad8b62013-10-24 01:27:291112 root->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291113 root->SetIsDrawable(true);
1114
loyso0940d412016-03-14 01:30:311115 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]4bad8b62013-10-24 01:27:291116 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291117 texture_layer_->SetIsDrawable(true);
[email protected]0d7fb302014-01-23 21:30:471118 root->AddChild(texture_layer_);
[email protected]4bad8b62013-10-24 01:27:291119
khushalsagarb69ba9452017-01-27 22:20:071120 layer_tree_host()->SetRootLayer(root);
[email protected]4bad8b62013-10-24 01:27:291121 LayerTreeTest::SetupTree();
1122 }
1123
dcheng716bedf2014-10-21 09:51:081124 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]4bad8b62013-10-24 01:27:291125
dcheng716bedf2014-10-21 09:51:081126 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011127 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]4bad8b62013-10-24 01:27:291128 case 1:
[email protected]4ea293f72014-08-13 03:03:171129 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
[email protected]cce34bd2013-12-02 23:24:451130 // Invalidate the texture layer to clear the mailbox before
1131 // ending the test.
1132 texture_layer_->SetNeedsDisplay();
1133 break;
1134 case 2:
[email protected]4bad8b62013-10-24 01:27:291135 break;
1136 default:
1137 NOTREACHED();
1138 break;
1139 }
1140 }
1141
dcheng716bedf2014-10-21 09:51:081142 void AfterTest() override {}
[email protected]4bad8b62013-10-24 01:27:291143
1144 private:
[email protected]4bad8b62013-10-24 01:27:291145 scoped_refptr<TextureLayer> texture_layer_;
[email protected]4bad8b62013-10-24 01:27:291146};
1147
[email protected]cce34bd2013-12-02 23:24:451148SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);
[email protected]4bad8b62013-10-24 01:27:291149
[email protected]b04264f92013-09-13 23:37:291150// Checks that changing a mailbox in the client for a TextureLayer that's
1151// invisible correctly works and uses the new mailbox as soon as the layer
1152// becomes visible (and returns the old one).
1153class TextureLayerChangeInvisibleMailboxTest
1154 : public LayerTreeTest,
1155 public TextureLayerClient {
1156 public:
1157 TextureLayerChangeInvisibleMailboxTest()
1158 : mailbox_changed_(true),
1159 mailbox_returned_(0),
1160 prepare_called_(0),
1161 commit_count_(0) {
1162 mailbox_ = MakeMailbox('1');
1163 }
1164
1165 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081166 bool PrepareTextureMailbox(
[email protected]e51444a2013-12-10 23:05:011167 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061168 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]b04264f92013-09-13 23:37:291169 ++prepare_called_;
1170 if (!mailbox_changed_)
1171 return false;
1172 *mailbox = mailbox_;
[email protected]9260757f2013-09-17 01:24:161173 *release_callback = SingleReleaseCallback::Create(
1174 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased,
1175 base::Unretained(this)));
[email protected]b04264f92013-09-13 23:37:291176 return true;
1177 }
1178
1179 TextureMailbox MakeMailbox(char name) {
dyene5db881b2016-03-01 19:47:031180 return TextureMailbox(MailboxFromChar(name),
1181 SyncTokenFromUInt(static_cast<uint32_t>(name)),
dyencc16ed4d2015-11-03 20:03:041182 GL_TEXTURE_2D);
[email protected]b04264f92013-09-13 23:37:291183 }
1184
dyencc16ed4d2015-11-03 20:03:041185 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031186 EXPECT_TRUE(sync_token.HasData());
[email protected]b04264f92013-09-13 23:37:291187 ++mailbox_returned_;
[email protected]b04264f92013-09-13 23:37:291188 }
1189
dcheng716bedf2014-10-21 09:51:081190 void SetupTree() override {
loyso0940d412016-03-14 01:30:311191 scoped_refptr<Layer> root = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291192 root->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291193 root->SetIsDrawable(true);
1194
loyso0940d412016-03-14 01:30:311195 solid_layer_ = SolidColorLayer::Create();
[email protected]b04264f92013-09-13 23:37:291196 solid_layer_->SetBounds(gfx::Size(10, 10));
1197 solid_layer_->SetIsDrawable(true);
1198 solid_layer_->SetBackgroundColor(SK_ColorWHITE);
1199 root->AddChild(solid_layer_);
1200
loyso0940d412016-03-14 01:30:311201 parent_layer_ = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291202 parent_layer_->SetBounds(gfx::Size(10, 10));
1203 parent_layer_->SetIsDrawable(true);
1204 root->AddChild(parent_layer_);
1205
loyso0940d412016-03-14 01:30:311206 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]b04264f92013-09-13 23:37:291207 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291208 texture_layer_->SetIsDrawable(true);
1209 parent_layer_->AddChild(texture_layer_);
1210
khushalsagarb69ba9452017-01-27 22:20:071211 layer_tree_host()->SetRootLayer(root);
[email protected]b04264f92013-09-13 23:37:291212 LayerTreeTest::SetupTree();
1213 }
1214
dcheng716bedf2014-10-21 09:51:081215 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]b04264f92013-09-13 23:37:291216
samans44b6dfc2017-04-19 16:50:531217 void DidReceiveCompositorFrameAck() override {
[email protected]b04264f92013-09-13 23:37:291218 ++commit_count_;
1219 switch (commit_count_) {
1220 case 1:
1221 // We should have updated the layer, committing the texture.
1222 EXPECT_EQ(1, prepare_called_);
1223 // Make layer invisible.
1224 parent_layer_->SetOpacity(0.f);
1225 break;
1226 case 2:
1227 // Layer shouldn't have been updated.
1228 EXPECT_EQ(1, prepare_called_);
1229 // Change the texture.
1230 mailbox_ = MakeMailbox('2');
1231 mailbox_changed_ = true;
1232 texture_layer_->SetNeedsDisplay();
1233 // Force a change to make sure we draw a frame.
1234 solid_layer_->SetBackgroundColor(SK_ColorGRAY);
1235 break;
1236 case 3:
1237 // Layer shouldn't have been updated.
1238 EXPECT_EQ(1, prepare_called_);
1239 // So the old mailbox isn't returned yet.
1240 EXPECT_EQ(0, mailbox_returned_);
1241 // Make layer visible again.
jaydasikacf223762016-05-16 23:02:091242 parent_layer_->SetOpacity(0.9f);
[email protected]b04264f92013-09-13 23:37:291243 break;
1244 case 4:
1245 // Layer should have been updated.
1246 EXPECT_EQ(2, prepare_called_);
1247 // So the old mailbox should have been returned already.
1248 EXPECT_EQ(1, mailbox_returned_);
1249 texture_layer_->ClearClient();
1250 break;
1251 case 5:
samans44b6dfc2017-04-19 16:50:531252 EXPECT_EQ(2, mailbox_returned_);
1253 EndTest();
[email protected]b04264f92013-09-13 23:37:291254 break;
1255 default:
1256 NOTREACHED();
1257 break;
1258 }
1259 }
1260
dcheng716bedf2014-10-21 09:51:081261 void AfterTest() override {}
[email protected]b04264f92013-09-13 23:37:291262
1263 private:
1264 scoped_refptr<SolidColorLayer> solid_layer_;
1265 scoped_refptr<Layer> parent_layer_;
1266 scoped_refptr<TextureLayer> texture_layer_;
1267
1268 // Used on the main thread.
1269 bool mailbox_changed_;
1270 TextureMailbox mailbox_;
1271 int mailbox_returned_;
1272 int prepare_called_;
1273 int commit_count_;
1274};
1275
samans44b6dfc2017-04-19 16:50:531276SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
[email protected]b04264f92013-09-13 23:37:291277
[email protected]0d7fb302014-01-23 21:30:471278// Test that TextureLayerImpl::ReleaseResources can be called which releases
1279// the mailbox back to TextureLayerClient.
1280class TextureLayerReleaseResourcesBase
1281 : public LayerTreeTest,
1282 public TextureLayerClient {
1283 public:
1284 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081285 bool PrepareTextureMailbox(
[email protected]0d7fb302014-01-23 21:30:471286 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061287 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
dyene5db881b2016-03-01 19:47:031288 *mailbox = TextureMailbox(MailboxFromChar('1'), SyncTokenFromUInt(1),
1289 GL_TEXTURE_2D);
[email protected]0d7fb302014-01-23 21:30:471290 *release_callback = SingleReleaseCallback::Create(
1291 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased,
1292 base::Unretained(this)));
1293 return true;
1294 }
1295
dyencc16ed4d2015-11-03 20:03:041296 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]0d7fb302014-01-23 21:30:471297 mailbox_released_ = true;
1298 }
1299
dcheng716bedf2014-10-21 09:51:081300 void SetupTree() override {
[email protected]0d7fb302014-01-23 21:30:471301 LayerTreeTest::SetupTree();
1302
1303 scoped_refptr<TextureLayer> texture_layer =
loyso0940d412016-03-14 01:30:311304 TextureLayer::CreateForMailbox(this);
[email protected]0d7fb302014-01-23 21:30:471305 texture_layer->SetBounds(gfx::Size(10, 10));
[email protected]0d7fb302014-01-23 21:30:471306 texture_layer->SetIsDrawable(true);
1307
khushalsagarb69ba9452017-01-27 22:20:071308 layer_tree_host()->root_layer()->AddChild(texture_layer);
jaydasikabd6f15a2016-04-21 19:45:371309 texture_layer_id_ = texture_layer->id();
[email protected]0d7fb302014-01-23 21:30:471310 }
1311
dcheng716bedf2014-10-21 09:51:081312 void BeginTest() override {
[email protected]0d7fb302014-01-23 21:30:471313 mailbox_released_ = false;
1314 PostSetNeedsCommitToMainThread();
1315 }
1316
dcheng716bedf2014-10-21 09:51:081317 void DidCommitAndDrawFrame() override { EndTest(); }
[email protected]0d7fb302014-01-23 21:30:471318
dcheng716bedf2014-10-21 09:51:081319 void AfterTest() override { EXPECT_TRUE(mailbox_released_); }
[email protected]0d7fb302014-01-23 21:30:471320
jaydasikabd6f15a2016-04-21 19:45:371321 protected:
1322 int texture_layer_id_;
1323
[email protected]0d7fb302014-01-23 21:30:471324 private:
1325 bool mailbox_released_;
1326};
1327
1328class TextureLayerReleaseResourcesAfterCommit
1329 : public TextureLayerReleaseResourcesBase {
1330 public:
dcheng716bedf2014-10-21 09:51:081331 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
kulkarni.a4015690f12014-10-10 13:50:061332 LayerTreeImpl* tree = nullptr;
danakj009cdfdf2015-02-17 22:35:141333 tree = host_impl->sync_tree();
jaydasikabd6f15a2016-04-21 19:45:371334 tree->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471335 }
1336};
1337
1338SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);
1339
1340class TextureLayerReleaseResourcesAfterActivate
1341 : public TextureLayerReleaseResourcesBase {
1342 public:
dcheng716bedf2014-10-21 09:51:081343 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
jaydasikabd6f15a2016-04-21 19:45:371344 host_impl->active_tree()->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471345 }
1346};
1347
1348SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);
1349
[email protected]9c2bd822013-07-26 12:30:171350class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest {
1351 public:
dyencc16ed4d2015-11-03 20:03:041352 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591353 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171354 EXPECT_FALSE(lost_resource);
1355 ++callback_count_;
1356 EndTest();
1357 }
1358
1359 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591360 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481361 std::unique_ptr<SingleReleaseCallback> callback =
1362 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171363 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback,
1364 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031365 layer_->SetTextureMailbox(
1366 TextureMailbox(MailboxFromChar(mailbox_char),
1367 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1368 GL_TEXTURE_2D),
1369 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171370 }
1371
dcheng716bedf2014-10-21 09:51:081372 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171373 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311374 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171375 root_->SetBounds(bounds);
1376
loyso0940d412016-03-14 01:30:311377 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171378 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171379 layer_->SetBounds(bounds);
1380
1381 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:071382 layer_tree_host()->SetRootLayer(root_);
1383 layer_tree_host()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171384 }
1385
dcheng716bedf2014-10-21 09:51:081386 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591387 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1388
[email protected]9c2bd822013-07-26 12:30:171389 callback_count_ = 0;
1390
1391 // Set the mailbox on the main thread.
1392 SetMailbox('1');
1393 EXPECT_EQ(0, callback_count_);
1394
1395 PostSetNeedsCommitToMainThread();
1396 }
1397
dcheng716bedf2014-10-21 09:51:081398 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011399 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171400 case 1:
1401 // Delete the TextureLayer on the main thread while the mailbox is in
1402 // the impl tree.
1403 layer_->RemoveFromParent();
kulkarni.a4015690f12014-10-10 13:50:061404 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171405 break;
1406 }
1407 }
1408
dcheng716bedf2014-10-21 09:51:081409 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171410
1411 private:
[email protected]9794fb32013-08-29 09:49:591412 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171413 int callback_count_;
1414 scoped_refptr<Layer> root_;
1415 scoped_refptr<TextureLayer> layer_;
1416};
1417
danakj0943a112016-08-11 00:33:461418SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxMainThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171419
1420class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest {
1421 public:
dyencc16ed4d2015-11-03 20:03:041422 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591423 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171424 EXPECT_FALSE(lost_resource);
1425 ++callback_count_;
1426 EndTest();
1427 }
1428
1429 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591430 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481431 std::unique_ptr<SingleReleaseCallback> callback =
1432 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171433 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback,
1434 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031435 layer_->SetTextureMailbox(
1436 TextureMailbox(MailboxFromChar(mailbox_char),
1437 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1438 GL_TEXTURE_2D),
1439 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171440 }
1441
dcheng716bedf2014-10-21 09:51:081442 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171443 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311444 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171445 root_->SetBounds(bounds);
1446
loyso0940d412016-03-14 01:30:311447 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171448 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171449 layer_->SetBounds(bounds);
1450
1451 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:071452 layer_tree_host()->SetRootLayer(root_);
1453 layer_tree_host()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171454 }
1455
dcheng716bedf2014-10-21 09:51:081456 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591457 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1458
[email protected]9c2bd822013-07-26 12:30:171459 callback_count_ = 0;
1460
1461 // Set the mailbox on the main thread.
1462 SetMailbox('1');
1463 EXPECT_EQ(0, callback_count_);
1464
1465 PostSetNeedsCommitToMainThread();
1466 }
1467
dcheng716bedf2014-10-21 09:51:081468 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011469 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171470 case 1:
1471 // Remove the TextureLayer on the main thread while the mailbox is in
1472 // the impl tree, but don't delete the TextureLayer until after the impl
1473 // tree side is deleted.
1474 layer_->RemoveFromParent();
1475 break;
1476 case 2:
kulkarni.a4015690f12014-10-10 13:50:061477 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171478 break;
1479 }
1480 }
1481
dcheng716bedf2014-10-21 09:51:081482 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171483
1484 private:
[email protected]9794fb32013-08-29 09:49:591485 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171486 int callback_count_;
1487 scoped_refptr<Layer> root_;
1488 scoped_refptr<TextureLayer> layer_;
1489};
1490
danakj0943a112016-08-11 00:33:461491SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171492
[email protected]ba565742012-11-10 09:29:481493} // namespace
1494} // namespace cc