aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-11-15 15:48:03 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-15 22:03:07 +0000
commitdcfca431e3c350e17eedb3402cc63577cea8d4ea (patch)
treeb65ff91284663aef37e7603bbdba1fda51eb0c89
parent20800c8b1bb7181fc7d3c6af756dc4440094ac90 (diff)
Use GrContextFactories that produce a single GrContext in unit tests.
This is to alleviate problems due to the command buffer getting bent out of shape when the current OpenGL context is switched out from under it (because we ran a test with a native GL context). This, however is not a full solution. More changes will be required to ensure that after running each command buffer or native test we bind the null context. This does allow us to take a step in that direction without breaking anything too badly. Moreover, there is no real benefit to reusing a GrContextFactory. Modifies DEF_GPUTEST to take GrContextOptions rather than a factory to use. Tests were already using their own factories anyway. In tests that use GrContextFactory the factory instance is moved to the inner loop. Modifies gpucts and skia_test to not use persistent GrContextFactories. Change-Id: Ie7a36793545c775f2f30653ead6fec93a3d22717 Reviewed-on: https://skia-review.googlesource.com/71861 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r--dm/DM.cpp3
-rw-r--r--dm/DMGpuTestProcs.cpp15
-rw-r--r--tests/GLProgramsTest.cpp6
-rw-r--r--tests/GpuDrawPathTest.cpp2
-rw-r--r--tests/GpuSampleLocationsTest.cpp2
-rw-r--r--tests/GrCCPRTest.cpp8
-rw-r--r--tests/GrContextAbandonTest.cpp4
-rw-r--r--tests/GrContextFactoryTest.cpp43
-rw-r--r--tests/GrPorterDuffTest.cpp4
-rw-r--r--tests/GrTRecorderTest.cpp2
-rw-r--r--tests/ImageTest.cpp13
-rw-r--r--tests/PathRendererCacheTests.cpp6
-rw-r--r--tests/ResourceCacheTest.cpp2
-rw-r--r--tests/SurfaceSemaphoreTest.cpp13
-rw-r--r--tests/Test.h39
-rw-r--r--tests/TestTest.cpp3
-rw-r--r--tests/skia_test.cpp70
-rw-r--r--tools/gpucts/gm_runner.cpp34
-rw-r--r--tools/gpucts/gm_runner.h13
-rw-r--r--tools/gpucts/gpucts.cpp42
-rw-r--r--tools/ok_test.cpp12
21 files changed, 139 insertions, 197 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 2ef7dc97fa..a4e70fe79f 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -1279,8 +1279,7 @@ static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions)
test.modifyGrContextOptions(&options);
start("unit", "test", "", test.name);
- GrContextFactory factory(options);
- test.run(&reporter, &factory);
+ test.run(&reporter, options);
}
done("unit", "test", "", test.name);
}
diff --git a/dm/DMGpuTestProcs.cpp b/dm/DMGpuTestProcs.cpp
index c3ec588b81..ef55c0ab55 100644
--- a/dm/DMGpuTestProcs.cpp
+++ b/dm/DMGpuTestProcs.cpp
@@ -36,7 +36,7 @@ bool IsNullGLContextType(int) { return false; }
#endif
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
- Reporter* reporter, GrContextFactory* factory) {
+ Reporter* reporter, const GrContextOptions& options) {
#if SK_SUPPORT_GPU
#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
@@ -55,8 +55,13 @@ void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contex
continue;
}
}
- ContextInfo ctxInfo = factory->getContextInfo(contextType,
- GrContextFactory::ContextOverrides::kDisableNVPR);
+ // We destroy the factory and its associated contexts after each test. This is due to the
+ // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but
+ // also tracks which of its contexts is current above that API and gets tripped up if the
+ // native windowing API is used directly outside of the command buffer code.
+ GrContextFactory factory(options);
+ ContextInfo ctxInfo = factory.getContextInfo(
+ contextType, GrContextFactory::ContextOverrides::kDisableNVPR);
if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
continue;
}
@@ -66,8 +71,8 @@ void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contex
(*test)(reporter, ctxInfo);
ctxInfo.grContext()->flush();
}
- ctxInfo = factory->getContextInfo(contextType,
- GrContextFactory::ContextOverrides::kRequireNVPRSupport);
+ ctxInfo = factory.getContextInfo(contextType,
+ GrContextFactory::ContextOverrides::kRequireNVPRSupport);
if (ctxInfo.grContext()) {
(*test)(reporter, ctxInfo);
ctxInfo.grContext()->flush();
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index e0ac272009..5c97b6b9fe 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -398,7 +398,7 @@ static void test_glprograms(skiatest::Reporter* reporter, const sk_gpu_test::Con
maxLevels));
}
-DEF_GPUTEST(GLPrograms, reporter, /*factory*/) {
+DEF_GPUTEST(GLPrograms, reporter, options) {
// Set a locale that would cause shader compilation to fail because of , as decimal separator.
// skbug 3330
#ifdef SK_BUILD_FOR_WIN
@@ -408,11 +408,11 @@ DEF_GPUTEST(GLPrograms, reporter, /*factory*/) {
#endif
// We suppress prints to avoid spew
- GrContextOptions opts;
+ GrContextOptions opts = options;
opts.fSuppressPrints = true;
sk_gpu_test::GrContextFactory debugFactory(opts);
skiatest::RunWithGPUTestContexts(test_glprograms, &skiatest::IsRenderingGLContextType, reporter,
- &debugFactory);
+ opts);
}
#endif
diff --git a/tests/GpuDrawPathTest.cpp b/tests/GpuDrawPathTest.cpp
index 83641cb2ec..012dc61cb8 100644
--- a/tests/GpuDrawPathTest.cpp
+++ b/tests/GpuDrawPathTest.cpp
@@ -91,7 +91,7 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GpuDrawPath, reporter, ctxInfo) {
}
}
-DEF_GPUTEST(GrPathKeys, reporter, /*factory*/) {
+DEF_GPUTEST(GrPathKeys, reporter, /* options */) {
SkPaint strokePaint;
strokePaint.setStyle(SkPaint::kStroke_Style);
strokePaint.setStrokeWidth(10.f);
diff --git a/tests/GpuSampleLocationsTest.cpp b/tests/GpuSampleLocationsTest.cpp
index 36b518111f..e78006344c 100644
--- a/tests/GpuSampleLocationsTest.cpp
+++ b/tests/GpuSampleLocationsTest.cpp
@@ -184,7 +184,7 @@ private:
SamplePattern fSamplePattern;
};
-DEF_GPUTEST(GLSampleLocations, reporter, /*factory*/) {
+DEF_GPUTEST(GLSampleLocations, reporter, /* options */) {
GLTestSampleLocationsInterface testInterface;
sk_sp<GrContext> ctx(GrContext::MakeGL(&testInterface));
diff --git a/tests/GrCCPRTest.cpp b/tests/GrCCPRTest.cpp
index b8e3db9c10..dc1025cf6e 100644
--- a/tests/GrCCPRTest.cpp
+++ b/tests/GrCCPRTest.cpp
@@ -124,10 +124,10 @@ protected:
SkPath fPath;
};
-#define DEF_CCPR_TEST(name) \
- DEF_GPUTEST(name, reporter, factory) { \
- name test; \
- test.run(reporter); \
+#define DEF_CCPR_TEST(name) \
+ DEF_GPUTEST(name, reporter, /* options */) { \
+ name test; \
+ test.run(reporter); \
}
class GrCCPRTest_cleanup : public CCPRTest {
diff --git a/tests/GrContextAbandonTest.cpp b/tests/GrContextAbandonTest.cpp
index 03e45128b0..544e121e04 100644
--- a/tests/GrContextAbandonTest.cpp
+++ b/tests/GrContextAbandonTest.cpp
@@ -14,10 +14,10 @@
using namespace sk_gpu_test;
-DEF_GPUTEST(GrContext_abandonContext, reporter, /*factory*/) {
+DEF_GPUTEST(GrContext_abandonContext, reporter, options) {
for (int testType = 0; testType < 6; ++testType) {
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
- GrContextFactory testFactory;
+ GrContextFactory testFactory(options);
GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i;
ContextInfo info = testFactory.getContextInfo(ctxType);
if (GrContext* context = info.grContext()) {
diff --git a/tests/GrContextFactoryTest.cpp b/tests/GrContextFactoryTest.cpp
index 1514d67717..29f68366c3 100644
--- a/tests/GrContextFactoryTest.cpp
+++ b/tests/GrContextFactoryTest.cpp
@@ -17,12 +17,12 @@
using namespace sk_gpu_test;
-DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, /*factory*/) {
+DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, options) {
// Test that if NVPR is requested, the context always has path rendering
// or the context creation fails.
- GrContextFactory testFactory;
- // Test that if NVPR is possible, caps are in sync.
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
+ GrContextFactory testFactory(options);
+ // Test that if NVPR is possible, caps are in sync.
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
GrContext* context = testFactory.get(ctxType,
GrContextFactory::ContextOverrides::kRequireNVPRSupport);
@@ -35,11 +35,11 @@ DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter,
}
}
-DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, /*factory*/) {
+DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, options) {
// Test that if NVPR is explicitly disabled, the context has no path rendering support.
- GrContextFactory testFactory;
for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) {
+ GrContextFactory testFactory(options);
GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i;
GrContext* context =
testFactory.get(ctxType, GrContextFactory::ContextOverrides::kDisableNVPR);
@@ -51,13 +51,13 @@ DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, /*factory*
}
}
-DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) {
+DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, options) {
// Test that if sRGB support is requested, the context always has that capability
// or the context creation fails. Also test that if the creation fails, a context
// created without that flag would not have had sRGB support.
- GrContextFactory testFactory;
- // Test that if sRGB is requested, caps are in sync.
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
+ GrContextFactory testFactory(options);
+ // Test that if sRGB is requested, caps are in sync.
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
GrContext* context =
testFactory.get(ctxType, GrContextFactory::ContextOverrides::kRequireSRGBSupport);
@@ -73,9 +73,9 @@ DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) {
}
}
-DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) {
- GrContextFactory testFactory;
+DEF_GPUTEST(GrContextFactory_abandon, reporter, options) {
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
+ GrContextFactory testFactory(options);
GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i;
ContextInfo info1 = testFactory.getContextInfo(ctxType);
if (!info1.grContext()) {
@@ -98,10 +98,9 @@ DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) {
}
}
-DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
- GrContextFactory testFactory;
-
+DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, options) {
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
+ GrContextFactory testFactory(options);
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
ContextInfo info1 = testFactory.getContextInfo(ctxType);
if (!info1.grContext()) {
@@ -141,17 +140,17 @@ DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
}
}
-DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, /*factory*/) {
- // Verify that contexts have a task group iff we supply an executor with context options
- GrContextOptions contextOptions;
- contextOptions.fExecutor = nullptr;
- GrContextFactory serialFactory(contextOptions);
+DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, options) {
+ for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
+ // Verify that contexts have a task group iff we supply an executor with context options
+ GrContextOptions contextOptions = options;
+ contextOptions.fExecutor = nullptr;
+ GrContextFactory serialFactory(contextOptions);
- std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1);
- contextOptions.fExecutor = threadPool.get();
- GrContextFactory threadedFactory(contextOptions);
+ std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1);
+ contextOptions.fExecutor = threadPool.get();
+ GrContextFactory threadedFactory(contextOptions);
- for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
ContextInfo serialInfo = serialFactory.getContextInfo(ctxType);
if (GrContext* serialContext = serialInfo.grContext()) {
diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp
index 6ce0458a56..ddfcdef602 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -1050,8 +1050,8 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const
TEST_ASSERT(blendInfo.fWriteColor);
}
-DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
- GrContextOptions opts;
+DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) {
+ GrContextOptions opts = options;
opts.fSuppressDualSourceBlending = true;
sk_gpu_test::GrContextFactory mockFactory(opts);
GrContext* ctx = mockFactory.get(sk_gpu_test::GrContextFactory::kNullGL_ContextType);
diff --git a/tests/GrTRecorderTest.cpp b/tests/GrTRecorderTest.cpp
index 0be0f68db9..5041dd9854 100644
--- a/tests/GrTRecorderTest.cpp
+++ b/tests/GrTRecorderTest.cpp
@@ -283,7 +283,7 @@ static void test_subclasses_iters(skiatest::Reporter* reporter, Order& order,
REPORTER_ASSERT(reporter, reverseIter.previous() == !!i);
}
-DEF_GPUTEST(GrTRecorder, reporter, factory) {
+DEF_GPUTEST(GrTRecorder, reporter, /* options */) {
test_empty_back_and_pop(reporter);
test_extra_data(reporter);
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 49ef86847d..30ae635c98 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -810,11 +810,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
}
-static void test_cross_context_image(skiatest::Reporter* reporter,
+static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options,
std::function<sk_sp<SkImage>(GrContext*)> imageMaker) {
- GrContextFactory testFactory;
-
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
+ GrContextFactory testFactory(options);
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
GrContext* ctx = ctxInfo.grContext();
@@ -958,21 +957,21 @@ static void test_cross_context_image(skiatest::Reporter* reporter,
}
}
-DEF_GPUTEST(SkImage_MakeCrossContextFromEncodedRelease, reporter, /*factory*/) {
+DEF_GPUTEST(SkImage_MakeCrossContextFromEncodedRelease, reporter, options) {
sk_sp<SkData> data = GetResourceAsData("mandrill_128.png");
SkASSERT(data.get());
- test_cross_context_image(reporter, [&data](GrContext* ctx) {
+ test_cross_context_image(reporter, options, [&data](GrContext* ctx) {
return SkImage::MakeCrossContextFromEncoded(ctx, data, false, nullptr);
});
}
-DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, /*factory*/) {
+DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) {
SkBitmap bitmap;
SkPixmap pixmap;
SkAssertResult(GetResourceAsBitmap("mandrill_128.png", &bitmap) && bitmap.peekPixels(&pixmap));
- test_cross_context_image(reporter, [&pixmap](GrContext* ctx) {
+ test_cross_context_image(reporter, options, [&pixmap](GrContext* ctx) {
return SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false, nullptr);
});
}
diff --git a/tests/PathRendererCacheTests.cpp b/tests/PathRendererCacheTests.cpp
index dbf01ab029..8c3ba2a46c 100644
--- a/tests/PathRendererCacheTests.cpp
+++ b/tests/PathRendererCacheTests.cpp
@@ -109,7 +109,7 @@ static void test_path(skiatest::Reporter* reporter,
}
// Test that deleting the original path invalidates the VBs cached by the tessellating path renderer
-DEF_GPUTEST(TessellatingPathRendererCacheTest, reporter, factory) {
+DEF_GPUTEST(TessellatingPathRendererCacheTest, reporter, /* options */) {
auto createPR = [](GrContext*) {
return new GrTessellatingPathRenderer();
};
@@ -130,9 +130,7 @@ DEF_GPUTEST(TessellatingPathRendererCacheTest, reporter, factory) {
}
// Test that deleting the original path invalidates the textures cached by the SW path renderer
-DEF_GPUTEST(SoftwarePathRendererCacheTest, reporter, factory) {
-// Currently disabled since the test is only passing thanks to uninteded behavior in deleting a
-// resource since we are over budget. If we increase the cache budget the test will fail
+DEF_GPUTEST(SoftwarePathRendererCacheTest, reporter, /* options */) {
auto createPR = [](GrContext* ctx) {
return new GrSoftwarePathRenderer(ctx->resourceProvider(), true);
};
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 863830aefe..0d977796cd 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -1596,7 +1596,7 @@ static void test_tags(skiatest::Reporter* reporter) {
#endif
}
-DEF_GPUTEST(ResourceCacheMisc, reporter, factory) {
+DEF_GPUTEST(ResourceCacheMisc, reporter, /* options */) {
// The below tests create their own mock contexts.
test_no_key(reporter);
test_budgeting(reporter);
diff --git a/tests/SurfaceSemaphoreTest.cpp b/tests/SurfaceSemaphoreTest.cpp
index 9b3f90429a..8ae0953d88 100644
--- a/tests/SurfaceSemaphoreTest.cpp
+++ b/tests/SurfaceSemaphoreTest.cpp
@@ -169,7 +169,7 @@ void surface_semaphore_test(skiatest::Reporter* reporter,
draw_child(reporter, childInfo2, backendImage, semaphores[1]);
}
-DEF_GPUTEST(SurfaceSemaphores, reporter, factory) {
+DEF_GPUTEST(SurfaceSemaphores, reporter, options) {
#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
static constexpr auto kNativeGLType = sk_gpu_test::GrContextFactory::kGL_ContextType;
#else
@@ -188,7 +188,8 @@ DEF_GPUTEST(SurfaceSemaphores, reporter, factory) {
continue;
}
}
- sk_gpu_test::ContextInfo ctxInfo = factory->getContextInfo(
+ sk_gpu_test::GrContextFactory factory(options);
+ sk_gpu_test::ContextInfo ctxInfo = factory.getContextInfo(
contextType, sk_gpu_test::GrContextFactory::ContextOverrides::kDisableNVPR);
if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) {
continue;
@@ -196,10 +197,10 @@ DEF_GPUTEST(SurfaceSemaphores, reporter, factory) {
skiatest::ReporterContext ctx(
reporter, SkString(sk_gpu_test::GrContextFactory::ContextTypeName(contextType)));
if (ctxInfo.grContext()) {
- sk_gpu_test::ContextInfo child1 = factory->getSharedContextInfo(ctxInfo.grContext(),
- 0);
- sk_gpu_test::ContextInfo child2 = factory->getSharedContextInfo(ctxInfo.grContext(),
- 1);
+ sk_gpu_test::ContextInfo child1 =
+ factory.getSharedContextInfo(ctxInfo.grContext(), 0);
+ sk_gpu_test::ContextInfo child2 =
+ factory.getSharedContextInfo(ctxInfo.grContext(), 1);
if (!child1.grContext() || !child2.grContext()) {
continue;
}
diff --git a/tests/Test.h b/tests/Test.h
index 3e344743db..fc47d25932 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -89,7 +89,7 @@ private:
Reporter* fReporter;
};
-typedef void (*TestProc)(skiatest::Reporter*, sk_gpu_test::GrContextFactory*);
+typedef void (*TestProc)(skiatest::Reporter*, const GrContextOptions&);
typedef void (*ContextOptionsProc)(GrContextOptions*);
struct Test {
@@ -106,9 +106,9 @@ struct Test {
}
}
- void run(skiatest::Reporter* r, sk_gpu_test::GrContextFactory* factory) const {
+ void run(skiatest::Reporter* r, const GrContextOptions& options) const {
TRACE_EVENT1("test", TRACE_FUNC, "name", this->name/*these are static*/);
- this->proc(r, factory);
+ this->proc(r, options);
}
};
@@ -146,8 +146,8 @@ extern bool IsGLContextType(GrContextFactoryContextType);
extern bool IsVulkanContextType(GrContextFactoryContextType);
extern bool IsRenderingGLContextType(GrContextFactoryContextType);
extern bool IsNullGLContextType(GrContextFactoryContextType);
-void RunWithGPUTestContexts(GrContextTestFn*, GrContextTypeFilterFn*,
- Reporter*, sk_gpu_test::GrContextFactory*);
+void RunWithGPUTestContexts(GrContextTestFn*, GrContextTypeFilterFn*, Reporter*,
+ const GrContextOptions&);
/** Timer provides wall-clock duration since its creation. */
class Timer {
@@ -197,30 +197,25 @@ private:
} \
} while (0)
-#define DEF_TEST(name, reporter) \
- static void test_##name(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); \
- skiatest::TestRegistry name##TestRegistry( \
- skiatest::Test(#name, false, test_##name)); \
- void test_##name(skiatest::Reporter* reporter, sk_gpu_test::GrContextFactory*)
+#define DEF_TEST(name, reporter) \
+ static void test_##name(skiatest::Reporter*, const GrContextOptions&); \
+ skiatest::TestRegistry name##TestRegistry(skiatest::Test(#name, false, test_##name)); \
+ void test_##name(skiatest::Reporter* reporter, const GrContextOptions&)
-
-#define DEF_GPUTEST(name, reporter, factory) \
- static void test_##name(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); \
- skiatest::TestRegistry name##TestRegistry( \
- skiatest::Test(#name, true, test_##name)); \
- void test_##name(skiatest::Reporter* reporter, sk_gpu_test::GrContextFactory* factory)
+#define DEF_GPUTEST(name, reporter, options) \
+ static void test_##name(skiatest::Reporter*, const GrContextOptions&); \
+ skiatest::TestRegistry name##TestRegistry(skiatest::Test(#name, true, test_##name)); \
+ void test_##name(skiatest::Reporter* reporter, const GrContextOptions& options)
#define DEF_GPUTEST_FOR_CONTEXTS(name, context_filter, reporter, context_info, options_filter) \
- static void test_##name(skiatest::Reporter*, \
- const sk_gpu_test::ContextInfo& context_info); \
+ static void test_##name(skiatest::Reporter*, const sk_gpu_test::ContextInfo& context_info); \
static void test_gpu_contexts_##name(skiatest::Reporter* reporter, \
- sk_gpu_test::GrContextFactory* factory) { \
- skiatest::RunWithGPUTestContexts(test_##name, context_filter, reporter, factory); \
+ const GrContextOptions& options) { \
+ skiatest::RunWithGPUTestContexts(test_##name, context_filter, reporter, options); \
} \
skiatest::TestRegistry name##TestRegistry( \
skiatest::Test(#name, true, test_gpu_contexts_##name, options_filter)); \
- void test_##name(skiatest::Reporter* reporter, \
- const sk_gpu_test::ContextInfo& context_info)
+ void test_##name(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& context_info)
#define DEF_GPUTEST_FOR_ALL_CONTEXTS(name, reporter, context_info) \
DEF_GPUTEST_FOR_CONTEXTS(name, nullptr, reporter, context_info, nullptr)
diff --git a/tests/TestTest.cpp b/tests/TestTest.cpp
index d366bb4703..fbec68340a 100644
--- a/tests/TestTest.cpp
+++ b/tests/TestTest.cpp
@@ -18,11 +18,10 @@ DEF_TEST(TestNormal, reporter) {
REPORTER_ASSERT(reporter, reporter);
}
-// This is an example of a GPU test that uses common GrContextFactory factory to do the test.
+// This is an example of a GPU test that uses GrContextOptions to do the test.
#if SK_SUPPORT_GPU
DEF_GPUTEST(TestGpuFactory, reporter, factory) {
REPORTER_ASSERT(reporter, reporter);
- REPORTER_ASSERT(reporter, factory);
}
#endif
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index 6b7df71c28..8e4cbae67a 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -22,6 +22,8 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextFactory.h"
+#else
+struct GrContextOptions {};
#endif
using namespace skiatest;
@@ -82,38 +84,32 @@ private:
class SkTestRunnable {
public:
- SkTestRunnable(const Test& test,
- Status* status,
- GrContextFactory* grContextFactory = nullptr)
- : fTest(test), fStatus(status), fGrContextFactory(grContextFactory) {}
-
- void operator()() {
- struct TestReporter : public skiatest::Reporter {
- public:
- TestReporter() : fStats(nullptr), fError(false), fTestCount(0) {}
- void bumpTestCount() override { ++fTestCount; }
- bool allowExtendedTest() const override {
- return FLAGS_extendedTest;
- }
- bool verbose() const override { return FLAGS_veryVerbose; }
- void reportFailed(const skiatest::Failure& failure) override {
- SkDebugf("\nFAILED: %s", failure.toString().c_str());
- fError = true;
- }
- void* stats() const override { return fStats; }
- void* fStats;
- bool fError;
- int fTestCount;
- } reporter;
-
- const Timer timer;
- fTest.proc(&reporter, fGrContextFactory);
- SkMSec elapsed = timer.elapsedMsInt();
- if (reporter.fError) {
- fStatus->reportFailure();
- }
- fStatus->endTest(fTest.name, !reporter.fError, elapsed,
- reporter.fTestCount);
+ SkTestRunnable(const Test& test, Status* status) : fTest(test), fStatus(status) {}
+
+ void operator()() {
+ struct TestReporter : public skiatest::Reporter {
+ public:
+ TestReporter() : fStats(nullptr), fError(false), fTestCount(0) {}
+ void bumpTestCount() override { ++fTestCount; }
+ bool allowExtendedTest() const override { return FLAGS_extendedTest; }
+ bool verbose() const override { return FLAGS_veryVerbose; }
+ void reportFailed(const skiatest::Failure& failure) override {
+ SkDebugf("\nFAILED: %s", failure.toString().c_str());
+ fError = true;
+ }
+ void* stats() const override { return fStats; }
+ void* fStats;
+ bool fError;
+ int fTestCount;
+ } reporter;
+
+ const Timer timer;
+ fTest.proc(&reporter, GrContextOptions());
+ SkMSec elapsed = timer.elapsedMsInt();
+ if (reporter.fError) {
+ fStatus->reportFailure();
+ }
+ fStatus->endTest(fTest.name, !reporter.fError, elapsed, reporter.fTestCount);
}
private:
@@ -233,17 +229,9 @@ int main(int argc, char** argv) {
}
}
- GrContextFactory* grContextFactoryPtr = nullptr;
-#if SK_SUPPORT_GPU
- // Give GPU tests a context factory if that makes sense on this machine.
- GrContextFactory grContextFactory;
- grContextFactoryPtr = &grContextFactory;
-
-#endif
-
// Run GPU tests on this thread.
for (int i = 0; i < gpuTests.count(); i++) {
- SkTestRunnable(*gpuTests[i], &status, grContextFactoryPtr)();
+ SkTestRunnable(*gpuTests[i], &status)();
}
// Block until threaded tests finish.
diff --git a/tools/gpucts/gm_runner.cpp b/tools/gpucts/gm_runner.cpp
index 92d918106d..a18c457d1b 100644
--- a/tools/gpucts/gm_runner.cpp
+++ b/tools/gpucts/gm_runner.cpp
@@ -9,7 +9,6 @@
#include <algorithm>
-#include "SkGraphics.h"
#include "SkSurface.h"
#include "gm.h"
@@ -34,23 +33,23 @@ const char* GetBackendName(SkiaBackend backend) {
return GrContextFactory::ContextTypeName(to_context_type(backend));
}
-bool BackendSupported(SkiaBackend backend, GrContextFactory* contextFactory) {
- return contextFactory->get(to_context_type(backend)) != nullptr;
+bool BackendSupported(SkiaBackend backend) {
+ GrContextFactory factory;
+ return factory.get(to_context_type(backend)) != nullptr;
}
GMK_ImageData Evaluate(SkiaBackend backend,
GMFactory gmFact,
- GrContextFactory* contextFactory,
std::vector<uint32_t>* storage) {
- SkASSERT(contextFactory);
SkASSERT(gmFact);
SkASSERT(storage);
std::unique_ptr<skiagm::GM> gm(gmFact(nullptr));
SkASSERT(gm.get());
int w = SkScalarRoundToInt(gm->width());
int h = SkScalarRoundToInt(gm->height());
- GrContext* context = contextFactory->get(to_context_type(backend));
+ GrContextFactory contextFactory;
+ GrContext* context = contextFactory.get(to_context_type(backend));
if (!context) {
return GMK_ImageData{nullptr, w, h};
}
@@ -72,21 +71,6 @@ GMK_ImageData Evaluate(SkiaBackend backend,
return GMK_ImageData{pix, w, h};
}
-std::unique_ptr<GrContextFactory> make_gr_context_factory() {
- GrContextOptions grContextOptions; // TODO: change options?
- return std::unique_ptr<GrContextFactory>(new GrContextFactory(grContextOptions));
-}
-
-SkiaContext::SkiaContext() : fGrContextFactory(make_gr_context_factory()) {
- SkGraphics::Init();
-}
-
-void SkiaContext::resetContextFactory() {
- fGrContextFactory->destroyContexts();
-}
-
-SkiaContext::~SkiaContext() {}
-
} // namespace gm_runner
#else
@@ -94,12 +78,8 @@ namespace sk_gpu_test {
class GrContextFactory {};
}
namespace gm_runner {
-SkiaContext::SkiaContext() {}
-SkiaContext::~SkiaContext() {}
-void SkiaContext::resetContextFactory() {}
-bool BackendSupported(SkiaBackend, sk_gpu_test::GrContextFactory*) { return false; }
-GMK_ImageData Evaluate(SkiaBackend, GMFactory,
- sk_gpu_test::GrContextFactory*, std::vector<uint32_t>*) {
+bool BackendSupported(SkiaBackend) { return false; }
+GMK_ImageData Evaluate(SkiaBackend, GMFactory, std::vector<uint32_t>*) {
return GMK_ImageData{nullptr, 0, 0};
}
const char* GetBackendName(SkiaBackend backend) { return "Unknown"; }
diff --git a/tools/gpucts/gm_runner.h b/tools/gpucts/gm_runner.h
index 6324914799..cd0d7d32bb 100644
--- a/tools/gpucts/gm_runner.h
+++ b/tools/gpucts/gm_runner.h
@@ -34,17 +34,7 @@ enum class SkiaBackend {
kVulkan,
};
-/**
-This class initializes Skia and a GrContextFactory.
-*/
-struct SkiaContext {
- SkiaContext();
- ~SkiaContext();
- void resetContextFactory();
- std::unique_ptr<sk_gpu_test::GrContextFactory> fGrContextFactory;
-};
-
-bool BackendSupported(SkiaBackend, sk_gpu_test::GrContextFactory*);
+bool BackendSupported(SkiaBackend);
/**
@return a list of all Skia GMs in lexicographic order.
@@ -68,7 +58,6 @@ storage (overwriting existing contents of storage).
*/
GMK_ImageData Evaluate(SkiaBackend,
GMFactory,
- sk_gpu_test::GrContextFactory*,
std::vector<uint32_t>* storage);
} // namespace gm_runner
diff --git a/tools/gpucts/gpucts.cpp b/tools/gpucts/gpucts.cpp
index d244d91e2d..c50519cc5b 100644
--- a/tools/gpucts/gpucts.cpp
+++ b/tools/gpucts/gpucts.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkGraphics.h"
#include "gm_runner.h"
#ifdef __clang__
@@ -25,7 +26,6 @@
struct GMTestCase {
gm_runner::GMFactory fGMFactory;
gm_runner::SkiaBackend fBackend;
- sk_gpu_test::GrContextFactory* fGrContextFactory;
};
struct GMTest : public testing::Test {
@@ -33,12 +33,11 @@ struct GMTest : public testing::Test {
GMTest(GMTestCase t) : fTest(t) {}
void TestBody() override {
if (!fTest.fGMFactory) {
- EXPECT_TRUE(gm_runner::BackendSupported(fTest.fBackend, fTest.fGrContextFactory));
+ EXPECT_TRUE(gm_runner::BackendSupported(fTest.fBackend));
return;
}
std::vector<uint32_t> pixels;
- GMK_ImageData imgData = gm_runner::Evaluate(
- fTest.fBackend, fTest.fGMFactory, fTest.fGrContextFactory, &pixels);
+ GMK_ImageData imgData = gm_runner::Evaluate(fTest.fBackend, fTest.fGMFactory, &pixels);
EXPECT_TRUE(imgData.pix);
if (!imgData.pix) {
return;
@@ -57,14 +56,13 @@ struct GMTestFactory : public testing::internal::TestFactoryBase {
////////////////////////////////////////////////////////////////////////////////
-struct UnitTestData {
- gm_runner::SkiaContext* fContext;
- skiatest::TestProc fProc;
-};
+#if !SK_SUPPORT_GPU
+struct GrContextOptions {};
+#endif
struct UnitTest : public testing::Test {
- UnitTestData fUnitTestData;
- UnitTest(UnitTestData d) : fUnitTestData(d) {}
+ skiatest::TestProc fProc;
+ UnitTest(skiatest::TestProc proc) : fProc(proc) {}
void TestBody() override {
struct : skiatest::Reporter {
void reportFailed(const skiatest::Failure& failure) override {
@@ -73,15 +71,14 @@ struct UnitTest : public testing::Test {
GTEST_NONFATAL_FAILURE_(desc.c_str());
}
} r;
- fUnitTestData.fContext->resetContextFactory();
- fUnitTestData.fProc(&r, fUnitTestData.fContext->fGrContextFactory.get());
+ fProc(&r, GrContextOptions());
}
};
struct UnitTestFactory : testing::internal::TestFactoryBase {
- UnitTestData fUnitTestData;
- UnitTestFactory(UnitTestData d) : fUnitTestData(d) {}
- testing::Test* CreateTest() override { return new UnitTest(fUnitTestData); }
+ skiatest::TestProc fProc;
+ UnitTestFactory(skiatest::TestProc proc) : fProc(proc) {}
+ testing::Test* CreateTest() override { return new UnitTest(fProc); }
};
std::vector<const skiatest::Test*> GetUnitTests() {
@@ -117,8 +114,7 @@ static void reg_test(const char* test, const char* testCase,
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
- gm_runner::SkiaContext context;
- sk_gpu_test::GrContextFactory* grContextFactory = context.fGrContextFactory.get();
+ SkGraphics::Init();
// Rendering Tests
gm_runner::SkiaBackend backends[] = {
@@ -132,10 +128,9 @@ int main(int argc, char** argv) {
for (auto backend : backends) {
const char* backendName = GetBackendName(backend);
std::string test = std::string("SkiaGM_") + backendName;
- reg_test(test.c_str(), "BackendSupported",
- new GMTestFactory(GMTestCase{nullptr, backend, grContextFactory}));
+ reg_test(test.c_str(), "BackendSupported", new GMTestFactory(GMTestCase{nullptr, backend}));
- if (!gm_runner::BackendSupported(backend, context.fGrContextFactory.get())) {
+ if (!gm_runner::BackendSupported(backend)) {
continue;
}
for (auto gmFactory : gms) {
@@ -151,14 +146,13 @@ int main(int argc, char** argv) {
continue;
}
#endif
- reg_test(test.c_str(), gmName.c_str(),
- new GMTestFactory(GMTestCase{gmFactory, backend, grContextFactory}));
+ reg_test(test.c_str(), gmName.c_str(),
+ new GMTestFactory(GMTestCase{gmFactory, backend}));
}
}
for (const skiatest::Test* test : GetUnitTests()) {
- reg_test("Skia_Unit_Tests", test->name,
- new UnitTestFactory(UnitTestData{&context, test->proc}));
+ reg_test("Skia_Unit_Tests", test->name, new UnitTestFactory(test->proc));
}
return RUN_ALL_TESTS();
}
diff --git a/tools/ok_test.cpp b/tools/ok_test.cpp
index 7c020d88e1..232904209d 100644
--- a/tools/ok_test.cpp
+++ b/tools/ok_test.cpp
@@ -10,6 +10,8 @@
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
+#else
+struct GrContextOptions {};
#endif
struct TestStream : Stream {
@@ -46,14 +48,8 @@ struct TestStream : Stream {
reporter.extended = extended;
reporter.verbose_ = verbose;
- sk_gpu_test::GrContextFactory* factory = nullptr;
- #if SK_SUPPORT_GPU
GrContextOptions options;
- sk_gpu_test::GrContextFactory a_real_factory(options);
- factory = &a_real_factory;
- #endif
-
- test.run(&reporter, factory);
+ test.run(&reporter, options);
return reporter.status;
}
};
@@ -95,7 +91,7 @@ namespace skiatest {
#endif
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
- Reporter* reporter, sk_gpu_test::GrContextFactory* factory) {
+ Reporter* reporter, const GrContextOptions& options) {
// TODO(bsalomon)
}
}