···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2020 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#ifndef IOSURFACE_PRIV_H
2121+#define IOSURFACE_PRIV_H
2222+#include <IOSurface/IOSurfaceTypes.h>
2323+#include <stdint.h>
2424+2525+// Private API definition between IOSurface.framework and iokitd
2626+2727+// IOSurfaceID is passed in as "input" if it's the only argument
2828+// struct contents as passed in "inputStruct".
2929+// See IOConnectCallMethod().
3030+3131+enum
3232+{
3333+ // in: dictionary
3434+ // out: _IOSurfaceObjectRetval
3535+ kIOSurfaceMethodCreate = 0,
3636+ // in: IOSurfaceID
3737+ kIOSurfaceMethodRelease = 1,
3838+ // in: struct _IOSurfaceLockUnlock
3939+ kIOSurfaceMethodLock = 2,
4040+ // in: struct _IOSurfaceLockUnlock
4141+ kIOSurfaceMethodUnlock = 3,
4242+ // in: IOSurfaceID
4343+ kIOSurfaceMethodLookupByID = 4,
4444+ kIOSurfaceMethodSetValue = 9,
4545+ // out: data for IOCFUnserializeWithSize()
4646+ kIOSurfaceMethodGetValues = 10,
4747+ kIOSurfaceMethodRemoveValue = 11,
4848+ // in: IOSurfaceID
4949+ kIOSurfaceMethodIncrementUseCount = 14,
5050+ // in: IOSurfaceID
5151+ kIOSurfaceMethodDecrementUseCount = 15,
5252+ // in: mach_port_t as a plain value
5353+ // out: _IOSurfaceObjectRetval
5454+ kIOSurfaceMethodCreateByMachPort = 34,
5555+ // in: IOSurfaceID
5656+ // out: mach_port_t as a plain value
5757+ kIOSurfaceMethodCreateMachPort = 35,
5858+};
5959+6060+struct _IOSurfacePlane
6161+{
6262+ uint64_t memoryOffset;
6363+6464+ uint32_t bytesPerElement;
6565+ uint32_t width;
6666+ uint32_t height;
6767+ uint32_t bytesPerRow;
6868+};
6969+7070+struct _IOSurfaceObjectRetval
7171+{
7272+ IOSurfaceID surfaceID;
7373+ uint32_t pixelFormat;
7474+7575+ // Where mapped into memory
7676+ uint64_t address;
7777+7878+ uint32_t planeCount;
7979+ struct _IOSurfacePlane planes[1];
8080+};
8181+8282+struct _IOSurfaceLockUnlock
8383+{
8484+ IOSurfaceID surfaceID;
8585+ uint32_t options;
8686+};
8787+8888+#endif
···11-/*
22- This file is part of Darling.
33-44- Copyright (C) 2017 Lubos Dolezel
55-66- Darling is free software: you can redistribute it and/or modify
77- it under the terms of the GNU General Public License as published by
88- the Free Software Foundation, either version 3 of the License, or
99- (at your option) any later version.
1010-1111- Darling is distributed in the hope that it will be useful,
1212- but WITHOUT ANY WARRANTY; without even the implied warranty of
1313- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414- GNU General Public License for more details.
1515-1616- You should have received a copy of the GNU General Public License
1717- along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818-*/
1919-2020-#include <stdlib.h>
2121-#include <stdio.h>
2222-#import <IOSurface/IOSurface.h>
2323-2424-#include <CoreFoundation/CoreFoundation.h>
2525-2626-const CFStringRef kIOSurfaceBytesPerElement = CFSTR("kIOSurfaceBytesPerElement");
2727-const CFStringRef kIOSurfaceHeight = CFSTR("kIOSurfaceHeight");
2828-const CFStringRef kIOSurfaceIsGlobal = CFSTR("kIOSurfaceIsGlobal");
2929-const CFStringRef kIOSurfacePixelFormat = CFSTR("kIOSurfacePixelFormat");
3030-const CFStringRef kIOSurfaceWidth = CFSTR("kIOSurfaceWidth");
3131-3232-static int verbose = 0;
3333-3434-__attribute__((constructor))
3535-static void initme(void) {
3636- verbose = getenv("STUB_VERBOSE") != NULL;
3737-}
3838-3939-@implementation IOSurface
4040-4141-- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
4242- return [NSMethodSignature signatureWithObjCTypes: "v@:"];
4343-}
4444-4545-- (void)forwardInvocation:(NSInvocation *)anInvocation {
4646- NSLog(@"Stub called: %@ in %@", NSStringFromSelector([anInvocation selector]), [self class]);
4747-}
4848-4949-@end
5050-5151-void* IOSurfaceAllowsPixelSizeCasting(void) {
5252- if (verbose) puts("STUB: IOSurfaceAllowsPixelSizeCasting called");
5353- return NULL;
5454-}
5555-5656-void* IOSurfaceBindAccel(void) {
5757- if (verbose) puts("STUB: IOSurfaceBindAccel called");
5858- return NULL;
5959-}
6060-6161-void* IOSurfaceBindAccelOnPlane(void) {
6262- if (verbose) puts("STUB: IOSurfaceBindAccelOnPlane called");
6363- return NULL;
6464-}
6565-6666-void* IOSurfaceClientAlignProperty(void) {
6767- if (verbose) puts("STUB: IOSurfaceClientAlignProperty called");
6868- return NULL;
6969-}
7070-7171-void* IOSurfaceClientAllowsPixelSizeCasting(void) {
7272- if (verbose) puts("STUB: IOSurfaceClientAllowsPixelSizeCasting called");
7373- return NULL;
7474-}
7575-7676-void* IOSurfaceClientBindAccel(void) {
7777- if (verbose) puts("STUB: IOSurfaceClientBindAccel called");
7878- return NULL;
7979-}
8080-8181-void* IOSurfaceClientCopyAllValues(void) {
8282- if (verbose) puts("STUB: IOSurfaceClientCopyAllValues called");
8383- return NULL;
8484-}
8585-8686-void* IOSurfaceClientCopyDataValueBytes(void) {
8787- if (verbose) puts("STUB: IOSurfaceClientCopyDataValueBytes called");
8888- return NULL;
8989-}
9090-9191-void* IOSurfaceClientCopyValue(void) {
9292- if (verbose) puts("STUB: IOSurfaceClientCopyValue called");
9393- return NULL;
9494-}
9595-9696-void* IOSurfaceClientCreate(void) {
9797- if (verbose) puts("STUB: IOSurfaceClientCreate called");
9898- return NULL;
9999-}
100100-101101-void* IOSurfaceClientCreateMachPort(void) {
102102- if (verbose) puts("STUB: IOSurfaceClientCreateMachPort called");
103103- return NULL;
104104-}
105105-106106-void* IOSurfaceClientDecrementUseCount(void) {
107107- if (verbose) puts("STUB: IOSurfaceClientDecrementUseCount called");
108108- return NULL;
109109-}
110110-111111-void* IOSurfaceClientFlushProcessorCaches(void) {
112112- if (verbose) puts("STUB: IOSurfaceClientFlushProcessorCaches called");
113113- return NULL;
114114-}
115115-116116-void* IOSurfaceClientGetAllocSize(void) {
117117- if (verbose) puts("STUB: IOSurfaceClientGetAllocSize called");
118118- return NULL;
119119-}
120120-121121-void* IOSurfaceClientGetBaseAddress(void) {
122122- if (verbose) puts("STUB: IOSurfaceClientGetBaseAddress called");
123123- return NULL;
124124-}
125125-126126-void* IOSurfaceClientGetBaseAddressOfPlane(void) {
127127- if (verbose) puts("STUB: IOSurfaceClientGetBaseAddressOfPlane called");
128128- return NULL;
129129-}
130130-131131-void* IOSurfaceClientGetBitDepthOfComponentOfPlane(void) {
132132- if (verbose) puts("STUB: IOSurfaceClientGetBitDepthOfComponentOfPlane called");
133133- return NULL;
134134-}
135135-136136-void* IOSurfaceClientGetBitOffsetOfComponentOfPlane(void) {
137137- if (verbose) puts("STUB: IOSurfaceClientGetBitOffsetOfComponentOfPlane called");
138138- return NULL;
139139-}
140140-141141-void* IOSurfaceClientGetBulkAttachments(void) {
142142- if (verbose) puts("STUB: IOSurfaceClientGetBulkAttachments called");
143143- return NULL;
144144-}
145145-146146-void* IOSurfaceClientGetBytesPerElement(void) {
147147- if (verbose) puts("STUB: IOSurfaceClientGetBytesPerElement called");
148148- return NULL;
149149-}
150150-151151-void* IOSurfaceClientGetBytesPerElementOfPlane(void) {
152152- if (verbose) puts("STUB: IOSurfaceClientGetBytesPerElementOfPlane called");
153153- return NULL;
154154-}
155155-156156-void* IOSurfaceClientGetBytesPerRow(void) {
157157- if (verbose) puts("STUB: IOSurfaceClientGetBytesPerRow called");
158158- return NULL;
159159-}
160160-161161-void* IOSurfaceClientGetBytesPerRowOfPlane(void) {
162162- if (verbose) puts("STUB: IOSurfaceClientGetBytesPerRowOfPlane called");
163163- return NULL;
164164-}
165165-166166-void* IOSurfaceClientGetCacheMode(void) {
167167- if (verbose) puts("STUB: IOSurfaceClientGetCacheMode called");
168168- return NULL;
169169-}
170170-171171-void* IOSurfaceClientGetElementHeight(void) {
172172- if (verbose) puts("STUB: IOSurfaceClientGetElementHeight called");
173173- return NULL;
174174-}
175175-176176-void* IOSurfaceClientGetElementHeightOfPlane(void) {
177177- if (verbose) puts("STUB: IOSurfaceClientGetElementHeightOfPlane called");
178178- return NULL;
179179-}
180180-181181-void* IOSurfaceClientGetElementWidth(void) {
182182- if (verbose) puts("STUB: IOSurfaceClientGetElementWidth called");
183183- return NULL;
184184-}
185185-186186-void* IOSurfaceClientGetElementWidthOfPlane(void) {
187187- if (verbose) puts("STUB: IOSurfaceClientGetElementWidthOfPlane called");
188188- return NULL;
189189-}
190190-191191-void* IOSurfaceClientGetHeight(void) {
192192- if (verbose) puts("STUB: IOSurfaceClientGetHeight called");
193193- return NULL;
194194-}
195195-196196-void* IOSurfaceClientGetHeightOfPlane(void) {
197197- if (verbose) puts("STUB: IOSurfaceClientGetHeightOfPlane called");
198198- return NULL;
199199-}
200200-201201-void* IOSurfaceClientGetID(void) {
202202- if (verbose) puts("STUB: IOSurfaceClientGetID called");
203203- return NULL;
204204-}
205205-206206-void* IOSurfaceClientGetNameOfComponentOfPlane(void) {
207207- if (verbose) puts("STUB: IOSurfaceClientGetNameOfComponentOfPlane called");
208208- return NULL;
209209-}
210210-211211-void* IOSurfaceClientGetNumberOfComponentsOfPlane(void) {
212212- if (verbose) puts("STUB: IOSurfaceClientGetNumberOfComponentsOfPlane called");
213213- return NULL;
214214-}
215215-216216-void* IOSurfaceClientGetPixelFormat(void) {
217217- if (verbose) puts("STUB: IOSurfaceClientGetPixelFormat called");
218218- return NULL;
219219-}
220220-221221-void* IOSurfaceClientGetPlaneCount(void) {
222222- if (verbose) puts("STUB: IOSurfaceClientGetPlaneCount called");
223223- return NULL;
224224-}
225225-226226-void* IOSurfaceClientGetPropertyAlignment(void) {
227227- if (verbose) puts("STUB: IOSurfaceClientGetPropertyAlignment called");
228228- return NULL;
229229-}
230230-231231-void* IOSurfaceClientGetPropertyMaximum(void) {
232232- if (verbose) puts("STUB: IOSurfaceClientGetPropertyMaximum called");
233233- return NULL;
234234-}
235235-236236-void* IOSurfaceClientGetProtectionOptions(void) {
237237- if (verbose) puts("STUB: IOSurfaceClientGetProtectionOptions called");
238238- return NULL;
239239-}
240240-241241-void* IOSurfaceClientGetRangeOfComponentOfPlane(void) {
242242- if (verbose) puts("STUB: IOSurfaceClientGetRangeOfComponentOfPlane called");
243243- return NULL;
244244-}
245245-246246-void* IOSurfaceClientGetSeed(void) {
247247- if (verbose) puts("STUB: IOSurfaceClientGetSeed called");
248248- return NULL;
249249-}
250250-251251-void* IOSurfaceClientGetSubsampling(void) {
252252- if (verbose) puts("STUB: IOSurfaceClientGetSubsampling called");
253253- return NULL;
254254-}
255255-256256-void* IOSurfaceClientGetTypeOfComponentOfPlane(void) {
257257- if (verbose) puts("STUB: IOSurfaceClientGetTypeOfComponentOfPlane called");
258258- return NULL;
259259-}
260260-261261-void* IOSurfaceClientGetUseCount(void) {
262262- if (verbose) puts("STUB: IOSurfaceClientGetUseCount called");
263263- return NULL;
264264-}
265265-266266-void* IOSurfaceClientGetWidth(void) {
267267- if (verbose) puts("STUB: IOSurfaceClientGetWidth called");
268268- return NULL;
269269-}
270270-271271-void* IOSurfaceClientGetWidthOfPlane(void) {
272272- if (verbose) puts("STUB: IOSurfaceClientGetWidthOfPlane called");
273273- return NULL;
274274-}
275275-276276-void* IOSurfaceClientGetYCbCrMatrix(void) {
277277- if (verbose) puts("STUB: IOSurfaceClientGetYCbCrMatrix called");
278278- return NULL;
279279-}
280280-281281-void* IOSurfaceClientIncrementUseCount(void) {
282282- if (verbose) puts("STUB: IOSurfaceClientIncrementUseCount called");
283283- return NULL;
284284-}
285285-286286-void* IOSurfaceClientIsDisplayable(void) {
287287- if (verbose) puts("STUB: IOSurfaceClientIsDisplayable called");
288288- return NULL;
289289-}
290290-291291-void* IOSurfaceClientIsInUse(void) {
292292- if (verbose) puts("STUB: IOSurfaceClientIsInUse called");
293293- return NULL;
294294-}
295295-296296-void* IOSurfaceClientLock(void) {
297297- if (verbose) puts("STUB: IOSurfaceClientLock called");
298298- return NULL;
299299-}
300300-301301-void* IOSurfaceClientLookup(void) {
302302- if (verbose) puts("STUB: IOSurfaceClientLookup called");
303303- return NULL;
304304-}
305305-306306-void* IOSurfaceClientLookupFromMachPort(void) {
307307- if (verbose) puts("STUB: IOSurfaceClientLookupFromMachPort called");
308308- return NULL;
309309-}
310310-311311-void* IOSurfaceClientNeedsBindAccel(void) {
312312- if (verbose) puts("STUB: IOSurfaceClientNeedsBindAccel called");
313313- return NULL;
314314-}
315315-316316-void* IOSurfaceClientRelease(void) {
317317- if (verbose) puts("STUB: IOSurfaceClientRelease called");
318318- return NULL;
319319-}
320320-321321-void* IOSurfaceClientRemoveSurfaceNotify(void) {
322322- if (verbose) puts("STUB: IOSurfaceClientRemoveSurfaceNotify called");
323323- return NULL;
324324-}
325325-326326-void* IOSurfaceClientRemoveValue(void) {
327327- if (verbose) puts("STUB: IOSurfaceClientRemoveValue called");
328328- return NULL;
329329-}
330330-331331-void* IOSurfaceClientRetain(void) {
332332- if (verbose) puts("STUB: IOSurfaceClientRetain called");
333333- return NULL;
334334-}
335335-336336-void* IOSurfaceClientSetBulkAttachments(void) {
337337- if (verbose) puts("STUB: IOSurfaceClientSetBulkAttachments called");
338338- return NULL;
339339-}
340340-341341-void* IOSurfaceClientSetPurgeable(void) {
342342- if (verbose) puts("STUB: IOSurfaceClientSetPurgeable called");
343343- return NULL;
344344-}
345345-346346-void* IOSurfaceClientSetSurfaceNotify(void) {
347347- if (verbose) puts("STUB: IOSurfaceClientSetSurfaceNotify called");
348348- return NULL;
349349-}
350350-351351-void* IOSurfaceClientSetValue(void) {
352352- if (verbose) puts("STUB: IOSurfaceClientSetValue called");
353353- return NULL;
354354-}
355355-356356-void* IOSurfaceClientSetYCbCrMatrix(void) {
357357- if (verbose) puts("STUB: IOSurfaceClientSetYCbCrMatrix called");
358358- return NULL;
359359-}
360360-361361-void* IOSurfaceClientSupportsProtectionOptions(void) {
362362- if (verbose) puts("STUB: IOSurfaceClientSupportsProtectionOptions called");
363363- return NULL;
364364-}
365365-366366-void* IOSurfaceClientUnlock(void) {
367367- if (verbose) puts("STUB: IOSurfaceClientUnlock called");
368368- return NULL;
369369-}
370370-371371-void* IOSurfaceCopyAllValues(void) {
372372- if (verbose) puts("STUB: IOSurfaceCopyAllValues called");
373373- return NULL;
374374-}
375375-376376-void* IOSurfaceCopyDataValueBytes(void) {
377377- if (verbose) puts("STUB: IOSurfaceCopyDataValueBytes called");
378378- return NULL;
379379-}
380380-381381-void* IOSurfaceCopyValue(void) {
382382- if (verbose) puts("STUB: IOSurfaceCopyValue called");
383383- return NULL;
384384-}
385385-386386-void* IOSurfaceCreate(void) {
387387- if (verbose) puts("STUB: IOSurfaceCreate called");
388388- return NULL;
389389-}
390390-391391-void* IOSurfaceCreateMachPort(void) {
392392- if (verbose) puts("STUB: IOSurfaceCreateMachPort called");
393393- return NULL;
394394-}
395395-396396-void* IOSurfaceCreateXPCObject(void) {
397397- if (verbose) puts("STUB: IOSurfaceCreateXPCObject called");
398398- return NULL;
399399-}
400400-401401-void* IOSurfaceDecrementUseCount(void) {
402402- if (verbose) puts("STUB: IOSurfaceDecrementUseCount called");
403403- return NULL;
404404-}
405405-406406-void* IOSurfaceFlushProcessorCaches(void) {
407407- if (verbose) puts("STUB: IOSurfaceFlushProcessorCaches called");
408408- return NULL;
409409-}
410410-411411-void* IOSurfaceGetAllocSize(void) {
412412- if (verbose) puts("STUB: IOSurfaceGetAllocSize called");
413413- return NULL;
414414-}
415415-416416-void* IOSurfaceGetBaseAddress(void) {
417417- if (verbose) puts("STUB: IOSurfaceGetBaseAddress called");
418418- return NULL;
419419-}
420420-421421-void* IOSurfaceGetBaseAddressOfPlane(void) {
422422- if (verbose) puts("STUB: IOSurfaceGetBaseAddressOfPlane called");
423423- return NULL;
424424-}
425425-426426-void* IOSurfaceGetBitDepthOfComponentOfPlane(void) {
427427- if (verbose) puts("STUB: IOSurfaceGetBitDepthOfComponentOfPlane called");
428428- return NULL;
429429-}
430430-431431-void* IOSurfaceGetBitOffsetOfComponentOfPlane(void) {
432432- if (verbose) puts("STUB: IOSurfaceGetBitOffsetOfComponentOfPlane called");
433433- return NULL;
434434-}
435435-436436-void* IOSurfaceGetBitsPerBlock(void) {
437437- if (verbose) puts("STUB: IOSurfaceGetBitsPerBlock called");
438438- return NULL;
439439-}
440440-441441-void* IOSurfaceGetBitsPerBlockOfPlane(void) {
442442- if (verbose) puts("STUB: IOSurfaceGetBitsPerBlockOfPlane called");
443443- return NULL;
444444-}
445445-446446-void* IOSurfaceGetBlockHeightOfPlane(void) {
447447- if (verbose) puts("STUB: IOSurfaceGetBlockHeightOfPlane called");
448448- return NULL;
449449-}
450450-451451-void* IOSurfaceGetBlockWidthOfPlane(void) {
452452- if (verbose) puts("STUB: IOSurfaceGetBlockWidthOfPlane called");
453453- return NULL;
454454-}
455455-456456-void* IOSurfaceGetBulkAttachments(void) {
457457- if (verbose) puts("STUB: IOSurfaceGetBulkAttachments called");
458458- return NULL;
459459-}
460460-461461-void* IOSurfaceGetBytesPerElement(void) {
462462- if (verbose) puts("STUB: IOSurfaceGetBytesPerElement called");
463463- return NULL;
464464-}
465465-466466-void* IOSurfaceGetBytesPerElementOfPlane(void) {
467467- if (verbose) puts("STUB: IOSurfaceGetBytesPerElementOfPlane called");
468468- return NULL;
469469-}
470470-471471-void* IOSurfaceGetBytesPerRow(void) {
472472- if (verbose) puts("STUB: IOSurfaceGetBytesPerRow called");
473473- return NULL;
474474-}
475475-476476-void* IOSurfaceGetBytesPerRowOfPlane(void) {
477477- if (verbose) puts("STUB: IOSurfaceGetBytesPerRowOfPlane called");
478478- return NULL;
479479-}
480480-481481-void* IOSurfaceGetCacheMode(void) {
482482- if (verbose) puts("STUB: IOSurfaceGetCacheMode called");
483483- return NULL;
484484-}
485485-486486-void* IOSurfaceGetElementHeight(void) {
487487- if (verbose) puts("STUB: IOSurfaceGetElementHeight called");
488488- return NULL;
489489-}
490490-491491-void* IOSurfaceGetElementHeightOfPlane(void) {
492492- if (verbose) puts("STUB: IOSurfaceGetElementHeightOfPlane called");
493493- return NULL;
494494-}
495495-496496-void* IOSurfaceGetElementWidth(void) {
497497- if (verbose) puts("STUB: IOSurfaceGetElementWidth called");
498498- return NULL;
499499-}
500500-501501-void* IOSurfaceGetElementWidthOfPlane(void) {
502502- if (verbose) puts("STUB: IOSurfaceGetElementWidthOfPlane called");
503503- return NULL;
504504-}
505505-506506-void* IOSurfaceGetGraphicsCommPageAddress(void) {
507507- if (verbose) puts("STUB: IOSurfaceGetGraphicsCommPageAddress called");
508508- return NULL;
509509-}
510510-511511-void* IOSurfaceGetHeight(void) {
512512- if (verbose) puts("STUB: IOSurfaceGetHeight called");
513513- return NULL;
514514-}
515515-516516-void* IOSurfaceGetHeightOfPlane(void) {
517517- if (verbose) puts("STUB: IOSurfaceGetHeightOfPlane called");
518518- return NULL;
519519-}
520520-521521-void* IOSurfaceGetID(void) {
522522- if (verbose) puts("STUB: IOSurfaceGetID called");
523523- return NULL;
524524-}
525525-526526-void* IOSurfaceGetNameOfComponentOfPlane(void) {
527527- if (verbose) puts("STUB: IOSurfaceGetNameOfComponentOfPlane called");
528528- return NULL;
529529-}
530530-531531-void* IOSurfaceGetNumberOfComponentsOfPlane(void) {
532532- if (verbose) puts("STUB: IOSurfaceGetNumberOfComponentsOfPlane called");
533533- return NULL;
534534-}
535535-536536-void* IOSurfaceGetPixelFormat(void) {
537537- if (verbose) puts("STUB: IOSurfaceGetPixelFormat called");
538538- return NULL;
539539-}
540540-541541-void* IOSurfaceGetPlaneCount(void) {
542542- if (verbose) puts("STUB: IOSurfaceGetPlaneCount called");
543543- return NULL;
544544-}
545545-546546-void* IOSurfaceGetPropertyAlignment(void) {
547547- if (verbose) puts("STUB: IOSurfaceGetPropertyAlignment called");
548548- return NULL;
549549-}
550550-551551-void* IOSurfaceGetPropertyMaximum(void) {
552552- if (verbose) puts("STUB: IOSurfaceGetPropertyMaximum called");
553553- return NULL;
554554-}
555555-556556-void* IOSurfaceGetProtectionOptions(void) {
557557- if (verbose) puts("STUB: IOSurfaceGetProtectionOptions called");
558558- return NULL;
559559-}
560560-561561-void* IOSurfaceGetRangeOfComponentOfPlane(void) {
562562- if (verbose) puts("STUB: IOSurfaceGetRangeOfComponentOfPlane called");
563563- return NULL;
564564-}
565565-566566-void* IOSurfaceGetSeed(void) {
567567- if (verbose) puts("STUB: IOSurfaceGetSeed called");
568568- return NULL;
569569-}
570570-571571-void* IOSurfaceGetSeedOfPlane(void) {
572572- if (verbose) puts("STUB: IOSurfaceGetSeedOfPlane called");
573573- return NULL;
574574-}
575575-576576-void* IOSurfaceGetSubsampling(void) {
577577- if (verbose) puts("STUB: IOSurfaceGetSubsampling called");
578578- return NULL;
579579-}
580580-581581-void* IOSurfaceGetTypeID(void) {
582582- if (verbose) puts("STUB: IOSurfaceGetTypeID called");
583583- return NULL;
584584-}
585585-586586-void* IOSurfaceGetTypeOfComponentOfPlane(void) {
587587- if (verbose) puts("STUB: IOSurfaceGetTypeOfComponentOfPlane called");
588588- return NULL;
589589-}
590590-591591-void* IOSurfaceGetUseCount(void) {
592592- if (verbose) puts("STUB: IOSurfaceGetUseCount called");
593593- return NULL;
594594-}
595595-596596-void* IOSurfaceGetWidth(void) {
597597- if (verbose) puts("STUB: IOSurfaceGetWidth called");
598598- return NULL;
599599-}
600600-601601-void* IOSurfaceGetWidthOfPlane(void) {
602602- if (verbose) puts("STUB: IOSurfaceGetWidthOfPlane called");
603603- return NULL;
604604-}
605605-606606-void* IOSurfaceGetYCbCrMatrix(void) {
607607- if (verbose) puts("STUB: IOSurfaceGetYCbCrMatrix called");
608608- return NULL;
609609-}
610610-611611-void* IOSurfaceIncrementUseCount(void) {
612612- if (verbose) puts("STUB: IOSurfaceIncrementUseCount called");
613613- return NULL;
614614-}
615615-616616-void* IOSurfaceIsDisplayable(void) {
617617- if (verbose) puts("STUB: IOSurfaceIsDisplayable called");
618618- return NULL;
619619-}
620620-621621-void* IOSurfaceIsInUse(void) {
622622- if (verbose) puts("STUB: IOSurfaceIsInUse called");
623623- return NULL;
624624-}
625625-626626-void* IOSurfaceLock(void) {
627627- if (verbose) puts("STUB: IOSurfaceLock called");
628628- return NULL;
629629-}
630630-631631-void* IOSurfaceLockPlane(void) {
632632- if (verbose) puts("STUB: IOSurfaceLockPlane called");
633633- return NULL;
634634-}
635635-636636-void* IOSurfaceLog(void) {
637637- if (verbose) puts("STUB: IOSurfaceLog called");
638638- return NULL;
639639-}
640640-641641-void* IOSurfaceLookup(void) {
642642- if (verbose) puts("STUB: IOSurfaceLookup called");
643643- return NULL;
644644-}
645645-646646-void* IOSurfaceLookupFromMachPort(void) {
647647- if (verbose) puts("STUB: IOSurfaceLookupFromMachPort called");
648648- return NULL;
649649-}
650650-651651-void* IOSurfaceLookupFromXPCObject(void) {
652652- if (verbose) puts("STUB: IOSurfaceLookupFromXPCObject called");
653653- return NULL;
654654-}
655655-656656-void* IOSurfaceNeedsBindAccel(void) {
657657- if (verbose) puts("STUB: IOSurfaceNeedsBindAccel called");
658658- return NULL;
659659-}
660660-661661-void* IOSurfaceNeedsBindAccelOnPlane(void) {
662662- if (verbose) puts("STUB: IOSurfaceNeedsBindAccelOnPlane called");
663663- return NULL;
664664-}
665665-666666-void* IOSurfaceNotifierCreate(void) {
667667- if (verbose) puts("STUB: IOSurfaceNotifierCreate called");
668668- return NULL;
669669-}
670670-671671-void* IOSurfaceNotifierGetMachPort(void) {
672672- if (verbose) puts("STUB: IOSurfaceNotifierGetMachPort called");
673673- return NULL;
674674-}
675675-676676-void* IOSurfaceNotifierGetRunLoopSource(void) {
677677- if (verbose) puts("STUB: IOSurfaceNotifierGetRunLoopSource called");
678678- return NULL;
679679-}
680680-681681-void* IOSurfaceNotifierGetTypeID(void) {
682682- if (verbose) puts("STUB: IOSurfaceNotifierGetTypeID called");
683683- return NULL;
684684-}
685685-686686-void* IOSurfaceNotifierSetDispatchQueue(void) {
687687- if (verbose) puts("STUB: IOSurfaceNotifierSetDispatchQueue called");
688688- return NULL;
689689-}
690690-691691-void* IOSurfaceRemoveAllValues(void) {
692692- if (verbose) puts("STUB: IOSurfaceRemoveAllValues called");
693693- return NULL;
694694-}
695695-696696-void* IOSurfaceRemoveValue(void) {
697697- if (verbose) puts("STUB: IOSurfaceRemoveValue called");
698698- return NULL;
699699-}
700700-701701-void* IOSurfaceSetBulkAttachments(void) {
702702- if (verbose) puts("STUB: IOSurfaceSetBulkAttachments called");
703703- return NULL;
704704-}
705705-706706-void* IOSurfaceSetBulkAttachments2(void) {
707707- if (verbose) puts("STUB: IOSurfaceSetBulkAttachments2 called");
708708- return NULL;
709709-}
710710-711711-void* IOSurfaceSetPurgeable(void) {
712712- if (verbose) puts("STUB: IOSurfaceSetPurgeable called");
713713- return NULL;
714714-}
715715-716716-void* IOSurfaceSetValue(void) {
717717- if (verbose) puts("STUB: IOSurfaceSetValue called");
718718- return NULL;
719719-}
720720-721721-void* IOSurfaceSetValues(void) {
722722- if (verbose) puts("STUB: IOSurfaceSetValues called");
723723- return NULL;
724724-}
725725-726726-void* IOSurfaceSetYCbCrMatrix(void) {
727727- if (verbose) puts("STUB: IOSurfaceSetYCbCrMatrix called");
728728- return NULL;
729729-}
730730-731731-void* IOSurfaceSupportsProtectionOptions(void) {
732732- if (verbose) puts("STUB: IOSurfaceSupportsProtectionOptions called");
733733- return NULL;
734734-}
735735-736736-void* IOSurfaceUnlock(void) {
737737- if (verbose) puts("STUB: IOSurfaceUnlock called");
738738- return NULL;
739739-}
740740-741741-void* IOSurfaceUnlockPlane(void) {
742742- if (verbose) puts("STUB: IOSurfaceUnlockPlane called");
743743- return NULL;
744744-}
745745-746746-void* _ioSurfaceAddClientRef(void) {
747747- if (verbose) puts("STUB: _ioSurfaceAddClientRef called");
748748- return NULL;
749749-}
+293
src/frameworks/IOSurface/src/IOSurfaceObjC.m
···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2020 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#import <IOSurface/IOSurface.h>
2121+#import <IOSurface/IOSurfaceObjC.h>
2222+#import <IOSurface/IOSurfacePriv.h>
2323+#import <Foundation/Foundation.h>
2424+#import <IOKit/IOCFSerialize.h>
2525+#include <stdatomic.h>
2626+2727+static io_service_t g_surfaceService;
2828+2929+typedef struct
3030+{
3131+ struct _IOSurfaceObjectRetval* surface;
3232+ _Atomic int32_t localUseCount;
3333+} ImplData;
3434+3535+@implementation IOSurface
3636+3737++ (void)initialize
3838+{
3939+ if (self == [IOSurface self])
4040+ {
4141+ CFMutableDictionaryRef matching = IOServiceNameMatching("IOSurfaceRoot");
4242+4343+ g_surfaceService = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
4444+4545+ CFRelease(matching);
4646+4747+ if (!g_surfaceService)
4848+ NSLog(@"Cannot obtain IOSurfaceRoot!\n");
4949+ }
5050+}
5151+5252+- (nullable instancetype)initWithResponse:(const void*)bytes length:(size_t)length
5353+{
5454+ ImplData* idata = (ImplData*) malloc(sizeof(ImplData));
5555+ idata->surface = malloc(length);
5656+ memcpy(idata->surface, bytes, length);
5757+5858+ idata->localUseCount = 0;
5959+ self->_impl = idata;
6060+6161+ return self;
6262+}
6363+6464+- (nullable instancetype)initWithProperties:(NSDictionary <IOSurfacePropertyKey, id> *)properties
6565+{
6666+ CFDataRef data = IOCFSerialize((CFTypeRef) properties, kIOCFSerializeToBinary);
6767+ uint8_t responseBuffer[3500];
6868+6969+ const void* bytes = CFDataGetBytePtr(data);
7070+ size_t length = CFDataGetLength(data);
7171+ size_t responseLength = sizeof(responseBuffer);
7272+7373+ kern_return_t ret = IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodCreate, NULL, 0, bytes, length, NULL, 0, responseBuffer, &responseLength);
7474+ CFRelease(data);
7575+7676+ if (ret != kIOSurfaceSuccess)
7777+ {
7878+ [self release];
7979+ return nil;
8080+ }
8181+8282+ return [self initWithResponse: responseBuffer length: responseLength];
8383+}
8484+8585+- (nullable instancetype)initWithSurfaceID:(IOSurfaceID)surfaceID
8686+{
8787+ uint8_t responseBuffer[3500];
8888+ size_t responseLength = sizeof(responseBuffer);
8989+9090+ uint64_t scalar = surfaceID;
9191+ kern_return_t ret = IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodLookupByID, &scalar, 1, NULL, 0, NULL, 0, responseBuffer, &responseLength);
9292+9393+ if (ret != kIOSurfaceSuccess)
9494+ {
9595+ [self release];
9696+ return nil;
9797+ }
9898+9999+ return [self initWithResponse: responseBuffer length: responseLength];
100100+}
101101+102102+- (void) dealloc
103103+{
104104+ ImplData* data = (ImplData*) _impl;
105105+ if (data != NULL)
106106+ {
107107+ if (data->surface != NULL)
108108+ {
109109+ IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodRelease, NULL, 0, &data->surface->surfaceID, 1, NULL, 0, NULL, 0);
110110+111111+ free(data->surface);
112112+ }
113113+114114+ free(data);
115115+ }
116116+ [super dealloc];
117117+}
118118+119119+- (NSUInteger) hash
120120+{
121121+ ImplData* data = (ImplData*) _impl;
122122+ return data->surface->surfaceID;
123123+}
124124+125125+- (BOOL)isEqual:(id)object
126126+{
127127+ if (![object isKindOfClass: [self class]])
128128+ return NO;
129129+130130+ IOSurface* that = (IOSurface*) object;
131131+ return ((ImplData*) self->_impl)->surface->surfaceID == ((ImplData*) that->_impl)->surface->surfaceID;
132132+}
133133+134134+- (CFTypeID) _cfTypeID
135135+{
136136+ return IOSurfaceGetTypeID();
137137+}
138138+139139+- (NSInteger) width
140140+{
141141+ return [self widthOfPlaneAtIndex: 0];
142142+}
143143+144144+- (NSInteger) height
145145+{
146146+ return [self heightOfPlaneAtIndex: 0];
147147+}
148148+149149+- (void *) baseAddress
150150+{
151151+ return [self baseAddressOfPlaneAtIndex: 0];
152152+}
153153+154154+- (NSInteger) bytesPerRow
155155+{
156156+ return [self bytesPerRowOfPlaneAtIndex: 0];
157157+}
158158+159159+- (NSInteger) bytesPerElement
160160+{
161161+ return [self bytesPerElementOfPlaneAtIndex: 0];
162162+}
163163+164164+- (NSInteger) elementWidth
165165+{
166166+ return [self elementWidthOfPlaneAtIndex: 0];
167167+}
168168+169169+- (NSInteger) elementHeight
170170+{
171171+ return [self elementHeightOfPlaneAtIndex: 0];
172172+}
173173+174174+- (OSType) pixelFormat
175175+{
176176+ return ((ImplData*) _impl)->surface->pixelFormat;
177177+}
178178+179179+- (NSUInteger) planeCount
180180+{
181181+ return ((ImplData*) _impl)->surface->planeCount;
182182+}
183183+184184+- (NSInteger)widthOfPlaneAtIndex:(NSUInteger)planeIndex
185185+{
186186+ if (planeIndex >= [self planeCount])
187187+ return 0;
188188+189189+ ImplData* data = (ImplData*) _impl;
190190+ return data->surface->planes[planeIndex].width;
191191+}
192192+193193+- (NSInteger)heightOfPlaneAtIndex:(NSUInteger)planeIndex
194194+{
195195+ if (planeIndex >= [self planeCount])
196196+ return 0;
197197+198198+ ImplData* data = (ImplData*) _impl;
199199+ return data->surface->planes[planeIndex].height;
200200+}
201201+202202+- (NSInteger)bytesPerRowOfPlaneAtIndex:(NSUInteger)planeIndex
203203+{
204204+ if (planeIndex >= [self planeCount])
205205+ return 0;
206206+207207+ ImplData* data = (ImplData*) _impl;
208208+ return data->surface->planes[planeIndex].bytesPerRow;
209209+}
210210+211211+- (NSInteger)bytesPerElementOfPlaneAtIndex:(NSUInteger)planeIndex
212212+{
213213+ if (planeIndex >= [self planeCount])
214214+ return 0;
215215+216216+ ImplData* data = (ImplData*) _impl;
217217+ return data->surface->planes[planeIndex].bytesPerElement;
218218+}
219219+220220+- (NSInteger)elementWidthOfPlaneAtIndex:(NSUInteger)planeIndex
221221+{
222222+ return 1;
223223+}
224224+225225+- (NSInteger)elementHeightOfPlaneAtIndex:(NSUInteger)planeIndex
226226+{
227227+ return 1;
228228+}
229229+230230+- (void *)baseAddressOfPlaneAtIndex:(NSUInteger)planeIndex
231231+{
232232+ if (planeIndex >= [self planeCount])
233233+ return NULL;
234234+235235+ ImplData* data = (ImplData*) _impl;
236236+ return (void*)(data->surface->address + data->surface->planes[planeIndex].memoryOffset);
237237+}
238238+239239+- (void)incrementUseCount
240240+{
241241+ ImplData* data = (ImplData*) _impl;
242242+ if ((data->localUseCount++) == 0)
243243+ {
244244+ uint64_t scalar = data->surface->surfaceID;
245245+ IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodIncrementUseCount, &scalar, 1, NULL, 0, NULL, 0, NULL, 0);
246246+ }
247247+}
248248+249249+- (void)decrementUseCount
250250+{
251251+ ImplData* data = (ImplData*) _impl;
252252+ if (--data->localUseCount == 0)
253253+ {
254254+ uint64_t scalar = data->surface->surfaceID;
255255+ IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodDecrementUseCount, &scalar, 1, NULL, 0, NULL, 0, NULL, 0);
256256+ }
257257+}
258258+259259+- (int32_t) localUseCount
260260+{
261261+ ImplData* data = (ImplData*) _impl;
262262+ return data->localUseCount;
263263+}
264264+265265+- (kern_return_t)lockWithOptions:(IOSurfaceLockOptions)options seed:(nullable uint32_t *)seed
266266+{
267267+ ImplData* data = (ImplData*) _impl;
268268+ struct _IOSurfaceLockUnlock args = {
269269+ .surfaceID = data->surface->surfaceID,
270270+ .options = options,
271271+ };
272272+ return IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodLock, NULL, 0, &args, sizeof(args), NULL, 0, NULL, 0);
273273+}
274274+275275+- (kern_return_t)unlockWithOptions:(IOSurfaceLockOptions)options seed:(nullable uint32_t *)seed
276276+{
277277+ ImplData* data = (ImplData*) _impl;
278278+ struct _IOSurfaceLockUnlock args = {
279279+ .surfaceID = data->surface->surfaceID,
280280+ .options = options,
281281+ };
282282+ return IOConnectCallMethod(g_surfaceService, kIOSurfaceMethodUnlock, NULL, 0, &args, sizeof(args), NULL, 0, NULL, 0);
283283+}
284284+285285+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
286286+ return [NSMethodSignature signatureWithObjCTypes: "v@:"];
287287+}
288288+289289+- (void)forwardInvocation:(NSInvocation *)anInvocation {
290290+ NSLog(@"Stub called: %@ in %@", NSStringFromSelector([anInvocation selector]), [self class]);
291291+}
292292+293293+@end
+218
src/frameworks/IOSurface/src/api.m
···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2020 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#import <IOSurface/IOSurface.h>
2121+#import <IOSurface/IOSurfaceObjC.h>
2222+2323+CFTypeID IOSurfaceGetTypeID(void)
2424+{
2525+ return (CFTypeID) [IOSurface self];
2626+}
2727+2828+IOSurfaceRef _Nullable IOSurfaceCreate(CFDictionaryRef properties)
2929+{
3030+ return (IOSurfaceRef) [[IOSurface alloc] initWithProperties: (NSDictionary*) properties];
3131+}
3232+3333+IOSurfaceRef _Nullable IOSurfaceLookupFromMachPort(mach_port_t port)
3434+{
3535+ return (IOSurfaceRef) [[IOSurface alloc] initWithMachPort: port];
3636+}
3737+3838+xpc_object_t IOSurfaceCreateXPCObject(IOSurfaceRef surface)
3939+{
4040+ return 0;
4141+}
4242+4343+IOSurfaceRef IOSurfaceLookupFromXPCObject(xpc_object_t obj)
4444+{
4545+#if NOTYET
4646+ if (xpc_get_type(obj) == _xpc_type_mach_send)
4747+ {
4848+ mach_port_t port = xpc_mach_send_get_right(obj);
4949+ return IOSurfaceLookupFromMachPort(port);
5050+ }
5151+#endif
5252+ return NULL;
5353+}
5454+5555+kern_return_t IOSurfaceLock(IOSurfaceRef buffer, IOSurfaceLockOptions options, uint32_t * _Nullable seed)
5656+{
5757+ return [(IOSurface*)buffer lockWithOptions: options seed: seed];
5858+}
5959+6060+kern_return_t IOSurfaceUnlock(IOSurfaceRef buffer, IOSurfaceLockOptions options, uint32_t * _Nullable seed)
6161+{
6262+ return [(IOSurface*)buffer unlockWithOptions: options seed: seed];
6363+}
6464+6565+size_t IOSurfaceGetWidth(IOSurfaceRef buffer)
6666+{
6767+ return [(IOSurface*)buffer width];
6868+}
6969+7070+size_t IOSurfaceGetHeight(IOSurfaceRef buffer)
7171+{
7272+ return [(IOSurface*)buffer height];
7373+}
7474+7575+void *IOSurfaceGetBaseAddress(IOSurfaceRef buffer)
7676+{
7777+ return [(IOSurface*)buffer baseAddress];
7878+}
7979+8080+OSType IOSurfaceGetPixelFormat(IOSurfaceRef buffer)
8181+{
8282+ return [(IOSurface*)buffer pixelFormat];
8383+}
8484+8585+void IOSurfaceSetValue(IOSurfaceRef buffer, CFStringRef key, CFTypeRef value)
8686+{
8787+ return [(IOSurface*)buffer setAttachment: (id) value forKey: (NSString*) key];
8888+}
8989+9090+9191+CFTypeRef _Nullable IOSurfaceCopyValue(IOSurfaceRef buffer, CFStringRef key)
9292+{
9393+ return (CFTypeRef) [[(IOSurface*) buffer attachmentForKey: (NSString*) key] retain];
9494+}
9595+9696+9797+void IOSurfaceRemoveValue(IOSurfaceRef buffer, CFStringRef key)
9898+{
9999+ [(IOSurface*)buffer removeAttachmentForKey: (NSString*) key];
100100+}
101101+102102+103103+void IOSurfaceSetValues(IOSurfaceRef buffer, CFDictionaryRef keysAndValues)
104104+{
105105+ [(IOSurface*)buffer setAllAttachments: (NSDictionary*)keysAndValues];
106106+}
107107+108108+109109+CFDictionaryRef _Nullable IOSurfaceCopyAllValues(IOSurfaceRef buffer)
110110+{
111111+ return (CFDictionaryRef) [[(IOSurface*)buffer allAttachments] retain];
112112+}
113113+114114+115115+void IOSurfaceRemoveAllValues(IOSurfaceRef buffer)
116116+{
117117+ return [(IOSurface*)buffer removeAllAttachments];
118118+}
119119+120120+size_t IOSurfaceGetBytesPerRow(IOSurfaceRef buffer)
121121+{
122122+ return [(IOSurface*)buffer bytesPerRow];
123123+}
124124+125125+void IOSurfaceIncrementUseCount(IOSurfaceRef buffer)
126126+{
127127+ [(IOSurface*)buffer incrementUseCount];
128128+}
129129+130130+131131+void IOSurfaceDecrementUseCount(IOSurfaceRef buffer)
132132+{
133133+ [(IOSurface*)buffer decrementUseCount];
134134+}
135135+136136+137137+int32_t IOSurfaceGetUseCount(IOSurfaceRef buffer)
138138+{
139139+ return [(IOSurface*)buffer localUseCount];
140140+}
141141+142142+size_t IOSurfaceGetPlaneCount(IOSurfaceRef buffer)
143143+{
144144+ return [(IOSurface*)buffer planeCount];
145145+}
146146+147147+uint32_t IOSurfaceGetSeed(IOSurfaceRef buffer)
148148+{
149149+ return [(IOSurface*)buffer seed];
150150+}
151151+152152+size_t IOSurfaceGetWidthOfPlane(IOSurfaceRef buffer, size_t planeIndex)
153153+{
154154+ return [(IOSurface*)buffer widthOfPlaneAtIndex: planeIndex];
155155+}
156156+157157+158158+size_t IOSurfaceGetHeightOfPlane(IOSurfaceRef buffer, size_t planeIndex)
159159+{
160160+ return [(IOSurface*)buffer heightOfPlaneAtIndex: planeIndex];
161161+}
162162+163163+164164+size_t IOSurfaceGetBytesPerElementOfPlane(IOSurfaceRef buffer, size_t planeIndex)
165165+{
166166+ return [(IOSurface*)buffer bytesPerElementOfPlaneAtIndex: planeIndex];
167167+}
168168+169169+170170+size_t IOSurfaceGetBytesPerRowOfPlane(IOSurfaceRef buffer, size_t planeIndex)
171171+{
172172+ return [(IOSurface*)buffer bytesPerRowOfPlaneAtIndex: planeIndex];
173173+}
174174+175175+176176+void *IOSurfaceGetBaseAddressOfPlane(IOSurfaceRef buffer, size_t planeIndex)
177177+{
178178+ return [(IOSurface*)buffer baseAddressOfPlaneAtIndex: planeIndex];
179179+}
180180+181181+182182+size_t IOSurfaceGetElementWidthOfPlane(IOSurfaceRef buffer, size_t planeIndex)
183183+{
184184+ return [(IOSurface*)buffer elementWidthOfPlaneAtIndex: planeIndex];
185185+}
186186+187187+188188+size_t IOSurfaceGetElementHeightOfPlane(IOSurfaceRef buffer, size_t planeIndex)
189189+{
190190+ return [(IOSurface*)buffer elementHeightOfPlaneAtIndex: planeIndex];
191191+}
192192+193193+size_t IOSurfaceGetBytesPerElement(IOSurfaceRef buffer)
194194+{
195195+ return [(IOSurface*)buffer bytesPerElementOfPlaneAtIndex: 0];
196196+}
197197+198198+199199+size_t IOSurfaceGetElementWidth(IOSurfaceRef buffer)
200200+{
201201+ return [(IOSurface*)buffer widthOfPlaneAtIndex: 0];
202202+}
203203+204204+205205+size_t IOSurfaceGetElementHeight(IOSurfaceRef buffer)
206206+{
207207+ return [(IOSurface*)buffer heightOfPlaneAtIndex: 0];
208208+}
209209+210210+Boolean IOSurfaceIsInUse(IOSurfaceRef buffer)
211211+{
212212+ return [(IOSurface*)buffer isInUse];
213213+}
214214+215215+kern_return_t IOSurfaceSetPurgeable(IOSurfaceRef buffer, uint32_t newState, uint32_t * _Nullable oldState)
216216+{
217217+ return [(IOSurface*)buffer setPurgeable:newState oldState:oldState];
218218+}
+69
src/frameworks/IOSurface/src/constants.m
···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2020 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+#import <IOSurface/IOSurfaceRef.h>
2020+#import <IOSurface/IOSurfaceObjC.h>
2121+2222+const CFStringRef kIOSurfaceAllocSize = CFSTR("IOSurfaceAllocSize");
2323+const CFStringRef kIOSurfaceWidth = CFSTR("IOSurfaceWidth");
2424+const CFStringRef kIOSurfaceHeight = CFSTR("IOSurfaceHeight");
2525+const CFStringRef kIOSurfaceBytesPerRow = CFSTR("IOSurfaceBytesPerRow");
2626+const CFStringRef kIOSurfaceBytesPerElement = CFSTR("IOSurfaceBytesPerElement");
2727+const CFStringRef kIOSurfaceElementWidth = CFSTR("IOSurfaceElementWidth");
2828+const CFStringRef kIOSurfaceElementHeight = CFSTR("IOSurfaceElementHeight");
2929+const CFStringRef kIOSurfaceOffset = CFSTR("IOSurfaceOffset");
3030+const CFStringRef kIOSurfacePlaneInfo = CFSTR("IOSurfacePlaneInfo");
3131+const CFStringRef kIOSurfacePlaneWidth = CFSTR("IOSurfacePlaneWidth");
3232+const CFStringRef kIOSurfacePlaneHeight = CFSTR("IOSurfacePlaneHeight");
3333+const CFStringRef kIOSurfacePlaneBytesPerRow = CFSTR("IOSurfacePlaneBytesPerRow");
3434+const CFStringRef kIOSurfacePlaneOffset = CFSTR("IOSurfacePlaneOffset");
3535+const CFStringRef kIOSurfacePlaneSize = CFSTR("IOSurfacePlaneSize");
3636+const CFStringRef kIOSurfacePlaneBase = CFSTR("IOSurfacePlaneBase");
3737+const CFStringRef kIOSurfacePlaneBitsPerElement = CFSTR("IOSurfacePlaneBitsPerElement");
3838+const CFStringRef kIOSurfacePlaneBytesPerElement = CFSTR("IOSurfacePlaneBytesPerElement");
3939+const CFStringRef kIOSurfacePlaneElementWidth = CFSTR("IOSurfacePlaneElementWidth");
4040+const CFStringRef kIOSurfacePlaneElementHeight = CFSTR("IOSurfacePlaneElementHeight");
4141+const CFStringRef kIOSurfaceCacheMode = CFSTR("IOSurfaceCacheMode");
4242+const CFStringRef kIOSurfaceIsGlobal = CFSTR("IOSurfaceIsGlobal");
4343+const CFStringRef kIOSurfacePixelFormat = CFSTR("IOSurfacePixelFormat");
4444+const CFStringRef kIOSurfacePixelSizeCastingAllowed = CFSTR("IOSurfacePixelSizeCastingAllowed");
4545+const CFStringRef kIOSurfacePlaneComponentBitDepths = CFSTR("IOSurfacePlaneComponentBitDepths");
4646+const CFStringRef kIOSurfacePlaneComponentBitOffsets = CFSTR("IOSurfacePlaneComponentBitOffsets");
4747+4848+IOSurfacePropertyKey IOSurfacePropertyKeyAllocSize = @"IOSurfacePropertyKeyAllocSize";
4949+IOSurfacePropertyKey IOSurfacePropertyKeyWidth = @"IOSurfacePropertyKeyWidth";
5050+IOSurfacePropertyKey IOSurfacePropertyKeyHeight = @"IOSurfacePropertyKeyHeight";
5151+IOSurfacePropertyKey IOSurfacePropertyKeyBytesPerRow = @"IOSurfacePropertyKeyBytesPerRow";
5252+IOSurfacePropertyKey IOSurfacePropertyKeyBytesPerElement = @"IOSurfacePropertyKeyBytesPerElement";
5353+IOSurfacePropertyKey IOSurfacePropertyKeyElementWidth = @"IOSurfacePropertyKeyElementWidth";
5454+IOSurfacePropertyKey IOSurfacePropertyKeyElementHeight = @"IOSurfacePropertyKeyElementHeight";
5555+IOSurfacePropertyKey IOSurfacePropertyKeyOffset = @"IOSurfacePropertyKeyOffset";
5656+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneInfo = @"IOSurfacePropertyKeyPlaneInfo";
5757+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneWidth = @"IOSurfacePropertyKeyPlaneWidth";
5858+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneHeight = @"IOSurfacePropertyKeyPlaneHeight";
5959+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneBytesPerRow = @"IOSurfacePropertyKeyPlaneBytesPerRow";
6060+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneOffset = @"IOSurfacePropertyKeyPlaneOffset";
6161+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneSize = @"IOSurfacePropertyKeyPlaneSize";
6262+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneBase = @"IOSurfacePropertyKeyPlaneBase";
6363+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneBytesPerElement = @"IOSurfacePropertyKeyPlaneBytesPerElement";
6464+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneElementWidth = @"IOSurfacePropertyKeyPlaneElementWidth";
6565+IOSurfacePropertyKey IOSurfacePropertyKeyPlaneElementHeight = @"IOSurfacePropertyKeyPlaneElementHeight";
6666+IOSurfacePropertyKey IOSurfacePropertyKeyCacheMode = @"IOSurfacePropertyKeyCacheMode";
6767+IOSurfacePropertyKey IOSurfacePropertyKeyPixelFormat = @"IOSurfacePropertyKeyPixelFormat";
6868+IOSurfacePropertyKey IOSurfacePropertyKeyPixelSizeCastingAllowed = @"IOSurfacePropertyKeyPixelSizeCastingAllowed";
6969+
+126
src/frameworks/IOSurface/src/stubs.m
···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2017 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#include <stdlib.h>
2121+#include <stdio.h>
2222+#import <IOSurface/IOSurface.h>
2323+2424+#include <CoreFoundation/CoreFoundation.h>
2525+2626+static int verbose = 0;
2727+2828+__attribute__((constructor))
2929+static void initme(void) {
3030+ verbose = getenv("STUB_VERBOSE") != NULL;
3131+}
3232+3333+3434+IOSurfaceRef _Nullable IOSurfaceLookup(IOSurfaceID csid){
3535+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
3636+ return 0;
3737+}
3838+3939+4040+IOSurfaceID IOSurfaceGetID(IOSurfaceRef buffer){
4141+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
4242+ return 0;
4343+}
4444+4545+4646+size_t IOSurfaceGetAllocSize(IOSurfaceRef buffer){
4747+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
4848+ return 0;
4949+}
5050+5151+5252+5353+size_t IOSurfaceGetNumberOfComponentsOfPlane(IOSurfaceRef buffer, size_t planeIndex){
5454+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
5555+ return 0;
5656+}
5757+5858+5959+IOSurfaceComponentName IOSurfaceGetNameOfComponentOfPlane(IOSurfaceRef buffer, size_t planeIndex, size_t componentIndex){
6060+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
6161+ return 0;
6262+}
6363+6464+6565+IOSurfaceComponentType IOSurfaceGetTypeOfComponentOfPlane(IOSurfaceRef buffer, size_t planeIndex, size_t componentIndex){
6666+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
6767+ return 0;
6868+}
6969+7070+7171+IOSurfaceComponentRange IOSurfaceGetRangeOfComponentOfPlane(IOSurfaceRef buffer, size_t planeIndex, size_t componentIndex){
7272+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
7373+ return 0;
7474+}
7575+7676+7777+size_t IOSurfaceGetBitDepthOfComponentOfPlane(IOSurfaceRef buffer, size_t planeIndex, size_t componentIndex){
7878+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
7979+ return 0;
8080+}
8181+8282+8383+size_t IOSurfaceGetBitOffsetOfComponentOfPlane(IOSurfaceRef buffer, size_t planeIndex, size_t componentIndex){
8484+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
8585+ return 0;
8686+}
8787+8888+8989+IOSurfaceSubsampling IOSurfaceGetSubsampling(IOSurfaceRef buffer){
9090+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
9191+ return 0;
9292+}
9393+9494+9595+9696+mach_port_t IOSurfaceCreateMachPort(IOSurfaceRef buffer){
9797+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
9898+ return 0;
9999+}
100100+101101+102102+size_t IOSurfaceGetPropertyMaximum(CFStringRef property){
103103+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
104104+ return 0;
105105+}
106106+107107+size_t IOSurfaceGetPropertyAlignment(CFStringRef property){
108108+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
109109+ return 0;
110110+}
111111+112112+113113+114114+size_t IOSurfaceAlignProperty(CFStringRef property, size_t value){
115115+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
116116+ return 0;
117117+}
118118+119119+120120+121121+Boolean IOSurfaceAllowsPixelSizeCasting(IOSurfaceRef buffer){
122122+ if (verbose) printf("STUB: %s called\n", __FUNCTION__);
123123+ return 0;
124124+}
125125+126126+