Commit f7738881 authored by kylechar's avatar kylechar Committed by Commit Bot

Use test shared image backing factory

SkiaOutputDeviceBufferQueueTest was crashing on Linux with passthrough
command decoder when SwANGLE is enabled. We end up testing
SkiaOutputDeviceBufferQueue with shared images it's not intended to work
with since it's the default implementation for the platform.

Add TestSharedImageBackingFactory that always creates a
TestSharedImageBacking to avoid this. We don't need a real shared image
in order to test SkiaOutputDeviceBufferQueue logic.

Bug: 1131521
Change-Id: I668a4a158c45ad36cabd53376e764a1c5343c013
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450724
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814234}
parent 5c44bb70
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gpu/command_buffer/service/scheduler.h" #include "components/viz/common/resources/resource_sizes.h"
#include "components/viz/service/display_embedder/output_presenter_gl.h" #include "components/viz/service/display_embedder/output_presenter_gl.h"
#include "components/viz/service/display_embedder/skia_output_surface_dependency_impl.h" #include "components/viz/service/display_embedder/skia_output_surface_dependency_impl.h"
#include "components/viz/service/gl/gpu_service_impl.h" #include "components/viz/service/gl/gpu_service_impl.h"
#include "components/viz/test/test_gpu_service_holder.h" #include "components/viz/test/test_gpu_service_holder.h"
#include "gpu/command_buffer/common/shared_image_usage.h" #include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/shared_image_backing_factory.h"
#include "gpu/command_buffer/service/test_shared_image_backing.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/types/display_snapshot.h" #include "ui/display/types/display_snapshot.h"
...@@ -31,6 +32,7 @@ using ::testing::Expectation; ...@@ -31,6 +32,7 @@ using ::testing::Expectation;
using ::testing::Ne; using ::testing::Ne;
using ::testing::Return; using ::testing::Return;
namespace viz {
namespace { namespace {
// These MACRO and TestOnGpu class make it easier to write tests that runs on // These MACRO and TestOnGpu class make it easier to write tests that runs on
...@@ -87,7 +89,7 @@ class TestOnGpu : public ::testing::Test { ...@@ -87,7 +89,7 @@ class TestOnGpu : public ::testing::Test {
} }
void SetUp() override { void SetUp() override {
gpu_service_holder_ = viz::TestGpuServiceHolder::GetInstance(); gpu_service_holder_ = TestGpuServiceHolder::GetInstance();
SetUpOnMain(); SetUpOnMain();
auto setup = base::BindLambdaForTesting([&]() { this->SetUpOnGpu(); }); auto setup = base::BindLambdaForTesting([&]() { this->SetUpOnGpu(); });
...@@ -121,12 +123,67 @@ class TestOnGpu : public ::testing::Test { ...@@ -121,12 +123,67 @@ class TestOnGpu : public ::testing::Test {
virtual void TearDownOnGpu() {} virtual void TearDownOnGpu() {}
virtual void TestBodyOnGpu() {} virtual void TestBodyOnGpu() {}
viz::TestGpuServiceHolder* gpu_service_holder_; TestGpuServiceHolder* gpu_service_holder_;
base::WaitableEvent wait_; base::WaitableEvent wait_;
}; };
// Here starts SkiaOutputDeviceBufferQueue test related code // Here starts SkiaOutputDeviceBufferQueue test related code
class TestSharedImageBackingFactory : public gpu::SharedImageBackingFactory {
public:
TestSharedImageBackingFactory() = default;
~TestSharedImageBackingFactory() override = default;
// gpu::SharedImageBackingFactory implementation.
std::unique_ptr<gpu::SharedImageBacking> CreateSharedImage(
const gpu::Mailbox& mailbox,
ResourceFormat format,
gpu::SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
GrSurfaceOrigin surface_origin,
SkAlphaType alpha_type,
uint32_t usage,
bool is_thread_safe) override {
size_t estimated_size =
ResourceSizes::CheckedSizeInBytes<size_t>(size, format);
return std::make_unique<gpu::TestSharedImageBacking>(
mailbox, format, size, color_space, surface_origin, alpha_type, usage,
estimated_size);
}
std::unique_ptr<gpu::SharedImageBacking> CreateSharedImage(
const gpu::Mailbox& mailbox,
ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
GrSurfaceOrigin surface_origin,
SkAlphaType alpha_type,
uint32_t usage,
base::span<const uint8_t> pixel_data) override {
return std::make_unique<gpu::TestSharedImageBacking>(
mailbox, format, size, color_space, surface_origin, alpha_type, usage,
pixel_data.size());
}
std::unique_ptr<gpu::SharedImageBacking> CreateSharedImage(
const gpu::Mailbox& mailbox,
int client_id,
gfx::GpuMemoryBufferHandle handle,
gfx::BufferFormat format,
gpu::SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
GrSurfaceOrigin surface_origin,
SkAlphaType alpha_type,
uint32_t usage) override {
NOTREACHED();
return nullptr;
}
bool CanImportGpuMemoryBuffer(
gfx::GpuMemoryBufferType memory_buffer_type) override {
return false;
}
};
class MockGLSurfaceAsync : public gl::GLSurfaceStub { class MockGLSurfaceAsync : public gl::GLSurfaceStub {
public: public:
bool SupportsAsyncSwap() override { return true; } bool SupportsAsyncSwap() override { return true; }
...@@ -198,11 +255,9 @@ class MemoryTrackerStub : public gpu::MemoryTracker { ...@@ -198,11 +255,9 @@ class MemoryTrackerStub : public gpu::MemoryTracker {
} // namespace } // namespace
namespace viz {
class SkiaOutputDeviceBufferQueueTest : public TestOnGpu { class SkiaOutputDeviceBufferQueueTest : public TestOnGpu {
public: public:
SkiaOutputDeviceBufferQueueTest() {} SkiaOutputDeviceBufferQueueTest() = default;
void SetUpOnMain() override { void SetUpOnMain() override {
gpu::SurfaceHandle surface_handle_ = gpu::kNullSurfaceHandle; gpu::SurfaceHandle surface_handle_ = gpu::kNullSurfaceHandle;
...@@ -220,6 +275,8 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu { ...@@ -220,6 +275,8 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu {
dependency_->GetSharedContextState().get(), dependency_->GetSharedContextState().get(),
dependency_->GetMailboxManager(), dependency_->GetSharedImageManager(), dependency_->GetMailboxManager(), dependency_->GetSharedImageManager(),
dependency_->GetGpuImageFactory(), memory_tracker_.get(), true), dependency_->GetGpuImageFactory(), memory_tracker_.get(), true),
shared_image_factory_->RegisterSharedImageBackingFactoryForTesting(
&test_backing_factory_);
shared_image_representation_factory_ = shared_image_representation_factory_ =
std::make_unique<gpu::SharedImageRepresentationFactory>( std::make_unique<gpu::SharedImageRepresentationFactory>(
dependency_->GetSharedImageManager(), memory_tracker_.get()); dependency_->GetSharedImageManager(), memory_tracker_.get());
...@@ -228,18 +285,12 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu { ...@@ -228,18 +285,12 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu {
base::DoNothing::Repeatedly<gpu::SwapBuffersCompleteParams, base::DoNothing::Repeatedly<gpu::SwapBuffersCompleteParams,
const gfx::Size&>(); const gfx::Size&>();
uint32_t shared_image_usage = output_device_ = std::make_unique<SkiaOutputDeviceBufferQueue>(
gpu::SHARED_IMAGE_USAGE_DISPLAY |
gpu::SHARED_IMAGE_USAGE_GLES2_FRAMEBUFFER_HINT;
auto onscreen_device = std::make_unique<SkiaOutputDeviceBufferQueue>(
std::make_unique<OutputPresenterGL>( std::make_unique<OutputPresenterGL>(
gl_surface_, dependency_.get(), shared_image_factory_.get(), gl_surface_, dependency_.get(), shared_image_factory_.get(),
shared_image_representation_factory_.get(), shared_image_usage), shared_image_representation_factory_.get()),
dependency_.get(), shared_image_representation_factory_.get(), dependency_.get(), shared_image_representation_factory_.get(),
memory_tracker_.get(), present_callback); memory_tracker_.get(), present_callback);
output_device_ = std::move(onscreen_device);
} }
void TearDownOnGpu() override { void TearDownOnGpu() override {
...@@ -345,6 +396,7 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu { ...@@ -345,6 +396,7 @@ class SkiaOutputDeviceBufferQueueTest : public TestOnGpu {
std::unique_ptr<SkiaOutputSurfaceDependency> dependency_; std::unique_ptr<SkiaOutputSurfaceDependency> dependency_;
scoped_refptr<MockGLSurfaceAsync> gl_surface_; scoped_refptr<MockGLSurfaceAsync> gl_surface_;
std::unique_ptr<MemoryTrackerStub> memory_tracker_; std::unique_ptr<MemoryTrackerStub> memory_tracker_;
TestSharedImageBackingFactory test_backing_factory_;
std::unique_ptr<gpu::SharedImageFactory> shared_image_factory_; std::unique_ptr<gpu::SharedImageFactory> shared_image_factory_;
std::unique_ptr<gpu::SharedImageRepresentationFactory> std::unique_ptr<gpu::SharedImageRepresentationFactory>
shared_image_representation_factory_; shared_image_representation_factory_;
......
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