aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tests/GrContextFactoryTest.cpp19
-rw-r--r--tools/gpu/GrContextFactory.cpp25
-rw-r--r--tools/gpu/GrContextFactory.h17
-rw-r--r--tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp6
4 files changed, 39 insertions, 28 deletions
diff --git a/tests/GrContextFactoryTest.cpp b/tests/GrContextFactoryTest.cpp
index 8e6a96410d..b0869d91ed 100644
--- a/tests/GrContextFactoryTest.cpp
+++ b/tests/GrContextFactoryTest.cpp
@@ -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());
- }
}
}
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 637c569f89..0c6c87ad6f 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -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
diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h
index e42f34c944..b1a4e1a6b4 100644
--- a/tools/gpu/GrContextFactory.h
+++ b/tools/gpu/GrContextFactory.h
@@ -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;
diff --git a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
index af35b7b6bc..49d774315b 100644
--- a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
+++ b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
@@ -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;