Bug 1082598 - Part 2: Fix Moz2D Skia usage for Skia update. r=jrmuizel

This commit is contained in:
Lee Salzman 2015-12-18 13:53:25 -05:00
parent 231d83f99e
commit f9d4573bec
4 changed files with 52 additions and 52 deletions

View File

@ -12,11 +12,7 @@
#include "FilterNodeSoftware.h"
#include "HelpersSkia.h"
#ifdef USE_SKIA_GPU
#include "skia/include/gpu/SkGpuDevice.h"
#include "skia/include/gpu/gl/GrGLInterface.h"
#endif
#include "skia/include/core/SkSurface.h"
#include "skia/include/core/SkTypeface.h"
#include "skia/include/effects/SkGradientShader.h"
#include "skia/include/core/SkColorFilter.h"
@ -149,29 +145,32 @@ bool
DrawTargetSkia::LockBits(uint8_t** aData, IntSize* aSize,
int32_t* aStride, SurfaceFormat* aFormat)
{
const SkBitmap &bitmap = mCanvas->getDevice()->accessBitmap(false);
if (!bitmap.lockPixelsAreWritable()) {
/* Test if the canvas' device has accessible pixels first, as actually
* accessing the pixels may trigger side-effects, even if it fails.
*/
if (!mCanvas->peekPixels(nullptr, nullptr)) {
return false;
}
SkImageInfo info;
size_t rowBytes;
void* pixels = mCanvas->accessTopLayerPixels(&info, &rowBytes);
if (!pixels) {
return false;
}
MarkChanged();
bitmap.lockPixels();
*aData = reinterpret_cast<uint8_t*>(bitmap.getPixels());
*aSize = IntSize(bitmap.width(), bitmap.height());
*aStride = int32_t(bitmap.rowBytes());
*aFormat = SkiaColorTypeToGfxFormat(bitmap.colorType());
*aData = reinterpret_cast<uint8_t*>(pixels);
*aSize = IntSize(info.width(), info.height());
*aStride = int32_t(rowBytes);
*aFormat = SkiaColorTypeToGfxFormat(info.colorType());
return true;
}
void
DrawTargetSkia::ReleaseBits(uint8_t* aData)
{
const SkBitmap &bitmap = mCanvas->getDevice()->accessBitmap(false);
MOZ_ASSERT(bitmap.lockPixelsAreWritable());
bitmap.unlockPixels();
bitmap.notifyPixelsChanged();
}
static void
@ -266,7 +265,7 @@ SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, TempBitmap& aTmpBitmap
SkSafeUnref(shader);
SkSafeUnref(aPaint.setShader(matrixShader));
if (pat.mFilter == Filter::POINT) {
aPaint.setFilterLevel(SkPaint::kNone_FilterLevel);
aPaint.setFilterQuality(kNone_SkFilterQuality);
}
break;
}
@ -333,7 +332,7 @@ struct AutoPaintSetup {
mPaint.setAlpha(ColorFloatToByte(aOptions.mAlpha));
mAlpha = aOptions.mAlpha;
}
mPaint.setFilterLevel(SkPaint::kLow_FilterLevel);
mPaint.setFilterQuality(kLow_SkFilterQuality);
}
// TODO: Maybe add an operator overload to access this easier?
@ -381,10 +380,10 @@ DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
AutoPaintSetup paint(mCanvas.get(), aOptions, &aDest);
if (aSurfOptions.mFilter == Filter::POINT) {
paint.mPaint.setFilterLevel(SkPaint::kNone_FilterLevel);
paint.mPaint.setFilterQuality(kNone_SkFilterQuality);
}
mCanvas->drawBitmapRectToRect(bitmap.mBitmap, &sourceRect, destRect, &paint.mPaint);
mCanvas->drawBitmapRect(bitmap.mBitmap, sourceRect, destRect, &paint.mPaint);
}
DrawTargetType
@ -797,9 +796,7 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface,
SkBitmap bm(bitmap.mBitmap);
bm.lockPixels();
if (bm.getPixels()) {
SkImageInfo info = bm.info();
info.fWidth = aSourceRect.width;
info.fHeight = aSourceRect.height;
SkImageInfo info = bm.info().makeWH(aSourceRect.width, aSourceRect.height);
uint8_t* pixels = static_cast<uint8_t*>(bm.getPixels());
// adjust pixels for the source offset
pixels += aSourceRect.x + aSourceRect.y*bm.rowBytes();
@ -831,7 +828,7 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface,
clearPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
mCanvas->drawPaint(clearPaint);
}
mCanvas->drawBitmapRect(bitmap.mBitmap, &source, dest, &paint);
mCanvas->drawBitmapRect(bitmap.mBitmap, source, dest, &paint);
mCanvas->restore();
}
@ -854,7 +851,7 @@ DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
SkBitmap bitmap;
bitmap.setInfo(skiInfo, stride);
if (!bitmap.allocPixels()) {
if (!bitmap.tryAllocPixels()) {
return false;
}
@ -883,24 +880,28 @@ DrawTargetSkia::InitWithGrContext(GrContext* aGrContext,
mSize = aSize;
mFormat = aFormat;
GrTextureDesc targetDescriptor;
GrSurfaceDesc targetDescriptor;
targetDescriptor.fFlags = kRenderTarget_GrTextureFlagBit;
targetDescriptor.fFlags = kRenderTarget_GrSurfaceFlag;
targetDescriptor.fWidth = mSize.width;
targetDescriptor.fHeight = mSize.height;
targetDescriptor.fConfig = GfxFormatToGrConfig(mFormat);
targetDescriptor.fOrigin = kBottomLeft_GrSurfaceOrigin;
targetDescriptor.fSampleCnt = 0;
SkAutoTUnref<GrTexture> skiaTexture(mGrContext->createUncachedTexture(targetDescriptor, NULL, 0));
SkAutoTUnref<GrTexture> skiaTexture(mGrContext->textureProvider()->createTexture(targetDescriptor, SkSurface::kNo_Budgeted, nullptr, 0));
if (!skiaTexture) {
return false;
}
mTexture = (uint32_t)skiaTexture->getTextureHandle();
SkAutoTUnref<SkSurface> gpuSurface(SkSurface::NewRenderTargetDirect(skiaTexture->asRenderTarget()));
if (!gpuSurface) {
return false;
}
SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(mGrContext.get(), skiaTexture->asRenderTarget()));
mCanvas.adopt(new SkCanvas(device.get()));
mTexture = reinterpret_cast<GrGLTextureInfo *>(skiaTexture->getTextureHandle())->fID;
mCanvas = gpuSurface->getCanvas();
return true;
}

View File

@ -142,7 +142,7 @@ private:
#ifdef USE_SKIA_GPU
RefPtrSkia<GrContext> mGrContext;
uint32_t mTexture;
GrGLuint mTexture;
#endif
IntSize mSize;

View File

@ -41,20 +41,20 @@ SkTypeface* ScaledFontCairo::GetSkTypeface()
{
if (!mTypeface) {
cairo_font_face_t* fontFace = cairo_scaled_font_get_font_face(mScaledFont);
MOZ_ASSERT(cairo_font_face_status(fontFace) == CAIRO_STATUS_SUCCESS);
FT_Face face = cairo_ft_scaled_font_lock_face(mScaledFont);
int style = SkTypeface::kNormal;
if (face->style_flags & FT_STYLE_FLAG_ITALIC)
style |= SkTypeface::kItalic;
if (face->style_flags & FT_STYLE_FLAG_BOLD)
style |= SkTypeface::kBold;
SkFontStyle style(face->style_flags & FT_STYLE_FLAG_BOLD ?
SkFontStyle::kBold_Weight : SkFontStyle::kNormal_Weight,
SkFontStyle::kNormal_Width,
face->style_flags & FT_STYLE_FLAG_ITALIC ?
SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant);
bool isFixedWidth = face->face_flags & FT_FACE_FLAG_FIXED_WIDTH;
cairo_ft_scaled_font_unlock_face(mScaledFont);
mTypeface = SkCreateTypefaceFromCairoFont(fontFace, (SkTypeface::Style)style, isFixedWidth);
mTypeface = SkCreateTypefaceFromCairoFont(fontFace, style, isFixedWidth);
}
return mTypeface;

View File

@ -13,6 +13,7 @@
#include "DataSurfaceHelpers.h"
#ifdef USE_SKIA_GPU
#include "GLDefs.h"
#include "skia/include/gpu/SkGrPixelRef.h"
#endif
@ -50,13 +51,11 @@ SourceSurfaceSkia::InitFromCanvas(SkCanvas* aCanvas,
SurfaceFormat aFormat,
DrawTargetSkia* aOwner)
{
SkISize size = aCanvas->getDeviceSize();
mBitmap = (SkBitmap)aCanvas->getDevice()->accessBitmap(false);
mBitmap = aCanvas->getDevice()->accessBitmap(false);
mFormat = aFormat;
mSize = IntSize(size.fWidth, size.fHeight);
mSize = IntSize(mBitmap.width(), mBitmap.height());
mStride = mBitmap.rowBytes();
mDrawTarget = aOwner;
@ -84,10 +83,6 @@ SourceSurfaceSkia::InitFromData(unsigned char* aData,
return false;
}
if (aFormat == SurfaceFormat::B8G8R8X8) {
mBitmap.setAlphaType(kIgnore_SkAlphaType);
}
mSize = aSize;
mFormat = aFormat;
mStride = mBitmap.rowBytes();
@ -109,11 +104,15 @@ SourceSurfaceSkia::InitFromTexture(DrawTargetSkia* aOwner,
skiaTexGlue.fOrigin = kTopLeft_GrSurfaceOrigin;
skiaTexGlue.fConfig = GfxFormatToGrConfig(aFormat);
skiaTexGlue.fSampleCnt = 0;
skiaTexGlue.fTextureHandle = aTexture;
GrTexture *skiaTexture = aOwner->mGrContext->wrapBackendTexture(skiaTexGlue);
GrGLTextureInfo texInfo;
texInfo.fTarget = LOCAL_GL_TEXTURE_2D;
texInfo.fID = aTexture;
skiaTexGlue.fTextureHandle = reinterpret_cast<GrBackendObject>(&texInfo);
GrTexture *skiaTexture = aOwner->mGrContext->textureProvider()->wrapBackendTexture(skiaTexGlue);
SkImageInfo imgInfo = SkImageInfo::Make(aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), kOpaque_SkAlphaType);
SkGrPixelRef *texRef = new SkGrPixelRef(imgInfo, skiaTexture, false);
SkGrPixelRef *texRef = new SkGrPixelRef(imgInfo, skiaTexture);
mBitmap.setInfo(imgInfo);
mBitmap.setPixelRef(texRef);
mFormat = aFormat;