Bug 910754 - Update gfx/2d's Skia code to use the new Skia APIs r=snorp
authorGeorge Wright <gw@gwright.org.uk>
Thu, 05 Dec 2013 23:01:53 -0500
changeset 186617 56474b57c3b87180fca578d0ab78f2174acc8beb
parent 186616 0c3c16ea5cd3b0e5d907ed3d69b9990a394d71a5
child 186618 218aa532182b7329aa213df24073a5aa40039727
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs910754
milestone30.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
Bug 910754 - Update gfx/2d's Skia code to use the new Skia APIs r=snorp
gfx/2d/DrawTargetSkia.cpp
gfx/2d/Scale.cpp
gfx/2d/SourceSurfaceSkia.cpp
gfx/2d/image_operations.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -2,17 +2,18 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DrawTargetSkia.h"
 #include "SourceSurfaceSkia.h"
 #include "ScaledFontBase.h"
 #include "ScaledFontCairo.h"
-#include "skia/SkDevice.h"
+#include "skia/SkGpuDevice.h"
+#include "skia/SkBitmapDevice.h"
 #include "FilterNodeSoftware.h"
 
 #ifdef USE_SKIA_GPU
 #include "skia/SkGpuDevice.h"
 #include "skia/GrGLInterface.h"
 #endif
 
 #include "skia/SkTypeface.h"
@@ -742,19 +743,19 @@ DrawTargetSkia::CopySurface(SourceSurfac
 
   mCanvas->drawBitmapRect(bitmap.mBitmap, &source, dest, &paint);
   mCanvas->restore();
 }
 
 bool
 DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
 {
-  SkAutoTUnref<SkDevice> device(new SkDevice(GfxFormatToSkiaConfig(aFormat),
-                                             aSize.width, aSize.height,
-                                             aFormat == SurfaceFormat::B8G8R8X8));
+  SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(GfxFormatToSkiaConfig(aFormat),
+                                                       aSize.width, aSize.height,
+                                                       aFormat == SurfaceFormat::B8G8R8X8));
 
   SkBitmap bitmap = device->accessBitmap(true);
   if (!bitmap.allocPixels()) {
     return false;
   }
 
   bitmap.eraseARGB(0, 0, 0, 0);
 
@@ -789,17 +790,17 @@ DrawTargetSkia::InitWithGLContextAndGrGL
   targetDescriptor.fWidth = mSize.width;
   targetDescriptor.fHeight = mSize.height;
   targetDescriptor.fConfig = GfxFormatToGrConfig(mFormat);
   targetDescriptor.fOrigin = kBottomLeft_GrSurfaceOrigin;
   targetDescriptor.fSampleCnt = 0;
   targetDescriptor.fRenderTargetHandle = 0; // GLContext always exposes the right framebuffer as id 0
 
   SkAutoTUnref<GrRenderTarget> target(mGrContext->wrapBackendRenderTarget(targetDescriptor));
-  SkAutoTUnref<SkDevice> device(new SkGpuDevice(mGrContext.get(), target.get()));
+  SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(mGrContext.get(), target.get()));
   SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
   mCanvas = canvas.get();
 
   AddGLDrawTarget(this);
 }
 
 void
 DrawTargetSkia::SetCacheLimits(int aCount, int aSizeInBytes)
@@ -807,28 +808,27 @@ DrawTargetSkia::SetCacheLimits(int aCoun
   MOZ_ASSERT(mGrContext, "No GrContext!");
   mGrContext->setTextureCacheLimits(aCount, aSizeInBytes);
 }
 #endif
 
 void
 DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat)
 {
-  bool isOpaque = false;
+  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);
-    isOpaque = true;
+    alphaType = kOpaque_SkAlphaType;
   }
 
   SkBitmap bitmap;
-  bitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
+  bitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride, alphaType);
   bitmap.setPixels(aData);
-  bitmap.setIsOpaque(isOpaque);
-  SkAutoTUnref<SkCanvas> canvas(new SkCanvas(new SkDevice(bitmap)));
+  SkAutoTUnref<SkCanvas> canvas(new SkCanvas(new SkBitmapDevice(bitmap)));
 
   mSize = aSize;
   mCanvas = canvas.get();
   mFormat = aFormat;
 }
 
 void
 DrawTargetSkia::SetTransform(const Matrix& aTransform)
--- a/gfx/2d/Scale.cpp
+++ b/gfx/2d/Scale.cpp
@@ -13,29 +13,28 @@
 namespace mozilla {
 namespace gfx {
 
 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
-  bool opaque;
+  SkAlphaType alphaType;
   if (format == SurfaceFormat::B8G8R8A8) {
-    opaque = false;
+    alphaType = kPremul_SkAlphaType;
   } else {
-    opaque = true;
+    alphaType = kOpaque_SkAlphaType;
   }
 
   SkBitmap::Config config = GfxFormatToSkiaConfig(format);
 
   SkBitmap imgSrc;
-  imgSrc.setConfig(config, srcWidth, srcHeight, srcStride);
+  imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType);
   imgSrc.setPixels(srcData);
-  imgSrc.setIsOpaque(opaque);
 
   // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed.
   if (config != SkBitmap::kARGB_8888_Config) {
     imgSrc.copyTo(&imgSrc, SkBitmap::kARGB_8888_Config);
   }
 
   // This returns an SkBitmap backed by dstData; since it also wrote to dstData,
   // we don't need to look at that SkBitmap.
--- a/gfx/2d/SourceSurfaceSkia.cpp
+++ b/gfx/2d/SourceSurfaceSkia.cpp
@@ -73,17 +73,17 @@ SourceSurfaceSkia::InitFromData(unsigned
   }
 
   if (aFormat == SurfaceFormat::B8G8R8X8) {
     mBitmap.lockPixels();
     // We have to manually set the A channel to be 255 as Skia doesn't understand BGRX
     ConvertBGRXToBGRA(reinterpret_cast<unsigned char*>(mBitmap.getPixels()), aSize, mBitmap.rowBytes());
     mBitmap.unlockPixels();
     mBitmap.notifyPixelsChanged();
-    mBitmap.setIsOpaque(true);
+    mBitmap.setAlphaType(kOpaque_SkAlphaType);
   }
 
   mSize = aSize;
   mFormat = aFormat;
   mStride = mBitmap.rowBytes();
   return true;
 }
 
--- a/gfx/2d/image_operations.cpp
+++ b/gfx/2d/image_operations.cpp
@@ -465,17 +465,17 @@ SkBitmap ImageOperations::ResizeSubpixel
       a = a > r ? a : r;
       a = a > g ? a : g;
       a = a > b ? a : b;
       *dst = SkPackARGB32(a, r, g, b);
     }
     src_row += h * row_words;
     dst_row += result.rowBytes() / 4;
   }
-  result.setIsOpaque(img.isOpaque());
+  result.setAlphaType(img.alphaType());
   return result;
 #else
   return SkBitmap();
 #endif  // OS_POSIX && !OS_MACOSX && !defined(OS_ANDROID)
 }
 
 // static
 SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source,
@@ -529,17 +529,17 @@ SkBitmap ImageOperations::ResizeBasic(co
 
   BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()),
                  !source.isOpaque(), filter.x_filter(), filter.y_filter(),
                  static_cast<int>(result.rowBytes()),
                  static_cast<unsigned char*>(result.getPixels()),
                  /* sse = */ false);
 
   // Preserve the "opaque" flag for use as an optimization later.
-  result.setIsOpaque(source.isOpaque());
+  result.setAlphaType(source.alphaType());
 
   return result;
 }
 
 // static
 SkBitmap ImageOperations::Resize(const SkBitmap& source,
                                  ResizeMethod method,
                                  int dest_width, int dest_height,