From 53a5f52f15a9fc155a2ed713269419de8e8ded85 Mon Sep 17 00:00:00 2001 From: George Wright Date: Thu, 5 Dec 2013 23:01:53 -0500 Subject: [PATCH] Bug 910754 - Update gfx/2d's Skia code to use the new Skia APIs r=snorp --- gfx/2d/DrawTargetSkia.cpp | 20 ++++++++++---------- gfx/2d/Scale.cpp | 9 ++++----- gfx/2d/SourceSurfaceSkia.cpp | 2 +- gfx/2d/image_operations.cpp | 4 ++-- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index 433c2f20505..4ab6a14ccc2 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -7,7 +7,8 @@ #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 @@ -747,9 +748,9 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface, bool DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat) { - SkAutoTUnref device(new SkDevice(GfxFormatToSkiaConfig(aFormat), - aSize.width, aSize.height, - aFormat == SurfaceFormat::B8G8R8X8)); + SkAutoTUnref device(new SkBitmapDevice(GfxFormatToSkiaConfig(aFormat), + aSize.width, aSize.height, + aFormat == SurfaceFormat::B8G8R8X8)); SkBitmap bitmap = device->accessBitmap(true); if (!bitmap.allocPixels()) { @@ -794,7 +795,7 @@ DrawTargetSkia::InitWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLCont targetDescriptor.fRenderTargetHandle = 0; // GLContext always exposes the right framebuffer as id 0 SkAutoTUnref target(mGrContext->wrapBackendRenderTarget(targetDescriptor)); - SkAutoTUnref device(new SkGpuDevice(mGrContext.get(), target.get())); + SkAutoTUnref device(new SkGpuDevice(mGrContext.get(), target.get())); SkAutoTUnref canvas(new SkCanvas(device.get())); mCanvas = canvas.get(); @@ -812,18 +813,17 @@ DrawTargetSkia::SetCacheLimits(int aCount, int aSizeInBytes) 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 canvas(new SkCanvas(new SkDevice(bitmap))); + SkAutoTUnref canvas(new SkCanvas(new SkBitmapDevice(bitmap))); mSize = aSize; mCanvas = canvas.get(); diff --git a/gfx/2d/Scale.cpp b/gfx/2d/Scale.cpp index bb784253007..0b5a26fadba 100644 --- a/gfx/2d/Scale.cpp +++ b/gfx/2d/Scale.cpp @@ -18,19 +18,18 @@ bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStr 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) { diff --git a/gfx/2d/SourceSurfaceSkia.cpp b/gfx/2d/SourceSurfaceSkia.cpp index a58c3aed755..1fb99a04c2c 100644 --- a/gfx/2d/SourceSurfaceSkia.cpp +++ b/gfx/2d/SourceSurfaceSkia.cpp @@ -78,7 +78,7 @@ SourceSurfaceSkia::InitFromData(unsigned char* aData, ConvertBGRXToBGRA(reinterpret_cast(mBitmap.getPixels()), aSize, mBitmap.rowBytes()); mBitmap.unlockPixels(); mBitmap.notifyPixelsChanged(); - mBitmap.setIsOpaque(true); + mBitmap.setAlphaType(kOpaque_SkAlphaType); } mSize = aSize; diff --git a/gfx/2d/image_operations.cpp b/gfx/2d/image_operations.cpp index a12272b9ee4..577633d8c89 100644 --- a/gfx/2d/image_operations.cpp +++ b/gfx/2d/image_operations.cpp @@ -470,7 +470,7 @@ SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source, src_row += h * row_words; dst_row += result.rowBytes() / 4; } - result.setIsOpaque(img.isOpaque()); + result.setAlphaType(img.alphaType()); return result; #else return SkBitmap(); @@ -534,7 +534,7 @@ SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source, /* sse = */ false); // Preserve the "opaque" flag for use as an optimization later. - result.setIsOpaque(source.isOpaque()); + result.setAlphaType(source.alphaType()); return result; }