From cf80f78f808e402d06dc891fce08b0f3b3865c15 Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Fri, 15 Feb 2019 12:39:31 +0100
Subject: Remove PUGL_CAIRO_GL

The old cairo_gl.h header or something similar is easy enough to use in
application code if someone wants to do this, and maintaining a separate
context type for it is a hassle and arguably out of scope.
---
 pugl/cairo_gl.h   | 105 ------------------------------------------------------
 pugl/pugl.h       |   5 ++-
 pugl/pugl_x11.c   |  36 -------------------
 pugl_cairo_test.c |   6 +---
 4 files changed, 3 insertions(+), 149 deletions(-)
 delete mode 100644 pugl/cairo_gl.h

diff --git a/pugl/cairo_gl.h b/pugl/cairo_gl.h
deleted file mode 100644
index 5c0f1f9..0000000
--- a/pugl/cairo_gl.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
-  Copyright 2016 David Robillard <http://drobilla.net>
-
-  Permission to use, copy, modify, and/or distribute this software for any
-  purpose with or without fee is hereby granted, provided that the above
-  copyright notice and this permission notice appear in all copies.
-
-  THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
-
-#if defined(PUGL_HAVE_GL) && defined(PUGL_HAVE_CAIRO)
-
-#include <cairo/cairo.h>
-#include <stdint.h>
-
-#include "pugl/gl.h"
-
-typedef struct {
-	unsigned texture_id;
-	uint8_t* buffer;
-} PuglCairoGL;
-
-static cairo_surface_t*
-pugl_cairo_gl_create(PuglCairoGL* ctx, int width, int height, int bpp)
-{
-	free(ctx->buffer);
-	ctx->buffer = (uint8_t*)calloc(bpp * width * height, sizeof(uint8_t));
-	if (!ctx->buffer) {
-		fprintf(stderr, "failed to allocate surface buffer\n");
-		return NULL;
-	}
-
-	return cairo_image_surface_create_for_data(
-		ctx->buffer, CAIRO_FORMAT_ARGB32, width, height, bpp * width);
-}
-
-static void
-pugl_cairo_gl_free(PuglCairoGL* ctx)
-{
-	free(ctx->buffer);
-	ctx->buffer = NULL;
-}
-
-static void
-pugl_cairo_gl_configure(PuglCairoGL* ctx, int width, int height)
-{
-	glDisable(GL_DEPTH_TEST);
-	glEnable(GL_BLEND);
-	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glEnable(GL_TEXTURE_RECTANGLE_ARB);
-
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
-
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	glDeleteTextures(1, &ctx->texture_id);
-	glGenTextures(1, &ctx->texture_id);
-	glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ctx->texture_id);
-	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
-}
-
-static void
-pugl_cairo_gl_draw(PuglCairoGL* ctx, int width, int height)
-{
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-	glViewport(0, 0, width, height);
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	glPushMatrix();
-	glEnable(GL_TEXTURE_RECTANGLE_ARB);
-	glEnable(GL_TEXTURE_2D);
-
-	glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
-	             width, height, 0,
-	             GL_BGRA, GL_UNSIGNED_BYTE, ctx->buffer);
-
-	glBegin(GL_QUADS);
-	glTexCoord2f(0.0f, (GLfloat)height);
-	glVertex2f(-1.0f, -1.0f);
-
-	glTexCoord2f((GLfloat)width, (GLfloat)height);
-	glVertex2f(1.0f, -1.0f);
-
-	glTexCoord2f((GLfloat)width, 0.0f);
-	glVertex2f(1.0f, 1.0f);
-
-	glTexCoord2f(0.0f, 0.0f);
-	glVertex2f(-1.0f, 1.0f);
-	glEnd();
-
-	glDisable(GL_TEXTURE_2D);
-	glDisable(GL_TEXTURE_RECTANGLE_ARB);
-	glPopMatrix();
-}
-
-#endif
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 1b22260..1cfe3c9 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -82,9 +82,8 @@ typedef enum {
    Drawing context type.
 */
 typedef enum {
-	PUGL_GL       = 0x1,
-	PUGL_CAIRO    = 0x2,
-	PUGL_CAIRO_GL = 0x3
+	PUGL_GL    = 0x1,  /**< OpenGL (3D) */
+	PUGL_CAIRO = 0x2   /**< Cairo (2D) */
 } PuglContextType;
 
 /**
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index ef08ac8..5acd797 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -39,7 +39,6 @@
 #include <cairo/cairo.h>
 #endif
 
-#include "pugl/cairo_gl.h"
 #include "pugl/pugl_internal.h"
 
 #ifndef MIN
@@ -97,9 +96,6 @@ struct PuglInternalsImpl {
 	GLXContext       ctx;
 	int              doubleBuffered;
 #endif
-#if defined(PUGL_HAVE_CAIRO) && defined(PUGL_HAVE_GL)
-	PuglCairoGL      cairo_gl;
-#endif
 };
 
 PuglInternals*
@@ -165,12 +161,6 @@ createContext(PuglView* view, XVisualInfo* vi)
 			impl->display, impl->win, vi->visual, view->width, view->height);
 	}
 #endif
-#if defined(PUGL_HAVE_GL) && defined(PUGL_HAVE_CAIRO)
-	if (view->ctx_type == PUGL_CAIRO_GL) {
-		impl->surface = pugl_cairo_gl_create(
-			&impl->cairo_gl, view->width, view->height, 4);
-	}
-#endif
 
 #ifdef PUGL_HAVE_CAIRO
 	if (view->ctx_type & PUGL_CAIRO) {
@@ -193,11 +183,6 @@ createContext(PuglView* view, XVisualInfo* vi)
 static void
 destroyContext(PuglView* view)
 {
-#if defined(PUGL_HAVE_CAIRO) && defined(PUGL_HAVE_GL)
-	if (view->ctx_type == PUGL_CAIRO_GL) {
-		pugl_cairo_gl_free(&view->impl->cairo_gl);
-	}
-#endif
 #ifdef PUGL_HAVE_GL
 	if (view->ctx_type & PUGL_GL) {
 		glXDestroyContext(view->impl->display, view->impl->ctx);
@@ -226,12 +211,6 @@ puglLeaveContext(PuglView* view, bool flush)
 {
 #ifdef PUGL_HAVE_GL
 	if (flush && view->ctx_type & PUGL_GL) {
-#ifdef PUGL_HAVE_CAIRO
-		if (view->ctx_type == PUGL_CAIRO_GL) {
-			pugl_cairo_gl_draw(&view->impl->cairo_gl, view->width, view->height);
-		}
-#endif
-
 		glFlush();
 		if (view->impl->doubleBuffered) {
 			glXSwapBuffers(view->impl->display, view->impl->win);
@@ -662,21 +641,6 @@ puglProcessEvents(PuglView* view)
 			                            config_event.configure.width,
 			                            config_event.configure.height);
 		}
-#ifdef PUGL_HAVE_GL
-		if (view->ctx_type == PUGL_CAIRO_GL) {
-			view->redisplay = true;
-			cairo_surface_destroy(view->impl->surface);
-			view->impl->surface = pugl_cairo_gl_create(
-				&view->impl->cairo_gl,
-				config_event.configure.width,
-				config_event.configure.height,
-				4);
-			pugl_cairo_gl_configure(&view->impl->cairo_gl,
-			                        config_event.configure.width,
-			                        config_event.configure.height);
-			createCairoContext(view);
-		}
-#endif
 #endif
 		puglDispatchEvent(view, (const PuglEvent*)&config_event);
 	}
diff --git a/pugl_cairo_test.c b/pugl_cairo_test.c
index 76c3ee7..78abcfa 100644
--- a/pugl_cairo_test.c
+++ b/pugl_cairo_test.c
@@ -162,19 +162,15 @@ onEvent(PuglView* view, const PuglEvent* event)
 int
 main(int argc, char** argv)
 {
-	bool useGL           = false;
 	bool ignoreKeyRepeat = false;
 	bool resizable       = false;
 	for (int i = 1; i < argc; ++i) {
 		if (!strcmp(argv[i], "-h")) {
 			printf("USAGE: %s [OPTIONS]...\n\n"
-			       "  -g  Use OpenGL\n"
 			       "  -h  Display this help\n"
 			       "  -i  Ignore key repeat\n"
 			       "  -r  Resizable window\n", argv[0]);
 			return 0;
-		} else if (!strcmp(argv[i], "-g")) {
-			useGL = true;
 		} else if (!strcmp(argv[i], "-i")) {
 			ignoreKeyRepeat = true;
 		} else if (!strcmp(argv[i], "-r")) {
@@ -187,7 +183,7 @@ main(int argc, char** argv)
 	PuglView* view = puglInit(NULL, NULL);
 	puglInitWindowSize(view, 512, 512);
 	puglInitResizable(view, resizable);
-	puglInitContextType(view, useGL ? PUGL_CAIRO_GL : PUGL_CAIRO);
+	puglInitContextType(view, PUGL_CAIRO);
 
 	puglIgnoreKeyRepeat(view, ignoreKeyRepeat);
 	puglSetEventFunc(view, onEvent);
-- 
cgit v1.2.3