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 <jcgregorio@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Joe Gregorio 2017-05-31 09:45:19 -04:00 committed by Skia Commit-Bot
parent 361941eec9
commit a8fabd3f28
6 changed files with 133 additions and 32 deletions

View File

@ -760,14 +760,21 @@ if (skia_enable_tools) {
# TODO: worth fixing? # TODO: worth fixing?
executable("fiddle") { executable("fiddle") {
libs = [] libs = []
if (is_linux) {
libs += [ "OSMesa" ]
}
sources = [ sources = [
"tools/fiddle/draw.cpp", "tools/fiddle/draw.cpp",
"tools/fiddle/fiddle_main.cpp", "tools/fiddle/fiddle_main.cpp",
] ]
if (skia_use_egl) {
sources += [ "tools/fiddle/egl_context.cpp" ]
} else if (skia_use_mesa) {
sources += [ "tools/fiddle/mesa_context.cpp" ]
if (is_linux) {
libs += [ "OSMesa" ]
}
} else {
sources += [ "tools/fiddle/null_context.cpp" ]
}
testonly = true testonly = true
deps = [ deps = [
":flags", ":flags",

View File

@ -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 <EGL/egl.h>
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<GrContext> 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>(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interface));
}

View File

@ -90,34 +90,6 @@ static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) {
return img ? img->encode() : nullptr; return img ? img->encode() : nullptr;
} }
#if defined(__linux) && !defined(__ANDROID__)
#include <GL/osmesa.h>
static sk_sp<GrContext> 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<const GrGLInterface> mesa(GrGLAssembleInterface(nullptr, osmesa_get));
if (!mesa) {
return nullptr;
}
return sk_sp<GrContext>(GrContext::Create(
kOpenGL_GrBackend,
reinterpret_cast<intptr_t>(mesa.get())));
}
#else
static sk_sp<GrContext> create_grcontext() { return nullptr; }
#endif
int main(int argc, char** argv) { int main(int argc, char** argv) {
SkCommandLineFlags::Parse(argc, argv); SkCommandLineFlags::Parse(argc, argv);
duration = FLAGS_duration; duration = FLAGS_duration;

View File

@ -55,4 +55,8 @@ extern DrawOptions GetDrawOptions();
extern void SkDebugf(const char * format, ...); extern void SkDebugf(const char * format, ...);
extern void draw(SkCanvas*); extern void draw(SkCanvas*);
// There are different implementations of create_grcontext() for EGL, Mesa,
// and a fallback to a null context.
extern sk_sp<GrContext> create_grcontext();
#endif // fiddle_main_DEFINED #endif // fiddle_main_DEFINED

View File

@ -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 <GL/osmesa.h>
// create_grcontext implementation for Mesa.
sk_sp<GrContext> 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<const GrGLInterface> mesa(GrGLAssembleInterface(nullptr, osmesa_get));
if (!mesa) {
return nullptr;
}
return sk_sp<GrContext>(GrContext::Create(
kOpenGL_GrBackend,
reinterpret_cast<intptr_t>(mesa.get())));
}

View File

@ -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<GrContext> create_grcontext() {
return nullptr;
}