From a8fabd3f28abcca6ddc1a233189bd6deb98510fb Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Wed, 31 May 2017 09:45:19 -0400 Subject: Fiddle can use EGL if available. To test this turn on egl, e.g. --args='skia_use_egl=true', and run by altering the library path to point to the right directory of the EGL driver you want to use, for example: LD_LIBRARY_PATH=/usr/lib/nvidia-367/ ./out/Release/fiddle | ./tools/fiddle/parse-fiddle-output Bug: skia: Change-Id: I2cce80318925fe88f9407646acb67628a8e48810 Reviewed-on: https://skia-review.googlesource.com/18137 Commit-Queue: Joe Gregorio Reviewed-by: Brian Salomon --- tools/fiddle/egl_context.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ tools/fiddle/fiddle_main.cpp | 28 ----------------- tools/fiddle/fiddle_main.h | 4 +++ tools/fiddle/mesa_context.cpp | 32 +++++++++++++++++++ tools/fiddle/null_context.cpp | 13 ++++++++ 5 files changed, 122 insertions(+), 28 deletions(-) create mode 100644 tools/fiddle/egl_context.cpp create mode 100644 tools/fiddle/mesa_context.cpp create mode 100644 tools/fiddle/null_context.cpp (limited to 'tools/fiddle') diff --git a/tools/fiddle/egl_context.cpp b/tools/fiddle/egl_context.cpp new file mode 100644 index 0000000000..cbab44cb37 --- /dev/null +++ b/tools/fiddle/egl_context.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "fiddle_main.h" + +#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() { + EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (EGL_NO_DISPLAY == eglDpy) { + return nullptr; + } + + EGLint major, minor; + if (EGL_TRUE != eglInitialize(eglDpy, &major, &minor)) { + 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, NULL); + if (EGL_NO_CONTEXT == eglCtx) { + return nullptr; + } + if (EGL_FALSE == eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx)) { + return nullptr; + } + + auto interface = GrGLCreateNativeInterface(); + if (!interface) { + return nullptr; + } + eglTerminate(eglDpy); + + return sk_sp(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interface)); +} diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp index 2ce9beb944..a097583b30 100644 --- a/tools/fiddle/fiddle_main.cpp +++ b/tools/fiddle/fiddle_main.cpp @@ -90,34 +90,6 @@ static SkData* encode_snapshot(const sk_sp& surface) { return img ? img->encode() : nullptr; } -#if defined(__linux) && !defined(__ANDROID__) - #include - static sk_sp create_grcontext() { - // We just leak the OSMesaContext... the process will die soon anyway. - if (OSMesaContext osMesaContext = OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr)) { - static uint32_t buffer[16 * 16]; - OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16); - } - - auto osmesa_get = [](void* ctx, const char name[]) { - SkASSERT(nullptr == ctx); - SkASSERT(OSMesaGetCurrentContext()); - return OSMesaGetProcAddress(name); - }; - sk_sp mesa(GrGLAssembleInterface(nullptr, osmesa_get)); - if (!mesa) { - return nullptr; - } - return sk_sp(GrContext::Create( - kOpenGL_GrBackend, - reinterpret_cast(mesa.get()))); - } -#else - static sk_sp create_grcontext() { return nullptr; } -#endif - - - int main(int argc, char** argv) { SkCommandLineFlags::Parse(argc, argv); duration = FLAGS_duration; diff --git a/tools/fiddle/fiddle_main.h b/tools/fiddle/fiddle_main.h index 7be317b8c1..4fadd365fa 100644 --- a/tools/fiddle/fiddle_main.h +++ b/tools/fiddle/fiddle_main.h @@ -55,4 +55,8 @@ extern DrawOptions GetDrawOptions(); extern void SkDebugf(const char * format, ...); 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(); + #endif // fiddle_main_DEFINED diff --git a/tools/fiddle/mesa_context.cpp b/tools/fiddle/mesa_context.cpp new file mode 100644 index 0000000000..70ee62bcc8 --- /dev/null +++ b/tools/fiddle/mesa_context.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "fiddle_main.h" + +#include + +// create_grcontext implementation for Mesa. +sk_sp create_grcontext() { + // We just leak the OSMesaContext... the process will die soon anyway. + if (OSMesaContext osMesaContext = OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr)) { + static uint32_t buffer[16 * 16]; + OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16); + } + + auto osmesa_get = [](void* ctx, const char name[]) { + SkASSERT(nullptr == ctx); + SkASSERT(OSMesaGetCurrentContext()); + return OSMesaGetProcAddress(name); + }; + sk_sp mesa(GrGLAssembleInterface(nullptr, osmesa_get)); + if (!mesa) { + return nullptr; + } + return sk_sp(GrContext::Create( + kOpenGL_GrBackend, + reinterpret_cast(mesa.get()))); +} diff --git a/tools/fiddle/null_context.cpp b/tools/fiddle/null_context.cpp new file mode 100644 index 0000000000..c331e8a98c --- /dev/null +++ b/tools/fiddle/null_context.cpp @@ -0,0 +1,13 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "fiddle_main.h" + +// create_grcontext for when neither Mesa nor EGL are available. +sk_sp create_grcontext() { + return nullptr; +} -- cgit v1.2.3