bool SourceSurfaceSkia::InitFromData(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat) { SkBitmap temp; SkAlphaType alphaType = (aFormat == SurfaceFormat::B8G8R8X8) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; SkImageInfo info = SkImageInfo::Make(aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), alphaType); temp.setInfo(info, aStride); temp.setPixels(aData); if (!temp.copyTo(&mBitmap, GfxFormatToSkiaColorType(aFormat))) { return false; } if (aFormat == SurfaceFormat::B8G8R8X8) { mBitmap.setAlphaType(kIgnore_SkAlphaType); } mSize = aSize; mFormat = aFormat; mStride = mBitmap.rowBytes(); return true; }
bool SourceSurfaceSkia::InitFromTexture(DrawTargetSkia* aOwner, unsigned int aTexture, const IntSize &aSize, SurfaceFormat aFormat) { MOZ_ASSERT(aOwner, "null GrContext"); #ifdef USE_SKIA_GPU GrBackendTextureDesc skiaTexGlue; mSize.width = skiaTexGlue.fWidth = aSize.width; mSize.height = skiaTexGlue.fHeight = aSize.height; skiaTexGlue.fFlags = kNone_GrBackendTextureFlag; skiaTexGlue.fOrigin = kBottomLeft_GrSurfaceOrigin; skiaTexGlue.fConfig = GfxFormatToGrConfig(aFormat); skiaTexGlue.fSampleCnt = 0; skiaTexGlue.fTextureHandle = aTexture; GrTexture *skiaTexture = aOwner->mGrContext->wrapBackendTexture(skiaTexGlue); SkImageInfo imgInfo = SkImageInfo::Make(aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), kOpaque_SkAlphaType); SkGrPixelRef *texRef = new SkGrPixelRef(imgInfo, skiaTexture, false); mBitmap.setInfo(imgInfo); mBitmap.setPixelRef(texRef); mFormat = aFormat; mStride = mBitmap.rowBytes(); #endif mDrawTarget = aOwner; return true; }
bool DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat) { SkAlphaType alphaType = (aFormat == SurfaceFormat::B8G8R8X8) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; SkImageInfo skiInfo = SkImageInfo::Make( aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), alphaType); SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(skiInfo)); if (!device) { return false; } SkBitmap bitmap = device->accessBitmap(true); if (!bitmap.allocPixels()) { return false; } bitmap.eraseARGB(0, 0, 0, 0); SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get())); mSize = aSize; mCanvas = canvas.get(); mFormat = aFormat; return true; }
void DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat) { SkAlphaType alphaType = kPremul_SkAlphaType; if (aFormat == SurfaceFormat::B8G8R8X8) { // We have to manually set the A channel to be 255 as Skia doesn't understand BGRX ConvertBGRXToBGRA(aData, aSize, aStride); alphaType = kOpaque_SkAlphaType; } SkBitmap bitmap; SkImageInfo info = SkImageInfo::Make(aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), alphaType); bitmap.setInfo(info, aStride); bitmap.setPixels(aData); mCanvas.adopt(new SkCanvas(new SkBitmapDevice(bitmap))); mSize = aSize; mFormat = aFormat; }
bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride, uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride, SurfaceFormat format) { #ifdef USE_SKIA SkAlphaType alphaType; if (format == SurfaceFormat::B8G8R8A8) { alphaType = kPremul_SkAlphaType; } else { alphaType = kOpaque_SkAlphaType; } SkImageInfo info = SkImageInfo::Make(srcWidth, srcHeight, GfxFormatToSkiaColorType(format), alphaType); SkBitmap imgSrc; imgSrc.installPixels(info, srcData, srcStride); // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed. if (format != SurfaceFormat::B8G8R8A8) { imgSrc.copyTo(&imgSrc, kBGRA_8888_SkColorType); } // This returns an SkBitmap backed by dstData; since it also wrote to dstData, // we don't need to look at that SkBitmap. SkBitmap result = skia::ImageOperations::Resize(imgSrc, skia::ImageOperations::RESIZE_BEST, dstWidth, dstHeight, dstData); return !result.isNull(); #else return false; #endif }