[PATCH 01/15] Bug 1043745 - Use SkColorType and SkImageInfo instead of SkBitmap::Config r=mattwoodrow
authorGeorge Wright <george@mozilla.com>
Sun, 27 Jul 2014 20:47:43 -0400
changeset 199132 6f6e5610d6a82f3155a27ff426d9d256b5f81eb6
parent 199131 50282184d46b74598021121b4ce11d5bd599c1d3
child 199133 8634d683261898aaf058d9989b09ef19ebbcf251
push id27298
push userryanvm@gmail.com
push dateTue, 12 Aug 2014 20:25:16 +0000
treeherdermozilla-central@7fc96293ada8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1043745
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
[PATCH 01/15] Bug 1043745 - Use SkColorType and SkImageInfo instead of SkBitmap::Config r=mattwoodrow
gfx/2d/DrawTargetSkia.cpp
gfx/2d/HelpersSkia.h
gfx/2d/Scale.cpp
gfx/2d/SourceSurfaceSkia.cpp
gfx/2d/image_operations.cpp
other-licenses/skia-npapi/SkANP.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -103,19 +103,25 @@ GetBitmapForSurface(SourceSurface* aSurf
     return result;
   }
 
   RefPtr<DataSourceSurface> surf = aSurface->GetDataSurface();
   if (!surf) {
     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;
 }
 
 DrawTargetSkia::DrawTargetSkia()
   : mTexture(0), mSnapshot(nullptr)
 {
@@ -163,18 +169,19 @@ SetPaintPattern(SkPaint& aPaint, const P
                                                           &stops->mColors.front(), 
                                                           &stops->mPositions.front(), 
                                                           stops->mCount, 
                                                           mode);
 
         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 {
         aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
       }
       break;
     }
     case PatternType::RADIAL_GRADIENT: {
@@ -193,36 +200,38 @@ SetPaintPattern(SkPaint& aPaint, const P
                                                                    SkFloatToScalar(pat.mRadius2),
                                                                    &stops->mColors.front(), 
                                                                    &stops->mPositions.front(), 
                                                                    stops->mCount, 
                                                                    mode);
         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 {
         aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
       }
       break;
     }
     case PatternType::SURFACE: {
       const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
       aTmpBitmap = GetBitmapForSurface(pat.mSurface);
       const SkBitmap& bitmap = aTmpBitmap.mBitmap;
 
       SkShader::TileMode mode = ExtendModeToTileMode(pat.mExtendMode);
       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);
       }
       break;
     }
   }
 }
 
@@ -570,17 +579,18 @@ DrawTargetSkia::MaskSurface(const Patter
     mCanvas->drawBitmap(bitmap.mBitmap, aOffset.x, aOffset.y, &paint.mPaint);
   } else {
     SkPaint maskPaint;
     TempBitmap tmpBitmap;
     SetPaintPattern(maskPaint, SurfacePattern(aMask, ExtendMode::CLAMP), tmpBitmap);
 
     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);
     SkAutoTUnref<SkRasterizer> raster(builder.detachRasterizer());
     paint.mPaint.setRasterizer(raster.get());
 
     IntSize size = aMask->GetSize();
     Rect rect = Rect(aOffset.x, aOffset.y, size.width, size.height);
@@ -682,17 +692,17 @@ DrawTargetSkia::CopySurface(SourceSurfac
     return;
   }
 
   MarkChanged();
 
   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()) {
 	  SkImageInfo info = bm.info();
 	  info.fWidth = aSourceRect.width;
 	  info.fHeight = aSourceRect.height;
 	  uint8_t* pixels = static_cast<uint8_t*>(bm.getPixels());
 	  // adjust pixels for the source offset
@@ -704,27 +714,27 @@ DrawTargetSkia::CopySurface(SourceSurfac
 
   mCanvas->save();
   mCanvas->resetMatrix();
   SkRect dest = IntRectToSkRect(IntRect(aDestination.x, aDestination.y, aSourceRect.width, aSourceRect.height)); 
   SkIRect source = IntRectToSkIRect(aSourceRect);
   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
     paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
   } else {
     paint.setXfermodeMode(SkXfermode::kSrc_Mode);
   }
   // 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);
     mCanvas->drawPaint(clearPaint);
   }
   mCanvas->drawBitmapRect(bitmap.mBitmap, &source, dest, &paint);
   mCanvas->restore();
 }
@@ -804,17 +814,22 @@ DrawTargetSkia::Init(unsigned char* aDat
   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;
-  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)));
 
   mSize = aSize;
   mCanvas = canvas.get();
   mFormat = aFormat;
 }
 
--- a/gfx/2d/HelpersSkia.h
+++ b/gfx/2d/HelpersSkia.h
@@ -33,16 +33,32 @@ GfxFormatToSkiaConfig(SurfaceFormat form
       return SkBitmap::kRGB_565_Config;
     case SurfaceFormat::A8:
       return SkBitmap::kA8_Config;
     default:
       return SkBitmap::kARGB_8888_Config;
   }
 }
 
+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)
 {
   switch (format)
   {
     case SurfaceFormat::B8G8R8A8:
       return kBGRA_8888_SkColorType;
     case SurfaceFormat::B8G8R8X8:
@@ -53,25 +69,25 @@ GfxFormatToSkiaColorType(SurfaceFormat f
     case SurfaceFormat::A8:
       return kAlpha_8_SkColorType;
     default:
       return kRGBA_8888_SkColorType;
   }
 }
 
 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;
   }
 }
 
 #ifdef USE_SKIA_GPU
 static inline GrPixelConfig
--- a/gfx/2d/Scale.cpp
+++ b/gfx/2d/Scale.cpp
@@ -20,25 +20,27 @@ bool Scale(uint8_t* srcData, int32_t src
 #ifdef USE_SKIA
   SkAlphaType alphaType;
   if (format == SurfaceFormat::B8G8R8A8) {
     alphaType = kPremul_SkAlphaType;
   } else {
     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,
   // we don't need to look at that SkBitmap.
   SkBitmap result = skia::ImageOperations::Resize(imgSrc,
                                                   skia::ImageOperations::RESIZE_BEST,
                                                   dstWidth, dstHeight,
                                                   dstData);
--- a/gfx/2d/SourceSurfaceSkia.cpp
+++ b/gfx/2d/SourceSurfaceSkia.cpp
@@ -60,17 +60,24 @@ SourceSurfaceSkia::InitFromCanvas(SkCanv
 
 bool 
 SourceSurfaceSkia::InitFromData(unsigned char* aData,
                                 const IntSize &aSize,
                                 int32_t aStride,
                                 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))) {
     return false;
   }
 
   if (aFormat == SurfaceFormat::B8G8R8X8) {
     mBitmap.setAlphaType(kIgnore_SkAlphaType);
--- a/gfx/2d/image_operations.cpp
+++ b/gfx/2d/image_operations.cpp
@@ -403,19 +403,23 @@ SkBitmap ImageOperations::ResizeSubpixel
   SkBitmap img = ResizeBasic(source, ImageOperations::RESIZE_LANCZOS3, width,
                              height, subset);
   const int row_words = img.rowBytes() / 4;
   if (w == 1 && h == 1)
     return img;
 
   // 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;
 
   SkAutoLockPixels locker(img);
   if (!img.readyToDraw())
     return img;
 
   uint32_t* src_row = img.getAddr32(0, 0);
@@ -510,23 +514,25 @@ SkBitmap ImageOperations::ResizeBasic(co
   // Get a source bitmap encompassing this touched area. We construct the
   // offsets and row strides such that it looks like a new bitmap, while
   // referring to the old data.
   const uint8_t* source_subset =
       reinterpret_cast<const uint8_t*>(source.getPixels());
 
   // 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())
     return SkBitmap();
 
   BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()),
                  !source.isOpaque(), filter.x_filter(), filter.y_filter(),
                  static_cast<int>(result.rowBytes()),
--- a/other-licenses/skia-npapi/SkANP.cpp
+++ b/other-licenses/skia-npapi/SkANP.cpp
@@ -51,30 +51,31 @@ ANPRectF* SkANP::SetRect(ANPRectF* dst, 
     dst->left = SkScalarToFloat(src.fLeft);
     dst->top = SkScalarToFloat(src.fTop);
     dst->right = SkScalarToFloat(src.fRight);
     dst->bottom = SkScalarToFloat(src.fBottom);
     return dst;
 }
 
 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;
 }
 
 bool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) {
     if (!(dst->baseAddr = src.getPixels())) {
         SkDebugf("SkANP::SetBitmap - getPixels() returned null\n");
         return false;