Fixes to shared context test API
Fixes a bug in Windows shared context creation, and makes the API less fiddly. BUG=skia: Change-Id: Ia32b2e3b4816e0b8d7e9be92c22a182ca1393177 Reviewed-on: https://skia-review.googlesource.com/8965 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
a07741a75a
commit
9eac2ea773
@ -98,7 +98,6 @@ DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) {
|
||||
|
||||
DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
|
||||
GrContextFactory testFactory;
|
||||
GrContextFactory::ContextOverrides noOverrides = GrContextFactory::ContextOverrides::kNone;
|
||||
|
||||
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
|
||||
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
|
||||
@ -112,7 +111,7 @@ DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
|
||||
testFactory.abandonContexts();
|
||||
|
||||
// Test that creating a context in a share group with an abandoned context fails.
|
||||
ContextInfo info2 = testFactory.getContextInfo(ctxType, noOverrides, info1.grContext());
|
||||
ContextInfo info2 = testFactory.getSharedContextInfo(info1.grContext());
|
||||
REPORTER_ASSERT(reporter, !info2.grContext());
|
||||
info1.grContext()->unref();
|
||||
|
||||
@ -120,7 +119,7 @@ DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
|
||||
ContextInfo info3 = testFactory.getContextInfo(ctxType);
|
||||
|
||||
// Creating a context in a share group may fail, but should never crash.
|
||||
ContextInfo info4 = testFactory.getContextInfo(ctxType, noOverrides, info3.grContext());
|
||||
ContextInfo info4 = testFactory.getSharedContextInfo(info3.grContext());
|
||||
if (!info4.grContext()) {
|
||||
continue;
|
||||
}
|
||||
@ -128,23 +127,11 @@ DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
|
||||
REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext());
|
||||
|
||||
// Passing a different index should create a new (unique) context.
|
||||
ContextInfo info5 = testFactory.getContextInfo(ctxType, noOverrides, info3.grContext(), 1);
|
||||
ContextInfo info5 = testFactory.getSharedContextInfo(info3.grContext(), 1);
|
||||
REPORTER_ASSERT(reporter, info5.grContext());
|
||||
REPORTER_ASSERT(reporter, info5.testContext());
|
||||
REPORTER_ASSERT(reporter, info5.grContext() != info4.grContext());
|
||||
REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext());
|
||||
|
||||
// Creating a shared context with a different type should always fail.
|
||||
for (int j = 0; j < GrContextFactory::kContextTypeCnt; ++j) {
|
||||
if (i == j) {
|
||||
continue;
|
||||
}
|
||||
GrContextFactory::ContextType differentCtxType =
|
||||
static_cast<GrContextFactory::ContextType>(j);
|
||||
ContextInfo info6 = testFactory.getContextInfo(differentCtxType, noOverrides,
|
||||
info3.grContext());
|
||||
REPORTER_ASSERT(reporter, !info6.grContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,8 +103,8 @@ const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType =
|
||||
GrContextFactory::kGLES_ContextType;
|
||||
#endif
|
||||
|
||||
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides,
|
||||
GrContext* shareContext, uint32_t shareIndex) {
|
||||
ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOverrides overrides,
|
||||
GrContext* shareContext, uint32_t shareIndex) {
|
||||
// (shareIndex != 0) -> (shareContext != nullptr)
|
||||
SkASSERT((shareIndex == 0) || (shareContext != nullptr));
|
||||
|
||||
@ -129,10 +129,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!masterContext || masterContext->fType != type) {
|
||||
return ContextInfo();
|
||||
}
|
||||
SkASSERT(masterContext && masterContext->fType == type);
|
||||
}
|
||||
|
||||
std::unique_ptr<TestContext> testCtx;
|
||||
@ -273,4 +270,20 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides
|
||||
return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext);
|
||||
}
|
||||
|
||||
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) {
|
||||
return this->getContextInfoInternal(type, overrides, nullptr, 0);
|
||||
}
|
||||
|
||||
ContextInfo GrContextFactory::getSharedContextInfo(GrContext* shareContext, uint32_t shareIndex) {
|
||||
SkASSERT(shareContext);
|
||||
for (int i = 0; i < fContexts.count(); ++i) {
|
||||
if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) {
|
||||
return this->getContextInfoInternal(fContexts[i].fType, fContexts[i].fOverrides,
|
||||
shareContext, shareIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return ContextInfo();
|
||||
}
|
||||
|
||||
} // namespace sk_gpu_test
|
||||
|
@ -144,13 +144,17 @@ public:
|
||||
|
||||
/**
|
||||
* Get a context initialized with a type of GL context. It also makes the GL context current.
|
||||
* If shareContextInfo is supplied, then a context is created or returned in the same share
|
||||
* group (able to share resources). To get multiple contexts in a single share group, pass the
|
||||
* same shareContextInfo, with different values for shareIndex.
|
||||
*/
|
||||
ContextInfo getContextInfo(ContextType type,
|
||||
ContextOverrides overrides = ContextOverrides::kNone,
|
||||
GrContext* shareContext = nullptr, uint32_t shareIndex = 0);
|
||||
ContextOverrides overrides = ContextOverrides::kNone);
|
||||
|
||||
/**
|
||||
* Get a context in the same share group as the passed in GrContext, with the same type and
|
||||
* overrides. To get multiple contexts in a single share group, pass the same shareContext,
|
||||
* with different values for shareIndex.
|
||||
*/
|
||||
ContextInfo getSharedContextInfo(GrContext* shareContext, uint32_t shareIndex = 0);
|
||||
|
||||
/**
|
||||
* Get a GrContext initialized with a type of GL context. It also makes the GL context current.
|
||||
*/
|
||||
@ -160,6 +164,9 @@ public:
|
||||
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
|
||||
|
||||
private:
|
||||
ContextInfo getContextInfoInternal(ContextType type, ContextOverrides overrides,
|
||||
GrContext* shareContext, uint32_t shareIndex);
|
||||
|
||||
struct Context {
|
||||
ContextType fType;
|
||||
ContextOverrides fOverrides;
|
||||
|
@ -85,7 +85,11 @@ WinGLTestContext::WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext*
|
||||
kGLES_GrGLStandard == forcedGpuAPI ?
|
||||
kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRequest;
|
||||
|
||||
HGLRC winShareContext = shareContext ? shareContext->fGlRenderContext : nullptr;
|
||||
HGLRC winShareContext = nullptr;
|
||||
if (shareContext) {
|
||||
winShareContext = shareContext->fPbufferContext ? shareContext->fPbufferContext->getGLRC()
|
||||
: shareContext->fGlRenderContext;
|
||||
}
|
||||
fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, 0, contextType, winShareContext);
|
||||
|
||||
HDC dc;
|
||||
|
Loading…
Reference in New Issue
Block a user