2016-03-31 01:56:19 +00:00
|
|
|
|
2014-11-13 19:12:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/gl/GLTestContext.h"
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif
|
2014-11-13 19:12:41 +00:00
|
|
|
|
2016-11-14 14:53:13 +00:00
|
|
|
#if SK_ANGLE
|
2020-02-18 19:34:38 +00:00
|
|
|
#include "tools/gpu/gl/angle/GLTestContext_angle.h"
|
2016-11-14 14:53:13 +00:00
|
|
|
#endif
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.h"
|
2016-06-09 20:07:13 +00:00
|
|
|
#ifdef SK_VULKAN
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/vk/VkTestContext.h"
|
2016-04-01 14:42:05 +00:00
|
|
|
#endif
|
2017-07-13 19:07:54 +00:00
|
|
|
#ifdef SK_METAL
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/mtl/MtlTestContext.h"
|
2017-07-13 19:07:54 +00:00
|
|
|
#endif
|
2020-02-18 19:34:38 +00:00
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
#include "tools/gpu/d3d/D3DTestContext.h"
|
|
|
|
#endif
|
2019-07-18 15:43:45 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
#include "tools/gpu/dawn/DawnTestContext.h"
|
|
|
|
#endif
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrCaps.h"
|
|
|
|
#include "tools/gpu/mock/MockTestContext.h"
|
2014-11-13 19:12:41 +00:00
|
|
|
|
2018-01-24 17:42:55 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN) && defined(SK_ENABLE_DISCRETE_GPU)
|
2016-12-28 16:19:22 +00:00
|
|
|
extern "C" {
|
|
|
|
// NVIDIA documents that the presence and value of this symbol programmatically enable the high
|
|
|
|
// performance GPU in laptops with switchable graphics.
|
|
|
|
// https://docs.nvidia.com/gameworks/content/technologies/desktop/optimus.htm
|
|
|
|
// From testing, including this symbol, even if it is set to 0, we still get the NVIDIA GPU.
|
|
|
|
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
|
|
|
|
|
|
|
|
// AMD has a similar mechanism, although I don't have an AMD laptop, so this is untested.
|
|
|
|
// https://community.amd.com/thread/169965
|
|
|
|
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
namespace sk_gpu_test {
|
2016-01-07 07:49:30 +00:00
|
|
|
GrContextFactory::GrContextFactory() { }
|
|
|
|
|
|
|
|
GrContextFactory::GrContextFactory(const GrContextOptions& opts)
|
|
|
|
: fGlobalOptions(opts) {
|
|
|
|
}
|
|
|
|
|
|
|
|
GrContextFactory::~GrContextFactory() {
|
|
|
|
this->destroyContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrContextFactory::destroyContexts() {
|
2018-01-16 16:20:41 +00:00
|
|
|
// We must delete the test contexts in reverse order so that any child context is finished and
|
|
|
|
// deleted before a parent context. This relies on the fact that when we make a new context we
|
|
|
|
// append it to the end of fContexts array.
|
|
|
|
// TODO: Look into keeping a dependency dag for contexts and deletion order
|
|
|
|
for (int i = fContexts.count() - 1; i >= 0; --i) {
|
|
|
|
Context& context = fContexts[i];
|
2017-11-17 14:25:23 +00:00
|
|
|
SkScopeExit restore(nullptr);
|
2016-05-11 17:09:18 +00:00
|
|
|
if (context.fTestContext) {
|
2017-11-17 14:25:23 +00:00
|
|
|
restore = context.fTestContext->makeCurrentAndAutoRestore();
|
2016-01-07 07:49:30 +00:00
|
|
|
}
|
|
|
|
if (!context.fGrContext->unique()) {
|
2016-04-11 21:21:33 +00:00
|
|
|
context.fGrContext->releaseResourcesAndAbandonContext();
|
|
|
|
context.fAbandoned = true;
|
2016-01-07 07:49:30 +00:00
|
|
|
}
|
|
|
|
context.fGrContext->unref();
|
2016-05-11 17:09:18 +00:00
|
|
|
delete context.fTestContext;
|
2016-01-07 07:49:30 +00:00
|
|
|
}
|
|
|
|
fContexts.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrContextFactory::abandonContexts() {
|
2018-01-16 16:20:41 +00:00
|
|
|
// We must abandon the test contexts in reverse order so that any child context is finished and
|
|
|
|
// abandoned before a parent context. This relies on the fact that when we make a new context we
|
|
|
|
// append it to the end of fContexts array.
|
|
|
|
// TODO: Look into keeping a dependency dag for contexts and deletion order
|
|
|
|
for (int i = fContexts.count() - 1; i >= 0; --i) {
|
|
|
|
Context& context = fContexts[i];
|
2016-04-11 21:21:33 +00:00
|
|
|
if (!context.fAbandoned) {
|
2016-05-11 17:09:18 +00:00
|
|
|
if (context.fTestContext) {
|
2017-11-17 14:25:23 +00:00
|
|
|
auto restore = context.fTestContext->makeCurrentAndAutoRestore();
|
2016-05-11 17:09:18 +00:00
|
|
|
context.fTestContext->testAbandon();
|
2019-12-04 20:17:54 +00:00
|
|
|
}
|
2020-06-05 15:42:39 +00:00
|
|
|
GrBackendApi api = context.fGrContext->backend();
|
|
|
|
bool requiresEarlyAbandon = api == GrBackendApi::kVulkan || api == GrBackendApi::kDawn;
|
2019-12-04 20:17:54 +00:00
|
|
|
if (requiresEarlyAbandon) {
|
|
|
|
context.fGrContext->abandonContext();
|
|
|
|
}
|
|
|
|
if (context.fTestContext) {
|
2016-05-11 17:09:18 +00:00
|
|
|
delete(context.fTestContext);
|
|
|
|
context.fTestContext = nullptr;
|
2016-04-11 21:21:33 +00:00
|
|
|
}
|
2019-12-04 20:17:54 +00:00
|
|
|
if (!requiresEarlyAbandon) {
|
|
|
|
context.fGrContext->abandonContext();
|
|
|
|
}
|
2016-04-11 21:21:33 +00:00
|
|
|
context.fAbandoned = true;
|
2016-01-07 07:49:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 18:54:31 +00:00
|
|
|
void GrContextFactory::releaseResourcesAndAbandonContexts() {
|
2018-01-16 16:20:41 +00:00
|
|
|
// We must abandon the test contexts in reverse order so that any child context is finished and
|
|
|
|
// abandoned before a parent context. This relies on the fact that when we make a new context we
|
|
|
|
// append it to the end of fContexts array.
|
|
|
|
// TODO: Look into keeping a dependency dag for contexts and deletion order
|
|
|
|
for (int i = fContexts.count() - 1; i >= 0; --i) {
|
|
|
|
Context& context = fContexts[i];
|
2017-11-17 14:25:23 +00:00
|
|
|
SkScopeExit restore(nullptr);
|
2016-04-11 21:21:33 +00:00
|
|
|
if (!context.fAbandoned) {
|
2016-05-11 17:09:18 +00:00
|
|
|
if (context.fTestContext) {
|
2017-11-17 14:25:23 +00:00
|
|
|
restore = context.fTestContext->makeCurrentAndAutoRestore();
|
2016-04-11 21:21:33 +00:00
|
|
|
}
|
2016-04-01 18:54:31 +00:00
|
|
|
context.fGrContext->releaseResourcesAndAbandonContext();
|
2016-05-11 17:09:18 +00:00
|
|
|
if (context.fTestContext) {
|
|
|
|
delete context.fTestContext;
|
|
|
|
context.fTestContext = nullptr;
|
2016-04-11 21:21:33 +00:00
|
|
|
}
|
2019-12-04 20:17:54 +00:00
|
|
|
context.fAbandoned = true;
|
2016-04-01 18:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
GrDirectContext* GrContextFactory::get(ContextType type, ContextOverrides overrides) {
|
|
|
|
return this->getContextInfo(type, overrides).directContext();
|
2017-06-08 20:03:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 19:51:44 +00:00
|
|
|
ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOverrides overrides,
|
2020-07-01 20:09:43 +00:00
|
|
|
GrDirectContext* shareContext,
|
|
|
|
uint32_t shareIndex) {
|
2017-02-21 21:58:08 +00:00
|
|
|
// (shareIndex != 0) -> (shareContext != nullptr)
|
|
|
|
SkASSERT((shareIndex == 0) || (shareContext != nullptr));
|
|
|
|
|
2014-11-13 19:12:41 +00:00
|
|
|
for (int i = 0; i < fContexts.count(); ++i) {
|
2016-01-07 07:49:30 +00:00
|
|
|
Context& context = fContexts[i];
|
|
|
|
if (context.fType == type &&
|
2017-02-21 19:36:05 +00:00
|
|
|
context.fOverrides == overrides &&
|
2017-02-21 21:58:08 +00:00
|
|
|
context.fShareContext == shareContext &&
|
|
|
|
context.fShareIndex == shareIndex &&
|
2016-04-11 21:21:33 +00:00
|
|
|
!context.fAbandoned) {
|
2016-05-11 17:09:18 +00:00
|
|
|
context.fTestContext->makeCurrent();
|
2017-10-18 12:33:29 +00:00
|
|
|
return ContextInfo(context.fType, context.fTestContext, context.fGrContext,
|
|
|
|
context.fOptions);
|
2014-11-13 19:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-21 21:58:08 +00:00
|
|
|
|
2020-07-30 20:07:01 +00:00
|
|
|
// If we're trying to create a context in a share group, find the primary context
|
|
|
|
Context* primaryContext = nullptr;
|
2017-02-21 21:58:08 +00:00
|
|
|
if (shareContext) {
|
|
|
|
for (int i = 0; i < fContexts.count(); ++i) {
|
|
|
|
if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) {
|
2020-07-30 20:07:01 +00:00
|
|
|
primaryContext = &fContexts[i];
|
2017-02-21 21:58:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 20:07:01 +00:00
|
|
|
SkASSERT(primaryContext && primaryContext->fType == type);
|
2017-02-21 21:58:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<TestContext> testCtx;
|
2018-10-12 13:31:11 +00:00
|
|
|
GrBackendApi backend = ContextTypeBackend(type);
|
2016-04-11 21:21:33 +00:00
|
|
|
switch (backend) {
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2018-10-12 13:31:11 +00:00
|
|
|
case GrBackendApi::kOpenGL: {
|
2020-07-30 20:07:01 +00:00
|
|
|
GLTestContext* glShareContext = primaryContext
|
|
|
|
? static_cast<GLTestContext*>(primaryContext->fTestContext) : nullptr;
|
2016-05-11 17:09:18 +00:00
|
|
|
GLTestContext* glCtx;
|
2016-04-11 21:21:33 +00:00
|
|
|
switch (type) {
|
|
|
|
case kGL_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = CreatePlatformGLTestContext(kGL_GrGLStandard, glShareContext);
|
2016-04-11 21:21:33 +00:00
|
|
|
break;
|
|
|
|
case kGLES_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = CreatePlatformGLTestContext(kGLES_GrGLStandard, glShareContext);
|
2016-04-11 21:21:33 +00:00
|
|
|
break;
|
2016-11-14 14:53:13 +00:00
|
|
|
#if SK_ANGLE
|
2016-10-14 15:13:48 +00:00
|
|
|
case kANGLE_D3D9_ES2_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = MakeANGLETestContext(ANGLEBackend::kD3D9, ANGLEContextVersion::kES2,
|
|
|
|
glShareContext).release();
|
2020-04-17 13:34:17 +00:00
|
|
|
// Chrome will only run on D3D9 with NVIDIA for 2012 and earlier drivers.
|
|
|
|
// (<= 269.73). We get shader link failures when testing on recent drivers
|
|
|
|
// using this backend.
|
|
|
|
if (glCtx) {
|
2021-05-06 19:11:43 +00:00
|
|
|
GrGLDriverInfo info = GrGLGetDriverInfo(glCtx->gl());
|
2021-05-07 17:42:17 +00:00
|
|
|
if (info.fANGLEVendor == GrGLVendor::kNVIDIA) {
|
2020-04-17 13:34:17 +00:00
|
|
|
delete glCtx;
|
|
|
|
return ContextInfo();
|
|
|
|
}
|
|
|
|
}
|
2016-04-11 21:21:33 +00:00
|
|
|
break;
|
2016-10-14 15:13:48 +00:00
|
|
|
case kANGLE_D3D11_ES2_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES2,
|
|
|
|
glShareContext).release();
|
2016-10-14 15:13:48 +00:00
|
|
|
break;
|
|
|
|
case kANGLE_D3D11_ES3_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES3,
|
|
|
|
glShareContext).release();
|
2016-10-14 15:13:48 +00:00
|
|
|
break;
|
|
|
|
case kANGLE_GL_ES2_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES2,
|
|
|
|
glShareContext).release();
|
2016-10-14 15:13:48 +00:00
|
|
|
break;
|
|
|
|
case kANGLE_GL_ES3_ContextType:
|
2017-02-21 21:58:08 +00:00
|
|
|
glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES3,
|
|
|
|
glShareContext).release();
|
2016-04-11 21:21:33 +00:00
|
|
|
break;
|
2016-11-14 14:53:13 +00:00
|
|
|
#endif
|
2017-05-24 19:30:35 +00:00
|
|
|
#ifndef SK_NO_COMMAND_BUFFER
|
2021-06-28 14:43:08 +00:00
|
|
|
case kCommandBuffer_ES2_ContextType:
|
|
|
|
glCtx = CommandBufferGLTestContext::Create(2, glShareContext);
|
|
|
|
break;
|
|
|
|
case kCommandBuffer_ES3_ContextType:
|
|
|
|
glCtx = CommandBufferGLTestContext::Create(3, glShareContext);
|
2016-04-11 21:21:33 +00:00
|
|
|
break;
|
2014-11-13 19:12:41 +00:00
|
|
|
#endif
|
2016-04-11 21:21:33 +00:00
|
|
|
default:
|
|
|
|
return ContextInfo();
|
|
|
|
}
|
2016-05-11 17:09:18 +00:00
|
|
|
if (!glCtx) {
|
2016-04-11 21:21:33 +00:00
|
|
|
return ContextInfo();
|
|
|
|
}
|
2020-08-26 19:27:03 +00:00
|
|
|
if (glCtx->gl()->fStandard == kGLES_GrGLStandard &&
|
|
|
|
(overrides & ContextOverrides::kFakeGLESVersionAs2)) {
|
|
|
|
glCtx->overrideVersion("OpenGL ES 2.0", "OpenGL ES GLSL ES 1.00");
|
|
|
|
}
|
2016-05-11 17:09:18 +00:00
|
|
|
testCtx.reset(glCtx);
|
2014-11-13 19:12:41 +00:00
|
|
|
break;
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif // SK_GL
|
2016-04-11 21:21:33 +00:00
|
|
|
#ifdef SK_VULKAN
|
2018-10-12 13:31:11 +00:00
|
|
|
case GrBackendApi::kVulkan: {
|
2020-07-30 20:07:01 +00:00
|
|
|
VkTestContext* vkSharedContext = primaryContext
|
|
|
|
? static_cast<VkTestContext*>(primaryContext->fTestContext) : nullptr;
|
2016-04-11 21:21:33 +00:00
|
|
|
SkASSERT(kVulkan_ContextType == type);
|
2017-05-15 17:50:35 +00:00
|
|
|
testCtx.reset(CreatePlatformVkTestContext(vkSharedContext));
|
2016-05-11 17:09:18 +00:00
|
|
|
if (!testCtx) {
|
2016-04-11 21:21:33 +00:00
|
|
|
return ContextInfo();
|
|
|
|
}
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
// We previously had an issue where the VkDevice destruction would occasionally hang
|
|
|
|
// on systems with NVIDIA GPUs and having an existing GL context fixed it. Now (March
|
|
|
|
// 2020) we still need the GL context to keep Vulkan/TSAN bots from running incredibly
|
|
|
|
// slow. Perhaps this prevents repeated driver loading/unloading? Note that keeping
|
|
|
|
// a persistent VkTestContext around instead was tried and did not work.
|
2017-01-24 22:22:05 +00:00
|
|
|
if (!fSentinelGLContext) {
|
|
|
|
fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard));
|
|
|
|
if (!fSentinelGLContext) {
|
|
|
|
fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 19:12:41 +00:00
|
|
|
break;
|
2017-05-15 17:50:35 +00:00
|
|
|
}
|
2017-07-13 19:07:54 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SK_METAL
|
2018-10-12 13:31:11 +00:00
|
|
|
case GrBackendApi::kMetal: {
|
2020-07-30 20:07:01 +00:00
|
|
|
MtlTestContext* mtlSharedContext = primaryContext
|
|
|
|
? static_cast<MtlTestContext*>(primaryContext->fTestContext) : nullptr;
|
2019-03-15 19:22:39 +00:00
|
|
|
SkASSERT(kMetal_ContextType == type);
|
|
|
|
testCtx.reset(CreatePlatformMtlTestContext(mtlSharedContext));
|
2017-07-13 19:07:54 +00:00
|
|
|
if (!testCtx) {
|
|
|
|
return ContextInfo();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-07-18 15:43:45 +00:00
|
|
|
#endif
|
2020-02-18 19:34:38 +00:00
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
case GrBackendApi::kDirect3D: {
|
2020-07-30 20:07:01 +00:00
|
|
|
D3DTestContext* d3dSharedContext = primaryContext
|
|
|
|
? static_cast<D3DTestContext*>(primaryContext->fTestContext) : nullptr;
|
2020-02-18 19:34:38 +00:00
|
|
|
SkASSERT(kDirect3D_ContextType == type);
|
|
|
|
testCtx.reset(CreatePlatformD3DTestContext(d3dSharedContext));
|
|
|
|
if (!testCtx) {
|
|
|
|
return ContextInfo();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-18 15:43:45 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
case GrBackendApi::kDawn: {
|
2020-07-30 20:07:01 +00:00
|
|
|
DawnTestContext* dawnSharedContext = primaryContext
|
|
|
|
? static_cast<DawnTestContext*>(primaryContext->fTestContext) : nullptr;
|
2019-07-18 15:43:45 +00:00
|
|
|
testCtx.reset(CreatePlatformDawnTestContext(dawnSharedContext));
|
|
|
|
if (!testCtx) {
|
|
|
|
return ContextInfo();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-04-11 21:21:33 +00:00
|
|
|
#endif
|
2018-10-12 13:31:11 +00:00
|
|
|
case GrBackendApi::kMock: {
|
2020-07-30 20:07:01 +00:00
|
|
|
TestContext* sharedContext = primaryContext ? primaryContext->fTestContext : nullptr;
|
2017-07-06 20:40:18 +00:00
|
|
|
SkASSERT(kMock_ContextType == type);
|
|
|
|
testCtx.reset(CreateMockTestContext(sharedContext));
|
|
|
|
if (!testCtx) {
|
|
|
|
return ContextInfo();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-04-11 21:21:33 +00:00
|
|
|
default:
|
2016-01-07 07:49:30 +00:00
|
|
|
return ContextInfo();
|
2014-11-13 19:12:41 +00:00
|
|
|
}
|
2017-11-17 14:25:23 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
SkASSERT(testCtx && testCtx->backend() == backend);
|
2016-07-29 15:14:20 +00:00
|
|
|
GrContextOptions grOptions = fGlobalOptions;
|
2017-05-08 19:02:07 +00:00
|
|
|
if (ContextOverrides::kAvoidStencilBuffers & overrides) {
|
|
|
|
grOptions.fAvoidStencilBuffers = true;
|
|
|
|
}
|
2021-04-09 15:57:59 +00:00
|
|
|
if (ContextOverrides::kReducedShaders & overrides) {
|
|
|
|
grOptions.fReducedShaderVariations = true;
|
|
|
|
}
|
2020-07-01 20:09:43 +00:00
|
|
|
sk_sp<GrDirectContext> grCtx;
|
2017-11-17 14:25:23 +00:00
|
|
|
{
|
|
|
|
auto restore = testCtx->makeCurrentAndAutoRestore();
|
2020-07-13 20:13:31 +00:00
|
|
|
grCtx = testCtx->makeContext(grOptions);
|
2017-11-17 14:25:23 +00:00
|
|
|
}
|
2020-08-16 12:48:02 +00:00
|
|
|
if (!grCtx) {
|
2016-01-07 07:49:30 +00:00
|
|
|
return ContextInfo();
|
2014-11-13 19:12:41 +00:00
|
|
|
}
|
2015-07-01 09:58:50 +00:00
|
|
|
|
2021-03-11 14:16:25 +00:00
|
|
|
if (shareContext) {
|
|
|
|
SkASSERT(grCtx->directContextID() != shareContext->directContextID());
|
|
|
|
}
|
|
|
|
|
2018-01-16 16:20:41 +00:00
|
|
|
// We must always add new contexts by pushing to the back so that when we delete them we delete
|
|
|
|
// them in reverse order in which they were made.
|
2016-01-07 07:49:30 +00:00
|
|
|
Context& context = fContexts.push_back();
|
2016-05-11 17:09:18 +00:00
|
|
|
context.fBackend = backend;
|
|
|
|
context.fTestContext = testCtx.release();
|
2016-01-07 07:49:30 +00:00
|
|
|
context.fGrContext = SkRef(grCtx.get());
|
|
|
|
context.fType = type;
|
2017-02-21 19:36:05 +00:00
|
|
|
context.fOverrides = overrides;
|
2016-04-11 21:21:33 +00:00
|
|
|
context.fAbandoned = false;
|
2017-02-21 21:58:08 +00:00
|
|
|
context.fShareContext = shareContext;
|
|
|
|
context.fShareIndex = shareIndex;
|
2017-10-18 12:33:29 +00:00
|
|
|
context.fOptions = grOptions;
|
2017-11-17 14:25:23 +00:00
|
|
|
context.fTestContext->makeCurrent();
|
2017-10-18 12:33:29 +00:00
|
|
|
return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions);
|
2014-11-13 19:12:41 +00:00
|
|
|
}
|
2017-02-21 21:58:08 +00:00
|
|
|
|
2017-02-24 19:51:44 +00:00
|
|
|
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) {
|
|
|
|
return this->getContextInfoInternal(type, overrides, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
ContextInfo GrContextFactory::getSharedContextInfo(GrDirectContext* shareContext,
|
|
|
|
uint32_t shareIndex) {
|
2017-02-24 19:51:44 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
} // namespace sk_gpu_test
|