pkg/macports: Update to 1.4.1

WARNING: Untested, because I don't have a Mac with me today.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
pkg/archlinux: Add PKGBUILD for waffle-1.4.1

And then upload it to the AUR, of course.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Merge branch 'maint-1.4'

* maint-1.4:
  pkg/archlinux: Add PKGBUILD for waffle-1.4.1
  pkg/macports: Update to 1.4.1
cmake: include the CPACK module

Will be used to ease distribution of binary tarballs.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
pkg/archlinux: add mingw-w64-waffle package

 - Remove explicit build options (waffle has autodetection).
 - Correct the destination directories.
 - Bump mingw64-crt requirement 3.1.0-3 (fixes the strerror_s issue).
 - Build twice - once for cross-builds and second time for win32 usage.

TODO:
 - Get CPack to amend the install prefix - fix the "build twice" issue.
 - Strip some/all of the binaries ?
 - Current package works of a local git repo. Rename to -git or
convert to a release one ?

v2:
 - Use single leading underscore for local variables.
 - Read user _srcroot if available.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
README: Add notes when building Waffle for Windows.

Update the existing document to reflect the areas where the existing
instructions are not applicable for Windows. Split some of the sections
at "per platform/build time" basis when needed.

 - Fix couple of trivial typos and drop the BUILD_DIR variable.
 - Disable waffle tests for now.
 - Minimised duplication, don't execute vcvarsall.bat and correctly
append Win64 in the generator string. Spotted by Jose.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: add skeleton implementation

This commit adds the bare-bone skeleton needed to implement a waffle
platform. All the function that it provides are essentially empty.

Update the documentation, examples and utils to accept
WAFFLE_PLATFORM_WGL as a valid choice.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: fill up the dl_* hooks

Windows has only one library that can be dlopen'ed to retieve GL
symbols - opengl32.dll.

Fire-up all the functions with their win32 counterpart.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: implement display management

Unlike GLX and EGL, WGL(Windows) does not have the concept of a display
in the sense used in waffle.

The 'root primitive' for WGL is a window with it's device context
which encapsulates the properties and capabilities of the device
doing the actual rendering (CPU or GPU).

As such we first need to create a unique window class that will be
used for all waffle windows, and then create the 'root' window.

The windows itself is disabled (cannot grab the input) and of zero
width and height.

While we're here make sure that we create a context, which will be
needed in a variety of cases - when we query the WGL extensions,
choose the config ...

v2: Bail out if we're using the GDI renderer.
v3: Zero-initialise pfd and explicitly set its required parameters.
v4: No not mention waffle_get_proc_address in commit msg.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: wire-up wgl_window and wgl_config hooks

WGL mandates that a window (device_context actually) must be
available before we choose the the config and create a context.
Create the window at wgl_config_choose() and hide it until
wgl_window_create() is executed.

Note that this will mandate 'only one window is allowed per config'
as such one should _never_ try to create two windows for a single
config with WGL.

To prevent issues, simply return NULL if we're trying to
create the second window.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Acked-by: Chad Versace <chad.versace@linux.intel.com>
wgl: wire-up waffle_get_proc_address()

For WGL we need a current context otherwise wglGetProcAddress will
return NULL pointer. Notice this in the documentation and leave it
up-to the user to design/use waffle in such a way this will work.

Remove the mesa workaround from gl_basic_test. Suggested by Chad.

Cc: Chad Versace <chad.versace@linux.intel.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
wgl: add context hooks

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Acked-by: Chad Versace <chad.versace@linux.intel.com>
wgl: check for various WGL extensions and fetch their funcptrs

Our assumption is that the original (root) context has the same
WGL core functions and any context created after that. Additionally
the wglCreateContextAttribsARB and wglChoosePixelFormatARB functions
and their pointers will remain constant across the creation of the
actual (working) context. Similar logic is used by SDL, xserver and
others.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: use wglChoosePixelFormatARB when available

With this commit we create an assumption that the root window DC
(device context) is compatible with the one for the new window.
Otherwise the pixel format will not be compatible, and we'll fail
at SetPixelFormat().

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: fully support ARB_create_context and EXT_create_context_es_profile.

Follow the specs and return correct error values when invalid context
attributes are provided.

Both extensions are virtually identical to their GLX counterparts,
as such copy the relevant implementation from waffle's GLX backend.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wgl: provide static GLES* symbols (dlsym) via opengl32.dll

Under Windows there is a single library that provides the basic/core
symbols for OpenGL and OpenGL ES* alike. One should attempt to use the
latter only if WGL_EXT_create_context_es{2,}_profile is supported.

We check for the extension in waffle_display_supports_context_api()
and users are strongly recommended check the function's return value.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
cmake: set most compiler flags/defines in a single location

Do not define the same thing (_XOPEN_SOURCE) three times and use
compiler specific flags.

 - GCC: Move visibility=hidden to global scale.
 - WIN32: Don't do TLS.
 - Static link Windows builds
   - MINGW: link-in libgcc*.dll
   - MSVC: link-in msvcrt*.dll

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
cmake: drop the waffle library prefix on Windows

Be a bit more consistent with Windows, rather than other platforms and
drop the library prefix. Suggested by Jose.

v2: Rebase

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
wgl: restrict exported symbols via module-definition file

msvc complains if the function declaration does not match its
definition (__declspec(dllexport)) thus to avoid messing up
with the public header, simply use a .def file.

v2: Drop the library prefix (lib) for the DLL.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>(v1)
Acked-by: Chad Versace <chad.versace@linux.intel.com>(v1)
wgl: avoid using container_of and DEFINE_CONTAINER_CAST_FUNC macros

msvc does not play nice with them. The wcore struct is always the first
component of the parent wgl struct, thus we should be safe with casting
without calculating/adding the offset (which is 0).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>