Revert "Add method to sk_gpu_test::TestContext to automatically restore the previous context."

This reverts commit 5627d65146.

Reason for revert: Google3

Original change's description:
> Add method to sk_gpu_test::TestContext to automatically restore the previous context.
> 
> The motivation for this is to allow a GM to create a GL context, do some some work in it, and then return to the context that was set when it was invoked.
> 
> Change-Id: Ie8496072a10f8f3ff36a08889e593a6ca961b61a
> Reviewed-on: https://skia-review.googlesource.com/70720
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

TBR=bsalomon@google.com,brianosman@google.com

Change-Id: Ifb79638c9d4500ca3be9a5be39a5ad78b20247c1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/72981
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-11-16 22:31:30 +00:00 committed by Skia Commit-Bot
parent 8dca18ac7b
commit 1e09e461d2
20 changed files with 56 additions and 268 deletions

View File

@ -272,7 +272,6 @@ skia_core_sources = [
"$_src/core/SkScan_Antihair.cpp", "$_src/core/SkScan_Antihair.cpp",
"$_src/core/SkScan_Hairline.cpp", "$_src/core/SkScan_Hairline.cpp",
"$_src/core/SkScan_Path.cpp", "$_src/core/SkScan_Path.cpp",
"$_src/core/SkScopeExit.h",
"$_src/core/SkSemaphore.cpp", "$_src/core/SkSemaphore.cpp",
"$_src/core/SkSharedMutex.cpp", "$_src/core/SkSharedMutex.cpp",
"$_src/core/SkSharedMutex.h", "$_src/core/SkSharedMutex.h",

View File

@ -46,4 +46,5 @@ skia_pdf_sources = [
"$_src/pdf/SkPDFTypes.h", "$_src/pdf/SkPDFTypes.h",
"$_src/pdf/SkPDFUtils.cpp", "$_src/pdf/SkPDFUtils.cpp",
"$_src/pdf/SkPDFUtils.h", "$_src/pdf/SkPDFUtils.h",
"$_src/pdf/SkScopeExit.h",
] ]

View File

@ -10,30 +10,6 @@
#include "SkTypes.h" #include "SkTypes.h"
/** SkScopeExit calls a std:::function<void()> in its destructor. */
class SkScopeExit {
public:
SkScopeExit(std::function<void()> f) : fFn(std::move(f)) {}
SkScopeExit(SkScopeExit&& that) : fFn(std::move(that.fFn)) {}
~SkScopeExit() {
if (fFn) {
fFn();
}
}
SkScopeExit& operator=(SkScopeExit&& that) {
fFn = std::move(that.fFn);
return *this;
}
private:
std::function<void()> fFn;
SkScopeExit( const SkScopeExit& ) = delete;
SkScopeExit& operator=(const SkScopeExit& ) = delete;
};
/** /**
* SK_AT_SCOPE_EXIT(stmt) evaluates stmt when the current scope ends. * SK_AT_SCOPE_EXIT(stmt) evaluates stmt when the current scope ends.
* *
@ -47,7 +23,28 @@ private:
* SkASSERT(x == 4); * SkASSERT(x == 4);
* } * }
*/ */
template <typename Fn>
class SkScopeExit {
public:
SkScopeExit(Fn f) : fFn(std::move(f)) {}
~SkScopeExit() { fFn(); }
private:
Fn fFn;
SkScopeExit( const SkScopeExit& ) = delete;
SkScopeExit& operator=(const SkScopeExit& ) = delete;
SkScopeExit( SkScopeExit&&) = delete;
SkScopeExit& operator=( SkScopeExit&&) = delete;
};
template <typename Fn>
inline SkScopeExit<Fn> SkMakeScopeExit(Fn&& fn) {
return {std::move(fn)};
}
#define SK_AT_SCOPE_EXIT(stmt) \ #define SK_AT_SCOPE_EXIT(stmt) \
SkScopeExit SK_MACRO_APPEND_LINE(at_scope_exit_)([&]() { stmt; }) SK_UNUSED auto&& SK_MACRO_APPEND_LINE(at_scope_exit_) = \
SkMakeScopeExit([&]() { stmt; });
#endif // SkScopeExit_DEFINED #endif // SkScopeExit_DEFINED

View File

@ -436,10 +436,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn
// Create a texture image. // Create a texture image.
[context] { return create_gpu_image(context); }, [context] { return create_gpu_image(context); },
// Create a texture image in a another GrContext. // Create a texture image in a another GrContext.
[otherContextInfo] { [testContext, otherContextInfo] {
auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore(); otherContextInfo.testContext()->makeCurrent();
sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext()); sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext());
otherContextInfo.grContext()->flush(); testContext->makeCurrent();
return otherContextImage; return otherContextImage;
} }
}; };
@ -487,6 +487,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn
} }
} }
testContext->makeCurrent();
context->flush(); context->flush();
} }
} }
@ -1196,10 +1197,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(makeBackendTexture, reporter, ctxInfo) {
{ create_picture_image, true, false }, { create_picture_image, true, false },
{ [context] { return create_gpu_image(context); }, true, true }, { [context] { return create_gpu_image(context); }, true, true },
// Create a texture image in a another GrContext. // Create a texture image in a another GrContext.
{ [otherContextInfo] { { [testContext, otherContextInfo] {
auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore(); otherContextInfo.testContext()->makeCurrent();
sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext()); sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext());
otherContextInfo.grContext()->flush(); testContext->makeCurrent();
return otherContextImage; return otherContextImage;
}, false, false }, }, false, false },
// Create an image that is too large to be texture backed. // Create an image that is too large to be texture backed.
@ -1231,6 +1232,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(makeBackendTexture, reporter, ctxInfo) {
kExpectedState[testCase.fCanTakeDirectly]); kExpectedState[testCase.fCanTakeDirectly]);
} }
testContext->makeCurrent();
context->flush(); context->flush();
} }
} }

View File

@ -52,9 +52,8 @@ GrContextFactory::~GrContextFactory() {
void GrContextFactory::destroyContexts() { void GrContextFactory::destroyContexts() {
for (Context& context : fContexts) { for (Context& context : fContexts) {
SkScopeExit restore(nullptr);
if (context.fTestContext) { if (context.fTestContext) {
restore = context.fTestContext->makeCurrentAndAutoRestore(); context.fTestContext->makeCurrent();
} }
if (!context.fGrContext->unique()) { if (!context.fGrContext->unique()) {
context.fGrContext->releaseResourcesAndAbandonContext(); context.fGrContext->releaseResourcesAndAbandonContext();
@ -70,7 +69,7 @@ void GrContextFactory::abandonContexts() {
for (Context& context : fContexts) { for (Context& context : fContexts) {
if (!context.fAbandoned) { if (!context.fAbandoned) {
if (context.fTestContext) { if (context.fTestContext) {
auto restore = context.fTestContext->makeCurrentAndAutoRestore(); context.fTestContext->makeCurrent();
context.fTestContext->testAbandon(); context.fTestContext->testAbandon();
delete(context.fTestContext); delete(context.fTestContext);
context.fTestContext = nullptr; context.fTestContext = nullptr;
@ -83,10 +82,9 @@ void GrContextFactory::abandonContexts() {
void GrContextFactory::releaseResourcesAndAbandonContexts() { void GrContextFactory::releaseResourcesAndAbandonContexts() {
for (Context& context : fContexts) { for (Context& context : fContexts) {
SkScopeExit restore(nullptr);
if (!context.fAbandoned) { if (!context.fAbandoned) {
if (context.fTestContext) { if (context.fTestContext) {
restore = context.fTestContext->makeCurrentAndAutoRestore(); context.fTestContext->makeCurrent();
} }
context.fGrContext->releaseResourcesAndAbandonContext(); context.fGrContext->releaseResourcesAndAbandonContext();
context.fAbandoned = true; context.fAbandoned = true;
@ -239,7 +237,7 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
default: default:
return ContextInfo(); return ContextInfo();
} }
testCtx->makeCurrent();
SkASSERT(testCtx && testCtx->backend() == backend); SkASSERT(testCtx && testCtx->backend() == backend);
GrContextOptions grOptions = fGlobalOptions; GrContextOptions grOptions = fGlobalOptions;
if (ContextOverrides::kDisableNVPR & overrides) { if (ContextOverrides::kDisableNVPR & overrides) {
@ -254,11 +252,7 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
if (ContextOverrides::kAvoidStencilBuffers & overrides) { if (ContextOverrides::kAvoidStencilBuffers & overrides) {
grOptions.fAvoidStencilBuffers = true; grOptions.fAvoidStencilBuffers = true;
} }
sk_sp<GrContext> grCtx; sk_sp<GrContext> grCtx = testCtx->makeGrContext(grOptions);
{
auto restore = testCtx->makeCurrentAndAutoRestore();
grCtx = testCtx->makeGrContext(grOptions);
}
if (!grCtx.get()) { if (!grCtx.get()) {
return ContextInfo(); return ContextInfo();
} }
@ -288,7 +282,6 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
context.fShareContext = shareContext; context.fShareContext = shareContext;
context.fShareIndex = shareIndex; context.fShareIndex = shareIndex;
context.fOptions = grOptions; context.fOptions = grOptions;
context.fTestContext->makeCurrent();
return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions); return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions);
} }

View File

@ -37,15 +37,8 @@ sk_sp<GrContext> TestContext::makeGrContext(const GrContextOptions&) {
void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); } void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
SkScopeExit TestContext::makeCurrentAndAutoRestore() const {
auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore());
this->makeCurrent();
return asr;
}
void TestContext::swapBuffers() { this->onPlatformSwapBuffers(); } void TestContext::swapBuffers() { this->onPlatformSwapBuffers(); }
void TestContext::waitOnSyncOrSwap() { void TestContext::waitOnSyncOrSwap() {
if (!fFenceSync) { if (!fFenceSync) {
// Fallback on the platform SwapBuffers method for synchronization. This may have no effect. // Fallback on the platform SwapBuffers method for synchronization. This may have no effect.

View File

@ -9,11 +9,10 @@
#ifndef TestContext_DEFINED #ifndef TestContext_DEFINED
#define TestContext_DEFINED #define TestContext_DEFINED
#include "../private/SkTemplates.h"
#include "FenceSync.h" #include "FenceSync.h"
#include "GrTypes.h" #include "GrTypes.h"
#include "SkRefCnt.h" #include "SkRefCnt.h"
#include "SkScopeExit.h" #include "../private/SkTemplates.h"
class GrContext; class GrContext;
struct GrContextOptions; struct GrContextOptions;
@ -46,18 +45,6 @@ public:
void makeCurrent() const; void makeCurrent() const;
/**
* Like makeCurrent() but this returns an object that will restore the previous current
* context in its destructor. Useful to undo the effect making this current before returning to
* a caller that doesn't expect the current context to be changed underneath it.
*
* The returned object restores the current context of the same type (e.g. egl, glx, ...) in its
* destructor. It is undefined behavior if that context is destroyed before the destructor
* executes. If the concept of a current context doesn't make sense for this context type then
* the returned object's destructor is a no-op.
*/
SkScopeExit SK_WARN_UNUSED_RESULT makeCurrentAndAutoRestore() const;
virtual GrBackend backend() = 0; virtual GrBackend backend() = 0;
virtual GrBackendContext backendContext() = 0; virtual GrBackendContext backendContext() = 0;
@ -107,14 +94,6 @@ protected:
virtual void teardown(); virtual void teardown();
virtual void onPlatformMakeCurrent() const = 0; virtual void onPlatformMakeCurrent() const = 0;
/**
* Subclasses should implement such that the returned function will cause the current context
* of this type to be made current again when it is called. It should additionally be the
* case that if "this" is already current when this is called, then "this" is destroyed (thereby
* setting the null context as current), and then the std::function is called the null context
* should remain current.
*/
virtual std::function<void()> onPlatformGetAutoContextRestore() const = 0;
virtual void onPlatformSwapBuffers() const = 0; virtual void onPlatformSwapBuffers() const = 0;
private: private:

View File

@ -34,16 +34,6 @@ struct Libs {
void* fEGLLib; void* fEGLLib;
}; };
std::function<void()> context_restorer() {
auto display = eglGetCurrentDisplay();
auto dsurface = eglGetCurrentSurface(EGL_DRAW);
auto rsurface = eglGetCurrentSurface(EGL_READ);
auto context = eglGetCurrentContext();
return [display, dsurface, rsurface, context] {
eglMakeCurrent(display, dsurface, rsurface, context);
};
}
static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
const Libs* libs = reinterpret_cast<const Libs*>(ctx); const Libs* libs = reinterpret_cast<const Libs*>(ctx);
GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name); GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name);
@ -97,7 +87,6 @@ private:
void destroyGLContext(); void destroyGLContext();
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override;
@ -225,7 +214,6 @@ ANGLEGLContext::ANGLEGLContext(ANGLEBackend type, ANGLEContextVersion version,
fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs); fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
SkScopeExit restorer(context_restorer());
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Could not set the context."); SkDebugf("Could not set the context.");
this->destroyGLContext(); this->destroyGLContext();
@ -332,10 +320,7 @@ std::unique_ptr<sk_gpu_test::GLTestContext> ANGLEGLContext::makeNew() const {
void ANGLEGLContext::destroyGLContext() { void ANGLEGLContext::destroyGLContext() {
if (EGL_NO_DISPLAY != fDisplay) { if (EGL_NO_DISPLAY != fDisplay) {
if (eglGetCurrentContext() == fContext) { eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
// This will ensure that the context is immediately deleted.
eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
if (EGL_NO_CONTEXT != fContext) { if (EGL_NO_CONTEXT != fContext) {
eglDestroyContext(fDisplay, fContext); eglDestroyContext(fDisplay, fContext);
@ -370,13 +355,6 @@ void ANGLEGLContext::onPlatformMakeCurrent() const {
} }
} }
std::function<void()> ANGLEGLContext::onPlatformGetAutoContextRestore() const {
if (eglGetCurrentContext() == fContext) {
return nullptr;
}
return context_restorer();
}
void ANGLEGLContext::onPlatformSwapBuffers() const { void ANGLEGLContext::onPlatformSwapBuffers() const {
if (!eglSwapBuffers(fDisplay, fSurface)) { if (!eglSwapBuffers(fDisplay, fSurface)) {
SkDebugf("Could not complete eglSwapBuffers.\n"); SkDebugf("Could not complete eglSwapBuffers.\n");

View File

@ -25,7 +25,6 @@ typedef void* EGLNativeDisplayType;
typedef void* EGLNativeWindowType; typedef void* EGLNativeWindowType;
typedef void (*__eglMustCastToProperFunctionPointerType)(void); typedef void (*__eglMustCastToProperFunctionPointerType)(void);
#define EGL_FALSE 0 #define EGL_FALSE 0
#define EGL_TRUE 1
#define EGL_OPENGL_ES2_BIT 0x0004 #define EGL_OPENGL_ES2_BIT 0x0004
#define EGL_CONTEXT_CLIENT_VERSION 0x3098 #define EGL_CONTEXT_CLIENT_VERSION 0x3098
#define EGL_NO_SURFACE ((EGLSurface)0) #define EGL_NO_SURFACE ((EGLSurface)0)
@ -46,8 +45,6 @@ typedef void (*__eglMustCastToProperFunctionPointerType)(void);
#define EGL_NONE 0x3038 #define EGL_NONE 0x3038
#define EGL_WIDTH 0x3057 #define EGL_WIDTH 0x3057
#define EGL_HEIGHT 0x3056 #define EGL_HEIGHT 0x3056
#define EGL_DRAW 0x3059
#define EGL_READ 0x305A
typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id);
typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *minor); typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *minor);
@ -80,37 +77,6 @@ static GetProcAddressProc gfGetProcAddress = nullptr;
static void* gLibrary = nullptr; static void* gLibrary = nullptr;
static bool gfFunctionsLoadedSuccessfully = false; static bool gfFunctionsLoadedSuccessfully = false;
// The command buffer does not correctly implement eglGetCurrent. It always returns EGL_NO_<foo>.
// So we implement them ourselves and hook eglMakeCurrent to store the current values in TLS.
thread_local EGLDisplay gCurrDisplay = EGL_NO_DISPLAY;
thread_local EGLSurface gCurrReadSurface = EGL_NO_SURFACE;
thread_local EGLSurface gCurrDrawSurface = EGL_NO_SURFACE;
thread_local EGLContext gCurrContext = EGL_NO_CONTEXT;
EGLDisplay fakeGetCurrentDisplay() { return gCurrDisplay; }
EGLSurface fakeGetCurrentSurface(EGLint readdraw) {
switch (readdraw) {
case EGL_DRAW:
return gCurrDrawSurface;
case EGL_READ:
return gCurrReadSurface;
default:
return EGL_NO_SURFACE;
}
}
EGLContext fakeGetCurrentContext() { return gCurrContext; }
EGLBoolean hookedMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext ctx) {
if (gfFunctionsLoadedSuccessfully && EGL_TRUE == gfMakeCurrent(display, draw, read, ctx)) {
gCurrDisplay = display;
gCurrDrawSurface = draw;
gCurrReadSurface = read;
gCurrContext = ctx;
return EGL_TRUE;
}
return EGL_FALSE;
}
namespace { namespace {
static void load_command_buffer_functions() { static void load_command_buffer_functions() {
if (!gLibrary) { if (!gLibrary) {
@ -138,11 +104,12 @@ static void load_command_buffer_functions() {
gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglSwapBuffers"); gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglSwapBuffers");
gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary, "eglGetProcAddress"); gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary, "eglGetProcAddress");
gfFunctionsLoadedSuccessfully = gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTerminate &&
gfGetDisplay && gfInitialize && gfTerminate && gfChooseConfig && gfChooseConfig && gfCreateWindowSurface &&
gfCreateWindowSurface && gfCreatePbufferSurface && gfDestroySurface && gfCreatePbufferSurface && gfDestroySurface &&
gfCreateContext && gfDestroyContext && gfMakeCurrent && gfSwapBuffers && gfCreateContext && gfDestroyContext && gfMakeCurrent &&
gfGetProcAddress; gfSwapBuffers && gfGetProcAddress;
} }
} }
} }
@ -167,19 +134,6 @@ static const GrGLInterface* create_command_buffer_interface() {
return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc);
} }
std::function<void()> context_restorer() {
if (!gfFunctionsLoadedSuccessfully) {
return nullptr;
}
auto display = fakeGetCurrentDisplay();
auto dsurface = fakeGetCurrentSurface(EGL_DRAW);
auto rsurface = fakeGetCurrentSurface(EGL_READ);
auto context = fakeGetCurrentContext();
return [display, dsurface, rsurface, context] {
hookedMakeCurrent(display, dsurface, rsurface, context);
};
}
} // anonymous namespace } // anonymous namespace
namespace sk_gpu_test { namespace sk_gpu_test {
@ -250,8 +204,7 @@ CommandBufferGLTestContext::CommandBufferGLTestContext(CommandBufferGLTestContex
return; return;
} }
SkScopeExit restorer(context_restorer()); if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
if (!hookedMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Command Buffer: Could not make EGL context current.\n"); SkDebugf("Command Buffer: Could not make EGL context current.\n");
this->destroyGLContext(); this->destroyGLContext();
return; return;
@ -284,19 +237,15 @@ void CommandBufferGLTestContext::destroyGLContext() {
if (EGL_NO_DISPLAY == fDisplay) { if (EGL_NO_DISPLAY == fDisplay) {
return; return;
} }
bool wasCurrent = false;
if (EGL_NO_CONTEXT != fContext) { if (EGL_NO_CONTEXT != fContext) {
wasCurrent = fakeGetCurrentContext() == fContext;
gfDestroyContext(fDisplay, fContext); gfDestroyContext(fDisplay, fContext);
fContext = EGL_NO_CONTEXT; fContext = EGL_NO_CONTEXT;
} }
if (wasCurrent) { // Call MakeCurrent after destroying the context, so that the EGL implementation knows that
// Call MakeCurrent after destroying the context, so that the EGL implementation knows that // the context is not used anymore after it is released from being current. This way
// the context is not used anymore after it is released from being current.This way the // command buffer does not need to abandon the context before destruction, and no
// command buffer does not need to abandon the context before destruction, and no // client-side errors are printed.
// client-side errors are printed. gfMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
hookedMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
if (EGL_NO_SURFACE != fSurface) { if (EGL_NO_SURFACE != fSurface) {
gfDestroySurface(fDisplay, fSurface); gfDestroySurface(fDisplay, fSurface);
@ -309,18 +258,11 @@ void CommandBufferGLTestContext::onPlatformMakeCurrent() const {
if (!gfFunctionsLoadedSuccessfully) { if (!gfFunctionsLoadedSuccessfully) {
return; return;
} }
if (!hookedMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Command Buffer: Could not make EGL context current.\n"); SkDebugf("Command Buffer: Could not make EGL context current.\n");
} }
} }
std::function<void()> CommandBufferGLTestContext::onPlatformGetAutoContextRestore() const {
if (!gfFunctionsLoadedSuccessfully || fakeGetCurrentContext() == fContext) {
return nullptr;
}
return context_restorer();
}
void CommandBufferGLTestContext::onPlatformSwapBuffers() const { void CommandBufferGLTestContext::onPlatformSwapBuffers() const {
if (!gfFunctionsLoadedSuccessfully) { if (!gfFunctionsLoadedSuccessfully) {
return; return;
@ -346,7 +288,7 @@ void CommandBufferGLTestContext::presentCommandBuffer() {
} }
bool CommandBufferGLTestContext::makeCurrent() { bool CommandBufferGLTestContext::makeCurrent() {
return hookedMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE;
} }
int CommandBufferGLTestContext::getStencilBits() { int CommandBufferGLTestContext::getStencilBits() {

View File

@ -42,8 +42,6 @@ private:
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char *name) const override; GrGLFuncPtr onPlatformGetProcAddress(const char *name) const override;

View File

@ -1203,7 +1203,6 @@ public:
private: private:
void onPlatformMakeCurrent() const override {} void onPlatformMakeCurrent() const override {}
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
void onPlatformSwapBuffers() const override {} void onPlatformSwapBuffers() const override {}
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; }
}; };

View File

@ -39,16 +39,6 @@ private:
typedef sk_gpu_test::FenceSync INHERITED; typedef sk_gpu_test::FenceSync INHERITED;
}; };
std::function<void()> context_restorer() {
auto display = eglGetCurrentDisplay();
auto dsurface = eglGetCurrentSurface(EGL_DRAW);
auto rsurface = eglGetCurrentSurface(EGL_READ);
auto context = eglGetCurrentContext();
return [display, dsurface, rsurface, context] {
eglMakeCurrent(display, dsurface, rsurface, context);
};
}
class EGLGLTestContext : public sk_gpu_test::GLTestContext { class EGLGLTestContext : public sk_gpu_test::GLTestContext {
public: public:
EGLGLTestContext(GrGLStandard forcedGpuAPI, EGLGLTestContext* shareContext); EGLGLTestContext(GrGLStandard forcedGpuAPI, EGLGLTestContext* shareContext);
@ -63,7 +53,6 @@ private:
void destroyGLContext(); void destroyGLContext();
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
@ -179,7 +168,6 @@ EGLGLTestContext::EGLGLTestContext(GrGLStandard forcedGpuAPI, EGLGLTestContext*
continue; continue;
} }
SkScopeExit restorer(context_restorer());
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError()); SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError());
this->destroyGLContext(); this->destroyGLContext();
@ -211,11 +199,9 @@ EGLGLTestContext::~EGLGLTestContext() {
void EGLGLTestContext::destroyGLContext() { void EGLGLTestContext::destroyGLContext() {
if (fDisplay) { if (fDisplay) {
eglMakeCurrent(fDisplay, 0, 0, 0);
if (fContext) { if (fContext) {
if (eglGetCurrentContext() == fContext) {
// This will ensure that the context is immediately deleted.
eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
eglDestroyContext(fDisplay, fContext); eglDestroyContext(fDisplay, fContext);
fContext = EGL_NO_CONTEXT; fContext = EGL_NO_CONTEXT;
} }
@ -298,13 +284,6 @@ void EGLGLTestContext::onPlatformMakeCurrent() const {
} }
} }
std::function<void()> EGLGLTestContext::onPlatformGetAutoContextRestore() const {
if (eglGetCurrentContext() == fContext) {
return nullptr;
}
return context_restorer();
}
void EGLGLTestContext::onPlatformSwapBuffers() const { void EGLGLTestContext::onPlatformSwapBuffers() const {
if (!eglSwapBuffers(fDisplay, fSurface)) { if (!eglSwapBuffers(fDisplay, fSurface)) {
SkDebugf("Could not complete eglSwapBuffers.\n"); SkDebugf("Could not complete eglSwapBuffers.\n");

View File

@ -51,13 +51,6 @@ static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
return 0; return 0;
} }
std::function<void()> context_restorer() {
auto display = glXGetCurrentDisplay();
auto drawable = glXGetCurrentDrawable();
auto context = glXGetCurrentContext();
return [display, drawable, context] { glXMakeCurrent(display, drawable, context); };
}
class GLXGLTestContext : public sk_gpu_test::GLTestContext { class GLXGLTestContext : public sk_gpu_test::GLTestContext {
public: public:
GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* shareList); GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* shareList);
@ -69,7 +62,6 @@ private:
GLXContext glxSharedContext); GLXContext glxSharedContext);
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
@ -222,7 +214,6 @@ GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext*
//SkDebugf("Direct GLX rendering context obtained.\n"); //SkDebugf("Direct GLX rendering context obtained.\n");
} }
SkScopeExit restorer(context_restorer());
//SkDebugf("Making context current.\n"); //SkDebugf("Making context current.\n");
if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
SkDebugf("Could not set the context.\n"); SkDebugf("Could not set the context.\n");
@ -254,11 +245,9 @@ GLXGLTestContext::~GLXGLTestContext() {
void GLXGLTestContext::destroyGLContext() { void GLXGLTestContext::destroyGLContext() {
if (fDisplay) { if (fDisplay) {
glXMakeCurrent(fDisplay, 0, 0);
if (fContext) { if (fContext) {
if (glXGetCurrentContext() == fContext) {
// This will ensure that the context is immediately deleted.
glXMakeContextCurrent(fDisplay, None, None, nullptr);
}
glXDestroyContext(fDisplay, fContext); glXDestroyContext(fDisplay, fContext);
fContext = nullptr; fContext = nullptr;
} }
@ -345,13 +334,6 @@ void GLXGLTestContext::onPlatformMakeCurrent() const {
} }
} }
std::function<void()> GLXGLTestContext::onPlatformGetAutoContextRestore() const {
if (glXGetCurrentContext() == fContext) {
return nullptr;
}
return context_restorer();
}
void GLXGLTestContext::onPlatformSwapBuffers() const { void GLXGLTestContext::onPlatformSwapBuffers() const {
glXSwapBuffers(fDisplay, fGlxPixmap); glXSwapBuffers(fDisplay, fGlxPixmap);
} }

View File

@ -14,11 +14,6 @@
namespace { namespace {
std::function<void()> context_restorer() {
EAGLContext* context = [EAGLContext currentContext];
return [context] { [EAGLContext setCurrentContext:context]; };
}
class IOSGLTestContext : public sk_gpu_test::GLTestContext { class IOSGLTestContext : public sk_gpu_test::GLTestContext {
public: public:
IOSGLTestContext(IOSGLTestContext* shareContext); IOSGLTestContext(IOSGLTestContext* shareContext);
@ -28,7 +23,6 @@ private:
void destroyGLContext(); void destroyGLContext();
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
@ -47,7 +41,6 @@ IOSGLTestContext::IOSGLTestContext(IOSGLTestContext* shareContext)
} else { } else {
fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
} }
SkScopeExit restorer(context_restorer());
[EAGLContext setCurrentContext:fEAGLContext]; [EAGLContext setCurrentContext:fEAGLContext];
sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface()); sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
@ -77,7 +70,6 @@ IOSGLTestContext::~IOSGLTestContext() {
void IOSGLTestContext::destroyGLContext() { void IOSGLTestContext::destroyGLContext() {
if (fEAGLContext) { if (fEAGLContext) {
if ([EAGLContext currentContext] == fEAGLContext) { if ([EAGLContext currentContext] == fEAGLContext) {
// This will ensure that the context is immediately deleted.
[EAGLContext setCurrentContext:nil]; [EAGLContext setCurrentContext:nil];
} }
fEAGLContext = nil; fEAGLContext = nil;
@ -94,13 +86,6 @@ void IOSGLTestContext::onPlatformMakeCurrent() const {
} }
} }
std::function<void()> IOSGLTestContext::onPlatformGetAutoContextRestore() const {
if ([EAGLContext currentContext] == fEAGLContext) {
return nullptr;
}
return context_restorer();
}
void IOSGLTestContext::onPlatformSwapBuffers() const { } void IOSGLTestContext::onPlatformSwapBuffers() const { }
GrGLFuncPtr IOSGLTestContext::onPlatformGetProcAddress(const char* procName) const { GrGLFuncPtr IOSGLTestContext::onPlatformGetProcAddress(const char* procName) const {

View File

@ -14,12 +14,6 @@
#include <dlfcn.h> #include <dlfcn.h>
namespace { namespace {
std::function<void()> context_restorer() {
auto context = CGLGetCurrentContext();
return [context] { CGLSetCurrentContext(context); };
}
class MacGLTestContext : public sk_gpu_test::GLTestContext { class MacGLTestContext : public sk_gpu_test::GLTestContext {
public: public:
MacGLTestContext(MacGLTestContext* shareContext); MacGLTestContext(MacGLTestContext* shareContext);
@ -29,7 +23,6 @@ private:
void destroyGLContext(); void destroyGLContext();
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
@ -65,7 +58,6 @@ MacGLTestContext::MacGLTestContext(MacGLTestContext* shareContext)
return; return;
} }
SkScopeExit restorer(context_restorer());
CGLSetCurrentContext(fContext); CGLSetCurrentContext(fContext);
sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface()); sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
@ -94,10 +86,6 @@ MacGLTestContext::~MacGLTestContext() {
void MacGLTestContext::destroyGLContext() { void MacGLTestContext::destroyGLContext() {
if (fContext) { if (fContext) {
if (CGLGetCurrentContext() == fContext) {
// This will ensure that the context is immediately deleted.
CGLSetCurrentContext(nullptr);
}
CGLReleaseContext(fContext); CGLReleaseContext(fContext);
fContext = nullptr; fContext = nullptr;
} }
@ -110,13 +98,6 @@ void MacGLTestContext::onPlatformMakeCurrent() const {
CGLSetCurrentContext(fContext); CGLSetCurrentContext(fContext);
} }
std::function<void()> MacGLTestContext::onPlatformGetAutoContextRestore() const {
if (CGLGetCurrentContext() == fContext) {
return nullptr;
}
return context_restorer();
}
void MacGLTestContext::onPlatformSwapBuffers() const { void MacGLTestContext::onPlatformSwapBuffers() const {
CGLFlushDrawable(fContext); CGLFlushDrawable(fContext);
} }

View File

@ -22,7 +22,6 @@ public:
private: private:
void onPlatformMakeCurrent() const override {} void onPlatformMakeCurrent() const override {}
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
void onPlatformSwapBuffers() const override {} void onPlatformSwapBuffers() const override {}
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; }
}; };

View File

@ -16,12 +16,6 @@
namespace { namespace {
std::function<void()> context_restorer() {
auto glrc = wglGetCurrentContext();
auto dc = wglGetCurrentDC();
return [glrc, dc] { wglMakeCurrent(dc, glrc); };
}
class WinGLTestContext : public sk_gpu_test::GLTestContext { class WinGLTestContext : public sk_gpu_test::GLTestContext {
public: public:
WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext* shareContext); WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext* shareContext);
@ -31,7 +25,6 @@ private:
void destroyGLContext(); void destroyGLContext();
void onPlatformMakeCurrent() const override; void onPlatformMakeCurrent() const override;
std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override; void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override;
@ -120,7 +113,6 @@ WinGLTestContext::WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext*
glrc = fPbufferContext->getGLRC(); glrc = fPbufferContext->getGLRC();
} }
SkScopeExit restorer(context_restorer());
if (!(wglMakeCurrent(dc, glrc))) { if (!(wglMakeCurrent(dc, glrc))) {
SkDebugf("Could not set the context.\n"); SkDebugf("Could not set the context.\n");
this->destroyGLContext(); this->destroyGLContext();
@ -150,7 +142,6 @@ WinGLTestContext::~WinGLTestContext() {
void WinGLTestContext::destroyGLContext() { void WinGLTestContext::destroyGLContext() {
SkSafeSetNull(fPbufferContext); SkSafeSetNull(fPbufferContext);
if (fGlRenderContext) { if (fGlRenderContext) {
// This deletes the context immediately even if it is current.
wglDeleteContext(fGlRenderContext); wglDeleteContext(fGlRenderContext);
fGlRenderContext = 0; fGlRenderContext = 0;
} }
@ -181,13 +172,6 @@ void WinGLTestContext::onPlatformMakeCurrent() const {
} }
} }
std::function<void()> WinGLTestContext::onPlatformGetAutoContextRestore() const {
if (wglGetCurrentContext() == fGlRenderContext) {
return nullptr;
}
return context_restorer();
}
void WinGLTestContext::onPlatformSwapBuffers() const { void WinGLTestContext::onPlatformSwapBuffers() const {
HDC dc; HDC dc;

View File

@ -34,7 +34,6 @@ public:
protected: protected:
void teardown() override {} void teardown() override {}
void onPlatformMakeCurrent() const override {} void onPlatformMakeCurrent() const override {}
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
void onPlatformSwapBuffers() const override {} void onPlatformSwapBuffers() const override {}
private: private:

View File

@ -144,7 +144,6 @@ private:
} }
void onPlatformMakeCurrent() const override {} void onPlatformMakeCurrent() const override {}
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
void onPlatformSwapBuffers() const override {} void onPlatformSwapBuffers() const override {}
id<MTLDevice> fDevice; id<MTLDevice> fDevice;

View File

@ -154,7 +154,6 @@ private:
} }
void onPlatformMakeCurrent() const override {} void onPlatformMakeCurrent() const override {}
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
void onPlatformSwapBuffers() const override {} void onPlatformSwapBuffers() const override {}
typedef sk_gpu_test::VkTestContext INHERITED; typedef sk_gpu_test::VkTestContext INHERITED;