aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Joe Gregorio <jcgregorio@google.com>2017-05-31 09:45:19 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-31 14:23:56 +0000
commita8fabd3f28abcca6ddc1a233189bd6deb98510fb (patch)
treef948d7819658439a4843b362efcf965cb24b1a3a /tools
parent361941eec909934eb960f3f2584946bbee48cde3 (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/fiddle/egl_context.cpp73
-rw-r--r--tools/fiddle/fiddle_main.cpp28
-rw-r--r--tools/fiddle/fiddle_main.h4
-rw-r--r--tools/fiddle/mesa_context.cpp32
-rw-r--r--tools/fiddle/null_context.cpp13
5 files changed, 122 insertions, 28 deletions
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 <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));
+}
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<SkSurface>& surface) {
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) {
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<GrContext> 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 <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())));
+}
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<GrContext> create_grcontext() {
+ return nullptr;
+}