mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
[PATCH 01/15] Bug 1043745 - Use SkColorType and SkImageInfo instead of SkBitmap::Config r=mattwoodrow
This commit is contained in:
parent
7dd2f3251a
commit
2ba75ff85d
@ -108,9 +108,15 @@ GetBitmapForSurface(SourceSurface* aSurface)
|
||||
MOZ_CRASH("Non-skia SourceSurfaces need to be DataSourceSurfaces");
|
||||
}
|
||||
|
||||
result.mBitmap.setConfig(GfxFormatToSkiaConfig(surf->GetFormat()),
|
||||
surf->GetSize().width, surf->GetSize().height,
|
||||
surf->Stride());
|
||||
SkAlphaType alphaType = (surf->GetFormat() == SurfaceFormat::B8G8R8X8) ?
|
||||
kOpaque_SkAlphaType : kPremul_SkAlphaType;
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(surf->GetSize().width,
|
||||
surf->GetSize().height,
|
||||
GfxFormatToSkiaColorType(surf->GetFormat()),
|
||||
alphaType);
|
||||
result.mBitmap.setInfo(info, surf->Stride());
|
||||
|
||||
result.mBitmap.setPixels(surf->GetData());
|
||||
result.mTmpSurface = surf.forget();
|
||||
return result;
|
||||
@ -168,8 +174,9 @@ SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, TempBitmap& aTmpBitmap
|
||||
if (shader) {
|
||||
SkMatrix mat;
|
||||
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
||||
shader->setLocalMatrix(mat);
|
||||
SkSafeUnref(aPaint.setShader(shader));
|
||||
SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
|
||||
SkSafeUnref(shader);
|
||||
SkSafeUnref(aPaint.setShader(matrixShader));
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -198,8 +205,9 @@ SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, TempBitmap& aTmpBitmap
|
||||
if (shader) {
|
||||
SkMatrix mat;
|
||||
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
||||
shader->setLocalMatrix(mat);
|
||||
SkSafeUnref(aPaint.setShader(shader));
|
||||
SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
|
||||
SkSafeUnref(shader);
|
||||
SkSafeUnref(aPaint.setShader(matrixShader));
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -216,8 +224,9 @@ SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, TempBitmap& aTmpBitmap
|
||||
SkShader* shader = SkShader::CreateBitmapShader(bitmap, mode, mode);
|
||||
SkMatrix mat;
|
||||
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
||||
shader->setLocalMatrix(mat);
|
||||
SkSafeUnref(aPaint.setShader(shader));
|
||||
SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
|
||||
SkSafeUnref(shader);
|
||||
SkSafeUnref(aPaint.setShader(matrixShader));
|
||||
if (pat.mFilter == Filter::POINT) {
|
||||
aPaint.setFilterLevel(SkPaint::kNone_FilterLevel);
|
||||
}
|
||||
@ -575,7 +584,8 @@ DrawTargetSkia::MaskSurface(const Pattern &aSource,
|
||||
|
||||
SkMatrix transform = maskPaint.getShader()->getLocalMatrix();
|
||||
transform.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
|
||||
maskPaint.getShader()->setLocalMatrix(transform);
|
||||
SkShader* matrixShader = SkShader::CreateLocalMatrixShader(maskPaint.getShader(), transform);
|
||||
maskPaint.setShader(matrixShader);
|
||||
|
||||
SkLayerRasterizer::Builder builder;
|
||||
builder.addLayer(maskPaint);
|
||||
@ -687,7 +697,7 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface,
|
||||
TempBitmap bitmap = GetBitmapForSurface(aSurface);
|
||||
|
||||
// This is a fast path that is disabled for now to mimimize risk
|
||||
if (false && !bitmap.mBitmap.getTexture() && mCanvas->getDevice()->config() == bitmap.mBitmap.config()) {
|
||||
if (false && !bitmap.mBitmap.getTexture() && mCanvas->imageInfo() == bitmap.mBitmap.info()) {
|
||||
SkBitmap bm(bitmap.mBitmap);
|
||||
bm.lockPixels();
|
||||
if (bm.getPixels()) {
|
||||
@ -709,7 +719,7 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface,
|
||||
mCanvas->clipRect(dest, SkRegion::kReplace_Op);
|
||||
SkPaint paint;
|
||||
|
||||
if (mCanvas->getDevice()->config() == SkBitmap::kRGB_565_Config) {
|
||||
if (mCanvas->imageInfo().colorType() == kRGB_565_SkColorType) {
|
||||
// Set the xfermode to SOURCE_OVER to workaround
|
||||
// http://code.google.com/p/skia/issues/detail?id=628
|
||||
// RGB565 is opaque so they're equivalent anyway
|
||||
@ -719,7 +729,7 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface,
|
||||
}
|
||||
// drawBitmapRect with A8 bitmaps ends up doing a mask operation
|
||||
// so we need to clear before
|
||||
if (bitmap.mBitmap.config() == SkBitmap::kA8_Config) {
|
||||
if (bitmap.mBitmap.colorType() == kAlpha_8_SkColorType) {
|
||||
SkPaint clearPaint;
|
||||
clearPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
|
||||
clearPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
||||
@ -809,7 +819,12 @@ DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride
|
||||
}
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride, alphaType);
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(aSize.width,
|
||||
aSize.height,
|
||||
GfxFormatToSkiaColorType(aFormat),
|
||||
alphaType);
|
||||
bitmap.setInfo(info, aStride);
|
||||
bitmap.setPixels(aData);
|
||||
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(new SkBitmapDevice(bitmap)));
|
||||
|
||||
|
@ -38,6 +38,22 @@ GfxFormatToSkiaConfig(SurfaceFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
static inline SurfaceFormat
|
||||
SkiaConfigToGfxFormat(SkBitmap::Config config)
|
||||
{
|
||||
switch (config)
|
||||
{
|
||||
case SkBitmap::kARGB_8888_Config:
|
||||
return SurfaceFormat::B8G8R8A8;
|
||||
case SkBitmap::kRGB_565_Config:
|
||||
return SurfaceFormat::R5G6B5;
|
||||
case SkBitmap::kA8_Config:
|
||||
return SurfaceFormat::A8;
|
||||
default:
|
||||
return SurfaceFormat::B8G8R8A8;
|
||||
}
|
||||
}
|
||||
|
||||
static inline SkColorType
|
||||
GfxFormatToSkiaColorType(SurfaceFormat format)
|
||||
{
|
||||
@ -58,15 +74,15 @@ GfxFormatToSkiaColorType(SurfaceFormat format)
|
||||
}
|
||||
|
||||
static inline SurfaceFormat
|
||||
SkiaConfigToGfxFormat(SkBitmap::Config config)
|
||||
SkiaColorTypeToGfxFormat(SkColorType type)
|
||||
{
|
||||
switch (config)
|
||||
switch (type)
|
||||
{
|
||||
case SkBitmap::kARGB_8888_Config:
|
||||
case kBGRA_8888_SkColorType:
|
||||
return SurfaceFormat::B8G8R8A8;
|
||||
case SkBitmap::kRGB_565_Config:
|
||||
case kRGB_565_SkColorType:
|
||||
return SurfaceFormat::R5G6B5;
|
||||
case SkBitmap::kA8_Config:
|
||||
case kAlpha_8_SkColorType:
|
||||
return SurfaceFormat::A8;
|
||||
default:
|
||||
return SurfaceFormat::B8G8R8A8;
|
||||
|
@ -25,15 +25,17 @@ bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStr
|
||||
alphaType = kOpaque_SkAlphaType;
|
||||
}
|
||||
|
||||
SkBitmap::Config config = GfxFormatToSkiaConfig(format);
|
||||
SkImageInfo info = SkImageInfo::Make(srcWidth,
|
||||
srcHeight,
|
||||
GfxFormatToSkiaColorType(format),
|
||||
alphaType);
|
||||
|
||||
SkBitmap imgSrc;
|
||||
imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType);
|
||||
imgSrc.setPixels(srcData);
|
||||
imgSrc.installPixels(info, srcData, srcStride);
|
||||
|
||||
// Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed.
|
||||
if (config != SkBitmap::kARGB_8888_Config) {
|
||||
imgSrc.copyTo(&imgSrc, kRGBA_8888_SkColorType);
|
||||
if (format != SurfaceFormat::B8G8R8A8) {
|
||||
imgSrc.copyTo(&imgSrc, kBGRA_8888_SkColorType);
|
||||
}
|
||||
|
||||
// This returns an SkBitmap backed by dstData; since it also wrote to dstData,
|
||||
|
@ -65,7 +65,14 @@ SourceSurfaceSkia::InitFromData(unsigned char* aData,
|
||||
SurfaceFormat aFormat)
|
||||
{
|
||||
SkBitmap temp;
|
||||
temp.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
|
||||
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))) {
|
||||
|
@ -408,9 +408,13 @@ SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source,
|
||||
|
||||
// Render into subpixels.
|
||||
SkBitmap result;
|
||||
result.setConfig(SkBitmap::kARGB_8888_Config, dest_subset.width(),
|
||||
dest_subset.height());
|
||||
result.allocPixels();
|
||||
SkImageInfo info = SkImageInfo::Make(dest_subset.width(),
|
||||
dest_subset.height(),
|
||||
kBGRA_8888_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
|
||||
|
||||
result.allocPixels(info);
|
||||
if (!result.readyToDraw())
|
||||
return img;
|
||||
|
||||
@ -515,13 +519,15 @@ SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source,
|
||||
|
||||
// Convolve into the result.
|
||||
SkBitmap result;
|
||||
result.setConfig(SkBitmap::kARGB_8888_Config,
|
||||
dest_subset.width(), dest_subset.height());
|
||||
SkImageInfo info = SkImageInfo::Make(dest_subset.width(),
|
||||
dest_subset.height(),
|
||||
kBGRA_8888_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
|
||||
if (dest_pixels) {
|
||||
result.setPixels(dest_pixels);
|
||||
result.installPixels(info, dest_pixels, info.minRowBytes());
|
||||
} else {
|
||||
result.allocPixels();
|
||||
result.allocPixels(info);
|
||||
}
|
||||
|
||||
if (!result.readyToDraw())
|
||||
|
@ -56,20 +56,21 @@ ANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) {
|
||||
}
|
||||
|
||||
SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) {
|
||||
SkBitmap::Config config = SkBitmap::kNo_Config;
|
||||
SkColorType colorType = kUnknown_SkColorType;
|
||||
|
||||
switch (src.format) {
|
||||
case kRGBA_8888_ANPBitmapFormat:
|
||||
config = SkBitmap::kARGB_8888_Config;
|
||||
colorType = kRGBA_8888_SkColorType;
|
||||
break;
|
||||
case kRGB_565_ANPBitmapFormat:
|
||||
config = SkBitmap::kRGB_565_Config;
|
||||
colorType = kRGB_565_SkColorType;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dst->setConfig(config, src.width, src.height, src.rowBytes);
|
||||
SkImageInfo info = SkImageInfo::Make(src.width, src.height, colorType, kPremul_SkAlphaType);
|
||||
dst->setInfo(info, src.rowBytes);
|
||||
dst->setPixels(src.baseAddr);
|
||||
return dst;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user