Bug 910754 - Update gfx/2d's Skia code to use the new Skia APIs r=snorp

This commit is contained in:
George Wright 2013-12-05 23:01:53 -05:00
parent 160a93d312
commit 71f60661f9
4 changed files with 17 additions and 18 deletions

View File

@ -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<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()) {
@ -794,7 +795,7 @@ DrawTargetSkia::InitWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLCont
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();
@ -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<SkCanvas> canvas(new SkCanvas(new SkDevice(bitmap)));
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(new SkBitmapDevice(bitmap)));
mSize = aSize;
mCanvas = canvas.get();

View File

@ -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) {

View File

@ -78,7 +78,7 @@ SourceSurfaceSkia::InitFromData(unsigned char* aData,
ConvertBGRXToBGRA(reinterpret_cast<unsigned char*>(mBitmap.getPixels()), aSize, mBitmap.rowBytes());
mBitmap.unlockPixels();
mBitmap.notifyPixelsChanged();
mBitmap.setIsOpaque(true);
mBitmap.setAlphaType(kOpaque_SkAlphaType);
}
mSize = aSize;

View File

@ -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;
}