Commit 0ac2010e authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

gpu/SharedImageFactory: add ForTesting method

This CL adds a method to register a backing factory for testing
to SharedImageFactory, to be used in crrev.com/c/1619832. It is
needed since otherwise the GetFactoryByUsage() method starts
digging into the factory specifics and usually for testing this
is not needed and is cumbersome to mock.

Bug: 984836
Change-Id: I8009d54cb2a9576e10c5c63c803b9c6294b60f3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1699531
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678338}
parent 19d48e40
...@@ -152,7 +152,9 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox, ...@@ -152,7 +152,9 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
// TODO(ericrk): Make this generic in the future. // TODO(ericrk): Make this generic in the future.
bool allow_legacy_mailbox = false; bool allow_legacy_mailbox = false;
SharedImageBackingFactory* factory = nullptr; SharedImageBackingFactory* factory = nullptr;
if (!using_vulkan_) { if (backing_factory_for_testing_) {
factory = backing_factory_for_testing_;
} else if (!using_vulkan_) {
allow_legacy_mailbox = true; allow_legacy_mailbox = true;
factory = gl_backing_factory_.get(); factory = gl_backing_factory_.get();
} else { } else {
...@@ -262,6 +264,11 @@ bool SharedImageFactory::OnMemoryDump( ...@@ -262,6 +264,11 @@ bool SharedImageFactory::OnMemoryDump(
return true; return true;
} }
void SharedImageFactory::RegisterSharedImageBackingFactoryForTesting(
SharedImageBackingFactory* factory) {
backing_factory_for_testing_ = factory;
}
bool SharedImageFactory::IsSharedBetweenThreads(uint32_t usage) { bool SharedImageFactory::IsSharedBetweenThreads(uint32_t usage) {
// If |shared_image_manager_| is thread safe, it means the display is running // If |shared_image_manager_| is thread safe, it means the display is running
// on a separate thread (which uses a separate GL context or VkDeviceQueue). // on a separate thread (which uses a separate GL context or VkDeviceQueue).
...@@ -273,6 +280,9 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage( ...@@ -273,6 +280,9 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage(
uint32_t usage, uint32_t usage,
bool* allow_legacy_mailbox, bool* allow_legacy_mailbox,
gfx::GpuMemoryBufferType gmb_type) { gfx::GpuMemoryBufferType gmb_type) {
if (backing_factory_for_testing_)
return backing_factory_for_testing_;
bool using_dawn = usage & SHARED_IMAGE_USAGE_WEBGPU; bool using_dawn = usage & SHARED_IMAGE_USAGE_WEBGPU;
bool vulkan_usage = using_vulkan_ && (usage & SHARED_IMAGE_USAGE_DISPLAY); bool vulkan_usage = using_vulkan_ && (usage & SHARED_IMAGE_USAGE_DISPLAY);
bool gl_usage = usage & SHARED_IMAGE_USAGE_GLES2; bool gl_usage = usage & SHARED_IMAGE_USAGE_GLES2;
......
...@@ -97,6 +97,9 @@ class GPU_GLES2_EXPORT SharedImageFactory { ...@@ -97,6 +97,9 @@ class GPU_GLES2_EXPORT SharedImageFactory {
bool RegisterBacking(std::unique_ptr<SharedImageBacking> backing, bool RegisterBacking(std::unique_ptr<SharedImageBacking> backing,
bool allow_legacy_mailbox); bool allow_legacy_mailbox);
void RegisterSharedImageBackingFactoryForTesting(
SharedImageBackingFactory* factory);
private: private:
bool IsSharedBetweenThreads(uint32_t usage); bool IsSharedBetweenThreads(uint32_t usage);
SharedImageBackingFactory* GetFactoryByUsage( SharedImageBackingFactory* GetFactoryByUsage(
...@@ -128,6 +131,8 @@ class GPU_GLES2_EXPORT SharedImageFactory { ...@@ -128,6 +131,8 @@ class GPU_GLES2_EXPORT SharedImageFactory {
// Used for creating DXGI Swap Chain. // Used for creating DXGI Swap Chain.
std::unique_ptr<SwapChainFactoryDXGI> swap_chain_factory_; std::unique_ptr<SwapChainFactoryDXGI> swap_chain_factory_;
#endif // OS_WIN #endif // OS_WIN
SharedImageBackingFactory* backing_factory_for_testing_ = nullptr;
}; };
class GPU_GLES2_EXPORT SharedImageRepresentationFactory { class GPU_GLES2_EXPORT SharedImageRepresentationFactory {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment