texture_layer_impl_unittest.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2014 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. #include "cc/layers/texture_layer_impl.h"
  5. #include <stddef.h>
  6. #include "base/bind.h"
  7. #include "cc/test/fake_layer_tree_frame_sink.h"
  8. #include "cc/test/layer_tree_impl_test_base.h"
  9. #include "cc/trees/layer_tree_frame_sink.h"
  10. #include "components/viz/common/gpu/context_provider.h"
  11. #include "components/viz/common/quads/draw_quad.h"
  12. #include "components/viz/common/quads/texture_draw_quad.h"
  13. #include "gpu/command_buffer/client/gles2_interface.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. namespace cc {
  16. namespace {
  17. void IgnoreCallback(const gpu::SyncToken& sync_token, bool lost) {}
  18. TEST(TextureLayerImplTest, VisibleOpaqueRegion) {
  19. const gfx::Size layer_bounds(100, 100);
  20. const gfx::Rect layer_rect(layer_bounds);
  21. const Region layer_region(layer_rect);
  22. LayerTreeImplTestBase impl;
  23. TextureLayerImpl* layer = impl.AddLayer<TextureLayerImpl>();
  24. layer->SetBounds(layer_bounds);
  25. layer->draw_properties().visible_layer_rect = layer_rect;
  26. layer->SetBlendBackgroundColor(true);
  27. CopyProperties(impl.root_layer(), layer);
  28. // Verify initial conditions.
  29. EXPECT_FALSE(layer->contents_opaque());
  30. EXPECT_EQ(SkColors::kTransparent, layer->background_color());
  31. EXPECT_EQ(Region().ToString(), layer->VisibleOpaqueRegion().ToString());
  32. // Opaque background.
  33. layer->SetBackgroundColor(SkColors::kWhite);
  34. EXPECT_EQ(layer_region.ToString(), layer->VisibleOpaqueRegion().ToString());
  35. // Transparent background.
  36. layer->SetBackgroundColor({1.0f, 1.0f, 1.0f, 0.5f});
  37. EXPECT_EQ(Region().ToString(), layer->VisibleOpaqueRegion().ToString());
  38. }
  39. TEST(TextureLayerImplTest, Occlusion) {
  40. gfx::Size layer_size(1000, 1000);
  41. gfx::Size viewport_size(1000, 1000);
  42. LayerTreeImplTestBase impl;
  43. auto resource = viz::TransferableResource::MakeGL(
  44. gpu::Mailbox::Generate(), GL_LINEAR, GL_TEXTURE_2D,
  45. gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
  46. gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456),
  47. layer_size, false /* is_overlay_candidate */);
  48. TextureLayerImpl* texture_layer_impl = impl.AddLayer<TextureLayerImpl>();
  49. texture_layer_impl->SetBounds(layer_size);
  50. texture_layer_impl->SetDrawsContent(true);
  51. texture_layer_impl->SetTransferableResource(resource,
  52. base::BindOnce(&IgnoreCallback));
  53. CopyProperties(impl.root_layer(), texture_layer_impl);
  54. impl.CalcDrawProps(viewport_size);
  55. {
  56. SCOPED_TRACE("No occlusion");
  57. gfx::Rect occluded;
  58. impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
  59. VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect(layer_size));
  60. EXPECT_EQ(1u, impl.quad_list().size());
  61. }
  62. {
  63. SCOPED_TRACE("Full occlusion");
  64. gfx::Rect occluded(texture_layer_impl->visible_layer_rect());
  65. impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
  66. VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
  67. EXPECT_EQ(impl.quad_list().size(), 0u);
  68. }
  69. {
  70. SCOPED_TRACE("Partial occlusion");
  71. gfx::Rect occluded(200, 0, 800, 1000);
  72. impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
  73. size_t partially_occluded_count = 0;
  74. VerifyQuadsAreOccluded(impl.quad_list(), occluded,
  75. &partially_occluded_count);
  76. // The layer outputs one quad, which is partially occluded.
  77. EXPECT_EQ(1u, impl.quad_list().size());
  78. EXPECT_EQ(1u, partially_occluded_count);
  79. }
  80. }
  81. } // namespace
  82. } // namespace cc