[waffle] [PATCH 6/8] android: plug memory leak in droid_window_create()

2016-04-05 Thread Emil Velikov
Prior to last few commits, leaking self might have been required. With
droid_create_surface() in proper shape we can correctly tear it down.

This effectively reverts commit 0009b5d0d2f "android: Improve name of
'error' goto label" with the commit message of which sharing no
information why this is needed.

Cc: Arun Sl 
Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_window.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/waffle/android/droid_window.c 
b/src/waffle/android/droid_window.c
index 048a2bb..dcfd31b 100644
--- a/src/waffle/android/droid_window.c
+++ b/src/waffle/android/droid_window.c
@@ -66,7 +66,7 @@ droid_window_create(struct wcore_platform *wc_plat,
 self->pANWContainer = droid_create_surface(width, height,
dpy->pSFContainer);
 if (!self->pANWContainer)
-goto error_droid_create_surface;
+goto error;
 
 ok = wegl_window_init(&self->wegl, wc_config,
   (intptr_t) *((intptr_t*)(self->pANWContainer)));
@@ -77,7 +77,6 @@ droid_window_create(struct wcore_platform *wc_plat,
 
 error:
 droid_window_destroy(&self->wegl.wcore);
-error_droid_create_surface:
 return NULL;
 }
 
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 7/8] android: teardown things in the correct order

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/waffle/android/droid_display.c 
b/src/waffle/android/droid_display.c
index 3f39739..6e66d17 100644
--- a/src/waffle/android/droid_display.c
+++ b/src/waffle/android/droid_display.c
@@ -72,10 +72,10 @@ droid_display_disconnect(struct wcore_display *wc_self)
 if (!self)
 return true;
 
+ok &= wegl_display_teardown(&self->wegl);
 if (self->pSFContainer)
 droid_deinit_gl(self->pSFContainer);
 
-ok &= wegl_display_teardown(&self->wegl);
 free(self);
 return ok;
 }
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 8/8] android: coding style fixes

2016-04-05 Thread Emil Velikov
Follow waffle's coding style by re-indent and adding space between the
type and *.

Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_display.c  |  2 +-
 src/waffle/android/droid_platform.c | 12 +++---
 src/waffle/android/droid_surfaceflingerlink.cpp | 55 ++---
 src/waffle/android/droid_surfaceflingerlink.h   | 26 +---
 4 files changed, 38 insertions(+), 57 deletions(-)

diff --git a/src/waffle/android/droid_display.c 
b/src/waffle/android/droid_display.c
index 6e66d17..306b5f7 100644
--- a/src/waffle/android/droid_display.c
+++ b/src/waffle/android/droid_display.c
@@ -35,7 +35,7 @@
 
 struct wcore_display*
 droid_display_connect(struct wcore_platform *wc_plat,
-const char *name)
+  const char *name)
 {
 bool ok = true;
 struct droid_display *self;
diff --git a/src/waffle/android/droid_platform.c 
b/src/waffle/android/droid_platform.c
index bbf2b14..bf5f34f 100644
--- a/src/waffle/android/droid_platform.c
+++ b/src/waffle/android/droid_platform.c
@@ -84,19 +84,17 @@ error:
 }
 
 static bool
-droid_dl_can_open(
-struct wcore_platform *wc_self,
-int32_t waffle_dl)
+droid_dl_can_open(struct wcore_platform *wc_self,
+  int32_t waffle_dl)
 {
 return linux_platform_dl_can_open(droid_platform(wc_self)->linux,
   waffle_dl);
 }
 
 static void*
-droid_dl_sym(
-struct wcore_platform *wc_self,
-int32_t waffle_dl,
-const char *name)
+droid_dl_sym(struct wcore_platform *wc_self,
+ int32_t waffle_dl,
+ const char *name)
 {
 return linux_platform_dl_sym(droid_platform(wc_self)->linux,
  waffle_dl, name);
diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp 
b/src/waffle/android/droid_surfaceflingerlink.cpp
index c3e2fc8..d8422a1 100644
--- a/src/waffle/android/droid_surfaceflingerlink.cpp
+++ b/src/waffle/android/droid_surfaceflingerlink.cpp
@@ -50,7 +50,7 @@ struct droid_surfaceflinger_container {
 
 struct droid_ANativeWindow_container {
 // it is important ANativeWindow* is the first element in this structure
-ANativeWindow* native_window;
+ANativeWindow *native_window;
 sp surface_control;
 sp window;
 };
@@ -61,7 +61,7 @@ const int32_t  droid_magic_surface_z = 0x7FFF;
 
 static void
 droid_tear_down_surfaceflinger_link(
-waffle::droid_surfaceflinger_container* pSFContainer)
+waffle::droid_surfaceflinger_container *pSFContainer)
 {
 delete pSFContainer->composer_client;
 delete pSFContainer;
@@ -70,9 +70,9 @@ droid_tear_down_surfaceflinger_link(
 static droid_surfaceflinger_container*
 droid_setup_surfaceflinger_link()
 {
-bool bRVal;
+droid_surfaceflinger_container *pSFContainer;
 EGLint iRVal;
-droid_surfaceflinger_container* pSFContainer;
+bool bRVal;
 
 pSFContainer = new droid_surfaceflinger_container;
 pSFContainer->composer_client = new SurfaceComposerClient;
@@ -90,9 +90,8 @@ error:
 }
 
 static void
-droid_destroy_surface(
-droid_surfaceflinger_container* pSFContainer,
-droid_ANativeWindow_container* pANWContainer)
+droid_destroy_surface(droid_surfaceflinger_container *pSFContainer,
+  droid_ANativeWindow_container *pANWContainer)
 {
 delete pANWContainer->window;
 pSFContainer->composer_client->openGlobalTransaction();
@@ -104,15 +103,12 @@ droid_destroy_surface(
 }
 
 static droid_ANativeWindow_container*
-droid_setup_surface(
-int width,
-int height,
-droid_surfaceflinger_container* pSFContainer)
+droid_setup_surface(int width, int height,
+droid_surfaceflinger_container *pSFContainer)
 {
-bool bRVal;
+droid_ANativeWindow_container *pANWContainer;
 EGLint iRVal;
-
-droid_ANativeWindow_container* pANWContainer;
+bool bRVal;
 
 pANWContainer = new droid_ANativeWindow_container;
 
@@ -179,9 +175,8 @@ error:
 }
 
 static bool
-droid_show_surface(
-droid_surfaceflinger_container* pSFContainer,
-droid_ANativeWindow_container* pANWContainer)
+droid_show_surface(droid_surfaceflinger_container *pSFContainer,
+   droid_ANativeWindow_container *pANWContainer)
 {
 int iRVal;
 
@@ -198,11 +193,9 @@ droid_show_surface(
 }
 
 static bool
-droid_resize_surface(
-droid_surfaceflinger_container* pSFContainer,
-droid_ANativeWindow_container* pANWContainer,
-int width,
-int height)
+droid_resize_surface(droid_surfaceflinger_container *pSFContainer,
+ droid_ANativeWindow_container* pANWContainer,
+ int width, int height)
 {
 int iRVal;
 
@@ -249,9 +242,8 @@ droid_create_surface(
 }
 
 extern "C" bool
-droid_show_surface(
-droid_surfaceflinger_container* pSFContainer,
-droid_ANativeWindow_container* pANWContainer)
+droid_show_surface(droid_surfaceflinger_container *pSFContainer,
+

[waffle] [PATCH 5/8] android: straighten droid_setup_surface error paths

2016-04-05 Thread Emil Velikov
Similar to previous commit drop the unneeded NULL check (left over from
commit c42522c76a94e82907b218c7670c89a8f92f952c (Android: Fix surface
setup segfault) and teardown things in the inverse order of creating
them (by using droid_destroy_surface).

Add a comment about the seemingly strange clear() in
droid_destroy_surface(), and don't forget to teardown the actual surface
object.

XXX: the comment does not cover the question if we should still delete
the object.

Cc: Juha-Pekka Heikkila 
Cc: Chad Versace 
Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_surfaceflingerlink.cpp | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp 
b/src/waffle/android/droid_surfaceflingerlink.cpp
index e8c31ab..c3e2fc8 100644
--- a/src/waffle/android/droid_surfaceflingerlink.cpp
+++ b/src/waffle/android/droid_surfaceflingerlink.cpp
@@ -94,7 +94,10 @@ droid_destroy_surface(
 droid_surfaceflinger_container* pSFContainer,
 droid_ANativeWindow_container* pANWContainer)
 {
+delete pANWContainer->window;
 pSFContainer->composer_client->openGlobalTransaction();
+// Admire the lengthy comment in the implementation of clear() why we
+// need it over the normal dtor.
 pANWContainer->surface_control->clear();
 pSFContainer->composer_client->closeGlobalTransaction();
 delete pANWContainer;
@@ -113,9 +116,6 @@ droid_setup_surface(
 
 pANWContainer = new droid_ANativeWindow_container;
 
-if (pANWContainer == NULL)
-goto error;
-
 // The signature of SurfaceComposerClient::createSurface() differs across
 // Android versions.
 #if WAFFLE_ANDROID_MAJOR_VERSION == 4 &&\
@@ -137,7 +137,6 @@ droid_setup_surface(
 if (pANWContainer->surface_control == NULL) {
 wcore_errorf(WAFFLE_ERROR_UNKNOWN,
  "Unable to get android::SurfaceControl");
-delete pANWContainer;
 goto error;
 }
 
@@ -145,21 +144,19 @@ droid_setup_surface(
 if (bRVal != true) {
 wcore_errorf(WAFFLE_ERROR_UNKNOWN,
  "Acquired android::SurfaceControl is invalid");
-delete pANWContainer;
 goto error;
 }
 
 pSFContainer->composer_client->openGlobalTransaction();
 iRVal = pANWContainer->surface_control->setLayer(droid_magic_surface_z);
+pSFContainer->composer_client->closeGlobalTransaction();
+
 if (iRVal != NO_ERROR) {
 wcore_errorf(WAFFLE_ERROR_UNKNOWN,
  "Error in android::SurfaceControl->setLayer");
-delete pANWContainer;
-goto error_closeTransaction;
+goto error;
 }
 
-pSFContainer->composer_client->closeGlobalTransaction();
-
 pANWContainer->window = pANWContainer->surface_control->getSurface();
 
 pSFContainer->composer_client->openGlobalTransaction();
@@ -169,7 +166,6 @@ droid_setup_surface(
 if (iRVal != NO_ERROR) {
 wcore_errorf(WAFFLE_ERROR_UNKNOWN,
  "error in android::SurfaceControl->setSize");
-delete pANWContainer;
 goto error;
 }
 
@@ -177,11 +173,8 @@ droid_setup_surface(
 
 return pANWContainer;
 
-error_closeTransaction:
-pSFContainer->composer_client->closeGlobalTransaction();
-
 error:
-droid_tear_down_surfaceflinger_link(pSFContainer);
+droid_destroy_surface(pSFContainer, pANWContainer)
 return NULL;
 }
 
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 3/8] android: annotate static functions as such

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_surfaceflingerlink.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp 
b/src/waffle/android/droid_surfaceflingerlink.cpp
index a0251c1..9930e47 100644
--- a/src/waffle/android/droid_surfaceflingerlink.cpp
+++ b/src/waffle/android/droid_surfaceflingerlink.cpp
@@ -59,7 +59,7 @@ const uint32_t droid_magic_surface_width = 32;
 const uint32_t droid_magic_surface_height = 32;
 const int32_t  droid_magic_surface_z = 0x7FFF;
 
-void
+static void
 droid_tear_down_surfaceflinger_link(
 waffle::droid_surfaceflinger_container* pSFContainer)
 {
@@ -74,7 +74,7 @@ droid_tear_down_surfaceflinger_link(
 delete pSFContainer;
 }
 
-droid_surfaceflinger_container*
+static droid_surfaceflinger_container*
 droid_setup_surfaceflinger_link()
 {
 bool bRVal;
@@ -100,7 +100,7 @@ error:
 return NULL;
 }
 
-void
+static void
 droid_destroy_surface(
 droid_surfaceflinger_container* pSFContainer,
 droid_ANativeWindow_container* pANWContainer)
@@ -111,7 +111,7 @@ droid_destroy_surface(
 delete pANWContainer;
 }
 
-droid_ANativeWindow_container*
+static droid_ANativeWindow_container*
 droid_setup_surface(
 int width,
 int height,
@@ -196,7 +196,7 @@ error:
 return NULL;
 }
 
-bool
+static bool
 droid_show_surface(
 droid_surfaceflinger_container* pSFContainer,
 droid_ANativeWindow_container* pANWContainer)
@@ -215,7 +215,7 @@ droid_show_surface(
 return true;
 }
 
-bool
+static bool
 droid_resize_surface(
 droid_surfaceflinger_container* pSFContainer,
 droid_ANativeWindow_container* pANWContainer,
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 4/8] android: cleanup surfaceflinger_link management

2016-04-05 Thread Emil Velikov
If the C++ runtime fails to create the relevant object(s) an exception
will be raised, thus the NULL checks will never get hit.

While we're here replace the opencoded SurfaceComposerClient dtor with
the proper one.

Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_surfaceflingerlink.cpp | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp 
b/src/waffle/android/droid_surfaceflingerlink.cpp
index 9930e47..e8c31ab 100644
--- a/src/waffle/android/droid_surfaceflingerlink.cpp
+++ b/src/waffle/android/droid_surfaceflingerlink.cpp
@@ -63,14 +63,7 @@ static void
 droid_tear_down_surfaceflinger_link(
 waffle::droid_surfaceflinger_container* pSFContainer)
 {
-if( pSFContainer == NULL)
-return;
-
-if (pSFContainer->composer_client != NULL) {
-pSFContainer->composer_client->dispose();
-pSFContainer->composer_client = NULL;
-}
-
+delete pSFContainer->composer_client;
 delete pSFContainer;
 }
 
@@ -82,10 +75,6 @@ droid_setup_surfaceflinger_link()
 droid_surfaceflinger_container* pSFContainer;
 
 pSFContainer = new droid_surfaceflinger_container;
-
-if (pSFContainer == NULL)
-goto error;
-
 pSFContainer->composer_client = new SurfaceComposerClient;
 iRVal = pSFContainer->composer_client->initCheck();
 if (iRVal != NO_ERROR) {
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 2/8] android: move droid_destroy_surface() further up the file

2016-04-05 Thread Emil Velikov
Analogous to previous commit, minus the case where the setup (wrongly)
open-codes it.

Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_surfaceflingerlink.cpp | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp 
b/src/waffle/android/droid_surfaceflingerlink.cpp
index 75803f3..a0251c1 100644
--- a/src/waffle/android/droid_surfaceflingerlink.cpp
+++ b/src/waffle/android/droid_surfaceflingerlink.cpp
@@ -100,6 +100,17 @@ error:
 return NULL;
 }
 
+void
+droid_destroy_surface(
+droid_surfaceflinger_container* pSFContainer,
+droid_ANativeWindow_container* pANWContainer)
+{
+pSFContainer->composer_client->openGlobalTransaction();
+pANWContainer->surface_control->clear();
+pSFContainer->composer_client->closeGlobalTransaction();
+delete pANWContainer;
+}
+
 droid_ANativeWindow_container*
 droid_setup_surface(
 int width,
@@ -225,17 +236,6 @@ droid_resize_surface(
 return true;
 }
 
-void
-droid_destroy_surface(
-droid_surfaceflinger_container* pSFContainer,
-droid_ANativeWindow_container* pANWContainer)
-{
-pSFContainer->composer_client->openGlobalTransaction();
-pANWContainer->surface_control->clear();
-pSFContainer->composer_client->closeGlobalTransaction();
-delete pANWContainer;
-}
-
 }; // namespace waffle
 
 extern "C" struct droid_surfaceflinger_container*
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [RFC PATCH 0/8] Android: plus memory leaks

2016-04-05 Thread Emil Velikov
Hi all,

Some ~3 month old patches that I had lying around. As they are untested, 
and likely wrong to a degree, I'm sending them as RFC.

Key note here is that we're dealing with smart pointers and my C++ in 
this area isn't exactly stellar. Any input as to why some (or even all) 
of the proposed changes are wrong is greatly appreciated.

Thanks
Emil

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 1/8] android: avoid unneeded (function) forward declaration

2016-04-05 Thread Emil Velikov
There is no specific reason why we cannot move the teardown function
prior to the setup one. Most (rest of) waffle does so already.

Signed-off-by: Emil Velikov 
---
 src/waffle/android/droid_surfaceflingerlink.cpp | 32 +++--
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp 
b/src/waffle/android/droid_surfaceflingerlink.cpp
index dc55a8a..75803f3 100644
--- a/src/waffle/android/droid_surfaceflingerlink.cpp
+++ b/src/waffle/android/droid_surfaceflingerlink.cpp
@@ -59,8 +59,20 @@ const uint32_t droid_magic_surface_width = 32;
 const uint32_t droid_magic_surface_height = 32;
 const int32_t  droid_magic_surface_z = 0x7FFF;
 
-void droid_tear_down_surfaceflinger_link(
-droid_surfaceflinger_container* pSFContainer);
+void
+droid_tear_down_surfaceflinger_link(
+waffle::droid_surfaceflinger_container* pSFContainer)
+{
+if( pSFContainer == NULL)
+return;
+
+if (pSFContainer->composer_client != NULL) {
+pSFContainer->composer_client->dispose();
+pSFContainer->composer_client = NULL;
+}
+
+delete pSFContainer;
+}
 
 droid_surfaceflinger_container*
 droid_setup_surfaceflinger_link()
@@ -224,22 +236,6 @@ droid_destroy_surface(
 delete pANWContainer;
 }
 
-
-void
-droid_tear_down_surfaceflinger_link(
-waffle::droid_surfaceflinger_container* pSFContainer)
-{
-if( pSFContainer == NULL)
-return;
-
-if (pSFContainer->composer_client != NULL) {
-pSFContainer->composer_client->dispose();
-pSFContainer->composer_client = NULL;
-}
-
-delete pSFContainer;
-}
-
 }; // namespace waffle
 
 extern "C" struct droid_surfaceflinger_container*
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 07/13] wegl: untangle dl_can_open() and support_api()

2016-04-05 Thread Emil Velikov
Calling dl_can_open() to determine whether the API is supported is
confusing and somewhat incorrect.

Instead, determine the supported APIs based on the string provided by
eglQueryString(EGL_CLIENT_APIS) and cross that with the minimum EGL
requirement (for eglBindAPI) for each one.

Note: we're added a minimum requirement of EGL 1.2 as things will
explode badly with versions prior to it.

v2: Completely reword commit message, finish implementation.

Signed-off-by: Emil Velikov 
---
 src/waffle/egl/wegl_config.c  | 37 ++---
 src/waffle/egl/wegl_display.c | 63 ++-
 src/waffle/egl/wegl_display.h |  2 ++
 3 files changed, 48 insertions(+), 54 deletions(-)

diff --git a/src/waffle/egl/wegl_config.c b/src/waffle/egl/wegl_config.c
index a79bc53..ef35b45 100644
--- a/src/waffle/egl/wegl_config.c
+++ b/src/waffle/egl/wegl_config.c
@@ -41,8 +41,6 @@ static bool
 check_context_attrs(struct wegl_display *dpy,
 const struct wcore_config_attrs *attrs)
 {
-struct wcore_platform *plat = dpy->wcore.platform;
-
 if (attrs->context_forward_compatible) {
 assert(attrs->context_api == WAFFLE_CONTEXT_OPENGL);
 assert(wcore_config_attrs_version_ge(attrs, 30));
@@ -57,6 +55,14 @@ check_context_attrs(struct wegl_display *dpy,
 
 switch (attrs->context_api) {
 case WAFFLE_CONTEXT_OPENGL:
+if (!dpy->supports_opengl) {
+wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
+ "EGL 1.4 of later and 
eglQueryString(EGL_CLIENT_APIS) "
+ "== OpenGL are required in order to request an 
OpenGL "
+ "context.");
+return false;
+}
+
 if (!wcore_config_attrs_version_eq(attrs, 10) && 
!dpy->KHR_create_context) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "KHR_EXT_create_context is required in order to "
@@ -77,32 +83,11 @@ check_context_attrs(struct wegl_display *dpy,
 return false;
 }
 
-if (!plat->vtbl->dl_can_open(plat, WAFFLE_DL_OPENGL)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL library");
-return false;
-}
-
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES1:
-if (!plat->vtbl->dl_can_open(plat, WAFFLE_DL_OPENGL_ES1)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL ES1 library");
-return false;
-}
-
-return true;
-
 case WAFFLE_CONTEXT_OPENGL_ES2:
-if (!plat->vtbl->dl_can_open(plat, WAFFLE_DL_OPENGL_ES2)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL ES2 library");
-return false;
-}
-
 return true;
-
 case WAFFLE_CONTEXT_OPENGL_ES3:
 if (!dpy->KHR_create_context) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
@@ -111,12 +96,6 @@ check_context_attrs(struct wegl_display *dpy,
 return false;
 }
 
-if (!plat->vtbl->dl_can_open(plat, WAFFLE_DL_OPENGL_ES3)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL ES3 library");
-return false;
-}
-
 return true;
 
 default:
diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c
index b3d0d88..c9368fc 100644
--- a/src/waffle/egl/wegl_display.c
+++ b/src/waffle/egl/wegl_display.c
@@ -24,6 +24,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include 
+#include 
 
 #include "wcore_error.h"
 #include "wcore_platform.h"
@@ -34,22 +35,46 @@
 #include "wegl_platform.h"
 
 static bool
-get_extensions(struct wegl_display *dpy)
+parse_version_extensions(struct wegl_display *dpy, EGLint major, EGLint minor)
 {
 struct wegl_platform *plat = wegl_platform(dpy->wcore.platform);
-const char *extensions = plat->eglQueryString(dpy->egl, EGL_EXTENSIONS);
+const char *apis = plat->eglQueryString(dpy->egl, EGL_CLIENT_APIS);
+const char *extensions;
 
-if (!extensions) {
-wegl_emit_error(plat, "eglQueryString(EGL_EXTENSIONS)");
+// Our minimum requirement - EGL 1.2 ...
+if (major != 1 || minor < 2) {
+wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
+ "EGL 1.2 or later is required");
 return false;
 }
 
-// waffle_is_extension_in_string() resets the error state. That's ok,
-// however, because if we've reached this point then no error should be
-// pending emission.
-assert(wcore_error_get_code() == 0);
+// ... plus working egl

[waffle] [PATCH 08/13] glx: remove dl_can_open() logic from supports_api()

2016-04-05 Thread Emil Velikov
As mentioned earlier with similar EGL commit - one should two to keep
the two separate.

Signed-off-by: Emil Velikov 
---
 src/waffle/glx/glx_config.c | 22 +-
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c
index 58d241e..fc88a7a 100644
--- a/src/waffle/glx/glx_config.c
+++ b/src/waffle/glx/glx_config.c
@@ -54,8 +54,6 @@ static bool
 glx_config_check_context_attrs(struct glx_display *dpy,
const struct wcore_config_attrs *attrs)
 {
-struct glx_platform *plat = glx_platform(dpy->wcore.platform);
-
 if (attrs->context_forward_compatible) {
 assert(attrs->context_api == WAFFLE_CONTEXT_OPENGL);
 assert(wcore_config_attrs_version_ge(attrs, 30));
@@ -104,12 +102,6 @@ glx_config_check_context_attrs(struct glx_display *dpy,
  "to create an OpenGL ES1 context");
 return false;
 }
-else if (!linux_platform_dl_can_open(plat->linux,
-WAFFLE_DL_OPENGL_ES1)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL ES1 library");
-return false;
-}
 
 return true;
 
@@ -122,12 +114,7 @@ glx_config_check_context_attrs(struct glx_display *dpy,
  "to create an OpenGL ES2 context");
 return false;
 }
-if (!linux_platform_dl_can_open(plat->linux,
-WAFFLE_DL_OPENGL_ES2)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL ES2 library");
-return false;
-}
+
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES3:
@@ -138,13 +125,6 @@ glx_config_check_context_attrs(struct glx_display *dpy,
 return false;
 }
 
-if (!linux_platform_dl_can_open(plat->linux,
-WAFFLE_DL_OPENGL_ES3)) {
-wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
- "failed to open the OpenGL ES3 library");
-return false;
-}
-
 return true;
 
 default:
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 06/13] wegl: add closing bracket in error message

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/egl/wegl_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c
index 88fce7a..b3d0d88 100644
--- a/src/waffle/egl/wegl_display.c
+++ b/src/waffle/egl/wegl_display.c
@@ -40,7 +40,7 @@ get_extensions(struct wegl_display *dpy)
 const char *extensions = plat->eglQueryString(dpy->egl, EGL_EXTENSIONS);
 
 if (!extensions) {
-wegl_emit_error(plat, "eglQueryString(EGL_EXTENSIONS");
+wegl_emit_error(plat, "eglQueryString(EGL_EXTENSIONS)");
 return false;
 }
 
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 02/13] wgl: indent with spaces, not tabs

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/wgl/wgl_config.h   | 2 +-
 src/waffle/wgl/wgl_context.h  | 2 +-
 src/waffle/wgl/wgl_display.h  | 2 +-
 src/waffle/wgl/wgl_platform.h | 2 +-
 src/waffle/wgl/wgl_window.h   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/waffle/wgl/wgl_config.h b/src/waffle/wgl/wgl_config.h
index 77f8905..58b352e 100644
--- a/src/waffle/wgl/wgl_config.h
+++ b/src/waffle/wgl/wgl_config.h
@@ -49,7 +49,7 @@ struct wgl_config {
 static inline struct wgl_config*
 wgl_config(struct wcore_config *wcore)
 {
-   return (struct wgl_config *)wcore;
+return (struct wgl_config *)wcore;
 }
 
 struct wcore_config*
diff --git a/src/waffle/wgl/wgl_context.h b/src/waffle/wgl/wgl_context.h
index c55ad58..72fd08b 100644
--- a/src/waffle/wgl/wgl_context.h
+++ b/src/waffle/wgl/wgl_context.h
@@ -41,7 +41,7 @@ struct wgl_context {
 static inline struct wgl_context*
 wgl_context(struct wcore_context *wcore)
 {
-   return (struct wgl_context *)wcore;
+return (struct wgl_context *)wcore;
 }
 
 struct wcore_context*
diff --git a/src/waffle/wgl/wgl_display.h b/src/waffle/wgl/wgl_display.h
index d0d94fe..cf05486 100644
--- a/src/waffle/wgl/wgl_display.h
+++ b/src/waffle/wgl/wgl_display.h
@@ -66,7 +66,7 @@ struct wgl_display {
 static inline struct wgl_display*
 wgl_display(struct wcore_display *wcore)
 {
-   return (struct wgl_display*)wcore;
+return (struct wgl_display*)wcore;
 }
 
 struct wcore_display*
diff --git a/src/waffle/wgl/wgl_platform.h b/src/waffle/wgl/wgl_platform.h
index a25d2f4..f514bad 100644
--- a/src/waffle/wgl/wgl_platform.h
+++ b/src/waffle/wgl/wgl_platform.h
@@ -46,7 +46,7 @@ struct wgl_platform {
 static inline struct wgl_platform*
 wgl_platform(struct wcore_platform *wcore)
 {
-   return (struct wgl_platform*)wcore;
+return (struct wgl_platform*)wcore;
 }
 
 struct wcore_platform*
diff --git a/src/waffle/wgl/wgl_window.h b/src/waffle/wgl/wgl_window.h
index 9b11509..43bea24 100644
--- a/src/waffle/wgl/wgl_window.h
+++ b/src/waffle/wgl/wgl_window.h
@@ -42,7 +42,7 @@ struct wgl_window {
 static inline struct wgl_window*
 wgl_window(struct wcore_window *wcore)
 {
-   return (struct wgl_window*)wcore;
+return (struct wgl_window*)wcore;
 }
 
 struct wcore_window*
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 13/13] linux: return NULL for libGL.so on Android

2016-04-05 Thread Emil Velikov
Unlikely that we'll ever hit it, but it brings consistency with the remainder 
of the function.

Signed-off-by: Emil Velikov 
---
 src/waffle/linux/linux_dl.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/waffle/linux/linux_dl.c b/src/waffle/linux/linux_dl.c
index 0858ef3..ea4aaa1 100644
--- a/src/waffle/linux/linux_dl.c
+++ b/src/waffle/linux/linux_dl.c
@@ -49,7 +49,11 @@ linux_dl_get_name(int32_t waffle_dl)
 {
 switch (waffle_dl) {
 case WAFFLE_DL_OPENGL:
+#ifdef WAFFLE_HAS_ANDROID
+return NULL;
+#else
 return "libGL.so.1";
+#endif
 case WAFFLE_DL_OPENGL_ES1:
 #ifdef WAFFLE_HAS_ANDROID
 return "libGLESv1_CM.so";
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 00/13] Do less validation of the context version

2016-04-05 Thread Emil Velikov
Hi all,

This is a re-spin of an ancient RFC [1] covering two (core) topics
 - Should waffle do fine grained checking of the context version prior 
to feeding it to the driver ? Leaning towards no.
 - Should we rely upon the library (libGL/libGLESv1/libGLESv2) presence 
to determine if context of respective API is supported ? Same sentiment.

And last but not least I've thrown out a bunch of the 
wcore_error_internal() in favour of assert. Core already handles all of
those 'default' cases, thus we can simplify things ;-)

The series can be found in branch for-upstream/context-cleanups-et-al

Comments and suggestion are appreciated.
Emil

[1] https://lists.freedesktop.org/archives/waffle/2015-November/001269.html

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 11/13] linux: replace wcore_error_internal with assert

2016-04-05 Thread Emil Velikov
Analogous to the earlier change - the WAFFLE_DL is checked before we
get here.

Signed-off-by: Emil Velikov 
---
 src/waffle/linux/linux_dl.c   | 3 ++-
 src/waffle/linux/linux_platform.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/waffle/linux/linux_dl.c b/src/waffle/linux/linux_dl.c
index 33eb69d..0858ef3 100644
--- a/src/waffle/linux/linux_dl.c
+++ b/src/waffle/linux/linux_dl.c
@@ -23,6 +23,7 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#include 
 #include 
 #include 
 
@@ -69,7 +70,7 @@ linux_dl_get_name(int32_t waffle_dl)
 return "libGLESv2.so.2";
 #endif
 default:
-wcore_error_internal("waffle_dl has bad value %#x", waffle_dl);
+assert(false);
 return NULL;
 }
 }
diff --git a/src/waffle/linux/linux_platform.c 
b/src/waffle/linux/linux_platform.c
index 56f6fe6..92c36c1 100644
--- a/src/waffle/linux/linux_platform.c
+++ b/src/waffle/linux/linux_platform.c
@@ -23,6 +23,7 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#include 
 #include 
 
 #include "wcore_error.h"
@@ -73,7 +74,7 @@ linux_platform_get_dl(
 case WAFFLE_DL_OPENGL_ES2: dl = &self->libgles2; break;
 case WAFFLE_DL_OPENGL_ES3: dl = &self->libgles2; break;
 default:
-wcore_error_internal("waffle_dl has bad value %#x", waffle_dl);
+assert(false);
 return NULL;
 }
 
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 01/13] wgl: remove unneeded asserts

2016-04-05 Thread Emil Velikov
fwd_compat is already handled at the top of the function, while
version checks will become invalid with a later patch.

Signed-off-by: Emil Velikov 
---
 src/waffle/wgl/wgl_config.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/src/waffle/wgl/wgl_config.c b/src/waffle/wgl/wgl_config.c
index 59a70a6..a21ba71 100644
--- a/src/waffle/wgl/wgl_config.c
+++ b/src/waffle/wgl/wgl_config.c
@@ -101,10 +101,6 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES1:
-assert(wcore_config_attrs_version_eq(attrs, 10) ||
-   wcore_config_attrs_version_eq(attrs, 11));
-assert(!attrs->context_forward_compatible);
-
 if (!dpy->EXT_create_context_es_profile) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "WGL_EXT_create_context_es_profile is required "
@@ -115,9 +111,6 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES2:
-assert(attrs->context_major_version == 2);
-assert(!attrs->context_forward_compatible);
-
 if (!dpy->EXT_create_context_es2_profile
 && !dpy->EXT_create_context_es_profile) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
@@ -130,8 +123,6 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES3:
-assert(attrs->context_major_version == 3);
-
 if (!dpy->EXT_create_context_es_profile) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "WGL_EXT_create_context_es_profile is required "
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 04/13] wcore: don't parse/validate the exact major/minor version

2016-04-05 Thread Emil Velikov
Keeping track what is and isn't the correct version at any given time
sounds unfeasible.

On one hand currently we allow any random value as minor for ES2 and
ES3, whist for GL we allow any values as long as they are >= 1.0

If we are to keep track what versions are valid, this is going to cause
problems as new versions of the specs get released.

Let's do the sane thing and remove all the fine-grained validation from
waffle.

v2 (Suggestions from Chad):
 - Keep < 1.0 check to prevent WAFFLE_DONT_CARE as context version.
 - Update the unit tests alongside this intended functionality change.

Signed-off-by: Emil Velikov 
---
 src/waffle/core/wcore_config_attrs.c  | 45 ---
 src/waffle/core/wcore_config_attrs_unittest.c | 64 ---
 2 files changed, 109 deletions(-)

diff --git a/src/waffle/core/wcore_config_attrs.c 
b/src/waffle/core/wcore_config_attrs.c
index 4a2cb5d..bb38fed 100644
--- a/src/waffle/core/wcore_config_attrs.c
+++ b/src/waffle/core/wcore_config_attrs.c
@@ -179,51 +179,6 @@ parse_context_version(struct wcore_config_attrs *attrs,
  "WAFFLE_CONTEXT_MINOR_VERSION must be >= 0");
 return false;
 }
-
-switch (attrs->context_api) {
-case WAFFLE_CONTEXT_OPENGL:
-if (wcore_config_attrs_version_lt(attrs, 10)) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- "for OpenGL, the requested context version "
- "must be >= 1.0");
-return false;
-}
-break;
-
-case WAFFLE_CONTEXT_OPENGL_ES1:
-if (!wcore_config_attrs_version_eq(attrs, 10) &&
-!wcore_config_attrs_version_eq(attrs, 11)) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- "for OpenGL ES1, the requested context version "
- "must be 1.0 or 1.1");
-return false;
-}
-break;
-
-case WAFFLE_CONTEXT_OPENGL_ES2:
-if (attrs->context_major_version != 2) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- "for OpenGL ES2, the requested major context "
- "version must be 2");
-return false;
-}
-break;
-
-case WAFFLE_CONTEXT_OPENGL_ES3:
-if (attrs->context_major_version != 3) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- "for OpenGL ES3, the requested major context "
- "version must be 3");
-return false;
-}
-break;
-
-default:
-wcore_error_internal("attrs->context_api has bad value 0x%x",
- attrs->context_api);
-return false;
-}
-
 return true;
 }
 
diff --git a/src/waffle/core/wcore_config_attrs_unittest.c 
b/src/waffle/core/wcore_config_attrs_unittest.c
index 501e30f..cd745d1 100644
--- a/src/waffle/core/wcore_config_attrs_unittest.c
+++ b/src/waffle/core/wcore_config_attrs_unittest.c
@@ -445,21 +445,6 @@ test_wcore_config_attrs_gles11(void **state) {
 }
 
 static void
-test_wcore_config_attrs_gles12_is_bad(void **state) {
-struct test_state_wcore_config_attrs *ts = *state;
-
-const int32_t attrib_list[] = {
-WAFFLE_CONTEXT_API, WAFFLE_CONTEXT_OPENGL_ES1,
-WAFFLE_CONTEXT_MAJOR_VERSION,   1,
-WAFFLE_CONTEXT_MINOR_VERSION,   2,
-0,
-};
-
-assert_false(wcore_config_attrs_parse(attrib_list, &ts->actual_attrs));
-assert_int_equal(wcore_error_get_code(), WAFFLE_ERROR_BAD_ATTRIBUTE);
-}
-
-static void
 test_wcore_config_attrs_gles20(void **state) {
 struct test_state_wcore_config_attrs *ts = *state;
 
@@ -492,21 +477,6 @@ test_wcore_config_attrs_gles21(void **state) {
 }
 
 static void
-test_wcore_config_attrs_gles2_with_version_30(void **state) {
-struct test_state_wcore_config_attrs *ts = *state;
-
-const int32_t attrib_list[] = {
-WAFFLE_CONTEXT_API, WAFFLE_CONTEXT_OPENGL_ES2,
-WAFFLE_CONTEXT_MAJOR_VERSION,   3,
-WAFFLE_CONTEXT_MINOR_VERSION,   0,
-0,
-};
-
-assert_false(wcore_config_attrs_parse(attrib_list, &ts->actual_attrs));
-assert_int_equal(wcore_error_get_code(), WAFFLE_ERROR_BAD_ATTRIBUTE);
-}
-
-static void
 test_wcore_config_attrs_gles30(void **state) {
 struct test_state_wcore_config_attrs *ts = *state;
 
@@ -539,36 +509,6 @@ test_wcore_config_attrs_gles31(void **state) {
 }
 
 static void
-test_wcore_config_attrs_gles3_with_version_20(void **state) {
-struct test_state_wcore_config_attrs *ts = *state;
-
-const int32_t attrib_list[] = {
-WAFFLE_CONTEXT_API, WAFFLE_CONTEXT_OPENGL_ES3,
-WAFFLE_CONTEXT_MAJOR_VERSION,   2,
-WAFFLE_CONTEXT_MINOR_VERSION,   0,
-0,
-};
-
-assert_false(wcore_config_

[waffle] [PATCH 10/13] cgl: fold all ES handling in supports_api()

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/cgl/cgl_display.m | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/waffle/cgl/cgl_display.m b/src/waffle/cgl/cgl_display.m
index 1820e6c..1ec5e39 100644
--- a/src/waffle/cgl/cgl_display.m
+++ b/src/waffle/cgl/cgl_display.m
@@ -75,9 +75,7 @@ cgl_display_supports_context_api(struct wcore_display 
*wc_self,
 case WAFFLE_CONTEXT_OPENGL:
 return true;
 case WAFFLE_CONTEXT_OPENGL_ES1:
-return false;
 case WAFFLE_CONTEXT_OPENGL_ES2:
-return false;
 case WAFFLE_CONTEXT_OPENGL_ES3:
 return false;
 default:
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 12/13] linux: cosmetic/coding style fixes

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/linux/linux_platform.c | 16 +---
 src/waffle/linux/linux_platform.h | 10 +++---
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/waffle/linux/linux_platform.c 
b/src/waffle/linux/linux_platform.c
index 92c36c1..1cdf805 100644
--- a/src/waffle/linux/linux_platform.c
+++ b/src/waffle/linux/linux_platform.c
@@ -62,16 +62,14 @@ linux_platform_destroy(struct linux_platform *self)
 }
 
 static struct linux_dl*
-linux_platform_get_dl(
-struct linux_platform *self,
-int32_t waffle_dl)
+linux_platform_get_dl(struct linux_platform *self, int32_t waffle_dl)
 {
 struct linux_dl **dl;
 
 switch (waffle_dl) {
 case WAFFLE_DL_OPENGL: dl = &self->libgl;break;
 case WAFFLE_DL_OPENGL_ES1: dl = &self->libgles1; break;
-case WAFFLE_DL_OPENGL_ES2: dl = &self->libgles2; break;
+case WAFFLE_DL_OPENGL_ES2:
 case WAFFLE_DL_OPENGL_ES3: dl = &self->libgles2; break;
 default:
 assert(false);
@@ -85,9 +83,7 @@ linux_platform_get_dl(
 }
 
 bool
-linux_platform_dl_can_open(
-struct linux_platform *self,
-int32_t waffle_dl)
+linux_platform_dl_can_open(struct linux_platform *self, int32_t waffle_dl)
 {
 struct linux_dl *dl = NULL;
 WCORE_ERROR_DISABLED({
@@ -97,10 +93,8 @@ linux_platform_dl_can_open(
 }
 
 void*
-linux_platform_dl_sym(
-struct linux_platform *self,
-int32_t waffle_dl,
-const char *name)
+linux_platform_dl_sym(struct linux_platform *self, int32_t waffle_dl,
+  const char *name)
 {
 struct linux_dl *dl = linux_platform_get_dl(self, waffle_dl);
 if (!dl)
diff --git a/src/waffle/linux/linux_platform.h 
b/src/waffle/linux/linux_platform.h
index 4ba1652..b5617b4 100644
--- a/src/waffle/linux/linux_platform.h
+++ b/src/waffle/linux/linux_platform.h
@@ -38,12 +38,8 @@ linux_platform_destroy(struct linux_platform *self);
 
 /// @copydoc waffle_dl_can_open()
 bool
-linux_platform_dl_can_open(
-struct linux_platform *self,
-int32_t waffle_dl);
+linux_platform_dl_can_open(struct linux_platform *self, int32_t waffle_dl);
 
 void*
-linux_platform_dl_sym(
-struct linux_platform *self,
-int32_t waffle_dl,
-const char *name);
+linux_platform_dl_sym(struct linux_platform *self, int32_t waffle_dl,
+  const char *name);
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 09/13] waffle: replace wcore_error_internal with assert()

2016-04-05 Thread Emil Velikov
The upper layer (api/core) already checks and bails out if the provided
value for context_api is invalid. Change the condition to an assert so
that we can catch it as (if) we extend the API and forget to update one
of the backends.

Signed-off-by: Emil Velikov 
---
 src/waffle/cgl/cgl_display.m | 3 +--
 src/waffle/core/wcore_config_attrs.c | 3 +--
 src/waffle/egl/wegl_config.c | 6 ++
 src/waffle/egl/wegl_context.c| 6 ++
 src/waffle/egl/wegl_display.c| 3 +--
 src/waffle/glx/glx_config.c  | 3 +--
 src/waffle/glx/glx_display.c | 3 +--
 src/waffle/nacl/nacl_display.c   | 3 +--
 src/waffle/wgl/wgl_config.c  | 3 +--
 src/waffle/wgl/wgl_display.c | 3 +--
 10 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/src/waffle/cgl/cgl_display.m b/src/waffle/cgl/cgl_display.m
index 015ca32..1820e6c 100644
--- a/src/waffle/cgl/cgl_display.m
+++ b/src/waffle/cgl/cgl_display.m
@@ -81,8 +81,7 @@ cgl_display_supports_context_api(struct wcore_display 
*wc_self,
 case WAFFLE_CONTEXT_OPENGL_ES3:
 return false;
 default:
-wcore_error_internal("waffle_context_api has bad value %#x",
- context_api);
+assert(false);
 return false;
 }
 }
diff --git a/src/waffle/core/wcore_config_attrs.c 
b/src/waffle/core/wcore_config_attrs.c
index 8f362a9..c7c02d4 100644
--- a/src/waffle/core/wcore_config_attrs.c
+++ b/src/waffle/core/wcore_config_attrs.c
@@ -151,8 +151,7 @@ set_context_version_default(struct wcore_config_attrs 
*attrs)
 attrs->context_minor_version = 0;
 return true;
 default:
-wcore_error_internal("attrs->context_api has bad value 0x%x",
- attrs->context_api);
+assert(false);
 return false;
 }
 }
diff --git a/src/waffle/egl/wegl_config.c b/src/waffle/egl/wegl_config.c
index ef35b45..bfa0b95 100644
--- a/src/waffle/egl/wegl_config.c
+++ b/src/waffle/egl/wegl_config.c
@@ -99,8 +99,7 @@ check_context_attrs(struct wegl_display *dpy,
 return true;
 
 default:
-wcore_error_internal("context_api has bad value %#x",
- attrs->context_api);
+assert(false);
 return false;
 }
 }
@@ -164,8 +163,7 @@ choose_real_config(struct wegl_display *dpy,
 attrib_list[renderable_index] = EGL_OPENGL_ES3_BIT_KHR;
 break;
 default:
-wcore_error_internal("waffle_context_api has bad value %#x",
- attrs->context_api);
+assert(false);
 return NULL;
 }
 
diff --git a/src/waffle/egl/wegl_context.c b/src/waffle/egl/wegl_context.c
index f4ee6cd..fff8f94 100644
--- a/src/waffle/egl/wegl_context.c
+++ b/src/waffle/egl/wegl_context.c
@@ -49,8 +49,7 @@ bind_api(struct wegl_platform *plat, int32_t 
waffle_context_api)
 ok &= plat->eglBindAPI(EGL_OPENGL_ES_API);
 break;
 default:
-wcore_error_internal("waffle_context_api has bad value #x%x",
- waffle_context_api);
+assert(false);
 return false;
 }
 
@@ -131,8 +130,7 @@ create_real_context(struct wegl_config *config,
 break;
 
 default:
-wcore_error_internal("waffle_context_api has bad value %#x",
- waffle_context_api);
+assert(false);
 return EGL_NO_CONTEXT;
 }
 
diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c
index c9368fc..f05815f 100644
--- a/src/waffle/egl/wegl_display.c
+++ b/src/waffle/egl/wegl_display.c
@@ -147,8 +147,7 @@ wegl_display_supports_context_api(struct wcore_display 
*wc_dpy,
 case WAFFLE_CONTEXT_OPENGL_ES3:
 return dpy->KHR_create_context;
 default:
-wcore_error_internal("waffle_context_api has bad value %#x",
- waffle_context_api);
+assert(false);
 return false;
 }
 }
diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c
index fc88a7a..94fe040 100644
--- a/src/waffle/glx/glx_config.c
+++ b/src/waffle/glx/glx_config.c
@@ -128,8 +128,7 @@ glx_config_check_context_attrs(struct glx_display *dpy,
 return true;
 
 default:
-wcore_error_internal("context_api has bad value %#x",
- attrs->context_api);
+assert(false);
 return false;
 }
 }
diff --git a/src/waffle/glx/glx_display.c b/src/waffle/glx/glx_display.c
index 24e967c..a0a8782 100644
--- a/src/waffle/glx/glx_display.c
+++ b/src/waffle/glx/glx_display.c
@@ -128,8 +128,7 @@ glx_display_supports_context_api(struct wcore_display 
*wc_self,
 case WAFFLE_CONTEXT_OPENGL_ES3:
 return self->EXT_create_context_es_profile;
 default:
-   

[waffle] [PATCH 05/13] wcore: indent with spaces, not tabs

2016-04-05 Thread Emil Velikov
Signed-off-by: Emil Velikov 
---
 src/waffle/core/wcore_config_attrs.c | 32 +++-
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/waffle/core/wcore_config_attrs.c 
b/src/waffle/core/wcore_config_attrs.c
index bb38fed..8f362a9 100644
--- a/src/waffle/core/wcore_config_attrs.c
+++ b/src/waffle/core/wcore_config_attrs.c
@@ -77,27 +77,25 @@ check_keys(const int32_t attrib_list[])
 }
 
 static bool
-parse_bool(const int32_t attrib_list[],
-  int32_t attrib_name,
-  bool *value,
-  bool default_value)
+parse_bool(const int32_t attrib_list[], int32_t attrib_name,
+   bool *value, bool default_value)
 {
-   int32_t raw_value;
+int32_t raw_value;
 
-   wcore_attrib_list32_get_with_default(attrib_list, attrib_name,
+wcore_attrib_list32_get_with_default(attrib_list, attrib_name,
&raw_value, default_value);
 
-   if (raw_value == WAFFLE_DONT_CARE) {
-   *value = default_value;
-   } else if (raw_value == true || raw_value == false) {
-   *value = raw_value;
-   } else {
-   wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
-"%s has bad value 0x%x. "
-"Must be true(1), false(0), or 
WAFFLE_DONT_CARE(-1)",
-wcore_enum_to_string(attrib_name), 
raw_value);
-   return false;
-   }
+if (raw_value == WAFFLE_DONT_CARE) {
+*value = default_value;
+} else if (raw_value == true || raw_value == false) {
+*value = raw_value;
+} else {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+"%s has bad value 0x%x. "
+"Must be true(1), false(0), or WAFFLE_DONT_CARE(-1)",
+wcore_enum_to_string(attrib_name), raw_value);
+return false;
+}
 
 return true;
 }
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 03/13] glx: remove unneeded asserts

2016-04-05 Thread Emil Velikov
Analogous to the WGL changes earlier.

Signed-off-by: Emil Velikov 
---
 src/waffle/glx/glx_config.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c
index 7792aa0..58d241e 100644
--- a/src/waffle/glx/glx_config.c
+++ b/src/waffle/glx/glx_config.c
@@ -98,10 +98,6 @@ glx_config_check_context_attrs(struct glx_display *dpy,
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES1:
-assert(wcore_config_attrs_version_eq(attrs, 10) ||
-   wcore_config_attrs_version_eq(attrs, 11));
-assert(!attrs->context_forward_compatible);
-
 if (!dpy->EXT_create_context_es_profile) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "GLX_EXT_create_context_es_profile is required "
@@ -118,9 +114,6 @@ glx_config_check_context_attrs(struct glx_display *dpy,
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES2:
-assert(attrs->context_major_version == 2);
-assert(!attrs->context_forward_compatible);
-
 if (!dpy->EXT_create_context_es_profile
 && !dpy->EXT_create_context_es2_profile) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
@@ -138,8 +131,6 @@ glx_config_check_context_attrs(struct glx_display *dpy,
 return true;
 
 case WAFFLE_CONTEXT_OPENGL_ES3:
-assert(attrs->context_major_version == 3);
-
 if (!dpy->EXT_create_context_es_profile) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "GLX_EXT_create_context_es_profile is required "
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 2/3] wgl: don't use ARB_create_context with pre 3.0 contexts

2016-04-05 Thread Emil Velikov
Direct port of previous commit.

Cc: Jose Fonseca 
Cc: Ilia Mirkin 
Signed-off-by: Emil Velikov 
---
 src/waffle/wgl/wgl_config.c  |  7 ---
 src/waffle/wgl/wgl_context.c | 12 +++-
 src/waffle/wgl/wgl_context.h | 15 +++
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/waffle/wgl/wgl_config.c b/src/waffle/wgl/wgl_config.c
index 59a70a6..29a9b7c 100644
--- a/src/waffle/wgl/wgl_config.c
+++ b/src/waffle/wgl/wgl_config.c
@@ -32,6 +32,7 @@
 #include "wcore_error.h"
 
 #include "wgl_config.h"
+#include "wgl_context.h"
 #include "wgl_display.h"
 #include "wgl_error.h"
 #include "wgl_platform.h"
@@ -73,11 +74,11 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,
 
 switch (attrs->context_api) {
 case WAFFLE_CONTEXT_OPENGL:
-if (!wcore_config_attrs_version_eq(attrs, 10) && 
!dpy->ARB_create_context) {
+if (wgl_context_needs_arb_create_context(attrs) &&
+!dpy->ARB_create_context) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "WGL_ARB_create_context is required in order to "
- "request an OpenGL version not equal to the 
default "
- "value 1.0");
+ "request an OpenGL version greater or equal than 
3.0");
 return false;
 }
 else if (wcore_config_attrs_version_ge(attrs, 32) && 
!dpy->ARB_create_context_profile) {
diff --git a/src/waffle/wgl/wgl_context.c b/src/waffle/wgl/wgl_context.c
index dd45f81..125ad7d 100644
--- a/src/waffle/wgl/wgl_context.c
+++ b/src/waffle/wgl/wgl_context.c
@@ -152,7 +152,17 @@ wgl_context_create_native(struct wgl_config *config,
 HGLRC real_share_ctx = share_ctx ? share_ctx->hglrc : NULL;
 HGLRC hglrc;
 
-if (dpy->ARB_create_context) {
+// Use ARB_create_context when we have
+// - OpenGL version 1.0, or
+// - OpenGL version 3.0 or greater, or
+// - OpenGL with fwd_compat, or
+// - Debug context
+//
+// The first one of the four is optional, the remainder hard requirement
+// for the use of ARB_create_context.
+if (dpy->ARB_create_context &&
+(wcore_config_attrs_version_eq(&config->wcore.attrs, 10) ||
+ wgl_context_needs_arb_create_context(&config->wcore.attrs))) {
 bool ok;
 
 // Choose a large size to prevent accidental overflow.
diff --git a/src/waffle/wgl/wgl_context.h b/src/waffle/wgl/wgl_context.h
index c55ad58..6d74aeb 100644
--- a/src/waffle/wgl/wgl_context.h
+++ b/src/waffle/wgl/wgl_context.h
@@ -27,6 +27,7 @@
 
 #include 
 
+#include "wcore_config_attrs.h"
 #include "wcore_context.h"
 #include "wcore_util.h"
 
@@ -51,3 +52,17 @@ wgl_context_create(struct wcore_platform *wc_plat,
 
 bool
 wgl_context_destroy(struct wcore_context *wc_self);
+
+static inline bool
+wgl_context_needs_arb_create_context(const struct wcore_config_attrs *attrs)
+{
+if (attrs->context_api == WAFFLE_CONTEXT_OPENGL &&
+(wcore_config_attrs_version_ge(attrs, 30) ||
+ attrs->context_forward_compatible))
+return true;
+
+if (attrs->context_debug)
+return true;
+
+return false;
+}
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 3/3] tests/gl_basic_test: query context flags only for desktop GL 3.0 or later

2016-04-05 Thread Emil Velikov
Spotted while attemting to use classic swrast with waffle.

Signed-off-by: Emil Velikov 
---
 tests/functional/gl_basic_test.c | 36 +++-
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/tests/functional/gl_basic_test.c b/tests/functional/gl_basic_test.c
index 19b0dac..d6b14d4 100644
--- a/tests/functional/gl_basic_test.c
+++ b/tests/functional/gl_basic_test.c
@@ -34,6 +34,7 @@
 /// 4. Verify the window contents with glReadPixels.
 /// 5. Tear down all waffle state.
 
+#include 
 #include 
 #include 
 #include 
@@ -103,6 +104,7 @@ typedef float   GLclampf;   /* single precision 
float in [0,1] */
 typedef double  GLdouble;   /* double precision float */
 typedef double  GLclampd;   /* double precision float in [0,1] */
 
+#define GL_VERSION  0x1F02
 #define GL_UNSIGNED_BYTE0x1401
 #define GL_UNSIGNED_INT 0x1405
 #define GL_FLOAT0x1406
@@ -123,6 +125,7 @@ typedef double  GLclampd;   /* double precision 
float in [0,1] */
 #endif
 
 static GLenum (APIENTRY *glGetError)(void);
+static const GLubyte *(APIENTRY *glGetString)(GLenum name);
 static void (APIENTRY *glGetIntegerv)(GLenum pname, GLint *params);
 static void (APIENTRY *glClearColor)(GLclampf red,
  GLclampf green,
@@ -301,20 +304,35 @@ gl_basic_draw__(struct gl_basic_draw_args__ args)
 ASSERT_TRUE(glGetError  = waffle_dl_sym(libgl, "glGetError"));
 ASSERT_TRUE(glGetIntegerv   = waffle_dl_sym(libgl, "glGetIntegerv"));
 ASSERT_TRUE(glReadPixels= waffle_dl_sym(libgl, "glReadPixels"));
+ASSERT_TRUE(glGetString = waffle_dl_sym(libgl, "glGetString"));
 
 ASSERT_TRUE(waffle_make_current(dpy, window, ctx));
 
-GLint context_flags = 0;
-if (context_forward_compatible || context_debug) {
-glGetIntegerv(GL_CONTEXT_FLAGS, &context_flags);
-}
+const char *version_str;
+int major, dummy, count;
 
-if (context_forward_compatible) {
-ASSERT_TRUE(context_flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT);
-}
+ASSERT_GL(version_str = (const char *) glGetString(GL_VERSION));
+ASSERT_TRUE(version_str != NULL);
 
-if (context_debug) {
-ASSERT_TRUE(context_flags & GL_CONTEXT_FLAG_DEBUG_BIT);
+while (*version_str != '\0' && !isdigit(*version_str))
+version_str++;
+
+count = sscanf(version_str, "%d.%d", &major, &dummy);
+ASSERT_TRUE(count == 2);
+
+if (waffle_context_api == WAFFLE_CONTEXT_OPENGL && major >= 3) {
+GLint context_flags = 0;
+if (context_forward_compatible || context_debug) {
+glGetIntegerv(GL_CONTEXT_FLAGS, &context_flags);
+}
+
+if (context_forward_compatible) {
+ASSERT_TRUE(context_flags & 
GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT);
+}
+
+if (context_debug) {
+ASSERT_TRUE(context_flags & GL_CONTEXT_FLAG_DEBUG_BIT);
+}
 }
 
 // Draw.
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 0/3] Pre OpenGL 3.0, ARB_create_context and waffle

2016-04-05 Thread Emil Velikov
Hi all,

A few fixes, all maint material considering we all agree on the idea.

Long story short, piglit explicitly feeds in a requested version in the 
range 10-15 which waffle interprets as "I must use 
{GLX,WGL}_ARB_create_context". Jose and Ilia managed to convince me that 
this should really be handled by waffle, so here is the result.

The lot can be found in branch for-upstream/ARB_create_context-for-pre-3.0
over at https://github.com/evelikov/waffle

-Emil

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 1/3] glx: don't use ARB_create_context with pre 3.0 contexts

2016-04-05 Thread Emil Velikov
This way if the user requests GL pre 3.0 context which lacks the
flags/extra bits which require ARB_create_context one can safely fall
back to the normal/legacy entry point.

This resolves piglits on non 3.0 capable drivers such as classic swrast,
nouveau_vieux and alike.

Cc: Jose Fonseca 
Cc: Ilia Mirkin 
Signed-off-by: Emil Velikov 
---
 src/waffle/glx/glx_config.c  |  7 ---
 src/waffle/glx/glx_context.c | 12 +++-
 src/waffle/glx/glx_context.h | 16 
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c
index 7792aa0..5d02bc3 100644
--- a/src/waffle/glx/glx_config.c
+++ b/src/waffle/glx/glx_config.c
@@ -32,6 +32,7 @@
 #include "wcore_error.h"
 
 #include "glx_config.h"
+#include "glx_context.h"
 #include "glx_display.h"
 #include "glx_platform.h"
 #include "glx_wrappers.h"
@@ -70,11 +71,11 @@ glx_config_check_context_attrs(struct glx_display *dpy,
 
 switch (attrs->context_api) {
 case WAFFLE_CONTEXT_OPENGL:
-if (!wcore_config_attrs_version_eq(attrs, 10) && 
!dpy->ARB_create_context) {
+if (glx_context_needs_arb_create_context(attrs) &&
+!dpy->ARB_create_context) {
 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
  "GLX_ARB_create_context is required in order to "
- "request an OpenGL version not equal to the 
default "
- "value 1.0");
+ "request an OpenGL version greater or equal than 
3.0");
 return false;
 }
 else if (wcore_config_attrs_version_ge(attrs, 32) && 
!dpy->ARB_create_context_profile) {
diff --git a/src/waffle/glx/glx_context.c b/src/waffle/glx/glx_context.c
index 1f9290b..8d532d3 100644
--- a/src/waffle/glx/glx_context.c
+++ b/src/waffle/glx/glx_context.c
@@ -169,7 +169,17 @@ glx_context_create_native(struct glx_config *config,
 struct glx_display *dpy = glx_display(config->wcore.display);
 struct glx_platform *platform = glx_platform(dpy->wcore.platform);
 
-if (dpy->ARB_create_context) {
+// Use ARB_create_context when we have
+// - OpenGL version 1.0, or
+// - OpenGL version 3.0 or greater, or
+// - OpenGL with fwd_compat, or
+// - Debug context
+//
+// The first one of the four is optional, the remainder hard requirement
+// for the use of ARB_create_context.
+if (dpy->ARB_create_context &&
+(wcore_config_attrs_version_eq(&config->wcore.attrs, 10) ||
+ glx_context_needs_arb_create_context(&config->wcore.attrs))) {
 bool ok;
 
 // Choose a large size to prevent accidental overflow.
diff --git a/src/waffle/glx/glx_context.h b/src/waffle/glx/glx_context.h
index bb2a4dd..b471b0e 100644
--- a/src/waffle/glx/glx_context.h
+++ b/src/waffle/glx/glx_context.h
@@ -29,6 +29,7 @@
 
 #include 
 
+#include "wcore_config_attrs.h"
 #include "wcore_context.h"
 #include "wcore_util.h"
 
@@ -55,3 +56,18 @@ glx_context_destroy(struct wcore_context *wc_self);
 
 union waffle_native_context*
 glx_context_get_native(struct wcore_context *wc_self);
+
+
+static inline bool
+glx_context_needs_arb_create_context(const struct wcore_config_attrs *attrs)
+{
+if (attrs->context_api == WAFFLE_CONTEXT_OPENGL &&
+(wcore_config_attrs_version_ge(attrs, 30) ||
+ attrs->context_forward_compatible))
+return true;
+
+if (attrs->context_debug)
+return true;
+
+return false;
+}
-- 
2.8.0

___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle