blob: 072e464cda9b43f33f5e3e2051e02f230f2ddd87 [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"
khushalsagar61567792016-09-17 00:13:5841#include "cc/trees/layer_tree_host_in_process.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
khushalsagar61567792016-09-17 00:13:5868class MockLayerTreeHost : public LayerTreeHostInProcess {
[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,
72 TaskGraphRunner* task_graph_runner) {
khushalsagar61567792016-09-17 00:13:5873 LayerTreeHostInProcess::InitParams params;
sadrul6780f3da2015-05-11 17:01:5274 params.client = client;
danakjcf610582015-06-16 22:48:5675 params.task_graph_runner = task_graph_runner;
loysoab32ee72016-06-08 03:33:1876 params.animation_host =
77 AnimationHost::CreateForTesting(ThreadInstance::MAIN);
sadrul6780f3da2015-05-11 17:01:5278 LayerTreeSettings settings;
jaydasika853306a2016-07-29 19:28:3479 settings.verify_transform_tree_calculations = true;
80 settings.verify_clip_tree_calculations = true;
sadrul6780f3da2015-05-11 17:01:5281 params.settings = &settings;
danakjffc181a2016-07-22 22:48:4382 return base::WrapUnique(new MockLayerTreeHost(&params));
[email protected]28571b042013-03-14 07:59:1583 }
[email protected]c0dd24c2012-08-30 23:25:2784
[email protected]28571b042013-03-14 07:59:1585 MOCK_METHOD0(SetNeedsCommit, void());
[email protected]3519b872013-07-30 07:17:5086 MOCK_METHOD0(SetNeedsUpdateLayers, void());
[email protected]aeeb3372013-11-05 14:05:5487 MOCK_METHOD0(StartRateLimiter, void());
88 MOCK_METHOD0(StopRateLimiter, void());
sadrul6780f3da2015-05-11 17:01:5289
90 private:
khushalsagar61567792016-09-17 00:13:5891 explicit MockLayerTreeHost(LayerTreeHostInProcess::InitParams* params)
92 : LayerTreeHostInProcess(params, CompositorMode::SINGLE_THREADED) {
danakjffc181a2016-07-22 22:48:4393 InitializeSingleThreaded(&single_thread_client_,
enne2b0ad682016-09-21 01:44:4794 base::ThreadTaskRunnerHandle::Get());
sadrul6780f3da2015-05-11 17:01:5295 }
danakjffc181a2016-07-22 22:48:4396
97 StubLayerTreeHostSingleThreadClient single_thread_client_;
[email protected]c0dd24c2012-08-30 23:25:2798};
99
[email protected]d72d9e02014-04-03 18:40:09100class FakeTextureLayerClient : public TextureLayerClient {
101 public:
[email protected]17e08432014-04-10 00:41:11102 FakeTextureLayerClient() : mailbox_changed_(true) {}
[email protected]d72d9e02014-04-03 18:40:09103
dcheng716bedf2014-10-21 09:51:08104 bool PrepareTextureMailbox(
[email protected]d72d9e02014-04-03 18:40:09105 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:06106 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]d72d9e02014-04-03 18:40:09107 if (!mailbox_changed_)
108 return false;
109
110 *mailbox = mailbox_;
danakja04855a2015-11-18 20:39:10111 *release_callback = std::move(release_callback_);
[email protected]d72d9e02014-04-03 18:40:09112 mailbox_changed_ = false;
113 return true;
114 }
115
[email protected]d72d9e02014-04-03 18:40:09116 void set_mailbox(const TextureMailbox& mailbox,
danakj60bc3bc2016-04-09 00:24:48117 std::unique_ptr<SingleReleaseCallback> release_callback) {
[email protected]d72d9e02014-04-03 18:40:09118 mailbox_ = mailbox;
danakja04855a2015-11-18 20:39:10119 release_callback_ = std::move(release_callback);
[email protected]d72d9e02014-04-03 18:40:09120 mailbox_changed_ = true;
121 }
122
123 private:
[email protected]d72d9e02014-04-03 18:40:09124 TextureMailbox mailbox_;
danakj60bc3bc2016-04-09 00:24:48125 std::unique_ptr<SingleReleaseCallback> release_callback_;
[email protected]d72d9e02014-04-03 18:40:09126 bool mailbox_changed_;
127 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient);
128};
129
130class MockMailboxCallback {
131 public:
132 MOCK_METHOD3(Release,
133 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04134 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09135 bool lost_resource));
136 MOCK_METHOD3(Release2,
jbauman9015c8b2014-12-11 00:49:37137 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04138 const gpu::SyncToken& sync_token,
[email protected]d72d9e02014-04-03 18:40:09139 bool lost_resource));
skyostil3976a3f2014-09-04 22:07:23140 MOCK_METHOD4(ReleaseImpl,
141 void(const gpu::Mailbox& mailbox,
dyencc16ed4d2015-11-03 20:03:04142 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23143 bool lost_resource,
144 BlockingTaskRunner* main_thread_task_runner));
145 MOCK_METHOD4(ReleaseImpl2,
jbauman9015c8b2014-12-11 00:49:37146 void(SharedBitmap* shared_bitmap,
dyencc16ed4d2015-11-03 20:03:04147 const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:23148 bool lost_resource,
149 BlockingTaskRunner* main_thread_task_runner));
[email protected]d72d9e02014-04-03 18:40:09150};
151
152struct CommonMailboxObjects {
jbauman9015c8b2014-12-11 00:49:37153 explicit CommonMailboxObjects(SharedBitmapManager* manager)
[email protected]d72d9e02014-04-03 18:40:09154 : mailbox_name1_(MailboxFromChar('1')),
155 mailbox_name2_(MailboxFromChar('2')),
lukasza2573ce7d2016-02-16 19:17:22156 sync_token1_(gpu::CommandBufferNamespace::GPU_IO,
157 123,
158 gpu::CommandBufferId::FromUnsafeValue(0x234),
159 1),
160 sync_token2_(gpu::CommandBufferNamespace::GPU_IO,
161 123,
162 gpu::CommandBufferId::FromUnsafeValue(0x234),
163 2) {
[email protected]d72d9e02014-04-03 18:40:09164 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
165 base::Unretained(&mock_callback_),
166 mailbox_name1_);
167 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
168 base::Unretained(&mock_callback_),
169 mailbox_name2_);
skyostil3976a3f2014-09-04 22:07:23170 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
171 base::Unretained(&mock_callback_),
172 mailbox_name1_);
173 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
174 base::Unretained(&mock_callback_),
175 mailbox_name2_);
avi02a4d172015-12-21 06:14:36176 const uint32_t arbitrary_target1 = GL_TEXTURE_2D;
177 const uint32_t arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
dyencc16ed4d2015-11-03 20:03:04178 mailbox1_ = TextureMailbox(mailbox_name1_, sync_token1_, arbitrary_target1);
179 mailbox2_ = TextureMailbox(mailbox_name2_, sync_token2_, arbitrary_target2);
[email protected]d72d9e02014-04-03 18:40:09180 gfx::Size size(128, 128);
jbauman9015c8b2014-12-11 00:49:37181 shared_bitmap_ = manager->AllocateSharedBitmap(size);
182 DCHECK(shared_bitmap_);
183 release_mailbox3_ =
184 base::Bind(&MockMailboxCallback::Release2,
185 base::Unretained(&mock_callback_), shared_bitmap_.get());
186 release_mailbox3_impl_ =
187 base::Bind(&MockMailboxCallback::ReleaseImpl2,
188 base::Unretained(&mock_callback_), shared_bitmap_.get());
189 mailbox3_ = TextureMailbox(shared_bitmap_.get(), size);
[email protected]d72d9e02014-04-03 18:40:09190 }
191
192 gpu::Mailbox mailbox_name1_;
193 gpu::Mailbox mailbox_name2_;
194 MockMailboxCallback mock_callback_;
195 ReleaseCallback release_mailbox1_;
196 ReleaseCallback release_mailbox2_;
197 ReleaseCallback release_mailbox3_;
skyostil3976a3f2014-09-04 22:07:23198 ReleaseCallbackImpl release_mailbox1_impl_;
199 ReleaseCallbackImpl release_mailbox2_impl_;
200 ReleaseCallbackImpl release_mailbox3_impl_;
[email protected]d72d9e02014-04-03 18:40:09201 TextureMailbox mailbox1_;
202 TextureMailbox mailbox2_;
203 TextureMailbox mailbox3_;
dyencc16ed4d2015-11-03 20:03:04204 gpu::SyncToken sync_token1_;
205 gpu::SyncToken sync_token2_;
danakj60bc3bc2016-04-09 00:24:48206 std::unique_ptr<SharedBitmap> shared_bitmap_;
[email protected]d72d9e02014-04-03 18:40:09207};
208
[email protected]31d4df82013-07-18 10:17:22209class TextureLayerTest : public testing::Test {
210 public:
211 TextureLayerTest()
danakj1120f4c2016-09-15 02:05:32212 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()),
khushalsagarb64b360d2015-10-21 19:25:16213 host_impl_(&task_runner_provider_,
214 &shared_bitmap_manager_,
215 &task_graph_runner_),
jbauman9015c8b2014-12-11 00:49:37216 test_data_(&shared_bitmap_manager_) {}
[email protected]31d4df82013-07-18 10:17:22217
218 protected:
dcheng93a52eb2014-12-23 02:14:23219 void SetUp() override {
danakjcf610582015-06-16 22:48:56220 layer_tree_host_ =
221 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
khushalsagar86928f92016-08-17 21:49:05222 layer_tree_ = layer_tree_host_->GetLayerTree();
[email protected]d72d9e02014-04-03 18:40:09223 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagar86928f92016-08-17 21:49:05224 layer_tree_->SetViewportSize(gfx::Size(10, 10));
[email protected]d72d9e02014-04-03 18:40:09225 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22226 }
227
dcheng93a52eb2014-12-23 02:14:23228 void TearDown() override {
[email protected]31d4df82013-07-18 10:17:22229 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]31d4df82013-07-18 10:17:22230 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
231
khushalsagar86928f92016-08-17 21:49:05232 layer_tree_->SetRootLayer(nullptr);
danakjf446a072014-09-27 21:55:48233 layer_tree_host_ = nullptr;
[email protected]31d4df82013-07-18 10:17:22234 }
235
danakj60bc3bc2016-04-09 00:24:48236 std::unique_ptr<MockLayerTreeHost> layer_tree_host_;
khushalsagar86928f92016-08-17 21:49:05237 LayerTree* layer_tree_;
khushalsagarb64b360d2015-10-21 19:25:16238 FakeImplTaskRunnerProvider task_runner_provider_;
[email protected]31d4df82013-07-18 10:17:22239 FakeLayerTreeHostClient fake_client_;
[email protected]4e2eb352014-03-20 17:25:45240 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:47241 TestTaskGraphRunner task_graph_runner_;
danakj1120f4c2016-09-15 02:05:32242 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_;
[email protected]31d4df82013-07-18 10:17:22243 FakeLayerTreeHostImpl host_impl_;
jbauman9015c8b2014-12-11 00:49:37244 CommonMailboxObjects test_data_;
[email protected]31d4df82013-07-18 10:17:22245};
246
[email protected]31d4df82013-07-18 10:17:22247TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
kulkarni.a4015690f12014-10-10 13:50:06248 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31249 TextureLayer::CreateForMailbox(nullptr);
khushalsagar86928f92016-08-17 21:49:05250 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer));
[email protected]31d4df82013-07-18 10:17:22251
252 // Test properties that should call SetNeedsCommit. All properties need to
253 // be set to new values in order for SetNeedsCommit to be called.
254 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
jackhou10c9af42014-12-04 05:24:44255 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
[email protected]31d4df82013-07-18 10:17:22256 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
257 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
258 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
259 0.5f, 0.5f, 0.5f, 0.5f));
260 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
261 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true));
[email protected]31d4df82013-07-18 10:17:22262}
263
[email protected]df41e252014-02-03 23:39:50264class TestMailboxHolder : public TextureLayer::TextureMailboxHolder {
[email protected]9794fb32013-08-29 09:49:59265 public:
[email protected]df41e252014-02-03 23:39:50266 using TextureLayer::TextureMailboxHolder::Create;
[email protected]9794fb32013-08-29 09:49:59267
268 protected:
dcheng716bedf2014-10-21 09:51:08269 ~TestMailboxHolder() override {}
[email protected]9794fb32013-08-29 09:49:59270};
271
[email protected]de44a152013-01-08 15:28:46272class TextureLayerWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15273 protected:
dcheng93a52eb2014-12-23 02:14:23274 void TearDown() override {
[email protected]28571b042013-03-14 07:59:15275 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
dyencc16ed4d2015-11-03 20:03:04276 EXPECT_CALL(
277 test_data_.mock_callback_,
278 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
279 .Times(1);
[email protected]28571b042013-03-14 07:59:15280 TextureLayerTest::TearDown();
281 }
[email protected]de44a152013-01-08 15:28:46282};
283
[email protected]28571b042013-03-14 07:59:15284TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
kulkarni.a4015690f12014-10-10 13:50:06285 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31286 TextureLayer::CreateForMailbox(nullptr);
[email protected]22898ed2013-06-01 04:52:30287 ASSERT_TRUE(test_layer.get());
[email protected]de44a152013-01-08 15:28:46288
[email protected]28571b042013-03-14 07:59:15289 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
khushalsagar86928f92016-08-17 21:49:05290 layer_tree_->SetRootLayer(test_layer);
[email protected]28571b042013-03-14 07:59:15291 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46292
[email protected]28571b042013-03-14 07:59:15293 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16294 test_layer->SetTextureMailbox(
295 test_data_.mailbox1_,
296 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]28571b042013-03-14 07:59:15297 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46298
[email protected]28571b042013-03-14 07:59:15299 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04300 EXPECT_CALL(
301 test_data_.mock_callback_,
302 Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
[email protected]28571b042013-03-14 07:59:15303 .Times(1);
[email protected]9260757f2013-09-17 01:24:16304 test_layer->SetTextureMailbox(
305 test_data_.mailbox2_,
306 SingleReleaseCallback::Create(test_data_.release_mailbox2_));
[email protected]28571b042013-03-14 07:59:15307 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
308 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46309
[email protected]28571b042013-03-14 07:59:15310 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
dyencc16ed4d2015-11-03 20:03:04311 EXPECT_CALL(
312 test_data_.mock_callback_,
313 Release(test_data_.mailbox_name2_, test_data_.sync_token2_, false))
[email protected]28571b042013-03-14 07:59:15314 .Times(1);
danakj968153f32014-10-15 22:52:16315 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]28571b042013-03-14 07:59:15316 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
317 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46318
[email protected]80d42bd2013-08-30 19:13:45319 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16320 test_layer->SetTextureMailbox(
321 test_data_.mailbox3_,
322 SingleReleaseCallback::Create(test_data_.release_mailbox3_));
[email protected]42f40a52013-06-08 04:38:51323 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
324 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
325
[email protected]42f40a52013-06-08 04:38:51326 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
327 EXPECT_CALL(test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04328 Release2(test_data_.shared_bitmap_.get(), _, false))
329 .Times(1);
danakj968153f32014-10-15 22:52:16330 test_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]42f40a52013-06-08 04:38:51331 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
332 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
333
[email protected]28571b042013-03-14 07:59:15334 // Test destructor.
335 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
[email protected]9260757f2013-09-17 01:24:16336 test_layer->SetTextureMailbox(
337 test_data_.mailbox1_,
338 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]de44a152013-01-08 15:28:46339}
340
[email protected]9794fb32013-08-29 09:49:59341class TextureLayerMailboxHolderTest : public TextureLayerTest {
342 public:
343 TextureLayerMailboxHolderTest()
344 : main_thread_("MAIN") {
345 main_thread_.Start();
fdoray70df5a92016-06-22 21:13:59346 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48347 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::InitializeOnMain,
348 base::Unretained(this)));
skyostil3976a3f2014-09-04 22:07:23349 Wait(main_thread_);
[email protected]9794fb32013-08-29 09:49:59350 }
351
352 void Wait(const base::Thread& thread) {
gabcca53112016-06-08 20:13:28353 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
354 base::WaitableEvent::InitialState::NOT_SIGNALED);
fdoray70df5a92016-06-22 21:13:59355 thread.task_runner()->PostTask(
[email protected]9794fb32013-08-29 09:49:59356 FROM_HERE,
357 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
358 event.Wait();
359 }
360
361 void CreateMainRef() {
362 main_ref_ = TestMailboxHolder::Create(
[email protected]9260757f2013-09-17 01:24:16363 test_data_.mailbox1_,
danakja5a05ba02015-11-20 20:14:21364 SingleReleaseCallback::Create(test_data_.release_mailbox1_));
[email protected]9794fb32013-08-29 09:49:59365 }
366
danakjf446a072014-09-27 21:55:48367 void ReleaseMainRef() { main_ref_ = nullptr; }
[email protected]9794fb32013-08-29 09:49:59368
danakj60bc3bc2016-04-09 00:24:48369 void CreateImplRef(std::unique_ptr<SingleReleaseCallbackImpl>* impl_ref) {
[email protected]9794fb32013-08-29 09:49:59370 *impl_ref = main_ref_->holder()->GetCallbackForImplThread();
371 }
372
373 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture,
374 base::WaitableEvent* wait_for_capture,
375 base::WaitableEvent* stop_capture) {
376 begin_capture->Wait();
skyostil3976a3f2014-09-04 22:07:23377 BlockingTaskRunner::CapturePostTasks capture(
378 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59379 wait_for_capture->Signal();
380 stop_capture->Wait();
381 }
382
383 protected:
skyostil3976a3f2014-09-04 22:07:23384 void InitializeOnMain() {
385 main_thread_task_runner_ =
skyostil0fd1dad2015-04-13 20:11:48386 BlockingTaskRunner::Create(main_thread_.task_runner());
skyostil3976a3f2014-09-04 22:07:23387 }
388
danakj60bc3bc2016-04-09 00:24:48389 std::unique_ptr<TestMailboxHolder::MainThreadReference> main_ref_;
[email protected]9794fb32013-08-29 09:49:59390 base::Thread main_thread_;
danakj60bc3bc2016-04-09 00:24:48391 std::unique_ptr<BlockingTaskRunner> main_thread_task_runner_;
[email protected]9794fb32013-08-29 09:49:59392};
393
394TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) {
kulkarni.a4015690f12014-10-10 13:50:06395 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31396 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59397 ASSERT_TRUE(test_layer.get());
398
fdoray70df5a92016-06-22 21:13:59399 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48400 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
401 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59402
403 Wait(main_thread_);
404
405 // The texture layer is attached to compositor1, and passes a reference to its
406 // impl tree.
danakj60bc3bc2016-04-09 00:24:48407 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59408 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48409 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
410 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59411
412 // Then the texture layer is removed and attached to compositor2, and passes a
413 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48414 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59415 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48416 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
417 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59418
419 Wait(main_thread_);
420 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
421
422 // The compositors both destroy their impl trees before the main thread layer
423 // is destroyed.
dyen398dd0142016-01-21 22:05:56424 compositor1->Run(SyncTokenFromUInt(100), false,
425 main_thread_task_runner_.get());
426 compositor2->Run(SyncTokenFromUInt(200), false,
427 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59428
429 Wait(main_thread_);
430
431 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
432 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
433
434 // The main thread ref is the last one, so the mailbox is released back to the
435 // embedder, with the last sync point provided by the impl trees.
436 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56437 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), false))
dyencc16ed4d2015-11-03 20:03:04438 .Times(1);
[email protected]9794fb32013-08-29 09:49:59439
fdoray70df5a92016-06-22 21:13:59440 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48441 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
442 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59443 Wait(main_thread_);
444 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
445}
446
447TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) {
kulkarni.a4015690f12014-10-10 13:50:06448 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31449 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59450 ASSERT_TRUE(test_layer.get());
451
fdoray70df5a92016-06-22 21:13:59452 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48453 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
454 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59455
456 Wait(main_thread_);
457
458 // The texture layer is attached to compositor1, and passes a reference to its
459 // impl tree.
danakj60bc3bc2016-04-09 00:24:48460 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59461 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48462 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
463 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59464
465 // Then the texture layer is removed and attached to compositor2, and passes a
466 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48467 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59468 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48469 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
470 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59471
472 Wait(main_thread_);
473 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
474
475 // One compositor destroys their impl tree.
dyen398dd0142016-01-21 22:05:56476 compositor1->Run(SyncTokenFromUInt(100), false,
477 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59478
479 // Then the main thread reference is destroyed.
fdoray70df5a92016-06-22 21:13:59480 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48481 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
482 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59483
484 Wait(main_thread_);
485
486 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
487 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
488
489 // The second impl reference is destroyed last, causing the mailbox to be
490 // released back to the embedder with the last sync point from the impl tree.
491 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56492 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
dyencc16ed4d2015-11-03 20:03:04493 .Times(1);
[email protected]9794fb32013-08-29 09:49:59494
dyen398dd0142016-01-21 22:05:56495 compositor2->Run(SyncTokenFromUInt(200), true,
496 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59497 Wait(main_thread_);
498 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
499}
500
501TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {
kulkarni.a4015690f12014-10-10 13:50:06502 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31503 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59504 ASSERT_TRUE(test_layer.get());
505
fdoray70df5a92016-06-22 21:13:59506 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48507 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
508 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59509
510 Wait(main_thread_);
511
512 // The texture layer is attached to compositor1, and passes a reference to its
513 // impl tree.
danakj60bc3bc2016-04-09 00:24:48514 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59515 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48516 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
517 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59518
519 // Then the texture layer is removed and attached to compositor2, and passes a
520 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48521 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59522 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48523 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
524 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59525
526 Wait(main_thread_);
527 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
528
529 // The main thread reference is destroyed first.
fdoray70df5a92016-06-22 21:13:59530 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48531 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
532 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59533
534 // One compositor destroys their impl tree.
dyen398dd0142016-01-21 22:05:56535 compositor2->Run(SyncTokenFromUInt(200), false,
536 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59537
538 Wait(main_thread_);
539
540 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
541 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
542
543 // The second impl reference is destroyed last, causing the mailbox to be
544 // released back to the embedder with the last sync point from the impl tree.
545 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56546 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(100), true))
dyencc16ed4d2015-11-03 20:03:04547 .Times(1);
[email protected]9794fb32013-08-29 09:49:59548
dyen398dd0142016-01-21 22:05:56549 compositor1->Run(SyncTokenFromUInt(100), true,
550 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59551 Wait(main_thread_);
552 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
553}
554
555TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) {
kulkarni.a4015690f12014-10-10 13:50:06556 scoped_refptr<TextureLayer> test_layer =
loyso0940d412016-03-14 01:30:31557 TextureLayer::CreateForMailbox(nullptr);
[email protected]9794fb32013-08-29 09:49:59558 ASSERT_TRUE(test_layer.get());
559
fdoray70df5a92016-06-22 21:13:59560 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48561 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef,
562 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59563
564 Wait(main_thread_);
565
566 // The texture layer is attached to compositor1, and passes a reference to its
567 // impl tree.
danakj60bc3bc2016-04-09 00:24:48568 std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
fdoray70df5a92016-06-22 21:13:59569 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48570 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
571 base::Unretained(this), &compositor1));
[email protected]9794fb32013-08-29 09:49:59572
573 // Then the texture layer is removed and attached to compositor2, and passes a
574 // reference to its impl tree.
danakj60bc3bc2016-04-09 00:24:48575 std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
fdoray70df5a92016-06-22 21:13:59576 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48577 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef,
578 base::Unretained(this), &compositor2));
[email protected]9794fb32013-08-29 09:49:59579
580 Wait(main_thread_);
581 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
582
583 // The main thread reference is destroyed first.
fdoray70df5a92016-06-22 21:13:59584 main_thread_.task_runner()->PostTask(
skyostil0fd1dad2015-04-13 20:11:48585 FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef,
586 base::Unretained(this)));
[email protected]9794fb32013-08-29 09:49:59587
588 EXPECT_CALL(test_data_.mock_callback_,
dyen398dd0142016-01-21 22:05:56589 Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
dyencc16ed4d2015-11-03 20:03:04590 .Times(1);
[email protected]9794fb32013-08-29 09:49:59591
gabcca53112016-06-08 20:13:28592 base::WaitableEvent begin_capture(
593 base::WaitableEvent::ResetPolicy::AUTOMATIC,
594 base::WaitableEvent::InitialState::NOT_SIGNALED);
595 base::WaitableEvent wait_for_capture(
596 base::WaitableEvent::ResetPolicy::AUTOMATIC,
597 base::WaitableEvent::InitialState::NOT_SIGNALED);
598 base::WaitableEvent stop_capture(
599 base::WaitableEvent::ResetPolicy::AUTOMATIC,
600 base::WaitableEvent::InitialState::NOT_SIGNALED);
[email protected]9794fb32013-08-29 09:49:59601
602 // Post a task to start capturing tasks on the main thread. This will block
603 // the main thread until we signal the |stop_capture| event.
fdoray70df5a92016-06-22 21:13:59604 main_thread_.task_runner()->PostTask(
[email protected]9794fb32013-08-29 09:49:59605 FROM_HERE,
606 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait,
skyostil0fd1dad2015-04-13 20:11:48607 base::Unretained(this), &begin_capture, &wait_for_capture,
[email protected]9794fb32013-08-29 09:49:59608 &stop_capture));
609
610 // Before the main thread capturing starts, one compositor destroys their
611 // impl reference. Since capturing did not start, this gets post-tasked to
612 // the main thread.
dyen398dd0142016-01-21 22:05:56613 compositor1->Run(SyncTokenFromUInt(100), false,
614 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59615
616 // Start capturing on the main thread.
617 begin_capture.Signal();
618 wait_for_capture.Wait();
619
620 // Meanwhile, the second compositor released its impl reference, but this task
621 // gets shortcutted directly to the main thread. This means the reference is
622 // released before compositor1, whose reference will be released later when
623 // the post-task is serviced. But since it was destroyed _on the impl thread_
624 // last, its sync point values should be used.
dyen398dd0142016-01-21 22:05:56625 compositor2->Run(SyncTokenFromUInt(200), true,
626 main_thread_task_runner_.get());
[email protected]9794fb32013-08-29 09:49:59627
628 stop_capture.Signal();
629 Wait(main_thread_);
630
631 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
632}
633
[email protected]e216fef02013-03-20 22:56:10634class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {
[email protected]28571b042013-03-14 07:59:15635 public:
danakj014316e2016-08-04 18:40:26636 TextureLayerImplWithMailboxThreadedCallback() = default;
637
danakj1120f4c2016-09-15 02:05:32638 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink(
danakj014316e2016-08-04 18:40:26639 scoped_refptr<ContextProvider> compositor_context_provider,
640 scoped_refptr<ContextProvider> worker_context_provider) override {
641 bool synchronous_composite =
642 !HasImplThread() &&
khushalsagarcebe4942016-09-07 23:27:01643 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler;
danakj014316e2016-08-04 18:40:26644 // 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),
649 CreateDisplayOutputSurface(compositor_context_provider),
650 shared_bitmap_manager(), gpu_memory_buffer_manager(),
khushalsagarcebe4942016-09-07 23:27:01651 layer_tree_host()->GetSettings().renderer_settings,
652 ImplThreadTaskRunner(), synchronous_composite,
653 force_disable_reclaim_resources);
danakj014316e2016-08-04 18:40:26654 }
[email protected]28571b042013-03-14 07:59:15655
656 // Make sure callback is received on main and doesn't block the impl thread.
danakj014316e2016-08-04 18:40:26657 void ReleaseCallback(char mailbox_char,
658 const gpu::SyncToken& sync_token,
659 bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:59660 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]7ba3ca72013-04-11 06:37:25661 EXPECT_FALSE(lost_resource);
[email protected]28571b042013-03-14 07:59:15662 ++callback_count_;
663 }
664
665 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:59666 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:48667 std::unique_ptr<SingleReleaseCallback> callback =
668 SingleReleaseCallback::Create(base::Bind(
[email protected]28571b042013-03-14 07:59:15669 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback,
danakj014316e2016-08-04 18:40:26670 base::Unretained(this), mailbox_char));
dyene5db881b2016-03-01 19:47:03671 layer_->SetTextureMailbox(
672 TextureMailbox(MailboxFromChar(mailbox_char),
673 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
674 GL_TEXTURE_2D),
675 std::move(callback));
danakj014316e2016-08-04 18:40:26676 // Damage the layer so we send a new frame with the new mailbox to the
677 // Display compositor.
678 layer_->SetNeedsDisplay();
[email protected]28571b042013-03-14 07:59:15679 }
680
dcheng716bedf2014-10-21 09:51:08681 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:59682 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
683
[email protected]28571b042013-03-14 07:59:15684 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31685 root_ = Layer::Create();
[email protected]28571b042013-03-14 07:59:15686 root_->SetBounds(bounds);
687
loyso0940d412016-03-14 01:30:31688 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]28571b042013-03-14 07:59:15689 layer_->SetIsDrawable(true);
[email protected]28571b042013-03-14 07:59:15690 layer_->SetBounds(bounds);
691
692 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:05693 layer_tree()->SetRootLayer(root_);
694 layer_tree()->SetViewportSize(bounds);
[email protected]28571b042013-03-14 07:59:15695 SetMailbox('1');
696 EXPECT_EQ(0, callback_count_);
697
698 // Case #1: change mailbox before the commit. The old mailbox should be
699 // released immediately.
700 SetMailbox('2');
701 EXPECT_EQ(1, callback_count_);
[email protected]e216fef02013-03-20 22:56:10702 PostSetNeedsCommitToMainThread();
[email protected]28571b042013-03-14 07:59:15703 }
704
dcheng716bedf2014-10-21 09:51:08705 void DidCommit() override {
[email protected]28571b042013-03-14 07:59:15706 ++commit_count_;
707 switch (commit_count_) {
708 case 1:
709 // Case #2: change mailbox after the commit (and draw), where the
710 // layer draws. The old mailbox should be released during the next
711 // commit.
712 SetMailbox('3');
713 EXPECT_EQ(1, callback_count_);
714 break;
715 case 2:
[email protected]28571b042013-03-14 07:59:15716 EXPECT_EQ(2, callback_count_);
717 // Case #3: change mailbox when the layer doesn't draw. The old
718 // mailbox should be released during the next commit.
719 layer_->SetBounds(gfx::Size());
720 SetMailbox('4');
721 break;
[email protected]9794fb32013-08-29 09:49:59722 case 3:
[email protected]28571b042013-03-14 07:59:15723 EXPECT_EQ(3, callback_count_);
724 // Case #4: release mailbox that was committed but never drawn. The
725 // old mailbox should be released during the next commit.
danakj968153f32014-10-15 22:52:16726 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]28571b042013-03-14 07:59:15727 break;
[email protected]9794fb32013-08-29 09:49:59728 case 4:
[email protected]28571b042013-03-14 07:59:15729 EXPECT_EQ(4, callback_count_);
[email protected]7096acc2013-06-18 21:12:43730 // Restore a mailbox for the next step.
731 SetMailbox('5');
732 break;
danakj014316e2016-08-04 18:40:26733 case 5:
[email protected]7096acc2013-06-18 21:12:43734 // Case #5: remove layer from tree. Callback should *not* be called, the
735 // mailbox is returned to the main thread.
736 EXPECT_EQ(4, callback_count_);
737 layer_->RemoveFromParent();
738 break;
danakj014316e2016-08-04 18:40:26739 case 6:
[email protected]7096acc2013-06-18 21:12:43740 EXPECT_EQ(4, callback_count_);
741 // Resetting the mailbox will call the callback now.
danakj968153f32014-10-15 22:52:16742 layer_->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]7096acc2013-06-18 21:12:43743 EXPECT_EQ(5, callback_count_);
[email protected]e216fef02013-03-20 22:56:10744 EndTest();
[email protected]28571b042013-03-14 07:59:15745 break;
746 default:
747 NOTREACHED();
748 break;
[email protected]de44a152013-01-08 15:28:46749 }
[email protected]28571b042013-03-14 07:59:15750 }
[email protected]de44a152013-01-08 15:28:46751
dcheng716bedf2014-10-21 09:51:08752 void AfterTest() override {}
[email protected]de44a152013-01-08 15:28:46753
[email protected]28571b042013-03-14 07:59:15754 private:
[email protected]9794fb32013-08-29 09:49:59755 base::ThreadChecker main_thread_;
danakj014316e2016-08-04 18:40:26756 int callback_count_ = 0;
757 int commit_count_ = 0;
[email protected]28571b042013-03-14 07:59:15758 scoped_refptr<Layer> root_;
759 scoped_refptr<TextureLayer> layer_;
[email protected]de44a152013-01-08 15:28:46760};
761
danakj0943a112016-08-11 00:33:46762SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
[email protected]74b43cc2013-08-30 06:29:27763
[email protected]74b43cc2013-08-30 06:29:27764class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest {
765 protected:
[email protected]98ea818e2014-01-24 10:22:08766 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {}
[email protected]74b43cc2013-08-30 06:29:27767
dyene5db881b2016-03-01 19:47:03768 static void ReleaseCallback(const gpu::SyncToken& original_sync_token,
769 const gpu::SyncToken& release_sync_token,
dyencc16ed4d2015-11-03 20:03:04770 bool lost_resource) {}
[email protected]74b43cc2013-08-30 06:29:27771
772 void SetMailbox(char mailbox_char) {
dyene5db881b2016-03-01 19:47:03773 const gpu::SyncToken sync_token =
774 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char));
danakj60bc3bc2016-04-09 00:24:48775 std::unique_ptr<SingleReleaseCallback> callback =
776 SingleReleaseCallback::Create(base::Bind(
777 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback,
778 sync_token));
dyencc16ed4d2015-11-03 20:03:04779 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char),
dyene5db881b2016-03-01 19:47:03780 sync_token, GL_TEXTURE_2D),
danakja04855a2015-11-18 20:39:10781 std::move(callback));
[email protected]74b43cc2013-08-30 06:29:27782 }
783
dcheng716bedf2014-10-21 09:51:08784 void BeginTest() override {
[email protected]74b43cc2013-08-30 06:29:27785 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:31786 root_ = Layer::Create();
[email protected]74b43cc2013-08-30 06:29:27787 root_->SetBounds(bounds);
788
loyso0940d412016-03-14 01:30:31789 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]74b43cc2013-08-30 06:29:27790 layer_->SetIsDrawable(true);
[email protected]74b43cc2013-08-30 06:29:27791 layer_->SetBounds(bounds);
792
793 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:05794 layer_tree()->SetRootLayer(root_);
795 layer_tree()->SetViewportSize(bounds);
[email protected]74b43cc2013-08-30 06:29:27796 SetMailbox('1');
797
798 PostSetNeedsCommitToMainThread();
799 }
800
dcheng716bedf2014-10-21 09:51:08801 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
danakj3c3973b2015-08-25 21:50:18802 base::AutoLock lock(activate_count_lock_);
[email protected]74b43cc2013-08-30 06:29:27803 ++activate_count_;
804 }
805
dcheng716bedf2014-10-21 09:51:08806 void DidCommit() override {
danakj3c3973b2015-08-25 21:50:18807 // The first frame doesn't cause anything to be returned so it does not
808 // need to wait for activation.
khushalsagarcebe4942016-09-07 23:27:01809 if (layer_tree_host()->SourceFrameNumber() > 1) {
danakj3c3973b2015-08-25 21:50:18810 base::AutoLock lock(activate_count_lock_);
811 // The activate happened before commit is done on the main side.
khushalsagarcebe4942016-09-07 23:27:01812 EXPECT_EQ(activate_count_, layer_tree_host()->SourceFrameNumber());
danakj3c3973b2015-08-25 21:50:18813 }
814
khushalsagarcebe4942016-09-07 23:27:01815 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]74b43cc2013-08-30 06:29:27816 case 1:
817 // The first mailbox has been activated. Set a new mailbox, and
818 // expect the next commit to finish *after* it is activated.
819 SetMailbox('2');
[email protected]74b43cc2013-08-30 06:29:27820 break;
821 case 2:
822 // The second mailbox has been activated. Remove the layer from
823 // the tree to cause another commit/activation. The commit should
824 // finish *after* the layer is removed from the active tree.
825 layer_->RemoveFromParent();
[email protected]74b43cc2013-08-30 06:29:27826 break;
827 case 3:
828 EndTest();
829 break;
830 }
831 }
832
dcheng716bedf2014-10-21 09:51:08833 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
danakj3c3973b2015-08-25 21:50:18834 // The activate didn't happen before commit is done on the impl side (but it
835 // should happen before the main thread is done).
836 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number());
[email protected]74b43cc2013-08-30 06:29:27837 }
838
dcheng716bedf2014-10-21 09:51:08839 void AfterTest() override {}
[email protected]74b43cc2013-08-30 06:29:27840
danakj3c3973b2015-08-25 21:50:18841 base::Lock activate_count_lock_;
[email protected]74b43cc2013-08-30 06:29:27842 int activate_count_;
843 scoped_refptr<Layer> root_;
844 scoped_refptr<TextureLayer> layer_;
845};
846
dgroganf22b7692016-08-30 23:24:08847// Flaky on windows. https://crbug.com/641613
848#if !defined(OS_WIN)
danakj0943a112016-08-11 00:33:46849SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit);
dgroganf22b7692016-08-30 23:24:08850#endif
[email protected]74b43cc2013-08-30 06:29:27851
[email protected]de44a152013-01-08 15:28:46852class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15853 protected:
dcheng93a52eb2014-12-23 02:14:23854 void SetUp() override {
[email protected]28571b042013-03-14 07:59:15855 TextureLayerTest::SetUp();
danakjcf610582015-06-16 22:48:56856 layer_tree_host_ =
857 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
khushalsagar86928f92016-08-17 21:49:05858 layer_tree_ = layer_tree_host_->GetLayerTree();
sievers71c62dd52015-10-07 01:44:39859 host_impl_.SetVisible(true);
danakj1120f4c2016-09-15 02:05:32860 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get()));
[email protected]28571b042013-03-14 07:59:15861 }
[email protected]de44a152013-01-08 15:28:46862
[email protected]0ec335c42013-07-04 06:17:08863 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) {
864 bool will_draw = layer->WillDraw(
865 mode, host_impl_.active_tree()->resource_provider());
866 if (will_draw)
867 layer->DidDraw(host_impl_.active_tree()->resource_provider());
868 return will_draw;
869 }
870
[email protected]408b5e22013-03-19 09:48:09871 FakeLayerTreeHostClient fake_client_;
[email protected]de44a152013-01-08 15:28:46872};
873
[email protected]ffbb2212013-06-02 23:47:59874// Test conditions for results of TextureLayerImpl::WillDraw under
875// different configurations of different mailbox, texture_id, and draw_mode.
876TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
skyostil3976a3f2014-09-04 22:07:23877 EXPECT_CALL(
878 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04879 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]0ec335c42013-07-04 06:17:08880 .Times(AnyNumber());
dyencc16ed4d2015-11-03 20:03:04881 EXPECT_CALL(
882 test_data_.mock_callback_,
883 ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _))
[email protected]0ec335c42013-07-04 06:17:08884 .Times(AnyNumber());
[email protected]ffbb2212013-06-02 23:47:59885 // Hardware mode.
886 {
danakj60bc3bc2016-04-09 00:24:48887 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11888 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16889 impl_layer->SetTextureMailbox(
890 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23891 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08892 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59893 }
894
895 {
danakj60bc3bc2016-04-09 00:24:48896 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11897 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16898 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08899 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
900 }
901
902 {
903 // Software resource.
danakj60bc3bc2016-04-09 00:24:48904 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11905 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16906 impl_layer->SetTextureMailbox(
907 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23908 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]3e44d7a2013-07-30 00:03:10909 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
[email protected]ffbb2212013-06-02 23:47:59910 }
911
[email protected]0ec335c42013-07-04 06:17:08912 // Software mode.
913 {
danakj60bc3bc2016-04-09 00:24:48914 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11915 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16916 impl_layer->SetTextureMailbox(
917 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23918 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08919 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
920 }
921
922 {
danakj60bc3bc2016-04-09 00:24:48923 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11924 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
danakj968153f32014-10-15 22:52:16925 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]0ec335c42013-07-04 06:17:08926 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
927 }
928
929 {
930 // Software resource.
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);
[email protected]9260757f2013-09-17 01:24:16933 impl_layer->SetTextureMailbox(
934 test_data_.mailbox3_,
skyostil3976a3f2014-09-04 22:07:23935 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
[email protected]0ec335c42013-07-04 06:17:08936 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
937 }
938
[email protected]ffbb2212013-06-02 23:47:59939 // Resourceless software mode.
940 {
danakj60bc3bc2016-04-09 00:24:48941 std::unique_ptr<TextureLayerImpl> impl_layer =
[email protected]17e08432014-04-10 00:41:11942 TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]9260757f2013-09-17 01:24:16943 impl_layer->SetTextureMailbox(
944 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23945 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]0ec335c42013-07-04 06:17:08946 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
[email protected]ffbb2212013-06-02 23:47:59947 }
[email protected]ffbb2212013-06-02 23:47:59948}
949
[email protected]28571b042013-03-14 07:59:15950TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
951 host_impl_.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:48952 std::unique_ptr<TextureLayerImpl> pending_layer;
[email protected]17e08432014-04-10 00:41:11953 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1);
[email protected]28571b042013-03-14 07:59:15954 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46955
danakj60bc3bc2016-04-09 00:24:48956 std::unique_ptr<LayerImpl> active_layer(
[email protected]28571b042013-03-14 07:59:15957 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
[email protected]ed511b8d2013-03-25 03:29:29958 ASSERT_TRUE(active_layer);
[email protected]de44a152013-01-08 15:28:46959
[email protected]9260757f2013-09-17 01:24:16960 pending_layer->SetTextureMailbox(
961 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23962 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]421e84f2013-02-22 03:27:15963
[email protected]28571b042013-03-14 07:59:15964 // Test multiple commits without an activation.
skyostil3976a3f2014-09-04 22:07:23965 EXPECT_CALL(
966 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:04967 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:15968 .Times(1);
[email protected]9260757f2013-09-17 01:24:16969 pending_layer->SetTextureMailbox(
970 test_data_.mailbox2_,
skyostil3976a3f2014-09-04 22:07:23971 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_));
[email protected]28571b042013-03-14 07:59:15972 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15973
[email protected]28571b042013-03-14 07:59:15974 // Test callback after activation.
[email protected]ed511b8d2013-03-25 03:29:29975 pending_layer->PushPropertiesTo(active_layer.get());
976 active_layer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:15977
skyostil3976a3f2014-09-04 22:07:23978 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]9260757f2013-09-17 01:24:16979 pending_layer->SetTextureMailbox(
980 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:23981 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:15982 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15983
[email protected]7ba3ca72013-04-11 06:37:25984 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:23985 ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1);
[email protected]ed511b8d2013-03-25 03:29:29986 pending_layer->PushPropertiesTo(active_layer.get());
987 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:15988 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46989
[email protected]28571b042013-03-14 07:59:15990 // Test resetting the mailbox.
[email protected]7ba3ca72013-04-11 06:37:25991 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:23992 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
danakj968153f32014-10-15 22:52:16993 pending_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]ed511b8d2013-03-25 03:29:29994 pending_layer->PushPropertiesTo(active_layer.get());
995 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:15996 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46997
[email protected]28571b042013-03-14 07:59:15998 // Test destructor.
skyostil3976a3f2014-09-04 22:07:23999 EXPECT_CALL(
1000 test_data_.mock_callback_,
dyencc16ed4d2015-11-03 20:03:041001 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
[email protected]28571b042013-03-14 07:59:151002 .Times(1);
[email protected]9260757f2013-09-17 01:24:161003 pending_layer->SetTextureMailbox(
1004 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231005 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]de44a152013-01-08 15:28:461006}
1007
[email protected]28571b042013-03-14 07:59:151008TEST_F(TextureLayerImplWithMailboxTest,
1009 TestDestructorCallbackOnCreatedResource) {
danakj60bc3bc2016-04-09 00:24:481010 std::unique_ptr<TextureLayerImpl> impl_layer;
[email protected]17e08432014-04-10 00:41:111011 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1);
[email protected]28571b042013-03-14 07:59:151012 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:461013
[email protected]7ba3ca72013-04-11 06:37:251014 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231015 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]9260757f2013-09-17 01:24:161016 impl_layer->SetTextureMailbox(
1017 test_data_.mailbox1_,
skyostil3976a3f2014-09-04 22:07:231018 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]ffbb2212013-06-02 23:47:591019 impl_layer->DidBecomeActive();
1020 EXPECT_TRUE(impl_layer->WillDraw(
1021 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider()));
[email protected]28571b042013-03-14 07:59:151022 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
danakj968153f32014-10-15 22:52:161023 impl_layer->SetTextureMailbox(TextureMailbox(), nullptr);
[email protected]de44a152013-01-08 15:28:461024}
1025
[email protected]28571b042013-03-14 07:59:151026TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
1027 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
jbaumanbbd425e2015-05-19 00:33:351028 ResourceId id = provider->CreateResourceFromTextureMailbox(
skyostil3976a3f2014-09-04 22:07:231029 test_data_.mailbox1_,
1030 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
[email protected]28571b042013-03-14 07:59:151031 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:461032
[email protected]28571b042013-03-14 07:59:151033 // Transfer some resources to the parent.
1034 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1035 resource_ids_to_transfer.push_back(id);
1036 TransferableResourceArray list;
1037 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
1038 EXPECT_TRUE(provider->InUseByConsumer(id));
skyostil3976a3f2014-09-04 22:07:231039 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
[email protected]28571b042013-03-14 07:59:151040 provider->DeleteResource(id);
1041 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]7ba3ca72013-04-11 06:37:251042 EXPECT_CALL(test_data_.mock_callback_,
skyostil3976a3f2014-09-04 22:07:231043 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
[email protected]e00bab022013-08-19 00:42:451044 ReturnedResourceArray returned;
1045 TransferableResource::ReturnResources(list, &returned);
1046 provider->ReceiveReturnsFromParent(returned);
[email protected]de44a152013-01-08 15:28:461047}
1048
[email protected]4bad8b62013-10-24 01:27:291049// Checks that TextureLayer::Update does not cause an extra commit when setting
1050// the texture mailbox.
1051class TextureLayerNoExtraCommitForMailboxTest
1052 : public LayerTreeTest,
1053 public TextureLayerClient {
1054 public:
[email protected]4bad8b62013-10-24 01:27:291055 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081056 bool PrepareTextureMailbox(
[email protected]df41e252014-02-03 23:39:501057 TextureMailbox* texture_mailbox,
danakj4d0dd802016-08-23 22:10:061058 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
khushalsagarcebe4942016-09-07 23:27:011059 if (layer_tree_host()->SourceFrameNumber() == 1) {
[email protected]9f35bd22014-06-03 15:25:461060 // Once this has been committed, the mailbox will be released.
[email protected]df41e252014-02-03 23:39:501061 *texture_mailbox = TextureMailbox();
[email protected]cce34bd2013-12-02 23:24:451062 return true;
1063 }
[email protected]4bad8b62013-10-24 01:27:291064
dyene5db881b2016-03-01 19:47:031065 *texture_mailbox = TextureMailbox(MailboxFromChar('1'),
1066 SyncTokenFromUInt(0x123), GL_TEXTURE_2D);
[email protected]4bad8b62013-10-24 01:27:291067 *release_callback = SingleReleaseCallback::Create(
1068 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased,
1069 base::Unretained(this)));
[email protected]4bad8b62013-10-24 01:27:291070 return true;
1071 }
1072
dyencc16ed4d2015-11-03 20:03:041073 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031074 EXPECT_TRUE(sync_token.HasData());
[email protected]cce34bd2013-12-02 23:24:451075 EndTest();
[email protected]4bad8b62013-10-24 01:27:291076 }
1077
dcheng716bedf2014-10-21 09:51:081078 void SetupTree() override {
loyso0940d412016-03-14 01:30:311079 scoped_refptr<Layer> root = Layer::Create();
[email protected]4bad8b62013-10-24 01:27:291080 root->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291081 root->SetIsDrawable(true);
1082
loyso0940d412016-03-14 01:30:311083 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]4bad8b62013-10-24 01:27:291084 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]4bad8b62013-10-24 01:27:291085 texture_layer_->SetIsDrawable(true);
[email protected]0d7fb302014-01-23 21:30:471086 root->AddChild(texture_layer_);
[email protected]4bad8b62013-10-24 01:27:291087
khushalsagar86928f92016-08-17 21:49:051088 layer_tree()->SetRootLayer(root);
[email protected]4bad8b62013-10-24 01:27:291089 LayerTreeTest::SetupTree();
1090 }
1091
dcheng716bedf2014-10-21 09:51:081092 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]4bad8b62013-10-24 01:27:291093
dcheng716bedf2014-10-21 09:51:081094 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011095 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]4bad8b62013-10-24 01:27:291096 case 1:
[email protected]4ea293f72014-08-13 03:03:171097 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting());
[email protected]cce34bd2013-12-02 23:24:451098 // Invalidate the texture layer to clear the mailbox before
1099 // ending the test.
1100 texture_layer_->SetNeedsDisplay();
1101 break;
1102 case 2:
[email protected]4bad8b62013-10-24 01:27:291103 break;
1104 default:
1105 NOTREACHED();
1106 break;
1107 }
1108 }
1109
dcheng716bedf2014-10-21 09:51:081110 void AfterTest() override {}
[email protected]4bad8b62013-10-24 01:27:291111
1112 private:
[email protected]4bad8b62013-10-24 01:27:291113 scoped_refptr<TextureLayer> texture_layer_;
[email protected]4bad8b62013-10-24 01:27:291114};
1115
[email protected]cce34bd2013-12-02 23:24:451116SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);
[email protected]4bad8b62013-10-24 01:27:291117
[email protected]b04264f92013-09-13 23:37:291118// Checks that changing a mailbox in the client for a TextureLayer that's
1119// invisible correctly works and uses the new mailbox as soon as the layer
1120// becomes visible (and returns the old one).
1121class TextureLayerChangeInvisibleMailboxTest
1122 : public LayerTreeTest,
1123 public TextureLayerClient {
1124 public:
1125 TextureLayerChangeInvisibleMailboxTest()
1126 : mailbox_changed_(true),
1127 mailbox_returned_(0),
1128 prepare_called_(0),
1129 commit_count_(0) {
1130 mailbox_ = MakeMailbox('1');
1131 }
1132
1133 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081134 bool PrepareTextureMailbox(
[email protected]e51444a2013-12-10 23:05:011135 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061136 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
[email protected]b04264f92013-09-13 23:37:291137 ++prepare_called_;
1138 if (!mailbox_changed_)
1139 return false;
1140 *mailbox = mailbox_;
[email protected]9260757f2013-09-17 01:24:161141 *release_callback = SingleReleaseCallback::Create(
1142 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased,
1143 base::Unretained(this)));
[email protected]b04264f92013-09-13 23:37:291144 return true;
1145 }
1146
1147 TextureMailbox MakeMailbox(char name) {
dyene5db881b2016-03-01 19:47:031148 return TextureMailbox(MailboxFromChar(name),
1149 SyncTokenFromUInt(static_cast<uint32_t>(name)),
dyencc16ed4d2015-11-03 20:03:041150 GL_TEXTURE_2D);
[email protected]b04264f92013-09-13 23:37:291151 }
1152
dyencc16ed4d2015-11-03 20:03:041153 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
dyene5db881b2016-03-01 19:47:031154 EXPECT_TRUE(sync_token.HasData());
[email protected]b04264f92013-09-13 23:37:291155 ++mailbox_returned_;
1156 }
1157
dcheng716bedf2014-10-21 09:51:081158 void SetupTree() override {
loyso0940d412016-03-14 01:30:311159 scoped_refptr<Layer> root = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291160 root->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291161 root->SetIsDrawable(true);
1162
loyso0940d412016-03-14 01:30:311163 solid_layer_ = SolidColorLayer::Create();
[email protected]b04264f92013-09-13 23:37:291164 solid_layer_->SetBounds(gfx::Size(10, 10));
1165 solid_layer_->SetIsDrawable(true);
1166 solid_layer_->SetBackgroundColor(SK_ColorWHITE);
1167 root->AddChild(solid_layer_);
1168
loyso0940d412016-03-14 01:30:311169 parent_layer_ = Layer::Create();
[email protected]b04264f92013-09-13 23:37:291170 parent_layer_->SetBounds(gfx::Size(10, 10));
1171 parent_layer_->SetIsDrawable(true);
1172 root->AddChild(parent_layer_);
1173
loyso0940d412016-03-14 01:30:311174 texture_layer_ = TextureLayer::CreateForMailbox(this);
[email protected]b04264f92013-09-13 23:37:291175 texture_layer_->SetBounds(gfx::Size(10, 10));
[email protected]b04264f92013-09-13 23:37:291176 texture_layer_->SetIsDrawable(true);
1177 parent_layer_->AddChild(texture_layer_);
1178
khushalsagar86928f92016-08-17 21:49:051179 layer_tree()->SetRootLayer(root);
[email protected]b04264f92013-09-13 23:37:291180 LayerTreeTest::SetupTree();
1181 }
1182
dcheng716bedf2014-10-21 09:51:081183 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]b04264f92013-09-13 23:37:291184
dcheng716bedf2014-10-21 09:51:081185 void DidCommitAndDrawFrame() override {
[email protected]b04264f92013-09-13 23:37:291186 ++commit_count_;
1187 switch (commit_count_) {
1188 case 1:
1189 // We should have updated the layer, committing the texture.
1190 EXPECT_EQ(1, prepare_called_);
1191 // Make layer invisible.
1192 parent_layer_->SetOpacity(0.f);
1193 break;
1194 case 2:
1195 // Layer shouldn't have been updated.
1196 EXPECT_EQ(1, prepare_called_);
1197 // Change the texture.
1198 mailbox_ = MakeMailbox('2');
1199 mailbox_changed_ = true;
1200 texture_layer_->SetNeedsDisplay();
1201 // Force a change to make sure we draw a frame.
1202 solid_layer_->SetBackgroundColor(SK_ColorGRAY);
1203 break;
1204 case 3:
1205 // Layer shouldn't have been updated.
1206 EXPECT_EQ(1, prepare_called_);
1207 // So the old mailbox isn't returned yet.
1208 EXPECT_EQ(0, mailbox_returned_);
1209 // Make layer visible again.
jaydasikacf223762016-05-16 23:02:091210 parent_layer_->SetOpacity(0.9f);
[email protected]b04264f92013-09-13 23:37:291211 break;
1212 case 4:
1213 // Layer should have been updated.
1214 EXPECT_EQ(2, prepare_called_);
1215 // So the old mailbox should have been returned already.
1216 EXPECT_EQ(1, mailbox_returned_);
1217 texture_layer_->ClearClient();
1218 break;
1219 case 5:
1220 EXPECT_EQ(2, mailbox_returned_);
1221 EndTest();
1222 break;
1223 default:
1224 NOTREACHED();
1225 break;
1226 }
1227 }
1228
dcheng716bedf2014-10-21 09:51:081229 void AfterTest() override {}
[email protected]b04264f92013-09-13 23:37:291230
1231 private:
1232 scoped_refptr<SolidColorLayer> solid_layer_;
1233 scoped_refptr<Layer> parent_layer_;
1234 scoped_refptr<TextureLayer> texture_layer_;
1235
1236 // Used on the main thread.
1237 bool mailbox_changed_;
1238 TextureMailbox mailbox_;
1239 int mailbox_returned_;
1240 int prepare_called_;
1241 int commit_count_;
1242};
1243
1244SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
1245
[email protected]0d7fb302014-01-23 21:30:471246// Test that TextureLayerImpl::ReleaseResources can be called which releases
1247// the mailbox back to TextureLayerClient.
1248class TextureLayerReleaseResourcesBase
1249 : public LayerTreeTest,
1250 public TextureLayerClient {
1251 public:
1252 // TextureLayerClient implementation.
dcheng716bedf2014-10-21 09:51:081253 bool PrepareTextureMailbox(
[email protected]0d7fb302014-01-23 21:30:471254 TextureMailbox* mailbox,
danakj4d0dd802016-08-23 22:10:061255 std::unique_ptr<SingleReleaseCallback>* release_callback) override {
dyene5db881b2016-03-01 19:47:031256 *mailbox = TextureMailbox(MailboxFromChar('1'), SyncTokenFromUInt(1),
1257 GL_TEXTURE_2D);
[email protected]0d7fb302014-01-23 21:30:471258 *release_callback = SingleReleaseCallback::Create(
1259 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased,
1260 base::Unretained(this)));
1261 return true;
1262 }
1263
dyencc16ed4d2015-11-03 20:03:041264 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]0d7fb302014-01-23 21:30:471265 mailbox_released_ = true;
1266 }
1267
dcheng716bedf2014-10-21 09:51:081268 void SetupTree() override {
[email protected]0d7fb302014-01-23 21:30:471269 LayerTreeTest::SetupTree();
1270
1271 scoped_refptr<TextureLayer> texture_layer =
loyso0940d412016-03-14 01:30:311272 TextureLayer::CreateForMailbox(this);
[email protected]0d7fb302014-01-23 21:30:471273 texture_layer->SetBounds(gfx::Size(10, 10));
[email protected]0d7fb302014-01-23 21:30:471274 texture_layer->SetIsDrawable(true);
1275
khushalsagar86928f92016-08-17 21:49:051276 layer_tree()->root_layer()->AddChild(texture_layer);
jaydasikabd6f15a2016-04-21 19:45:371277 texture_layer_id_ = texture_layer->id();
[email protected]0d7fb302014-01-23 21:30:471278 }
1279
dcheng716bedf2014-10-21 09:51:081280 void BeginTest() override {
[email protected]0d7fb302014-01-23 21:30:471281 mailbox_released_ = false;
1282 PostSetNeedsCommitToMainThread();
1283 }
1284
dcheng716bedf2014-10-21 09:51:081285 void DidCommitAndDrawFrame() override { EndTest(); }
[email protected]0d7fb302014-01-23 21:30:471286
dcheng716bedf2014-10-21 09:51:081287 void AfterTest() override { EXPECT_TRUE(mailbox_released_); }
[email protected]0d7fb302014-01-23 21:30:471288
jaydasikabd6f15a2016-04-21 19:45:371289 protected:
1290 int texture_layer_id_;
1291
[email protected]0d7fb302014-01-23 21:30:471292 private:
1293 bool mailbox_released_;
1294};
1295
1296class TextureLayerReleaseResourcesAfterCommit
1297 : public TextureLayerReleaseResourcesBase {
1298 public:
dcheng716bedf2014-10-21 09:51:081299 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
kulkarni.a4015690f12014-10-10 13:50:061300 LayerTreeImpl* tree = nullptr;
danakj009cdfdf2015-02-17 22:35:141301 tree = host_impl->sync_tree();
jaydasikabd6f15a2016-04-21 19:45:371302 tree->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471303 }
1304};
1305
1306SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);
1307
1308class TextureLayerReleaseResourcesAfterActivate
1309 : public TextureLayerReleaseResourcesBase {
1310 public:
dcheng716bedf2014-10-21 09:51:081311 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
jaydasikabd6f15a2016-04-21 19:45:371312 host_impl->active_tree()->LayerById(texture_layer_id_)->ReleaseResources();
[email protected]0d7fb302014-01-23 21:30:471313 }
1314};
1315
1316SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);
1317
[email protected]9c2bd822013-07-26 12:30:171318class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest {
1319 public:
dyencc16ed4d2015-11-03 20:03:041320 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591321 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171322 EXPECT_FALSE(lost_resource);
1323 ++callback_count_;
1324 EndTest();
1325 }
1326
1327 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591328 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481329 std::unique_ptr<SingleReleaseCallback> callback =
1330 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171331 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback,
1332 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031333 layer_->SetTextureMailbox(
1334 TextureMailbox(MailboxFromChar(mailbox_char),
1335 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1336 GL_TEXTURE_2D),
1337 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171338 }
1339
dcheng716bedf2014-10-21 09:51:081340 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171341 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311342 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171343 root_->SetBounds(bounds);
1344
loyso0940d412016-03-14 01:30:311345 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171346 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171347 layer_->SetBounds(bounds);
1348
1349 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:051350 layer_tree()->SetRootLayer(root_);
1351 layer_tree()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171352 }
1353
dcheng716bedf2014-10-21 09:51:081354 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591355 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1356
[email protected]9c2bd822013-07-26 12:30:171357 callback_count_ = 0;
1358
1359 // Set the mailbox on the main thread.
1360 SetMailbox('1');
1361 EXPECT_EQ(0, callback_count_);
1362
1363 PostSetNeedsCommitToMainThread();
1364 }
1365
dcheng716bedf2014-10-21 09:51:081366 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011367 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171368 case 1:
1369 // Delete the TextureLayer on the main thread while the mailbox is in
1370 // the impl tree.
1371 layer_->RemoveFromParent();
kulkarni.a4015690f12014-10-10 13:50:061372 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171373 break;
1374 }
1375 }
1376
dcheng716bedf2014-10-21 09:51:081377 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171378
1379 private:
[email protected]9794fb32013-08-29 09:49:591380 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171381 int callback_count_;
1382 scoped_refptr<Layer> root_;
1383 scoped_refptr<TextureLayer> layer_;
1384};
1385
danakj0943a112016-08-11 00:33:461386SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxMainThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171387
1388class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest {
1389 public:
dyencc16ed4d2015-11-03 20:03:041390 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) {
[email protected]9794fb32013-08-29 09:49:591391 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
[email protected]9c2bd822013-07-26 12:30:171392 EXPECT_FALSE(lost_resource);
1393 ++callback_count_;
1394 EndTest();
1395 }
1396
1397 void SetMailbox(char mailbox_char) {
[email protected]9794fb32013-08-29 09:49:591398 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
danakj60bc3bc2016-04-09 00:24:481399 std::unique_ptr<SingleReleaseCallback> callback =
1400 SingleReleaseCallback::Create(base::Bind(
[email protected]9c2bd822013-07-26 12:30:171401 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback,
1402 base::Unretained(this)));
dyene5db881b2016-03-01 19:47:031403 layer_->SetTextureMailbox(
1404 TextureMailbox(MailboxFromChar(mailbox_char),
1405 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)),
1406 GL_TEXTURE_2D),
1407 std::move(callback));
[email protected]9c2bd822013-07-26 12:30:171408 }
1409
dcheng716bedf2014-10-21 09:51:081410 void SetupTree() override {
[email protected]9c2bd822013-07-26 12:30:171411 gfx::Size bounds(100, 100);
loyso0940d412016-03-14 01:30:311412 root_ = Layer::Create();
[email protected]9c2bd822013-07-26 12:30:171413 root_->SetBounds(bounds);
1414
loyso0940d412016-03-14 01:30:311415 layer_ = TextureLayer::CreateForMailbox(nullptr);
[email protected]9c2bd822013-07-26 12:30:171416 layer_->SetIsDrawable(true);
[email protected]9c2bd822013-07-26 12:30:171417 layer_->SetBounds(bounds);
1418
1419 root_->AddChild(layer_);
khushalsagar86928f92016-08-17 21:49:051420 layer_tree()->SetRootLayer(root_);
1421 layer_tree()->SetViewportSize(bounds);
[email protected]9c2bd822013-07-26 12:30:171422 }
1423
dcheng716bedf2014-10-21 09:51:081424 void BeginTest() override {
[email protected]9794fb32013-08-29 09:49:591425 EXPECT_EQ(true, main_thread_.CalledOnValidThread());
1426
[email protected]9c2bd822013-07-26 12:30:171427 callback_count_ = 0;
1428
1429 // Set the mailbox on the main thread.
1430 SetMailbox('1');
1431 EXPECT_EQ(0, callback_count_);
1432
1433 PostSetNeedsCommitToMainThread();
1434 }
1435
dcheng716bedf2014-10-21 09:51:081436 void DidCommitAndDrawFrame() override {
khushalsagarcebe4942016-09-07 23:27:011437 switch (layer_tree_host()->SourceFrameNumber()) {
[email protected]9c2bd822013-07-26 12:30:171438 case 1:
1439 // Remove the TextureLayer on the main thread while the mailbox is in
1440 // the impl tree, but don't delete the TextureLayer until after the impl
1441 // tree side is deleted.
1442 layer_->RemoveFromParent();
1443 break;
1444 case 2:
kulkarni.a4015690f12014-10-10 13:50:061445 layer_ = nullptr;
[email protected]9c2bd822013-07-26 12:30:171446 break;
1447 }
1448 }
1449
dcheng716bedf2014-10-21 09:51:081450 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
[email protected]9c2bd822013-07-26 12:30:171451
1452 private:
[email protected]9794fb32013-08-29 09:49:591453 base::ThreadChecker main_thread_;
[email protected]9c2bd822013-07-26 12:30:171454 int callback_count_;
1455 scoped_refptr<Layer> root_;
1456 scoped_refptr<TextureLayer> layer_;
1457};
1458
danakj0943a112016-08-11 00:33:461459SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted);
[email protected]9c2bd822013-07-26 12:30:171460
[email protected]ba565742012-11-10 09:29:481461} // namespace
1462} // namespace cc