From 8e9810ce0ff205f921e44e257adadecb7074386a Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Tue, 29 May 2018 13:56:27 -0400 Subject: [fiddle] Init gpu using the GLTestContext. The previous way was failing with SwiftShader. Bug: skia: Change-Id: I6f3937d4d3bc36851476e29be891dc0a38871ef0 Reviewed-on: https://skia-review.googlesource.com/130325 Commit-Queue: Joe Gregorio Reviewed-by: Brian Salomon Reviewed-by: Mike Klein --- tools/fiddle/egl_context.cpp | 76 +++++++++---------------------------------- tools/fiddle/fiddle_main.cpp | 6 ++-- tools/fiddle/fiddle_main.h | 8 ++++- tools/fiddle/null_context.cpp | 3 +- 4 files changed, 27 insertions(+), 66 deletions(-) (limited to 'tools/fiddle') diff --git a/tools/fiddle/egl_context.cpp b/tools/fiddle/egl_context.cpp index 7994b01a67..1dac076b66 100644 --- a/tools/fiddle/egl_context.cpp +++ b/tools/fiddle/egl_context.cpp @@ -9,78 +9,32 @@ #include "SkRefCnt.h" #include "gl/GrGLFunctions.h" #include "gl/GrGLInterface.h" +#include "gl/GLTestContext.h" #include #include #include -static const EGLint configAttribs[] = { - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, - EGL_BLUE_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_RED_SIZE, 8, - EGL_DEPTH_SIZE, 8, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_NONE -}; - -static const int pbufferWidth = 9; -static const int pbufferHeight = 9; - -static const EGLint pbufferAttribs[] = { - EGL_WIDTH, pbufferWidth, - EGL_HEIGHT, pbufferHeight, - EGL_NONE, -}; - // create_grcontext implementation for EGL. -sk_sp create_grcontext(std::ostringstream &driverinfo) { - EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (EGL_NO_DISPLAY == eglDpy) { +sk_sp create_grcontext(std::ostringstream& driverinfo, + std::unique_ptr* glContext) { + // We are leaking tc, but that's OK because fiddle is a short lived proces. + glContext->reset(sk_gpu_test::CreatePlatformGLTestContext(kGLES_GrGLStandard)); + if (!glContext) { return nullptr; } - - EGLint major, minor; - if (EGL_TRUE != eglInitialize(eglDpy, &major, &minor)) { + (*glContext)->makeCurrent(); + sk_sp result = (*glContext)->makeGrContext(GrContextOptions()); + if (!result) { + glContext->reset(); return nullptr; } - EGLint numConfigs; - EGLConfig eglCfg; - if (EGL_TRUE != eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs)) { - return nullptr; - } - - EGLSurface eglSurf = eglCreatePbufferSurface(eglDpy, eglCfg, pbufferAttribs); - if (EGL_NO_SURFACE == eglSurf) { - return nullptr; - } - - if (EGL_TRUE != eglBindAPI(EGL_OPENGL_API)) { - return nullptr; - } - - EGLContext eglCtx = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT, nullptr); - if (EGL_NO_CONTEXT == eglCtx) { - return nullptr; - } - if (EGL_FALSE == eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx)) { - return nullptr; - } - - driverinfo << "EGL " << major << "." << minor << "\n"; - GrGLGetStringProc getString = (GrGLGetStringProc )eglGetProcAddress("glGetString"); - driverinfo << "GL Versionr: " << getString(GL_VERSION) << "\n"; - driverinfo << "GL Vendor: " << getString(GL_VENDOR) << "\n"; - driverinfo << "GL Renderer: " << getString(GL_RENDERER) << "\n"; - driverinfo << "GL Extensions: " << getString(GL_EXTENSIONS) << "\n"; - - auto interface = GrGLMakeNativeInterface(); - if (!interface) { - return nullptr; - } - eglTerminate(eglDpy); + driverinfo << "GL Version: " << glGetString(GL_VERSION) << "\n"; + driverinfo << "GL Vendor: " << glGetString(GL_VENDOR) << "\n"; + driverinfo << "GL Renderer: " << glGetString(GL_RENDERER) << "\n"; + driverinfo << "GL Extensions: " << glGetString(GL_EXTENSIONS) << "\n"; - return sk_sp(GrContext::MakeGL(interface)); + return result; } diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp index 578f7cbf0c..f000025e6a 100644 --- a/tools/fiddle/fiddle_main.cpp +++ b/tools/fiddle/fiddle_main.cpp @@ -23,9 +23,8 @@ DEFINE_double(frame, 1.0, "A double value in [0, 1] that specifies the point in #include "GrBackendSurface.h" #include "GrContextPriv.h" #include "GrGpu.h" - #include "GrTest.h" - +#include "gl/GLTestContext.h" // Globals externed in fiddle_main.h sk_sp backingTexture; // not externed @@ -283,7 +282,8 @@ int main(int argc, char** argv) { rasterData = encode_snapshot(rasterSurface); } if (options.gpu) { - sk_sp grContext = create_grcontext(gGLDriverInfo); + std::unique_ptr glContext; + sk_sp grContext = create_grcontext(gGLDriverInfo, &glContext); if (!grContext) { fputs("Unable to get GrContext.\n", stderr); } else { diff --git a/tools/fiddle/fiddle_main.h b/tools/fiddle/fiddle_main.h index 5492a424ea..ca41998cba 100644 --- a/tools/fiddle/fiddle_main.h +++ b/tools/fiddle/fiddle_main.h @@ -20,6 +20,7 @@ #include "skia.h" #endif +#include #include extern GrBackendTexture backEndTexture; @@ -30,6 +31,10 @@ extern sk_sp image; extern double duration; // The total duration of the animation in seconds. extern double frame; // A value in [0, 1] of where we are in the animation. +namespace sk_gpu_test { +class GLTestContext; +} + struct DrawOptions { DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16, bool textOnly, const char* s, @@ -86,6 +91,7 @@ extern void draw(SkCanvas*); // There are different implementations of create_grcontext() for EGL, Mesa, // and a fallback to a null context. -extern sk_sp create_grcontext(std::ostringstream &driverinfo); +extern sk_sp create_grcontext(std::ostringstream& driverinfo, + std::unique_ptr* glContext); #endif // fiddle_main_DEFINED diff --git a/tools/fiddle/null_context.cpp b/tools/fiddle/null_context.cpp index 3fe0054ecc..903ae10418 100644 --- a/tools/fiddle/null_context.cpp +++ b/tools/fiddle/null_context.cpp @@ -8,7 +8,8 @@ #include "fiddle_main.h" // create_grcontext for when neither Mesa nor EGL are available. -sk_sp create_grcontext(std::ostringstream &driverinfo) { +sk_sp create_grcontext(std::ostringstream& driverinfo, + std::unique_ptr* glContext) { driverinfo << "(no GL driver available)"; return nullptr; } -- cgit v1.2.3