-
Notifications
You must be signed in to change notification settings - Fork 1
/
Factory.cpp
812 lines (687 loc) · 18.8 KB
/
Factory.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
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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 "2D.h"
#ifdef USE_CAIRO
#include "DrawTargetCairo.h"
#include "ScaledFontCairo.h"
#endif
#ifdef USE_SKIA
#include "DrawTargetSkia.h"
#include "ScaledFontBase.h"
#if defined(MOZ_ENABLE_FREETYPE) && defined(USE_CAIRO)
#define USE_SKIA_FREETYPE
#include "ScaledFontCairo.h"
#endif
#endif
#if defined(WIN32)
#include "ScaledFontWin.h"
#endif
#ifdef XP_MACOSX
#include "ScaledFontMac.h"
#endif
#ifdef XP_MACOSX
#include "DrawTargetCG.h"
#endif
#ifdef WIN32
#include "DrawTargetD2D.h"
#ifdef USE_D2D1_1
#include "DrawTargetD2D1.h"
#endif
#include "ScaledFontDWrite.h"
#include <d3d10_1.h>
#include "HelpersD2D.h"
#endif
#include "DrawTargetDual.h"
#include "DrawTargetTiled.h"
#include "DrawTargetRecording.h"
#include "SourceSurfaceRawData.h"
#include "DrawEventRecorder.h"
#include "Logging.h"
#include "mozilla/CheckedInt.h"
#if defined(DEBUG) || defined(PR_LOGGING)
PRLogModuleInfo *
GetGFX2DLog()
{
static PRLogModuleInfo *sLog;
if (!sLog)
sLog = PR_NewLogModule("gfx2d");
return sLog;
}
#endif
// The following code was largely taken from xpcom/glue/SSE.cpp and
// made a little simpler.
enum CPUIDRegister { eax = 0, ebx = 1, ecx = 2, edx = 3 };
#ifdef HAVE_CPUID_H
// cpuid.h is available on gcc 4.3 and higher on i386 and x86_64
#include <cpuid.h>
static inline bool
HasCPUIDBit(unsigned int level, CPUIDRegister reg, unsigned int bit)
{
unsigned int regs[4];
return __get_cpuid(level, ®s[0], ®s[1], ®s[2], ®s[3]) &&
(regs[reg] & bit);
}
#define HAVE_CPU_DETECTION
#else
#if defined(_MSC_VER) && _MSC_VER >= 1600 && (defined(_M_IX86) || defined(_M_AMD64))
// MSVC 2005 or later supports __cpuid by intrin.h
// But it does't work on MSVC 2005 with SDK 7.1 (Bug 753772)
#include <intrin.h>
#define HAVE_CPU_DETECTION
#elif defined(__SUNPRO_CC) && (defined(__i386) || defined(__x86_64__))
// Define a function identical to MSVC function.
#ifdef __i386
static void
__cpuid(int CPUInfo[4], int InfoType)
{
asm (
"xchg %esi, %ebx\n"
"cpuid\n"
"movl %eax, (%edi)\n"
"movl %ebx, 4(%edi)\n"
"movl %ecx, 8(%edi)\n"
"movl %edx, 12(%edi)\n"
"xchg %esi, %ebx\n"
:
: "a"(InfoType), // %eax
"D"(CPUInfo) // %edi
: "%ecx", "%edx", "%esi"
);
}
#else
static void
__cpuid(int CPUInfo[4], int InfoType)
{
asm (
"xchg %rsi, %rbx\n"
"cpuid\n"
"movl %eax, (%rdi)\n"
"movl %ebx, 4(%rdi)\n"
"movl %ecx, 8(%rdi)\n"
"movl %edx, 12(%rdi)\n"
"xchg %rsi, %rbx\n"
:
: "a"(InfoType), // %eax
"D"(CPUInfo) // %rdi
: "%ecx", "%edx", "%rsi"
);
}
#define HAVE_CPU_DETECTION
#endif
#endif
#ifdef HAVE_CPU_DETECTION
static inline bool
HasCPUIDBit(unsigned int level, CPUIDRegister reg, unsigned int bit)
{
// Check that the level in question is supported.
volatile int regs[4];
__cpuid((int *)regs, level & 0x80000000u);
if (unsigned(regs[0]) < level)
return false;
__cpuid((int *)regs, level);
return !!(unsigned(regs[reg]) & bit);
}
#endif
#endif
namespace mozilla {
namespace gfx {
// XXX - Need to define an API to set this.
GFX2D_API int sGfxLogLevel = LOG_DEBUG;
#ifdef WIN32
ID3D10Device1 *Factory::mD3D10Device;
#ifdef USE_D2D1_1
ID3D11Device *Factory::mD3D11Device;
ID2D1Device *Factory::mD2D1Device;
#endif
#endif
#ifdef MOZ_ENABLE_FREETYPE
FT_Library Factory::mFreetypeLibrary = nullptr;
#endif
DrawEventRecorder *Factory::mRecorder;
bool
Factory::HasSSE2()
{
#if defined(__SSE2__) || defined(_M_X64) || \
(defined(_M_IX86_FP) && _M_IX86_FP >= 2)
// gcc with -msse2 (default on OSX and x86-64)
// cl.exe with -arch:SSE2 (default on x64 compiler)
return true;
#elif defined(HAVE_CPU_DETECTION)
static enum {
UNINITIALIZED,
NO_SSE2,
HAS_SSE2
} sDetectionState = UNINITIALIZED;
if (sDetectionState == UNINITIALIZED) {
sDetectionState = HasCPUIDBit(1u, edx, (1u<<26)) ? HAS_SSE2 : NO_SSE2;
}
return sDetectionState == HAS_SSE2;
#else
return false;
#endif
}
bool
Factory::CheckSurfaceSize(const IntSize &sz, int32_t limit)
{
if (sz.width < 0 || sz.height < 0) {
gfxDebug() << "Surface width or height < 0!";
return false;
}
// reject images with sides bigger than limit
if (limit && (sz.width > limit || sz.height > limit)) {
gfxDebug() << "Surface size too large (exceeds caller's limit)!";
return false;
}
// make sure the surface area doesn't overflow a int32_t
CheckedInt<int32_t> tmp = sz.width;
tmp *= sz.height;
if (!tmp.isValid()) {
gfxDebug() << "Surface size too large (would overflow)!";
return false;
}
// assuming 4 bytes per pixel, make sure the allocation size
// doesn't overflow a int32_t either
CheckedInt<int32_t> stride = sz.width;
stride *= 4;
// When aligning the stride to 16 bytes, it can grow by up to 15 bytes.
stride += 16 - 1;
if (!stride.isValid()) {
gfxDebug() << "Surface size too large (stride overflows int32_t)!";
return false;
}
CheckedInt<int32_t> numBytes = GetAlignedStride<16>(sz.width * 4);
numBytes *= sz.height;
if (!numBytes.isValid()) {
gfxDebug() << "Surface size too large (allocation size would overflow int32_t)!";
return false;
}
return true;
}
TemporaryRef<DrawTarget>
Factory::CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat)
{
if (!CheckSurfaceSize(aSize)) {
return nullptr;
}
RefPtr<DrawTarget> retVal;
switch (aBackend) {
#ifdef WIN32
case BackendType::DIRECT2D:
{
RefPtr<DrawTargetD2D> newTarget;
newTarget = new DrawTargetD2D();
if (newTarget->Init(aSize, aFormat)) {
retVal = newTarget;
}
break;
}
#ifdef USE_D2D1_1
case BackendType::DIRECT2D1_1:
{
RefPtr<DrawTargetD2D1> newTarget;
newTarget = new DrawTargetD2D1();
if (newTarget->Init(aSize, aFormat)) {
retVal = newTarget;
}
break;
}
#endif
#elif defined XP_MACOSX
case BackendType::COREGRAPHICS:
case BackendType::COREGRAPHICS_ACCELERATED:
{
RefPtr<DrawTargetCG> newTarget;
newTarget = new DrawTargetCG();
if (newTarget->Init(aBackend, aSize, aFormat)) {
retVal = newTarget;
}
break;
}
#endif
#ifdef USE_SKIA
case BackendType::SKIA:
{
RefPtr<DrawTargetSkia> newTarget;
newTarget = new DrawTargetSkia();
if (newTarget->Init(aSize, aFormat)) {
retVal = newTarget;
}
break;
}
#endif
#ifdef USE_CAIRO
case BackendType::CAIRO:
{
RefPtr<DrawTargetCairo> newTarget;
newTarget = new DrawTargetCairo();
if (newTarget->Init(aSize, aFormat)) {
retVal = newTarget;
}
break;
}
#endif
default:
gfxDebug() << "Invalid draw target type specified.";
return nullptr;
}
if (mRecorder && retVal) {
return new DrawTargetRecording(mRecorder, retVal);
}
if (!retVal) {
// Failed
gfxDebug() << "Failed to create DrawTarget, Type: " << int(aBackend) << " Size: " << aSize;
}
return retVal.forget();
}
TemporaryRef<DrawTarget>
Factory::CreateRecordingDrawTarget(DrawEventRecorder *aRecorder, DrawTarget *aDT)
{
return new DrawTargetRecording(aRecorder, aDT);
}
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetForData(BackendType aBackend,
unsigned char *aData,
const IntSize &aSize,
int32_t aStride,
SurfaceFormat aFormat)
{
if (!CheckSurfaceSize(aSize)) {
return nullptr;
}
RefPtr<DrawTarget> retVal;
switch (aBackend) {
#ifdef USE_SKIA
case BackendType::SKIA:
{
RefPtr<DrawTargetSkia> newTarget;
newTarget = new DrawTargetSkia();
newTarget->Init(aData, aSize, aStride, aFormat);
retVal = newTarget;
break;
}
#endif
#ifdef XP_MACOSX
case BackendType::COREGRAPHICS:
{
RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
if (newTarget->Init(aBackend, aData, aSize, aStride, aFormat))
return newTarget.forget();
break;
}
#endif
#ifdef USE_CAIRO
case BackendType::CAIRO:
{
RefPtr<DrawTargetCairo> newTarget;
newTarget = new DrawTargetCairo();
if (newTarget->Init(aData, aSize, aStride, aFormat)) {
retVal = newTarget.forget();
}
break;
}
#endif
default:
gfxDebug() << "Invalid draw target type specified.";
return nullptr;
}
if (mRecorder && retVal) {
return new DrawTargetRecording(mRecorder, retVal, true);
}
if (!retVal) {
gfxDebug() << "Failed to create DrawTarget, Type: " << int(aBackend) << " Size: " << aSize;
}
return retVal.forget();
}
TemporaryRef<DrawTarget>
Factory::CreateTiledDrawTarget(const TileSet& aTileSet)
{
RefPtr<DrawTargetTiled> dt = new DrawTargetTiled();
if (!dt->Init(aTileSet)) {
return nullptr;
}
return dt.forget();
}
TemporaryRef<ScaledFont>
Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize)
{
switch (aNativeFont.mType) {
#ifdef WIN32
case NativeFontType::DWRITE_FONT_FACE:
{
return new ScaledFontDWrite(static_cast<IDWriteFontFace*>(aNativeFont.mFont), aSize);
}
#if defined(USE_CAIRO) || defined(USE_SKIA)
case NativeFontType::GDI_FONT_FACE:
{
return new ScaledFontWin(static_cast<LOGFONT*>(aNativeFont.mFont), aSize);
}
#endif
#endif
#ifdef XP_MACOSX
case NativeFontType::MAC_FONT_FACE:
{
return new ScaledFontMac(static_cast<CGFontRef>(aNativeFont.mFont), aSize);
}
#endif
#if defined(USE_CAIRO) || defined(USE_SKIA_FREETYPE)
case NativeFontType::CAIRO_FONT_FACE:
{
return new ScaledFontCairo(static_cast<cairo_scaled_font_t*>(aNativeFont.mFont), aSize);
}
#endif
default:
gfxWarning() << "Invalid native font type specified.";
return nullptr;
}
}
TemporaryRef<ScaledFont>
Factory::CreateScaledFontForTrueTypeData(uint8_t *aData, uint32_t aSize,
uint32_t aFaceIndex, Float aGlyphSize,
FontType aType)
{
switch (aType) {
#ifdef WIN32
case FontType::DWRITE:
{
return new ScaledFontDWrite(aData, aSize, aFaceIndex, aGlyphSize);
}
#endif
default:
gfxWarning() << "Unable to create requested font type from truetype data";
return nullptr;
}
}
TemporaryRef<ScaledFont>
Factory::CreateScaledFontWithCairo(const NativeFont& aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont)
{
#ifdef USE_CAIRO
// In theory, we could pull the NativeFont out of the cairo_scaled_font_t*,
// but that would require a lot of code that would be otherwise repeated in
// various backends.
// Therefore, we just reuse CreateScaledFontForNativeFont's implementation.
RefPtr<ScaledFont> font = CreateScaledFontForNativeFont(aNativeFont, aSize);
static_cast<ScaledFontBase*>(font.get())->SetCairoScaledFont(aScaledFont);
return font.forget();
#else
return nullptr;
#endif
}
TemporaryRef<DrawTarget>
Factory::CreateDualDrawTarget(DrawTarget *targetA, DrawTarget *targetB)
{
RefPtr<DrawTarget> newTarget =
new DrawTargetDual(targetA, targetB);
RefPtr<DrawTarget> retVal = newTarget;
if (mRecorder) {
retVal = new DrawTargetRecording(mRecorder, retVal);
}
return retVal.forget();
}
#ifdef MOZ_ENABLE_FREETYPE
FT_Library
Factory::GetFreetypeLibrary()
{
if (!mFreetypeLibrary) {
FT_Init_FreeType(&mFreetypeLibrary);
}
return mFreetypeLibrary;
}
#endif
#ifdef WIN32
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat)
{
RefPtr<DrawTargetD2D> newTarget;
newTarget = new DrawTargetD2D();
if (newTarget->Init(aTexture, aFormat)) {
RefPtr<DrawTarget> retVal = newTarget;
if (mRecorder) {
retVal = new DrawTargetRecording(mRecorder, retVal, true);
}
return retVal.forget();
}
gfxWarning() << "Failed to create draw target for D3D10 texture.";
// Failed
return nullptr;
}
TemporaryRef<DrawTarget>
Factory::CreateDualDrawTargetForD3D10Textures(ID3D10Texture2D *aTextureA,
ID3D10Texture2D *aTextureB,
SurfaceFormat aFormat)
{
RefPtr<DrawTargetD2D> newTargetA;
RefPtr<DrawTargetD2D> newTargetB;
newTargetA = new DrawTargetD2D();
if (!newTargetA->Init(aTextureA, aFormat)) {
gfxWarning() << "Failed to create draw target for D3D10 texture.";
return nullptr;
}
newTargetB = new DrawTargetD2D();
if (!newTargetB->Init(aTextureB, aFormat)) {
gfxWarning() << "Failed to create draw target for D3D10 texture.";
return nullptr;
}
RefPtr<DrawTarget> newTarget =
new DrawTargetDual(newTargetA, newTargetB);
RefPtr<DrawTarget> retVal = newTarget;
if (mRecorder) {
retVal = new DrawTargetRecording(mRecorder, retVal);
}
return retVal.forget();
}
void
Factory::SetDirect3D10Device(ID3D10Device1 *aDevice)
{
// do not throw on failure; return error codes and disconnect the device
// On Windows 8 error codes are the default, but on Windows 7 the
// default is to throw (or perhaps only with some drivers?)
aDevice->SetExceptionMode(0);
mD3D10Device = aDevice;
}
ID3D10Device1*
Factory::GetDirect3D10Device()
{
#ifdef DEBUG
UINT mode = mD3D10Device->GetExceptionMode();
MOZ_ASSERT(0 == mode);
#endif
return mD3D10Device;
}
#ifdef USE_D2D1_1
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat)
{
RefPtr<DrawTargetD2D1> newTarget;
newTarget = new DrawTargetD2D1();
if (newTarget->Init(aTexture, aFormat)) {
RefPtr<DrawTarget> retVal = newTarget;
if (mRecorder) {
retVal = new DrawTargetRecording(mRecorder, retVal, true);
}
return retVal;
}
gfxWarning() << "Failed to create draw target for D3D10 texture.";
// Failed
return nullptr;
}
void
Factory::SetDirect3D11Device(ID3D11Device *aDevice)
{
mD3D11Device = aDevice;
RefPtr<ID2D1Factory1> factory = D2DFactory1();
RefPtr<IDXGIDevice> device;
aDevice->QueryInterface((IDXGIDevice**)byRef(device));
factory->CreateDevice(device, &mD2D1Device);
}
ID3D11Device*
Factory::GetDirect3D11Device()
{
return mD3D11Device;
}
ID2D1Device*
Factory::GetD2D1Device()
{
return mD2D1Device;
}
bool
Factory::SupportsD2D1()
{
return !!D2DFactory1();
}
#endif
TemporaryRef<GlyphRenderingOptions>
Factory::CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams)
{
return new GlyphRenderingOptionsDWrite(aParams);
}
uint64_t
Factory::GetD2DVRAMUsageDrawTarget()
{
return DrawTargetD2D::mVRAMUsageDT;
}
uint64_t
Factory::GetD2DVRAMUsageSourceSurface()
{
return DrawTargetD2D::mVRAMUsageSS;
}
void
Factory::D2DCleanup()
{
DrawTargetD2D::CleanupD2D();
}
#endif // XP_WIN
#ifdef USE_SKIA_GPU
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetSkiaWithGrContext(GrContext* aGrContext,
const IntSize &aSize,
SurfaceFormat aFormat)
{
RefPtr<DrawTarget> newTarget = new DrawTargetSkia();
if (!newTarget->InitWithGrContext(aGrContext, aSize, aFormat)) {
return nullptr;
}
return newTarget.forget();
}
#endif // USE_SKIA_GPU
void
Factory::PurgeTextureCaches()
{
}
#ifdef USE_SKIA_FREETYPE
TemporaryRef<GlyphRenderingOptions>
Factory::CreateCairoGlyphRenderingOptions(FontHinting aHinting, bool aAutoHinting)
{
RefPtr<GlyphRenderingOptionsCairo> options =
new GlyphRenderingOptionsCairo();
options->SetHinting(aHinting);
options->SetAutoHinting(aAutoHinting);
return options.forget();
}
#endif
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat)
{
RefPtr<DrawTarget> retVal;
#ifdef USE_CAIRO
RefPtr<DrawTargetCairo> newTarget = new DrawTargetCairo();
if (newTarget->Init(aSurface, aSize, aFormat)) {
retVal = newTarget;
}
if (mRecorder && retVal) {
RefPtr<DrawTarget> recordDT = new DrawTargetRecording(mRecorder, retVal, true);
return recordDT.forget();
}
#endif
return retVal.forget();
}
#ifdef XP_MACOSX
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetForCairoCGContext(CGContextRef cg, const IntSize& aSize)
{
RefPtr<DrawTarget> retVal;
RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
if (newTarget->Init(cg, aSize)) {
retVal = newTarget;
}
if (mRecorder && retVal) {
return new DrawTargetRecording(mRecorder, retVal);
}
return retVal.forget();
}
#endif
TemporaryRef<DataSourceSurface>
Factory::CreateWrappingDataSourceSurface(uint8_t *aData, int32_t aStride,
const IntSize &aSize,
SurfaceFormat aFormat)
{
if (aSize.width <= 0 || aSize.height <= 0) {
return nullptr;
}
RefPtr<SourceSurfaceRawData> newSurf = new SourceSurfaceRawData();
if (newSurf->InitWrappingData(aData, aSize, aStride, aFormat, false)) {
return newSurf.forget();
}
return nullptr;
}
TemporaryRef<DataSourceSurface>
Factory::CreateDataSourceSurface(const IntSize &aSize,
SurfaceFormat aFormat,
bool aZero)
{
if (!CheckSurfaceSize(aSize)) {
gfxWarning() << "CreateDataSourceSurface failed with bad size";
return nullptr;
}
RefPtr<SourceSurfaceAlignedRawData> newSurf = new SourceSurfaceAlignedRawData();
if (newSurf->Init(aSize, aFormat, aZero)) {
return newSurf.forget();
}
gfxWarning() << "CreateDataSourceSurface failed in init";
return nullptr;
}
TemporaryRef<DataSourceSurface>
Factory::CreateDataSourceSurfaceWithStride(const IntSize &aSize,
SurfaceFormat aFormat,
int32_t aStride,
bool aZero)
{
if (aStride < aSize.width * BytesPerPixel(aFormat)) {
gfxWarning() << "CreateDataSourceSurfaceWithStride failed with bad stride";
return nullptr;
}
RefPtr<SourceSurfaceAlignedRawData> newSurf = new SourceSurfaceAlignedRawData();
if (newSurf->InitWithStride(aSize, aFormat, aStride, aZero)) {
return newSurf.forget();
}
gfxWarning() << "CreateDataSourceSurfaceWithStride failed to initialize";
return nullptr;
}
TemporaryRef<DrawEventRecorder>
Factory::CreateEventRecorderForFile(const char *aFilename)
{
return new DrawEventRecorderFile(aFilename);
}
void
Factory::SetGlobalEventRecorder(DrawEventRecorder *aRecorder)
{
mRecorder = aRecorder;
}
LogForwarder* Factory::mLogForwarder = nullptr;
// static
void
Factory::SetLogForwarder(LogForwarder* aLogFwd) {
mLogForwarder = aLogFwd;
}
// static
void
CriticalLogger::OutputMessage(const std::string &aString, int aLevel)
{
if (Factory::GetLogForwarder()) {
Factory::GetLogForwarder()->Log(aString);
}
BasicLogger::OutputMessage(aString, aLevel);
}
}
}