chromium/cc/layers/texture_layer_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/layers/texture_layer.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <memory>
#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/animation/animation_host.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/texture_layer_client.h"
#include "cc/layers/texture_layer_impl.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/layer_tree_test.h"
#include "cc/test/stub_layer_tree_host_single_thread_client.h"
#include "cc/test/test_layer_tree_frame_sink.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "components/viz/common/gpu/raster_context_provider.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/resources/bitmap_allocation.h"
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/resources/shared_bitmap.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "components/viz/service/display/software_output_device.h"
#include "components/viz/test/fake_output_surface.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
AnyNumber;
AtLeast;
InvokeWithoutArgs;
Mock;

// TODO(crbug.com/40883999): settings new expecations after
// VerifyAndClearExpectations is undefined behavior. See
// http://google.github.io/googletest/gmock_cook_book.html#forcing-a-verification
#define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test)

namespace cc {
namespace {

gpu::Mailbox MailboxFromChar(char value) {}

gpu::SyncToken SyncTokenFromUInt(uint32_t value) {}

scoped_refptr<CrossThreadSharedBitmap> AllocateCrossThreadSharedBitmap(
    gfx::Size size,
    viz::SharedImageFormat format) {}

class MockLayerTreeHost : public LayerTreeHost {};

class MockReleaseCallback {};

struct CommonResourceObjects {};

class TextureLayerTest : public testing::Test {};

TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {}

class RunOnCommitLayerTreeHostClient : public FakeLayerTreeHostClient {};

// If the compositor is destroyed while TextureLayer has a resource in it, the
// resource should be returned to the client. https://crbug.com/857262
TEST_F(TextureLayerTest, ShutdownWithResource) {}

class TestMailboxHolder : public TextureLayer::TransferableResourceHolder {};

class TextureLayerWithResourceTest : public TextureLayerTest {};

TEST_F(TextureLayerWithResourceTest, ReplaceMailboxOnMainThreadBeforeCommit) {}

TEST_F(TextureLayerWithResourceTest, AffectedByHdr) {}

class TextureLayerMailboxHolderTest : public TextureLayerTest {};

TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) {}

TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) {}

TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {}

class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);

class TextureLayerImplWithResourceTest : public TextureLayerTest {};

// Test conditions for results of TextureLayerImpl::WillDraw under
// different configurations of different mailbox, texture_id, and draw_mode.
TEST_F(TextureLayerImplWithResourceTest, TestWillDraw) {}

TEST_F(TextureLayerImplWithResourceTest, TestImplLayerCallbacks) {}

TEST_F(TextureLayerImplWithResourceTest,
       TestDestructorCallbackOnCreatedResource) {}

// Checks that TextureLayer::Update does not cause an extra commit when setting
// the texture mailbox.
class TextureLayerNoExtraCommitForMailboxTest : public LayerTreeTest,
                                                public TextureLayerClient {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);

// Checks that changing a mailbox in the client for a TextureLayer that's
// invisible correctly works and uses the new mailbox as soon as the layer
// becomes visible (and returns the old one).
class TextureLayerChangeInvisibleMailboxTest : public LayerTreeTest,
                                               public TextureLayerClient {};

// TODO(crbug.com/40760099): Test fails on chromeos-amd64-generic-rel.
#if BUILDFLAG(IS_CHROMEOS)
#define MAYBE_SINGLE_AND_MULTI_THREAD_TEST_F
#else
#define MAYBE_SINGLE_AND_MULTI_THREAD_TEST_F
#endif

MAYBE_SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);

// Test that TextureLayerImpl::ReleaseResources can be called which releases
// the resource back to TextureLayerClient.
class TextureLayerReleaseResourcesBase : public LayerTreeTest,
                                         public TextureLayerClient {};

class TextureLayerReleaseResourcesAfterCommit
    : public TextureLayerReleaseResourcesBase {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);

class TextureLayerReleaseResourcesAfterActivate
    : public TextureLayerReleaseResourcesBase {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);

class TextureLayerWithResourceMainThreadDeleted : public LayerTreeTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithResourceMainThreadDeleted);

class TextureLayerWithResourceImplThreadDeleted : public LayerTreeTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithResourceImplThreadDeleted);

class StubTextureLayerClient : public TextureLayerClient {};

class SoftwareLayerTreeHostClient : public StubLayerTreeHostClient {};

class SoftwareTextureLayerTest : public LayerTreeTest {};

class SoftwareTextureLayerSwitchTreesTest : public SoftwareTextureLayerTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(SoftwareTextureLayerSwitchTreesTest);

// Verify that duplicate SharedBitmapIds aren't registered if resources are
// purged due to memory pressure.
class SoftwareTextureLayerPurgeMemoryTest : public SoftwareTextureLayerTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(SoftwareTextureLayerPurgeMemoryTest);

class SoftwareTextureLayerMultipleRegisterTest
    : public SoftwareTextureLayerTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(SoftwareTextureLayerMultipleRegisterTest);

class SoftwareTextureLayerRegisterUnregisterTest
    : public SoftwareTextureLayerTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(SoftwareTextureLayerRegisterUnregisterTest);

class SoftwareTextureLayerLoseFrameSinkTest : public SoftwareTextureLayerTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(SoftwareTextureLayerLoseFrameSinkTest);

class SoftwareTextureLayerUnregisterRegisterTest
    : public SoftwareTextureLayerTest {};

SINGLE_AND_MULTI_THREAD_TEST_F(SoftwareTextureLayerUnregisterRegisterTest);

class TextureLayerNoResourceTest : public LayerTreeTest, TextureLayerClient {};

SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoResourceTest);

}  // namespace
}  // namespace cc