forked from HinTak/skia-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_grcontext.py
610 lines (383 loc) · 18.6 KB
/
test_grcontext.py
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
import sys
import skia
import pytest
from datetime import timedelta
@pytest.fixture
def backend_semaphore():
return skia.GrBackendSemaphore()
@pytest.mark.skip(reason='m120:withdrawn from public API')
def test_GrBackendSemaphore_initGL(backend_semaphore):
backend_semaphore.initGL(None)
@pytest.fixture
def backend_semaphore_vk():
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
return skia.GrBackendSemaphore.MakeVk(None)
@pytest.mark.skip(reason='m124:GrBackendSemaphore::initVulkan replaced by GrBackendSemaphores::MakeVk')
def test_GrBackendSemaphore_initVulkan(backend_semaphore):
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
backend_semaphore.initVulkan(None)
def test_GrBackendSemaphore_isInitialized(backend_semaphore):
assert isinstance(backend_semaphore.isInitialized(), bool)
@pytest.mark.skip(reason='m120:withdrawn from public API')
def test_GrBackendSemaphore_glSync(backend_semaphore):
backend_semaphore.glSync()
def test_GrBackendSemaphore_vkSemaphore(backend_semaphore):
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
backend_semaphore.vkSemaphore()
def test_GrBackendSemaphore_vkSemaphore_vk(backend_semaphore_vk):
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
backend_semaphore_vk.vkSemaphore()
@pytest.fixture(scope='module')
def backend_format():
return skia.GrBackendFormat.MakeMock(
skia.GrColorType.kBGRA_8888, skia.Image.kBC1_RGBA8_UNORM)
def test_GrBackendFormat_MakeGL():
assert isinstance(skia.GrBackendFormat.MakeGL(0, 0), skia.GrBackendFormat)
def test_GrBackendFormat_MakeVk_1():
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
assert isinstance(
skia.GrBackendFormat.MakeVk(0), (type(None), skia.GrBackendFormat))
def test_GrBackendFormat_MakeVk_2():
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
assert isinstance(
skia.GrBackendFormat.MakeVk(skia.GrVkYcbcrConversionInfo()),
(type(None), skia.GrBackendFormat))
def test_GrBackendFormat_MakeMock(backend_format):
assert isinstance(backend_format, skia.GrBackendFormat)
def test_GrBackendFormat_eq(backend_format):
assert backend_format == backend_format
def test_GrBackendFormat_ne(backend_format):
assert backend_format != skia.GrBackendFormat()
def test_GrBackendFormat_backend(backend_format):
assert isinstance(backend_format.backend(), skia.GrBackendApi)
def test_GrBackendFormat_textureType(backend_format):
assert isinstance(backend_format.textureType(), skia.GrTextureType)
def test_GrBackendFormat_channelMask(backend_format):
assert isinstance(backend_format.channelMask(), int)
def test_GrBackendFormat_asVkFormat(backend_format):
fmt = 1
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
assert isinstance(backend_format.asVkFormat(fmt), bool)
def test_GrBackendFormat_asGLFormat(backend_format):
assert isinstance(backend_format.asGLFormat(), skia.GrGLFormat)
def test_GrBackendFormat_getVkYcbcrConversionInfo(backend_format):
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
assert isinstance(
backend_format.getVkYcbcrConversionInfo(),
(type(None), skia.GrVkYcbcrConversionInfo))
def test_GrBackendFormat_isValid(backend_format):
assert isinstance(backend_format.isValid(), bool)
@pytest.fixture(scope='module')
def backend_texture(context, gl_texture_info):
return skia.GrBackendTexture(
256, 256, skia.GrMipmapped.kNo, gl_texture_info)
def test_GrBackendTexture_init_glInfo(gl_texture_info):
assert isinstance(
skia.GrBackendTexture(128, 128, skia.GrMipmapped.kNo, gl_texture_info),
skia.GrBackendTexture)
def test_GrBackendTexture_init_mockInfo(mock_texture_info):
assert isinstance(
skia.GrBackendTexture(
128, 128, skia.GrMipmapped.kNo, mock_texture_info),
skia.GrBackendTexture)
def test_GrBackendTexture_dimensions(backend_texture):
assert isinstance(backend_texture.dimensions(), skia.ISize)
def test_GrBackendTexture_width(backend_texture):
assert isinstance(backend_texture.width(), int)
def test_GrBackendTexture_height(backend_texture):
assert isinstance(backend_texture.height(), int)
def test_GrBackendTexture_hasMipmaps(backend_texture):
assert isinstance(backend_texture.hasMipmaps(), bool)
def test_GrBackendTexture_getGLTextureInfo(backend_texture, gl_texture_info):
assert isinstance(backend_texture.getGLTextureInfo(gl_texture_info), bool)
def test_GrBackendTexture_glTextureParametersModified(backend_texture):
backend_texture.glTextureParametersModified()
def test_GrBackendTexture_getBackendFormat(backend_texture):
assert isinstance(backend_texture.getBackendFormat(), skia.GrBackendFormat)
def test_GrBackendTexture_getMockTextureInfo(
backend_texture, mock_texture_info):
assert isinstance(
backend_texture.getMockTextureInfo(mock_texture_info), bool)
def test_GrBackendTexture_isProtected(backend_texture):
assert isinstance(backend_texture.isProtected(), bool)
def test_GrBackendTexture_isValid(backend_texture):
assert isinstance(backend_texture.isValid(), bool)
def test_GrBackendTexture_isSameTexture(backend_texture):
assert isinstance(backend_texture.isSameTexture(backend_texture), bool)
@pytest.fixture
def grflushinfo():
return skia.GrFlushInfo()
def test_GrFlushInfo_fNumSemaphores(grflushinfo):
assert isinstance(grflushinfo.fNumSemaphores, int)
def test_GrFlushInfo_semaphores(grflushinfo, backend_semaphore):
if not backend_semaphore.isInitialized():
pytest.skip("backend_semaphore.initGL() withdrawn in m120. Segfault. Init differently? REVISIT")
grflushinfo.semaphores = [backend_semaphore]
assert isinstance(grflushinfo.semaphores, list)
@pytest.fixture
def backend_render_target():
return skia.GrBackendRenderTarget()
@pytest.mark.parametrize('args', [
tuple(),
(128, 128, 2, 8, skia.GrGLFramebufferInfo()),
(128, 128, skia.GrVkImageInfo()),
(128, 128, 2, 8, skia.GrMockRenderTargetInfo()),
])
def test_GrBackendRenderTarget_init(args):
args_has_Vk_types = False
for x in args:
if isinstance(x, skia.GrVkImageInfo):
args_has_Vk_types = True
if sys.platform.startswith("darwin") and args_has_Vk_types:
pytest.skip("Known not to work")
assert isinstance(
skia.GrBackendRenderTarget(*args), skia.GrBackendRenderTarget)
def test_GrBackendRenderTarget_dimensions(backend_render_target):
assert isinstance(backend_render_target.dimensions(), skia.ISize)
def test_GrBackendRenderTarget_width(backend_render_target):
assert isinstance(backend_render_target.width(), int)
def test_GrBackendRenderTarget_height(backend_render_target):
assert isinstance(backend_render_target.height(), int)
def test_GrBackendRenderTarget_sampleCnt(backend_render_target):
assert isinstance(backend_render_target.sampleCnt(), int)
def test_GrBackendRenderTarget_stencilBits(backend_render_target):
assert isinstance(backend_render_target.stencilBits(), int)
def test_GrBackendRenderTarget_backend(backend_render_target):
assert isinstance(backend_render_target.backend(), skia.GrBackendApi)
def test_GrBackendRenderTarget_isFramebufferOnly(backend_render_target):
assert isinstance(backend_render_target.isFramebufferOnly(), bool)
def test_GrBackendRenderTarget_getGLFramebufferInfo(backend_render_target):
info = skia.GrGLFramebufferInfo()
assert isinstance(backend_render_target.getGLFramebufferInfo(info), bool)
def test_GrBackendRenderTarget_getVkImageInfo(backend_render_target):
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
info = skia.GrVkImageInfo()
assert isinstance(backend_render_target.getVkImageInfo(info), bool)
def test_GrBackendRenderTarget_setVkImageLayout(backend_render_target):
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
backend_render_target.setVkImageLayout(0)
def test_GrBackendRenderTarget_getBackendFormat(backend_render_target):
assert isinstance(
backend_render_target.getBackendFormat(), skia.GrBackendFormat)
def test_GrBackendRenderTarget_getMockRenderTargetInfo(backend_render_target):
info = skia.GrMockRenderTargetInfo()
assert isinstance(backend_render_target.getMockRenderTargetInfo(info), bool)
def test_GrBackendRenderTarget_isProtected(backend_render_target):
assert isinstance(backend_render_target.isProtected(), bool)
def test_GrBackendRenderTarget_isValid(backend_render_target):
assert isinstance(backend_render_target.isValid(), bool)
@pytest.fixture
def backend_surface_mutable_state():
return skia.GrBackendSurfaceMutableState()
@pytest.mark.skip(reason='m118:REVISIT')
def test_GrBackendSurfaceMutableState_init(backend_surface_mutable_state):
assert isinstance(
backend_surface_mutable_state, skia.GrBackendSurfaceMutableState)
@pytest.mark.skip(reason='m118:REVISIT')
def test_GrBackendSurfaceMutableState_isValid(backend_surface_mutable_state):
assert isinstance(backend_surface_mutable_state.isValid(), bool)
@pytest.mark.skip(reason='m118:REVISIT')
def test_GrBackendSurfaceMutableState_backend(backend_surface_mutable_state):
assert isinstance(
backend_surface_mutable_state.backend(), skia.gpuBackendApi)
def test_GrContext_resetContext(context):
context.resetContext()
def test_GrContext_resetGLTextureBindings(context):
context.resetGLTextureBindings()
@pytest.mark.skip(reason='This destroys the context')
def test_GrContext_abandonContext(context):
context.abandonContext()
def test_GrRecordingContext_abandoned(context):
assert isinstance(context.abandoned(), bool)
def test_GrContext_oomed(context):
assert isinstance(context.oomed(), bool)
@pytest.mark.skip(reason='This destroys the context')
def test_GrContext_releaseResourcesAndAbandonContext(context):
context.releaseResourcesAndAbandonContext()
def test_GrContext_getResourceCacheLimit(context):
assert isinstance(context.getResourceCacheLimit(), int)
def test_GrContext_getResourceCacheUsage(context):
resource_count, max_resource_bytes = 0, 0
context.getResourceCacheUsage(resource_count, max_resource_bytes)
def test_GrContext_getResourceCachePurgeableBytes(context):
assert isinstance(context.getResourceCachePurgeableBytes(), int)
def test_GrContext_setResourceCacheLimit(context):
context.setResourceCacheLimit((1 << 16))
def test_GrContext_freeGpuResources(context):
context.freeGpuResources()
@pytest.mark.skip(reason='m116:REVISIT')
def test_GrContext_performDeferredCleanup(context):
context.performDeferredCleanup(timedelta(milliseconds=1000))
def test_GrContext_purgeResourcesNotUsedInMs(context):
context.purgeResourcesNotUsedInMs(timedelta(milliseconds=1000))
@pytest.mark.parametrize('args', [
(1 << 16, True),
(skia.GrPurgeResourceOptions.kAllResources,),
])
def test_GrContext_purgeUnlockedResources(context, args):
context.purgeUnlockedResources(*args)
def test_GrContext_maxTextureSize(context):
assert isinstance(context.maxTextureSize(), int)
def test_GrContext_maxRenderTargetSize(context):
assert isinstance(context.maxRenderTargetSize(), int)
def test_GrContext_colorTypeSupportedAsImage(context):
assert isinstance(context.colorTypeSupportedAsImage(
skia.ColorType.kRGBA_8888_ColorType), bool)
def test_GrContext_colorTypeSupportedAsSurface(context):
assert isinstance(context.colorTypeSupportedAsSurface(
skia.ColorType.kRGBA_8888_ColorType), bool)
def test_GrContext_maxSurfaceSampleCountForColorType(context):
assert isinstance(context.maxSurfaceSampleCountForColorType(
skia.ColorType.kRGBA_8888_ColorType), int)
def test_GrContext_wait(context, backend_semaphore):
if not backend_semaphore.isInitialized():
pytest.skip("backend_semaphore.initGL() withdrawn in m120. Segfault. Init differently? REVISIT")
assert isinstance(context.wait([backend_semaphore]), bool)
def test_GrContext_flush(context, grflushinfo):
assert isinstance(context.flush(grflushinfo), skia.GrSemaphoresSubmitted)
def test_GrContext_flushAndSubmit(context):
context.flushAndSubmit()
def test_GrContext_submit(context):
context.submit()
def test_GrContext_checkAsyncWorkCompletion(context):
context.checkAsyncWorkCompletion()
def test_GrContext_supportsDistanceFieldText(context):
assert isinstance(context.supportsDistanceFieldText(), bool)
def test_GrContext_storeVkPipelineCacheData(context):
context.storeVkPipelineCacheData()
def test_GrRecordingContext_defaultBackendFormat(context):
assert isinstance(
context.defaultBackendFormat(
skia.ColorType.kRGBA_8888_ColorType, skia.GrRenderable.kNo),
skia.GrBackendFormat)
def test_GrRecordingContext_maxTextureSize(context):
assert isinstance(context.maxTextureSize(), int)
def test_GrRecordingContext_maxRenderTargetSize(context):
assert isinstance(context.maxRenderTargetSize(), int)
def test_GrRecordingContext_colorTypeSupportedAsImage(context):
assert isinstance(
context.colorTypeSupportedAsImage(skia.kRGBA_8888_ColorType), bool)
@pytest.mark.parametrize('args', [
(64, 64, skia.GrBackendFormat(), skia.GrMipmapped.kNo,
skia.GrRenderable.kNo),
(64, 64, skia.ColorType.kRGBA_8888_ColorType, skia.GrMipmapped.kNo,
skia.GrRenderable.kNo),
(64, 64, skia.GrBackendFormat(), 0xFFFFFFFF, skia.GrMipmapped.kNo,
skia.GrRenderable.kNo),
(64, 64, skia.ColorType.kRGBA_8888_ColorType, 0xFFFFFFFF,
skia.GrMipmapped.kNo, skia.GrRenderable.kNo),
])
def test_GrContext_createBackendTexture(context, args, request):
backend_texture = context.createBackendTexture(*args)
assert isinstance(backend_texture, skia.GrBackendTexture)
context.deleteBackendTexture(backend_texture)
def test_GrContext_createBackendTexture_2(context, pixmap):
backend_texture = context.createBackendTexture(
[pixmap], skia.GrRenderable.kNo)
assert isinstance(backend_texture, skia.GrBackendTexture)
context.deleteBackendTexture(backend_texture)
def test_GrContext_createBackendTexture_3(context, pixmap):
backend_texture = context.createBackendTexture(
pixmap, skia.GrRenderable.kNo)
assert isinstance(backend_texture, skia.GrBackendTexture)
context.deleteBackendTexture(backend_texture)
def test_GrContext_updateBackendTexture_1(context):
backend_texture = context.createBackendTexture(
64, 64, skia.ColorType.kRGBA_8888_ColorType, 0xFFFFFFFF,
skia.GrMipmapped.kNo, skia.GrRenderable.kNo)
assert isinstance(
context.updateBackendTexture(backend_texture, skia.ColorBLACK), bool)
context.deleteBackendTexture(backend_texture)
def test_GrContext_updateBackendTexture_2(context, pixmap):
backend_texture = context.createBackendTexture(
64, 64, skia.ColorType.kRGBA_8888_ColorType, 0xFFFFFFFF,
skia.GrMipmapped.kNo, skia.GrRenderable.kNo)
assert isinstance(
context.updateBackendTexture(backend_texture, [pixmap]), bool)
context.deleteBackendTexture(backend_texture)
def test_GrContext_compressedBackendFormat(context):
assert isinstance(
context.compressedBackendFormat(skia.Image.kBC1_RGBA8_UNORM),
skia.GrBackendFormat)
@pytest.mark.parametrize('args', [
(64, 64, skia.GrBackendFormat(), 0xFFFFFFFF, skia.GrMipmapped.kNo),
(64, 64, skia.Image.kBC1_RGBA8_UNORM, 0xFFFFFFFF, skia.GrMipmapped.kNo),
(16, 16, skia.GrBackendFormat(), bytearray(256), skia.GrMipmapped.kNo),
(16, 16, skia.Image.kBC1_RGBA8_UNORM, bytearray(256), skia.GrMipmapped.kNo),
])
def test_GrContext_createCompressedBackendTexture(context, args):
backend_texture = context.createCompressedBackendTexture(*args)
assert isinstance(backend_texture, skia.GrBackendTexture)
context.deleteBackendTexture(backend_texture)
@pytest.mark.skip("Vulkan not supported")
def test_GrContext_setBackendTextureState(context, backend_texture):
state = skia.GrBackendSurfaceMutableState()
assert isinstance(
context.setBackendTextureState(backend_texture, state), bool)
@pytest.mark.skip("Vulkan not supported")
def test_GrContext_setBackendRenderTargetState(context, backend_render_target):
state = skia.GrBackendSurfaceMutableState()
assert isinstance(
context.setBackendRenderTargetState(backend_render_target, state), bool)
# def test_GrContext_deleteBackendTexture(context):
# pass
def test_GrContext_precompileShader(context):
assert isinstance(context.precompileShader(b'', b''), bool)
def test_GrContext_ComputeImageSize(image):
assert isinstance(
skia.GrContext.ComputeImageSize(image, skia.GrMipmapped.kYes),
int)
def test_GrDirectContext_MakeGL(context):
assert isinstance(context, skia.GrContext)
def test_GrDirectContext_MakeVulkan():
context = skia.GrVkBackendContext()
options = skia.GrContextOptions()
if sys.platform.startswith("darwin"):
pytest.skip("Known not to work")
assert isinstance(
skia.GrDirectContext.MakeVulkan(context),
(type(None), skia.GrDirectContext))
assert isinstance(
skia.GrDirectContext.MakeVulkan(context, options),
(type(None), skia.GrDirectContext))
def test_GrDirectContext_MakeMock():
assert isinstance(
skia.GrDirectContext.MakeMock(
skia.GrMockOptions(), skia.GrContextOptions()),
skia.GrDirectContext)
@pytest.fixture(scope='module')
def gl_texture_info():
return skia.GrGLTextureInfo()
def test_GrGLTextureInfo_init(gl_texture_info):
assert isinstance(gl_texture_info, skia.GrGLTextureInfo)
@pytest.fixture(scope='module')
def mock_texture_info():
return skia.GrMockTextureInfo()
def test_GrMockTextureInfo_init(mock_texture_info):
assert isinstance(mock_texture_info, skia.GrMockTextureInfo)
@pytest.fixture(scope='module')
def mock_render_target_info():
return skia.GrMockRenderTargetInfo()
def test_GrMockRenderTargetInfo_init(mock_render_target_info):
assert isinstance(mock_render_target_info, skia.GrMockRenderTargetInfo)
@pytest.fixture(scope='module')
def gl_framebuffer_info():
return skia.GrGLFramebufferInfo()
def test_GrGLFramebufferInfo_init(gl_framebuffer_info):
assert isinstance(gl_framebuffer_info, skia.GrGLFramebufferInfo)
def test_GrVkImageInfo_init():
# No op on "darwin", passes
assert isinstance(skia.GrVkImageInfo(), skia.GrVkImageInfo)
def test_GrVkBackendContext_init():
# No op on "darwin", passes
assert isinstance(skia.GrVkBackendContext(), skia.GrVkBackendContext)