blob: dc9c60d3795f3d13050e5329ae5973bcac64884f [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 {
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:
samans0834fe042017-03-03 17:03:22790 void ReleaseCallback(const gpu::SyncToken& original_sync_token,
791 const gpu::SyncToken& release_sync_token,
792 bool lost_resource) {
793 released_count_++;
794 switch (released_count_) {
795 case 1:
796 break;
797 case 2:
798 EXPECT_EQ(3, layer_tree_host()->SourceFrameNumber());
799 EndTest();
800 break;
801 default:
802 NOTREACHED();
803 }
804 }
[email protected]74b43cc2013-08-30 06:29:27805
806 void SetMailbox(char mailbox_char) {
dyene5db881b2016-03-01 19:47:03807 const gpu::SyncToken sync_token =
808 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char));
danakj60bc3bc2016-04-09 00:24:48809 std::unique_ptr<SingleReleaseCallback> callback =
810 SingleReleaseCallback::Create(base::Bind(
811 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback,
samans0834fe042017-03-03 17:03:22812 base::Unretained(this), sync_token));
dyencc16ed4d2015-11-03 20:03:04813 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char),
dyene5db881b2016-03-01 19:47:03814 sync_token, GL_TEXTURE_2D),
danakja04855a2015-11-18 20:39:10815 std::move(callback));
[email protected]74b43cc2013-08-30 06:29:27816 }
817
dcheng716bedf2014-10-21 09:51:08818 void BeginTest() override {
[email protected]74b43cc2013-08-30 06:29:27819 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31820 root_ = Layer::Create();
[email protected]74b43cc2013-08-30 06:29:27821 root_->SetBounds(bounds);
822
loyso0940d412016-03-14 01:30:31823 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]74b43cc2013-08-30 06:29:27824 layer_->SetIsDrawable(true);
[email protected]74b43cc2013-08-30 06:29:27825 layer_->SetBounds(bounds);
826
827 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:07828 layer_tree_host()->SetRootLayer(root_);
829 layer_tree_host()->SetViewportSize(bounds);
[email protected]74b43cc2013-08-30 06:29:27830 SetMailbox('1');
831
832 PostSetNeedsCommitToMainThread();
833 }
834
dcheng716bedf2014-10-21 09:51:08835 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
danakj3c3973b2015-08-25 21:50:18836 base::AutoLock lock(activate_count_lock_);
[email protected]74b43cc2013-08-30 06:29:27837 ++activate_count_;
838 }
839
dcheng716bedf2014-10-21 09:51:08840 void DidCommit() override {
danakj3c3973b2015-08-25 21:50:18841 // The first frame doesn't cause anything to be returned so it does not
842 // need to wait for activation.
khushalsagarcebe4942016-09-07 23:27:01843 if (layer_tree_host()->SourceFrameNumber() > 1) {
danakj3c3973b2015-08-25 21:50:18844 base::AutoLock lock(activate_count_lock_);
845 // The activate happened before commit is done on the main side.
khushalsagarcebe4942016-09-07 23:27:01846 EXPECT_EQ(activate_count_, layer_tree_host()->SourceFrameNumber());
danakj3c3973b2015-08-25 21:50:18847 }
848
khushalsagarcebe4942016-09-07 23:27:01849 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]74b43cc2013-08-30 06:29:27850 case 1:
851 // The first mailbox has been activated. Set a new mailbox, and
852 // expect the next commit to finish *after* it is activated.
853 SetMailbox('2');
[email protected]74b43cc2013-08-30 06:29:27854 break;
855 case 2:
856 // The second mailbox has been activated. Remove the layer from
857 // the tree to cause another commit/activation. The commit should
858 // finish *after* the layer is removed from the active tree.
859 layer_->RemoveFromParent();
[email protected]74b43cc2013-08-30 06:29:27860 break;
861 case 3:
samans0834fe042017-03-03 17:03:22862 // This ensures all texture mailboxes are released before the end of the
863 // test.
864 layer_->ClearClient();
[email protected]74b43cc2013-08-30 06:29:27865 break;
samans0834fe042017-03-03 17:03:22866 default:
867 NOTREACHED();
[email protected]74b43cc2013-08-30 06:29:27868 }
869 }
870
dcheng716bedf2014-10-21 09:51:08871 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
danakj3c3973b2015-08-25 21:50:18872 // The activate didn't happen before commit is done on the impl side (but it
873 // should happen before the main thread is done).
874 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number());
[email protected]74b43cc2013-08-30 06:29:27875 }
876
dcheng716bedf2014-10-21 09:51:08877 void AfterTest() override {}
[email protected]74b43cc2013-08-30 06:29:27878
danakj3c3973b2015-08-25 21:50:18879 base::Lock activate_count_lock_;
samans0834fe042017-03-03 17:03:22880 int activate_count_ = 0;
[email protected]74b43cc2013-08-30 06:29:27881 scoped_refptr<Layer> root_;
882 scoped_refptr<TextureLayer> layer_;
samans0834fe042017-03-03 17:03:22883 int released_count_ = 0;
[email protected]74b43cc2013-08-30 06:29:27884};
885
danakj0943a112016-08-11 00:33:46886SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
[email protected]74b43cc2013-08-30 06:29:27887
[email protected]de44a152013-01-08 15:28:46888class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15889 protected:
dcheng93a52eb2014-12-23 02:14:23890 void SetUp() override {
[email protected]28571b042013-03-14 07:59:15891 TextureLayerTest::SetUp();
loyso2cb3f32f2016-11-08 07:08:34892 layer_tree_host_ = MockLayerTreeHost::Create(
893 &fake_client_, &task_graph_runner_, animation_host_.get());
sievers71c62dd52015-10-07 01:44:39894 host_impl_.SetVisible(true);
danakj1120f4c2016-09-15 02:05:32895 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get()));
[email protected]28571b042013-03-14 07:59:15896 }
[email protected]de44a152013-01-08 15:28:46897
[email protected]0ec335c42013-07-04 06:17:08898 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
899 bool will_draw = layer->WillDraw(
900 mode, host_impl_.active_tree()->resource_provider());
901 if (will_draw)
902 layer->DidDraw(host_impl_.active_tree()->resource_provider());
903 return will_draw;
904 }
905
[email protected]408b5e22013-03-19 09:48:09906 FakeLayerTreeHostClient fake_client_;
[email protected]de44a152013-01-08 15:28:46907};
908
[email protected]ffbb2212013-06-02 23:47:59909// Test conditions for results of TextureLayerImpl::WillDraw under
910// different configurations of different mailbox, texture_id, and draw_mode.
911TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
skyostil3976a3f2014-09-04 22:07:23912 EXPECT_CALL(
913 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04914 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]0ec335c42013-07-04 06:17:08915 .Times(AnyNumber());
dyencc16ed4d2015-11-03 20:03:04916 EXPECT_CALL(
917 test_data_.mock_callback_,
918 ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _))
[email protected]0ec335c42013-07-04 06:17:08919 .Times(AnyNumber());
[email protected]ffbb2212013-06-02 23:47:59920 // Hardware mode.
921 {
danakj60bc3bc2016-04-09 00:24:48922 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11923 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16924 impl_layer->SetTextureMailbox(
925 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23926 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08927 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59928 }
929
930 {
danakj60bc3bc2016-04-09 00:24:48931 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11932 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16933 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08934 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
935 }
936
937 {
938 // Software resource.
danakj60bc3bc2016-04-09 00:24:48939 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11940 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16941 impl_layer->SetTextureMailbox(
942 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23943 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]3e44d7a2013-07-30 00:03:10944 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59945 }
946
[email protected]0ec335c42013-07-04 06:17:08947 // Software mode.
948 {
danakj60bc3bc2016-04-09 00:24:48949 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11950 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16951 impl_layer->SetTextureMailbox(
952 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23953 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08954 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
955 }
956
957 {
danakj60bc3bc2016-04-09 00:24:48958 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11959 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16960 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08961 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
962 }
963
964 {
965 // Software resource.
danakj60bc3bc2016-04-09 00:24:48966 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11967 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16968 impl_layer->SetTextureMailbox(
969 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23970 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]0ec335c42013-07-04 06:17:08971 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
972 }
973
[email protected]ffbb2212013-06-02 23:47:59974 // Resourceless software mode.
975 {
danakj60bc3bc2016-04-09 00:24:48976 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11977 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16978 impl_layer->SetTextureMailbox(
979 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23980 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08981 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
[email protected]ffbb2212013-06-02 23:47:59982 }
[email protected]ffbb2212013-06-02 23:47:59983}
984
[email protected]28571b042013-03-14 07:59:15985TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
986 host_impl_.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:48987 std::unique_ptr<TextureLayerImpl> pending_layer;
[email protected]17e08432014-04-10 00:41:11988 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1);
[email protected]28571b042013-03-14 07:59:15989 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46990
danakj60bc3bc2016-04-09 00:24:48991 std::unique_ptr<LayerImpl> active_layer(
[email protected]28571b042013-03-14 07:59:15992 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
[email protected]ed511b8d2013-03-25 03:29:29993 ASSERT_TRUE(active_layer);
[email protected]de44a152013-01-08 15:28:46994
[email protected]9260757f2013-09-17 01:24:16995 pending_layer->SetTextureMailbox(
996 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23997 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]421e84f2013-02-22 03:27:15998
[email protected]28571b042013-03-14 07:59:15999 // Test multiple commits without an activation.
skyostil3976a3f2014-09-04 22:07:231000 EXPECT_CALL(
1001 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:041002 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:151003 .Times(1);
[email protected]9260757f2013-09-17 01:24:161004 pending_layer->SetTextureMailbox(
1005 test_data_.mailbox2_,
skyostil3976a3f2014-09-04 22:07:231006 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_));
[email protected]28571b042013-03-14 07:59:151007 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:151008
[email protected]28571b042013-03-14 07:59:151009 // Test callback after activation.
[email protected]ed511b8d2013-03-25 03:29:291010 pending_layer->PushPropertiesTo(active_layer.get());
1011 active_layer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:151012
skyostil3976a3f2014-09-04 22:07:231013 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]9260757f2013-09-17 01:24:161014 pending_layer->SetTextureMailbox(
1015 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231016 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151017 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:151018
[email protected]7ba3ca72013-04-11 06:37:251019 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231020 ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1);
[email protected]ed511b8d2013-03-25 03:29:291021 pending_layer->PushPropertiesTo(active_layer.get());
1022 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:151023 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:461024
[email protected]28571b042013-03-14 07:59:151025 // Test resetting the mailbox.
[email protected]7ba3ca72013-04-11 06:37:251026 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231027 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
danakj968153f32014-10-15 22:52:161028 pending_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]ed511b8d2013-03-25 03:29:291029 pending_layer->PushPropertiesTo(active_layer.get());
1030 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:151031 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:461032
[email protected]28571b042013-03-14 07:59:151033 // Test destructor.
skyostil3976a3f2014-09-04 22:07:231034 EXPECT_CALL(
1035 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:041036 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:151037 .Times(1);
[email protected]9260757f2013-09-17 01:24:161038 pending_layer->SetTextureMailbox(
1039 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231040 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]de44a152013-01-08 15:28:461041}
1042
[email protected]28571b042013-03-14 07:59:151043TEST_F(TextureLayerImplWithMailboxTest,
1044 TestDestructorCallbackOnCreatedResource) {
danakj60bc3bc2016-04-09 00:24:481045 std::unique_ptr<TextureLayerImpl> impl_layer;
[email protected]17e08432014-04-10 00:41:111046 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]28571b042013-03-14 07:59:151047 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:461048
[email protected]7ba3ca72013-04-11 06:37:251049 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231050 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]9260757f2013-09-17 01:24:161051 impl_layer->SetTextureMailbox(
1052 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231053 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]ffbb2212013-06-02 23:47:591054 impl_layer->DidBecomeActive();
1055 EXPECT_TRUE(impl_layer->WillDraw(
1056 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider()));
[email protected]28571b042013-03-14 07:59:151057 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
danakj968153f32014-10-15 22:52:161058 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]de44a152013-01-08 15:28:461059}
1060
[email protected]28571b042013-03-14 07:59:151061TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
1062 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
jbaumanbbd425e2015-05-19 00:33:351063 ResourceId id = provider->CreateResourceFromTextureMailbox(
skyostil3976a3f2014-09-04 22:07:231064 test_data_.mailbox1_,
1065 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151066 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:461067
[email protected]28571b042013-03-14 07:59:151068 // Transfer some resources to the parent.
1069 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1070 resource_ids_to_transfer.push_back(id);
1071 TransferableResourceArray list;
1072 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
1073 EXPECT_TRUE(provider->InUseByConsumer(id));
skyostil3976a3f2014-09-04 22:07:231074 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]28571b042013-03-14 07:59:151075 provider->DeleteResource(id);
1076 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]7ba3ca72013-04-11 06:37:251077 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231078 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]e00bab022013-08-19 00:42:451079 ReturnedResourceArray returned;
1080 TransferableResource::ReturnResources(list, &returned);
1081 provider->ReceiveReturnsFromParent(returned);
[email protected]de44a152013-01-08 15:28:461082}
1083
[email protected]4bad8b62013-10-24 01:27:291084// Checks that TextureLayer::Update does not cause an extra commit when setting
1085// the texture mailbox.
1086class TextureLayerNoExtraCommitForMailboxTest
1087 : public LayerTreeTest,
1088 public TextureLayerClient {
1089 public:
[email protected]4bad8b62013-10-24 01:27:291090 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081091 bool PrepareTextureMailbox(
[email protected]df41e252014-02-03 23:39:501092 TextureMailbox* texture_mailbox,
danakj4d0dd802016-08-23 22:10:061093 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
khushalsagarcebe4942016-09-07 23:27:011094 if (layer_tree_host()->SourceFrameNumber() == 1) {
[email protected]9f35bd22014-06-03 15:25:461095 // Once this has been committed, the mailbox will be released.
[email protected]df41e252014-02-03 23:39:501096 *texture_mailbox = TextureMailbox();
[email protected]cce34bd2013-12-02 23:24:451097 return true;
1098 }
[email protected]4bad8b62013-10-24 01:27:291099
dyene5db881b2016-03-01 19:47:031100 *texture_mailbox = TextureMailbox(MailboxFromChar('1'),
1101 SyncTokenFromUInt(0x123), GL_TEXTURE_2D);
[email protected]4bad8b62013-10-24 01:27:291102 *release_callback = SingleReleaseCallback::Create(
1103 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased,
1104 base::Unretained(this)));
[email protected]4bad8b62013-10-24 01:27:291105 return true;
1106 }
1107
dyencc16ed4d2015-11-03 20:03:041108 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031109 EXPECT_TRUE(sync_token.HasData());
[email protected]cce34bd2013-12-02 23:24:451110 EndTest();
[email protected]4bad8b62013-10-24 01:27:291111 }
1112
dcheng716bedf2014-10-21 09:51:081113 void SetupTree() override {
loyso0940d412016-03-14 01:30:311114 scoped_refptr<Layer> root = Layer::Create();
[email protected]4bad8b62013-10-24 01:27:291115 root->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291116 root->SetIsDrawable(true);
1117
loyso0940d412016-03-14 01:30:311118 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]4bad8b62013-10-24 01:27:291119 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291120 texture_layer_->SetIsDrawable(true);
[email protected]0d7fb302014-01-23 21:30:471121 root->AddChild(texture_layer_);
[email protected]4bad8b62013-10-24 01:27:291122
khushalsagarb69ba9452017-01-27 22:20:071123 layer_tree_host()->SetRootLayer(root);
[email protected]4bad8b62013-10-24 01:27:291124 LayerTreeTest::SetupTree();
1125 }
1126
dcheng716bedf2014-10-21 09:51:081127 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]4bad8b62013-10-24 01:27:291128
dcheng716bedf2014-10-21 09:51:081129 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011130 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]4bad8b62013-10-24 01:27:291131 case 1:
[email protected]4ea293f72014-08-13 03:03:171132 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
[email protected]cce34bd2013-12-02 23:24:451133 // Invalidate the texture layer to clear the mailbox before
1134 // ending the test.
1135 texture_layer_->SetNeedsDisplay();
1136 break;
1137 case 2:
[email protected]4bad8b62013-10-24 01:27:291138 break;
1139 default:
1140 NOTREACHED();
1141 break;
1142 }
1143 }
1144
dcheng716bedf2014-10-21 09:51:081145 void AfterTest() override {}
[email protected]4bad8b62013-10-24 01:27:291146
1147 private:
[email protected]4bad8b62013-10-24 01:27:291148 scoped_refptr<TextureLayer> texture_layer_;
[email protected]4bad8b62013-10-24 01:27:291149};
1150
[email protected]cce34bd2013-12-02 23:24:451151SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);
[email protected]4bad8b62013-10-24 01:27:291152
[email protected]b04264f92013-09-13 23:37:291153// Checks that changing a mailbox in the client for a TextureLayer that's
1154// invisible correctly works and uses the new mailbox as soon as the layer
1155// becomes visible (and returns the old one).
1156class TextureLayerChangeInvisibleMailboxTest
1157 : public LayerTreeTest,
1158 public TextureLayerClient {
1159 public:
1160 TextureLayerChangeInvisibleMailboxTest()
1161 : mailbox_changed_(true),
1162 mailbox_returned_(0),
1163 prepare_called_(0),
1164 commit_count_(0) {
1165 mailbox_ = MakeMailbox('1');
1166 }
1167
1168 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081169 bool PrepareTextureMailbox(
[email protected]e51444a2013-12-10 23:05:011170 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061171 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]b04264f92013-09-13 23:37:291172 ++prepare_called_;
1173 if (!mailbox_changed_)
1174 return false;
1175 *mailbox = mailbox_;
[email protected]9260757f2013-09-17 01:24:161176 *release_callback = SingleReleaseCallback::Create(
1177 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased,
1178 base::Unretained(this)));
[email protected]b04264f92013-09-13 23:37:291179 return true;
1180 }
1181
1182 TextureMailbox MakeMailbox(char name) {
dyene5db881b2016-03-01 19:47:031183 return TextureMailbox(MailboxFromChar(name),
1184 SyncTokenFromUInt(static_cast<uint32_t>(name)),
dyencc16ed4d2015-11-03 20:03:041185 GL_TEXTURE_2D);
[email protected]b04264f92013-09-13 23:37:291186 }
1187
dyencc16ed4d2015-11-03 20:03:041188 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031189 EXPECT_TRUE(sync_token.HasData());
[email protected]b04264f92013-09-13 23:37:291190 ++mailbox_returned_;
samans5dbd77c72017-03-03 17:51:321191 switch (mailbox_returned_) {
1192 case 1:
1193 break;
1194 case 2:
1195 EXPECT_EQ(commit_count_, 5);
1196 EndTest();
1197 break;
1198 default:
1199 NOTREACHED();
1200 }
[email protected]b04264f92013-09-13 23:37:291201 }
1202
dcheng716bedf2014-10-21 09:51:081203 void SetupTree() override {
loyso0940d412016-03-14 01:30:311204 scoped_refptr<Layer> root = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291205 root->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291206 root->SetIsDrawable(true);
1207
loyso0940d412016-03-14 01:30:311208 solid_layer_ = SolidColorLayer::Create();
[email protected]b04264f92013-09-13 23:37:291209 solid_layer_->SetBounds(gfx::Size(10, 10));
1210 solid_layer_->SetIsDrawable(true);
1211 solid_layer_->SetBackgroundColor(SK_ColorWHITE);
1212 root->AddChild(solid_layer_);
1213
loyso0940d412016-03-14 01:30:311214 parent_layer_ = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291215 parent_layer_->SetBounds(gfx::Size(10, 10));
1216 parent_layer_->SetIsDrawable(true);
1217 root->AddChild(parent_layer_);
1218
loyso0940d412016-03-14 01:30:311219 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]b04264f92013-09-13 23:37:291220 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291221 texture_layer_->SetIsDrawable(true);
1222 parent_layer_->AddChild(texture_layer_);
1223
khushalsagarb69ba9452017-01-27 22:20:071224 layer_tree_host()->SetRootLayer(root);
[email protected]b04264f92013-09-13 23:37:291225 LayerTreeTest::SetupTree();
1226 }
1227
dcheng716bedf2014-10-21 09:51:081228 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]b04264f92013-09-13 23:37:291229
dcheng716bedf2014-10-21 09:51:081230 void DidCommitAndDrawFrame() override {
[email protected]b04264f92013-09-13 23:37:291231 ++commit_count_;
1232 switch (commit_count_) {
1233 case 1:
1234 // We should have updated the layer, committing the texture.
1235 EXPECT_EQ(1, prepare_called_);
1236 // Make layer invisible.
1237 parent_layer_->SetOpacity(0.f);
1238 break;
1239 case 2:
1240 // Layer shouldn't have been updated.
1241 EXPECT_EQ(1, prepare_called_);
1242 // Change the texture.
1243 mailbox_ = MakeMailbox('2');
1244 mailbox_changed_ = true;
1245 texture_layer_->SetNeedsDisplay();
1246 // Force a change to make sure we draw a frame.
1247 solid_layer_->SetBackgroundColor(SK_ColorGRAY);
1248 break;
1249 case 3:
1250 // Layer shouldn't have been updated.
1251 EXPECT_EQ(1, prepare_called_);
1252 // So the old mailbox isn't returned yet.
1253 EXPECT_EQ(0, mailbox_returned_);
1254 // Make layer visible again.
jaydasikacf223762016-05-16 23:02:091255 parent_layer_->SetOpacity(0.9f);
[email protected]b04264f92013-09-13 23:37:291256 break;
1257 case 4:
1258 // Layer should have been updated.
1259 EXPECT_EQ(2, prepare_called_);
1260 // So the old mailbox should have been returned already.
1261 EXPECT_EQ(1, mailbox_returned_);
1262 texture_layer_->ClearClient();
1263 break;
1264 case 5:
[email protected]b04264f92013-09-13 23:37:291265 break;
1266 default:
1267 NOTREACHED();
1268 break;
1269 }
1270 }
1271
dcheng716bedf2014-10-21 09:51:081272 void AfterTest() override {}
[email protected]b04264f92013-09-13 23:37:291273
1274 private:
1275 scoped_refptr<SolidColorLayer> solid_layer_;
1276 scoped_refptr<Layer> parent_layer_;
1277 scoped_refptr<TextureLayer> texture_layer_;
1278
1279 // Used on the main thread.
1280 bool mailbox_changed_;
1281 TextureMailbox mailbox_;
1282 int mailbox_returned_;
1283 int prepare_called_;
1284 int commit_count_;
1285};
1286
maxmorin3d6b9c442017-04-05 10:41:141287// Flaky when multi-threaded. crbug.com/702868
1288SINGLE_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
[email protected]b04264f92013-09-13 23:37:291289
[email protected]0d7fb302014-01-23 21:30:471290// Test that TextureLayerImpl::ReleaseResources can be called which releases
1291// the mailbox back to TextureLayerClient.
1292class TextureLayerReleaseResourcesBase
1293 : public LayerTreeTest,
1294 public TextureLayerClient {
1295 public:
1296 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081297 bool PrepareTextureMailbox(
[email protected]0d7fb302014-01-23 21:30:471298 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061299 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
dyene5db881b2016-03-01 19:47:031300 *mailbox = TextureMailbox(MailboxFromChar('1'), SyncTokenFromUInt(1),
1301 GL_TEXTURE_2D);
[email protected]0d7fb302014-01-23 21:30:471302 *release_callback = SingleReleaseCallback::Create(
1303 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased,
1304 base::Unretained(this)));
1305 return true;
1306 }
1307
dyencc16ed4d2015-11-03 20:03:041308 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]0d7fb302014-01-23 21:30:471309 mailbox_released_ = true;
1310 }
1311
dcheng716bedf2014-10-21 09:51:081312 void SetupTree() override {
[email protected]0d7fb302014-01-23 21:30:471313 LayerTreeTest::SetupTree();
1314
1315 scoped_refptr<TextureLayer> texture_layer =
loyso0940d412016-03-14 01:30:311316 TextureLayer::CreateForMailbox(this);
[email protected]0d7fb302014-01-23 21:30:471317 texture_layer->SetBounds(gfx::Size(10, 10));
[email protected]0d7fb302014-01-23 21:30:471318 texture_layer->SetIsDrawable(true);
1319
khushalsagarb69ba9452017-01-27 22:20:071320 layer_tree_host()->root_layer()->AddChild(texture_layer);
jaydasikabd6f15a2016-04-21 19:45:371321 texture_layer_id_ = texture_layer->id();
[email protected]0d7fb302014-01-23 21:30:471322 }
1323
dcheng716bedf2014-10-21 09:51:081324 void BeginTest() override {
[email protected]0d7fb302014-01-23 21:30:471325 mailbox_released_ = false;
1326 PostSetNeedsCommitToMainThread();
1327 }
1328
dcheng716bedf2014-10-21 09:51:081329 void DidCommitAndDrawFrame() override { EndTest(); }
[email protected]0d7fb302014-01-23 21:30:471330
dcheng716bedf2014-10-21 09:51:081331 void AfterTest() override { EXPECT_TRUE(mailbox_released_); }
[email protected]0d7fb302014-01-23 21:30:471332
jaydasikabd6f15a2016-04-21 19:45:371333 protected:
1334 int texture_layer_id_;
1335
[email protected]0d7fb302014-01-23 21:30:471336 private:
1337 bool mailbox_released_;
1338};
1339
1340class TextureLayerReleaseResourcesAfterCommit
1341 : public TextureLayerReleaseResourcesBase {
1342 public:
dcheng716bedf2014-10-21 09:51:081343 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
kulkarni.a4015690f12014-10-10 13:50:061344 LayerTreeImpl* tree = nullptr;
danakj009cdfdf2015-02-17 22:35:141345 tree = host_impl->sync_tree();
jaydasikabd6f15a2016-04-21 19:45:371346 tree->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471347 }
1348};
1349
1350SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);
1351
1352class TextureLayerReleaseResourcesAfterActivate
1353 : public TextureLayerReleaseResourcesBase {
1354 public:
dcheng716bedf2014-10-21 09:51:081355 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
jaydasikabd6f15a2016-04-21 19:45:371356 host_impl->active_tree()->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471357 }
1358};
1359
1360SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);
1361
[email protected]9c2bd822013-07-26 12:30:171362class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest {
1363 public:
dyencc16ed4d2015-11-03 20:03:041364 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591365 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171366 EXPECT_FALSE(lost_resource);
1367 ++callback_count_;
1368 EndTest();
1369 }
1370
1371 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591372 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481373 std::unique_ptr<SingleReleaseCallback> callback =
1374 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171375 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback,
1376 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031377 layer_->SetTextureMailbox(
1378 TextureMailbox(MailboxFromChar(mailbox_char),
1379 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1380 GL_TEXTURE_2D),
1381 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171382 }
1383
dcheng716bedf2014-10-21 09:51:081384 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171385 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311386 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171387 root_->SetBounds(bounds);
1388
loyso0940d412016-03-14 01:30:311389 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171390 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171391 layer_->SetBounds(bounds);
1392
1393 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:071394 layer_tree_host()->SetRootLayer(root_);
1395 layer_tree_host()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171396 }
1397
dcheng716bedf2014-10-21 09:51:081398 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591399 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1400
[email protected]9c2bd822013-07-26 12:30:171401 callback_count_ = 0;
1402
1403 // Set the mailbox on the main thread.
1404 SetMailbox('1');
1405 EXPECT_EQ(0, callback_count_);
1406
1407 PostSetNeedsCommitToMainThread();
1408 }
1409
dcheng716bedf2014-10-21 09:51:081410 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011411 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171412 case 1:
1413 // Delete the TextureLayer on the main thread while the mailbox is in
1414 // the impl tree.
1415 layer_->RemoveFromParent();
kulkarni.a4015690f12014-10-10 13:50:061416 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171417 break;
1418 }
1419 }
1420
dcheng716bedf2014-10-21 09:51:081421 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171422
1423 private:
[email protected]9794fb32013-08-29 09:49:591424 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171425 int callback_count_;
1426 scoped_refptr<Layer> root_;
1427 scoped_refptr<TextureLayer> layer_;
1428};
1429
danakj0943a112016-08-11 00:33:461430SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxMainThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171431
1432class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest {
1433 public:
dyencc16ed4d2015-11-03 20:03:041434 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591435 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171436 EXPECT_FALSE(lost_resource);
1437 ++callback_count_;
1438 EndTest();
1439 }
1440
1441 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591442 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481443 std::unique_ptr<SingleReleaseCallback> callback =
1444 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171445 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback,
1446 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031447 layer_->SetTextureMailbox(
1448 TextureMailbox(MailboxFromChar(mailbox_char),
1449 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1450 GL_TEXTURE_2D),
1451 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171452 }
1453
dcheng716bedf2014-10-21 09:51:081454 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171455 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311456 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171457 root_->SetBounds(bounds);
1458
loyso0940d412016-03-14 01:30:311459 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171460 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171461 layer_->SetBounds(bounds);
1462
1463 root_->AddChild(layer_);
khushalsagarb69ba9452017-01-27 22:20:071464 layer_tree_host()->SetRootLayer(root_);
1465 layer_tree_host()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171466 }
1467
dcheng716bedf2014-10-21 09:51:081468 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591469 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1470
[email protected]9c2bd822013-07-26 12:30:171471 callback_count_ = 0;
1472
1473 // Set the mailbox on the main thread.
1474 SetMailbox('1');
1475 EXPECT_EQ(0, callback_count_);
1476
1477 PostSetNeedsCommitToMainThread();
1478 }
1479
dcheng716bedf2014-10-21 09:51:081480 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011481 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171482 case 1:
1483 // Remove the TextureLayer on the main thread while the mailbox is in
1484 // the impl tree, but don't delete the TextureLayer until after the impl
1485 // tree side is deleted.
1486 layer_->RemoveFromParent();
1487 break;
1488 case 2:
kulkarni.a4015690f12014-10-10 13:50:061489 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171490 break;
1491 }
1492 }
1493
dcheng716bedf2014-10-21 09:51:081494 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171495
1496 private:
[email protected]9794fb32013-08-29 09:49:591497 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171498 int callback_count_;
1499 scoped_refptr<Layer> root_;
1500 scoped_refptr<TextureLayer> layer_;
1501};
1502
danakj0943a112016-08-11 00:33:461503SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171504
[email protected]ba565742012-11-10 09:29:481505} // namespace
1506} // namespace cc