blob: f0a68028e4ae024d36c0adda9c92d15a8fd63b05 [file] [log] [blame]
[email protected]c0dd24c2012-08-30 23:25:271// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cc3cfaa2013-03-18 09:05:525#include "cc/layers/texture_layer.h"
[email protected]c0dd24c2012-08-30 23:25:276
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8#include <stdint.h>
9
[email protected]b04264f92013-09-13 23:37:2910#include <algorithm>
[email protected]de44a152013-01-08 15:28:4611#include <string>
12
[email protected]b04264f92013-09-13 23:37:2913#include "base/bind.h"
[email protected]de44a152013-01-08 15:28:4614#include "base/callback.h"
skyostil0fd1dad2015-04-13 20:11:4815#include "base/location.h"
avi02a4d172015-12-21 06:14:3616#include "base/macros.h"
danakj60bc3bc2016-04-09 00:24:4817#include "base/memory/ptr_util.h"
skyostil0fd1dad2015-04-13 20:11:4818#include "base/single_thread_task_runner.h"
danakj3c3973b2015-08-25 21:50:1819#include "base/synchronization/lock.h"
[email protected]9794fb32013-08-29 09:49:5920#include "base/synchronization/waitable_event.h"
[email protected]74b43cc2013-08-30 06:29:2721#include "base/threading/thread.h"
gab39cb4ed72016-05-11 17:45:1922#include "base/threading/thread_task_runner_handle.h"
[email protected]74b43cc2013-08-30 06:29:2723#include "base/time/time.h"
loysoab32ee72016-06-08 03:33:1824#include "cc/animation/animation_host.h"
[email protected]b04264f92013-09-13 23:37:2925#include "cc/layers/solid_color_layer.h"
[email protected]97d519fb2013-03-29 02:27:5426#include "cc/layers/texture_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5227#include "cc/layers/texture_layer_impl.h"
[email protected]b04264f92013-09-13 23:37:2928#include "cc/output/context_provider.h"
[email protected]e00bab022013-08-19 00:42:4529#include "cc/resources/returned_resource.h"
danakj1120f4c2016-09-15 02:05:3230#include "cc/test/fake_compositor_frame_sink.h"
khushalsagarb64b360d2015-10-21 19:25:1631#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]101441ce2012-10-16 01:45:0332#include "cc/test/fake_layer_tree_host_client.h"
[email protected]586d51ed2012-12-07 20:31:4533#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]06d68d02013-04-19 18:46:2134#include "cc/test/layer_test_common.h"
[email protected]e216fef02013-03-20 22:56:1035#include "cc/test/layer_tree_test.h"
danakjffc181a2016-07-22 22:48:4336#include "cc/test/stub_layer_tree_host_single_thread_client.h"
danakj1120f4c2016-09-15 02:05:3237#include "cc/test/test_compositor_frame_sink.h"
reveman34b7a1522015-03-23 20:27:4738#include "cc/test/test_task_graph_runner.h"
[email protected]c2610b9f2013-10-31 06:54:5939#include "cc/test/test_web_graphics_context_3d.h"
[email protected]9794fb32013-08-29 09:49:5940#include "cc/trees/blocking_task_runner.h"
khushalsagare0e4486e2017-01-25 03:15:0341#include "cc/trees/layer_tree_host.h"
[email protected]556fd292013-03-18 08:03:0442#include "cc/trees/layer_tree_impl.h"
43#include "cc/trees/single_thread_proxy.h"
[email protected]0bf5a202013-07-10 14:50:5444#include "gpu/GLES2/gl2extchromium.h"
[email protected]7f0c53db2012-10-02 00:23:1845#include "testing/gmock/include/gmock/gmock.h"
46#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2747
[email protected]c0dd24c2012-08-30 23:25:2748using ::testing::Mock;
49using ::testing::_;
50using ::testing::AtLeast;
51using ::testing::AnyNumber;
[email protected]d72d9e02014-04-03 18:40:0952using ::testing::InvokeWithoutArgs;
[email protected]c0dd24c2012-08-30 23:25:2753
[email protected]ba565742012-11-10 09:29:4854namespace cc {
[email protected]c0dd24c2012-08-30 23:25:2755namespace {
56
[email protected]e0a4d732014-02-15 00:23:2657gpu::Mailbox MailboxFromChar(char value) {
[email protected]df41e252014-02-03 23:39:5058 gpu::Mailbox mailbox;
[email protected]e0a4d732014-02-15 00:23:2659 memset(mailbox.name, value, sizeof(mailbox.name));
[email protected]df41e252014-02-03 23:39:5060 return mailbox;
61}
62
dyen398dd0142016-01-21 22:05:5663gpu::SyncToken SyncTokenFromUInt(uint32_t value) {
lukasza2573ce7d2016-02-16 19:17:2264 return gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0,
65 gpu::CommandBufferId::FromUnsafeValue(0x123), value);
dyen398dd0142016-01-21 22:05:5666}
67
khushalsagare0e4486e2017-01-25 03:15:0368class MockLayerTreeHost : public LayerTreeHost {
[email protected]28571b042013-03-14 07:59:1569 public:
danakj60bc3bc2016-04-09 00:24:4870 static std::unique_ptr<MockLayerTreeHost> Create(
danakjcf610582015-06-16 22:48:5671 FakeLayerTreeHostClient* client,
loyso2cb3f32f2016-11-08 07:08:3472 TaskGraphRunner* task_graph_runner,
73 MutatorHost* mutator_host) {
khushalsagare0e4486e2017-01-25 03:15:0374 LayerTreeHost::InitParams params;
sadrul6780f3da2015-05-11 17:01:5275 params.client = client;
danakjcf610582015-06-16 22:48:5676 params.task_graph_runner = task_graph_runner;
loyso2cb3f32f2016-11-08 07:08:3477 params.mutator_host = mutator_host;
sadrul6780f3da2015-05-11 17:01:5278 LayerTreeSettings settings;
jaydasika853306a2016-07-29 19:28:3479 settings.verify_clip_tree_calculations = true;
sadrul6780f3da2015-05-11 17:01:5280 params.settings = &settings;
danakjffc181a2016-07-22 22:48:4381 return base::WrapUnique(new MockLayerTreeHost(&params));
[email protected]28571b042013-03-14 07:59:1582 }
[email protected]c0dd24c2012-08-30 23:25:2783
[email protected]28571b042013-03-14 07:59:1584 MOCK_METHOD0(SetNeedsCommit, void());
[email protected]3519b872013-07-30 07:17:5085 MOCK_METHOD0(SetNeedsUpdateLayers, void());
[email protected]aeeb3372013-11-05 14:05:5486 MOCK_METHOD0(StartRateLimiter, void());
87 MOCK_METHOD0(StopRateLimiter, void());
sadrul6780f3da2015-05-11 17:01:5288
89 private:
khushalsagare0e4486e2017-01-25 03:15:0390 explicit MockLayerTreeHost(LayerTreeHost::InitParams* params)
91 : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) {
danakjffc181a2016-07-22 22:48:4392 InitializeSingleThreaded(&single_thread_client_,
enne2b0ad682016-09-21 01:44:4793 base::ThreadTaskRunnerHandle::Get());
sadrul6780f3da2015-05-11 17:01:5294 }
danakjffc181a2016-07-22 22:48:4395
96 StubLayerTreeHostSingleThreadClient single_thread_client_;
[email protected]c0dd24c2012-08-30 23:25:2797};
98
[email protected]d72d9e02014-04-03 18:40:0999class FakeTextureLayerClient : public TextureLayerClient {
100 public:
[email protected]17e08432014-04-10 00:41:11101 FakeTextureLayerClient() : mailbox_changed_(true) {}
[email protected]d72d9e02014-04-03 18:40:09102
dcheng716bedf2014-10-21 09:51:08103 bool PrepareTextureMailbox(
[email protected]d72d9e02014-04-03 18:40:09104 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:06105 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]d72d9e02014-04-03 18:40:09106 if (!mailbox_changed_)
107 return false;
108
109 *mailbox = mailbox_;
danakja04855a2015-11-18 20:39:10110 *release_callback = std::move(release_callback_);
[email protected]d72d9e02014-04-03 18:40:09111 mailbox_changed_ = false;
112 return true;
113 }
114
[email protected]d72d9e02014-04-03 18:40:09115 void set_mailbox(const TextureMailbox& mailbox,
danakj60bc3bc2016-04-09 00:24:48116 std::unique_ptr<SingleReleaseCallback> release_callback) {
[email protected]d72d9e02014-04-03 18:40:09117 mailbox_ = mailbox;
danakja04855a2015-11-18 20:39:10118 release_callback_ = std::move(release_callback);
[email protected]d72d9e02014-04-03 18:40:09119 mailbox_changed_ = true;
120 }
121
122 private:
[email protected]d72d9e02014-04-03 18:40:09123 TextureMailbox mailbox_;
danakj60bc3bc2016-04-09 00:24:48124 std::unique_ptr<SingleReleaseCallback> release_callback_;
[email protected]d72d9e02014-04-03 18:40:09125 bool mailbox_changed_;
126 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient);
127};
128
129class MockMailboxCallback {
130 public:
131 MOCK_METHOD3(Release,
132 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04133 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09134 bool lost_resource));
135 MOCK_METHOD3(Release2,
jbauman9015c8b2014-12-11 00:49:37136 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04137 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09138 bool lost_resource));
skyostil3976a3f2014-09-04 22:07:23139 MOCK_METHOD4(ReleaseImpl,
140 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04141 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23142 bool lost_resource,
143 BlockingTaskRunner* main_thread_task_runner));
144 MOCK_METHOD4(ReleaseImpl2,
jbauman9015c8b2014-12-11 00:49:37145 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04146 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23147 bool lost_resource,
148 BlockingTaskRunner* main_thread_task_runner));
[email protected]d72d9e02014-04-03 18:40:09149};
150
151struct CommonMailboxObjects {
jbauman9015c8b2014-12-11 00:49:37152 explicit CommonMailboxObjects(SharedBitmapManager* manager)
[email protected]d72d9e02014-04-03 18:40:09153 : mailbox_name1_(MailboxFromChar('1')),
154 mailbox_name2_(MailboxFromChar('2')),
lukasza2573ce7d2016-02-16 19:17:22155 sync_token1_(gpu::CommandBufferNamespace::GPU_IO,
156 123,
157 gpu::CommandBufferId::FromUnsafeValue(0x234),
158 1),
159 sync_token2_(gpu::CommandBufferNamespace::GPU_IO,
160 123,
161 gpu::CommandBufferId::FromUnsafeValue(0x234),
162 2) {
[email protected]d72d9e02014-04-03 18:40:09163 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
164 base::Unretained(&mock_callback_),
165 mailbox_name1_);
166 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
167 base::Unretained(&mock_callback_),
168 mailbox_name2_);
skyostil3976a3f2014-09-04 22:07:23169 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
170 base::Unretained(&mock_callback_),
171 mailbox_name1_);
172 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
173 base::Unretained(&mock_callback_),
174 mailbox_name2_);
avi02a4d172015-12-21 06:14:36175 const uint32_t arbitrary_target1 = GL_TEXTURE_2D;
176 const uint32_t arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
dyencc16ed4d2015-11-03 20:03:04177 mailbox1_ = TextureMailbox(mailbox_name1_, sync_token1_, arbitrary_target1);
178 mailbox2_ = TextureMailbox(mailbox_name2_, sync_token2_, arbitrary_target2);
[email protected]d72d9e02014-04-03 18:40:09179 gfx::Size size(128, 128);
jbauman9015c8b2014-12-11 00:49:37180 shared_bitmap_ = manager->AllocateSharedBitmap(size);
181 DCHECK(shared_bitmap_);
182 release_mailbox3_ =
183 base::Bind(&MockMailboxCallback::Release2,
184 base::Unretained(&mock_callback_), shared_bitmap_.get());
185 release_mailbox3_impl_ =
186 base::Bind(&MockMailboxCallback::ReleaseImpl2,
187 base::Unretained(&mock_callback_), shared_bitmap_.get());
188 mailbox3_ = TextureMailbox(shared_bitmap_.get(), size);
[email protected]d72d9e02014-04-03 18:40:09189 }
190
191 gpu::Mailbox mailbox_name1_;
192 gpu::Mailbox mailbox_name2_;
193 MockMailboxCallback mock_callback_;
194 ReleaseCallback release_mailbox1_;
195 ReleaseCallback release_mailbox2_;
196 ReleaseCallback release_mailbox3_;
skyostil3976a3f2014-09-04 22:07:23197 ReleaseCallbackImpl release_mailbox1_impl_;
198 ReleaseCallbackImpl release_mailbox2_impl_;
199 ReleaseCallbackImpl release_mailbox3_impl_;
[email protected]d72d9e02014-04-03 18:40:09200 TextureMailbox mailbox1_;
201 TextureMailbox mailbox2_;
202 TextureMailbox mailbox3_;
dyencc16ed4d2015-11-03 20:03:04203 gpu::SyncToken sync_token1_;
204 gpu::SyncToken sync_token2_;
danakj60bc3bc2016-04-09 00:24:48205 std::unique_ptr<SharedBitmap> shared_bitmap_;
[email protected]d72d9e02014-04-03 18:40:09206};
207
[email protected]31d4df82013-07-18 10:17:22208class TextureLayerTest : public testing::Test {
209 public:
210 TextureLayerTest()
danakj1120f4c2016-09-15 02:05:32211 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()),
khushalsagarb64b360d2015-10-21 19:25:16212 host_impl_(&task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:16213 &task_graph_runner_),
jbauman9015c8b2014-12-11 00:49:37214 test_data_(&shared_bitmap_manager_) {}
[email protected]31d4df82013-07-18 10:17:22215
216 protected:
dcheng93a52eb2014-12-23 02:14:23217 void SetUp() override {
loyso2cb3f32f2016-11-08 07:08:34218 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
219 layer_tree_host_ = MockLayerTreeHost::Create(
220 &fake_client_, &task_graph_runner_, animation_host_.get());
khushalsagar86928f92016-08-17 21:49:05221 layer_tree_ = layer_tree_host_->GetLayerTree();
[email protected]d72d9e02014-04-03 18:40:09222 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagar86928f92016-08-17 21:49:05223 layer_tree_->SetViewportSize(gfx::Size(10, 10));
[email protected]d72d9e02014-04-03 18:40:09224 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22225 }
226
dcheng93a52eb2014-12-23 02:14:23227 void TearDown() override {
[email protected]31d4df82013-07-18 10:17:22228 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22229 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
230
loyso2cb3f32f2016-11-08 07:08:34231 animation_host_->SetMutatorHostClient(nullptr);
khushalsagar86928f92016-08-17 21:49:05232 layer_tree_->SetRootLayer(nullptr);
danakjf446a072014-09-27 21:55:48233 layer_tree_host_ = nullptr;
loyso2cb3f32f2016-11-08 07:08:34234 animation_host_ = nullptr;
[email protected]31d4df82013-07-18 10:17:22235 }
236
danakj60bc3bc2016-04-09 00:24:48237 std::unique_ptr<MockLayerTreeHost> layer_tree_host_;
loyso2cb3f32f2016-11-08 07:08:34238 std::unique_ptr<AnimationHost> animation_host_;
khushalsagar86928f92016-08-17 21:49:05239 LayerTree* layer_tree_;
khushalsagarb64b360d2015-10-21 19:25:16240 FakeImplTaskRunnerProvider task_runner_provider_;
[email protected]31d4df82013-07-18 10:17:22241 FakeLayerTreeHostClient fake_client_;
[email protected]4e2eb352014-03-20 17:25:45242 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:47243 TestTaskGraphRunner task_graph_runner_;
danakj1120f4c2016-09-15 02:05:32244 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_;
[email protected]31d4df82013-07-18 10:17:22245 FakeLayerTreeHostImpl host_impl_;
jbauman9015c8b2014-12-11 00:49:37246 CommonMailboxObjects test_data_;
[email protected]31d4df82013-07-18 10:17:22247};
248
[email protected]31d4df82013-07-18 10:17:22249TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
kulkarni.a4015690f12014-10-10 13:50:06250 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31251 TextureLayer::CreateForMailbox(nullptr);
khushalsagar86928f92016-08-17 21:49:05252 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer));
[email protected]31d4df82013-07-18 10:17:22253
254 // Test properties that should call SetNeedsCommit. All properties need to
255 // be set to new values in order for SetNeedsCommit to be called.
256 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
jackhou10c9af42014-12-04 05:24:44257 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
[email protected]31d4df82013-07-18 10:17:22258 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
259 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
260 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
261 0.5f, 0.5f, 0.5f, 0.5f));
262 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
263 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true));
[email protected]31d4df82013-07-18 10:17:22264}
265
[email protected]df41e252014-02-03 23:39:50266class TestMailboxHolder : public TextureLayer::TextureMailboxHolder {
[email protected]9794fb32013-08-29 09:49:59267 public:
[email protected]df41e252014-02-03 23:39:50268 using TextureLayer::TextureMailboxHolder::Create;
[email protected]9794fb32013-08-29 09:49:59269
270 protected:
dcheng716bedf2014-10-21 09:51:08271 ~TestMailboxHolder() override {}
[email protected]9794fb32013-08-29 09:49:59272};
273
[email protected]de44a152013-01-08 15:28:46274class TextureLayerWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15275 protected:
dcheng93a52eb2014-12-23 02:14:23276 void TearDown() override {
[email protected]28571b042013-03-14 07:59:15277 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
dyencc16ed4d2015-11-03 20:03:04278 EXPECT_CALL(
279 test_data_.mock_callback_,
280 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
281 .Times(1);
[email protected]28571b042013-03-14 07:59:15282 TextureLayerTest::TearDown();
283 }
[email protected]de44a152013-01-08 15:28:46284};
285
[email protected]28571b042013-03-14 07:59:15286TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
kulkarni.a4015690f12014-10-10 13:50:06287 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31288 TextureLayer::CreateForMailbox(nullptr);
[email protected]22898ed2013-06-01 04:52:30289 ASSERT_TRUE(test_layer.get());
[email protected]de44a152013-01-08 15:28:46290
[email protected]28571b042013-03-14 07:59:15291 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagar86928f92016-08-17 21:49:05292 layer_tree_->SetRootLayer(test_layer);
[email protected]28571b042013-03-14 07:59:15293 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46294
[email protected]28571b042013-03-14 07:59:15295 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16296 test_layer->SetTextureMailbox(
297 test_data_.mailbox1_,
298 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]28571b042013-03-14 07:59:15299 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46300
[email protected]28571b042013-03-14 07:59:15301 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04302 EXPECT_CALL(
303 test_data_.mock_callback_,
304 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
[email protected]28571b042013-03-14 07:59:15305 .Times(1);
[email protected]9260757f2013-09-17 01:24:16306 test_layer->SetTextureMailbox(
307 test_data_.mailbox2_,
308 SingleReleaseCallback::Create(test_data_.release_mailbox2_));
[email protected]28571b042013-03-14 07:59:15309 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
310 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46311
[email protected]28571b042013-03-14 07:59:15312 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04313 EXPECT_CALL(
314 test_data_.mock_callback_,
315 Release(test_data_.mailbox_name2_, test_data_.sync_token2_, false))
[email protected]28571b042013-03-14 07:59:15316 .Times(1);
danakj968153f32014-10-15 22:52:16317 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]28571b042013-03-14 07:59:15318 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
319 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46320
[email protected]80d42bd2013-08-30 19:13:45321 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16322 test_layer->SetTextureMailbox(
323 test_data_.mailbox3_,
324 SingleReleaseCallback::Create(test_data_.release_mailbox3_));
[email protected]42f40a52013-06-08 04:38:51325 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
326 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
327
[email protected]42f40a52013-06-08 04:38:51328 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
329 EXPECT_CALL(test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04330 Release2(test_data_.shared_bitmap_.get(), _, false))
331 .Times(1);
danakj968153f32014-10-15 22:52:16332 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]42f40a52013-06-08 04:38:51333 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
334 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
335
[email protected]28571b042013-03-14 07:59:15336 // Test destructor.
337 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16338 test_layer->SetTextureMailbox(
339 test_data_.mailbox1_,
340 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]de44a152013-01-08 15:28:46341}
342
[email protected]9794fb32013-08-29 09:49:59343class TextureLayerMailboxHolderTest : public TextureLayerTest {
344 public:
345 TextureLayerMailboxHolderTest()
346 : main_thread_("MAIN") {
347 main_thread_.Start();
fdoray70df5a92016-06-22 21:13:59348 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48349 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::InitializeOnMain,
350 base::Unretained(this)));
skyostil3976a3f2014-09-04 22:07:23351 Wait(main_thread_);
[email protected]9794fb32013-08-29 09:49:59352 }
353
354 void Wait(const base::Thread& thread) {
gabcca53112016-06-08 20:13:28355 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
356 base::WaitableEvent::InitialState::NOT_SIGNALED);
fdoray70df5a92016-06-22 21:13:59357 thread.task_runner()->PostTask(
[email protected]9794fb32013-08-29 09:49:59358 FROM_HERE,
359 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
360 event.Wait();
361 }
362
363 void CreateMainRef() {
364 main_ref_ = TestMailboxHolder::Create(
[email protected]9260757f2013-09-17 01:24:16365 test_data_.mailbox1_,
danakja5a05ba02015-11-20 20:14:21366 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]9794fb32013-08-29 09:49:59367 }
368
danakjf446a072014-09-27 21:55:48369 void ReleaseMainRef() { main_ref_ = nullptr; }
[email protected]9794fb32013-08-29 09:49:59370
danakj60bc3bc2016-04-09 00:24:48371 void CreateImplRef(std::unique_ptr<SingleReleaseCallbackImpl>* impl_ref) {
[email protected]9794fb32013-08-29 09:49:59372 *impl_ref = main_ref_->holder()->GetCallbackForImplThread();
373 }
374
375 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture,
376 base::WaitableEvent* wait_for_capture,
377 base::WaitableEvent* stop_capture) {
378 begin_capture->Wait();
skyostil3976a3f2014-09-04 22:07:23379 BlockingTaskRunner::CapturePostTasks capture(
380 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59381 wait_for_capture->Signal();
382 stop_capture->Wait();
383 }
384
385 protected:
skyostil3976a3f2014-09-04 22:07:23386 void InitializeOnMain() {
387 main_thread_task_runner_ =
skyostil0fd1dad2015-04-13 20:11:48388 BlockingTaskRunner::Create(main_thread_.task_runner());
skyostil3976a3f2014-09-04 22:07:23389 }
390
danakj60bc3bc2016-04-09 00:24:48391 std::unique_ptr<TestMailboxHolder::MainThreadReference> main_ref_;
[email protected]9794fb32013-08-29 09:49:59392 base::Thread main_thread_;
danakj60bc3bc2016-04-09 00:24:48393 std::unique_ptr<BlockingTaskRunner> main_thread_task_runner_;
[email protected]9794fb32013-08-29 09:49:59394};
395
396TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) {
kulkarni.a4015690f12014-10-10 13:50:06397 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31398 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59399 ASSERT_TRUE(test_layer.get());
400
fdoray70df5a92016-06-22 21:13:59401 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48402 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
403 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59404
405 Wait(main_thread_);
406
407 // The texture layer is attached to compositor1, and passes a reference to its
408 // impl tree.
danakj60bc3bc2016-04-09 00:24:48409 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59410 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48411 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
412 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59413
414 // Then the texture layer is removed and attached to compositor2, and passes a
415 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48416 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59417 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48418 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
419 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59420
421 Wait(main_thread_);
422 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
423
424 // The compositors both destroy their impl trees before the main thread layer
425 // is destroyed.
dyen398dd0142016-01-21 22:05:56426 compositor1->Run(SyncTokenFromUInt(100), false,
427 main_thread_task_runner_.get());
428 compositor2->Run(SyncTokenFromUInt(200), false,
429 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59430
431 Wait(main_thread_);
432
433 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
434 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
435
436 // The main thread ref is the last one, so the mailbox is released back to the
437 // embedder, with the last sync point provided by the impl trees.
438 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56439 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), false))
dyencc16ed4d2015-11-03 20:03:04440 .Times(1);
[email protected]9794fb32013-08-29 09:49:59441
fdoray70df5a92016-06-22 21:13:59442 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48443 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
444 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59445 Wait(main_thread_);
446 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
447}
448
449TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) {
kulkarni.a4015690f12014-10-10 13:50:06450 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31451 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59452 ASSERT_TRUE(test_layer.get());
453
fdoray70df5a92016-06-22 21:13:59454 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48455 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
456 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59457
458 Wait(main_thread_);
459
460 // The texture layer is attached to compositor1, and passes a reference to its
461 // impl tree.
danakj60bc3bc2016-04-09 00:24:48462 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59463 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48464 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
465 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59466
467 // Then the texture layer is removed and attached to compositor2, and passes a
468 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48469 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59470 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48471 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
472 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59473
474 Wait(main_thread_);
475 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
476
477 // One compositor destroys their impl tree.
dyen398dd0142016-01-21 22:05:56478 compositor1->Run(SyncTokenFromUInt(100), false,
479 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59480
481 // Then the main thread reference is destroyed.
fdoray70df5a92016-06-22 21:13:59482 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48483 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
484 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59485
486 Wait(main_thread_);
487
488 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
489 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
490
491 // The second impl reference is destroyed last, causing the mailbox to be
492 // released back to the embedder with the last sync point from the impl tree.
493 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56494 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
dyencc16ed4d2015-11-03 20:03:04495 .Times(1);
[email protected]9794fb32013-08-29 09:49:59496
dyen398dd0142016-01-21 22:05:56497 compositor2->Run(SyncTokenFromUInt(200), true,
498 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59499 Wait(main_thread_);
500 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
501}
502
503TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {
kulkarni.a4015690f12014-10-10 13:50:06504 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31505 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59506 ASSERT_TRUE(test_layer.get());
507
fdoray70df5a92016-06-22 21:13:59508 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48509 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
510 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59511
512 Wait(main_thread_);
513
514 // The texture layer is attached to compositor1, and passes a reference to its
515 // impl tree.
danakj60bc3bc2016-04-09 00:24:48516 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59517 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48518 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
519 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59520
521 // Then the texture layer is removed and attached to compositor2, and passes a
522 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48523 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59524 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48525 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
526 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59527
528 Wait(main_thread_);
529 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
530
531 // The main thread reference is destroyed first.
fdoray70df5a92016-06-22 21:13:59532 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48533 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
534 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59535
536 // One compositor destroys their impl tree.
dyen398dd0142016-01-21 22:05:56537 compositor2->Run(SyncTokenFromUInt(200), false,
538 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59539
540 Wait(main_thread_);
541
542 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
543 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
544
545 // The second impl reference is destroyed last, causing the mailbox to be
546 // released back to the embedder with the last sync point from the impl tree.
547 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56548 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(100), true))
dyencc16ed4d2015-11-03 20:03:04549 .Times(1);
[email protected]9794fb32013-08-29 09:49:59550
dyen398dd0142016-01-21 22:05:56551 compositor1->Run(SyncTokenFromUInt(100), true,
552 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59553 Wait(main_thread_);
554 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
555}
556
557TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) {
kulkarni.a4015690f12014-10-10 13:50:06558 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31559 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59560 ASSERT_TRUE(test_layer.get());
561
fdoray70df5a92016-06-22 21:13:59562 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48563 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
564 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59565
566 Wait(main_thread_);
567
568 // The texture layer is attached to compositor1, and passes a reference to its
569 // impl tree.
danakj60bc3bc2016-04-09 00:24:48570 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59571 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48572 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
573 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59574
575 // Then the texture layer is removed and attached to compositor2, and passes a
576 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48577 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59578 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48579 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
580 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59581
582 Wait(main_thread_);
583 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
584
585 // The main thread reference is destroyed first.
fdoray70df5a92016-06-22 21:13:59586 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48587 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
588 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59589
590 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56591 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
dyencc16ed4d2015-11-03 20:03:04592 .Times(1);
[email protected]9794fb32013-08-29 09:49:59593
gabcca53112016-06-08 20:13:28594 base::WaitableEvent begin_capture(
595 base::WaitableEvent::ResetPolicy::AUTOMATIC,
596 base::WaitableEvent::InitialState::NOT_SIGNALED);
597 base::WaitableEvent wait_for_capture(
598 base::WaitableEvent::ResetPolicy::AUTOMATIC,
599 base::WaitableEvent::InitialState::NOT_SIGNALED);
600 base::WaitableEvent stop_capture(
601 base::WaitableEvent::ResetPolicy::AUTOMATIC,
602 base::WaitableEvent::InitialState::NOT_SIGNALED);
[email protected]9794fb32013-08-29 09:49:59603
604 // Post a task to start capturing tasks on the main thread. This will block
605 // the main thread until we signal the |stop_capture| event.
fdoray70df5a92016-06-22 21:13:59606 main_thread_.task_runner()->PostTask(
[email protected]9794fb32013-08-29 09:49:59607 FROM_HERE,
608 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait,
skyostil0fd1dad2015-04-13 20:11:48609 base::Unretained(this), &begin_capture, &wait_for_capture,
[email protected]9794fb32013-08-29 09:49:59610 &stop_capture));
611
612 // Before the main thread capturing starts, one compositor destroys their
613 // impl reference. Since capturing did not start, this gets post-tasked to
614 // the main thread.
dyen398dd0142016-01-21 22:05:56615 compositor1->Run(SyncTokenFromUInt(100), false,
616 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59617
618 // Start capturing on the main thread.
619 begin_capture.Signal();
620 wait_for_capture.Wait();
621
622 // Meanwhile, the second compositor released its impl reference, but this task
623 // gets shortcutted directly to the main thread. This means the reference is
624 // released before compositor1, whose reference will be released later when
625 // the post-task is serviced. But since it was destroyed _on the impl thread_
626 // last, its sync point values should be used.
dyen398dd0142016-01-21 22:05:56627 compositor2->Run(SyncTokenFromUInt(200), true,
628 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59629
630 stop_capture.Signal();
631 Wait(main_thread_);
632
633 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
634}
635
[email protected]e216fef02013-03-20 22:56:10636class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {
[email protected]28571b042013-03-14 07:59:15637 public:
danakj014316e2016-08-04 18:40:26638 TextureLayerImplWithMailboxThreadedCallback() = default;
639
danakj1120f4c2016-09-15 02:05:32640 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink(
danakj014316e2016-08-04 18:40:26641 scoped_refptr<ContextProvider> compositor_context_provider,
642 scoped_refptr<ContextProvider> worker_context_provider) override {
643 bool synchronous_composite =
644 !HasImplThread() &&
khushalsagarcebe4942016-09-07 23:27:01645 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler;
ericrk4b443522017-01-13 22:54:24646 // Allow relaim resources for this test so that mailboxes in the display
647 // will be returned inside the commit that replaces them.
648 bool force_disable_reclaim_resources = false;
danakj1120f4c2016-09-15 02:05:32649 return base::MakeUnique<TestCompositorFrameSink>(
danakj014316e2016-08-04 18:40:26650 compositor_context_provider, std::move(worker_context_provider),
danakj014316e2016-08-04 18:40:26651 shared_bitmap_manager(), gpu_memory_buffer_manager(),
khushalsagarcebe4942016-09-07 23:27:01652 layer_tree_host()->GetSettings().renderer_settings,
ericrk4b443522017-01-13 22:54:24653 ImplThreadTaskRunner(), synchronous_composite,
654 force_disable_reclaim_resources);
danakj014316e2016-08-04 18:40:26655 }
[email protected]28571b042013-03-14 07:59:15656
657 // Make sure callback is received on main and doesn't block the impl thread.
danakj014316e2016-08-04 18:40:26658 void ReleaseCallback(char mailbox_char,
659 const gpu::SyncToken& sync_token,
660 bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:59661 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]7ba3ca72013-04-11 06:37:25662 EXPECT_FALSE(lost_resource);
[email protected]28571b042013-03-14 07:59:15663 ++callback_count_;
664 }
665
666 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:59667 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:48668 std::unique_ptr<SingleReleaseCallback> callback =
669 SingleReleaseCallback::Create(base::Bind(
[email protected]28571b042013-03-14 07:59:15670 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback,
danakj014316e2016-08-04 18:40:26671 base::Unretained(this), mailbox_char));
dyene5db881b2016-03-01 19:47:03672 layer_->SetTextureMailbox(
673 TextureMailbox(MailboxFromChar(mailbox_char),
674 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
675 GL_TEXTURE_2D),
676 std::move(callback));
danakj014316e2016-08-04 18:40:26677 // Damage the layer so we send a new frame with the new mailbox to the
678 // Display compositor.
679 layer_->SetNeedsDisplay();
[email protected]28571b042013-03-14 07:59:15680 }
681
dcheng716bedf2014-10-21 09:51:08682 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:59683 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
684
[email protected]28571b042013-03-14 07:59:15685 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31686 root_ = Layer::Create();
[email protected]28571b042013-03-14 07:59:15687 root_->SetBounds(bounds);
688
loyso0940d412016-03-14 01:30:31689 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]28571b042013-03-14 07:59:15690 layer_->SetIsDrawable(true);
[email protected]28571b042013-03-14 07:59:15691 layer_->SetBounds(bounds);
692
693 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:05694 layer_tree()->SetRootLayer(root_);
695 layer_tree()->SetViewportSize(bounds);
[email protected]28571b042013-03-14 07:59:15696 SetMailbox('1');
697 EXPECT_EQ(0, callback_count_);
698
699 // Case #1: change mailbox before the commit. The old mailbox should be
700 // released immediately.
701 SetMailbox('2');
702 EXPECT_EQ(1, callback_count_);
[email protected]e216fef02013-03-20 22:56:10703 PostSetNeedsCommitToMainThread();
[email protected]28571b042013-03-14 07:59:15704 }
705
dcheng716bedf2014-10-21 09:51:08706 void DidCommit() override {
ericrk4b443522017-01-13 22:54:24707 ++commit_count_;
708 switch (commit_count_) {
[email protected]28571b042013-03-14 07:59:15709 case 1:
710 // Case #2: change mailbox after the commit (and draw), where the
711 // layer draws. The old mailbox should be released during the next
712 // commit.
713 SetMailbox('3');
714 EXPECT_EQ(1, callback_count_);
715 break;
716 case 2:
[email protected]28571b042013-03-14 07:59:15717 EXPECT_EQ(2, callback_count_);
718 // Case #3: change mailbox when the layer doesn't draw. The old
719 // mailbox should be released during the next commit.
720 layer_->SetBounds(gfx::Size());
721 SetMailbox('4');
722 break;
[email protected]9794fb32013-08-29 09:49:59723 case 3:
[email protected]28571b042013-03-14 07:59:15724 EXPECT_EQ(3, callback_count_);
725 // Case #4: release mailbox that was committed but never drawn. The
726 // old mailbox should be released during the next commit.
danakj968153f32014-10-15 22:52:16727 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]28571b042013-03-14 07:59:15728 break;
[email protected]9794fb32013-08-29 09:49:59729 case 4:
[email protected]28571b042013-03-14 07:59:15730 EXPECT_EQ(4, callback_count_);
[email protected]7096acc2013-06-18 21:12:43731 // Restore a mailbox for the next step.
732 SetMailbox('5');
733 break;
danakj014316e2016-08-04 18:40:26734 case 5:
[email protected]7096acc2013-06-18 21:12:43735 // Case #5: remove layer from tree. Callback should *not* be called, the
736 // mailbox is returned to the main thread.
737 EXPECT_EQ(4, callback_count_);
738 layer_->RemoveFromParent();
739 break;
danakj014316e2016-08-04 18:40:26740 case 6:
[email protected]7096acc2013-06-18 21:12:43741 EXPECT_EQ(4, callback_count_);
742 // Resetting the mailbox will call the callback now.
danakj968153f32014-10-15 22:52:16743 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]7096acc2013-06-18 21:12:43744 EXPECT_EQ(5, callback_count_);
[email protected]e216fef02013-03-20 22:56:10745 EndTest();
[email protected]28571b042013-03-14 07:59:15746 break;
747 default:
748 NOTREACHED();
749 break;
[email protected]de44a152013-01-08 15:28:46750 }
[email protected]28571b042013-03-14 07:59:15751 }
[email protected]de44a152013-01-08 15:28:46752
dcheng716bedf2014-10-21 09:51:08753 void AfterTest() override {}
[email protected]de44a152013-01-08 15:28:46754
[email protected]28571b042013-03-14 07:59:15755 private:
[email protected]9794fb32013-08-29 09:49:59756 base::ThreadChecker main_thread_;
danakj014316e2016-08-04 18:40:26757 int callback_count_ = 0;
ericrk4b443522017-01-13 22:54:24758 int commit_count_ = 0;
[email protected]28571b042013-03-14 07:59:15759 scoped_refptr<Layer> root_;
760 scoped_refptr<TextureLayer> layer_;
[email protected]de44a152013-01-08 15:28:46761};
762
danakj0943a112016-08-11 00:33:46763SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
[email protected]74b43cc2013-08-30 06:29:27764
[email protected]74b43cc2013-08-30 06:29:27765class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest {
766 protected:
[email protected]98ea818e2014-01-24 10:22:08767 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {}
[email protected]74b43cc2013-08-30 06:29:27768
dyene5db881b2016-03-01 19:47:03769 static void ReleaseCallback(const gpu::SyncToken& original_sync_token,
770 const gpu::SyncToken& release_sync_token,
dyencc16ed4d2015-11-03 20:03:04771 bool lost_resource) {}
[email protected]74b43cc2013-08-30 06:29:27772
773 void SetMailbox(char mailbox_char) {
dyene5db881b2016-03-01 19:47:03774 const gpu::SyncToken sync_token =
775 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char));
danakj60bc3bc2016-04-09 00:24:48776 std::unique_ptr<SingleReleaseCallback> callback =
777 SingleReleaseCallback::Create(base::Bind(
778 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback,
779 sync_token));
dyencc16ed4d2015-11-03 20:03:04780 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char),
dyene5db881b2016-03-01 19:47:03781 sync_token, GL_TEXTURE_2D),
danakja04855a2015-11-18 20:39:10782 std::move(callback));
[email protected]74b43cc2013-08-30 06:29:27783 }
784
dcheng716bedf2014-10-21 09:51:08785 void BeginTest() override {
[email protected]74b43cc2013-08-30 06:29:27786 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31787 root_ = Layer::Create();
[email protected]74b43cc2013-08-30 06:29:27788 root_->SetBounds(bounds);
789
loyso0940d412016-03-14 01:30:31790 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]74b43cc2013-08-30 06:29:27791 layer_->SetIsDrawable(true);
[email protected]74b43cc2013-08-30 06:29:27792 layer_->SetBounds(bounds);
793
794 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:05795 layer_tree()->SetRootLayer(root_);
796 layer_tree()->SetViewportSize(bounds);
[email protected]74b43cc2013-08-30 06:29:27797 SetMailbox('1');
798
799 PostSetNeedsCommitToMainThread();
800 }
801
dcheng716bedf2014-10-21 09:51:08802 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
danakj3c3973b2015-08-25 21:50:18803 base::AutoLock lock(activate_count_lock_);
[email protected]74b43cc2013-08-30 06:29:27804 ++activate_count_;
805 }
806
dcheng716bedf2014-10-21 09:51:08807 void DidCommit() override {
danakj3c3973b2015-08-25 21:50:18808 // The first frame doesn't cause anything to be returned so it does not
809 // need to wait for activation.
khushalsagarcebe4942016-09-07 23:27:01810 if (layer_tree_host()->SourceFrameNumber() > 1) {
danakj3c3973b2015-08-25 21:50:18811 base::AutoLock lock(activate_count_lock_);
812 // The activate happened before commit is done on the main side.
khushalsagarcebe4942016-09-07 23:27:01813 EXPECT_EQ(activate_count_, layer_tree_host()->SourceFrameNumber());
danakj3c3973b2015-08-25 21:50:18814 }
815
khushalsagarcebe4942016-09-07 23:27:01816 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]74b43cc2013-08-30 06:29:27817 case 1:
818 // The first mailbox has been activated. Set a new mailbox, and
819 // expect the next commit to finish *after* it is activated.
820 SetMailbox('2');
[email protected]74b43cc2013-08-30 06:29:27821 break;
822 case 2:
823 // The second mailbox has been activated. Remove the layer from
824 // the tree to cause another commit/activation. The commit should
825 // finish *after* the layer is removed from the active tree.
826 layer_->RemoveFromParent();
[email protected]74b43cc2013-08-30 06:29:27827 break;
828 case 3:
829 EndTest();
830 break;
831 }
832 }
833
dcheng716bedf2014-10-21 09:51:08834 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
danakj3c3973b2015-08-25 21:50:18835 // The activate didn't happen before commit is done on the impl side (but it
836 // should happen before the main thread is done).
837 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number());
[email protected]74b43cc2013-08-30 06:29:27838 }
839
dcheng716bedf2014-10-21 09:51:08840 void AfterTest() override {}
[email protected]74b43cc2013-08-30 06:29:27841
danakj3c3973b2015-08-25 21:50:18842 base::Lock activate_count_lock_;
[email protected]74b43cc2013-08-30 06:29:27843 int activate_count_;
844 scoped_refptr<Layer> root_;
845 scoped_refptr<TextureLayer> layer_;
846};
847
tsergeantf41fd0f2016-09-29 00:20:39848// Flaky on windows and linux. https://crbug.com/641613
849#if !defined(OS_WIN) && !defined(OS_LINUX)
danakj0943a112016-08-11 00:33:46850SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
dgroganf22b7692016-08-30 23:24:08851#endif
[email protected]74b43cc2013-08-30 06:29:27852
[email protected]de44a152013-01-08 15:28:46853class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15854 protected:
dcheng93a52eb2014-12-23 02:14:23855 void SetUp() override {
[email protected]28571b042013-03-14 07:59:15856 TextureLayerTest::SetUp();
loyso2cb3f32f2016-11-08 07:08:34857 layer_tree_host_ = MockLayerTreeHost::Create(
858 &fake_client_, &task_graph_runner_, animation_host_.get());
khushalsagar86928f92016-08-17 21:49:05859 layer_tree_ = layer_tree_host_->GetLayerTree();
sievers71c62dd52015-10-07 01:44:39860 host_impl_.SetVisible(true);
danakj1120f4c2016-09-15 02:05:32861 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get()));
[email protected]28571b042013-03-14 07:59:15862 }
[email protected]de44a152013-01-08 15:28:46863
[email protected]0ec335c42013-07-04 06:17:08864 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
865 bool will_draw = layer->WillDraw(
866 mode, host_impl_.active_tree()->resource_provider());
867 if (will_draw)
868 layer->DidDraw(host_impl_.active_tree()->resource_provider());
869 return will_draw;
870 }
871
[email protected]408b5e22013-03-19 09:48:09872 FakeLayerTreeHostClient fake_client_;
[email protected]de44a152013-01-08 15:28:46873};
874
[email protected]ffbb2212013-06-02 23:47:59875// Test conditions for results of TextureLayerImpl::WillDraw under
876// different configurations of different mailbox, texture_id, and draw_mode.
877TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
skyostil3976a3f2014-09-04 22:07:23878 EXPECT_CALL(
879 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04880 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]0ec335c42013-07-04 06:17:08881 .Times(AnyNumber());
dyencc16ed4d2015-11-03 20:03:04882 EXPECT_CALL(
883 test_data_.mock_callback_,
884 ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _))
[email protected]0ec335c42013-07-04 06:17:08885 .Times(AnyNumber());
[email protected]ffbb2212013-06-02 23:47:59886 // Hardware mode.
887 {
danakj60bc3bc2016-04-09 00:24:48888 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11889 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16890 impl_layer->SetTextureMailbox(
891 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23892 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08893 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59894 }
895
896 {
danakj60bc3bc2016-04-09 00:24:48897 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11898 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16899 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08900 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
901 }
902
903 {
904 // Software resource.
danakj60bc3bc2016-04-09 00:24:48905 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11906 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16907 impl_layer->SetTextureMailbox(
908 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23909 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]3e44d7a2013-07-30 00:03:10910 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59911 }
912
[email protected]0ec335c42013-07-04 06:17:08913 // Software mode.
914 {
danakj60bc3bc2016-04-09 00:24:48915 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11916 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16917 impl_layer->SetTextureMailbox(
918 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23919 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08920 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
921 }
922
923 {
danakj60bc3bc2016-04-09 00:24:48924 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11925 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16926 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08927 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
928 }
929
930 {
931 // Software resource.
danakj60bc3bc2016-04-09 00:24:48932 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11933 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16934 impl_layer->SetTextureMailbox(
935 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23936 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]0ec335c42013-07-04 06:17:08937 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
938 }
939
[email protected]ffbb2212013-06-02 23:47:59940 // Resourceless software mode.
941 {
danakj60bc3bc2016-04-09 00:24:48942 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11943 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16944 impl_layer->SetTextureMailbox(
945 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23946 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08947 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
[email protected]ffbb2212013-06-02 23:47:59948 }
[email protected]ffbb2212013-06-02 23:47:59949}
950
[email protected]28571b042013-03-14 07:59:15951TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
952 host_impl_.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:48953 std::unique_ptr<TextureLayerImpl> pending_layer;
[email protected]17e08432014-04-10 00:41:11954 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1);
[email protected]28571b042013-03-14 07:59:15955 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46956
danakj60bc3bc2016-04-09 00:24:48957 std::unique_ptr<LayerImpl> active_layer(
[email protected]28571b042013-03-14 07:59:15958 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
[email protected]ed511b8d2013-03-25 03:29:29959 ASSERT_TRUE(active_layer);
[email protected]de44a152013-01-08 15:28:46960
[email protected]9260757f2013-09-17 01:24:16961 pending_layer->SetTextureMailbox(
962 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23963 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]421e84f2013-02-22 03:27:15964
[email protected]28571b042013-03-14 07:59:15965 // Test multiple commits without an activation.
skyostil3976a3f2014-09-04 22:07:23966 EXPECT_CALL(
967 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04968 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:15969 .Times(1);
[email protected]9260757f2013-09-17 01:24:16970 pending_layer->SetTextureMailbox(
971 test_data_.mailbox2_,
skyostil3976a3f2014-09-04 22:07:23972 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_));
[email protected]28571b042013-03-14 07:59:15973 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15974
[email protected]28571b042013-03-14 07:59:15975 // Test callback after activation.
[email protected]ed511b8d2013-03-25 03:29:29976 pending_layer->PushPropertiesTo(active_layer.get());
977 active_layer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:15978
skyostil3976a3f2014-09-04 22:07:23979 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]9260757f2013-09-17 01:24:16980 pending_layer->SetTextureMailbox(
981 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23982 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:15983 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15984
[email protected]7ba3ca72013-04-11 06:37:25985 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:23986 ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1);
[email protected]ed511b8d2013-03-25 03:29:29987 pending_layer->PushPropertiesTo(active_layer.get());
988 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:15989 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46990
[email protected]28571b042013-03-14 07:59:15991 // Test resetting the mailbox.
[email protected]7ba3ca72013-04-11 06:37:25992 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:23993 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
danakj968153f32014-10-15 22:52:16994 pending_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]ed511b8d2013-03-25 03:29:29995 pending_layer->PushPropertiesTo(active_layer.get());
996 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:15997 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46998
[email protected]28571b042013-03-14 07:59:15999 // Test destructor.
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_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231006 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]de44a152013-01-08 15:28:461007}
1008
[email protected]28571b042013-03-14 07:59:151009TEST_F(TextureLayerImplWithMailboxTest,
1010 TestDestructorCallbackOnCreatedResource) {
danakj60bc3bc2016-04-09 00:24:481011 std::unique_ptr<TextureLayerImpl> impl_layer;
[email protected]17e08432014-04-10 00:41:111012 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]28571b042013-03-14 07:59:151013 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:461014
[email protected]7ba3ca72013-04-11 06:37:251015 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231016 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]9260757f2013-09-17 01:24:161017 impl_layer->SetTextureMailbox(
1018 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231019 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]ffbb2212013-06-02 23:47:591020 impl_layer->DidBecomeActive();
1021 EXPECT_TRUE(impl_layer->WillDraw(
1022 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider()));
[email protected]28571b042013-03-14 07:59:151023 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
danakj968153f32014-10-15 22:52:161024 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]de44a152013-01-08 15:28:461025}
1026
[email protected]28571b042013-03-14 07:59:151027TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
1028 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
jbaumanbbd425e2015-05-19 00:33:351029 ResourceId id = provider->CreateResourceFromTextureMailbox(
skyostil3976a3f2014-09-04 22:07:231030 test_data_.mailbox1_,
1031 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151032 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:461033
[email protected]28571b042013-03-14 07:59:151034 // Transfer some resources to the parent.
1035 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1036 resource_ids_to_transfer.push_back(id);
1037 TransferableResourceArray list;
1038 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
1039 EXPECT_TRUE(provider->InUseByConsumer(id));
skyostil3976a3f2014-09-04 22:07:231040 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]28571b042013-03-14 07:59:151041 provider->DeleteResource(id);
1042 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]7ba3ca72013-04-11 06:37:251043 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231044 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]e00bab022013-08-19 00:42:451045 ReturnedResourceArray returned;
1046 TransferableResource::ReturnResources(list, &returned);
1047 provider->ReceiveReturnsFromParent(returned);
[email protected]de44a152013-01-08 15:28:461048}
1049
[email protected]4bad8b62013-10-24 01:27:291050// Checks that TextureLayer::Update does not cause an extra commit when setting
1051// the texture mailbox.
1052class TextureLayerNoExtraCommitForMailboxTest
1053 : public LayerTreeTest,
1054 public TextureLayerClient {
1055 public:
[email protected]4bad8b62013-10-24 01:27:291056 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081057 bool PrepareTextureMailbox(
[email protected]df41e252014-02-03 23:39:501058 TextureMailbox* texture_mailbox,
danakj4d0dd802016-08-23 22:10:061059 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
khushalsagarcebe4942016-09-07 23:27:011060 if (layer_tree_host()->SourceFrameNumber() == 1) {
[email protected]9f35bd22014-06-03 15:25:461061 // Once this has been committed, the mailbox will be released.
[email protected]df41e252014-02-03 23:39:501062 *texture_mailbox = TextureMailbox();
[email protected]cce34bd2013-12-02 23:24:451063 return true;
1064 }
[email protected]4bad8b62013-10-24 01:27:291065
dyene5db881b2016-03-01 19:47:031066 *texture_mailbox = TextureMailbox(MailboxFromChar('1'),
1067 SyncTokenFromUInt(0x123), GL_TEXTURE_2D);
[email protected]4bad8b62013-10-24 01:27:291068 *release_callback = SingleReleaseCallback::Create(
1069 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased,
1070 base::Unretained(this)));
[email protected]4bad8b62013-10-24 01:27:291071 return true;
1072 }
1073
dyencc16ed4d2015-11-03 20:03:041074 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031075 EXPECT_TRUE(sync_token.HasData());
[email protected]cce34bd2013-12-02 23:24:451076 EndTest();
[email protected]4bad8b62013-10-24 01:27:291077 }
1078
dcheng716bedf2014-10-21 09:51:081079 void SetupTree() override {
loyso0940d412016-03-14 01:30:311080 scoped_refptr<Layer> root = Layer::Create();
[email protected]4bad8b62013-10-24 01:27:291081 root->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291082 root->SetIsDrawable(true);
1083
loyso0940d412016-03-14 01:30:311084 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]4bad8b62013-10-24 01:27:291085 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291086 texture_layer_->SetIsDrawable(true);
[email protected]0d7fb302014-01-23 21:30:471087 root->AddChild(texture_layer_);
[email protected]4bad8b62013-10-24 01:27:291088
khushalsagar86928f92016-08-17 21:49:051089 layer_tree()->SetRootLayer(root);
[email protected]4bad8b62013-10-24 01:27:291090 LayerTreeTest::SetupTree();
1091 }
1092
dcheng716bedf2014-10-21 09:51:081093 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]4bad8b62013-10-24 01:27:291094
dcheng716bedf2014-10-21 09:51:081095 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011096 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]4bad8b62013-10-24 01:27:291097 case 1:
[email protected]4ea293f72014-08-13 03:03:171098 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
[email protected]cce34bd2013-12-02 23:24:451099 // Invalidate the texture layer to clear the mailbox before
1100 // ending the test.
1101 texture_layer_->SetNeedsDisplay();
1102 break;
1103 case 2:
[email protected]4bad8b62013-10-24 01:27:291104 break;
1105 default:
1106 NOTREACHED();
1107 break;
1108 }
1109 }
1110
dcheng716bedf2014-10-21 09:51:081111 void AfterTest() override {}
[email protected]4bad8b62013-10-24 01:27:291112
1113 private:
[email protected]4bad8b62013-10-24 01:27:291114 scoped_refptr<TextureLayer> texture_layer_;
[email protected]4bad8b62013-10-24 01:27:291115};
1116
[email protected]cce34bd2013-12-02 23:24:451117SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);
[email protected]4bad8b62013-10-24 01:27:291118
[email protected]b04264f92013-09-13 23:37:291119// Checks that changing a mailbox in the client for a TextureLayer that's
1120// invisible correctly works and uses the new mailbox as soon as the layer
1121// becomes visible (and returns the old one).
1122class TextureLayerChangeInvisibleMailboxTest
1123 : public LayerTreeTest,
1124 public TextureLayerClient {
1125 public:
1126 TextureLayerChangeInvisibleMailboxTest()
1127 : mailbox_changed_(true),
1128 mailbox_returned_(0),
1129 prepare_called_(0),
1130 commit_count_(0) {
1131 mailbox_ = MakeMailbox('1');
1132 }
1133
1134 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081135 bool PrepareTextureMailbox(
[email protected]e51444a2013-12-10 23:05:011136 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061137 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]b04264f92013-09-13 23:37:291138 ++prepare_called_;
1139 if (!mailbox_changed_)
1140 return false;
1141 *mailbox = mailbox_;
[email protected]9260757f2013-09-17 01:24:161142 *release_callback = SingleReleaseCallback::Create(
1143 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased,
1144 base::Unretained(this)));
[email protected]b04264f92013-09-13 23:37:291145 return true;
1146 }
1147
1148 TextureMailbox MakeMailbox(char name) {
dyene5db881b2016-03-01 19:47:031149 return TextureMailbox(MailboxFromChar(name),
1150 SyncTokenFromUInt(static_cast<uint32_t>(name)),
dyencc16ed4d2015-11-03 20:03:041151 GL_TEXTURE_2D);
[email protected]b04264f92013-09-13 23:37:291152 }
1153
dyencc16ed4d2015-11-03 20:03:041154 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031155 EXPECT_TRUE(sync_token.HasData());
[email protected]b04264f92013-09-13 23:37:291156 ++mailbox_returned_;
1157 }
1158
dcheng716bedf2014-10-21 09:51:081159 void SetupTree() override {
loyso0940d412016-03-14 01:30:311160 scoped_refptr<Layer> root = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291161 root->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291162 root->SetIsDrawable(true);
1163
loyso0940d412016-03-14 01:30:311164 solid_layer_ = SolidColorLayer::Create();
[email protected]b04264f92013-09-13 23:37:291165 solid_layer_->SetBounds(gfx::Size(10, 10));
1166 solid_layer_->SetIsDrawable(true);
1167 solid_layer_->SetBackgroundColor(SK_ColorWHITE);
1168 root->AddChild(solid_layer_);
1169
loyso0940d412016-03-14 01:30:311170 parent_layer_ = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291171 parent_layer_->SetBounds(gfx::Size(10, 10));
1172 parent_layer_->SetIsDrawable(true);
1173 root->AddChild(parent_layer_);
1174
loyso0940d412016-03-14 01:30:311175 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]b04264f92013-09-13 23:37:291176 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291177 texture_layer_->SetIsDrawable(true);
1178 parent_layer_->AddChild(texture_layer_);
1179
khushalsagar86928f92016-08-17 21:49:051180 layer_tree()->SetRootLayer(root);
[email protected]b04264f92013-09-13 23:37:291181 LayerTreeTest::SetupTree();
1182 }
1183
dcheng716bedf2014-10-21 09:51:081184 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]b04264f92013-09-13 23:37:291185
dcheng716bedf2014-10-21 09:51:081186 void DidCommitAndDrawFrame() override {
[email protected]b04264f92013-09-13 23:37:291187 ++commit_count_;
1188 switch (commit_count_) {
1189 case 1:
1190 // We should have updated the layer, committing the texture.
1191 EXPECT_EQ(1, prepare_called_);
1192 // Make layer invisible.
1193 parent_layer_->SetOpacity(0.f);
1194 break;
1195 case 2:
1196 // Layer shouldn't have been updated.
1197 EXPECT_EQ(1, prepare_called_);
1198 // Change the texture.
1199 mailbox_ = MakeMailbox('2');
1200 mailbox_changed_ = true;
1201 texture_layer_->SetNeedsDisplay();
1202 // Force a change to make sure we draw a frame.
1203 solid_layer_->SetBackgroundColor(SK_ColorGRAY);
1204 break;
1205 case 3:
1206 // Layer shouldn't have been updated.
1207 EXPECT_EQ(1, prepare_called_);
1208 // So the old mailbox isn't returned yet.
1209 EXPECT_EQ(0, mailbox_returned_);
1210 // Make layer visible again.
jaydasikacf223762016-05-16 23:02:091211 parent_layer_->SetOpacity(0.9f);
[email protected]b04264f92013-09-13 23:37:291212 break;
1213 case 4:
1214 // Layer should have been updated.
1215 EXPECT_EQ(2, prepare_called_);
1216 // So the old mailbox should have been returned already.
1217 EXPECT_EQ(1, mailbox_returned_);
1218 texture_layer_->ClearClient();
1219 break;
1220 case 5:
1221 EXPECT_EQ(2, mailbox_returned_);
1222 EndTest();
1223 break;
1224 default:
1225 NOTREACHED();
1226 break;
1227 }
1228 }
1229
dcheng716bedf2014-10-21 09:51:081230 void AfterTest() override {}
[email protected]b04264f92013-09-13 23:37:291231
1232 private:
1233 scoped_refptr<SolidColorLayer> solid_layer_;
1234 scoped_refptr<Layer> parent_layer_;
1235 scoped_refptr<TextureLayer> texture_layer_;
1236
1237 // Used on the main thread.
1238 bool mailbox_changed_;
1239 TextureMailbox mailbox_;
1240 int mailbox_returned_;
1241 int prepare_called_;
1242 int commit_count_;
1243};
1244
1245SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
1246
[email protected]0d7fb302014-01-23 21:30:471247// Test that TextureLayerImpl::ReleaseResources can be called which releases
1248// the mailbox back to TextureLayerClient.
1249class TextureLayerReleaseResourcesBase
1250 : public LayerTreeTest,
1251 public TextureLayerClient {
1252 public:
1253 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081254 bool PrepareTextureMailbox(
[email protected]0d7fb302014-01-23 21:30:471255 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061256 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
dyene5db881b2016-03-01 19:47:031257 *mailbox = TextureMailbox(MailboxFromChar('1'), SyncTokenFromUInt(1),
1258 GL_TEXTURE_2D);
[email protected]0d7fb302014-01-23 21:30:471259 *release_callback = SingleReleaseCallback::Create(
1260 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased,
1261 base::Unretained(this)));
1262 return true;
1263 }
1264
dyencc16ed4d2015-11-03 20:03:041265 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]0d7fb302014-01-23 21:30:471266 mailbox_released_ = true;
1267 }
1268
dcheng716bedf2014-10-21 09:51:081269 void SetupTree() override {
[email protected]0d7fb302014-01-23 21:30:471270 LayerTreeTest::SetupTree();
1271
1272 scoped_refptr<TextureLayer> texture_layer =
loyso0940d412016-03-14 01:30:311273 TextureLayer::CreateForMailbox(this);
[email protected]0d7fb302014-01-23 21:30:471274 texture_layer->SetBounds(gfx::Size(10, 10));
[email protected]0d7fb302014-01-23 21:30:471275 texture_layer->SetIsDrawable(true);
1276
khushalsagar86928f92016-08-17 21:49:051277 layer_tree()->root_layer()->AddChild(texture_layer);
jaydasikabd6f15a2016-04-21 19:45:371278 texture_layer_id_ = texture_layer->id();
[email protected]0d7fb302014-01-23 21:30:471279 }
1280
dcheng716bedf2014-10-21 09:51:081281 void BeginTest() override {
[email protected]0d7fb302014-01-23 21:30:471282 mailbox_released_ = false;
1283 PostSetNeedsCommitToMainThread();
1284 }
1285
dcheng716bedf2014-10-21 09:51:081286 void DidCommitAndDrawFrame() override { EndTest(); }
[email protected]0d7fb302014-01-23 21:30:471287
dcheng716bedf2014-10-21 09:51:081288 void AfterTest() override { EXPECT_TRUE(mailbox_released_); }
[email protected]0d7fb302014-01-23 21:30:471289
jaydasikabd6f15a2016-04-21 19:45:371290 protected:
1291 int texture_layer_id_;
1292
[email protected]0d7fb302014-01-23 21:30:471293 private:
1294 bool mailbox_released_;
1295};
1296
1297class TextureLayerReleaseResourcesAfterCommit
1298 : public TextureLayerReleaseResourcesBase {
1299 public:
dcheng716bedf2014-10-21 09:51:081300 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
kulkarni.a4015690f12014-10-10 13:50:061301 LayerTreeImpl* tree = nullptr;
danakj009cdfdf2015-02-17 22:35:141302 tree = host_impl->sync_tree();
jaydasikabd6f15a2016-04-21 19:45:371303 tree->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471304 }
1305};
1306
1307SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);
1308
1309class TextureLayerReleaseResourcesAfterActivate
1310 : public TextureLayerReleaseResourcesBase {
1311 public:
dcheng716bedf2014-10-21 09:51:081312 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
jaydasikabd6f15a2016-04-21 19:45:371313 host_impl->active_tree()->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471314 }
1315};
1316
1317SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);
1318
[email protected]9c2bd822013-07-26 12:30:171319class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest {
1320 public:
dyencc16ed4d2015-11-03 20:03:041321 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591322 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171323 EXPECT_FALSE(lost_resource);
1324 ++callback_count_;
1325 EndTest();
1326 }
1327
1328 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591329 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481330 std::unique_ptr<SingleReleaseCallback> callback =
1331 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171332 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback,
1333 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031334 layer_->SetTextureMailbox(
1335 TextureMailbox(MailboxFromChar(mailbox_char),
1336 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1337 GL_TEXTURE_2D),
1338 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171339 }
1340
dcheng716bedf2014-10-21 09:51:081341 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171342 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311343 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171344 root_->SetBounds(bounds);
1345
loyso0940d412016-03-14 01:30:311346 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171347 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171348 layer_->SetBounds(bounds);
1349
1350 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:051351 layer_tree()->SetRootLayer(root_);
1352 layer_tree()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171353 }
1354
dcheng716bedf2014-10-21 09:51:081355 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591356 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1357
[email protected]9c2bd822013-07-26 12:30:171358 callback_count_ = 0;
1359
1360 // Set the mailbox on the main thread.
1361 SetMailbox('1');
1362 EXPECT_EQ(0, callback_count_);
1363
1364 PostSetNeedsCommitToMainThread();
1365 }
1366
dcheng716bedf2014-10-21 09:51:081367 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011368 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171369 case 1:
1370 // Delete the TextureLayer on the main thread while the mailbox is in
1371 // the impl tree.
1372 layer_->RemoveFromParent();
kulkarni.a4015690f12014-10-10 13:50:061373 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171374 break;
1375 }
1376 }
1377
dcheng716bedf2014-10-21 09:51:081378 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171379
1380 private:
[email protected]9794fb32013-08-29 09:49:591381 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171382 int callback_count_;
1383 scoped_refptr<Layer> root_;
1384 scoped_refptr<TextureLayer> layer_;
1385};
1386
danakj0943a112016-08-11 00:33:461387SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxMainThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171388
1389class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest {
1390 public:
dyencc16ed4d2015-11-03 20:03:041391 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591392 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171393 EXPECT_FALSE(lost_resource);
1394 ++callback_count_;
1395 EndTest();
1396 }
1397
1398 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591399 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481400 std::unique_ptr<SingleReleaseCallback> callback =
1401 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171402 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback,
1403 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031404 layer_->SetTextureMailbox(
1405 TextureMailbox(MailboxFromChar(mailbox_char),
1406 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1407 GL_TEXTURE_2D),
1408 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171409 }
1410
dcheng716bedf2014-10-21 09:51:081411 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171412 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311413 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171414 root_->SetBounds(bounds);
1415
loyso0940d412016-03-14 01:30:311416 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171417 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171418 layer_->SetBounds(bounds);
1419
1420 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:051421 layer_tree()->SetRootLayer(root_);
1422 layer_tree()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171423 }
1424
dcheng716bedf2014-10-21 09:51:081425 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591426 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1427
[email protected]9c2bd822013-07-26 12:30:171428 callback_count_ = 0;
1429
1430 // Set the mailbox on the main thread.
1431 SetMailbox('1');
1432 EXPECT_EQ(0, callback_count_);
1433
1434 PostSetNeedsCommitToMainThread();
1435 }
1436
dcheng716bedf2014-10-21 09:51:081437 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011438 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171439 case 1:
1440 // Remove the TextureLayer on the main thread while the mailbox is in
1441 // the impl tree, but don't delete the TextureLayer until after the impl
1442 // tree side is deleted.
1443 layer_->RemoveFromParent();
1444 break;
1445 case 2:
kulkarni.a4015690f12014-10-10 13:50:061446 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171447 break;
1448 }
1449 }
1450
dcheng716bedf2014-10-21 09:51:081451 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171452
1453 private:
[email protected]9794fb32013-08-29 09:49:591454 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171455 int callback_count_;
1456 scoped_refptr<Layer> root_;
1457 scoped_refptr<TextureLayer> layer_;
1458};
1459
danakj0943a112016-08-11 00:33:461460SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171461
[email protected]ba565742012-11-10 09:29:481462} // namespace
1463} // namespace cc