Bug 998042 - 4-byte align Skia surfaces to interoperate with Cairo r=jrmuizel

This commit is contained in:
Lee Salzman 2015-10-08 12:16:46 -04:00
parent e5a53c61f3
commit dd33849286

View File

@ -837,20 +837,18 @@ DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
aSize.width, aSize.height, aSize.width, aSize.height,
GfxFormatToSkiaColorType(aFormat), GfxFormatToSkiaColorType(aFormat),
alphaType); alphaType);
// we need to have surfaces that have a stride aligned to 4 for interop with cairo
int stride = (BytesPerPixel(aFormat)*aSize.width + (4-1)) & -4;
SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(skiInfo)); SkBitmap bitmap;
if (!device) { bitmap.setInfo(skiInfo, stride);
return false;
}
SkBitmap bitmap = device->accessBitmap(true);
if (!bitmap.allocPixels()) { if (!bitmap.allocPixels()) {
return false; return false;
} }
bitmap.eraseARGB(0, 0, 0, 0); bitmap.eraseARGB(0, 0, 0, 0);
mCanvas.adopt(new SkCanvas(device.get())); mCanvas.adopt(new SkCanvas(bitmap));
mSize = aSize; mSize = aSize;
mFormat = aFormat; mFormat = aFormat;