Commit c62c1140 authored by Juanmi Huertas's avatar Juanmi Huertas Committed by Commit Bot

Refactoring sharedGpuContextTest to stop using AcceleratedUsage

Replacing instances of AcceleratedResourceUsage for SharedImage and
Bitmap resource providers.
Changing expectation of a test as this now should fail and not fallback
into the Bitmap mode unless we explicitly call it.
Adding a new SharedGPUContextTest with the Viz context system, to be
able to validate the correct creation of a CanvasResourceProvider
of SharedImage.

Also modifying gpu_test_utils to set the context to not lost.

Bug: 1035589, 1021287
Change-Id: I15342b57f3721bad7bb2b44af184c5b0ae8a4764
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095878Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750301}
parent 656ffccb
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/test/null_task_runner.h" #include "base/test/null_task_runner.h"
#include "components/viz/test/test_gles2_interface.h" #include "components/viz/test/test_gles2_interface.h"
#include "gpu/command_buffer/client/gles2_interface.h" #include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/common/capabilities.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 "third_party/blink/renderer/platform/graphics/canvas_2d_layer_bridge.h" #include "third_party/blink/renderer/platform/graphics/canvas_2d_layer_bridge.h"
...@@ -38,7 +39,12 @@ class SharedGpuContextTestBase : public Test { ...@@ -38,7 +39,12 @@ class SharedGpuContextTestBase : public Test {
-> std::unique_ptr<WebGraphicsContext3DProvider> { -> std::unique_ptr<WebGraphicsContext3DProvider> {
*gpu_compositing_disabled = false; *gpu_compositing_disabled = false;
gl->SetIsContextLost(false); gl->SetIsContextLost(false);
return std::make_unique<FakeWebGraphicsContext3DProvider>(gl); auto fake_context =
std::make_unique<FakeWebGraphicsContext3DProvider>(gl);
gpu::Capabilities capabilities;
capabilities.max_texture_size = 20;
fake_context->SetCapabilities(capabilities);
return fake_context;
}; };
SharedGpuContext::SetContextProviderFactoryForTesting( SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(&gl_))); WTF::BindRepeating(factory, WTF::Unretained(&gl_)));
...@@ -120,6 +126,27 @@ class SoftwareCompositingTest : public Test { ...@@ -120,6 +126,27 @@ class SoftwareCompositingTest : public Test {
FakeGLES2Interface gl_; FakeGLES2Interface gl_;
}; };
class SharedGpuContextTestViz : public Test {
public:
void SetUp() override {
task_runner_ = base::MakeRefCounted<base::NullTaskRunner>();
handle_ = std::make_unique<base::ThreadTaskRunnerHandle>(task_runner_);
test_context_provider_ = viz::TestContextProvider::Create();
InitializeSharedGpuContext(test_context_provider_.get(),
/*cache = */ nullptr,
SetIsContextLost::kSetToFalse);
}
void TearDown() override {
handle_.reset();
task_runner_.reset();
SharedGpuContext::ResetForTesting();
}
scoped_refptr<base::NullTaskRunner> task_runner_;
std::unique_ptr<base::ThreadTaskRunnerHandle> handle_;
scoped_refptr<viz::TestContextProvider> test_context_provider_;
};
TEST_F(SharedGpuContextTest, contextLossAutoRecovery) { TEST_F(SharedGpuContextTest, contextLossAutoRecovery) {
EXPECT_NE(SharedGpuContext::ContextProviderWrapper(), nullptr); EXPECT_NE(SharedGpuContext::ContextProviderWrapper(), nullptr);
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context = base::WeakPtr<WebGraphicsContext3DProviderWrapper> context =
...@@ -133,26 +160,6 @@ TEST_F(SharedGpuContextTest, contextLossAutoRecovery) { ...@@ -133,26 +160,6 @@ TEST_F(SharedGpuContextTest, contextLossAutoRecovery) {
EXPECT_FALSE(!!context); EXPECT_FALSE(!!context);
} }
TEST_F(SharedGpuContextTest, AccelerateImageBufferSurfaceAutoRecovery) {
// Verifies that after a context loss, attempting to allocate an
// AcceleratedImageBufferSurface will restore the context and succeed
gl_.SetIsContextLost(true);
EXPECT_FALSE(SharedGpuContext::IsValidWithoutRestoring());
IntSize size(10, 10);
std::unique_ptr<CanvasResourceProvider> resource_provider =
CanvasResourceProvider::Create(
size,
CanvasResourceProvider::ResourceUsage::kAcceleratedResourceUsage,
SharedGpuContext::ContextProviderWrapper(),
0, // msaa_sample_count
kLow_SkFilterQuality, CanvasColorParams(),
CanvasResourceProvider::kDefaultPresentationMode,
nullptr // canvas_resource_dispatcher
);
EXPECT_TRUE(resource_provider && resource_provider->IsValid());
EXPECT_TRUE(SharedGpuContext::IsValidWithoutRestoring());
}
TEST_F(SharedGpuContextTest, Canvas2DLayerBridgeAutoRecovery) { TEST_F(SharedGpuContextTest, Canvas2DLayerBridgeAutoRecovery) {
// Verifies that after a context loss, attempting to allocate a // Verifies that after a context loss, attempting to allocate a
// Canvas2DLayerBridge will restore the context and succeed. // Canvas2DLayerBridge will restore the context and succeed.
...@@ -181,20 +188,15 @@ TEST_F(BadSharedGpuContextTest, AllowSoftwareToAcceleratedCanvasUpgrade) { ...@@ -181,20 +188,15 @@ TEST_F(BadSharedGpuContextTest, AllowSoftwareToAcceleratedCanvasUpgrade) {
} }
TEST_F(BadSharedGpuContextTest, AccelerateImageBufferSurfaceCreationFails) { TEST_F(BadSharedGpuContextTest, AccelerateImageBufferSurfaceCreationFails) {
// With a bad shared context, AccelerateImageBufferSurface creation should // With a bad shared context, AccelerateImageBufferSurface should fail and
// fail gracefully // return a nullptr provider
IntSize size(10, 10); IntSize size(10, 10);
std::unique_ptr<CanvasResourceProvider> resource_provider = std::unique_ptr<CanvasResourceProvider> resource_provider =
CanvasResourceProvider::Create( CanvasResourceProvider::CreateSharedImageProvider(
size, size, SharedGpuContext::ContextProviderWrapper(),
CanvasResourceProvider::ResourceUsage::kAcceleratedResourceUsage,
SharedGpuContext::ContextProviderWrapper(),
0, // msaa_sample_count
kLow_SkFilterQuality, CanvasColorParams(), kLow_SkFilterQuality, CanvasColorParams(),
CanvasResourceProvider::kDefaultPresentationMode, /* is_origin_top_left = */ true, /*shared_image_usage_flags = */ 0u);
nullptr // canvas_resource_dispatcher EXPECT_FALSE(resource_provider);
);
EXPECT_FALSE(!resource_provider);
} }
TEST_F(SharedGpuContextTest, CompositingMode) { TEST_F(SharedGpuContextTest, CompositingMode) {
...@@ -209,6 +211,22 @@ TEST_F(SoftwareCompositingTest, CompositingMode) { ...@@ -209,6 +211,22 @@ TEST_F(SoftwareCompositingTest, CompositingMode) {
EXPECT_FALSE(SharedGpuContext::IsGpuCompositingEnabled()); EXPECT_FALSE(SharedGpuContext::IsGpuCompositingEnabled());
} }
TEST_F(SharedGpuContextTestViz, AccelerateImageBufferSurfaceAutoRecovery) {
// Verifies that after a context loss, attempting to allocate an
// AcceleratedImageBufferSurface will restore the context and succeed
test_context_provider_->TestContextGL()->set_context_lost(true);
EXPECT_FALSE(SharedGpuContext::IsValidWithoutRestoring());
IntSize size(10, 10);
std::unique_ptr<CanvasResourceProvider> resource_provider =
CanvasResourceProvider::CreateSharedImageProvider(
size, SharedGpuContext::ContextProviderWrapper(),
kLow_SkFilterQuality, CanvasColorParams(),
/* is_origin_top_left = */ true, /*shared_image_usage_flags = */ 0u);
EXPECT_TRUE(resource_provider && resource_provider->IsValid());
EXPECT_TRUE(resource_provider->IsAccelerated());
EXPECT_TRUE(SharedGpuContext::IsValidWithoutRestoring());
}
} // unnamed namespace } // unnamed namespace
} // blink } // blink
...@@ -12,23 +12,33 @@ ...@@ -12,23 +12,33 @@
namespace blink { namespace blink {
void InitializeSharedGpuContext(viz::TestContextProvider* context_provider, void InitializeSharedGpuContext(viz::TestContextProvider* test_context_provider,
cc::ImageDecodeCache* cache) { cc::ImageDecodeCache* cache,
SetIsContextLost set_context_lost) {
auto factory = [](viz::TestGLES2Interface* gl, GrContext* context, auto factory = [](viz::TestGLES2Interface* gl, GrContext* context,
cc::ImageDecodeCache* cache, bool* gpu_compositing_disabled) cc::ImageDecodeCache* cache,
SetIsContextLost set_context_lost,
bool* gpu_compositing_disabled)
-> std::unique_ptr<WebGraphicsContext3DProvider> { -> std::unique_ptr<WebGraphicsContext3DProvider> {
*gpu_compositing_disabled = false; *gpu_compositing_disabled = false;
if (set_context_lost == SetIsContextLost::kSetToFalse)
gl->set_context_lost(false);
else if (set_context_lost == SetIsContextLost::kSetToTrue)
gl->set_context_lost(true);
// else set_context_lost will not be modified
auto context_provider = auto context_provider =
std::make_unique<FakeWebGraphicsContext3DProvider>(gl, cache, context); std::make_unique<FakeWebGraphicsContext3DProvider>(gl, cache, context);
context_provider->SetCapabilities(gl->test_capabilities()); context_provider->SetCapabilities(gl->test_capabilities());
return context_provider; return context_provider;
}; };
context_provider->BindToCurrentThread(); test_context_provider->BindToCurrentThread();
viz::TestGLES2Interface* gl = context_provider->TestContextGL(); viz::TestGLES2Interface* gl = test_context_provider->TestContextGL();
GrContext* context = context_provider->GrContext(); GrContext* context = test_context_provider->GrContext();
SharedGpuContext::SetContextProviderFactoryForTesting( SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(gl), WTF::Unretained(context), WTF::BindRepeating(factory, WTF::Unretained(gl), WTF::Unretained(context),
WTF::Unretained(cache))); WTF::Unretained(cache), set_context_lost));
} }
} // namespace blink } // namespace blink
...@@ -15,9 +15,12 @@ class TestContextProvider; ...@@ -15,9 +15,12 @@ class TestContextProvider;
namespace blink { namespace blink {
void InitializeSharedGpuContext(viz::TestContextProvider* context_provider, enum class SetIsContextLost { kNotModifyValue, kSetToTrue, kSetToFalse };
cc::ImageDecodeCache* cache = nullptr);
void InitializeSharedGpuContext(
viz::TestContextProvider* context_provider,
cc::ImageDecodeCache* cache = nullptr,
SetIsContextLost set_context_lost = SetIsContextLost::kNotModifyValue);
} }
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_GPU_TEST_UTILS_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_GPU_TEST_UTILS_H_
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