forked from servo/rust-azure
/
azure-c.cpp
524 lines (452 loc) · 19.4 KB
/
azure-c.cpp
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "azure-c.h"
#include "mozilla/gfx/2D.h"
#include <assert.h>
#include <string.h>
using namespace mozilla;
// Utilities
static AzIntSize IntSizeToC(gfx::IntSize src) {
AzIntSize dst;
memcpy(&dst, &src, sizeof(dst));
return dst;
}
#define CHECK_SIZE(name) assert(sizeof(Az##name) == sizeof(gfx::name))
#define CHECK_ENUM(name) assert((int)AZ_##name == (int)gfx::name)
extern "C"
void AzSanityCheck() {
CHECK_SIZE(Matrix);
CHECK_SIZE(Float);
CHECK_SIZE(Color);
CHECK_SIZE(GradientStop);
CHECK_SIZE(Rect);
CHECK_SIZE(IntRect);
CHECK_SIZE(Point);
CHECK_SIZE(IntPoint);
CHECK_SIZE(Size);
CHECK_SIZE(IntSize);
CHECK_SIZE(DrawOptions);
CHECK_SIZE(StrokeOptions);
CHECK_SIZE(DrawSurfaceOptions);
CHECK_SIZE(Glyph);
CHECK_SIZE(GlyphBuffer);
CHECK_SIZE(NativeFont);
CHECK_ENUM(SURFACE_DATA);
CHECK_ENUM(SURFACE_D2D1_BITMAP);
CHECK_ENUM(SURFACE_D2D1_DRAWTARGET);
CHECK_ENUM(SURFACE_CAIRO);
CHECK_ENUM(SURFACE_CAIRO_IMAGE);
CHECK_ENUM(SURFACE_COREGRAPHICS_IMAGE);
CHECK_ENUM(SURFACE_COREGRAPHICS_CGCONTEXT);
CHECK_ENUM(SURFACE_SKIA);
CHECK_ENUM(SURFACE_DUAL_DT);
CHECK_ENUM(FORMAT_B8G8R8A8);
CHECK_ENUM(FORMAT_B8G8R8X8);
CHECK_ENUM(FORMAT_R5G6B5);
CHECK_ENUM(FORMAT_A8);
CHECK_ENUM(BACKEND_NONE);
CHECK_ENUM(BACKEND_DIRECT2D);
CHECK_ENUM(BACKEND_COREGRAPHICS);
CHECK_ENUM(BACKEND_CAIRO);
CHECK_ENUM(BACKEND_SKIA);
CHECK_ENUM(FONT_DWRITE);
CHECK_ENUM(FONT_GDI);
CHECK_ENUM(FONT_MAC);
CHECK_ENUM(FONT_SKIA);
CHECK_ENUM(FONT_CAIRO);
CHECK_ENUM(FONT_COREGRAPHICS);
CHECK_ENUM(NATIVE_SURFACE_D3D10_TEXTURE);
CHECK_ENUM(NATIVE_SURFACE_CAIRO_SURFACE);
CHECK_ENUM(NATIVE_SURFACE_CGCONTEXT);
CHECK_ENUM(NATIVE_FONT_DWRITE_FONT_FACE);
CHECK_ENUM(NATIVE_FONT_GDI_FONT_FACE);
CHECK_ENUM(NATIVE_FONT_MAC_FONT_FACE);
CHECK_ENUM(NATIVE_FONT_SKIA_FONT_FACE);
CHECK_ENUM(NATIVE_FONT_CAIRO_FONT_FACE);
CHECK_ENUM(OP_OVER);
CHECK_ENUM(OP_ADD);
CHECK_ENUM(OP_ATOP);
CHECK_ENUM(OP_OUT);
CHECK_ENUM(OP_IN);
CHECK_ENUM(OP_SOURCE);
CHECK_ENUM(OP_DEST_IN);
CHECK_ENUM(OP_DEST_OUT);
CHECK_ENUM(OP_DEST_OVER);
CHECK_ENUM(OP_DEST_ATOP);
CHECK_ENUM(OP_XOR);
CHECK_ENUM(OP_MULTIPLY);
CHECK_ENUM(OP_SCREEN);
CHECK_ENUM(OP_OVERLAY);
/* ... */
CHECK_ENUM(OP_LUMINOSITY);
CHECK_ENUM(OP_COUNT);
CHECK_ENUM(EXTEND_CLAMP);
CHECK_ENUM(EXTEND_REPEAT);
CHECK_ENUM(EXTEND_REFLECT);
CHECK_ENUM(FILL_WINDING);
CHECK_ENUM(FILL_EVEN_ODD);
CHECK_ENUM(AA_NONE);
CHECK_ENUM(AA_GRAY);
CHECK_ENUM(AA_SUBPIXEL);
CHECK_ENUM(SNAP_NONE);
CHECK_ENUM(SNAP_ALIGNED);
CHECK_ENUM(FILTER_LINEAR);
CHECK_ENUM(FILTER_POINT);
CHECK_ENUM(PATTERN_COLOR);
CHECK_ENUM(PATTERN_SURFACE);
CHECK_ENUM(PATTERN_LINEAR_GRADIENT);
CHECK_ENUM(PATTERN_RADIAL_GRADIENT);
CHECK_ENUM(JOIN_BEVEL);
CHECK_ENUM(JOIN_ROUND);
CHECK_ENUM(JOIN_MITER);
CHECK_ENUM(JOIN_MITER_OR_BEVEL);
CHECK_ENUM(CAP_BUTT);
CHECK_ENUM(CAP_ROUND);
CHECK_ENUM(CAP_SQUARE);
CHECK_ENUM(SAMPLING_UNBOUNDED);
CHECK_ENUM(SAMPLING_BOUNDED);
assert((int)AZ_eSideTop == (int)css::eSideTop);
assert((int)AZ_eSideRight == (int)css::eSideRight);
assert((int)AZ_eSideBottom == (int)css::eSideBottom);
assert((int)AZ_eSideLeft == (int)css::eSideLeft);
}
extern "C" AzColorPatternRef
AzCreateColorPattern(AzColor *aColor) {
gfx::Color *gfxColor = reinterpret_cast<gfx::Color*>(aColor);
gfx::ColorPattern *gfxColorPattern = new gfx::ColorPattern(*gfxColor);
return gfxColorPattern;
}
extern "C" void
AzReleaseColorPattern(AzColorPatternRef aColorPattern) {
gfx::ColorPattern *gfxColorPattern = static_cast<gfx::ColorPattern*>(aColorPattern);
delete gfxColorPattern;
}
extern "C" AzSkiaSharedGLContextRef
AzCreateSkiaSharedGLContext(AzGLNativeContextRef aNativeContext, AzIntSize *aSize) {
GrGLNativeContext* nativeContext = reinterpret_cast<GrGLNativeContext*>(aNativeContext);
SkNativeSharedGLContext *sharedGLContext = new SkNativeSharedGLContext(*nativeContext);
if (sharedGLContext == NULL) {
return NULL;
}
if (!sharedGLContext->init(aSize->width, aSize->height)) {
return NULL;
}
return sharedGLContext;
}
extern "C" void
AzRetainSkiaSharedGLContext(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
sharedGLContext->AddRef();
}
extern "C" void
AzReleaseSkiaSharedGLContext(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
sharedGLContext->Release();
}
extern "C" unsigned int
AzSkiaSharedGLContextGetFBOID(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
return sharedGLContext->getFBOID();
}
extern "C" AzSkiaGrGLSharedSurfaceRef
AzSkiaSharedGLContextStealSurface(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
return reinterpret_cast<void*>(sharedGLContext->stealSurface());
}
extern "C" AzSkiaGrContextRef
AzSkiaSharedGLContextGetGrContext(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
return sharedGLContext->getGrContext();
}
extern "C" void
AzSkiaSharedGLContextMakeCurrent(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
sharedGLContext->makeCurrent();
}
extern "C" void
AzSkiaSharedGLContextFlush(AzSkiaSharedGLContextRef aGLContext) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
sharedGLContext->flush();
}
extern "C" AzDrawTargetRef
AzCreateDrawTarget(AzBackendType aBackend, AzIntSize *aSize, AzSurfaceFormat aFormat) {
gfx::BackendType backendType = static_cast<gfx::BackendType>(aBackend);
gfx::IntSize *size = reinterpret_cast<gfx::IntSize*>(aSize);
gfx::SurfaceFormat surfaceFormat = static_cast<gfx::SurfaceFormat>(aFormat);
RefPtr<gfx::DrawTarget> target = gfx::Factory::CreateDrawTarget(backendType,
*size,
surfaceFormat);
target->AddRef();
return target;
}
extern "C" AzDrawTargetRef
AzCreateDrawTargetForData(AzBackendType aBackend, unsigned char *aData, AzIntSize *aSize,
int32_t aStride, AzSurfaceFormat aFormat) {
gfx::BackendType backendType = static_cast<gfx::BackendType>(aBackend);
gfx::IntSize *size = reinterpret_cast<gfx::IntSize*>(aSize);
gfx::SurfaceFormat surfaceFormat = static_cast<gfx::SurfaceFormat>(aFormat);
RefPtr<gfx::DrawTarget> target = gfx::Factory::CreateDrawTargetForData(backendType,
aData,
*size,
aStride,
surfaceFormat);
if (target != NULL) {
target->AddRef();
}
return target;
}
extern "C" AzDrawTargetRef
AzCreateSkiaDrawTargetForFBO(AzSkiaSharedGLContextRef aGLContext, AzIntSize *aSize, AzSurfaceFormat aFormat) {
SkNativeSharedGLContext *sharedGLContext = static_cast<SkNativeSharedGLContext*>(aGLContext);
GrContext *grContext = sharedGLContext->getGrContext();
gfx::IntSize *size = reinterpret_cast<gfx::IntSize*>(aSize);
gfx::SurfaceFormat surfaceFormat = static_cast<gfx::SurfaceFormat>(aFormat);
RefPtr<gfx::DrawTarget> target = gfx::Factory::CreateSkiaDrawTargetForFBO(sharedGLContext->getFBOID(),
grContext,
*size,
surfaceFormat);
if (target != NULL) {
target->AddRef();
}
return target;
}
extern "C" void
AzRetainDrawTarget(AzDrawTargetRef aTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aTarget);
gfxDrawTarget->AddRef();
}
extern "C" void
AzReleaseDrawTarget(AzDrawTargetRef aTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aTarget);
gfxDrawTarget->Release();
}
extern "C" AzIntSize
AzDrawTargetGetSize(AzDrawTargetRef aDrawTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
return IntSizeToC(gfxDrawTarget->GetSize());
}
extern "C" void
AzDrawTargetFlush(AzDrawTargetRef aDrawTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfxDrawTarget->Flush();
}
extern "C" void
AzDrawTargetClearRect(AzDrawTargetRef aDrawTarget, AzRect *aRect) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::Rect *gfxRect = reinterpret_cast<gfx::Rect*>(aRect);
gfxDrawTarget->ClearRect(*gfxRect);
}
extern "C" void
AzDrawTargetFill(AzDrawTargetRef aDrawTarget, AzPathRef aPath,
AzPatternRef aPattern, AzDrawOptions *aDrawOptions) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::Path *gfxPath = static_cast<gfx::Path*>(aPath);
gfx::Pattern *gfxPattern = static_cast<gfx::Pattern*>(aPattern);
gfx::DrawOptions *gfxDrawOptions = reinterpret_cast<gfx::DrawOptions*>(aDrawOptions);
gfxDrawTarget->Fill(gfxPath, *gfxPattern, *gfxDrawOptions);
}
extern "C" void
AzDrawTargetPushClip(AzDrawTargetRef aDrawTarget, const AzPathRef *aPath) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
const gfx::Path *gfxPath = reinterpret_cast<const gfx::Path*>(aPath);
gfxDrawTarget->PushClip(gfxPath);
}
extern "C" void
AzDrawTargetPopClip(AzDrawTargetRef aDrawTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfxDrawTarget->PopClip();
}
extern "C" void
AzDrawTargetFillRect(AzDrawTargetRef aDrawTarget, AzRect *aRect,
AzPatternRef aPattern) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::Rect *gfxRect = reinterpret_cast<gfx::Rect*>(aRect);
gfx::Pattern *gfxPattern = static_cast<gfx::Pattern*>(aPattern);
gfxDrawTarget->FillRect(*gfxRect, *gfxPattern);
}
extern "C" void
AzDrawTargetStrokeRect(AzDrawTargetRef aDrawTarget, AzRect *aRect,
AzPatternRef aPattern, AzStrokeOptions *aStrokeOptions,
AzDrawOptions *aDrawOptions) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::Rect *gfxRect = reinterpret_cast<gfx::Rect*>(aRect);
gfx::Pattern *gfxPattern = static_cast<gfx::Pattern*>(aPattern);
gfx::StrokeOptions *gfxStrokeOptions = reinterpret_cast<gfx::StrokeOptions*>(aStrokeOptions);
gfx::DrawOptions *gfxDrawOptions = reinterpret_cast<gfx::DrawOptions*>(aDrawOptions);
gfxDrawTarget->StrokeRect(*gfxRect, *gfxPattern, *gfxStrokeOptions, *gfxDrawOptions);
}
extern "C" void
AzDrawTargetStrokeLine(AzDrawTargetRef aDrawTarget,
AzPoint *aStart, AzPoint *aEnd,
AzPatternRef aPattern,
AzStrokeOptions *aStrokeOptions,
AzDrawOptions *aDrawOptions) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::Point *gfxStart = reinterpret_cast<gfx::Point*>(aStart);
gfx::Point *gfxEnd = reinterpret_cast<gfx::Point*>(aEnd);
gfx::Pattern *gfxPattern = static_cast<gfx::Pattern*>(aPattern);
gfx::StrokeOptions *gfxStrokeOptions = reinterpret_cast<gfx::StrokeOptions*>(aStrokeOptions);
gfx::DrawOptions *gfxDrawOptions = reinterpret_cast<gfx::DrawOptions*>(aDrawOptions);
gfxDrawTarget->StrokeLine(*gfxStart, *gfxEnd, *gfxPattern, *gfxStrokeOptions, *gfxDrawOptions);
}
extern "C" void
AzDrawTargetFillGlyphs(AzDrawTargetRef aDrawTarget,
AzScaledFontRef aFont,
AzGlyphBuffer *aGlyphBuffer,
AzPatternRef aPattern,
AzDrawOptions *aOptions,
AzGlyphRenderingOptionsRef aRenderingOptions) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::ScaledFont *gfxScaledFont = static_cast<gfx::ScaledFont*>(aFont);
gfx::GlyphBuffer *gfxGlyphBuffer = reinterpret_cast<gfx::GlyphBuffer*>(aGlyphBuffer);
gfx::Pattern *gfxPattern = static_cast<gfx::Pattern*>(aPattern);
gfx::DrawOptions *gfxOptions = reinterpret_cast<gfx::DrawOptions*>(aOptions);
gfx::GlyphRenderingOptions *gfxRenderingOptions = static_cast<gfx::GlyphRenderingOptions*>(aRenderingOptions);
gfxDrawTarget->FillGlyphs(gfxScaledFont, *gfxGlyphBuffer, *gfxPattern, *gfxOptions, gfxRenderingOptions);
}
extern "C" void
AzDrawTargetDrawSurface(AzDrawTargetRef aDrawTarget,
AzSourceSurfaceRef aSurface,
AzRect *aDest,
AzRect *aSource,
AzDrawSurfaceOptionsRef aSurfOptions,
AzDrawOptions *aOptions) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::SourceSurface *gfxSourceSurface = static_cast<gfx::SourceSurface*>(aSurface);
gfx::Rect *gfxDest = reinterpret_cast<gfx::Rect*>(aDest);
gfx::Rect *gfxSource = reinterpret_cast<gfx::Rect*>(aSource);
gfx::DrawSurfaceOptions *gfxDrawSurfaceOptions = static_cast<gfx::DrawSurfaceOptions*>(aSurfOptions);
gfx::DrawOptions *gfxDrawOptions = reinterpret_cast<gfx::DrawOptions*>(aOptions);
gfxDrawTarget->DrawSurface(gfxSourceSurface, *gfxDest, *gfxSource, *gfxDrawSurfaceOptions, *gfxDrawOptions);
}
extern "C" AzSourceSurfaceRef
AzDrawTargetGetSnapshot(AzDrawTargetRef aDrawTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
RefPtr<gfx::SourceSurface> gfxSourceSurface = gfxDrawTarget->Snapshot();
gfxSourceSurface->AddRef();
return gfxSourceSurface;
}
extern "C" AzSourceSurfaceRef
AzDrawTargetCreateSourceSurfaceFromData(AzDrawTargetRef aDrawTarget,
unsigned char *aData,
AzIntSize *aSize,
int32_t aStride,
AzSurfaceFormat aFormat) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::IntSize *gfxSize = reinterpret_cast<gfx::IntSize*>(aSize);
gfx::SurfaceFormat gfxSurfaceFormat = static_cast<gfx::SurfaceFormat>(aFormat);
RefPtr<gfx::SourceSurface> gfxSourceSurface = gfxDrawTarget->CreateSourceSurfaceFromData(aData, *gfxSize, aStride, gfxSurfaceFormat);
gfxSourceSurface->AddRef();
return gfxSourceSurface;
}
extern "C" void
AzReleaseSourceSurface(AzSourceSurfaceRef aSurface) {
gfx::SourceSurface *gfxSourceSurface = static_cast<gfx::SourceSurface*>(aSurface);
gfxSourceSurface->Release();
}
extern "C" AzIntSize
AzSourceSurfaceGetSize(AzSourceSurfaceRef aSurface) {
gfx::SourceSurface *gfxSourceSurface = static_cast<gfx::SourceSurface*>(aSurface);
return IntSizeToC(gfxSourceSurface->GetSize());
}
extern "C" AzSurfaceFormat
AzSourceSurfaceGetFormat(AzSourceSurfaceRef aSurface) {
gfx::SourceSurface *gfxSourceSurface = static_cast<gfx::SourceSurface*>(aSurface);
return static_cast<AzSurfaceFormat>(gfxSourceSurface->GetFormat());
}
extern "C" AzDataSourceSurfaceRef
AzSourceSurfaceGetDataSurface(AzSourceSurfaceRef aSurface) {
gfx::SourceSurface *gfxSourceSurface = static_cast<gfx::SourceSurface*>(aSurface);
RefPtr<gfx::DataSourceSurface> gfxDataSourceSurface = gfxSourceSurface->GetDataSurface();
gfxDataSourceSurface->AddRef();
return gfxDataSourceSurface;
}
extern "C" uint8_t *AzDataSourceSurfaceGetData(AzDataSourceSurfaceRef aSurface) {
gfx::DataSourceSurface *gfxDataSourceSurface = static_cast<gfx::DataSourceSurface*>(aSurface);
return gfxDataSourceSurface->GetData();
}
extern "C" int32_t AzDataSourceSurfaceGetStride(AzDataSourceSurfaceRef aSurface) {
gfx::DataSourceSurface *gfxDataSourceSurface = static_cast<gfx::DataSourceSurface*>(aSurface);
return gfxDataSourceSurface->Stride();
}
extern "C" AzScaledFontRef
AzCreateScaledFontForNativeFont(AzNativeFont *aNativeFont, AzFloat aSize) {
gfx::NativeFont *gfxNativeFont = reinterpret_cast<gfx::NativeFont*>(aNativeFont);
RefPtr<gfx::ScaledFont> font = gfx::Factory::CreateScaledFontForNativeFont(*gfxNativeFont, aSize);
font->AddRef();
return font;
}
extern "C" void
AzReleaseScaledFont(AzScaledFontRef aFont) {
gfx::ScaledFont *gfxFont = static_cast<gfx::ScaledFont*>(aFont);
gfxFont->Release();
}
extern "C" void
AzDrawTargetSetTransform(AzDrawTargetRef aDrawTarget,
AzMatrix *aTransform) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
gfx::Matrix *gfxMatrix = reinterpret_cast<gfx::Matrix*>(aTransform);
gfxDrawTarget->SetTransform(*gfxMatrix);
}
extern "C" AzFontOptions*
AzCreateFontOptions(char *aName, AzFontStyle aStyle) {
#ifdef MOZ_ENABLE_FREETYPE
gfx::FontOptions *options = new gfx::FontOptions;
options->mName = std::string(aName);
options->mStyle = static_cast<gfx::FontStyle>(aStyle);
return options;
#else
abort();
#endif
}
extern "C" void
AzDestroyFontOptions(AzFontOptions* aOptions) {
#ifdef MOZ_ENABLE_FREETYPE
gfx::FontOptions *fontOptions = reinterpret_cast<gfx::FontOptions*>(aOptions);
delete fontOptions;
#else
abort();
#endif
}
extern "C" AzGLContext
AzSkiaGetCurrentGLContext() {
return SkNativeSharedGLContext::GetCurrent();
}
// FIXME: Needs to take a FillRule
extern "C" AzPathBuilderRef
AzCreatePathBuilder(AzDrawTargetRef aDrawTarget) {
gfx::DrawTarget *gfxDrawTarget = static_cast<gfx::DrawTarget*>(aDrawTarget);
RefPtr<gfx::PathBuilder> gfxPathBuilder = gfxDrawTarget->CreatePathBuilder();
gfxPathBuilder->AddRef();
return gfxPathBuilder;
}
extern "C" void
AzReleasePathBuilder(AzPathBuilderRef aPathBuilder) {
gfx::PathBuilder *gfxPathBuilder = static_cast<gfx::PathBuilder*>(aPathBuilder);
gfxPathBuilder->Release();
}
extern "C" void
AzPathBuilderMoveTo(AzPathBuilderRef aPathBuilder, const AzPoint *aPoint) {
gfx::PathBuilder *gfxPathBuilder = static_cast<gfx::PathBuilder*>(aPathBuilder);
const gfx::Point *gfxPoint = reinterpret_cast<const gfx::Point*>(aPoint);
gfxPathBuilder->MoveTo(*gfxPoint);
}
extern "C" void
AzPathBuilderLineTo(AzPathBuilderRef aPathBuilder, const AzPoint *aPoint) {
gfx::PathBuilder *gfxPathBuilder = static_cast<gfx::PathBuilder*>(aPathBuilder);
const gfx::Point *gfxPoint = reinterpret_cast<const gfx::Point*>(aPoint);
gfxPathBuilder->LineTo(*gfxPoint);
}
extern "C" AzPathRef
AzPathBuilderFinish(AzPathBuilderRef aPathBuilder) {
gfx::PathBuilder *gfxPathBuilder = static_cast<gfx::PathBuilder*>(aPathBuilder);
RefPtr<gfx::Path> gfxPath = gfxPathBuilder->Finish();
gfxPath->AddRef();
return gfxPath;
}
extern "C" void
AzReleasePath(AzPathRef aPath) {
gfx::Path *gfxPath = static_cast<gfx::Path*>(aPath);
gfxPath->Release();
}