skia-bindings 0.97.0

Skia Bindings for Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#include "bindings.h"

#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkCPURecorder.h"
#include "include/core/SkDrawable.h"
#include "include/core/SkPicture.h"
#include "include/core/SkSurface.h"
#include "include/core/SkImageGenerator.h"
#include "include/gpu/MutableTextureState.h"
#include "include/gpu/ganesh/GrBackendSemaphore.h"
#include "include/gpu/ganesh/GrDirectContext.h"
#include "include/gpu/ganesh/GrYUVABackendTextures.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"

// Size / Alignment proxy for GrContextOptions
typedef std::optional<uint64_t> OptionalU64;

extern "C" void C_GpuUnreferencedTypes(skgpu::Origin *, OptionalU64*) {}

//
// core/SkSurface.h
//

extern "C" bool C_SkSurface_replaceBackendTexture(
        SkSurface* self,
        const GrBackendTexture* backendTexture,
        GrSurfaceOrigin origin,
        SkSurface::ContentChangeMode contentChangeMode) {
    return self->replaceBackendTexture(*backendTexture, origin, contentChangeMode);
}

//
// gpu/GrBackendSurface.h
//

// GrBackendSemaphore

extern "C" void C_GrBackendSemaphore_Construct(GrBackendSemaphore* uninitialized) {
    new(uninitialized) GrBackendSemaphore();
}

extern "C" void C_GrBackendSemaphore_CopyConstruct(
    GrBackendSemaphore* uninitialized,
    const GrBackendSemaphore* semaphore) {
    new(uninitialized) GrBackendSemaphore(*semaphore);
}

extern "C" void C_GrBackendSemaphore_destruct(GrBackendSemaphore* semaphore) {
    semaphore->~GrBackendSemaphore();
}

extern "C" GrBackendApi C_GrBackendSemaphore_backend(const GrBackendSemaphore* semaphore) {
    return semaphore->backend();
}

extern "C" bool C_GrBackendSemaphore_isInitialized(const GrBackendSemaphore* semaphore) {
    return semaphore->isInitialized();
}

// GrBackendRenderTarget

extern "C" void C_GrBackendRenderTarget_Construct(GrBackendRenderTarget* uninitialized) {
    new(uninitialized) GrBackendRenderTarget();
}

extern "C" void C_GrBackendRenderTarget_CopyConstruct(GrBackendRenderTarget* uninitialized, const GrBackendRenderTarget* renderTarget) {
    new(uninitialized) GrBackendRenderTarget(*renderTarget);
}

extern "C" void C_GrBackendRenderTarget_destruct(GrBackendRenderTarget* self) {
    self->~GrBackendRenderTarget();
}

extern "C" void C_GrBackendRenderTarget_getBackendFormat(const GrBackendRenderTarget* self, GrBackendFormat* uninitialized) {
    new(uninitialized) GrBackendFormat(self->getBackendFormat());
}

// GrBackendTexture

extern "C" GrBackendTexture* C_GrBackendTexture_new() {
    return new GrBackendTexture();
}

extern "C" GrBackendTexture* C_GrBackendTexture_Clone(const GrBackendTexture* texture) {
    return new GrBackendTexture(*texture);
}

extern "C" void C_GrBackendTexture_delete(const GrBackendTexture* self) {
    delete self;
}

extern "C" void C_GrBackendTexture_getBackendFormat(const GrBackendTexture* self, GrBackendFormat* format) {
    *format = self->getBackendFormat();
}

// GrBackendFormat

extern "C" void C_GrBackendFormat_Construct(GrBackendFormat* uninitialized) {
    new(uninitialized)GrBackendFormat();
}

extern "C" void C_GrBackendFormat_destruct(GrBackendFormat* self) {
    self->~GrBackendFormat();
}

extern "C" bool C_GrBackendFormat_Equals(const GrBackendFormat* lhs, const GrBackendFormat* rhs) {
    return *lhs == *rhs;
}

extern "C" void C_GrBackendFormat_makeTexture2D(const GrBackendFormat* self, GrBackendFormat* format) {
    *format = self->makeTexture2D();
}

//
// gpu/MutableTextureState.h
//

extern "C" skgpu::MutableTextureState* C_MutableTextureState_Construct() {
    return new skgpu::MutableTextureState();
}

extern "C" skgpu::MutableTextureState* C_MutableTextureState_CopyConstruct(const skgpu::MutableTextureState* state) {
    return new skgpu::MutableTextureState(*state);
}

extern "C" skgpu::BackendApi C_MutableTextureState_backend(const skgpu::MutableTextureState* self) {
    return self->backend();
}

//
// gpu/GrRecordingContext.h
//

// GrContext_Base.h
extern "C" GrDirectContext* C_GrRecordingContext_asDirectContext(GrRecordingContext* self) {
    return self->asDirectContext();
}

// GrContext_Base.h
extern "C" GrBackendApi C_GrRecordingContext_backend(const GrRecordingContext* self) {
    return self->backend();
}

extern "C" void C_GrRecordingContext_defaultBackendFormat(const GrRecordingContext* self, SkColorType ct, GrRenderable renderable, GrBackendFormat* result) {
    *result = self->defaultBackendFormat(ct, renderable);
}

// GrContext_Base.h
extern "C" void C_GrRecordingContext_compressedBackendFormat(const GrRecordingContext* self, SkTextureCompressionType compressionType, GrBackendFormat* backendFormat) {
    *backendFormat = self->compressedBackendFormat(compressionType);
}

extern "C" bool C_GrRecordingContext_abandoned(GrRecordingContext* self) {
    return self->abandoned();
}

extern "C" int C_GrRecordingContext_maxSurfaceSampleCountForColorType(const GrRecordingContext* self, SkColorType colorType) {
    return self->maxSurfaceSampleCountForColorType(colorType);
}

extern "C" skcpu::Recorder* C_GrRecordingContext_makeCPURecorder(GrRecordingContext* self) {
    return self->makeCPURecorder().release();
}

//
// gpu/GrDirectContext.h
//

extern "C" void C_GrDirectContext_flushAndSubmit(GrDirectContext* self) {
    self->flushAndSubmit();
}

extern "C" GrSemaphoresSubmitted C_GrDirectContext_flushImageWithInfo(GrDirectContext* self, SkImage* image, const GrFlushInfo* info) {
    return self->flush(sp(image), *info);
}

extern "C" void C_GrDirectContext_flushImage(GrDirectContext* self, SkImage* image) {
    self->flush(sp(image));
}

extern "C" void C_GrDirectContext_flushAndSubmitImage(GrDirectContext* self, SkImage* image) {
    self->flushAndSubmit(sp(image));
}

extern "C" void C_GrDirectContext_compressedBackendFormat(const GrDirectContext* self, SkTextureCompressionType compression, GrBackendFormat* result) {
    *result = self->compressedBackendFormat(compression);
}

extern "C" void C_GrDirectContext_directContextId(const GrDirectContext* self, GrDirectContext::DirectContextID* r) {
    *r = self->directContextID();
}

extern "C" void C_GrDirectContext_performDeferredCleanup(GrDirectContext* self, long msNotUsed, GrPurgeResourceOptions opts) {
    self->performDeferredCleanup(std::chrono::milliseconds(msNotUsed), opts);
}

//
// gpu/GrContextOptions.h
//

extern "C" void C_GrContextOptions_Construct(GrContextOptions* uninitialized) {
    new(uninitialized) GrContextOptions();
}

//
// gpu/GrRecordingContext.h
//

extern "C" bool C_GrRecordingContext_colorTypeSupportedAsSurface(const GrRecordingContext* self, SkColorType colorType) {
    return self->colorTypeSupportedAsSurface(colorType);
}

//
// gpu/GrYUVABackendTextures.h
//

extern "C" void C_GrYUVABackendTextureInfo_destruct(GrYUVABackendTextureInfo* self) {
    self->~GrYUVABackendTextureInfo();
}

extern "C" void C_GrYUVABackendTextureInfo_CopyConstruct(GrYUVABackendTextureInfo* uninitialized, const GrYUVABackendTextureInfo* src) {
    new(uninitialized) GrYUVABackendTextureInfo(*src);
}

extern "C" bool C_GrYUVABackendTextureInfo_equals(const GrYUVABackendTextureInfo* a, const GrYUVABackendTextureInfo* b) {
    return *a == *b;
}

extern "C" GrYUVABackendTextures* C_GrYUVABackendTextures_new(
    const SkYUVAInfo& yuvaInfo,
    const GrBackendTexture* const *backend_textures,
    GrSurfaceOrigin textureOrigin
) {
    GrBackendTexture textures[SkYUVAInfo::kMaxPlanes];
    for (int i = 0; i < SkYUVAInfo::kMaxPlanes; ++i) {
        textures[i] = *backend_textures[i];
    }
    return new GrYUVABackendTextures(yuvaInfo, textures, textureOrigin);
}

extern "C" void C_GrYUVABackendTextures_delete(GrYUVABackendTextures* self) {
    delete self;
}

extern "C" const SkYUVAInfo* C_GrYUVABackendTextures_yuvaInfo(const GrYUVABackendTextures* self) {
    return &self->yuvaInfo();
}

extern "C" GrSurfaceOrigin C_GrYUVABackendTextures_textureOrigin(const GrYUVABackendTextures* self) {
    return self->textureOrigin();
}

extern "C" const GrBackendTexture* C_GrYUVABackendTextures_textures(const GrYUVABackendTextures* self) {
    return self->textures().data();
}

//
// core/SkCanvas.h
//

extern "C" GrRecordingContext* C_SkCanvas_recordingContext(const SkCanvas* self) {
    return self->recordingContext();
}

//
// core/SkDrawable.h
//

extern "C" SkDrawable::GpuDrawHandler *C_SkDrawable_snapGpuDrawHandler(SkDrawable *self, GrBackendApi backendApi,
                                                                       const SkMatrix *matrix,
                                                                       const SkIRect *clipBounds,
                                                                       const SkImageInfo *bufferInfo) {
    return self->snapGpuDrawHandler(backendApi, *matrix, *clipBounds, *bufferInfo).release();
}

extern "C" void C_SkDrawable_GpuDrawHandler_delete(SkDrawable::GpuDrawHandler *self) {
    delete self;
}

extern "C" void C_SkDrawable_GpuDrawHandler_draw(SkDrawable::GpuDrawHandler *self, const GrBackendDrawableInfo *info) {
    self->draw(*info);
}

//
// gpu/ganesh/SkImageGanesh.h
//

extern "C" SkImage* C_SkImages_AdoptTextureFrom(
        GrRecordingContext* context,
        const GrBackendTexture* backendTexture,
        GrSurfaceOrigin origin,
        SkColorType colorType,
        SkAlphaType alphaType,
        SkColorSpace* colorSpace) {
    return SkImages::AdoptTextureFrom(context, *backendTexture, origin, colorType, alphaType, sp(colorSpace)).release();
}

extern "C" SkImage* C_SkImages_BorrowTextureFrom(
        GrRecordingContext* context,
        const GrBackendTexture* backendTexture,
        GrSurfaceOrigin origin,
        SkColorType colorType,
        SkAlphaType alphaType,
        SkColorSpace* colorSpace) {
    return SkImages::BorrowTextureFrom(context, *backendTexture, origin, colorType, alphaType, sp(colorSpace)).release();
}

extern "C" SkImage* C_SkImages_CrossContextTextureFromPixmap(
        GrDirectContext* context,
        const SkPixmap* pixmap,
        bool buildMips,
        bool limitToMaxTextureSize) {
    return SkImages::CrossContextTextureFromPixmap(context, *pixmap, buildMips, limitToMaxTextureSize).release();
}

extern "C" SkImage *C_SkImages_TextureFromCompressedTextureData(GrDirectContext *context, SkData *data, int width, int height,
                                                SkTextureCompressionType type, skgpu::Mipmapped mipMapped,
                                                GrProtected prot) {
    return SkImages::TextureFromCompressedTextureData(context, sp(data), width, height, type, mipMapped, prot).release();
}

extern "C" SkImage* C_SkImages_TextureFromImage(
        GrDirectContext* context,
        const SkImage* self,
        skgpu::Mipmapped mipMapped,
        skgpu::Budgeted budgeted) {
    return SkImages::TextureFromImage(context, self, mipMapped, budgeted).release();
}

extern "C" SkImage* C_SkImages_TextureFromYUVAPixmaps(
    GrRecordingContext* context,
    const SkYUVAPixmaps* pixmaps,
    skgpu::Mipmapped buildMips,
    bool limitToMaxTextureSize,
    SkColorSpace* imageColorSpace
) {
    return SkImages::TextureFromYUVAPixmaps(context, *pixmaps, buildMips, limitToMaxTextureSize, sp(imageColorSpace)).release();
}


extern "C" SkImage* C_SkImages_TextureFromYUVATextures(
    GrRecordingContext* context,
    const GrYUVABackendTextures* yuvaTextures,
    SkColorSpace* imageColorSpace) {
    return SkImages::TextureFromYUVATextures(context, *yuvaTextures, sp(imageColorSpace)).release();
}

extern "C" GrBackendTexture* C_SkImages_GetBackendTextureFromImage(
    const SkImage* self,
    bool flushPendingGrContextIO,
    GrSurfaceOrigin* origin)
{
    auto texture = new GrBackendTexture();
    // TODO: Might need to check the return value, only the validity of the texture is checked by the caller.
    SkImages::GetBackendTextureFromImage(self, texture, flushPendingGrContextIO, origin);
    return texture;
}

extern "C" SkImage* C_SkImages_SubsetTextureFrom(
    GrDirectContext* context,
    const SkImage* image,
    const SkIRect* subset) 
{
    return SkImages::SubsetTextureFrom(context, image, *subset).release();
}

//
// gpu/ganesh/SkSurfaceGanesh.h
//

extern "C" SkSurface* C_SkSurfaces_RenderTarget(
    GrRecordingContext* context,
    skgpu::Budgeted budgeted,
    const SkImageInfo* imageInfo,
    int sampleCount,
    GrSurfaceOrigin surfaceOrigin,
    const SkSurfaceProps* surfaceProps,
    bool shouldCreateWithMips,
    bool isProtected) {
    return SkSurfaces::RenderTarget(
            context,
            budgeted,
            *imageInfo,
            sampleCount,
            surfaceOrigin,
            surfaceProps,
            shouldCreateWithMips, 
            isProtected).release();
}

extern "C" SkSurface* C_SkSurfaces_WrapBackendTexture(
        GrRecordingContext* context,
        const GrBackendTexture* backendTexture,
        GrSurfaceOrigin origin,
        int sampleCnt,
        SkColorType colorType,
        SkColorSpace* colorSpace,
        const SkSurfaceProps* surfaceProps) {
    return SkSurfaces::WrapBackendTexture(
            context,
            *backendTexture,
            origin,
            sampleCnt,
            colorType,
            sp(colorSpace), surfaceProps).release();
}

extern "C" SkSurface* C_SkSurfaces_WrapBackendRenderTarget(
    GrRecordingContext* context,
    const GrBackendRenderTarget* backendRenderTarget,
    GrSurfaceOrigin origin,
    SkColorType colorType,
    SkColorSpace* colorSpace,
    const SkSurfaceProps* surfaceProps
    )
{
    return SkSurfaces::WrapBackendRenderTarget(
            context,
            *backendRenderTarget,
            origin,
            colorType,
            sp(colorSpace),
            surfaceProps).release();
}

extern "C" GrBackendTexture* C_SkSurfaces_GetBackendTexture(
    SkSurface* surface,
    SkSurface::BackendHandleAccess handleAccess) 
{
    return new GrBackendTexture(SkSurfaces::GetBackendTexture(surface, handleAccess));
}

extern "C" void C_SkSurfaces_GetBackendRenderTarget(
    SkSurface* surface,
    SkSurface::BackendHandleAccess handleAccess,
    GrBackendRenderTarget *backendRenderTarget)
{
    *backendRenderTarget = SkSurfaces::GetBackendRenderTarget(surface, handleAccess);
}

extern "C" void C_SkSurfaces_ResolveMSAA(SkSurface* surface)
{
    SkSurfaces::ResolveMSAA(surface);
}