Bug 1890216 - Fix Skia API usage in Gecko for m125 update. r=aosmond

A number of public APIs in Skia have changed since the update to m125,
so various places in Gecko need to be updated to track it.

Differential Revision: https://phabricator.services.mozilla.com/D209821
This commit is contained in:
Lee Salzman 2024-05-10 03:49:34 +00:00
parent 9b6c6b200d
commit 69890c6a53
8 changed files with 30 additions and 22 deletions

View File

@ -257,7 +257,7 @@ static sk_sp<SkImage> GetSkImageForSurface(SourceSurface* aSurface,
}
DataSourceSurface::MappedSurface map;
SkImage::RasterReleaseProc releaseProc;
void (*releaseProc)(const void*, void*);
if (dataSurface->GetType() == SurfaceType::DATA_SHARED_WRAPPER) {
// Technically all surfaces should be mapped and unmapped explicitly but it
// appears SourceSurfaceSkia and DataSourceSurfaceWrapper have issues with
@ -283,7 +283,7 @@ static sk_sp<SkImage> GetSkImageForSurface(SourceSurface* aSurface,
SkPixmap pixmap(MakeSkiaImageInfo(surf->GetSize(), surf->GetFormat()),
map.mData, map.mStride);
sk_sp<SkImage> image = SkImage::MakeFromRaster(pixmap, releaseProc, surf);
sk_sp<SkImage> image = SkImages::RasterFromPixmap(pixmap, releaseProc, surf);
if (!image) {
releaseProc(map.mData, surf);
gfxDebug() << "Failed making Skia raster image for temporary surface";
@ -347,7 +347,7 @@ already_AddRefed<SourceSurface> DrawTargetSkia::Snapshot(
// pixels.
SkPixmap pixmap;
if (mSurface->peekPixels(&pixmap)) {
image = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
image = SkImages::RasterFromPixmap(pixmap, nullptr, nullptr);
} else {
image = mSurface->makeImageSnapshot();
}
@ -412,10 +412,10 @@ static sk_sp<SkImage> ExtractSubset(sk_sp<SkImage> aImage,
pixmap.extractSubset(&subsetPixmap, subsetRect)) {
// Release the original image reference so only the subset image keeps it
// alive.
return SkImage::MakeFromRaster(subsetPixmap, ReleaseImage,
aImage.release());
return SkImages::RasterFromPixmap(subsetPixmap, ReleaseImage,
aImage.release());
}
return aImage->makeSubset(subsetRect);
return aImage->makeSubset(nullptr, subsetRect);
}
static void FreeAlphaPixels(void* aBuf, void*) { sk_free(aBuf); }
@ -711,7 +711,7 @@ struct AutoPaintSetup {
Float mAlpha;
};
void DrawTargetSkia::Flush() { mCanvas->flush(); }
void DrawTargetSkia::Flush() {}
void DrawTargetSkia::DrawSurface(SourceSurface* aSurface, const Rect& aDest,
const Rect& aSource,
@ -1509,7 +1509,6 @@ bool DrawTarget::Draw3DTransformedSurface(SourceSurface* aSurface,
dstCanvas->drawImage(srcImage, 0, 0, SkSamplingOptions(SkFilterMode::kLinear),
&paint);
dstCanvas->flush();
// Temporarily reset the DT's transform, since it has already been composed
// above.
@ -1756,10 +1755,10 @@ bool DrawTargetSkia::Init(const IntSize& aSize, SurfaceFormat aFormat) {
if (!buf) {
return false;
}
mSurface = AsRefPtr(SkSurface::MakeRasterDirectReleaseProc(
mSurface = AsRefPtr(SkSurfaces::WrapPixels(
info, buf, stride, FreeAlphaPixels, nullptr, &props));
} else {
mSurface = AsRefPtr(SkSurface::MakeRaster(info, stride, &props));
mSurface = AsRefPtr(SkSurfaces::Raster(info, stride, &props));
}
if (!mSurface) {
return false;
@ -1805,8 +1804,8 @@ bool DrawTargetSkia::Init(unsigned char* aData, const IntSize& aSize,
VerifyRGBXFormat(aData, aSize, aStride, aFormat));
SkSurfaceProps props(0, GetSkPixelGeometry());
mSurface = AsRefPtr(SkSurface::MakeRasterDirect(
MakeSkiaImageInfo(aSize, aFormat), aData, aStride, &props));
mSurface = AsRefPtr(SkSurfaces::WrapPixels(MakeSkiaImageInfo(aSize, aFormat),
aData, aStride, &props));
if (!mSurface) {
return false;
}
@ -1832,7 +1831,7 @@ bool DrawTargetSkia::Init(RefPtr<DataSourceSurface>&& aSurface) {
VerifyRGBXFormat(map->GetData(), size, map->GetStride(), format));
SkSurfaceProps props(0, GetSkPixelGeometry());
mSurface = AsRefPtr(SkSurface::MakeRasterDirectReleaseProc(
mSurface = AsRefPtr(SkSurfaces::WrapPixels(
MakeSkiaImageInfo(size, format), map->GetData(), map->GetStride(),
DrawTargetSkia::ReleaseMappedSkSurface, map, &props));
if (!mSurface) {

View File

@ -9,9 +9,11 @@
#include "2D.h"
#include "skia/include/core/SkCanvas.h"
#include "skia/include/core/SkFontTypes.h"
#include "skia/include/core/SkPathEffect.h"
#include "skia/include/core/SkPathTypes.h"
#include "skia/include/core/SkShader.h"
#include "skia/include/core/SkTileMode.h"
#include "skia/include/effects/SkDashPathEffect.h"
#include "mozilla/Assertions.h"
#include <cmath>

View File

@ -11,6 +11,8 @@
# include "nsCocoaFeatures.h"
#endif
#include "PathSkia.h"
#include "skia/include/core/SkFont.h"
#include "skia/include/core/SkFontTypes.h"
#include "skia/include/core/SkPaint.h"
#include "skia/include/core/SkPath.h"
#include "skia/include/ports/SkTypeface_mac.h"

View File

@ -106,7 +106,7 @@ AntialiasMode ScaledFontWin::GetDefaultAAMode() {
}
SkTypeface* ScaledFontWin::CreateSkTypeface() {
return SkCreateTypefaceFromLOGFONT(mLogFont);
return SkCreateTypefaceFromLOGFONT(mLogFont).release();
}
cairo_font_face_t* ScaledFontWin::CreateCairoFontFace(

View File

@ -84,7 +84,7 @@ static sk_sp<SkImage> ReadSkImage(const sk_sp<SkImage>& aImage,
if (sk_sp<SkData> data = MakeSkData(nullptr, aInfo.height(), aStride)) {
if (aImage->readPixels(aInfo, data->writable_data(), aStride, aX, aY,
SkImage::kDisallow_CachingHint)) {
return SkImage::MakeRasterData(aInfo, data, aStride);
return SkImages::RasterFromData(aInfo, data, aStride);
}
}
return nullptr;
@ -98,7 +98,7 @@ bool SourceSurfaceSkia::InitFromData(unsigned char* aData, const IntSize& aSize,
}
SkImageInfo info = MakeSkiaImageInfo(aSize, aFormat);
mImage = SkImage::MakeRasterData(info, data, aStride);
mImage = SkImages::RasterFromData(info, data, aStride);
if (!mImage) {
return false;
}

View File

@ -9,6 +9,8 @@
#include "nsString.h"
#include <vector>
#include "skia/src/pdf/SkPDFUtils.h"
namespace mozilla::gfx {
PrintTargetSkPDF::PrintTargetSkPDF(const IntSize& aSize,
@ -43,8 +45,8 @@ nsresult PrintTargetSkPDF::BeginPrinting(const nsAString& aTitle,
SkPDF::Metadata metadata;
metadata.fTitle = NS_ConvertUTF16toUTF8(aTitle).get();
metadata.fCreator = "Firefox";
SkTime::DateTime now;
SkTime::GetDateTime(&now);
SkPDF::DateTime now = {0};
SkPDFUtils::GetDateTime(&now);
metadata.fCreation = now;
metadata.fModified = now;

View File

@ -37,7 +37,6 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Scale.h"
#include "nsComponentManagerUtils.h"
#include "nsError.h"
#include "nsIConsoleService.h"

View File

@ -531,8 +531,9 @@ imgTools::EncodeScaledImage(imgIContainer* aContainer,
}
// Otherwise we need to scale it using a draw target.
RefPtr<DataSourceSurface> dataSurface =
Factory::CreateDataSourceSurface(scaledSize, SurfaceFormat::B8G8R8A8);
// Ensure the surface is initialized to clear in case we need to blend to it.
RefPtr<DataSourceSurface> dataSurface = Factory::CreateDataSourceSurface(
scaledSize, SurfaceFormat::B8G8R8A8, true);
if (NS_WARN_IF(!dataSurface)) {
return NS_ERROR_FAILURE;
}
@ -550,11 +551,14 @@ imgTools::EncodeScaledImage(imgIContainer* aContainer,
return NS_ERROR_OUT_OF_MEMORY;
}
// Prefer using OP_OVER to scale the surface instead of OP_SOURCE, as both
// D2D and Skia have specific fast-paths for these, and may give divergent
// and slower results when using OP_SOURCE.
IntSize frameSize = frame->GetSize();
dt->DrawSurface(frame, Rect(0, 0, scaledSize.width, scaledSize.height),
Rect(0, 0, frameSize.width, frameSize.height),
DrawSurfaceOptions(),
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
DrawOptions(1.0f, CompositionOp::OP_OVER));
return EncodeImageData(dataSurface, map, aMimeType, aOutputOptions, aStream);
}