Re: [waffle] json, approach 2, version 2

2016-06-18 Thread Frank Henigman
Perhaps I rewrote the branch after posting that link, it appears not
to be on the json5 branch anymore.  Though the link should still take
you to original (now orphaned) commit.
In any case, you and Emil answered my question.  I'll assume I did the
glxinfo correctly for now, and you'll see it when I send v2 of the
series.  I'll send v2 after rebasing and incorporating the latest
suggestions.
Thanks.

On Tue, Jun 14, 2016 at 12:13 PM, Chad Versace <chad.vers...@intel.com> wrote:
> On Thu 21 Apr 2016, Frank Henigman wrote:
>> Thanks Emil and Chad for reviewing my json series.  All suggestions
>> implemented in v2, except where I replied inline.  I'll hold off
>> sending in case there's more back-and-forth over the first set of
>> comments.  Would also be nice if Chad merged his get-current branch
>> into master, as I use it in v2.
>
>> Not sure if I did the right thing with glx info.  Seems like all three
>> sections (server, client, common) show about the same list of
>> extensions.  That can wait until I send v2, or if anyone wants to look
>> now:
>> https://github.com/fjhenigman/waffle/commit/b358ac50c00ce51fae6546b1e96c9adc32fcbdc7
>
> Hi Frank,
>
> I've returned from sabbatical, and am now trying to catch up with
> everything.
>
> I can't find the above sha1 in your repo. Should I be examining your
> json5 branch?
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 07/12] waffle: support platform-specific information

2016-04-24 Thread Frank Henigman
On Sun, Apr 24, 2016 at 5:04 PM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 24 April 2016 at 20:52, Frank Henigman <fjhenig...@google.com> wrote:
>> On Sun, Apr 24, 2016 at 6:36 AM, Emil Velikov <emil.l.veli...@gmail.com> 
>> wrote:
>>> On 21 April 2016 at 21:26, Frank Henigman <fjhenig...@google.com> wrote:
>>>> On Fri, Jan 8, 2016 at 7:44 AM, Emil Velikov <emil.l.veli...@gmail.com> 
>>>> wrote:
>>>>> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>>>>>> Add a platform hook so platform-specific information can be included
>>>>>> by waffle_display_info_json().
>>>>>>
>>>>>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>>>>>> ---
>>>>>>  src/waffle/api/waffle_display.c  | 10 +-
>>>>>>  src/waffle/core/wcore_platform.h |  4 
>>>>>>  2 files changed, 13 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/src/waffle/api/waffle_display.c 
>>>>>> b/src/waffle/api/waffle_display.c
>>>>>> index 7abe2ef..d6988ac 100644
>>>>>> --- a/src/waffle/api/waffle_display.c
>>>>>> +++ b/src/waffle/api/waffle_display.c
>>>>>> @@ -367,8 +367,16 @@ waffle_display_info_json(struct waffle_display 
>>>>>> *self, bool platform_too)
>>>>>>
>>>>>>  json_appendv(jj, "{", "generic", "{", "");
>>>>>>  add_generic_info(jj, wc_self->current_context);
>>>>>> -json_appendv(jj, "}", "}", "");
>>>>>> +json_append(jj, "}");
>>>>>>
>>>>>> +if (platform_too) {
>>>>>> +json_appendv(jj, "platform", "{", "");
>>>>>> +if (api_platform->vtbl->display.info_json)
>>>>>> +api_platform->vtbl->display.info_json(wc_self, jj);
>>>>> The rest of waffle tends to set UNSUPPORTED_ON_PLATFORM if the backend
>>>>> is missing the vfunc.
>>>>
>>>> I'm reluctant to set an error for something that isn't clearly an
>>>> error (it might just be that a backend doesn't have platform-specific
>>>> details) because it could add a burden to the user to distinguish this
>>>> case from definite errors.
>>> With all respect I have to disagree. Error checking/handling is not a
>>> 'burden'. Even if some choose to ignore it that doesn't make it less
>>> relevant ;-)
>>>
>>> Obviously things would be way easier/cleaner if things were split -
>>> generic info vs platform specific (or even finer). As-is, with all of
>>> them in one piece, no error-checking or UNSUPPORTED_ON_PLATFORM one
>>> gets badly formatted/corrupted json. Thus the user has no way of
>>> knowing if things failed for reason some, or the setup simply lacks
>>> the information Y that they need.
>>> 
>>
>> You never get corrupt json.  If the hook isn't implemented you get
>> different json.  In v1 you'd get an empty platform section.  In v2 the
>> platform section (e.g. "glx" or "egl") is omitted.  This is better
>> because:
>> - the json consumer is in the best position to decide what to do about
>> a missing platform section - the api shouldn't decide it's an error
>> - the caller of waffle_display_info_json() doesn't have to check
>> waffle error state to know if there was a "real" error, they'll know
>> by the NULL return
> So when someone gets an OOM (even if it's during the platform
> specifics) NULL is returned ? That does sound a bit strange, yet again
> I would not read too much into it.

That's true - when memory runs out the whole string is lost.  I guess
that's the trade off for the simplicity of the error handling.  I'm
quite happy with that trade off.

> As long as others are happy go with it.
>
>> - we don't need to implement the hook in every back end
>>
> Need, perhaps not. It would be pretty good though ;-)

I don't want to have to try to land code (even a stub) in back ends
which I've never even compiled (and which would be a pain in the butt
to set up for compiling).  Waffle needs continuous integration.  (:
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 05/12] waffle: add waffle_display_info_json()

2016-04-24 Thread Frank Henigman
On Sun, Apr 24, 2016 at 4:54 PM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 24 April 2016 at 20:50, Frank Henigman <fjhenig...@google.com> wrote:
>> On Sun, Apr 24, 2016 at 6:42 AM, Emil Velikov <emil.l.veli...@gmail.com> 
>> wrote:
>>> On 21 April 2016 at 21:25, Frank Henigman <fjhenig...@google.com> wrote:
>>>> On Fri, Jan 8, 2016 at 7:40 AM, Emil Velikov <emil.l.veli...@gmail.com> 
>>>> wrote:
>>>>> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>>>>>> Duplicate wflinfo functionality in the API, with the difference that the
>>>>>> information is returned in JSON form.
>>>>>> The function has a parameter for including platform-specific information,
>>>>>> but it is ignored for now.
>>>>>>
>>>>>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>>>>>> ---
>>>>>>  include/waffle/waffle.h |   5 +
>>>>>>  man/waffle_display.3.xml|  19 +++
>>>>>>  src/waffle/api/waffle_display.c | 284 
>>>>>> +++-
>>>>>>  src/waffle/waffle.def.in|   1 +
>>>>>>  4 files changed, 308 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
>>>>>> index df0218e..1800399 100644
>>>>>> --- a/include/waffle/waffle.h
>>>>>> +++ b/include/waffle/waffle.h
>>>>>> @@ -214,6 +214,11 @@ bool
>>>>>>  waffle_display_supports_context_api(struct waffle_display *self,
>>>>>>  int32_t context_api);
>>>>>>
>>>>>> +#if WAFFLE_API_VERSION >= 0x0106
>>>>>> +char*
>>>>>> +waffle_display_info_json(struct waffle_display *self, bool 
>>>>>> platform_too);
>>>>> The function does not work solely with the display, but it requires a
>>>>> (bound) context. Thus it does not really fit waffle naming scheme. I'm
>>>>> afraid that I'm short of suggestions though (barring my "returning
>>>>> json formatted data sounds iffy, lets use tokens" rant from earlier)
>>>>>
>>>>>
>>>>>> +#endif
>>>>>> +
>>>>>>  union waffle_native_display*
>>>>>>  waffle_display_get_native(struct waffle_display *self);
>>>>>>
>>>>>> diff --git a/man/waffle_display.3.xml b/man/waffle_display.3.xml
>>>>>> index 9896247..5358472 100644
>>>>>> --- a/man/waffle_display.3.xml
>>>>>> +++ b/man/waffle_display.3.xml
>>>>>> @@ -24,6 +24,7 @@
>>>>>>  waffle_display
>>>>>>  waffle_display_connect
>>>>>>  waffle_display_disconnect
>>>>>> +waffle_display_info_json
>>>>>>  waffle_display_supports_context_api
>>>>>>  waffle_display_get_native
>>>>>>  class waffle_display
>>>>>> @@ -58,6 +59,12 @@ struct waffle_display;
>>>>>>
>>>>>>
>>>>>>
>>>>>> +char* 
>>>>>> waffle_display_info_json
>>>>>> +struct waffle_display 
>>>>>> *self
>>>>>> +bool platform_info
>>>>>> +  
>>>>>> +
>>>>>> +  
>>>>>>  bool 
>>>>>> waffle_display_supports_context_api
>>>>>>  struct waffle_display 
>>>>>> *self
>>>>>>  int32_t context_api
>>>>>> @@ -129,6 +136,18 @@ struct waffle_display;
>>>>>>
>>>>>>
>>>>>>
>>>>>> +waffle_display_info_json()
>>>>>> +
>>>>>> +  
>>>>>> +Return a JSON string containing information about the 
>>>>>> current context on the given display, including Waffle platform and API, 
>>>>>> GL version/vendor/renderer and extensions.
>>>>>> +If platform_info is true, 
>>>>>> platform-specific information (such as GLX or EGL versions and 
>>>>>> exten

Re: [waffle] [PATCH 04/12] core: add JSON library

2016-04-24 Thread Frank Henigman
On Sun, Apr 24, 2016 at 4:50 PM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 6 January 2016 at 19:56, Frank Henigman <fjhenig...@google.com> wrote:
>
>> +static void
>> +put(struct json *jj, char *s)
>> +{
>> +if (!jj->buf)
>> +return;
>> +
>> +for (;;) {
>> +if (!(*jj->pos = *s++))
>> +break;
>> +if (++jj->pos == jj->buf + jj->size) {
>> +size_t z = jj->size * 2;
>> +jj->buf = realloc(jj->buf, z);
>> +if (!jj->buf)
>
> As I did not look closely at the patch this piece made me believe it
> will corrupt the output. Although it will only leak memory.
> Namely: if realloc fails, the old pointer is lost yet the data isn't freed.

Nice catch.  When I did the testing with simulated allocation failures
I also checked for leaks, but I probably implemented the realloc
wrapper wrong (probably unconditionally freed the given pointer).  I
did the testing again and it found this leak.  Easily fixed by doing a
free when the realloc fails.  So I'll go out on a limb and claim v2
will not crash, leak or return a partial result if memory runs out at
any point in the building of a json string.

>
>> +char *buf = malloc(strlen(s) * 3 + 2);
>> +if (!buf)
> Nit: Just return NULL and drop the label ? Imho there is no point in
> jumping only to free(NULL).

It jumps to free(dup) where dup!=NULL.

> Thanks
> Emil

Emil: sorry for the duplicate - I didn't reply to the list the first time.
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 07/12] waffle: support platform-specific information

2016-04-24 Thread Frank Henigman
On Sun, Apr 24, 2016 at 6:36 AM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 21 April 2016 at 21:26, Frank Henigman <fjhenig...@google.com> wrote:
>> On Fri, Jan 8, 2016 at 7:44 AM, Emil Velikov <emil.l.veli...@gmail.com> 
>> wrote:
>>> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>>>> Add a platform hook so platform-specific information can be included
>>>> by waffle_display_info_json().
>>>>
>>>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>>>> ---
>>>>  src/waffle/api/waffle_display.c  | 10 +-
>>>>  src/waffle/core/wcore_platform.h |  4 
>>>>  2 files changed, 13 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/src/waffle/api/waffle_display.c 
>>>> b/src/waffle/api/waffle_display.c
>>>> index 7abe2ef..d6988ac 100644
>>>> --- a/src/waffle/api/waffle_display.c
>>>> +++ b/src/waffle/api/waffle_display.c
>>>> @@ -367,8 +367,16 @@ waffle_display_info_json(struct waffle_display *self, 
>>>> bool platform_too)
>>>>
>>>>  json_appendv(jj, "{", "generic", "{", "");
>>>>  add_generic_info(jj, wc_self->current_context);
>>>> -json_appendv(jj, "}", "}", "");
>>>> +json_append(jj, "}");
>>>>
>>>> +if (platform_too) {
>>>> +json_appendv(jj, "platform", "{", "");
>>>> +if (api_platform->vtbl->display.info_json)
>>>> +api_platform->vtbl->display.info_json(wc_self, jj);
>>> The rest of waffle tends to set UNSUPPORTED_ON_PLATFORM if the backend
>>> is missing the vfunc.
>>
>> I'm reluctant to set an error for something that isn't clearly an
>> error (it might just be that a backend doesn't have platform-specific
>> details) because it could add a burden to the user to distinguish this
>> case from definite errors.
> With all respect I have to disagree. Error checking/handling is not a
> 'burden'. Even if some choose to ignore it that doesn't make it less
> relevant ;-)
>
> Obviously things would be way easier/cleaner if things were split -
> generic info vs platform specific (or even finer). As-is, with all of
> them in one piece, no error-checking or UNSUPPORTED_ON_PLATFORM one
> gets badly formatted/corrupted json. Thus the user has no way of
> knowing if things failed for reason some, or the setup simply lacks
> the information Y that they need.
> 

You never get corrupt json.  If the hook isn't implemented you get
different json.  In v1 you'd get an empty platform section.  In v2 the
platform section (e.g. "glx" or "egl") is omitted.  This is better
because:
- the json consumer is in the best position to decide what to do about
a missing platform section - the api shouldn't decide it's an error
- the caller of waffle_display_info_json() doesn't have to check
waffle error state to know if there was a "real" error, they'll know
by the NULL return
- we don't need to implement the hook in every back end

>>  If someone does need to act on the
>> presence or absence or platform-specifics, they can always examine the
>> json.
> Personally I'd just discard the check and use the function
> unconditionally. For platforms that I'm unsure I'll just put a uniform
> stub alike "not-implemented", thus any users parsing the data will
> have clear feedback.
>
> Does that sound reasonable ?
> Emil
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 05/12] waffle: add waffle_display_info_json()

2016-04-24 Thread Frank Henigman
On Sun, Apr 24, 2016 at 6:42 AM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 21 April 2016 at 21:25, Frank Henigman <fjhenig...@google.com> wrote:
>> On Fri, Jan 8, 2016 at 7:40 AM, Emil Velikov <emil.l.veli...@gmail.com> 
>> wrote:
>>> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>>>> Duplicate wflinfo functionality in the API, with the difference that the
>>>> information is returned in JSON form.
>>>> The function has a parameter for including platform-specific information,
>>>> but it is ignored for now.
>>>>
>>>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>>>> ---
>>>>  include/waffle/waffle.h |   5 +
>>>>  man/waffle_display.3.xml|  19 +++
>>>>  src/waffle/api/waffle_display.c | 284 
>>>> +++-
>>>>  src/waffle/waffle.def.in|   1 +
>>>>  4 files changed, 308 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
>>>> index df0218e..1800399 100644
>>>> --- a/include/waffle/waffle.h
>>>> +++ b/include/waffle/waffle.h
>>>> @@ -214,6 +214,11 @@ bool
>>>>  waffle_display_supports_context_api(struct waffle_display *self,
>>>>  int32_t context_api);
>>>>
>>>> +#if WAFFLE_API_VERSION >= 0x0106
>>>> +char*
>>>> +waffle_display_info_json(struct waffle_display *self, bool platform_too);
>>> The function does not work solely with the display, but it requires a
>>> (bound) context. Thus it does not really fit waffle naming scheme. I'm
>>> afraid that I'm short of suggestions though (barring my "returning
>>> json formatted data sounds iffy, lets use tokens" rant from earlier)
>>>
>>>
>>>> +#endif
>>>> +
>>>>  union waffle_native_display*
>>>>  waffle_display_get_native(struct waffle_display *self);
>>>>
>>>> diff --git a/man/waffle_display.3.xml b/man/waffle_display.3.xml
>>>> index 9896247..5358472 100644
>>>> --- a/man/waffle_display.3.xml
>>>> +++ b/man/waffle_display.3.xml
>>>> @@ -24,6 +24,7 @@
>>>>  waffle_display
>>>>  waffle_display_connect
>>>>  waffle_display_disconnect
>>>> +waffle_display_info_json
>>>>  waffle_display_supports_context_api
>>>>  waffle_display_get_native
>>>>  class waffle_display
>>>> @@ -58,6 +59,12 @@ struct waffle_display;
>>>>
>>>>
>>>>
>>>> +char* 
>>>> waffle_display_info_json
>>>> +struct waffle_display 
>>>> *self
>>>> +bool platform_info
>>>> +  
>>>> +
>>>> +  
>>>>  bool 
>>>> waffle_display_supports_context_api
>>>>  struct waffle_display 
>>>> *self
>>>>  int32_t context_api
>>>> @@ -129,6 +136,18 @@ struct waffle_display;
>>>>
>>>>
>>>>
>>>> +waffle_display_info_json()
>>>> +
>>>> +  
>>>> +Return a JSON string containing information about the current 
>>>> context on the given display, including Waffle platform and API, GL 
>>>> version/vendor/renderer and extensions.
>>>> +If platform_info is true, 
>>>> platform-specific information (such as GLX or EGL versions and extensions) 
>>>> will be included as available.
>>>> +Returns NULL on error.
>>>> +The string should be deallocated with 
>>>> free3.
>>>> +  
>>>> +
>>>> +  
>>>> +
>>>> +  
>>>>  
>>>> waffle_display_supports_context_api()
>>>>  
>>>>
>>>> diff --git a/src/waffle/api/waffle_display.c 
>>>> b/src/waffle/api/waffle_display.c
>>>> index fa19462..7abe2ef 100644
>>>> --- a/src/waffle/api/waffle_display.c
>>>> +++ b/src/waffle/api/waffle_display.c
>>>> @@ -23,13 +23,61 @@
>>>>  // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
>>>> THE USE
>>>> 

Re: [waffle] [PATCH 10/12] egl: implement platform-specific information

2016-04-21 Thread Frank Henigman
On Fri, Jan 8, 2016 at 7:50 AM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>> Implement the platform hook of waffle_display_info_json() so it can
>> pick up egl-specific information.
>>
>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>> ---
>>  src/waffle/egl/wegl_display.c  | 32 ++--
>>  src/waffle/egl/wegl_display.h  |  4 
>>  src/waffle/egl/wegl_platform.h |  3 +++
>>  3 files changed, 37 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c
>> index 88fce7a..dcfe934 100644
>> --- a/src/waffle/egl/wegl_display.c
>> +++ b/src/waffle/egl/wegl_display.c
>> @@ -25,6 +25,8 @@
>>
>>  #include 
>>
>> +#include "json.h"
>> +
>>  #include "wcore_error.h"
>>  #include "wcore_platform.h"
>>
>> @@ -63,7 +65,6 @@ wegl_display_init(struct wegl_display *dpy,
>>  {
>>  struct wegl_platform *plat = wegl_platform(wc_plat);
>>  bool ok;
>> -EGLint major, minor;
>>
>>  ok = wcore_display_init(>wcore, wc_plat);
>>  if (!ok)
>> @@ -75,7 +76,7 @@ wegl_display_init(struct wegl_display *dpy,
>>  goto fail;
>>  }
>>
>> -ok = plat->eglInitialize(dpy->egl, , );
>> +ok = plat->eglInitialize(dpy->egl, >major, >minor);
>>  if (!ok) {
>>  wegl_emit_error(plat, "eglInitialize");
>>  goto fail;
>> @@ -139,3 +140,30 @@ wegl_display_supports_context_api(struct wcore_display 
>> *wc_dpy,
>>
>>  return wc_plat->vtbl->dl_can_open(wc_plat, waffle_dl);
>>  }
>> +
>> +void
>> +wegl_display_info_json(struct wcore_display *wc_dpy, struct json *jj)
>> +{
>> +struct wegl_display *dpy = wegl_display(wc_dpy);
>> +struct wegl_platform *plat = wegl_platform(dpy->wcore.platform);
>> +
>> +const char *version = plat->eglQueryString(dpy->egl, EGL_VERSION);
>> +const char *vendor = plat->eglQueryString(dpy->egl, EGL_VENDOR);
>> +#ifdef EGL_VERSION_1_2
>> +const char *apis = plat->eglQueryString(dpy->egl, EGL_CLIENT_APIS);
>> +#endif
> I would suggesting adding the define on top ifndef EGL_VERSION_1_2,
> and dropping the checks here and below.

Sorry, not sure what you mean by this.  It sounds like skipping the
whole thing ifndef EGL_VERSION_1_2 ?  And that's ok because no one
uses <= 1.2 anymore?
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 07/12] waffle: support platform-specific information

2016-04-21 Thread Frank Henigman
On Fri, Jan 8, 2016 at 7:44 AM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>> Add a platform hook so platform-specific information can be included
>> by waffle_display_info_json().
>>
>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>> ---
>>  src/waffle/api/waffle_display.c  | 10 +-
>>  src/waffle/core/wcore_platform.h |  4 
>>  2 files changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/waffle/api/waffle_display.c 
>> b/src/waffle/api/waffle_display.c
>> index 7abe2ef..d6988ac 100644
>> --- a/src/waffle/api/waffle_display.c
>> +++ b/src/waffle/api/waffle_display.c
>> @@ -367,8 +367,16 @@ waffle_display_info_json(struct waffle_display *self, 
>> bool platform_too)
>>
>>  json_appendv(jj, "{", "generic", "{", "");
>>  add_generic_info(jj, wc_self->current_context);
>> -json_appendv(jj, "}", "}", "");
>> +json_append(jj, "}");
>>
>> +if (platform_too) {
>> +json_appendv(jj, "platform", "{", "");
>> +if (api_platform->vtbl->display.info_json)
>> +api_platform->vtbl->display.info_json(wc_self, jj);
> The rest of waffle tends to set UNSUPPORTED_ON_PLATFORM if the backend
> is missing the vfunc.

I'm reluctant to set an error for something that isn't clearly an
error (it might just be that a backend doesn't have platform-specific
details) because it could add a burden to the user to distinguish this
case from definite errors.  If someone does need to act on the
presence or absence or platform-specifics, they can always examine the
json.
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 06/12] wflinfo: add option for JSON output

2016-04-21 Thread Frank Henigman
On Fri, Apr 8, 2016 at 8:14 PM, Chad Versace <chad.vers...@intel.com> wrote:
> On 01/06/2016 11:56 AM, Frank Henigman wrote:
>> With "-f json" wflinfo will now print the result of
>> waffle_display_info_json().
>>
>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>> ---
>>  src/utils/wflinfo.c | 40 
>>  1 file changed, 36 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
>> index 268d4b8..58f5688 100644
>> --- a/src/utils/wflinfo.c
>> +++ b/src/utils/wflinfo.c
>
>
>> @@ -1119,9 +1137,23 @@ main(int argc, char **argv)
>>  glGetStringi = waffle_get_proc_address("glGetStringi");
>>  }
>>
>> -ok = print_wflinfo();
>> -if (!ok)
>> -error_waffle();
>> +char *info;
>> +switch (opts.format) {
>> +case FORMAT_ORIGINAL:
>> +ok = print_wflinfo();
>> +if (!ok)
>> +error_waffle();
>> +break;
>> +
>> +case FORMAT_JSON:
>> +info = waffle_display_info_json(dpy, false);
>> +if (info) {
>> +printf("%s\n", info);
>> +free(info);
>> +} else
>> +error_waffle();
>> +break;
>> +}
>
>
> I agree with the patch series's goals: teach wflinfo to print 
> platform-specific
> info (such as EGL info); extract that info inside libwaffle and expose it
> through public API; that public API should provide JSON, and perhaps 
> additional
> formats.
>
> But this patch 6/12 poses a problem. Post-patch, wflinfo can print its info in
> the old format and in a json format. But, depending on the output format,
> wflinfo uses completely separate code paths to obtain the information.
>
> The actual information that wflinfo provides, and the method by which it
> obtains that info, should be largely independent of the output format. When 
> the
> user chooses an output format, that choice should affect the *presentation* 
> but
> not fundamentally affect the *content*.
>
> So...
>
> For wflinfo's sake, we need a public waffle_get_my_info() function that 
> returns
> data that can be translated into the old format and into the json format, or 
> perhaps
> returns the old format and json directly.
>
> To move forward with this patch series, I see the following options:
>
> 1. waffle_get_my_info() returns only json
>
>   I don't like this. This would require that wflinfo decode the json in
>   order to provide the old format output. I would like to avoid decoding
>   json in Waffle though, because that would require either (a) Waffle
>   contain a json decoder implementation or (b) Waffle rely on some json
>   library. As for (a), I don't want to maintain a json-decoder (a json
>   *encoder*, though, I don't object to). As for (b), Waffle is such
>   a small, focused project that it feels wrong to pull in a json-decoder
>   library as a dependency.
>
>   BUT, maybe this option could work and I'm overestimating the maintenance
>   overhead of decoding json.
>
> 2. waffle_get_my_info() returns only some-other-well-defined-format-FOO
>
>I don't like this either. Just like option 1, it would require that
>wflinfo decode the FOO format in order to provide json output.
>
> 3. waffle_get_my_info() can return a json string or a string in the old
>wflinfo format
>
>If option 3 can be implemented cleanly, I think it's the best choice.
>This option eliminates the need for decoding any special format.
>
>Perhaps we could implement this by defining a private struct...
>
> struct wcore_display_info {
> struct {
> char *platform;
> char *api;
> } waffle;
>
> struct {
> char *vendor;
> char *renderer;
> ...
> char **extensions;
> } opengl;
>
> struct {
> char *version;
> char *vendor;
> char *client_apis;
> ...
> } egl;
>
> ...
> };
>
> ...that waffle_get_my_info() populates and then encodes into the
> respected format: JSON, the old wflinfo format, a format that
> mimics glxinfo, or whatever.
>
>
> Frank, what do y

Re: [waffle] [PATCH 05/12] waffle: add waffle_display_info_json()

2016-04-21 Thread Frank Henigman
On Fri, Jan 8, 2016 at 7:40 AM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>> Duplicate wflinfo functionality in the API, with the difference that the
>> information is returned in JSON form.
>> The function has a parameter for including platform-specific information,
>> but it is ignored for now.
>>
>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>> ---
>>  include/waffle/waffle.h |   5 +
>>  man/waffle_display.3.xml|  19 +++
>>  src/waffle/api/waffle_display.c | 284 
>> +++-
>>  src/waffle/waffle.def.in|   1 +
>>  4 files changed, 308 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
>> index df0218e..1800399 100644
>> --- a/include/waffle/waffle.h
>> +++ b/include/waffle/waffle.h
>> @@ -214,6 +214,11 @@ bool
>>  waffle_display_supports_context_api(struct waffle_display *self,
>>  int32_t context_api);
>>
>> +#if WAFFLE_API_VERSION >= 0x0106
>> +char*
>> +waffle_display_info_json(struct waffle_display *self, bool platform_too);
> The function does not work solely with the display, but it requires a
> (bound) context. Thus it does not really fit waffle naming scheme. I'm
> afraid that I'm short of suggestions though (barring my "returning
> json formatted data sounds iffy, lets use tokens" rant from earlier)
>
>
>> +#endif
>> +
>>  union waffle_native_display*
>>  waffle_display_get_native(struct waffle_display *self);
>>
>> diff --git a/man/waffle_display.3.xml b/man/waffle_display.3.xml
>> index 9896247..5358472 100644
>> --- a/man/waffle_display.3.xml
>> +++ b/man/waffle_display.3.xml
>> @@ -24,6 +24,7 @@
>>  waffle_display
>>  waffle_display_connect
>>  waffle_display_disconnect
>> +waffle_display_info_json
>>  waffle_display_supports_context_api
>>  waffle_display_get_native
>>  class waffle_display
>> @@ -58,6 +59,12 @@ struct waffle_display;
>>
>>
>>
>> +char* 
>> waffle_display_info_json
>> +struct waffle_display 
>> *self
>> +bool platform_info
>> +  
>> +
>> +  
>>  bool 
>> waffle_display_supports_context_api
>>  struct waffle_display 
>> *self
>>  int32_t context_api
>> @@ -129,6 +136,18 @@ struct waffle_display;
>>
>>
>>
>> +waffle_display_info_json()
>> +
>> +  
>> +Return a JSON string containing information about the current 
>> context on the given display, including Waffle platform and API, GL 
>> version/vendor/renderer and extensions.
>> +If platform_info is true, 
>> platform-specific information (such as GLX or EGL versions and extensions) 
>> will be included as available.
>> +Returns NULL on error.
>> +The string should be deallocated with 
>> free3.
>> +  
>> +
>> +  
>> +
>> +  
>>  
>> waffle_display_supports_context_api()
>>  
>>
>> diff --git a/src/waffle/api/waffle_display.c 
>> b/src/waffle/api/waffle_display.c
>> index fa19462..7abe2ef 100644
>> --- a/src/waffle/api/waffle_display.c
>> +++ b/src/waffle/api/waffle_display.c
>> @@ -23,13 +23,61 @@
>>  // 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 "api_priv.h"
>>
>> -#include "wcore_error.h"
>> +#include "json.h"
>> +
>> +#include "wcore_context.h"
>>  #include "wcore_display.h"
>> +#include "wcore_error.h"
>>  #include "wcore_platform.h"
>>  #include "wcore_util.h"
>>
>> +typedef unsigned int GLint;
>> +typedef unsigned int GLenum;
>> +typedef unsigned char GLubyte;
>> +
>> +enum {
>> +// Copied from .
>> +GL_NO_ERROR = 0,
>> +
>> +GL_CONTEXT_FLAGS = 0x821e,
>> +GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT = 0x0001,
>> +GL_CONTEXT_FLAG_DEBUG_BIT  = 0x0002,
>> +GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB  = 0x0004,
>> +
&g

Re: [waffle] [PATCH 04/12] core: add JSON library

2016-04-21 Thread Frank Henigman
On Fri, Apr 8, 2016 at 7:38 PM, Chad Versace <chad.vers...@intel.com> wrote:
> On 01/08/2016 04:17 AM, Emil Velikov wrote:
>> On 6 January 2016 at 21:56, Frank Henigman <fjhenig...@google.com> wrote:
>>> A small library for building JSON strings.
>>>
>>> Signed-off-by: Frank Henigman <fjhenig...@google.com>
>>> ---
>>>  src/waffle/CMakeLists.txt |   1 +
>>>  src/waffle/core/json.c| 235 
>>> ++
>>>  src/waffle/core/json.h|  93 ++
>
>> Is the library is copied/derived from another project or written from
>> scratch ? If the former should we move it to third_party/  ?
>
> I have the same question. Was this code copied from a public Google project?
> If so, the we should place in third_party/ with a note explaining its origin
> and explaining how to update it in the future. If not, the the current 
> location
> in src/waffle/core/ is appropriate.

I wrote it.  I didn't really want to write a json lib, but I did want
the json-building code (the code that calls a json lib) to be as clear
and simple as I could make it, and it seemed I needed to write
something to facilitate that.  I'm open to a third party solution, if
it doesn't require uglier code to use it.  I didn't think of it at the
time, but maybe a little wrapping around some third party lib could do
the job.  But by now I don't remember anything about the third party
libs I looked at.
___
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] Approaches to JSON

2016-01-11 Thread Frank Henigman
On Mon, Jan 11, 2016 at 3:43 PM, Chad Versace 
wrote:

> There are two sets of very different json patchsets on the list. Each
> has advantages and disadvantages.
>
> Dylan's patchset duplicates a small amount of code. And it doesn't teach
> wflinfo to print any additional info, such as GLX or EGL specific info.
> However, the patchset is short, sweet, has no major flaw, and is
> the correct approach for what he wished to accomplish: teach wflinfo to
> print its current output in a new format, json.
>
> Having json output makes Dylan's life easier as a Piglit developer, and
> the sooner he can get json the better. So I'm inclined to expedite
> Dylan's patchset and merge it soon, pending fixes.
>
> Frank's patchset adds platform-specific info the wflinfo's output, which
> is a feature it really needs. And the code for the platform-specific
> info rightly belongs in core waffle, which the patchset gets right.
> However, the patchset is much larger, needs lots more review, and needs
> to undergo some API changes.
>
> In other words, Frank's patches will take more time to land, and Dylan's
> are nearly ready to land as-is. And I don't want to artificially stall
> Dylan's Piglit work.
>
> I've decided my preferred format for wflinfo's json output. If the
> format is acceptable to everyone, then I want to see Dylan fixup
> patch 4/4 of his series and resubmit.
>
> I've been taking notes on Frank's patchset, but won't have time to
> provide real feedback until Tuesday (tomorrow) morning.
>
>
> JSON Format
> ---
> Below is the json format I prefer. Is this acceptable to everyone? Did I
> underspecify the format?
>
> The major things I considered when deciding the format are:
>   1. Keep it simple.
>   2. Explicit is better than implicit.
>   3. Make life easy for existing wflinfo parsers
>  that wish to begin consuming the json. That means existing keys and
>  values should closely resemble eachother, and preferably be
>  identical.
>
> Definition:
>   * All key names are lower case, for consistency.
>   * Key names use ' ', not '-' nor '_', as the separator. This is
> consistent with wflinfo's current output and glxinfo's output.
>   * For existing keys in wflinfo's current output, the JSON key names
> should match modulo case.
>   * For existing values in wflinfo's current output, the JSON value
> should be identical.
>   * The "opengl" table contains all info specific to the OpenGL context.
> That includes GLSL info, as that is a property of the OpenGL
> context.
>
>   {
> "waffle": {
>   "platform": String,
>   "api": String,
> },
> "opengl": {
>   "vendor string": String,
>   "renderer string": String,
>   "version string": String,
>   "shading language version string": String,
>   "extensions": [String],
> },
> 
> "egl": {
>   "vendor string": String,
>   "version string": String,
>   "version": [Int, Int],
>   "extensions": [String],
>   "client apis": [String],
> },
> 
> 
> "glx": {
>   "server": {
> "vendor string": String,
> "version string": String,
> "extensions string": [String],
>   },
>   "client": {
> "vendor string": String,
> "version string": String,
> "extensions": [String],
>   }
>   "common": {
> "version": [Int, Int],
> "extensions": [String],
>   },
> },
> 
>   }
>
> The GLX and EGL tables can be extended in the future to contain
> additional information, such as visual configs.
>

Your JSON format is fine with me.

So if I understand, you're still interested in my patches after landing
Dylan's?  If so I'll just wait until all review comments are in (take your
time) and then prepare v2.  Thanks.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 02/29] gbm: don't fetch gbm_bo_* symbols from libgbm

2016-01-06 Thread Frank Henigman
On Wed, Jan 6, 2016 at 4:27 PM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> Neither one of these is (or has been) used. Remove them for now and
> introduce back when needed.
>
> Presently this causes run-time issues whenever someone attempts to use an
> old version of libgbm (mesa circa 9.2) as the gbm_bo_get_fd symbol is
> missing.
>
> Due to the multiple gbm provides and their inconsistent versioning
> (xxx: check ?) we cannot reliably add a limitation during the configure
> stage.
>
> This commit reverts a hunk of commit 14e3356a01d(gbm: make platform
> friendlier to derived classes). The latter of which could have kept
> these as a separate patch :)
>
> Cc: Frank Henigman <fjhenig...@google.com>
> Cc: Chad Versace <chad.vers...@intel.com>
> Signed-off-by: Emil Velikov <emil.l.veli...@gmail.com>
> ---
>  src/waffle/gbm/wgbm_platform.h | 11 +--
>  1 file changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/src/waffle/gbm/wgbm_platform.h b/src/waffle/gbm/wgbm_platform.h
> index 1a08183..edcbe95 100644
> --- a/src/waffle/gbm/wgbm_platform.h
> +++ b/src/waffle/gbm/wgbm_platform.h
> @@ -41,16 +41,7 @@
>  f(struct gbm_surface *, gbm_surface_create   , (struct 
> gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t 
> flags)) \
>  f(void, gbm_surface_destroy  , (struct 
> gbm_surface *surface)) \
>  f(struct gbm_bo * , gbm_surface_lock_front_buffer, (struct 
> gbm_surface *surface)) \
> -f(void, gbm_surface_release_buffer   , (struct 
> gbm_surface *surface, struct gbm_bo *bo)) \
> -f(struct gbm_bo * , gbm_bo_create, (struct 
> gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t 
> flags)) \
> -f(void, gbm_bo_destroy   , (struct gbm_bo 
> *bo)) \
> -f(int , gbm_bo_get_fd, (struct gbm_bo 
> *bo)) \
> -f(uint32_t, gbm_bo_get_width , (struct gbm_bo 
> *bo)) \
> -f(uint32_t, gbm_bo_get_height, (struct gbm_bo 
> *bo)) \
> -f(uint32_t, gbm_bo_get_stride, (struct gbm_bo 
> *bo)) \
> -f(uint32_t, gbm_bo_get_format, (struct gbm_bo 
> *bo)) \
> -f(union gbm_bo_handle , gbm_bo_get_handle, (struct gbm_bo 
> *bo)) \
> -f(struct gbm_device * , gbm_bo_get_device, (struct gbm_bo 
> *bo))

My surfaceless branch uses these.  The branch I've been thinking I'll
send to the list "soon" for ages.
I'll add in a check for gbm_bo_get_fd and disable surfaceless if not
found (though I'm sure it wouldn't work anyway on ancient mesa).
In the mean time if you have to remove this stuff go ahead, or maybe
just remove gbm_bo_get_fd. Then I won't have to add the others back
in.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 00/12] JSON and platform-specific wflinfo

2016-01-06 Thread Frank Henigman
On Wed, Jan 6, 2016 at 6:43 PM, Dylan Baker  wrote:
> Okay, I have some comments:
>
> When I run wflinfo -p gbm -a gl -f json | jsontidy (a small python script I
> have that formats JSON to be human readable)
> I get this:
> {
> "generic": {
> "waffle": {
> "api": "WAFFLE_CONTEXT_OPENGL",
> "platform": "WAFFLE_PLATFORM_GBM"
> },
> "extensions": [
> "GL_3DFX_texture_compression_FXT1",
> ... (truncated for readability)
> "GL_SUN_multi_draw_arrays"
> ],
> "opengl": {
> "renderer": "Mesa DRI Intel(R) Haswell Mobile ",
> "version": "3.0 Mesa 11.1.0",
> "vendor": "Intel Open Source Technology Center"
> },
> "shading_language_version": "1.30"
> }
> }
>
> I think the shading_language_version and extensions belong in the opengl
> dictionary.

I didn't give much thought at the time to structure nor key names.
Figured there
would some debate in any case.  (-:
Makes sense to put gl extensions in the "opengl" block.
How about a glsl block?  Seems like there might be other stuff in it some day,
and adds consistency to the use of "version" i.e.
  "glsl" : {
"version" : "1.30"
  }
I'm not as sure about putting it inside the opengl block, but not
fussy about it either.
If there's no dissent I'll do as you suggest.

> Other than that the output seems reasonable and quite usable for my
> purposes.

Once again sorry for not sending mine out sooner.  If none of your patch makes
it in, hopefully it had some value to you as an exercise.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 08/12] wflinfo: add flag for platform-specific info

2016-01-06 Thread Frank Henigman
When given a "-s" flag wflinfo will now also print some platform-specific
information.  This affects only JSON output, not other formats.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 src/utils/wflinfo.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
index 58f5688..6732274 100644
--- a/src/utils/wflinfo.c
+++ b/src/utils/wflinfo.c
@@ -80,6 +80,9 @@ static const char *usage_message =
 "-f, --format\n"
 "One of: original (default) or json\n"
 "\n"
+"-s, --specific\n"
+"Include platform-specific information (json format only).\n"
+"\n"
 "--forward-compatible\n"
 "Create a forward-compatible context.\n"
 "\n"
@@ -104,6 +107,7 @@ enum {
 OPT_PROFILE,
 OPT_FORMAT = 'f',
 OPT_VERBOSE = 'v',
+OPT_SPECIFIC = 's',
 OPT_DEBUG_CONTEXT,
 OPT_FORWARD_COMPATIBLE,
 OPT_HELP = 'h',
@@ -116,6 +120,7 @@ static const struct option get_opts[] = {
 { .name = "profile",.has_arg = required_argument, .val = 
OPT_PROFILE },
 { .name = "format", .has_arg = required_argument, .val = 
OPT_FORMAT },
 { .name = "verbose",.has_arg = no_argument,   .val = 
OPT_VERBOSE },
+{ .name = "specific",   .has_arg = no_argument,   .val = 
OPT_SPECIFIC },
 { .name = "debug-context",  .has_arg = no_argument,   .val = 
OPT_DEBUG_CONTEXT },
 { .name = "forward-compatible", .has_arg = no_argument,   .val = 
OPT_FORWARD_COMPATIBLE },
 { .name = "help",   .has_arg = no_argument,   .val = 
OPT_HELP },
@@ -257,6 +262,8 @@ struct options {
 
 bool verbose;
 
+bool specific;
+
 bool context_forward_compatible;
 bool context_debug;
 
@@ -343,7 +350,7 @@ parse_args(int argc, char *argv[], struct options *opts)
 opterr = 0;
 
 while (loop_get_opt) {
-int opt = getopt_long(argc, argv, "a:f:hp:vV:", get_opts, NULL);
+int opt = getopt_long(argc, argv, "a:f:hp:svV:", get_opts, NULL);
 switch (opt) {
 case -1:
 loop_get_opt = false;
@@ -405,6 +412,9 @@ parse_args(int argc, char *argv[], struct options *opts)
 case OPT_VERBOSE:
 opts->verbose = true;
 break;
+case OPT_SPECIFIC:
+opts->specific = true;
+break;
 case OPT_FORWARD_COMPATIBLE:
 opts->context_forward_compatible = true;
 break;
@@ -1146,7 +1156,7 @@ main(int argc, char **argv)
 break;
 
 case FORMAT_JSON:
-info = waffle_display_info_json(dpy, false);
+info = waffle_display_info_json(dpy, opts.specific);
 if (info) {
 printf("%s\n", info);
 free(info);
-- 
2.6.0.rc2.230.g3dd15c0

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


[waffle] [PATCH 01/12] core: store platform type in wcore_platform

2016-01-06 Thread Frank Henigman
Facilitates platform-specific code in core functions, like the forthcoming
wflinfo-like function.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 src/waffle/api/waffle_init.c | 32 +---
 src/waffle/core/wcore_platform.h |  1 +
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/waffle/api/waffle_init.c b/src/waffle/api/waffle_init.c
index 60091d1..3d8d350 100644
--- a/src/waffle/api/waffle_init.c
+++ b/src/waffle/api/waffle_init.c
@@ -142,43 +142,53 @@ waffle_init_parse_attrib_list(
 static struct wcore_platform*
 waffle_init_create_platform(int32_t waffle_platform)
 {
+struct wcore_platform *wc_platform = NULL;
+
 switch (waffle_platform) {
 #ifdef WAFFLE_HAS_ANDROID
 case WAFFLE_PLATFORM_ANDROID:
-return droid_platform_create();
+wc_platform = droid_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_CGL
 case WAFFLE_PLATFORM_CGL:
-return cgl_platform_create();
+wc_platform = cgl_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_GLX
 case WAFFLE_PLATFORM_GLX:
-return glx_platform_create();
+wc_platform = glx_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_WAYLAND
 case  WAFFLE_PLATFORM_WAYLAND:
-return wayland_platform_create();
+wc_platform = wayland_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_X11_EGL
 case WAFFLE_PLATFORM_X11_EGL:
-return xegl_platform_create();
+wc_platform = xegl_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_GBM
 case WAFFLE_PLATFORM_GBM:
-return wgbm_platform_create();
+wc_platform = wgbm_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_WGL
 case WAFFLE_PLATFORM_WGL:
-return wgl_platform_create();
+wc_platform = wgl_platform_create();
+break;
 #endif
 #ifdef WAFFLE_HAS_NACL
 case WAFFLE_PLATFORM_NACL:
-return nacl_platform_create();
+wc_platform = nacl_platform_create();
+break;
 #endif
-default:
-assert(false);
-return NULL;
 }
+assert(wc_platform);
+wc_platform->waffle_platform = waffle_platform;
+return wc_platform;
 }
 
 WAFFLE_API bool
diff --git a/src/waffle/core/wcore_platform.h b/src/waffle/core/wcore_platform.h
index 780d07a..30d1c6c 100644
--- a/src/waffle/core/wcore_platform.h
+++ b/src/waffle/core/wcore_platform.h
@@ -139,6 +139,7 @@ struct wcore_platform_vtbl {
 
 struct wcore_platform {
 const struct wcore_platform_vtbl *vtbl;
+int32_t waffle_platform; // WAFFLE_PLATFORM_* enum
 };
 
 static inline bool
-- 
2.6.0.rc2.230.g3dd15c0

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


[waffle] [PATCH 12/12] x11_egl: implement platform-specific information

2016-01-06 Thread Frank Henigman
Implement the platform hook of waffle_display_info_json() so it can
pick up x11_egl-specific information.  So far only egl information is
provided, nothing specific to x11.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 src/waffle/xegl/xegl_platform.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/waffle/xegl/xegl_platform.c b/src/waffle/xegl/xegl_platform.c
index e36a41b..2f5e922 100644
--- a/src/waffle/xegl/xegl_platform.c
+++ b/src/waffle/xegl/xegl_platform.c
@@ -152,6 +152,7 @@ static const struct wcore_platform_vtbl xegl_platform_vtbl 
= {
 .connect = xegl_display_connect,
 .destroy = xegl_display_destroy,
 .supports_context_api = wegl_display_supports_context_api,
+.info_json = wegl_display_info_json,
 .get_native = xegl_display_get_native,
 },
 
-- 
2.6.0.rc2.230.g3dd15c0

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


[waffle] [PATCH 11/12] gbm: implement platform-specific information

2016-01-06 Thread Frank Henigman
Implement the platform hook of waffle_display_info_json() so it can
pick up gbm-specific information.  So far only egl information is
provided, nothing specific to gbm.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 src/waffle/gbm/wgbm_platform.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c
index 0fc0352..0d5675a 100644
--- a/src/waffle/gbm/wgbm_platform.c
+++ b/src/waffle/gbm/wgbm_platform.c
@@ -191,6 +191,7 @@ static const struct wcore_platform_vtbl wgbm_platform_vtbl 
= {
 .destroy = wgbm_display_destroy,
 .supports_context_api = wegl_display_supports_context_api,
 .get_native = wgbm_display_get_native,
+.info_json = wegl_display_info_json,
 },
 
 .config = {
-- 
2.6.0.rc2.230.g3dd15c0

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


[waffle] [PATCH 00/12] JSON and platform-specific wflinfo

2016-01-06 Thread Frank Henigman
This patch set does two main things, the second of which could just as
well be a separate patch set.
1-6: Move wflinfo functionality into the api, info returned as a json string.
7-12: Extend the functionality to include platform-specific info, such as
  provided by glxinfo.

After 1-6 wflinfo can be gutted to just get json from the api and present
it as desired (dump the json, legacy wflinfo format, glxinfo compatibility
format, verbose or not).  I do not have a patch for that yet.

Since another json patch set was recently posted, I'll point out how
this one differs...
This set moves wflinfo functionality into the api, the other extends
the wflinfo program.  Both options were discussed on the mailing list
in Feb 2015 and the former was favored.  This set includes a small
library for constructing json strings, with the aim of keeping string
building code as clear and simple as possible.  It also tries to write
one key:value per line to allow grepping in lieu of full json parsing.
Finally this set adds additional platform-specific info, though as
stated above that could be considered a follow-on.


Frank Henigman (12):
  core: store platform type in wcore_platform
  core: store context API in wcore_context
  core: store current context in wcore_display
  core: add JSON library
  waffle: add waffle_display_info_json()
  wflinfo: add option for JSON output
  waffle: support platform-specific information
  wflinfo: add flag for platform-specific info
  glx: implement platform-specific information
  egl: implement platform-specific information
  gbm: implement platform-specific information
  x11_egl: implement platform-specific information

 include/waffle/waffle.h  |   5 +
 man/waffle_display.3.xml |  19 +++
 src/utils/wflinfo.c  |  50 ++-
 src/waffle/CMakeLists.txt|   1 +
 src/waffle/api/waffle_display.c  | 292 ++-
 src/waffle/api/waffle_gl_misc.c  |  11 +-
 src/waffle/api/waffle_init.c |  32 +++--
 src/waffle/core/json.c   | 235 +++
 src/waffle/core/json.h   |  93 +
 src/waffle/core/wcore_context.h  |   2 +
 src/waffle/core/wcore_display.c  |   1 +
 src/waffle/core/wcore_display.h  |   2 +
 src/waffle/core/wcore_platform.h |   5 +
 src/waffle/egl/wegl_display.c|  32 -
 src/waffle/egl/wegl_display.h|   4 +
 src/waffle/egl/wegl_platform.h   |   3 +
 src/waffle/gbm/wgbm_platform.c   |   1 +
 src/waffle/glx/glx_display.c |  41 ++
 src/waffle/glx/glx_display.h |   4 +
 src/waffle/glx/glx_platform.c|   4 +
 src/waffle/glx/glx_platform.h|   3 +
 src/waffle/waffle.def.in |   1 +
 src/waffle/xegl/xegl_platform.c  |   1 +
 23 files changed, 820 insertions(+), 22 deletions(-)
 create mode 100644 src/waffle/core/json.c
 create mode 100644 src/waffle/core/json.h

-- 
2.6.0.rc2.230.g3dd15c0

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


[waffle] [PATCH 02/12] core: store context API in wcore_context

2016-01-06 Thread Frank Henigman
Facilitates api-specific code in core functions, like the forthcoming
wflinfo-like function.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 src/waffle/core/wcore_context.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/waffle/core/wcore_context.h b/src/waffle/core/wcore_context.h
index 3800113..451bbf7 100644
--- a/src/waffle/core/wcore_context.h
+++ b/src/waffle/core/wcore_context.h
@@ -40,6 +40,7 @@ union waffle_native_context;
 
 struct wcore_context {
 struct api_object api;
+int32_t context_api; // WAFFLE_CONTEXT_API enum, e.g. WAFFLE_CONTEXT_OPENGL
 struct wcore_display *display;
 };
 
@@ -61,6 +62,7 @@ wcore_context_init(struct wcore_context *self,
 assert(config);
 
 self->api.display_id = config->display->api.display_id;
+self->context_api = config->attrs.context_api;
 self->display = config->display;
 
 return true;
-- 
2.6.0.rc2.230.g3dd15c0

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


[waffle] [PATCH 05/12] waffle: add waffle_display_info_json()

2016-01-06 Thread Frank Henigman
Duplicate wflinfo functionality in the API, with the difference that the
information is returned in JSON form.
The function has a parameter for including platform-specific information,
but it is ignored for now.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 include/waffle/waffle.h |   5 +
 man/waffle_display.3.xml|  19 +++
 src/waffle/api/waffle_display.c | 284 +++-
 src/waffle/waffle.def.in|   1 +
 4 files changed, 308 insertions(+), 1 deletion(-)

diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index df0218e..1800399 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -214,6 +214,11 @@ bool
 waffle_display_supports_context_api(struct waffle_display *self,
 int32_t context_api);
 
+#if WAFFLE_API_VERSION >= 0x0106
+char*
+waffle_display_info_json(struct waffle_display *self, bool platform_too);
+#endif
+
 union waffle_native_display*
 waffle_display_get_native(struct waffle_display *self);
 
diff --git a/man/waffle_display.3.xml b/man/waffle_display.3.xml
index 9896247..5358472 100644
--- a/man/waffle_display.3.xml
+++ b/man/waffle_display.3.xml
@@ -24,6 +24,7 @@
 waffle_display
 waffle_display_connect
 waffle_display_disconnect
+waffle_display_info_json
 waffle_display_supports_context_api
 waffle_display_get_native
 class waffle_display
@@ -58,6 +59,12 @@ struct waffle_display;
   
 
   
+char* waffle_display_info_json
+struct waffle_display *self
+bool platform_info
+  
+
+  
 bool 
waffle_display_supports_context_api
 struct waffle_display *self
 int32_t context_api
@@ -129,6 +136,18 @@ struct waffle_display;
   
 
   
+waffle_display_info_json()
+
+  
+Return a JSON string containing information about the current 
context on the given display, including Waffle platform and API, GL 
version/vendor/renderer and extensions.
+If platform_info is true, platform-specific 
information (such as GLX or EGL versions and extensions) will be included as 
available.
+Returns NULL on error.
+The string should be deallocated with 
free3.
+  
+
+  
+
+  
 waffle_display_supports_context_api()
 
   
diff --git a/src/waffle/api/waffle_display.c b/src/waffle/api/waffle_display.c
index fa19462..7abe2ef 100644
--- a/src/waffle/api/waffle_display.c
+++ b/src/waffle/api/waffle_display.c
@@ -23,13 +23,61 @@
 // 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 "api_priv.h"
 
-#include "wcore_error.h"
+#include "json.h"
+
+#include "wcore_context.h"
 #include "wcore_display.h"
+#include "wcore_error.h"
 #include "wcore_platform.h"
 #include "wcore_util.h"
 
+typedef unsigned int GLint;
+typedef unsigned int GLenum;
+typedef unsigned char GLubyte;
+
+enum {
+// Copied from .
+GL_NO_ERROR = 0,
+
+GL_CONTEXT_FLAGS = 0x821e,
+GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT = 0x0001,
+GL_CONTEXT_FLAG_DEBUG_BIT  = 0x0002,
+GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB  = 0x0004,
+
+GL_VENDOR  = 0x1F00,
+GL_RENDERER= 0x1F01,
+GL_VERSION = 0x1F02,
+GL_EXTENSIONS  = 0x1F03,
+GL_NUM_EXTENSIONS  = 0x821D,
+GL_SHADING_LANGUAGE_VERSION= 0x8B8C,
+};
+
+#ifndef _WIN32
+#define APIENTRY
+#else
+#ifndef APIENTRY
+#define APIENTRY __stdcall
+#endif
+#endif
+
+static GLenum (APIENTRY *glGetError)(void);
+static void (APIENTRY *glGetIntegerv)(GLenum pname, GLint *params);
+static const GLubyte * (APIENTRY *glGetString)(GLenum name);
+static const GLubyte * (APIENTRY *glGetStringi)(GLenum name, GLint i);
+
+#if defined(__GNUC__)
+#define NORETURN __attribute__((noreturn))
+#elif defined(_MSC_VER)
+#define NORETURN __declspec(noreturn)
+#else
+#define NORETURN
+#endif
+
 WAFFLE_API struct waffle_display*
 waffle_display_connect(const char *name)
 {
@@ -90,6 +138,240 @@ waffle_display_supports_context_api(
 context_api);
 }
 
+static int
+parse_version(const char *version)
+{
+int count, major, minor;
+
+if (version == NULL)
+return 0;
+
+while (*version != '\0' && !isdigit(*version))
+version++;
+
+count = sscanf(version, "%d.%d", , );
+if (count != 2)
+return 0;
+
+if (minor > 9)
+return 0;
+
+return (major * 10) + minor;
+}
+
+static void
+add_context_flags(struct json *jj)
+{
+static struct {
+GLint flag;

[waffle] [PATCH 03/12] core: store current context in wcore_display

2016-01-06 Thread Frank Henigman
For core functions that need to know the current context, like the
forthcoming wflinfo-like function.

Signed-off-by: Frank Henigman <fjhenig...@google.com>
---
 src/waffle/api/waffle_gl_misc.c | 11 +++
 src/waffle/core/wcore_display.c |  1 +
 src/waffle/core/wcore_display.h |  2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/waffle/api/waffle_gl_misc.c b/src/waffle/api/waffle_gl_misc.c
index 138974d..4161ce8 100644
--- a/src/waffle/api/waffle_gl_misc.c
+++ b/src/waffle/api/waffle_gl_misc.c
@@ -94,10 +94,13 @@ waffle_make_current(
 if (!api_check_entry(obj_list, len))
 return false;
 
-return api_platform->vtbl->make_current(api_platform,
-wc_dpy,
-wc_window,
-wc_ctx);
+bool ok = api_platform->vtbl->make_current(api_platform,
+   wc_dpy,
+   wc_window,
+   wc_ctx);
+if (ok)
+wc_dpy->current_context = wc_ctx;
+return ok;
 }
 
 WAFFLE_API void*
diff --git a/src/waffle/core/wcore_display.c b/src/waffle/core/wcore_display.c
index 18262c3..bcaeacb 100644
--- a/src/waffle/core/wcore_display.c
+++ b/src/waffle/core/wcore_display.c
@@ -52,6 +52,7 @@ wcore_display_init(struct wcore_display *self,
 mtx_unlock();
 
 self->platform = platform;
+self->current_context = NULL;
 
 if (self->api.display_id == 0) {
 fprintf(stderr, "waffle: error: internal counter wrapped to 0\n");
diff --git a/src/waffle/core/wcore_display.h b/src/waffle/core/wcore_display.h
index 6e374e3..1ccff6f 100644
--- a/src/waffle/core/wcore_display.h
+++ b/src/waffle/core/wcore_display.h
@@ -37,12 +37,14 @@
 extern "C" {
 #endif
 
+struct wcore_context;
 struct wcore_display;
 struct wcore_platform;
 union waffle_native_display;
 
 struct wcore_display {
 struct api_object api;
+struct wcore_context *current_context;
 struct wcore_platform *platform;
 };
 
-- 
2.6.0.rc2.230.g3dd15c0

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


Re: [waffle] [RFC 1/3] wflinfo.c: split out flags struct

2015-12-27 Thread Frank Henigman
On Wed, Dec 16, 2015 at 8:37 PM,   wrote:
> From: Dylan Baker 
>
> This is groundwork for adding a json interface to wflinfo.
> ---
>  src/utils/wflinfo.c | 19 +++
>  1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
> index 268d4b8..905fd90 100644
> --- a/src/utils/wflinfo.c
> +++ b/src/utils/wflinfo.c
> @@ -487,17 +487,18 @@ print_extensions(bool use_stringi)
>  printf("\n");
>  }
>
> +static struct {
> +GLint flag;
> +char *str;
> +} flags[] = {
> +{ GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT, "FORWARD_COMPATIBLE" },
> +{ GL_CONTEXT_FLAG_DEBUG_BIT, "DEBUG" },
> +{ GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB, "ROBUST_ACCESS" },
> +};
> +
>  static void
>  print_context_flags(void)
>  {
> -static struct {
> -GLint flag;
> -char *str;
> -} flags[] = {
> -{ GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT, "FORWARD_COMPATIBLE" },
> -{ GL_CONTEXT_FLAG_DEBUG_BIT, "DEBUG" },
> -{ GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB, "ROBUST_ACCESS" },
> -};
>  int flag_count = sizeof(flags) / sizeof(flags[0]);
>  GLint context_flags = 0;
>
> @@ -526,6 +527,8 @@ print_context_flags(void)
>  }
>  }
>  printf("\n");
> +
> +return;

Not a big deal but I don't see the point of adding this return.

>  }
>
>  /// @brief Print out information about the context that was created.
> --
> 2.6.4
>
> ___
> waffle mailing list
> waffle@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/waffle
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [RFC 2/3] wflinfo.c: split version, renderer, and vendor checks

2015-12-27 Thread Frank Henigman
On Wed, Dec 16, 2015 at 8:37 PM,   wrote:
> From: Dylan Baker 
>
> Pull these out into helper functions, this change will be used in a
> following patch to add a json printer.
>
> Signed-off-by: Dylan Baker 
> ---
>  src/utils/wflinfo.c | 50 --
>  1 file changed, 36 insertions(+), 14 deletions(-)
>
> diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
> index 905fd90..b843757 100644
> --- a/src/utils/wflinfo.c
> +++ b/src/utils/wflinfo.c
> @@ -458,6 +458,39 @@ parse_version(const char *version)
>  return (major * 10) + minor;
>  }
>
> +static const char *
> +get_vendor(void)
> +{
> +const char *vendor = (const char *) glGetString(GL_VENDOR);
> +if (glGetError() != GL_NO_ERROR || vendor == NULL) {
> +vendor = "WFLINFO_GL_ERROR";
> +}
> +
> +return vendor;
> +}
> +
> +static const char *
> +get_renderer(void)
> +{
> +const char *renderer = (const char *) glGetString(GL_RENDERER);
> +if (glGetError() != GL_NO_ERROR || renderer == NULL) {
> +renderer = "WFLINFO_GL_ERROR";
> +}
> +
> +return renderer;
> +}
> +
> +static const char *
> +get_version(void)
> +{
> +const char *version_str = (const char *) glGetString(GL_VERSION);
> +if (glGetError() != GL_NO_ERROR || version_str == NULL) {
> +version_str = "WFLINFO_GL_ERROR";
> +}
> +
> +return version_str;
> +}
> +
>  static void
>  print_extensions(bool use_stringi)
>  {
> @@ -539,20 +572,9 @@ print_wflinfo(const struct options *opts)
>  /* Clear all errors */
>  }
>
> -const char *vendor = (const char *) glGetString(GL_VENDOR);
> -if (glGetError() != GL_NO_ERROR || vendor == NULL) {
> -vendor = "WFLINFO_GL_ERROR";
> -}
> -
> -const char *renderer = (const char *) glGetString(GL_RENDERER);
> -if (glGetError() != GL_NO_ERROR || renderer == NULL) {
> -renderer = "WFLINFO_GL_ERROR";
> -}
> -
> -const char *version_str = (const char *) glGetString(GL_VERSION);
> -if (glGetError() != GL_NO_ERROR || version_str == NULL) {
> -version_str = "WFLINFO_GL_ERROR";
> -}
> +const char * vendor =  get_vendor();
> +const char * renderer = get_renderer();
> +const char * version_str = get_version();

nit: usually no space after *

>  const char *platform = enum_map_to_str(platform_map, opts->platform);
>  assert(platform != NULL);
> --
> 2.6.4
>
> ___
> waffle mailing list
> waffle@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/waffle
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [RFC 0/3] Add JSON output to wflinfo

2015-12-27 Thread Frank Henigman
On Wed, Dec 16, 2015 at 8:37 PM,   wrote:
> From: Dylan Baker 
>
> This is a pretty rough RFC for adding JSON output to wflinfo. The
> intended consumer of this feature is piglit, for use with the
> fast-skipping mechanism. This mechanism currently parses the human
> readable form of wflinfo, but this seems less than ideal, and I remember
> someone else (I think from google), asking for json formatted output
> from wflinfo.

That may have been me.  I actually implemented stuff but never sent it
to the list.
Sorry, I might have saved you some you some work if I'd made the
effort to land my version.
I'll comment on your version then send my own and after some
discussion on the list one or the other or some combination ought to
land.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 4/4] wflinfo: use waffle_string_to_enum()

2015-04-22 Thread Frank Henigman
Remove platform and api lists, and instead use waffle_string_to_enum()
to parse command line platform and api arguments.
Also use waffle_enum_to_string() when printing platform and api.
This means it now prints GLX instead of glx and GL_ES2 instead of
gles2, for example.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/utils/wflinfo.c | 80 -
 1 file changed, 11 insertions(+), 69 deletions(-)

diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
index 268d4b8..f75ffc0 100644
--- a/src/utils/wflinfo.c
+++ b/src/utils/wflinfo.c
@@ -237,10 +237,10 @@ static const GLubyte * (APIENTRY *glGetStringi)(GLenum 
name, GLint i);
 /// @brief Command line options.
 struct options {
 /// @brief One of `WAFFLE_PLATFORM_*`.
-int platform;
+int32_t platform;
 
 /// @brief One of `WAFFLE_CONTEXT_OPENGL_*`.
-int context_api;
+int32_t context_api;
 
 /// @brief One of `WAFFLE_CONTEXT_PROFILE_*` or `WAFFLE_NONE`.
 int context_profile;
@@ -257,70 +257,12 @@ struct options {
 int dl;
 };
 
-struct enum_map {
-int i;
-const char *s;
-};
-
-static const struct enum_map platform_map[] = {
-{WAFFLE_PLATFORM_ANDROID,   android   },
-{WAFFLE_PLATFORM_CGL,   cgl,  },
-{WAFFLE_PLATFORM_GBM,   gbm   },
-{WAFFLE_PLATFORM_GLX,   glx   },
-{WAFFLE_PLATFORM_WAYLAND,   wayland   },
-{WAFFLE_PLATFORM_WGL,   wgl   },
-{WAFFLE_PLATFORM_X11_EGL,   x11_egl   },
-{0, 0   },
-};
-
-static const struct enum_map context_api_map[] = {
-{WAFFLE_CONTEXT_OPENGL, gl},
-{WAFFLE_CONTEXT_OPENGL_ES1, gles1 },
-{WAFFLE_CONTEXT_OPENGL_ES2, gles2 },
-{WAFFLE_CONTEXT_OPENGL_ES3, gles3 },
-{0, 0   },
-};
-
-/// @brief Translate string to `enum waffle_enum`.
-///
-/// @param self is a list of map items. The last item must be zero-filled.
-/// @param result is altered only if @a s if found.
-/// @return true if @a s was found in @a map.
-static bool
-enum_map_translate_str(
-const struct enum_map *self,
-const char *s,
-int *result)
-{
-for (const struct enum_map *i = self; i-i != 0; ++i) {
-if (!strncmp(s, i-s, strlen(i-s) + 1)) {
-*result = i-i;
-return true;
-}
-}
-
-return false;
-}
-
-static const char *
-enum_map_to_str(const struct enum_map *self,
-int val)
-{
-for (const struct enum_map *i = self; i-i != 0; ++i) {
-if (i-i == val) {
-return i-s;
-}
-}
-
-return NULL;
-}
-
 /// @return true on success.
 static bool
 parse_args(int argc, char *argv[], struct options *opts)
 {
-bool ok;
 bool loop_get_opt = true;
+char ename[99];
 
 #ifdef __APPLE__
 removeXcodeArgs(argc, argv);
@@ -343,17 +285,15 @@ parse_args(int argc, char *argv[], struct options *opts)
 case '?':
 goto error_unrecognized_arg;
 case OPT_PLATFORM:
-ok = enum_map_translate_str(platform_map, optarg,
-opts-platform);
-if (!ok) {
+snprintf(ename, sizeof(ename), WAFFLE_PLATFORM_%s, optarg);
+if (!waffle_string_to_enum(ename, opts-platform)) {
 usage_error_printf('%s' is not a valid platform,
optarg);
 }
 break;
 case OPT_API:
-ok = enum_map_translate_str(context_api_map, optarg,
-opts-context_api);
-if (!ok) {
+snprintf(ename, sizeof(ename), WAFFLE_CONTEXT_OPEN%s, 
optarg);
+if (!waffle_string_to_enum(ename, opts-context_api)) {
 usage_error_printf('%s' is not a valid API for an OpenGL 
context, optarg);
 }
@@ -551,12 +491,14 @@ print_wflinfo(const struct options *opts)
 version_str = WFLINFO_GL_ERROR;
 }
 
-const char *platform = enum_map_to_str(platform_map, opts-platform);
+const char *platform = waffle_enum_to_string(opts-platform);
 assert(platform != NULL);
+platform += sizeof WAFFLE_PLATFORM_ - 1;
 printf(Waffle platform: %s\n, platform);
 
-const char *api = enum_map_to_str(context_api_map, opts-context_api);
+const char *api = waffle_enum_to_string(opts-context_api);
 assert(api != NULL);
+api += sizeof WAFFLE_CONTEXT_OPEN - 1;
 printf(Waffle api: %s\n, api);
 
 printf(OpenGL vendor string: %s\n, vendor);
-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH 0/4] waffle_string_to_enum()

2015-04-22 Thread Frank Henigman
Here is waffle_string_to_enum() which I suggested a while back.
The main motivation is the number of waffle applications which need
to translate command line args to a platform and api.
Not only do we avoid writing that code over and over (perhaps inconsistently),
but now those programs won't need to be updated when waffle gets a new
platform; they should just work with the new platform.
I've updated wflinfo as proof of concept.  If people like this I'll
do gl_basic too.

Frank Henigman (4):
  waffle: put waffle_enum items in a macro
  waffle: use enum list in waffle_enum_to_string()
  waffle: add waffle_string_to_enum()
  wflinfo: use waffle_string_to_enum()

 include/waffle/waffle.h  | 155 ---
 man/waffle_enum.3.xml|  24 +++
 src/utils/wflinfo.c  |  80 +++---
 src/waffle/api/waffle_enum.c |   7 ++
 src/waffle/core/wcore_util.c | 130 +++-
 src/waffle/core/wcore_util.h |   3 +
 src/waffle/waffle.def.in |   1 +
 7 files changed, 215 insertions(+), 185 deletions(-)

-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH 1/4] waffle: put waffle_enum items in a macro

2015-04-22 Thread Frank Henigman
List all waffle_enum items in a big #define to avoid duplicating
the list when a case is needed for each item, e.g. enum to string.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 include/waffle/waffle.h | 150 ++--
 1 file changed, 81 insertions(+), 69 deletions(-)

diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index 297a487..dd39f2c 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -98,80 +98,92 @@ waffle_error_to_string(enum waffle_error e);
 // waffle_enum
 // ---
 
-enum waffle_enum {
-// --
-// Generic
-// --
-
-WAFFLE_DONT_CARE= -1,
-WAFFLE_NONE =  0,
-
-// --
-// For waffle_init()
-// --
-
-WAFFLE_PLATFORM = 0x0010,
-WAFFLE_PLATFORM_ANDROID = 0x0011,
-WAFFLE_PLATFORM_CGL = 0x0012,
-WAFFLE_PLATFORM_GLX = 0x0013,
-WAFFLE_PLATFORM_WAYLAND = 0x0014,
-WAFFLE_PLATFORM_X11_EGL = 0x0015,
-WAFFLE_PLATFORM_GBM = 0x0016,
-WAFFLE_PLATFORM_WGL = 0x0017,
-WAFFLE_PLATFORM_NACL= 0x0018,
-
-// --
-// For waffle_config_choose()
-// --
-
-WAFFLE_CONTEXT_API  = 0x020a,
-WAFFLE_CONTEXT_OPENGL   = 0x020b,
-WAFFLE_CONTEXT_OPENGL_ES1   = 0x020c,
-WAFFLE_CONTEXT_OPENGL_ES2   = 0x020d,
-WAFFLE_CONTEXT_OPENGL_ES3   = 0x0214,
-
-WAFFLE_CONTEXT_MAJOR_VERSION= 0x020e,
-WAFFLE_CONTEXT_MINOR_VERSION= 0x020f,
-
-WAFFLE_CONTEXT_PROFILE  = 0x0210,
-WAFFLE_CONTEXT_CORE_PROFILE = 0x0211,
-WAFFLE_CONTEXT_COMPATIBILITY_PROFILE= 0x0212,
+#define WAFFLE_ENUM_LIST_ANY(f) \
+/* */ \
+/* Generic */ \
+/* */ \
+  \
+f(WAFFLE_DONT_CARE  , -1) \
+f(WAFFLE_NONE   ,  0) \
+  \
+/* */ \
+/* For waffle_init()   */ \
+/* */ \
+  \
+f(WAFFLE_PLATFORM   , 0x0010) \
+f(WAFFLE_PLATFORM_ANDROID   , 0x0011) \
+f(WAFFLE_PLATFORM_CGL   , 0x0012) \
+f(WAFFLE_PLATFORM_GLX   , 0x0013) \
+f(WAFFLE_PLATFORM_WAYLAND   , 0x0014) \
+f(WAFFLE_PLATFORM_X11_EGL   , 0x0015) \
+f(WAFFLE_PLATFORM_GBM   , 0x0016) \
+f(WAFFLE_PLATFORM_WGL   , 0x0017) \
+f(WAFFLE_PLATFORM_NACL  , 0x0018) \
+  \
+/* */ \
+/* For waffle_config_choose()  */ \
+/* */ \
+  \
+f(WAFFLE_CONTEXT_API, 0x020a) \
+f(WAFFLE_CONTEXT_OPENGL , 0x020b) \
+f(WAFFLE_CONTEXT_OPENGL_ES1 , 0x020c) \
+f(WAFFLE_CONTEXT_OPENGL_ES2

Re: [waffle] [PATCH 1/4] waffle: put waffle_enum items in a macro

2015-04-22 Thread Frank Henigman
On Wed, Apr 22, 2015 at 8:09 PM, Jordan Justen
jordan.l.jus...@intel.com wrote:
 On 2015-04-22 11:03:47, Frank Henigman wrote:
 List all waffle_enum items in a big #define to avoid duplicating
 the list when a case is needed for each item, e.g. enum to string.

 This looks kind of yucky. :)

 When you recently mentioned the idea of changing wflinfo to be written
 in python, it made me think about python bindings for waffle.

 This lead me to think that it might be nice if the waffle API was
 defined by something like XML. This would allow us to generate
 waffle.h, python bindings, and things like this enum to string
 mapping.

 We do something similar (enum to string mapping) on the OpenGL API in
 piglit.

 -Jordan

There seem to be three ways to generate the desired code:
- manually repeating lists of stuff
- with the preprocessor, as in this patch
- with external definitions and scripts
What's the right tool for job?  Repetition might be ok if you only
need something in a couple places, but gets old fast if you have to
edit six places every time you want to add an item to a list.  XML and
scripts might be appropriate if you need to do something complicated,
something the preprocessor can't do.
I chose middle ground here, to get rid of repetition as simply as possible.
FWIW the macro list pattern has already been introduced to waffle.
See wgbm_platform.h.

Is your objection purely for aesthetic reasons or is there some
technical drawback?
If aesthetics are important, would it make any difference if we move
the list macro out of the public header and into a private header?
Then we'd be repeating the list once, but subsequent uses would employ
the private macro.  Though this would also deprive waffle users of the
chance to use the macro.

Yucky is in the eye of the beholder.  (^:
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH 08/10] wflinfo: add 'null' platform

2015-03-30 Thread Frank Henigman
Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/utils/wflinfo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
index 268d4b8..0a58aab 100644
--- a/src/utils/wflinfo.c
+++ b/src/utils/wflinfo.c
@@ -62,7 +62,7 @@ static const char *usage_message =
 \n
 Required Parameters:\n
 -p, --platform\n
-One of: android, cgl, gbm, glx, wayland, wgl or x11_egl\n
+One of: android, cgl, gbm, glx, null, wayland, wgl or x11_egl\n
 \n
 -a, --api\n
 One of: gl, gles1, gles2 or gles3\n
@@ -267,6 +267,7 @@ static const struct enum_map platform_map[] = {
 {WAFFLE_PLATFORM_CGL,   cgl,  },
 {WAFFLE_PLATFORM_GBM,   gbm   },
 {WAFFLE_PLATFORM_GLX,   glx   },
+{WAFFLE_PLATFORM_NULL,  null  },
 {WAFFLE_PLATFORM_WAYLAND,   wayland   },
 {WAFFLE_PLATFORM_WGL,   wgl   },
 {WAFFLE_PLATFORM_X11_EGL,   x11_egl   },
-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH 10/10] waffle: add 'null' platform

2015-03-30 Thread Frank Henigman
The 'null' platform (WAFFLE_PLATFORM_NULL) works with EGL_PLATFORM_NULL,
KHR_surfaceless_context and EXT_image_dma_buf_import to hide surfaceless
operation behind a waffle window.
In this platform waffle windows contain gbm buffers which GLES renders
into via dmabuf - EGL image - GL framebuffer.
The gbm buffers can be displayed via DRM/KMS.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 LICENSE.txt|   5 +
 Options.cmake  |   8 +
 cmake/Modules/WaffleDefineCompilerFlags.cmake  |   4 +
 cmake/Modules/WaffleFindDependencies.cmake |   3 +
 .../Modules/WafflePrintConfigurationSummary.cmake  |   3 +
 include/CMakeLists.txt |   1 +
 include/waffle/waffle.h|  13 +
 include/waffle/waffle_null.h   |  65 +++
 src/waffle/CMakeLists.txt  |  19 +
 src/waffle/api/waffle_init.c   |  11 +
 src/waffle/core/wcore_util.c   |   1 +
 src/waffle/null/wnull_context.c|  87 +++
 src/waffle/null/wnull_context.h|  62 ++
 src/waffle/null/wnull_display.c| 631 +
 src/waffle/null/wnull_display.h|  93 +++
 src/waffle/null/wnull_platform.c   | 103 
 src/waffle/null/wnull_platform.h   |  10 +
 src/waffle/null/wnull_window.c | 495 
 src/waffle/null/wnull_window.h |  44 ++
 19 files changed, 1658 insertions(+)
 create mode 100644 include/waffle/waffle_null.h
 create mode 100644 src/waffle/null/wnull_context.c
 create mode 100644 src/waffle/null/wnull_context.h
 create mode 100644 src/waffle/null/wnull_display.c
 create mode 100644 src/waffle/null/wnull_display.h
 create mode 100644 src/waffle/null/wnull_platform.c
 create mode 100644 src/waffle/null/wnull_platform.h
 create mode 100644 src/waffle/null/wnull_window.c
 create mode 100644 src/waffle/null/wnull_window.h

diff --git a/LICENSE.txt b/LICENSE.txt
index c6993ac..55e257b 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,5 @@
 Copyright 2012 Intel Corporation
+Copyright (c) 2015, Google Inc.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -11,6 +12,10 @@ modification, are permitted provided that the following 
conditions are met:
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
 
+- Neither the name of Google Inc. nor the names of its contributors may be used
+  to endorse or promote products derived from this software without specific
+  prior written permission.
+
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
diff --git a/Options.cmake b/Options.cmake
index 4f097a0..d6edf21 100644
--- a/Options.cmake
+++ b/Options.cmake
@@ -23,6 +23,12 @@ if(waffle_on_linux)
 set(gbm_default OFF)
 endif()
 
+if(gbm_FOUND AND libudev_FOUND AND egl_FOUND AND libdrm_FOUND)
+set(null_default ON)
+else()
+set(null_default OFF)
+endif()
+
 # On Linux, you must enable at least one of the below options.
 option(waffle_has_glx Build support for GLX ${glx_default})
 option(waffle_has_wayland Build support for Wayland ${wayland_default})
@@ -33,6 +39,8 @@ if(waffle_on_linux)
 # NaCl specific settings.
 set(nacl_sdk_path  CACHE STRING Set nacl_sdk path here)
 set(nacl_version pepper_39 CACHE STRING Set NaCl bundle here)
+
+option(waffle_has_null Build support for Null ${null_default})
 endif()
 
 option(waffle_build_tests Build tests ON)
diff --git a/cmake/Modules/WaffleDefineCompilerFlags.cmake 
b/cmake/Modules/WaffleDefineCompilerFlags.cmake
index 679d09c..00bbeea 100644
--- a/cmake/Modules/WaffleDefineCompilerFlags.cmake
+++ b/cmake/Modules/WaffleDefineCompilerFlags.cmake
@@ -118,6 +118,10 @@ if(waffle_on_linux)
 add_definitions(-DWAFFLE_HAS_GBM)
 endif()
 
+if(waffle_has_null)
+add_definitions(-DWAFFLE_HAS_NULL)
+endif()
+
 if(waffle_has_tls)
 add_definitions(-DWAFFLE_HAS_TLS)
 endif()
diff --git a/cmake/Modules/WaffleFindDependencies.cmake 
b/cmake/Modules/WaffleFindDependencies.cmake
index 3fd7338..110c2b4 100644
--- a/cmake/Modules/WaffleFindDependencies.cmake
+++ b/cmake/Modules/WaffleFindDependencies.cmake
@@ -79,6 +79,9 @@ if(waffle_on_linux)
 # waffle_has_gbm
 waffle_pkg_config(gbm gbm)
 waffle_pkg_config(libudev libudev)
+
+# waffle_has_null
+waffle_pkg_config(libdrm libdrm)
 endif()
 
 
diff --git a/cmake/Modules/WafflePrintConfigurationSummary.cmake 
b/cmake/Modules/WafflePrintConfigurationSummary.cmake
index 1199ea3..13d0dbe

[waffle] [PATCH 03/10] gbm: make wgbm_get_default_fd_for_pattern public

2015-03-30 Thread Frank Henigman
Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/waffle/gbm/wgbm_display.c | 2 +-
 src/waffle/gbm/wgbm_display.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/waffle/gbm/wgbm_display.c b/src/waffle/gbm/wgbm_display.c
index 76e6c32..b46524a 100644
--- a/src/waffle/gbm/wgbm_display.c
+++ b/src/waffle/gbm/wgbm_display.c
@@ -65,7 +65,7 @@ wgbm_display_destroy(struct wcore_display *wc_self)
 return ok;
 }
 
-static int
+int
 wgbm_get_default_fd_for_pattern(const char *pattern)
 {
 struct udev *ud;
diff --git a/src/waffle/gbm/wgbm_display.h b/src/waffle/gbm/wgbm_display.h
index ba4bb89..e19664a 100644
--- a/src/waffle/gbm/wgbm_display.h
+++ b/src/waffle/gbm/wgbm_display.h
@@ -65,3 +65,6 @@ wgbm_display_get_native(struct wcore_display *wc_self);
 void
 wgbm_display_fill_native(struct wgbm_display *self,
  struct waffle_gbm_display *n_dpy);
+
+int
+wgbm_get_default_fd_for_pattern(const char *pattern);
-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH 07/10] waffle: add full screen window request

2015-03-30 Thread Frank Henigman
You can now put WAFFLE_WINDOW_FULLSCREEN in the attribute list passed
to waffle_window_create2() and get a full screen window.
Only glx and x11_egl implemented so far.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 include/waffle/waffle.h|  1 +
 src/waffle/api/waffle_window.c | 69 ++
 src/waffle/glx/glx_window.c| 12 ++--
 src/waffle/xegl/xegl_window.c  | 13 ++--
 4 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index 297a487..df0218e 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -172,6 +172,7 @@ enum waffle_enum {
 
 WAFFLE_WINDOW_WIDTH = 0x0310,
 WAFFLE_WINDOW_HEIGHT= 0x0311,
+WAFFLE_WINDOW_FULLSCREEN= 0x0312,
 };
 
 const char*
diff --git a/src/waffle/api/waffle_window.c b/src/waffle/api/waffle_window.c
index 9ab63ca..10004c0 100644
--- a/src/waffle/api/waffle_window.c
+++ b/src/waffle/api/waffle_window.c
@@ -42,6 +42,7 @@ waffle_window_create2(
 struct wcore_config *wc_config = wcore_config(config);
 intptr_t *attrib_list_filtered = NULL;
 intptr_t width = 0, height = 0;
+intptr_t unused;
 
 const struct api_object *obj_list[] = {
 wc_config ? wc_config-api : NULL,
@@ -53,38 +54,42 @@ waffle_window_create2(
 
 attrib_list_filtered = wcore_attrib_list_copy(attrib_list);
 
-if (!wcore_attrib_list_pop(attrib_list_filtered,
-   WAFFLE_WINDOW_WIDTH, width)) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- required attribute WAFFLE_WINDOW_WIDTH is missing);
-goto done;
-}
-
-if (!wcore_attrib_list_pop(attrib_list_filtered,
-   WAFFLE_WINDOW_HEIGHT, height)) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- required attribute WAFFLE_WINDOW_HEIGHT is missing);
-goto done;
-}
-
-if (width = 0) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- WAFFLE_WINDOW_WIDTH is not positive);
-goto done;
-} else if (width  INT32_MAX) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- WAFFLE_WINDOW_WIDTH is greater than INT32_MAX);
-goto done;
-}
-
-if (height = 0) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- WAFFLE_WINDOW_HEIGHT is not positive);
-goto done;
-} else if (height  INT32_MAX) {
-wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
- WAFFLE_WINDOW_HEIGHT is greater than INT32_MAX);
-goto done;
+if (!wcore_attrib_list_get(attrib_list_filtered,
+   WAFFLE_WINDOW_FULLSCREEN, unused)) {
+
+if (!wcore_attrib_list_pop(attrib_list_filtered,
+   WAFFLE_WINDOW_WIDTH, width)) {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ required attribute WAFFLE_WINDOW_WIDTH is missing);
+goto done;
+}
+
+if (!wcore_attrib_list_pop(attrib_list_filtered,
+   WAFFLE_WINDOW_HEIGHT, height)) {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ required attribute WAFFLE_WINDOW_HEIGHT is missing);
+goto done;
+}
+
+if (width = 0) {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ WAFFLE_WINDOW_WIDTH is not positive);
+goto done;
+} else if (width  INT32_MAX) {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ WAFFLE_WINDOW_WIDTH is greater than INT32_MAX);
+goto done;
+}
+
+if (height = 0) {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ WAFFLE_WINDOW_HEIGHT is not positive);
+goto done;
+} else if (height  INT32_MAX) {
+wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ WAFFLE_WINDOW_HEIGHT is greater than INT32_MAX);
+goto done;
+}
 }
 
 wc_self = api_platform-vtbl-window.create(api_platform,
diff --git a/src/waffle/glx/glx_window.c b/src/waffle/glx/glx_window.c
index 331bb51..8be188c 100644
--- a/src/waffle/glx/glx_window.c
+++ b/src/waffle/glx/glx_window.c
@@ -61,9 +61,17 @@ glx_window_create(struct wcore_platform *wc_plat,
 struct glx_display *dpy = glx_display(wc_config-display);
 struct glx_config *config = glx_config(wc_config);
 bool ok = true;
+intptr_t unused;
+size_t expect = 0;
 
-if (wcore_attrib_list_length(attrib_list)  0) {
-wcore_error_bad_attribute(attrib_list[0]);
+if (wcore_attrib_list_get(attrib_list, WAFFLE_WINDOW_FULLSCREEN, unused)) 
{
+width = DisplayWidth(dpy-x11.xlib, dpy-x11.screen);
+height = DisplayHeight(dpy-x11.xlib, dpy-x11.screen

[waffle] [PATCH 05/10] wegl: add EGL image create/destroy

2015-03-30 Thread Frank Henigman
From: Frank Henigman fjhenig...@gmail.com

Store EGLImageCreateKHR and EGLImageDestroyKHR in the EGL platform struct.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/waffle/egl/wegl_platform.c | 9 -
 src/waffle/egl/wegl_platform.h | 4 
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/waffle/egl/wegl_platform.c b/src/waffle/egl/wegl_platform.c
index 800025e..0c9eb44 100644
--- a/src/waffle/egl/wegl_platform.c
+++ b/src/waffle/egl/wegl_platform.c
@@ -72,8 +72,11 @@ wegl_platform_init(struct wegl_platform *self)
 goto error;
 }
 
+#define OPTIONAL_EGL_SYMBOL(function)  \
+self-function = dlsym(self-eglHandle, #function);
+
 #define RETRIEVE_EGL_SYMBOL(function)  \
-self-function = dlsym(self-eglHandle, #function);\
+OPTIONAL_EGL_SYMBOL(function)  \
 if (!self-function) { \
 wcore_errorf(WAFFLE_ERROR_FATAL, \
  dlsym(\%s\, \ #function \) failed: %s,\
@@ -82,6 +85,9 @@ wegl_platform_init(struct wegl_platform *self)
 goto error;\
 }
 
+OPTIONAL_EGL_SYMBOL(eglCreateImageKHR);
+OPTIONAL_EGL_SYMBOL(eglDestroyImageKHR);
+
 RETRIEVE_EGL_SYMBOL(eglMakeCurrent);
 RETRIEVE_EGL_SYMBOL(eglGetProcAddress);
 
@@ -106,6 +112,7 @@ wegl_platform_init(struct wegl_platform *self)
 RETRIEVE_EGL_SYMBOL(eglDestroySurface);
 RETRIEVE_EGL_SYMBOL(eglSwapBuffers);
 
+#undef OPTIONAL_EGL_SYMBOL
 #undef RETRIEVE_EGL_SYMBOL
 
 error:
diff --git a/src/waffle/egl/wegl_platform.h b/src/waffle/egl/wegl_platform.h
index 645c3f8..7ae0490 100644
--- a/src/waffle/egl/wegl_platform.h
+++ b/src/waffle/egl/wegl_platform.h
@@ -26,6 +26,7 @@
 #pragma once
 
 #include EGL/egl.h
+#include EGL/eglext.h
 
 #include wcore_platform.h
 #include wcore_util.h
@@ -68,6 +69,9 @@ struct wegl_platform {
  const EGLint *attrib_list);
 EGLBoolean (*eglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
 EGLBoolean (*eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
+
+EGLImageKHR (*eglCreateImageKHR) (EGLDisplay dpy, EGLContext ctx, EGLenum 
target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLBoolean (*eglDestroyImageKHR)(EGLDisplay dpy, EGLImageKHR image);
 };
 
 DEFINE_CONTAINER_CAST_FUNC(wegl_platform,
-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH 06/10] gbm: wegl_display ok in wgbm_config_get_gbm_format

2015-03-30 Thread Frank Henigman
From: Frank Henigman fjhenig...@gmail.com

wgbm_config_get_gbm_format() does not need to cast the display all the
way to wgbm_display; wegl_display is far enough.
Now wgbm_config_get_gbm_format() can be used outside of the gbm platform.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/waffle/gbm/wgbm_config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/waffle/gbm/wgbm_config.c b/src/waffle/gbm/wgbm_config.c
index 67470d5..1d64b71 100644
--- a/src/waffle/gbm/wgbm_config.c
+++ b/src/waffle/gbm/wgbm_config.c
@@ -55,10 +55,10 @@ wgbm_config_get_gbm_format(struct wcore_platform *wc_plat,
struct wcore_config *wc_config)
 {
 EGLint gbm_format;
-struct wgbm_display *dpy = wgbm_display(wc_display);
+struct wegl_display *dpy = wegl_display(wc_display);
 struct wegl_platform *plat = wegl_platform(wc_plat);
 struct wegl_config *egl_config = wegl_config(wc_config);
-bool ok = plat-eglGetConfigAttrib(dpy-wegl.egl,
+bool ok = plat-eglGetConfigAttrib(dpy-egl,
egl_config-egl,
EGL_NATIVE_VISUAL_ID,
gbm_format);
-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH 01/10] wegl: enable deriving from wegl_context

2015-03-30 Thread Frank Henigman
Factor out init and teardown functions from create and destroy
so a derived class can use them on its embedded wegl_context object.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/waffle/egl/wegl_context.c | 79 +++
 src/waffle/egl/wegl_context.h | 10 --
 2 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/src/waffle/egl/wegl_context.c b/src/waffle/egl/wegl_context.c
index 2aec0dd..0f4c784 100644
--- a/src/waffle/egl/wegl_context.c
+++ b/src/waffle/egl/wegl_context.c
@@ -68,7 +68,6 @@ create_real_context(struct wegl_config *config,
 struct wegl_display *dpy = wegl_display(config-wcore.display);
 struct wegl_platform *plat = wegl_platform(dpy-wcore.platform);
 struct wcore_config_attrs *attrs = config-wcore.attrs;
-bool ok = true;
 int32_t waffle_context_api = attrs-context_api;
 EGLint attrib_list[64];
 EGLint context_flags = 0;
@@ -144,9 +143,8 @@ create_real_context(struct wegl_config *config,
 
 attrib_list[i++] = EGL_NONE;
 
-ok = bind_api(plat, waffle_context_api);
-if (!ok)
-return false;
+if (!bind_api(plat, waffle_context_api))
+return EGL_NO_CONTEXT;
 
 EGLContext ctx = plat-eglCreateContext(dpy-egl, config-egl,
 share_ctx, attrib_list);
@@ -156,22 +154,15 @@ create_real_context(struct wegl_config *config,
 return ctx;
 }
 
-struct wcore_context*
-wegl_context_create(struct wcore_platform *wc_plat,
-struct wcore_config *wc_config,
-struct wcore_context *wc_share_ctx)
+bool
+wegl_context_init(struct wegl_context *ctx,
+  struct wcore_config *wc_config,
+  struct wcore_context *wc_share_ctx)
 {
-struct wegl_context *ctx;
 struct wegl_config *config = wegl_config(wc_config);
 struct wegl_context *share_ctx = wegl_context(wc_share_ctx);
 bool ok;
 
-(void) wc_plat;
-
-ctx = wcore_calloc(sizeof(*ctx));
-if (!ctx)
-return NULL;
-
 ok = wcore_context_init(ctx-wcore, config-wcore);
 if (!ok)
 goto fail;
@@ -179,40 +170,68 @@ wegl_context_create(struct wcore_platform *wc_plat,
 ctx-egl = create_real_context(config,
share_ctx
? share_ctx-egl
-   : NULL);
-if (!ctx-egl)
+   : EGL_NO_CONTEXT);
+if (ctx-egl == EGL_NO_CONTEXT)
 goto fail;
 
-return ctx-wcore;
+return true;
 
 fail:
+wegl_context_teardown(ctx);
+return false;
+}
+
+struct wcore_context*
+wegl_context_create(struct wcore_platform *wc_plat,
+struct wcore_config *wc_config,
+struct wcore_context *wc_share_ctx)
+{
+struct wegl_context *ctx;
+
+(void) wc_plat;
+
+ctx = wcore_calloc(sizeof(*ctx));
+if (!ctx)
+return NULL;
+
+if (wegl_context_init(ctx, wc_config, wc_share_ctx))
+return ctx-wcore;
+
 wegl_context_destroy(ctx-wcore);
 return NULL;
 }
 
 bool
-wegl_context_destroy(struct wcore_context *wc_ctx)
+wegl_context_teardown(struct wegl_context *ctx)
 {
-struct wegl_display *dpy = wegl_display(wc_ctx-display);
-struct wegl_platform *plat = wegl_platform(dpy-wcore.platform);
-struct wegl_context *ctx;
 bool result = true;
 
-if (!wc_ctx)
+if (!ctx)
 return result;
 
-ctx = wegl_context(wc_ctx);
+if (ctx-egl != EGL_NO_CONTEXT) {
+struct wegl_display *dpy = wegl_display(ctx-wcore.display);
+struct wegl_platform *plat = wegl_platform(dpy-wcore.platform);
 
-if (ctx-egl) {
-bool ok = plat-eglDestroyContext(wegl_display(wc_ctx-display)-egl,
-  ctx-egl);
-if (!ok) {
+if (!plat-eglDestroyContext(dpy-egl, ctx-egl)) {
 wegl_emit_error(plat, eglDestroyContext);
 result = false;
 }
 }
 
-result = wcore_context_teardown(wc_ctx);
-free(ctx);
+result = wcore_context_teardown(ctx-wcore);
+return result;
+}
+
+bool
+wegl_context_destroy(struct wcore_context *wc_ctx)
+{
+bool result = true;
+
+if (wc_ctx) {
+struct wegl_context *ctx = wegl_context(wc_ctx);
+result = wegl_context_teardown(ctx);
+free(ctx);
+}
 return result;
 }
diff --git a/src/waffle/egl/wegl_context.h b/src/waffle/egl/wegl_context.h
index 3583d61..b7d4d6a 100644
--- a/src/waffle/egl/wegl_context.h
+++ b/src/waffle/egl/wegl_context.h
@@ -33,8 +33,6 @@
 #include wcore_context.h
 #include wcore_util.h
 
-struct wegl_display;
-
 struct wegl_context {
 struct wcore_context wcore;
 EGLContext egl;
@@ -45,6 +43,14 @@ DEFINE_CONTAINER_CAST_FUNC(wegl_context,
struct wcore_context,
wcore)
 
+bool
+wegl_context_init(struct wegl_context *ctx,
+  struct

[waffle] [PATCH 02/10] gbm: make platform friendlier to derived classes

2015-03-30 Thread Frank Henigman
Retrieve additional gbm functions.
Change some functions from private to public.
Factor init and teardown out of create and destroy respectively,
so a derived class can used them on its embedded platform object.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 src/waffle/gbm/wgbm_platform.c | 58 +-
 src/waffle/gbm/wgbm_platform.h | 51 -
 2 files changed, 74 insertions(+), 35 deletions(-)

diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c
index 981c366..0fc0352 100644
--- a/src/waffle/gbm/wgbm_platform.c
+++ b/src/waffle/gbm/wgbm_platform.c
@@ -46,10 +46,9 @@ static const char *libgbm_filename = libgbm.so.1;
 
 static const struct wcore_platform_vtbl wgbm_platform_vtbl;
 
-static bool
-wgbm_platform_destroy(struct wcore_platform *wc_self)
+bool
+wgbm_platform_teardown(struct wgbm_platform *self)
 {
-struct wgbm_platform *self = wgbm_platform(wegl_platform(wc_self));
 bool ok = true;
 int error = 0;
 
@@ -72,20 +71,27 @@ wgbm_platform_destroy(struct wcore_platform *wc_self)
 }
 
 ok = wegl_platform_teardown(self-wegl);
+return ok;
+}
+
+bool
+wgbm_platform_destroy(struct wcore_platform *wc_self)
+{
+struct wgbm_platform *self = wgbm_platform(wegl_platform(wc_self));
+
+if (!self)
+return true;
+
+bool ok = wgbm_platform_teardown(self);
 free(self);
 return ok;
 }
 
-struct wcore_platform*
-wgbm_platform_create(void)
+bool
+wgbm_platform_init(struct wgbm_platform *self)
 {
-struct wgbm_platform *self;
 bool ok = true;
 
-self = wcore_calloc(sizeof(*self));
-if (self == NULL)
-return NULL;
-
 ok = wegl_platform_init(self-wegl);
 if (!ok)
 goto error;
@@ -98,7 +104,7 @@ wgbm_platform_create(void)
 goto error;
 }
 
-#define RETRIEVE_GBM_SYMBOL(function)  \
+#define RETRIEVE_GBM_SYMBOL(type, function, args)  
\
 self-function = dlsym(self-gbmHandle, #function);\
 if (!self-function) { \
 wcore_errorf(WAFFLE_ERROR_FATAL, \
@@ -107,15 +113,7 @@ wgbm_platform_create(void)
 goto error;\
 }
 
-RETRIEVE_GBM_SYMBOL(gbm_create_device);
-RETRIEVE_GBM_SYMBOL(gbm_device_get_fd);
-RETRIEVE_GBM_SYMBOL(gbm_device_destroy);
-
-RETRIEVE_GBM_SYMBOL(gbm_surface_create);
-RETRIEVE_GBM_SYMBOL(gbm_surface_destroy);
-
-RETRIEVE_GBM_SYMBOL(gbm_surface_lock_front_buffer);
-RETRIEVE_GBM_SYMBOL(gbm_surface_release_buffer);
+GBM_FUNCTIONS(RETRIEVE_GBM_SYMBOL);
 #undef RETRIEVE_GBM_SYMBOL
 
 self-linux = linux_platform_create();
@@ -125,14 +123,28 @@ wgbm_platform_create(void)
 setenv(EGL_PLATFORM, drm, true);
 
 self-wegl.wcore.vtbl = wgbm_platform_vtbl;
-return self-wegl.wcore;
+return true;
 
 error:
+wgbm_platform_teardown(self);
+return false;
+}
+
+struct wcore_platform*
+wgbm_platform_create(void)
+{
+struct wgbm_platform *self = wcore_calloc(sizeof(*self));
+if (self == NULL)
+return NULL;
+
+if (wgbm_platform_init(self))
+return self-wegl.wcore;
+
 wgbm_platform_destroy(self-wegl.wcore);
 return NULL;
 }
 
-static bool
+bool
 wgbm_dl_can_open(struct wcore_platform *wc_self,
  int32_t waffle_dl)
 {
@@ -140,7 +152,7 @@ wgbm_dl_can_open(struct wcore_platform *wc_self,
 return linux_platform_dl_can_open(self-linux, waffle_dl);
 }
 
-static void*
+void*
 wgbm_dl_sym(struct wcore_platform *wc_self,
 int32_t waffle_dl,
 const char *name)
diff --git a/src/waffle/gbm/wgbm_platform.h b/src/waffle/gbm/wgbm_platform.h
index 259eb19..1a08183 100644
--- a/src/waffle/gbm/wgbm_platform.h
+++ b/src/waffle/gbm/wgbm_platform.h
@@ -34,6 +34,24 @@
 #include wegl_platform.h
 #include wcore_util.h
 
+#define GBM_FUNCTIONS(f) \
+f(struct gbm_device * , gbm_create_device, (int fd)) \
+f(int , gbm_device_get_fd, (struct gbm_device 
*dev)) \
+f(void, gbm_device_destroy   , (struct gbm_device 
*gbm)) \
+f(struct gbm_surface *, gbm_surface_create   , (struct gbm_device 
*gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags)) \
+f(void, gbm_surface_destroy  , (struct gbm_surface 
*surface)) \
+f(struct gbm_bo * , gbm_surface_lock_front_buffer, (struct gbm_surface 
*surface)) \
+f(void, gbm_surface_release_buffer   , (struct gbm_surface 
*surface, struct gbm_bo *bo)) \
+f(struct gbm_bo * , gbm_bo_create, (struct gbm_device 
*gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags)) \
+f(void, gbm_bo_destroy   , (struct gbm_bo 
*bo)) \
+f(int

[waffle] [PATCH 09/10] gl_basic: add 'null' platform

2015-03-30 Thread Frank Henigman
Signed-off-by: Frank Henigman fjhenig...@google.com
---
 examples/gl_basic.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 8f59d21..ab9c78c 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -243,6 +243,7 @@ static const struct enum_map platform_map[] = {
 {WAFFLE_PLATFORM_CGL,   cgl,  },
 {WAFFLE_PLATFORM_GBM,   gbm   },
 {WAFFLE_PLATFORM_GLX,   glx   },
+{WAFFLE_PLATFORM_NULL,  null   },
 {WAFFLE_PLATFORM_WAYLAND,   wayland   },
 {WAFFLE_PLATFORM_WGL,   wgl   },
 {WAFFLE_PLATFORM_X11_EGL,   x11_egl   },
-- 
2.2.0.rc0.207.ga3a616c

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


[waffle] [PATCH] gl_basic: request alpha planes

2015-03-23 Thread Frank Henigman
Alpha planes are written and read, so we should ask for them in the config.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
 examples/gl_basic.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index ab9c78c..e59dc11 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -639,6 +639,8 @@ main(int argc, char **argv)
 config_attrib_list[i++] = 8;
 config_attrib_list[i++] = WAFFLE_BLUE_SIZE;
 config_attrib_list[i++] = 8;
+config_attrib_list[i++] = WAFFLE_ALPHA_SIZE;
+config_attrib_list[i++] = 8;
 config_attrib_list[i++] = WAFFLE_DOUBLE_BUFFERED;
 config_attrib_list[i++] = true;
 config_attrib_list[i++] = 0;
-- 
2.2.0.rc0.207.ga3a616c

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


Re: [waffle] EGL null platform

2015-02-12 Thread Frank Henigman
EGL_PLATFORM_NULL is not upstreamed yet either, though perhaps it
could be fairly easily.
Also I'm developing with minigbm, though it could probably also work
with mesa gbm.
My priority is to get this working for chromeos tests, as we've
already switched to null platform + minigbm.
That will probably take a couple weeks, after which I'll be keen to upstream.
No doubt some early review will be beneficial, so as soon as the
branch is somewhat stable I'll invite the list to take a look.

On Wed, Feb 11, 2015 at 9:05 PM, Chad Versace chad.vers...@intel.com wrote:
 Frank, I see in your Github repo that you're working on support for
 Chrome OS's null platform. I'm looking forward to it, because some
 of us in Intel would like to use it too. Do you have an idea when
 it will be ready for upstreaming?


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

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


Re: [waffle] [wflinfo] [RFC] platform-specific info from wflinfo

2015-02-12 Thread Frank Henigman
On Thu, Feb 12, 2015 at 5:44 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 12 February 2015 at 02:01, Chad Versace chad.vers...@intel.com wrote:
 On 02/10/2015 01:20 PM, Frank Henigman wrote:
 On Tue, Feb 10, 2015 at 4:08 PM, Frank Henigman fjhenig...@google.com 
 wrote:

 Looks like Issue #3 is the format of the information.  I thought it
 was given we should duplicate existing glxinfo/eglinfo/etc as closely
 as possible, in order to be a drop-in replacement, but if I follow the
 suggestions Chad made on github
 (https://github.com/fjhenigman/waffle/commit/d0b45bb9850e6ae29ee379a2d3e8ba14afc1b872)
 we'll be diverging.  Improving on existing tools is ok with me - I
 don't have a huge investment in code to parse their output - but I
 wonder if others feel differently.

 (+Jordan, +Dylan, questions below)

 Oh, when I made those Github comments, I didn't know you were trying to
 duplicate glxinfo output verbatim. Now I understand why the GLX lines
 look so different from wflinfo's current output.

 glxinfo wraps long lines for extension strings and separates extension names 
 with commas.
 wflinfo intentionally prints extensions strings in their original form: 
 single line,
 extension names separated by spaces. If I recall correctly, Jordan and Dylan 
 wanted
 that format so that consumers who parsed wflinfo text output would be 
 guaranteed a stable
 format.

 If wflinfo has mixed line formats (some lines are comma-separated and 
 wrapped, some
 are space-separated), I fear that may cause problems for already-existing 
 consumers.
 Dylan, Jordan, do you have an opinion here? Does this really matter?

 The above are some examples why I am doubtful about adding such
 function in waffle.

 One might want the extensions listed in alphabetic order, another to
 have them one per line, another will likely be interested the client
 extensions, or maybe the server ones, the GLX/CGL/WGL/EGL version only
 ?

 Imho in order for one to get some flexibility I would opt for query
 mechanism for issue 1.

 Chad, genuine question, can you please describe how having a string is
 more extensible ?


 Thanks
 Emil

I'm sold on easy parsing and wflinfo compatibility over {glx,egl}info
compatibility.  There's no reason we can't have everything actually.
The parameter I proposed could be used to select output format: match
glxinfo, match older wflinfo, latest and easiest-to-parse, etc.
I don't mean to answer for Chad, but the nice thing about returning a
string is we can tweak it without changing the api, and maybe without
breaking existing parsers (at least not badly).  You could say this is
just a fuzzy and therefore useless kind of api, but that's glass half
empty thinking.  (^:
I think a string is a good start.  We can lock in the format(s) if and
when we choose, it in no way hinders later attempts at something
fancier, and it shouldn't be hard to keep the string for compatibility
after something fancier is available.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [wflinfo] [RFC] platform-specific info from wflinfo

2015-02-10 Thread Frank Henigman
On Tue, Feb 10, 2015 at 3:09 PM, Chad Versace chad.vers...@intel.com wrote:
 On 02/10/2015 10:31 AM, Dylan Baker wrote:
 I like this idea, it would be convenient for piglit to be able to assume
 waffle info can provide all of the information we currently call out to
 multiple binaries for.

 Yes, Piglit wants this. I imagine more users will begin using it too.

 On Sun, Feb 08, 2015 at 07:50:15PM -0500, Frank Henigman wrote:
 I'd like to extend wflinfo so it can print platform-specific
 information and eventually be able to replace glxinfo, eglinfo and the
 like (I only know what's on linux).  There would be a new flag to
 request the platform-specific output in addition to the existing
 output.  For example on glx you'd see glx extensions, on egl you'd see
 egl extensions.
 I've started two different implementations and I'd like to know which
 is preferred before I go any farther.  Or if there's a better idea
 than either of my approaches.  I've dubbed the two approaches native
 and core.

 native
 - all the work is done in wflinfo, no changes to waffle api
 - use waffle_display_get_native() to access platform-specific stuff
 - pro: changes limited to wflinfo, doesn't clutter up the rest of waffle
 - con: some duplicate code to open libraries and lookup symbols
 - https://github.com/fjhenigman/waffle/tree/ps_native

 core
 - add waffle_display_print_info() to waffle api
 - add print_info() method to each platform
 - pro: less code, no duplication
 - con (perhaps): some wflinfo functionality is now in core waffle
 - https://github.com/fjhenigman/waffle/tree/ps_core

 I'm leaning toward core because there is less code.  We get to
 leverage the platform libraries and functions already stored in waffle
 platform structs.  But if the consensus is it's cleaner to keep this
 stuff in wflinfo I'm ok with that too.

 I prefer core too. Not for the sake of less code, but because I like
 the idea of it being available as core API.

 I've begun adding Github comments to your ps_core branch. We can do
 review Github-style, if you like. If you send patches to the list,
 that's ok too.

Thanks for feedback.  From here on I'll send patch sets to the list.
I'll incorporate any github suggestions in the first such set.

 I see two significant design decisions that need to be made:

   Issue #1: Should Waffle provide a query mechanism for the native
   platform info? Or should it just dump the info as a well-formatted
   string?

  Resolved: I like the way that your waffle_display_print_info() just dumps
  the information as a string. That's much simpler and more
  extensible than a true query mechanism.

   Issue #2: How should Waffle give that information string to the user?

  I think hardcoding stdout as the destination for the information
  is too restrictive. A very simple alternative would be that
  waffle_display_print_info() return a C-string that the user is
  required to free. Or perhaps the user should pass a string
  buffer and max length to waffle_display_print_info(),
  similar to snprintf(). Or maybe something completely different.
  What do you think is the best approach?

Returning a string.  If the user has to supply a buffer they won't
know how big it needs to be.
I think the function will want an enum or bitmask parameter for
controlling, for example, verbosity.
If we ever want a fancy query interface that returns structs instead
of a string, we'll be able to
re-implement the string-returning function over that interface for
backward compatibility.
I suggest calling this one waffle_display_info_string() instead of
taking a name we might want to
use later, like waffle_display_info or waffle_display_query.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [wflinfo] [RFC] platform-specific info from wflinfo

2015-02-10 Thread Frank Henigman
On Tue, Feb 10, 2015 at 4:08 PM, Frank Henigman fjhenig...@google.com wrote:
 On Tue, Feb 10, 2015 at 3:09 PM, Chad Versace chad.vers...@intel.com wrote:
 On 02/10/2015 10:31 AM, Dylan Baker wrote:
 I like this idea, it would be convenient for piglit to be able to assume
 waffle info can provide all of the information we currently call out to
 multiple binaries for.

 Yes, Piglit wants this. I imagine more users will begin using it too.

 On Sun, Feb 08, 2015 at 07:50:15PM -0500, Frank Henigman wrote:
 I'd like to extend wflinfo so it can print platform-specific
 information and eventually be able to replace glxinfo, eglinfo and the
 like (I only know what's on linux).  There would be a new flag to
 request the platform-specific output in addition to the existing
 output.  For example on glx you'd see glx extensions, on egl you'd see
 egl extensions.
 I've started two different implementations and I'd like to know which
 is preferred before I go any farther.  Or if there's a better idea
 than either of my approaches.  I've dubbed the two approaches native
 and core.

 native
 - all the work is done in wflinfo, no changes to waffle api
 - use waffle_display_get_native() to access platform-specific stuff
 - pro: changes limited to wflinfo, doesn't clutter up the rest of waffle
 - con: some duplicate code to open libraries and lookup symbols
 - https://github.com/fjhenigman/waffle/tree/ps_native

 core
 - add waffle_display_print_info() to waffle api
 - add print_info() method to each platform
 - pro: less code, no duplication
 - con (perhaps): some wflinfo functionality is now in core waffle
 - https://github.com/fjhenigman/waffle/tree/ps_core

 I'm leaning toward core because there is less code.  We get to
 leverage the platform libraries and functions already stored in waffle
 platform structs.  But if the consensus is it's cleaner to keep this
 stuff in wflinfo I'm ok with that too.

 I prefer core too. Not for the sake of less code, but because I like
 the idea of it being available as core API.

 I've begun adding Github comments to your ps_core branch. We can do
 review Github-style, if you like. If you send patches to the list,
 that's ok too.

 Thanks for feedback.  From here on I'll send patch sets to the list.
 I'll incorporate any github suggestions in the first such set.

 I see two significant design decisions that need to be made:

   Issue #1: Should Waffle provide a query mechanism for the native
   platform info? Or should it just dump the info as a well-formatted
   string?

  Resolved: I like the way that your waffle_display_print_info() just 
 dumps
  the information as a string. That's much simpler and more
  extensible than a true query mechanism.

   Issue #2: How should Waffle give that information string to the user?

  I think hardcoding stdout as the destination for the information
  is too restrictive. A very simple alternative would be that
  waffle_display_print_info() return a C-string that the user is
  required to free. Or perhaps the user should pass a string
  buffer and max length to waffle_display_print_info(),
  similar to snprintf(). Or maybe something completely different.
  What do you think is the best approach?

 Returning a string.  If the user has to supply a buffer they won't
 know how big it needs to be.
 I think the function will want an enum or bitmask parameter for
 controlling, for example, verbosity.
 If we ever want a fancy query interface that returns structs instead
 of a string, we'll be able to
 re-implement the string-returning function over that interface for
 backward compatibility.
 I suggest calling this one waffle_display_info_string() instead of
 taking a name we might want to
 use later, like waffle_display_info or waffle_display_query.

Looks like Issue #3 is the format of the information.  I thought it
was given we should duplicate existing glxinfo/eglinfo/etc as closely
as possible, in order to be a drop-in replacement, but if I follow the
suggestions Chad made on github
(https://github.com/fjhenigman/waffle/commit/d0b45bb9850e6ae29ee379a2d3e8ba14afc1b872)
we'll be diverging.  Improving on existing tools is ok with me - I
don't have a huge investment in code to parse their output - but I
wonder if others feel differently.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


[waffle] [PATCH] wflinfo: find glGetStringi on both Mali and WGL

2015-01-26 Thread Frank Henigman
Do the glGetStringi lookup after making context current so it works on WGL.
Remove an incorrect glGetStringi lookup, which returned NULL on Mali.

Signed-off-by: Frank Henigman fjhenig...@google.com
---
Not sure what happened but wflinfo is still broken on mali because of the 
glGetStringi madness.
Chad put in a fix:
https://github.com/waffle-gl/waffle/commit/0543d0d12aa16e0daf361937619998c8995fd6fc
and ten days before that Emil had moved the offending 
waffle_get_proc_address(glGetStringi) down about 20 lines:
https://github.com/waffle-gl/waffle/commit/6ae99a4701bd5117a182c2e555a0c0a2061254d3
It looks like both changes to that line got in, because after Chad's change 
successfully sets the address the old, wrong line later sets it to null.
Sorry but I'm not able to test on Windows.

 src/utils/wflinfo.c | 40 +++-
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c
index 5a9195c..5e173b7 100644
--- a/src/utils/wflinfo.c
+++ b/src/utils/wflinfo.c
@@ -1076,6 +1076,25 @@ main(int argc, char **argv)
 if (!glGetString)
 error_get_gl_symbol(glGetString);
 
+const struct wflinfo_config_attrs config_attrs = {
+.api = opts.context_api,
+.profile = opts.context_profile,
+.major = opts.context_major,
+.minor = opts.context_minor,
+.forward_compat = opts.context_forward_compatible,
+.debug = opts.context_debug,
+};
+
+wflinfo_create_context(dpy, config_attrs, ctx, config);
+
+window = waffle_window_create(config, WINDOW_WIDTH, WINDOW_HEIGHT);
+if (!window)
+error_waffle();
+
+ok = waffle_make_current(dpy, window, ctx);
+if (!ok)
+error_waffle();
+
 // Retrieving GL functions is tricky. When glGetStringi is supported, here
 // are some boggling variations as of 2014-11-19:
 //   - Mali drivers on EGL 1.4 expose glGetStringi statically from
@@ -1099,27 +1118,6 @@ main(int argc, char **argv)
 glGetStringi = waffle_get_proc_address(glGetStringi);
 }
 
-const struct wflinfo_config_attrs config_attrs = {
-.api = opts.context_api,
-.profile = opts.context_profile,
-.major = opts.context_major,
-.minor = opts.context_minor,
-.forward_compat = opts.context_forward_compatible,
-.debug = opts.context_debug,
-};
-
-wflinfo_create_context(dpy, config_attrs, ctx, config);
-
-window = waffle_window_create(config, WINDOW_WIDTH, WINDOW_HEIGHT);
-if (!window)
-error_waffle();
-
-ok = waffle_make_current(dpy, window, ctx);
-if (!ok)
-error_waffle();
-
-glGetStringi = waffle_get_proc_address(glGetStringi);
-
 ok = print_wflinfo(opts);
 if (!ok)
 error_waffle();
-- 
2.2.0.rc0.207.ga3a616c

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


Re: [waffle] [PATCH 00/11] Add new public func waffle_window_create2()

2014-12-23 Thread Frank Henigman
On Mon, Dec 22, 2014 at 8:11 PM, Chad Versace chad.vers...@intel.com wrote:
 On 12/21/2014 01:41 PM, Emil Velikov wrote:
 On 16 December 2014 at 08:18, Chad Versace chad.vers...@linux.intel.com 
 wrote:
 Today, waffle_window() has only two parameters: width and height.

 Frank Henigman wants to extend Waffle's GBM backend with the ability to
 post window contents to the display. Multiple methods exist for posting
 content to the screen with the drm API, and that method should be
 configurable per waffle_window. Therefore, we need to be able to pass
 additional attributes to waffle_window_create().

 It would also be nice to specify at time of creation that the
 waffle_window should be full screen. Again, we need to pass additional
 attributes to waffle_window_create().

 The new function waffle_window_create2() is conceptually equivalent to
 the original waffle_window_create() with the addition of an attrib_list
 parameter.  The only supported attributes are currently
 WAFFLE_WINDOW_WIDTH and WAFFLE_WINDOW_HEIGHT.

 I tested the new function on GLX, X11/EGL, Wayland, and GBM.

 I did not even test the build on Windows, Android, and Mac. Before merging 
 this
 series, I will ensure it doesn't break the build on those platforms. I don't
 have the ability to actually test on Android or Windows, though.

 This patch series is available on my personal branch 
 'waffle_window_create2'.

 Hi Chad,

 Overall it looks very good imho. I've managed to spot only a few of
 trivial bits.
 Just a small note for future work - popping an attribute at a time,
 will become noticeable as the attribs list grows.

 Just as you, I winced when I wrote the code that popped one attribute
 at a time. I really wanted to write it better, but I repeated to myself
 the mantra pre-optimization is the root of all evil. The pop-one-at-a-time
 code is very easy to read in comparison to walk-the-list-once-and-pop-as-we-go
 code, so I think it's the better choice, at least until the attribute lists
 grow substantially longer.

 Also if you're not a fan of adding numbers at the end of function
 names you might use waffle_window_create_{with,from}_attibs

 I weighed the two naming conventions. I thought that, if we ever
 bump the signature for waffle_window_create again, then we might
 not be able to invent a creatively descriptive but short name
 for the new function. But good ole #3 is always there for us.

 Also, I tried typing waffle_window_create_attribs and waffle_window_create2
 several times, and I just couldn't bring myself to make people to type
 a function name so lengthily Java-like.

 I assume you're not a fan of using 2?

Another option is to break compatibility and rename the existing
function waffle_window_create(_size,0,_old,_orig) and reuse the nice
clean name for the nice new function.  It seems an easy enough fix for
people updating their waffle version.  I'll do the chrome os test
code, and piglit seems to have just one call to waffle_window_create.
Are there many other users I don't know about?

If you buy that, why not also change all the int32_t attribs[]
signatures to intptr_t, and not keep around two versions of those
functions.

Seems like short term pain for long term gain, to me.
___
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle


Re: [waffle] [PATCH 02/11] core: Define intptr_t variants of wcore_attrib_list functions

2014-12-23 Thread Frank Henigman
On Tue, Dec 16, 2014 at 3:18 AM, Chad Versace
chad.vers...@linux.intel.com wrote:
 When designing the original Waffle 1.0 API, I made a mistake when
 I chose to declare attribute lists as arrays of int32_t. Instead, they
 should have been arrays of intptr_t.

 A new public function, waffle_window_create2, will have a `const
 intptr_t attrib_list[]` parameter. Therefore waffle needs intptr_t
 variants of the wcore_attrib_list functions.

 Signed-off-by: Chad Versace chad.vers...@linux.intel.com
 ---
  src/waffle/core/wcore_attrib_list.c | 73 
 +
  src/waffle/core/wcore_attrib_list.h | 23 
  2 files changed, 96 insertions(+)

 diff --git a/src/waffle/core/wcore_attrib_list.c 
 b/src/waffle/core/wcore_attrib_list.c
 index 09a4dec..a7f087d 100644
 --- a/src/waffle/core/wcore_attrib_list.c
 +++ b/src/waffle/core/wcore_attrib_list.c
 @@ -29,6 +29,79 @@
  #include stdint.h
  #include stddef.h

 +size_t
 +wcore_attrib_list_length(const intptr_t attrib_list[])
 +{
 +const intptr_t *i = attrib_list;
 +
 +if (attrib_list == NULL)
 +return 0;
 +
 +while (*i != 0)
 +i += 2;
 +
 +return (i - attrib_list) / 2;
 +}
 +
 +bool
 +wcore_attrib_list_get(
 +const intptr_t *attrib_list,
 +intptr_t key,
 +intptr_t *value)
 +{
 +if (attrib_list == NULL)
 +return false;
 +
 +for (size_t i = 0; attrib_list[i] != 0; i += 2) {
 +if (attrib_list[i] != key)
 +continue;
 +
 +*value = attrib_list[i + 1];
 +return true;
 +}
 +
 +return false;
 +}
 +
 +bool
 +wcore_attrib_list_get_with_default(
 +const intptr_t attrib_list[],
 +intptr_t key,
 +intptr_t *value,
 +intptr_t default_value)
 +{
 +if (wcore_attrib_list_get(attrib_list, key, value)) {
 +return true;
 +}
 +else {
 +*value = default_value;
 +return false;
 +}
 +}
 +
 +bool
 +wcore_attrib_list_update(
 +intptr_t *attrib_list,
 +intptr_t key,
 +intptr_t value)
 +{
 +intptr_t *i = attrib_list;
 +
 +if (attrib_list == NULL)
 +return false;
 +
 +while (*i != 0  *i != key)
 +i += 2;
 +
 +if (*i == key) {
 +i[1] = value;
 +return true;
 +}
 +else {
 +return false;
 +}
 +}

Speaking of wincing (patch 00/11 thread) this code duplication makes
me wince.  If we really have to keep outside facing int32_t functions,
can we immediately translate int32_t's passed into them to intptr_t's
and keep waffle internals all intptr_t?  With an eye to deprecating
the int32_t interfaces?

 +
  int32_t
  wcore_attrib_list32_length(const int32_t attrib_list[])
  {
 diff --git a/src/waffle/core/wcore_attrib_list.h 
 b/src/waffle/core/wcore_attrib_list.h
 index 8339578..5e6473b 100644
 --- a/src/waffle/core/wcore_attrib_list.h
 +++ b/src/waffle/core/wcore_attrib_list.h
 @@ -27,6 +27,29 @@

  #include stdbool.h
  #include stdint.h
 +#include stdlib.h
 +
 +size_t
 +wcore_attrib_list_length(const intptr_t attrib_list[]);
 +
 +bool
 +wcore_attrib_list_get(
 +const intptr_t *attrib_list,
 +intptr_t key,
 +intptr_t *value);
 +
 +bool
 +wcore_attrib_list_get_with_default(
 +const intptr_t attrib_list[],
 +intptr_t key,
 +intptr_t *value,
 +intptr_t default_value);
 +
 +bool
 +wcore_attrib_list_update(
 +intptr_t *attrib_list,
 +intptr_t key,
 +intptr_t value);

  int32_t
  wcore_attrib_list32_length(const int32_t attrib_list[]);
 --
 2.2.0

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


Re: [waffle] [PATCH 09/11] waffle: Add public func waffle_window_create2()

2014-12-23 Thread Frank Henigman
On Tue, Dec 16, 2014 at 3:18 AM, Chad Versace
chad.vers...@linux.intel.com wrote:
 Today, waffle_window() has only two parameters: width and height.

 Frank Henigman wants to extend Waffle's GBM backend with the ability to
 post window contents to the display. Multiple methods exist for posting
 content to the screen with the drm API, and that method should be
 configurable per waffle_window. Therefore, we need to be able to pass
 additional attributes to waffle_window_create().

 It would also be nice to specify at time of creation that the
 waffle_window should be full screen. Again, we need to pass additional
 attributes to waffle_window_create().

 The new function waffle_window_create2() is conceptually equivalent to
 the original waffle_window_create() with the addition of an attrib_list
 parameter.  The only supported attributes are currently
 WAFFLE_WINDOW_WIDTH and WAFFLE_WINDOW_HEIGHT.

 See the manpage changes for more details.

 Signed-off-by: Chad Versace chad.vers...@linux.intel.com
 ---
  include/waffle/waffle.h| 14 +
  man/waffle_enum.3.xml  |  7 +
  man/waffle_window.3.xml| 27 
  src/waffle/api/waffle_window.c | 71 
 ++
  src/waffle/core/wcore_util.c   |  2 ++
  5 files changed, 121 insertions(+)

 diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
 index e04b23f..820d012 100644
 --- a/include/waffle/waffle.h
 +++ b/include/waffle/waffle.h
 @@ -150,6 +150,13 @@ enum waffle_enum {
  WAFFLE_DL_OPENGL_ES1= 0x0302,
  WAFFLE_DL_OPENGL_ES2= 0x0303,
  WAFFLE_DL_OPENGL_ES3= 0x0304,
 +
 +// --
 +// For waffle_window
 +// --
 +
 +WAFFLE_WINDOW_WIDTH = 0x0310,
 +WAFFLE_WINDOW_HEIGHT= 0x0311,
  };

  const char*
 @@ -221,6 +228,13 @@ waffle_context_get_native(struct waffle_context *self);
  // waffle_window
  // 
 ---

 +#if WAFFLE_API_VERSION = 0x0106
 +struct waffle_window*
 +waffle_window_create2(
 +struct waffle_config *config,
 +const intptr_t attrib_list[]);
 +#endif
 +
  struct waffle_window*
  waffle_window_create(
  struct waffle_config *config,
 diff --git a/man/waffle_enum.3.xml b/man/waffle_enum.3.xml
 index a96bd20..ee5f236 100644
 --- a/man/waffle_enum.3.xml
 +++ b/man/waffle_enum.3.xml
 @@ -141,6 +141,13 @@ enum waffle_enum {
  WAFFLE_DL_OPENGL= 0x0301,
  WAFFLE_DL_OPENGL_ES1= 0x0302,
  WAFFLE_DL_OPENGL_ES2= 0x0303,
 +
 +// --
 +// For waffle_window
 +// --
 +
 +WAFFLE_WINDOW_WIDTH = 0x0310,
 +WAFFLE_WINDOW_HEIGHT= 0x0311,
  };
  ]]
  /programlisting
 diff --git a/man/waffle_window.3.xml b/man/waffle_window.3.xml
 index de046fa..795152a 100644
 --- a/man/waffle_window.3.xml
 +++ b/man/waffle_window.3.xml
 @@ -56,6 +56,12 @@ struct waffle_window;
/funcprototype

funcprototype
 +funcdefstruct waffle_window* 
 functionwaffle_window_create2/function/funcdef
 +paramdefstruct waffle_window 
 *parameterconfig/parameter/paramdef
 +paramdefconst intptr_t 
 parameterattrib_list/parameter[]/paramdef
 +  /funcprototype
 +
 +  funcprototype
  funcdefbool functionwaffle_window_destroy/function/funcdef
  paramdefstruct waffle_window 
 *parameterself/parameter/paramdef
/funcprototype
 @@ -104,6 +110,27 @@ struct waffle_window;
/varlistentry

varlistentry
 +termfunctionwaffle_window_create2()/function/term
 +listitem
 +  para
 +Feature test macro: codeWAFFLE_API_VERSION = 0x0106/code.
 +(See 
 citerefentryrefentrytitlewaffle_feature_test_macros/refentrytitlemanvolnum7/manvolnum/citerefentry).
 +  /para
 +  para
 +Create a window with the properties specified by
 +parameterconfig/parameter and
 +parameterattrib_list/parameter.
 +
 +parameterattrib_list/parameter must contain the attributes
 +constantWAFFLE_WINDOW_WIDTH/constant and
 +constantWAFFLE_WINDOW_HEIGHT/constant,
 +whose values must be positive
 +and no greater than constantINT32_MAX/constant.
 +  /para
 +/listitem
 +  /varlistentry
 +
 +  varlistentry

Re: [waffle] [RFC] Add display support to GBM backend

2014-12-12 Thread Frank Henigman
On Wed, Nov 19, 2014 at 2:38 PM, Chad Versace chad.vers...@intel.com wrote:
 Frank sent this patch as a proof-of-concept. It's a draft, and not ready for
 committing. I'm posting to the list just to start discussion.

 See [https://github.com/waffle-gl/waffle/issues/18]. I think detailed patch
 discussions like this are easier over email than Github's issue tracker, so
 let's keep the bulk of the discussion in email.

 Frank, I haven't examined every detail in this patch. I focused on the
 high-level design.  I'll probably wait to examine the fine details until you
 submit a real patch for upstreaming.

 From: Frank Henigman fjhenig...@chromium.org
 Date: Tue, 21 Oct 2014 22:58:45 -0400
 Subject: [PATCH] gbm WIP: show gbm buffers on screen

 Four options based on the value of environment variable MODE:
 COPY: copy render buffer to scanout buffer and flip to scanout buffer
 FLIP: scan out directly from render buffer
 ORIG: do what the code originally did, i.e. nothing
 unset or empty: don't display, but still lock and release buffer

 TO DO
 - make it a compile time option
 - make it a proper run time option, via config attributes or something,
   instead of by env var


 I prefer to make the display-mode a runtime option via attributes to
 waffle_window. Perhaps we should define a new function:

struct waffle_window*
waffle_window_create_attrs(struct waffle_config *config,
   const intptr_t attrib_list[]);

 - leave hooks and graceful fails for (as yet) unsupported drm drivers,
   currently only i915 is supported


 If initially the only supported driver is i915, that's ok with me. We have
 to start somewhere, and I don't like waiting for perfect completeness.

 - address all XXX in code
 ---
  cmake/Modules/WaffleFindDependencies.cmake |   1 +
  include/waffle/waffle_gbm.h|   1 +
  src/waffle/CMakeLists.txt  |   2 +
  src/waffle/gbm/wgbm_display.h  |   2 +
  src/waffle/gbm/wgbm_platform.c |   2 +-
  src/waffle/gbm/wgbm_window.c   | 394
 -
  src/waffle/gbm/wgbm_window.h   |   3 +
  7 files changed, 402 insertions(+), 3 deletions(-)

 diff --git a/cmake/Modules/WaffleFindDependencies.cmake
 b/cmake/Modules/WaffleFindDependencies.cmake
 index 9245772..a35ac8f 100644
 --- a/cmake/Modules/WaffleFindDependencies.cmake
 +++ b/cmake/Modules/WaffleFindDependencies.cmake
 @@ -79,4 +79,5 @@ if(waffle_on_linux)
  # waffle_has_gbm
  waffle_pkg_config(gbm gbm)
  waffle_pkg_config(libudev libudev)
 +waffle_pkg_config(libdrm libdrm)
  endif()
 diff --git a/include/waffle/waffle_gbm.h b/include/waffle/waffle_gbm.h
 index fe45343..c9e4691 100644
 --- a/include/waffle/waffle_gbm.h
 +++ b/include/waffle/waffle_gbm.h
 @@ -41,6 +41,7 @@ struct gbm_surface;
   struct waffle_gbm_display {
  struct gbm_device *gbm_device;
 +struct waffle_drm_display *drm_display;
  EGLDisplay egl_display;
  };
  diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt
 index 0e42192..4866dfb 100644
 --- a/src/waffle/CMakeLists.txt
 +++ b/src/waffle/CMakeLists.txt
 @@ -23,6 +23,7 @@ include_directories(
  ${gbm_INCLUDE_DIRS}
  ${gl_INCLUDE_DIRS}
  ${libudev_INCLUDE_DIRS}
 +${libdrm_INCLUDE_DIRS}
  ${wayland-client_INCLUDE_DIRS}
  ${wayland-egl_INCLUDE_DIRS}
  ${x11-xcb_INCLUDE_DIRS}
 @@ -58,6 +59,7 @@ if(waffle_on_linux)
  list(APPEND waffle_libdeps
  ${gbm_LDFLAGS}
  ${libudev_LDFLAGS}
 +${libdrm_LDFLAGS}
  )
  endif()
  endif()
 diff --git a/src/waffle/gbm/wgbm_display.h b/src/waffle/gbm/wgbm_display.h
 index ba4bb89..59d295a 100644
 --- a/src/waffle/gbm/wgbm_display.h
 +++ b/src/waffle/gbm/wgbm_display.h
 @@ -34,10 +34,12 @@
   struct wcore_platform;
  struct gbm_device;
 +struct drm_display;
   struct wgbm_display {
  struct gbm_device *gbm_device;
  struct wegl_display wegl;
 +struct drm_display *drm_display;
  };
   static inline struct wgbm_display*
 diff --git a/src/waffle/gbm/wgbm_platform.c
 b/src/waffle/gbm/wgbm_platform.c
 index 5624660..d556145 100644
 --- a/src/waffle/gbm/wgbm_platform.c
 +++ b/src/waffle/gbm/wgbm_platform.c
 @@ -156,7 +156,7 @@ static const struct wcore_platform_vtbl
 wgbm_platform_vtbl = {
  .create = wgbm_window_create,
  .destroy = wgbm_window_destroy,
  .show = wgbm_window_show,
 -.swap_buffers = wegl_window_swap_buffers,
 +.swap_buffers = wgbm_window_swap_buffers,
  .get_native = wgbm_window_get_native,
  },
  };
 diff --git a/src/waffle/gbm/wgbm_window.c b/src/waffle/gbm/wgbm_window.c
 index 85378da..2a889f4 100644
 --- a/src/waffle/gbm/wgbm_window.c
 +++ b/src/waffle/gbm/wgbm_window.c
 @@ -25,11 +25,16 @@
   #define __GBM__ 1
  +#include errno.h
  #include stdlib.h
  #include string.h
   #include gbm.h
  +#include xf86drm.h
 +#include xf86drmMode.h
 +#include i915_drm.h