1 /*
2   Copyright 2012-2020 David Robillard <d@drobilla.net>
3 
4   Permission to use, copy, modify, and/or distribute this software for any
5   purpose with or without fee is hereby granted, provided that the above
6   copyright notice and this permission notice appear in all copies.
7 
8   THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 
17 #ifndef PUGL_DETAIL_TYPES_H
18 #define PUGL_DETAIL_TYPES_H
19 
20 #include "pugl/pugl.h"
21 
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 // Unused parameter macro to suppresses warnings and make it impossible to use
27 #if defined(__cplusplus)
28 #  define PUGL_UNUSED(name)
29 #elif defined(__GNUC__) || defined(__clang__)
30 #  define PUGL_UNUSED(name) name##_unused __attribute__((__unused__))
31 #else
32 #  define PUGL_UNUSED(name) name
33 #endif
34 
35 /// Platform-specific world internals
36 typedef struct PuglWorldInternalsImpl PuglWorldInternals;
37 
38 /// Platform-specific view internals
39 typedef struct PuglInternalsImpl PuglInternals;
40 
41 /// View hints
42 typedef int PuglHints[PUGL_NUM_VIEW_HINTS];
43 
44 /// Blob of arbitrary data
45 typedef struct {
46   void*  data; ///< Dynamically allocated data
47   size_t len;  ///< Length of data in bytes
48 } PuglBlob;
49 
50 /// Cross-platform view definition
51 struct PuglViewImpl {
52   PuglWorld*         world;
53   const PuglBackend* backend;
54   PuglInternals*     impl;
55   PuglHandle         handle;
56   PuglEventFunc      eventFunc;
57   char*              title;
58   PuglBlob           clipboard;
59   PuglNativeView     parent;
60   uintptr_t          transientParent;
61   PuglRect           frame;
62   PuglEventConfigure lastConfigure;
63   PuglHints          hints;
64   int                defaultWidth;
65   int                defaultHeight;
66   int                minWidth;
67   int                minHeight;
68   int                maxWidth;
69   int                maxHeight;
70   int                minAspectX;
71   int                minAspectY;
72   int                maxAspectX;
73   int                maxAspectY;
74   bool               visible;
75 };
76 
77 /// Cross-platform world definition
78 struct PuglWorldImpl {
79   PuglWorldInternals* impl;
80   PuglWorldHandle     handle;
81   char*               className;
82   double              startTime;
83   size_t              numViews;
84   PuglView**          views;
85 };
86 
87 /// Opaque surface used by graphics backend
88 typedef void PuglSurface;
89 
90 /// Graphics backend interface
91 struct PuglBackendImpl {
92   /// Get visual information from display and setup view as necessary
93   PuglStatus (*configure)(PuglView*);
94 
95   /// Create surface and drawing context
96   PuglStatus (*create)(PuglView*);
97 
98   /// Destroy surface and drawing context
99   PuglStatus (*destroy)(PuglView*);
100 
101   /// Enter drawing context, for drawing if expose is non-null
102   PuglStatus (*enter)(PuglView*, const PuglEventExpose*);
103 
104   /// Leave drawing context, after drawing if expose is non-null
105   PuglStatus (*leave)(PuglView*, const PuglEventExpose*);
106 
107   /// Return the puglGetContext() handle for the application, if any
108   void* (*getContext)(PuglView*);
109 };
110 
111 #endif // PUGL_DETAIL_TYPES_H
112