CF & F both building + other fixes

This commit is contained in:
Lubos Dolezel 2017-02-28 17:52:50 +01:00
parent cf5eb30667
commit 95645475a0
21 changed files with 16 additions and 1608 deletions

6
.gitmodules vendored
View File

@ -190,3 +190,9 @@
[submodule "src/external/configd"]
path = src/external/configd
url = ../darling-configd.git
[submodule "src/external/coregraphics"]
path = src/external/coregraphics
url = ../darling-coregraphics.git
[submodule "src/external/IONetworkingFamily"]
path = src/external/IONetworkingFamily
url = ../darling-IONetworkingFamily.git

View File

@ -110,10 +110,11 @@ add_subdirectory(external/libxslt)
add_subdirectory(external/icu/icuSources)
add_subdirectory(external/corefoundation)
add_subdirectory(external/openssl/src)
#add_subdirectory(external/foundation)
#add_subdirectory(external/configd/SystemConfiguration.fproj)
add_subdirectory(external/foundation)
add_subdirectory(external/curl)
add_subdirectory(external/liblzma)
#add_subdirectory(external/cfnetwork)
#add_subdirectory(external/cfnetwork/src)
add_subdirectory(external/pcre)
add_subdirectory(external/sqlite)
add_subdirectory(external/openpam)

View File

@ -1,37 +0,0 @@
#ifndef CGBASE_H_
#define CGBASE_H_
#include <limits.h>
#ifndef CGFLOAT_DEFINED
# ifdef __x86_64__
# define CGFLOAT_IS_DOUBLE 1
# define CGFLOAT_MIN DBL_MIN
# define CGFLOAT_MAX DBL_MAX
# ifdef DARLING_BUILD
# define CGFLOAT_EPSILON DBL_EPSILON
# endif
typedef double CGFloat;
# else
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
# ifdef DARLING_BUILD
# define CGFLOAT_EPSILON FLT_EPSILON
# endif
typedef float CGFloat;
# endif
#endif
#ifndef BEGIN_EXTERN_C
# ifdef __cplusplus
# define BEGIN_EXTERN_C extern "C" {
# define END_EXTERN_C }
# else
# define BEGIN_EXTERN_C
# define END_EXTERN_C
# endif
#endif
#endif

View File

@ -1,100 +0,0 @@
#include "CGContext.h"
#include <CoreFoundation/CFRuntime.h>
#include <CoreFoundation/CFDictionary.h>
#include <CoreFoundation/CFString.h>
#include <QPainter>
static CFTypeID _kCGContextTypeID;
__attribute__((constructor)) void CGContextInitialize();
struct __CGContext
{
CFRuntimeBase _parent;
QPainter* painter;
};
CGContextRef CGContextForPaintDevice(QPaintDevice* paintDevice)
{
CGContextRef context = (CGContextRef)_CFRuntimeCreateInstance (nullptr, _kCGContextTypeID,
sizeof(struct __CGContext) - sizeof(CFRuntimeBase), nullptr);
// TODO: mutual reference counting?
context->painter = new QPainter(paintDevice);
return context;
}
QPainter* CGContextGetPainter(CGContextRef ref)
{
return ref->painter;
}
CGContextRef CGContextRetain(CGContextRef c)
{
if (c)
CFRetain(c);
return c;
}
void CGContextRelease(CGContextRef c)
{
if (c)
CFRelease(c);
}
static CFHashCode CGContextHash (CFTypeRef cf)
{
return CFHash (cf);
}
static CFStringRef CGContextCopyFormattingDesc (CFTypeRef cf, CFDictionaryRef formatOptions)
{
return CFSTR("CGContext");
}
static Boolean CGContextEqual (CFTypeRef cf1, CFTypeRef cf2)
{
return cf1 == cf2;
}
static void CGContextDealloc(CFTypeRef cf)
{
CGContextRef ref = CGContextRef(cf);
delete ref->painter;
}
void CGContextInitialize()
{
static const CFRuntimeClass CGContextClass =
{
0,
"CGContext",
NULL,
NULL,
CGContextDealloc,
NULL,
CGContextHash,
CGContextCopyFormattingDesc,
NULL
};
_kCGContextTypeID = _CFRuntimeRegisterClass (&CGContextClass);
}
CFTypeID CGContextGetTypeID(void)
{
return _kCGContextTypeID;
}
void CGContextSaveGState(CGContextRef c)
{
c->painter->save();
}
void CGContextRestoreGState(CGContextRef c)
{
c->painter->restore();
}
void CGContextFlush(CGContextRef c)
{
}

View File

@ -1,21 +0,0 @@
#ifndef CGCONTEXT_H_
#define CGCONTEXT_H_
#include "CGGeometry.h"
#include <CoreFoundation/CFBase.h>
BEGIN_EXTERN_C
struct __CGContext;
typedef struct __CGContext *CGContextRef;
CGContextRef CGContextRetain(CGContextRef c);
void CGContextRelease(CGContextRef c);
CFTypeID CGContextGetTypeID(void);
void CGContextSaveGState(CGContextRef c);
void CGContextRestoreGState(CGContextRef c);
void CGContextFlush(CGContextRef c);
END_EXTERN_C
#endif

View File

@ -1,117 +0,0 @@
/*
This file is part of Darling.
Copyright (C) 2013 Lubos Dolezel
Darling is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Darling is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CGDIRECTDISPLAY_H
#define CGDIRECTDISPLAY_H
#include <stdint.h>
#include <Foundation/NSString.h>
#include <CoreFoundation/CFDictionary.h>
#include <CoreFoundation/CFArray.h>
#include <CoreGraphics/CGGeometry.h>
#include "CGError.h"
extern "C"
{
typedef uint32_t CGCaptureOptions;
typedef uint32_t CGDirectDisplayID;
typedef CFDictionaryRef CGDisplayModeRef;
typedef float CGGammaValue;
CGDirectDisplayID CGMainDisplayID();
// couple of missing functions (locating the displays)
CGError CGGetActiveDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut);
CGError CGGetOnlineDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut);
size_t CGDisplayPixelsWide(CGDirectDisplayID id);
size_t CGDisplayPixelsHigh(CGDirectDisplayID id);
// old mode APIs
extern CFStringRef kCGDisplayWidth;
extern CFStringRef kCGDisplayHeight;
extern CFStringRef kCGDisplayMode;
extern CFStringRef kCGDisplayBitsPerPixel;
extern CFStringRef kCGDisplayBitsPerSample;
extern CFStringRef kCGDisplaySamplesPerPixel;
extern CFStringRef kCGDisplayRefreshRate;
extern CFStringRef kCGDisplayModeUsableForDesktopGUI;
extern CFStringRef kCGDisplayIOFlags;
extern CFStringRef kCGDisplayBytesPerRow;
CFDictionaryRef CGDisplayCurrentMode(CGDirectDisplayID id);
CGError CGDisplaySwitchToMode(CGDirectDisplayID id, CFDictionaryRef mode);
// new mode APIs
CFArrayRef CGDisplayCopyAllDisplayModes(CGDirectDisplayID id);
CGDisplayModeRef CGDisplayCopyDisplayMode(CGDirectDisplayID id);
CGDisplayModeRef CGDisplayModeRetain(CGDisplayModeRef mode);
void CGDisplayModeRelease(CGDisplayModeRef mode);
CFStringRef CGDisplayModeCopyPixelEncoding(CGDisplayModeRef mode);
size_t CGDisplayModeGetHeight(CGDisplayModeRef mode);
double CGDisplayModeGetRefreshRate(CGDisplayModeRef mode);
CFTypeID CGDisplayModeGetTypeID(); // typeid of CGDisplayModeRef
size_t CGDisplayModeGetWidth(CGDisplayModeRef mode);
bool CGDisplayModeIsUsableForDesktopGUI(CGDisplayModeRef mode);
bool CGDisplayIsActive(CGDirectDisplayID id);
bool CGDisplayIsAlwaysInMirrorSet(CGDirectDisplayID id);
bool CGDisplayIsAsleep(CGDirectDisplayID id);
bool CGDisplayIsBuiltin(CGDirectDisplayID id);
bool CGDisplayIsCaptured(CGDirectDisplayID id);
bool CGDisplayIsInHWMirrorSet(CGDirectDisplayID id);
bool CGDisplayIsInMirrorSet(CGDirectDisplayID id);
bool CGDisplayIsMain(CGDirectDisplayID id);
bool CGDisplayIsOnline(CGDirectDisplayID id);
bool CGDisplayIsStereo(CGDirectDisplayID id);
CGDirectDisplayID CGDisplayMirrorsDisplay(CGDirectDisplayID id);
uint32_t CGDisplayModelNumber(CGDirectDisplayID);
CGDirectDisplayID CGDisplayPrimaryDisplay(CGDirectDisplayID id);
double CGDisplayRotation(CGDirectDisplayID id);
CGSize CGDisplayScreenSize(CGDirectDisplayID id);
uint32_t CGDisplaySerialNumber(CGDirectDisplayID id);
CGError CGDisplaySetDisplayMode(CGDirectDisplayID id, CGDisplayModeRef mode, CFDictionaryRef unused);
uint32_t CGDisplayUnitNumber(CGDirectDisplayID id);
bool CGDisplayUsesOpenGLAcceleration(CGDirectDisplayID id);
uint32_t CGDisplayVendorNumber(CGDirectDisplayID id);
CGError CGCaptureAllDisplays();
CGError CGCaptureAllDisplaysWithOptions(CGCaptureOptions opts);
bool CGDisplayIsCaptured(CGDirectDisplayID id);
CGError CGDisplayRelease(CGDirectDisplayID id);
CGError CGReleaseAllDisplays();
CGError CGDisplayHideCursor(CGDirectDisplayID id);
CGError CGDisplayShowCursor(CGDirectDisplayID id);
CGError CGDisplayMoveCursorToPoint(CGDirectDisplayID id, CGPoint pt);
void CGGetLastMouseDelta(int32_t* x, int32_t* y);
// gamma
CGError CGSetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue redMin, CGGammaValue redMax, CGGammaValue redGamma,
CGGammaValue greenMin, CGGammaValue greenMax, CGGammaValue greenGamma, CGGammaValue blueMin, CGGammaValue blueMax, CGGammaValue blueGamma);
CGError CGGetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue* redMin, CGGammaValue* redMax, CGGammaValue* redGamma,
CGGammaValue* greenMin, CGGammaValue* greenMax, CGGammaValue* greenGamma, CGGammaValue* blueMin, CGGammaValue* blueMax, CGGammaValue* blueGamma);
uint32_t CGDisplayGammaTableCapacity(CGDirectDisplayID id);
CGError CGSetDisplayTransferByTable(CGDirectDisplayID id, uint32_t tableSize, const CGGammaValue* redTable, const CGGammaValue* greenTable, const CGGammaValue* blueTable);
CGError CGGetDisplayTransferByTable(CGDirectDisplayID id, uint32_t capacity, CGGammaValue* redTable, CGGammaValue* greenTable, CGGammaValue* blueTable, uint32_t* sampleCount);
}
#endif

View File

@ -1,593 +0,0 @@
/*
This file is part of Darling.
Copyright (C) 2013 Lubos Dolezel
Darling is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Darling is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "CGDirectDisplay.h"
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFNumber.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <cstdlib>
#include <cmath>
static Display* g_display = nullptr;
static Display* getDisplay();
static void closeDisplay() __attribute__((destructor));
static int g_lastMouseX = -1, g_lastMouseY = -1;
CFStringRef kCGDisplayWidth = CFSTR("Width");
CFStringRef kCGDisplayHeight = CFSTR("Height");
CFStringRef kCGDisplayMode = CFSTR("Mode");
CFStringRef kCGDisplayBitsPerPixel = CFSTR("BitsPerPixel");
CFStringRef kCGDisplayBitsPerSample = CFSTR("BitsPerSample");
CFStringRef kCGDisplaySamplesPerPixel = CFSTR("SamplesPerPixel");
CFStringRef kCGDisplayRefreshRate = CFSTR("RefreshRate");
CFStringRef kCGDisplayModeUsableForDesktopGUI = CFSTR("UsableForDesktopGUI");
CFStringRef kCGDisplayIOFlags = CFSTR("IOFlags");
CFStringRef kCGDisplayBytesPerRow = CFSTR("kCGDisplayBytesPerRow");
static CFStringRef kCGDarlingResolutionIndex = CFSTR("kCGDarlingResolutionIndex");
Display* getDisplay()
{
if (g_display)
return g_display;
g_display = XOpenDisplay(nullptr);
// Returning a CG error would be better than this
if (!g_display)
{
std::cerr << "Darling CG: Cannot open a connection to the X server!\n";
if (!getenv("DISPLAY"))
std::cerr << "The application you are trying to run requires an X server and cannot be run only in the console.\n";
abort();
}
int evbase, errbase;
if (!XRRQueryExtension(g_display, &evbase, &errbase))
{
std::cerr << "Darling CG: XRandR not available\n";
abort();
}
return g_display;
}
void closeDisplay()
{
if (g_display)
{
XCloseDisplay(g_display);
g_display = nullptr;
}
}
bool checkRandRVersion(int minMaj, int minMin)
{
static int maj = 0, min = 0;
if (!maj && !min)
XRRQueryVersion(getDisplay(), &maj, &min);
if (minMaj < maj)
return false;
if (minMin < min)
return false;
return true;
}
CGError CGCaptureAllDisplays()
{
return kCGErrorSuccess;
}
CGError CGCaptureAllDisplaysWithOptions(CGCaptureOptions opts)
{
return kCGErrorSuccess;
}
bool CGDisplayIsCaptured(CGDirectDisplayID id)
{
return true;
}
CGError CGDisplayRelease(CGDirectDisplayID id)
{
return kCGErrorSuccess;
}
CGError CGReleaseAllDisplays()
{
return kCGErrorSuccess;
}
CGError CGDisplayMoveCursorToPoint(CGDirectDisplayID id, CGPoint pt)
{
Display* dpy = getDisplay();
Window root_window;
root_window = XRootWindow(dpy, 0);
XSelectInput(dpy, root_window, KeyReleaseMask);
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, pt.x, pt.y);
g_lastMouseX = pt.x;
g_lastMouseY = pt.y;
XFlush(dpy);
return kCGErrorSuccess;
}
void CGGetLastMouseDelta(int32_t* x, int32_t* y)
{
Display* dpy = getDisplay();
Window root_window;
Window window_returned;
int root_x, root_y;
int win_x, win_y;
unsigned int mask_return;
root_window = XRootWindow(dpy, 0);
XQueryPointer(dpy, root_window, &window_returned,
&window_returned, &root_x, &root_y, &win_x, &win_y,
&mask_return);
if (g_lastMouseX == -1)
*x = 0;
else
*x = root_x - g_lastMouseX;
if (g_lastMouseY == -1)
*y = 0;
else
*y = root_y - g_lastMouseY;
g_lastMouseX = root_x;
g_lastMouseY = root_y;
}
CGError CGGetActiveDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut)
{
Display* dpy = getDisplay();
int count = XScreenCount(dpy);
for (int i = 0; i < count && i < max; i++)
list[i] = i;
*countOut = std::min<uint32_t>(count, max);
return kCGErrorSuccess;
}
CGError CGGetOnlineDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut)
{
return CGGetActiveDisplayList(max, list, countOut);
}
size_t CGDisplayPixelsWide(CGDirectDisplayID id)
{
Screen* screen = XScreenOfDisplay(getDisplay(), id);
if (!screen)
return 0;
else
return XWidthOfScreen(screen);
}
size_t CGDisplayPixelsHigh(CGDirectDisplayID id)
{
Screen* screen = XScreenOfDisplay(getDisplay(), id);
if (!screen)
return 0;
else
return XHeightOfScreen(screen);
}
static void CFDictAddInt(CFMutableDictionaryRef dict, CFStringRef key, int number)
{
CFNumberRef num;
num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &number);
CFDictionaryAddValue(dict, key, num);
CFRelease(num);
}
CFArrayRef CGDisplayCopyAllDisplayModes(CGDirectDisplayID id)
{
CFMutableArrayRef rv;
Display* dpy = getDisplay();
XRRScreenConfiguration* rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id));
XRRScreenSize *rrsizes;
int nSizes;
rrsizes = XRRConfigSizes(rrc, &nSizes);
if (nSizes <= 0)
{
XRRFreeScreenConfigInfo(rrc);
return nullptr;
}
rv = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
for (int i = 0; i < nSizes; i++)
{
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
short* rates;
int nRates;
CFDictAddInt(dict, kCGDisplayWidth, rrsizes[i].width);
CFDictAddInt(dict, kCGDisplayHeight, rrsizes[i].height);
CFDictAddInt(dict, kCGDisplayBitsPerPixel, 24);
CFDictAddInt(dict, kCGDisplayIOFlags, 0);
CFDictAddInt(dict, kCGDarlingResolutionIndex, i);
CFDictionaryAddValue(dict, kCGDisplayModeUsableForDesktopGUI,
(rrsizes[i].width > 800 && rrsizes[i].height > 600) ? kCFBooleanTrue : kCFBooleanFalse);
rates = XRRConfigRates (rrc, i, &nRates);
for (int j = 0; j < nRates; j++)
{
CFMutableDictionaryRef dictR = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, (CFDictionaryRef) dict);
CFDictAddInt(dictR, kCGDisplayRefreshRate, rates[j]);
CFDictAddInt(dictR, kCGDisplayMode, (i << 16) | rates[j]);
CFArrayAppendValue(rv, dictR);
CFRelease(dictR);
}
CFRelease(dict);
}
XRRFreeScreenConfigInfo(rrc);
return (CFArrayRef) rv;
}
CGError CGDisplaySwitchToMode(CGDirectDisplayID id, CFDictionaryRef mode)
{
XRRScreenConfiguration* rrc;
Display* dpy = getDisplay();
CFNumberRef sizeIndex, refreshRate;
int sizeIndexN, refreshRateN;
Status status;
sizeIndex = (CFNumberRef) CFDictionaryGetValue(mode, kCGDarlingResolutionIndex);
if (!sizeIndex)
return kCGErrorIllegalArgument;
refreshRate = (CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayRefreshRate);
if (!refreshRate)
return kCGErrorIllegalArgument;
CFNumberGetValue(sizeIndex, kCFNumberIntType, &sizeIndexN);
CFNumberGetValue(refreshRate, kCFNumberIntType, &refreshRateN);
rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id));
// TODO: remove fixed RR_Rotate_0
status = XRRSetScreenConfigAndRate(dpy, rrc, RootWindow(dpy, id), sizeIndexN, RR_Rotate_0, refreshRateN, CurrentTime);
return (status != Success) ? kCGErrorFailure : kCGErrorSuccess;
}
CFDictionaryRef CGDisplayCurrentMode(CGDirectDisplayID id)
{
Display* dpy = getDisplay();
XRRScreenConfiguration* rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id));
XRRScreenSize *rrsizes;
int nSizes;
SizeID curSize;
Rotation curRotation;
rrsizes = XRRConfigSizes(rrc, &nSizes);
if (nSizes <= 0)
{
XRRFreeScreenConfigInfo(rrc);
return nullptr;
}
curSize = XRRConfigCurrentConfiguration(rrc, &curRotation);
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictAddInt(dict, kCGDisplayWidth, rrsizes[curSize].width);
CFDictAddInt(dict, kCGDisplayHeight, rrsizes[curSize].height);
CFDictAddInt(dict, kCGDisplayBitsPerPixel, 24);
CFDictAddInt(dict, kCGDisplayIOFlags, 0);
CFDictAddInt(dict, kCGDarlingResolutionIndex, curSize);
CFDictionaryAddValue(dict, kCGDisplayModeUsableForDesktopGUI,
(rrsizes[curSize].width > 800 && rrsizes[curSize].height > 600) ? kCFBooleanTrue : kCFBooleanFalse);
short rate = XRRConfigCurrentRate(rrc);
CFDictAddInt(dict, kCGDisplayRefreshRate, rate);
CFDictAddInt(dict, kCGDisplayMode, (curSize << 16) | rate);
XRRFreeScreenConfigInfo(rrc);
return (CFDictionaryRef) dict;
}
CGDisplayModeRef CGDisplayCopyDisplayMode(CGDirectDisplayID id)
{
return CGDisplayCurrentMode(id);
}
CGDisplayModeRef CGDisplayModeRetain(CGDisplayModeRef mode)
{
return (CGDisplayModeRef) CFRetain(mode);
}
void CGDisplayModeRelease(CGDisplayModeRef mode)
{
CFRelease(mode);
}
CFStringRef CGDisplayModeCopyPixelEncoding(CGDisplayModeRef mode)
{
return nullptr;
}
static size_t CGDisplayModeGetInt(CGDisplayModeRef mode, CFStringRef key)
{
int n;
CFNumberRef height = (CFNumberRef) CFDictionaryGetValue(mode, key);
if (!height)
return 0;
CFNumberGetValue(height, kCFNumberIntType, &n);
return n;
}
size_t CGDisplayModeGetHeight(CGDisplayModeRef mode)
{
return CGDisplayModeGetInt(mode, kCGDisplayHeight);
}
double CGDisplayModeGetRefreshRate(CGDisplayModeRef mode)
{
return CGDisplayModeGetInt(mode, kCGDisplayRefreshRate);
}
CFTypeID CGDisplayModeGetTypeID()
{
return CFDictionaryGetTypeID();
}
size_t CGDisplayModeGetWidth(CGDisplayModeRef mode)
{
return CGDisplayModeGetInt(mode, kCGDisplayWidth);
}
bool CGDisplayModeIsUsableForDesktopGUI(CGDisplayModeRef mode)
{
CFBooleanRef _bool = (CFBooleanRef) CFDictionaryGetValue(mode, kCGDisplayModeUsableForDesktopGUI);
return !!CFBooleanGetValue(_bool);
}
bool CGDisplayIsActive(CGDirectDisplayID id)
{
return true;
}
bool CGDisplayIsAlwaysInMirrorSet(CGDirectDisplayID id)
{
return false;
}
bool CGDisplayIsAsleep(CGDirectDisplayID id)
{
return false;
}
bool CGDisplayIsBuiltin(CGDirectDisplayID id)
{
return false;
}
bool CGDisplayIsInHWMirrorSet(CGDirectDisplayID id)
{
return false;
}
bool CGDisplayIsInMirrorSet(CGDirectDisplayID id)
{
return false;
}
bool CGDisplayIsMain(CGDirectDisplayID id)
{
return true;
}
bool CGDisplayIsOnline(CGDirectDisplayID id)
{
return true;
}
bool CGDisplayIsStereo(CGDirectDisplayID id)
{
return false;
}
CGDirectDisplayID CGDisplayMirrorsDisplay(CGDirectDisplayID id)
{
return id;
}
uint32_t CGDisplayModelNumber(CGDirectDisplayID)
{
return 0;
}
CGDirectDisplayID CGDisplayPrimaryDisplay(CGDirectDisplayID id)
{
return id;
}
double CGDisplayRotation(CGDirectDisplayID id)
{
Display* dpy = getDisplay();
XRRScreenConfiguration* rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id));
Rotation rot;
XRRConfigCurrentConfiguration(rrc, &rot);
XRRFreeScreenConfigInfo(rrc);
switch (rot)
{
case RR_Rotate_0:
return 0.0;
case RR_Rotate_90:
return 90.0;
case RR_Rotate_180:
return 180.0;
case RR_Rotate_270:
return 270.0;
default:
return 0.0;
}
}
CGSize CGDisplayScreenSize(CGDirectDisplayID id)
{
Display* dpy = getDisplay();
XRRScreenResources* rrc = XRRGetScreenResources(dpy, RootWindow(dpy, id));
CGSize size;
// No idea if this is even nearly correct, idea taken from Qt
for (int i = 0; i < rrc->noutput; i++)
{
XRROutputInfo *output = XRRGetOutputInfo(dpy, rrc, rrc->outputs[i]);
if (output->crtc)
size = CGSizeMake(output->mm_width, output->mm_height);
XRRFreeOutputInfo(output);
}
XRRFreeScreenResources(rrc);
return size;
}
uint32_t CGDisplaySerialNumber(CGDirectDisplayID id)
{
return 0;
}
CGError CGDisplaySetDisplayMode(CGDirectDisplayID id, CGDisplayModeRef mode, CFDictionaryRef)
{
return CGDisplaySwitchToMode(id, mode);
}
uint32_t CGDisplayUnitNumber(CGDirectDisplayID id)
{
return 0;
}
bool CGDisplayUsesOpenGLAcceleration(CGDirectDisplayID id)
{
return true;
}
uint32_t CGDisplayVendorNumber(CGDirectDisplayID id)
{
return 0;
}
CGError CGSetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue redMin, CGGammaValue redMax, CGGammaValue redGamma,
CGGammaValue greenMin, CGGammaValue greenMax, CGGammaValue greenGamma, CGGammaValue blueMin, CGGammaValue blueMax, CGGammaValue blueGamma)
{
if (!checkRandRVersion(1, 2))
return kCGErrorNotImplemented;
int SAMPLES = CGDisplayGammaTableCapacity(id);
CGGammaValue r[SAMPLES], g[SAMPLES], b[SAMPLES];
auto CalculateSample = [](float index, float min, float max, float value) -> float
{
return min + ((max-min) * powf(index, value));
};
for (int i = 0; i < SAMPLES; i++)
{
float index = 1.0f/SAMPLES * i;
r[i] = CalculateSample(index, redMin, redMax, redGamma);
g[i] = CalculateSample(index, greenMin, greenMax, greenGamma);
b[i] = CalculateSample(index, blueMin, blueMax, blueGamma);
}
return CGSetDisplayTransferByTable(id, SAMPLES, r, g, b);
}
CGError CGGetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue* redMin, CGGammaValue* redMax, CGGammaValue* redGamma,
CGGammaValue* greenMin, CGGammaValue* greenMax, CGGammaValue* greenGamma, CGGammaValue* blueMin, CGGammaValue* blueMax, CGGammaValue* blueGamma)
{
if (!checkRandRVersion(1, 2))
return kCGErrorNotImplemented;
return kCGErrorNotImplemented;
}
uint32_t CGDisplayGammaTableCapacity(CGDirectDisplayID id)
{
if (!checkRandRVersion(1, 2))
return kCGErrorNotImplemented;
Display* dpy = getDisplay();
XRRScreenResources* rrc = XRRGetScreenResources(dpy, RootWindow(dpy, id));
int rv;
rv = XRRGetCrtcGammaSize(dpy, rrc->crtcs[0]);
XRRFreeScreenResources(rrc);
return rv;
}
CGError CGSetDisplayTransferByTable(CGDirectDisplayID id, uint32_t tableSize, const CGGammaValue* redTable, const CGGammaValue* greenTable, const CGGammaValue* blueTable)
{
if (!checkRandRVersion(1, 2))
return kCGErrorNotImplemented;
XRRCrtcGamma* gamma;
Display* dpy = getDisplay();
XRRScreenResources* rrc;
gamma = XRRAllocGamma(tableSize);
if (!gamma)
return kCGErrorCannotComplete;
rrc = XRRGetScreenResources(dpy, RootWindow(dpy, id));
for (uint32_t i = 0; i < tableSize; i++)
{
gamma->red[i] = short(redTable[i]*65535.0f);
gamma->green[i] = short(greenTable[i]*65535.0f);
gamma->blue[i] = short(blueTable[i]*65535.0f);
}
for (int i = 0; i < rrc->ncrtc; i++)
XRRSetCrtcGamma(dpy, rrc->crtcs[i], gamma);
XRRFreeScreenResources(rrc);
XRRFreeGamma(gamma);
return kCGErrorNotImplemented;
}
CGError CGGetDisplayTransferByTable(CGDirectDisplayID id, uint32_t capacity, CGGammaValue* redTable, CGGammaValue* greenTable, CGGammaValue* blueTable, uint32_t* sampleCount)
{
if (!checkRandRVersion(1, 2))
return kCGErrorNotImplemented;
return kCGErrorNotImplemented;
}

View File

@ -1,22 +0,0 @@
#ifndef CGERROR_H
#define CGERROR_H
#include <stdint.h>
typedef int32_t CGError;
enum : CGError
{
kCGErrorSuccess = 0,
kCGErrorFailure = 1000,
kCGErrorIllegalArgument,
kCGErrorInvalidConnection,
kCGErrorInvalidContext,
kCGErrorCannotComplete,
kCGErrorNotImplemented,
kCGErrorRangeCheck,
kCGErrorTypeCheck,
kCGErrorInvalidOperation = 1010,
kCGErrorNoneAvailable
};
#endif

View File

@ -1,13 +0,0 @@
#ifndef CGEVENTREF_H_
#define CGEVENTREF_H_
#ifdef DARLING_BUILD
# include <QEvent>
typedef QEvent *CGEventRef;
#else
struct __CGEvent;
typedef struct __CGEvent *CGEventRef;
#endif
#endif

View File

@ -1,404 +0,0 @@
#include "CGGeometry.h"
#include <limits>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <CoreFoundation/CFNumber.h>
#include <CoreFoundation/CFString.h>
#include <QRect>
const CGRect CGRectInfinite = { CGPoint { -CGFLOAT_MAX / 2, -CGFLOAT_MAX / 2 }, CGSize { CGFLOAT_MAX, CGFLOAT_MAX } };
const CGPoint CGPointZero = { 0, 0 };
const CGSize CGSizeZero = { 0, 0 };
const CGRect CGRectZero = { CGPointZero, CGSizeZero };
const CGRect CGRectNull = { { std::numeric_limits<CGFloat>::infinity(), std::numeric_limits<CGFloat>::infinity() }, CGSizeZero };
inline CGFloat cgabs(CGFloat a) { return a > 0 ? a : -a; }
CGPoint CGPointMake(CGFloat x, CGFloat y)
{
return CGPoint { x, y };
}
CGSize CGSizeMake(CGFloat width, CGFloat height)
{
return CGSize { width, height };
}
CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
return CGRect { CGPoint { x, y }, CGSize { width, height } };
}
CGVector CGVectorMake(CGFloat dx, CGFloat dy)
{
return CGVector { dx, dy };
}
bool CGSizeEqualToSize(CGSize size1, CGSize size2)
{
return cgabs(size1.width - size2.width) < CGFLOAT_EPSILON
&& cgabs(size1.height - size2.height) < CGFLOAT_EPSILON;
}
bool CGPointEqualToPoint(CGPoint point1, CGPoint point2)
{
return cgabs(point1.x - point2.x) < CGFLOAT_EPSILON
&& cgabs(point1.y - point2.y) < CGFLOAT_EPSILON;
}
bool CGRectEqualToRect(CGRect rect1, CGRect rect2)
{
return CGSizeEqualToSize(rect1.size, rect2.size)
&& CGPointEqualToPoint(rect1.origin, rect2.origin);
}
CGFloat CGRectGetHeight(CGRect rect)
{
return cgabs(rect.size.height);
}
CGFloat CGRectGetWidth(CGRect rect)
{
return cgabs(rect.size.width);
}
CGFloat CGRectGetMaxX(CGRect rect)
{
return (rect.size.width > 0) ? (rect.origin.x + rect.size.width) : (rect.origin.x);
}
CGFloat CGRectGetMaxY(CGRect rect)
{
return (rect.size.height > 0) ? (rect.origin.y + rect.size.height) : (rect.origin.y);
}
CGFloat CGRectGetMidY(CGRect rect)
{
return rect.origin.y + rect.size.height/2;
}
CGFloat CGRectGetMidX(CGRect rect)
{
return rect.origin.x + rect.size.width/2;
}
CGFloat CGRectGetMinX(CGRect rect)
{
return (rect.size.width > 0) ? (rect.origin.x) : (rect.origin.x + rect.size.width);
}
CGFloat CGRectGetMinY(CGRect rect)
{
return (rect.size.height > 0) ? (rect.origin.y) : (rect.origin.y + rect.size.height);
}
bool CGRectIsNull(CGRect rect)
{
return rect.origin.x == std::numeric_limits<CGFloat>::infinity()
&& rect.origin.y == std::numeric_limits<CGFloat>::infinity();
}
bool CGRectIsInfinite(CGRect rect)
{
return rect.origin.x == CGRectInfinite.origin.x
&& rect.origin.y == CGRectInfinite.origin.y
&& rect.size.width == CGRectInfinite.size.width
&& rect.size.height == CGRectInfinite.size.height;
}
bool CGRectIsEmpty(CGRect rect)
{
return rect.size.height == 0 && rect.size.width == 0;
}
bool CGRectContainsPoint(CGRect rect, CGPoint point)
{
return point.x >= rect.origin.x && point.x < rect.origin.x+rect.size.width
&& point.y >= rect.origin.y && point.y < rect.origin.y+rect.size.height;
}
bool CGRectContainsRect(CGRect rect1, CGRect rect2)
{
return CGRectContainsPoint(rect1, rect2.origin)
&& CGRectContainsPoint(rect1, CGPoint { rect2.origin.x+rect2.size.width, rect2.origin.y+rect2.size.height });
}
CGRect CGRectStandardize(CGRect rect)
{
if (rect.size.width < 0)
{
rect.origin.x += rect.size.width;
rect.size.width = -rect.size.width;
}
if (rect.size.height < 0)
{
rect.origin.y += rect.size.height;
rect.size.height = -rect.size.height;
}
return rect;
}
CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy)
{
return CGRect { CGPoint { rect.origin.x+dx, rect.origin.y+dy }, rect.size };
}
CGRect CGRectIntegral(CGRect rect)
{
return CGRect {
CGPoint { std::floor(rect.origin.x), std::floor(rect.origin.y) },
CGSize { std::ceil(rect.size.width), std::ceil(rect.size.height) }
};
}
CGRect CGRectIntersection(CGRect r1, CGRect r2)
{
r1 = CGRectStandardize(r1);
r2 = CGRectStandardize(r2);
CGFloat x0 = std::max(r1.origin.x, r2.origin.x);
CGFloat x1 = std::min(r1.origin.x + r1.size.width, r2.origin.x + r2.size.width);
if (x0 <= x1)
{
CGFloat y0 = std::max(r1.origin.y, r2.origin.y);
CGFloat y1 = std::min(r1.origin.y + r1.size.height, r2.origin.y + r2.size.height);
if (y0 <= y1)
{
return CGRect {
CGPoint { x0, y0 },
CGSize { x1 - x0, y1 - y0 }
};
}
}
return CGRectNull;
}
CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)
{
if (cgabs(dx)*2 > rect.size.width || cgabs(dy)*2 > rect.size.height)
return CGRectNull;
rect.origin.x -= dx;
rect.origin.y -= dy;
rect.size.width -= dx*2;
rect.size.height -= dy*2;
return rect;
}
CGRect CGRectUnion(CGRect r1, CGRect r2)
{
if (CGRectIsNull(r1))
return r2;
if (CGRectIsNull(r2))
return r1;
r1 = CGRectStandardize(r1);
r2 = CGRectStandardize(r2);
CGFloat x0 = std::min(r1.origin.x, r2.origin.x);
CGFloat x1 = std::max(r1.origin.x + r1.size.width, r2.origin.x + r2.size.width);
CGFloat y0 = std::min(r1.origin.y, r2.origin.y);
CGFloat y1 = std::max(r1.origin.y + r1.size.height, r2.origin.y + r2.size.height);
return CGRect {
CGPoint { x0, y0 },
CGSize { x1 - x0, y1 - y0 }
};
}
void CGRectDivide(CGRect rect, CGRect* slice, CGRect* remainder, CGFloat amount, CGRectEdge edge)
{
rect = CGRectStandardize(rect);
if (((edge == CGRectMinXEdge || edge == CGRectMaxXEdge) && amount > rect.size.width)
|| ((edge == CGRectMinYEdge || edge == CGRectMaxYEdge) && amount > rect.size.height))
{
memcpy(slice, &rect, sizeof(CGRect));
memcpy(remainder, &CGRectZero, sizeof(CGRect));
return;
}
switch (edge)
{
case CGRectMinXEdge:
slice->origin.x = rect.origin.x;
slice->origin.y = rect.origin.y;
slice->size.width = amount;
slice->size.height = rect.size.height;
remainder->origin.x = rect.origin.x + amount;
remainder->origin.y = rect.origin.y;
remainder->size.width = rect.size.width - amount;
remainder->size.height = rect.size.height;
break;
case CGRectMinYEdge:
slice->origin.x = rect.origin.x;
slice->origin.y = rect.origin.y;
slice->size.width = rect.size.width;
slice->size.height = amount;
remainder->origin.x = rect.origin.x;
remainder->origin.y = rect.origin.y + amount;
remainder->size.width = rect.size.width;
remainder->size.height = rect.size.height - amount;
break;
case CGRectMaxXEdge:
slice->origin.x = rect.origin.x + rect.size.width - amount;
slice->origin.y = rect.origin.y;
slice->size.width = amount;
slice->size.height = rect.size.height;
remainder->origin.x = rect.origin.x;
remainder->origin.y = rect.origin.y;
remainder->size.width = rect.size.width - amount;
remainder->size.height = rect.size.height;
break;
case CGRectMaxYEdge:
slice->origin.x = rect.origin.x;
slice->origin.y = rect.origin.y + rect.size.height - amount;
slice->size.width = rect.size.width;
slice->size.height = amount;
remainder->origin.x = rect.origin.x;
remainder->origin.y = rect.origin.y;
remainder->size.width = rect.size.width;
remainder->size.height = rect.size.height - amount;
break;
}
}
CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point)
{
CFNumberRef values[2];
static const CFStringRef keys[] = { CFSTR("X"), CFSTR("Y") };
CFDictionaryRef dict;
values[0] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &point.x);
values[1] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &point.y);
dict = CFDictionaryCreate(nullptr, (const void**) keys, (const void**) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(values[0]);
CFRelease(values[1]);
return dict;
}
CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size)
{
CFNumberRef values[2];
static const CFStringRef keys[] = { CFSTR("Width"), CFSTR("Height") };
CFDictionaryRef dict;
values[0] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &size.width);
values[1] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &size.height);
dict = CFDictionaryCreate(nullptr, (const void**) keys, (const void**) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(values[0]);
CFRelease(values[1]);
return dict;
}
CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect)
{
CFNumberRef values[4];
static const CFStringRef keys[] = { CFSTR("X"), CFSTR("Y"), CFSTR("Width"), CFSTR("Height") };
CFDictionaryRef dict;
values[0] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.origin.x);
values[1] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.origin.y);
values[2] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.size.width);
values[3] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.size.height);
dict = CFDictionaryCreate(nullptr, (const void**) keys, (const void**) values, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(values[0]);
CFRelease(values[1]);
CFRelease(values[2]);
CFRelease(values[3]);
return dict;
}
bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point)
{
CFNumberRef x, y;
if (!point)
return false;
x = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("X"));
y = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Y"));
if (!x || !y)
return false;
if (CFGetTypeID(x) != CFNumberGetTypeID() || CFGetTypeID(y) != CFNumberGetTypeID())
return false;
return CFNumberGetValue(x, kCFNumberCGFloatType, &point->x)
&& CFNumberGetValue(y, kCFNumberCGFloatType, &point->y);
}
bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size)
{
CFNumberRef w, h;
if (!size)
return false;
w = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Width"));
h = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Height"));
if (!w || !h)
return false;
if (CFGetTypeID(w) != CFNumberGetTypeID() || CFGetTypeID(h) != CFNumberGetTypeID())
return false;
return CFNumberGetValue(w, kCFNumberCGFloatType, &size->width)
&& CFNumberGetValue(h, kCFNumberCGFloatType, &size->height);
}
bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect)
{
CFNumberRef x, y, w, h;
if (!rect)
return false;
x = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("X"));
y = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Y"));
w = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Width"));
h = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Height"));
if (!x || !y || !w || !h)
return false;
if (CFGetTypeID(x) != CFNumberGetTypeID() || CFGetTypeID(y) != CFNumberGetTypeID()
|| CFGetTypeID(w) != CFNumberGetTypeID() || CFGetTypeID(h) != CFNumberGetTypeID())
{
return false;
}
return CFNumberGetValue(x, kCFNumberCGFloatType, &rect->origin.x)
&& CFNumberGetValue(y, kCFNumberCGFloatType, &rect->origin.y)
&& CFNumberGetValue(w, kCFNumberCGFloatType, &rect->size.width)
&& CFNumberGetValue(h, kCFNumberCGFloatType, &rect->size.height);
}

View File

@ -1,98 +0,0 @@
#ifndef CGGEOMETRY_H_
#define CGGEOMETRY_H_
#include "CGBase.h"
#include <float.h>
#include <stdbool.h>
#include <CoreFoundation/CFDictionary.h>
BEGIN_EXTERN_C
struct CGPoint
{
CGFloat x;
CGFloat y;
};
typedef struct CGPoint CGPoint;
//typedef struct CGPoint NSPoint;
struct CGSize
{
CGFloat width;
CGFloat height;
};
typedef struct CGSize CGSize;
//typedef struct CGSize NSSize;
struct CGVector
{
CGFloat dx;
CGFloat dy;
};
typedef struct CGVector CGVector;
struct CGRect
{
CGPoint origin;
CGSize size;
};
typedef struct CGRect CGRect;
//typedef struct CGRect NSRect;
enum CGRectEdge
{
CGRectMinXEdge,
CGRectMinYEdge,
CGRectMaxXEdge,
CGRectMaxYEdge
};
typedef enum CGRectEdge CGRectEdge;
extern const CGRect CGRectInfinite;
extern const CGPoint CGPointZero;
extern const CGRect CGRectZero;
extern const CGSize CGSizeZero;
extern const CGRect CGRectNull;
CGPoint CGPointMake(CGFloat x, CGFloat y);
CGSize CGSizeMake(CGFloat width, CGFloat height);
CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height);
CGVector CGVectorMake(CGFloat dx, CGFloat dy);
bool CGSizeEqualToSize(CGSize size1, CGSize size2);
bool CGPointEqualToPoint(CGPoint point1, CGPoint point2);
bool CGRectEqualToRect(CGRect rect1, CGRect rect2);
CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point);
CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size);
CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect);
bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point);
bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size);
bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect);
CGFloat CGRectGetHeight(CGRect rect);
CGFloat CGRectGetWidth(CGRect rect);
CGFloat CGRectGetMaxX(CGRect rect);
CGFloat CGRectGetMaxY(CGRect rect);
CGFloat CGRectGetMinX(CGRect rect);
CGFloat CGRectGetMinY(CGRect rect);
CGFloat CGRectGetMidX(CGRect rect);
CGFloat CGRectGetMidY(CGRect rect);
bool CGRectIsNull(CGRect rect);
bool CGRectIsInfinite(CGRect rect);
bool CGRectContainsPoint(CGRect rect, CGPoint point);
bool CGRectContainsRect(CGRect rect1, CGRect rect2);
CGRect CGRectStandardize(CGRect rect);
CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy);
CGRect CGRectIntegral(CGRect rect);
CGRect CGRectIntersection(CGRect r1, CGRect r2);
CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy);
CGRect CGRectUnion(CGRect r1, CGRect r2);
void CGRectDivide(CGRect rect, CGRect* slice, CGRect* remainder, CGFloat amount, CGRectEdge edge);
END_EXTERN_C
#endif

View File

@ -1,126 +0,0 @@
#include "CGLayer.h"
#include <QPicture>
#include <QPainter>
#include <CoreFoundation/CFRuntime.h>
#include <CoreFoundation/CFDictionary.h>
#include <CoreFoundation/CFString.h>
static CFTypeID _kCGLayerTypeID;
__attribute__((constructor)) void CGLayerInitialize();
// in CGContext.cpp
CGContextRef CGContextForPaintDevice(QPaintDevice* paintDevice);
QPainter* CGContextGetPainter(CGContextRef ref);
struct __CGLayer
{
CFRuntimeBase _parent;
QPicture* picture;
CGContextRef context;
};
void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point, CGLayerRef layer)
{
QPainter* painter = CGContextGetPainter(context);
painter->drawPicture(QPointF(point.x, point.y), *layer->picture);
}
void CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer)
{
QPainter* painter = CGContextGetPainter(context);
QTransform tf = painter->worldTransform();
qreal sx, sy;
CGSize origSize = CGLayerGetSize(layer);
sx = CGRectGetWidth(rect) / origSize.width;
sy = CGRectGetHeight(rect) / origSize.height;
painter->scale(sx, sy);
painter->drawPicture(QPointF(rect.origin.x / sx, rect.origin.y / sy), *layer->picture);
painter->setWorldTransform(tf);
}
CGLayerRef CGLayerCreateWithContext(CGContextRef context, CGSize size, CFDictionaryRef auxiliaryInfo)
{
CGLayerRef layer = (CGLayerRef)_CFRuntimeCreateInstance (nullptr, _kCGLayerTypeID,
sizeof(struct __CGLayer) - sizeof(CFRuntimeBase), nullptr);
layer->picture = new QPicture;
layer->picture->setBoundingRect(QRect(0, 0, size.width, size.height));
layer->context = CGContextForPaintDevice(layer->picture);
// TODO: copy over settings from "context"
return layer;
}
CGContextRef CGLayerGetContext(CGLayerRef layer)
{
return layer->context;
}
CGSize CGLayerGetSize(CGLayerRef layer)
{
QRect rect = layer->picture->boundingRect();
return CGSize { CGFloat(rect.width()), CGFloat(rect.height()) };
}
static CFHashCode CGLayerHash (CFTypeRef cf)
{
return CFHash (cf);
}
static CFStringRef CGLayerCopyFormattingDesc (CFTypeRef cf, CFDictionaryRef formatOptions)
{
return CFSTR("CGLayer");
}
static Boolean CGLayerEqual (CFTypeRef cf1, CFTypeRef cf2)
{
return cf1 == cf2;
}
static void CGLayerDealloc(CFTypeRef cf)
{
CGLayerRef ref = CGLayerRef(cf);
CFRelease(ref->context);
delete ref->picture;
}
void CGLayerInitialize()
{
static const CFRuntimeClass CGLayerClass =
{
0,
"CGLayer",
NULL,
NULL,
CGLayerDealloc,
NULL,
CGLayerHash,
CGLayerCopyFormattingDesc,
NULL
};
_kCGLayerTypeID = _CFRuntimeRegisterClass (&CGLayerClass);
}
CFTypeID CGLayerGetTypeID(void)
{
return _kCGLayerTypeID;
}
void CGLayerRelease(CGLayerRef layer)
{
if (layer)
CFRelease(layer);
}
CGLayerRef CGLayerRetain(CGLayerRef layer)
{
if (layer)
CFRetain(layer);
return layer;
}

View File

@ -1,23 +0,0 @@
#ifndef CGLAYER_H_
#define CGLAYER_H_
#include <CoreFoundation/CFDictionary.h>
#include "CGContext.h"
#include "CGGeometry.h"
BEGIN_EXTERN_C
struct __CGLayer;
typedef __CGLayer *CGLayerRef;
void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point, CGLayerRef layer);
void CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer);
CGLayerRef CGLayerCreateWithContext(CGContextRef context, CGSize size, CFDictionaryRef auxiliaryInfo);
CGContextRef CGLayerGetContext(CGLayerRef layer);
CGSize CGLayerGetSize(CGLayerRef layer);
CFTypeID CGLayerGetTypeID(void);
void CGLayerRelease(CGLayerRef layer);
CGLayerRef CGLayerRetain(CGLayerRef layer);
END_EXTERN_C
#endif

View File

@ -1,47 +0,0 @@
project(CoreGraphics)
cmake_minimum_required(VERSION 2.4.0)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(QT_USE_QTDECLARATIVE TRUE)
find_package(Qt4 REQUIRED)
add_definitions(${QT_DEFINITIONS})
include_directories(${QT_INCLUDE_DIR})
include(${QT_USE_FILE})
#if (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
# message(FATAL_ERROR "Clang is the only supported compiler.")
#endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
#configure_file(config.h.in config.h)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks")
add_definitions(-D__STDC_LIMIT_MACROS)
add_definitions(-DDARLING_BUILD)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../util)
set(CoreGraphics_SRCS
CGDirectDisplay.mm
CGGeometry.cpp
CGLayer.cpp
CGContext.cpp
)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/darling")
#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_library(CoreGraphics SHARED ${CoreGraphics_SRCS})
target_link_libraries(CoreGraphics -lopal -lgnustep-corebase -lX11 -lXrandr
-lgnustep-corebase ${QT_LIBRARIES})
install(TARGETS CoreGraphics DESTINATION "${CMAKE_INSTALL_LIBDIR}/darling")

@ -1 +1 @@
Subproject commit cc74282c30112106b85ca36d4c42ba6088785beb
Subproject commit 1d514ec3454cd31c4e5aadb2855cb02ae13ea0f3

1
src/external/IONetworkingFamily vendored Submodule

@ -0,0 +1 @@
Subproject commit d24f751267f8ac86759d16cb95224410cc586d5d

@ -1 +1 @@
Subproject commit e5e3f95c4476317bd957b3500e16475c4cf55433
Subproject commit 5d8d13ea122c1739cf415c941a0da43c806b4d8b

1
src/external/coregraphics vendored Submodule

@ -0,0 +1 @@
Subproject commit 7243e159cbce985107d895a877aefc219ef8fe83

@ -1 +1 @@
Subproject commit 9479987947e4da8ed491aa433b69c8f9dee8986e
Subproject commit 8c7be80b924c0df33e4b7dda6dcae4eca1c831aa

@ -1 +1 @@
Subproject commit 3a6ab78bb16b6fbd79823bc684cc0d588b098af8
Subproject commit 3f7acfe743f55738cf025ed2438a5800895b189e

@ -1 +1 @@
Subproject commit 7dbf79587a5726b42c2902c0b515a005f58b58e1
Subproject commit e7f550d34d2252a6d8bd376b1ac7bc0d0bee2eb7