Bug 898803. Add support for different surface formats to DrawTargetCG. r=joe

This causes us to get cleartype when drawing with alpha with CG.

--HG--
extra : rebase_source : 611c5b76ce0ea926ea8e1e26501ca3d8d9a6b452
This commit is contained in:
Jeff Muizelaar 2013-07-29 15:01:29 -04:00
Родитель ae8f359c4b
Коммит 6db2981894
1 изменённых файлов: 21 добавлений и 5 удалений

Просмотреть файл

@ -1199,12 +1199,27 @@ DrawTargetCG::Init(BackendType aType,
mData = nullptr;
}
mFormat = FORMAT_B8G8R8A8;
if (!mCg || aType == BACKEND_COREGRAPHICS) {
int bitsPerComponent = 8;
CGBitmapInfo bitinfo;
bitinfo = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst;
if (aFormat == FORMAT_A8) {
if (mColorSpace)
CGColorSpaceRelease(mColorSpace);
mColorSpace = nullptr;
bitinfo = kCGImageAlphaOnly;
mFormat = FORMAT_A8;
} else {
bitinfo = kCGBitmapByteOrder32Host;
if (aFormat == FORMAT_B8G8R8X8) {
bitinfo |= kCGImageAlphaNoneSkipFirst;
mFormat = aFormat;
} else {
bitinfo |= kCGImageAlphaPremultipliedFirst;
}
}
// XXX: what should we do if this fails?
mCg = CGBitmapContextCreate (aData,
mSize.width,
@ -1229,8 +1244,6 @@ DrawTargetCG::Init(BackendType aType,
// use the default for content.
CGContextSetInterpolationQuality(mCg, kCGInterpolationLow);
// XXX: set correct format
mFormat = FORMAT_B8G8R8A8;
if (aType == BACKEND_COREGRAPHICS_ACCELERATED) {
// The bitmap backend uses callac to clear, we can't do that without
@ -1285,9 +1298,12 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize)
mFormat = FORMAT_B8G8R8A8;
if (GetContextType(mCg) == CG_CONTEXT_TYPE_BITMAP) {
CGColorSpaceRef colorspace;
CGBitmapInfo bitinfo = CGBitmapContextGetBitmapInfo(mCg);
colorspace = CGBitmapContextGetColorSpace (mCg);
if (CGColorSpaceGetNumberOfComponents(colorspace) == 1) {
mFormat = FORMAT_A8;
mFormat = FORMAT_A8;
} else if ((bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst) {
mFormat = FORMAT_B8G8R8X8;
}
}