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>
This commit is contained in:
parent
20800c8b1b
commit
dcfca431e3
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
|
||||
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()) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
39
tests/Test.h
39
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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) {}
|
||||
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 @@ 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.
|
||||
|
@ -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"; }
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user