OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 | 1181 |
1182 TextureMailbox MakeMailbox(char name) { | 1182 TextureMailbox MakeMailbox(char name) { |
1183 return TextureMailbox(MailboxFromChar(name), | 1183 return TextureMailbox(MailboxFromChar(name), |
1184 SyncTokenFromUInt(static_cast<uint32_t>(name)), | 1184 SyncTokenFromUInt(static_cast<uint32_t>(name)), |
1185 GL_TEXTURE_2D); | 1185 GL_TEXTURE_2D); |
1186 } | 1186 } |
1187 | 1187 |
1188 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) { | 1188 void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) { |
1189 EXPECT_TRUE(sync_token.HasData()); | 1189 EXPECT_TRUE(sync_token.HasData()); |
1190 ++mailbox_returned_; | 1190 ++mailbox_returned_; |
1191 switch (mailbox_returned_) { | |
1192 case 1: | |
1193 break; | |
1194 case 2: | |
1195 EXPECT_EQ(commit_count_, 5); | |
1196 EndTest(); | |
1197 break; | |
1198 default: | |
1199 NOTREACHED(); | |
1200 } | |
1201 } | 1191 } |
1202 | 1192 |
1203 void SetupTree() override { | 1193 void SetupTree() override { |
1204 scoped_refptr<Layer> root = Layer::Create(); | 1194 scoped_refptr<Layer> root = Layer::Create(); |
1205 root->SetBounds(gfx::Size(10, 10)); | 1195 root->SetBounds(gfx::Size(10, 10)); |
1206 root->SetIsDrawable(true); | 1196 root->SetIsDrawable(true); |
1207 | 1197 |
1208 solid_layer_ = SolidColorLayer::Create(); | 1198 solid_layer_ = SolidColorLayer::Create(); |
1209 solid_layer_->SetBounds(gfx::Size(10, 10)); | 1199 solid_layer_->SetBounds(gfx::Size(10, 10)); |
1210 solid_layer_->SetIsDrawable(true); | 1200 solid_layer_->SetIsDrawable(true); |
1211 solid_layer_->SetBackgroundColor(SK_ColorWHITE); | 1201 solid_layer_->SetBackgroundColor(SK_ColorWHITE); |
1212 root->AddChild(solid_layer_); | 1202 root->AddChild(solid_layer_); |
1213 | 1203 |
1214 parent_layer_ = Layer::Create(); | 1204 parent_layer_ = Layer::Create(); |
1215 parent_layer_->SetBounds(gfx::Size(10, 10)); | 1205 parent_layer_->SetBounds(gfx::Size(10, 10)); |
1216 parent_layer_->SetIsDrawable(true); | 1206 parent_layer_->SetIsDrawable(true); |
1217 root->AddChild(parent_layer_); | 1207 root->AddChild(parent_layer_); |
1218 | 1208 |
1219 texture_layer_ = TextureLayer::CreateForMailbox(this); | 1209 texture_layer_ = TextureLayer::CreateForMailbox(this); |
1220 texture_layer_->SetBounds(gfx::Size(10, 10)); | 1210 texture_layer_->SetBounds(gfx::Size(10, 10)); |
1221 texture_layer_->SetIsDrawable(true); | 1211 texture_layer_->SetIsDrawable(true); |
1222 parent_layer_->AddChild(texture_layer_); | 1212 parent_layer_->AddChild(texture_layer_); |
1223 | 1213 |
1224 layer_tree_host()->SetRootLayer(root); | 1214 layer_tree_host()->SetRootLayer(root); |
1225 LayerTreeTest::SetupTree(); | 1215 LayerTreeTest::SetupTree(); |
1226 } | 1216 } |
1227 | 1217 |
1228 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1218 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1229 | 1219 |
1230 void DidCommitAndDrawFrame() override { | 1220 void DidReceiveCompositorFrameAck() override { |
1231 ++commit_count_; | 1221 ++commit_count_; |
1232 switch (commit_count_) { | 1222 switch (commit_count_) { |
1233 case 1: | 1223 case 1: |
1234 // We should have updated the layer, committing the texture. | 1224 // We should have updated the layer, committing the texture. |
1235 EXPECT_EQ(1, prepare_called_); | 1225 EXPECT_EQ(1, prepare_called_); |
1236 // Make layer invisible. | 1226 // Make layer invisible. |
1237 parent_layer_->SetOpacity(0.f); | 1227 parent_layer_->SetOpacity(0.f); |
1238 break; | 1228 break; |
1239 case 2: | 1229 case 2: |
1240 // Layer shouldn't have been updated. | 1230 // Layer shouldn't have been updated. |
(...skipping 14 matching lines...) Expand all Loading... |
1255 parent_layer_->SetOpacity(0.9f); | 1245 parent_layer_->SetOpacity(0.9f); |
1256 break; | 1246 break; |
1257 case 4: | 1247 case 4: |
1258 // Layer should have been updated. | 1248 // Layer should have been updated. |
1259 EXPECT_EQ(2, prepare_called_); | 1249 EXPECT_EQ(2, prepare_called_); |
1260 // So the old mailbox should have been returned already. | 1250 // So the old mailbox should have been returned already. |
1261 EXPECT_EQ(1, mailbox_returned_); | 1251 EXPECT_EQ(1, mailbox_returned_); |
1262 texture_layer_->ClearClient(); | 1252 texture_layer_->ClearClient(); |
1263 break; | 1253 break; |
1264 case 5: | 1254 case 5: |
| 1255 EXPECT_EQ(2, mailbox_returned_); |
| 1256 EndTest(); |
1265 break; | 1257 break; |
1266 default: | 1258 default: |
1267 NOTREACHED(); | 1259 NOTREACHED(); |
1268 break; | 1260 break; |
1269 } | 1261 } |
1270 } | 1262 } |
1271 | 1263 |
1272 void AfterTest() override {} | 1264 void AfterTest() override {} |
1273 | 1265 |
1274 private: | 1266 private: |
1275 scoped_refptr<SolidColorLayer> solid_layer_; | 1267 scoped_refptr<SolidColorLayer> solid_layer_; |
1276 scoped_refptr<Layer> parent_layer_; | 1268 scoped_refptr<Layer> parent_layer_; |
1277 scoped_refptr<TextureLayer> texture_layer_; | 1269 scoped_refptr<TextureLayer> texture_layer_; |
1278 | 1270 |
1279 // Used on the main thread. | 1271 // Used on the main thread. |
1280 bool mailbox_changed_; | 1272 bool mailbox_changed_; |
1281 TextureMailbox mailbox_; | 1273 TextureMailbox mailbox_; |
1282 int mailbox_returned_; | 1274 int mailbox_returned_; |
1283 int prepare_called_; | 1275 int prepare_called_; |
1284 int commit_count_; | 1276 int commit_count_; |
1285 }; | 1277 }; |
1286 | 1278 |
1287 // Flaky when multi-threaded. crbug.com/702868 | 1279 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); |
1288 SINGLE_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); | |
1289 | 1280 |
1290 // Test that TextureLayerImpl::ReleaseResources can be called which releases | 1281 // Test that TextureLayerImpl::ReleaseResources can be called which releases |
1291 // the mailbox back to TextureLayerClient. | 1282 // the mailbox back to TextureLayerClient. |
1292 class TextureLayerReleaseResourcesBase | 1283 class TextureLayerReleaseResourcesBase |
1293 : public LayerTreeTest, | 1284 : public LayerTreeTest, |
1294 public TextureLayerClient { | 1285 public TextureLayerClient { |
1295 public: | 1286 public: |
1296 // TextureLayerClient implementation. | 1287 // TextureLayerClient implementation. |
1297 bool PrepareTextureMailbox( | 1288 bool PrepareTextureMailbox( |
1298 TextureMailbox* mailbox, | 1289 TextureMailbox* mailbox, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 base::ThreadChecker main_thread_; | 1488 base::ThreadChecker main_thread_; |
1498 int callback_count_; | 1489 int callback_count_; |
1499 scoped_refptr<Layer> root_; | 1490 scoped_refptr<Layer> root_; |
1500 scoped_refptr<TextureLayer> layer_; | 1491 scoped_refptr<TextureLayer> layer_; |
1501 }; | 1492 }; |
1502 | 1493 |
1503 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); | 1494 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); |
1504 | 1495 |
1505 } // namespace | 1496 } // namespace |
1506 } // namespace cc | 1497 } // namespace cc |
OLD | NEW |