1a12d83a6d37ea85217af50cdaf07de58819446e
[WebKit-https.git] / Source / WebCore / PAL / pal / spi / cg / CoreGraphicsSPI.h
1 /*
2  * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #pragma once
27
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <CoreGraphics/CoreGraphics.h>
30
31 #if USE(IOSURFACE)
32 #include <pal/spi/cocoa/IOSurfaceSPI.h>
33 #endif
34
35 #if PLATFORM(MAC)
36 #include <ColorSync/ColorSync.h>
37 #endif
38
39 #if USE(APPLE_INTERNAL_SDK)
40
41 #if PLATFORM(MAC)
42 #include <ColorSync/ColorSyncPriv.h>
43 #endif
44 #include <CoreGraphics/CGFontCache.h>
45 #include <CoreGraphics/CoreGraphicsPrivate.h>
46
47 #else
48
49 struct CGFontHMetrics {
50     int ascent;
51     int descent;
52     int lineGap;
53     int maxAdvanceWidth;
54     int minLeftSideBearing;
55     int minRightSideBearing;
56 };
57
58 struct CGFontDescriptor {
59     CGRect bbox;
60     CGFloat ascent;
61     CGFloat descent;
62     CGFloat capHeight;
63     CGFloat italicAngle;
64     CGFloat stemV;
65     CGFloat stemH;
66     CGFloat avgWidth;
67     CGFloat maxWidth;
68     CGFloat missingWidth;
69     CGFloat leading;
70     CGFloat xHeight;
71 };
72
73 typedef const struct CGColorTransform* CGColorTransformRef;
74
75 typedef enum {
76     kCGContextTypeUnknown,
77     kCGContextTypePDF,
78     kCGContextTypePostScript,
79     kCGContextTypeWindow,
80     kCGContextTypeBitmap,
81     kCGContextTypeGL,
82     kCGContextTypeDisplayList,
83     kCGContextTypeKSeparation,
84     kCGContextTypeIOSurface,
85     kCGContextTypeCount
86 } CGContextType;
87
88 typedef enum {
89     kCGCompositeCopy = 1,
90     kCGCompositeSover = 2,
91 } CGCompositeOperation;
92
93 enum {
94     kCGFontRenderingStyleAntialiasing = 1 << 0,
95     kCGFontRenderingStyleSmoothing = 1 << 1,
96     kCGFontRenderingStyleSubpixelPositioning = 1 << 2,
97     kCGFontRenderingStyleSubpixelQuantization = 1 << 3,
98     kCGFontRenderingStylePlatformNative = 1 << 9,
99     kCGFontRenderingStyleMask = 0x20F,
100 };
101 typedef uint32_t CGFontRenderingStyle;
102
103 enum {
104     kCGFontAntialiasingStyleUnfiltered = 0 << 7,
105     kCGFontAntialiasingStyleFilterLight = 1 << 7,
106 #if PLATFORM(MAC)
107     kCGFontAntialiasingStyleUnfilteredCustomDilation = (8 << 7),
108 #endif
109 };
110 typedef uint32_t CGFontAntialiasingStyle;
111
112 enum {
113     kCGImageCachingTransient = 1,
114     kCGImageCachingTemporary = 3,
115 };
116 typedef uint32_t CGImageCachingFlags;
117
118 #if PLATFORM(COCOA)
119 typedef struct CGSRegionEnumeratorObject* CGSRegionEnumeratorObj;
120 typedef struct CGSRegionObject* CGSRegionObj;
121 typedef struct CGSRegionObject* CGRegionRef;
122 #endif
123
124 #ifdef CGFLOAT_IS_DOUBLE
125 #define CGRound(value) round((value))
126 #define CGFloor(value) floor((value))
127 #define CGCeiling(value) ceil((value))
128 #define CGFAbs(value) fabs((value))
129 #else
130 #define CGRound(value) roundf((value))
131 #define CGFloor(value) floorf((value))
132 #define CGCeiling(value) ceilf((value))
133 #define CGFAbs(value) fabsf((value))
134 #endif
135
136 static inline CGFloat CGFloatMin(CGFloat a, CGFloat b) { return isnan(a) ? b : ((isnan(b) || a < b) ? a : b); }
137
138 typedef struct CGFontCache CGFontCache;
139
140 #if PLATFORM(COCOA)
141
142 enum {
143     kCGSWindowCaptureNominalResolution = 0x0200,
144     kCGSCaptureIgnoreGlobalClipShape = 0x0800,
145 };
146 typedef uint32_t CGSWindowCaptureOptions;
147
148 typedef CF_ENUM (int32_t, CGStyleDrawOrdering) {
149     kCGStyleDrawOrderingStyleOnly = 0,
150     kCGStyleDrawOrderingBelow = 1,
151     kCGStyleDrawOrderingAbove = 2,
152 };
153
154 typedef CF_ENUM (int32_t, CGFocusRingOrdering) {
155     kCGFocusRingOrderingNone = kCGStyleDrawOrderingStyleOnly,
156     kCGFocusRingOrderingBelow = kCGStyleDrawOrderingBelow,
157     kCGFocusRingOrderingAbove = kCGStyleDrawOrderingAbove,
158 };
159
160 typedef CF_ENUM (int32_t, CGFocusRingTint) {
161     kCGFocusRingTintBlue = 0,
162     kCGFocusRingTintGraphite = 1,
163 };
164
165 struct CGFocusRingStyle {
166     unsigned int version;
167     CGFocusRingTint tint;
168     CGFocusRingOrdering ordering;
169     CGFloat alpha;
170     CGFloat radius;
171     CGFloat threshold;
172     CGRect bounds;
173     int accumulate;
174 };
175 typedef struct CGFocusRingStyle CGFocusRingStyle;
176
177 #endif // PLATFORM(COCOA)
178
179 #if PLATFORM(MAC)
180
181 typedef CF_ENUM(uint32_t, CGSNotificationType) {
182     kCGSFirstConnectionNotification = 900,
183     kCGSFirstSessionNotification = 1500,
184 };
185
186 static const CGSNotificationType kCGSConnectionWindowModificationsStarted = (CGSNotificationType)(kCGSFirstConnectionNotification + 6);
187 static const CGSNotificationType kCGSConnectionWindowModificationsStopped = (CGSNotificationType)(kCGSFirstConnectionNotification + 7);
188 static const CGSNotificationType kCGSessionConsoleConnect = kCGSFirstSessionNotification;
189 static const CGSNotificationType kCGSessionConsoleDisconnect = (CGSNotificationType)(kCGSessionConsoleConnect + 1);
190
191 #endif // PLATFORM(MAC)
192
193 #endif // USE(APPLE_INTERNAL_SDK)
194
195 #if PLATFORM(COCOA)
196 typedef uint32_t CGSByteCount;
197 typedef uint32_t CGSConnectionID;
198 typedef uint32_t CGSWindowCount;
199 typedef uint32_t CGSWindowID;
200
201 typedef CGSWindowID* CGSWindowIDList;
202 typedef struct CF_BRIDGED_TYPE(id) CGSRegionObject* CGSRegionObj;
203 typedef struct CF_BRIDGED_TYPE(id) CGStyle* CGStyleRef;
204
205 typedef void* CGSNotificationArg;
206 typedef void* CGSNotificationData;
207 #endif
208
209 #if PLATFORM(MAC)
210 typedef void (*CGSNotifyConnectionProcPtr)(CGSNotificationType, void* data, uint32_t data_length, void* arg, CGSConnectionID);
211 typedef void (*CGSNotifyProcPtr)(CGSNotificationType, void* data, uint32_t data_length, void* arg);
212 #endif
213
214 WTF_EXTERN_C_BEGIN
215
216 CGColorRef CGColorTransformConvertColor(CGColorTransformRef, CGColorRef, CGColorRenderingIntent);
217 CGColorTransformRef CGColorTransformCreate(CGColorSpaceRef, CFDictionaryRef attributes);
218
219 CGAffineTransform CGContextGetBaseCTM(CGContextRef);
220 CGCompositeOperation CGContextGetCompositeOperation(CGContextRef);
221 CGColorRef CGContextGetFillColorAsColor(CGContextRef);
222 CGFloat CGContextGetLineWidth(CGContextRef);
223 bool CGContextGetShouldSmoothFonts(CGContextRef);
224 bool CGContextGetShouldAntialias(CGContextRef);
225 void CGContextSetBaseCTM(CGContextRef, CGAffineTransform);
226 void CGContextSetCTM(CGContextRef, CGAffineTransform);
227 void CGContextSetCompositeOperation(CGContextRef, CGCompositeOperation);
228 void CGContextSetShouldAntialiasFonts(CGContextRef, bool shouldAntialiasFonts);
229 void CGContextResetClip(CGContextRef);
230 CGContextType CGContextGetType(CGContextRef);
231
232 CFStringRef CGFontCopyFamilyName(CGFontRef);
233 bool CGFontGetDescriptor(CGFontRef, CGFontDescriptor*);
234 bool CGFontGetGlyphAdvancesForStyle(CGFontRef, const CGAffineTransform* , CGFontRenderingStyle, const CGGlyph[], size_t count, CGSize advances[]);
235 void CGFontGetGlyphsForUnichars(CGFontRef, const UniChar[], CGGlyph[], size_t count);
236 const CGFontHMetrics* CGFontGetHMetrics(CGFontRef);
237 const char* CGFontGetPostScriptName(CGFontRef);
238 bool CGFontIsFixedPitch(CGFontRef);
239 void CGFontSetShouldUseMulticache(bool);
240
241 void CGImageSetCachingFlags(CGImageRef, CGImageCachingFlags);
242 CGImageCachingFlags CGImageGetCachingFlags(CGImageRef);
243
244 CGDataProviderRef CGPDFDocumentGetDataProvider(CGPDFDocumentRef);
245
246 CGFontAntialiasingStyle CGContextGetFontAntialiasingStyle(CGContextRef);
247 void CGContextSetFontAntialiasingStyle(CGContextRef, CGFontAntialiasingStyle);
248 bool CGContextGetAllowsFontSubpixelPositioning(CGContextRef);
249 bool CGContextDrawsWithCorrectShadowOffsets(CGContextRef);
250 CGPatternRef CGPatternCreateWithImage2(CGImageRef, CGAffineTransform, CGPatternTiling);
251
252 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || PLATFORM(IOS)
253 bool CGColorSpaceUsesExtendedRange(CGColorSpaceRef);
254
255 typedef struct CGPDFAnnotation *CGPDFAnnotationRef;
256 typedef bool (^CGPDFAnnotationDrawCallbackType)(CGContextRef context, CGPDFPageRef page, CGPDFAnnotationRef annotation);
257 void CGContextDrawPDFPageWithAnnotations(CGContextRef, CGPDFPageRef, CGPDFAnnotationDrawCallbackType);
258 void CGContextDrawPathDirect(CGContextRef, CGPathDrawingMode, CGPathRef, const CGRect* boundingBox);
259 #endif
260
261 #if USE(IOSURFACE)
262 CGContextRef CGIOSurfaceContextCreate(IOSurfaceRef, size_t, size_t, size_t, size_t, CGColorSpaceRef, CGBitmapInfo);
263 CGImageRef CGIOSurfaceContextCreateImage(CGContextRef);
264 CGImageRef CGIOSurfaceContextCreateImageReference(CGContextRef);
265 CGColorSpaceRef CGIOSurfaceContextGetColorSpace(CGContextRef);
266 #endif
267
268 #if PLATFORM(COCOA)
269 CGColorSpaceRef CGContextCopyDeviceColorSpace(CGContextRef);
270 CGError CGSNewRegionWithRect(const CGRect*, CGRegionRef*);
271 CGError CGSPackagesEnableConnectionOcclusionNotifications(CGSConnectionID, bool flag, bool* outCurrentVisibilityState);
272 CGError CGSPackagesEnableConnectionWindowModificationNotifications(CGSConnectionID, bool flag, bool* outConnectionIsCurrentlyIdle);
273 CGError CGSReleaseRegion(const CGRegionRef CF_RELEASES_ARGUMENT);
274 CGError CGSReleaseRegionEnumerator(const CGSRegionEnumeratorObj);
275 CGError CGSSetWindowAlpha(CGSConnectionID, CGSWindowID, float alpha);
276 CGError CGSSetWindowClipShape(CGSConnectionID, CGSWindowID, CGRegionRef shape);
277 CGError CGSSetWindowWarp(CGSConnectionID, CGSWindowID, int w, int h, const float* mesh);
278 CGRect* CGSNextRect(const CGSRegionEnumeratorObj);
279 CGSRegionEnumeratorObj CGSRegionEnumerator(CGRegionRef);
280 CGStyleRef CGStyleCreateFocusRingWithColor(const CGFocusRingStyle*, CGColorRef);
281 void CGContextSetStyle(CGContextRef, CGStyleRef);
282 #endif
283
284 #if PLATFORM(WIN)
285 CGFontCache* CGFontCacheGetLocalCache();
286 void CGFontCacheSetShouldAutoExpire(CGFontCache*, bool);
287 void CGFontCacheSetMaxSize(CGFontCache*, size_t);
288 #endif
289
290 #if PLATFORM(MAC)
291 CGSConnectionID CGSMainConnectionID(void);
292 CFArrayRef CGSHWCaptureWindowList(CGSConnectionID, CGSWindowIDList windowList, CGSWindowCount, CGSWindowCaptureOptions);
293 CGError CGSSetConnectionProperty(CGSConnectionID, CGSConnectionID ownerCid, CFStringRef key, CFTypeRef value);
294 CGError CGSCopyConnectionProperty(CGSConnectionID, CGSConnectionID ownerCid, CFStringRef key, CFTypeRef *value);
295 CGError CGSGetScreenRectForWindow(CGSConnectionID, CGSWindowID, CGRect *);
296 CGError CGSRegisterConnectionNotifyProc(CGSConnectionID, CGSNotifyConnectionProcPtr, CGSNotificationType, void* arg);
297 CGError CGSRegisterNotifyProc(CGSNotifyProcPtr, CGSNotificationType, void* arg);
298 bool ColorSyncProfileIsWideGamut(ColorSyncProfileRef);
299 #endif
300
301 WTF_EXTERN_C_END