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>
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 2ef7dc9..a4e70fe 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -1279,8 +1279,7 @@
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 c3ec588..ef55c0a 100644
--- a/dm/DMGpuTestProcs.cpp
+++ b/dm/DMGpuTestProcs.cpp
@@ -36,7 +36,7 @@
#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 @@
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 @@
(*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 e0ac272..5c97b6b 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -398,7 +398,7 @@
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 @@
#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 83641cb..012dc61 100644
--- a/tests/GpuDrawPathTest.cpp
+++ b/tests/GpuDrawPathTest.cpp
@@ -91,7 +91,7 @@
}
}
-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 36b5181..e780063 100644
--- a/tests/GpuSampleLocationsTest.cpp
+++ b/tests/GpuSampleLocationsTest.cpp
@@ -184,7 +184,7 @@
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 b8e3db9..dc1025c 100644
--- a/tests/GrCCPRTest.cpp
+++ b/tests/GrCCPRTest.cpp
@@ -124,10 +124,10 @@
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 03e4512..544e121 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 1514d67..29f6836 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_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_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_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_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_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);
-
- std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1);
- contextOptions.fExecutor = threadPool.get();
- GrContextFactory threadedFactory(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);
+
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 6ce0458..ddfcdef 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -1050,8 +1050,8 @@
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 0be0f68..5041dd9 100644
--- a/tests/GrTRecorderTest.cpp
+++ b/tests/GrTRecorderTest.cpp
@@ -283,7 +283,7 @@
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 49ef868..30ae635 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -810,11 +810,10 @@
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 @@
}
}
-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 dbf01ab..8c3ba2a 100644
--- a/tests/PathRendererCacheTests.cpp
+++ b/tests/PathRendererCacheTests.cpp
@@ -109,7 +109,7 @@
}
// 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 @@
}
// 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 863830a..0d97779 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -1596,7 +1596,7 @@
#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 9b3f904..8ae0953 100644
--- a/tests/SurfaceSemaphoreTest.cpp
+++ b/tests/SurfaceSemaphoreTest.cpp
@@ -169,7 +169,7 @@
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 @@
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 @@
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 3e34474..fc47d25 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -89,7 +89,7 @@
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 @@
}
}
- 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 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 @@
} \
} 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 d366bb4..fbec683 100644
--- a/tests/TestTest.cpp
+++ b/tests/TestTest.cpp
@@ -18,11 +18,10 @@
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 6b7df71..8e4cbae 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 @@
class SkTestRunnable {
public:
- SkTestRunnable(const Test& test,
- Status* status,
- GrContextFactory* grContextFactory = nullptr)
- : fTest(test), fStatus(status), fGrContextFactory(grContextFactory) {}
+ 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;
+ 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);
+ 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 @@
}
}
- 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 92d9181..a18c457 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 @@
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 @@
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 @@
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 6324914..cd0d7d3 100644
--- a/tools/gpucts/gm_runner.h
+++ b/tools/gpucts/gm_runner.h
@@ -34,17 +34,7 @@
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 @@
*/
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 d244d91..c50519c 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 @@
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 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 @@
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 @@
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 @@
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 @@
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 7c020d8..2329042 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 @@
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 @@
#endif
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
- Reporter* reporter, sk_gpu_test::GrContextFactory* factory) {
+ Reporter* reporter, const GrContextOptions& options) {
// TODO(bsalomon)
}
}