ecere: gfx/gui: support P/NaCl platform. add new Pepper interface driver for targetin...
[sdk] / ecere / src / gfx / drivers / XDisplayDriver.ec
index ed272af..e4401ff 100644 (file)
@@ -2,7 +2,7 @@ namespace gfx::drivers;
 
 import "instance"
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX) && !defined(__EMSCRIPTEN__) && !defined(__pnacl__)
 
 default:
 
@@ -21,8 +21,10 @@ default:
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#if !defined(__EMSCRIPTEN__) && !defined(__pnacl__)
 #include <X11/extensions/shape.h>
 #include <X11/extensions/Xrender.h>
+#endif
 #include <X11/extensions/XShm.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
@@ -70,6 +72,7 @@ class XSurface : struct
    bool opaqueText;
    int xOffset;
    bool writingText;
+   bool writingOutline;
 
    ColorAlpha foreground, background;
    bool opaque;
@@ -517,6 +520,8 @@ class XDisplayDriver : DisplayDriver
                xDisplay.image = XShmCreateImage(xGlobalDisplay, xSystemVisual /*DefaultVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay))*/,
                   format->depth, ZPixmap, null, &xDisplay.shminfo, width, height);
             }
+            else if(display.useSharedMemory && !xSharedMemory)
+               printf("%s", $"Error: Requested shared memory but shared memory pixmaps are not supported by X server.\n");
 #endif
             if(xDisplay.image)
             {
@@ -538,7 +543,7 @@ class XDisplayDriver : DisplayDriver
                         xDisplay.bitmap.height = height;
                         xDisplay.bitmap.stride = xDisplay.image->bytes_per_line >> GetColorDepthShifts(display.pixelFormat);
                         xDisplay.bitmap.pixelFormat = display.pixelFormat;
-                        xDisplay.bitmap.picture = xDisplay.shminfo.shmaddr;
+                        xDisplay.bitmap.picture = (byte *)xDisplay.shminfo.shmaddr;
                         xDisplay.bitmap.size = width * height;
                         xDisplay.bitmap.sizeBytes = (uint)xDisplay.bitmap.size << GetColorDepthShifts(display.pixelFormat);
                      }
@@ -628,7 +633,7 @@ class XDisplayDriver : DisplayDriver
 
    void RestorePalette(Display display)
    {
-      XDisplay xDisplay = display.driverData;
+
    }
 
    void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
@@ -721,7 +726,7 @@ class XDisplayDriver : DisplayDriver
       */
       // image.red_mask  = 0xFFFF0000;
 
-      image.data = bitmap.picture;
+      image.data = (char *)bitmap.picture;
       XInitImage(&image);
 
       if(bitmap.pixelFormat != pixelFormatAlpha && bitmap.alphaBlend)
@@ -839,7 +844,6 @@ class XDisplayDriver : DisplayDriver
       XSurface xSurface = surface.driverData;
       XDisplay xDisplay = display.driverData;
       bool changed = false;
-      XRectangle rectangle;
       if(clip != null)
       {
          Box box = clip;
@@ -908,7 +912,7 @@ class XDisplayDriver : DisplayDriver
          xImage = XGetImage(xGlobalDisplay, DefaultRootWindow(xGlobalDisplay), sx, sy, sw, sh, MAXDWORD, ZPixmap);
 
       source.pixelFormat = format;
-      source.picture = xImage->data;
+      source.picture = (byte *)xImage->data;
       source.width = sw;
       source.height = sh;
       source.stride = xImage->bytes_per_line / 4;
@@ -936,8 +940,7 @@ class XDisplayDriver : DisplayDriver
    {
       XSurface xSurface = surface.driverData;
       XDisplay xDisplay = display ? display.driverData : null;
-      XRenderColor renderColor = { color.color.r * color.a, color.color.g * color.a, color.color.b * color.a, color.a * 255};
-      X11Picture colorPicture;
+      XRenderColor renderColor = { (uint16)(color.color.r * color.a), (uint16)(color.color.g * color.a), (uint16)(color.color.b * color.a), (uint16)(color.a * 255) };
 
       if(xSurface.colorPicture)
          XRenderFreePicture(xGlobalDisplay, xSurface.colorPicture);
@@ -1189,7 +1192,7 @@ class XDisplayDriver : DisplayDriver
             (uint16)(xSurface.background.color.r * xSurface.background.a),
             (uint16)(xSurface.background.color.g * xSurface.background.a),
             (uint16)(xSurface.background.color.b * xSurface.background.a),
-            (uint16)xSurface.background.a * 255
+            (uint16)(xSurface.background.a * 255)
          };
          x1 += surface.offset.x;
          y1 += surface.offset.y;
@@ -1227,7 +1230,7 @@ class XDisplayDriver : DisplayDriver
                (uint16)(xSurface.background.color.r * xSurface.background.a),
                (uint16)(xSurface.background.color.g * xSurface.background.a),
                (uint16)(xSurface.background.color.b * xSurface.background.a),
-               (uint16)xSurface.background.a * 255
+               (uint16)(xSurface.background.a * 255)
             };
             x1 += surface.offset.x;
             y1 += surface.offset.y;
@@ -1366,7 +1369,6 @@ class XDisplayDriver : DisplayDriver
 
    void Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
    {
-      XDisplay xDisplay = display.driverData;
       XSurface xSurface = surface.driverData;
       XBitmap xBitmap = src.driverData;
       if(xBitmap)
@@ -1438,7 +1440,7 @@ class XDisplayDriver : DisplayDriver
          image.bytes_per_line = ((src.pixelFormat == pixelFormat888) ? 4 : 2) * src.stride;
          image.bits_per_pixel = (src.pixelFormat == pixelFormat888) ? 32 : 16;
 
-         image.data = src.picture;
+         image.data = (char *)src.picture;
          XInitImage(&image);
 
          XPutImage(xGlobalDisplay, (Pixmap)xSurface.pixmap, xDisplay.gc, &image,
@@ -1461,7 +1463,7 @@ class XDisplayDriver : DisplayDriver
          image.bytes_per_line = ((temp.pixelFormat == pixelFormat888) ? 4 : 2) * temp.stride;
          image.bits_per_pixel = (temp.pixelFormat == pixelFormat888) ? 32 : 16;
 
-         image.data = temp.picture;
+         image.data = (char *)temp.picture;
 
          XInitImage(&image);
          if(!src.transparent)
@@ -1588,7 +1590,7 @@ class XDisplayDriver : DisplayDriver
          image.bytes_per_line = ((temp.pixelFormat == pixelFormat888) ? 4 : 2) * temp.stride;
          image.bits_per_pixel = (temp.pixelFormat == pixelFormat888) ? 32 : 16;
 
-         image.data = temp.picture;
+         image.data = (char *)temp.picture;
          XInitImage(&image);
 
          // printf("Blitting DI\n");
@@ -1623,7 +1625,7 @@ class XDisplayDriver : DisplayDriver
          image.bytes_per_line = ((temp.pixelFormat == pixelFormat888) ? 4 : 2) * temp.stride;
          image.bits_per_pixel = (temp.pixelFormat == pixelFormat888) ? 32 : 16;;
 
-         image.data = temp.picture;
+         image.data = (char *)temp.picture;
          XInitImage(&image);
 
          // printf("Blitting DI\n");
@@ -1635,7 +1637,7 @@ class XDisplayDriver : DisplayDriver
       }
    }
 
-   Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
+   Font LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
    {
       Font font;
       font = ((subclass(DisplayDriver))class(LFBDisplayDriver)).LoadFont(displaySystem, faceName, size, flags);
@@ -1662,10 +1664,10 @@ class XDisplayDriver : DisplayDriver
    #define CHAR_WIDTH   6
    #define CHAR_HEIGHT  14
 
-   void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
+   void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
    {
       XSurface xSurface = surface.driverData;
-      XDisplay xDisplay = display.driverData;
+      //XDisplay xDisplay = display.driverData;
       int tw, th;
 
       ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextExtent(display, surface, text, len, &tw, &th);
@@ -1700,7 +1702,7 @@ class XDisplayDriver : DisplayDriver
       ((subclass(DisplayDriver))class(LFBDisplayDriver)).WriteText(display, surface, x, y, text, len);
    }
 
-   void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
+   void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
    {
       XSurface xSurface = surface.driverData;
       /*
@@ -1713,7 +1715,7 @@ class XDisplayDriver : DisplayDriver
       FontExtent(display.displaySystem, xSurface.font, text, len, width, height);
    }
 
-   void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height)
+   void FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
    {
       /*
       if(width) *width = len * CHAR_WIDTH;
@@ -1729,7 +1731,6 @@ class XDisplayDriver : DisplayDriver
 
    void LineStipple(Display display, Surface surface, uint stipple)
    {
-      XSurface xSurface = surface.driverData;
       XDisplay xDisplay = display.driverData;
       char list[32] = { 0 };
       int count = 0;
@@ -1841,13 +1842,13 @@ class XDisplayDriver : DisplayDriver
    }
 }
 
-default dllexport int __attribute__((stdcall)) IS_XGetPixmap(Bitmap bitmap)
+default dllexport long IS_XGetPixmap(Bitmap bitmap)
 {
    XBitmap xBitmap = bitmap.driverData;
    return xBitmap.pixmap;
 }
 
-default dllexport void __attribute__((stdcall)) IS_XGetSurfaceInfo(Surface surface, Pixmap * pixmap, GC * gc, int *x, int * y)
+default dllexport void IS_XGetSurfaceInfo(Surface surface, Pixmap * pixmap, GC * gc, int *x, int * y)
 {
    Display display = surface.display;
    XDisplay xDisplay = display.driverData;