зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1542344 - fix API mismatches in ImageEncoder; r=mccr8
ImageEncoder::ExtractDataInternal takes a `const nsAString&` for its options, but flattens it into a null-terminated `nsString` so callees can take a `char16_t*`. But nearly all of those callees eventually wind up calling ImageEncoder::GetInputStream, which just constructs an `nsDependentString` from the passed character pointer. There's no reason to do all this extra work. We can just pass the original options reference all the way through the stack and avoid needless conversions. Differential Revision: https://phabricator.services.mozilla.com/D26353 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4e774a774b
Коммит
ebdc4b2408
|
@ -285,11 +285,11 @@ nsresult ImageEncoder::ExtractDataAsync(
|
|||
nsresult ImageEncoder::GetInputStream(int32_t aWidth, int32_t aHeight,
|
||||
uint8_t* aImageBuffer, int32_t aFormat,
|
||||
imgIEncoder* aEncoder,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) {
|
||||
nsresult rv = aEncoder->InitFromData(aImageBuffer, aWidth * aHeight * 4,
|
||||
aWidth, aHeight, aWidth * 4, aFormat,
|
||||
nsDependentString(aEncoderOptions));
|
||||
aEncoderOptions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<imgIEncoder> encoder(aEncoder);
|
||||
|
@ -319,16 +319,14 @@ nsresult ImageEncoder::ExtractDataInternal(
|
|||
|
||||
rv = ImageEncoder::GetInputStream(
|
||||
aSize.width, aSize.height, aImageBuffer, aFormat, aEncoder,
|
||||
nsPromiseFlatString(aOptions).get(), getter_AddRefs(imgStream));
|
||||
aOptions, getter_AddRefs(imgStream));
|
||||
} else if (aContext && !aUsePlaceholder) {
|
||||
NS_ConvertUTF16toUTF8 encoderType(aType);
|
||||
rv = aContext->GetInputStream(encoderType.get(),
|
||||
nsPromiseFlatString(aOptions).get(),
|
||||
rv = aContext->GetInputStream(encoderType.get(), aOptions,
|
||||
getter_AddRefs(imgStream));
|
||||
} else if (aRenderer && !aUsePlaceholder) {
|
||||
NS_ConvertUTF16toUTF8 encoderType(aType);
|
||||
rv = aRenderer->GetInputStream(encoderType.get(),
|
||||
nsPromiseFlatString(aOptions).get(),
|
||||
rv = aRenderer->GetInputStream(encoderType.get(), aOptions,
|
||||
getter_AddRefs(imgStream));
|
||||
} else if (aImage && !aUsePlaceholder) {
|
||||
// It is safe to convert PlanarYCbCr format from YUV to RGB off-main-thread.
|
||||
|
|
|
@ -78,7 +78,7 @@ class ImageEncoder {
|
|||
static nsresult GetInputStream(int32_t aWidth, int32_t aHeight,
|
||||
uint8_t* aImageBuffer, int32_t aFormat,
|
||||
imgIEncoder* aEncoder,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream);
|
||||
|
||||
private:
|
||||
|
|
|
@ -1648,7 +1648,7 @@ nsString CanvasRenderingContext2D::GetHitRegion(
|
|||
|
||||
NS_IMETHODIMP
|
||||
CanvasRenderingContext2D::GetInputStream(const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) {
|
||||
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
||||
enccid += aMimeType;
|
||||
|
|
|
@ -405,7 +405,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
|
|||
nsIDocShell* aShell, NotNull<gfx::DrawTarget*> aTarget) override;
|
||||
|
||||
NS_IMETHOD GetInputStream(const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) override;
|
||||
|
||||
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
||||
|
|
|
@ -139,7 +139,7 @@ mozilla::UniquePtr<uint8_t[]> ImageBitmapRenderingContext::GetImageBuffer(
|
|||
|
||||
NS_IMETHODIMP
|
||||
ImageBitmapRenderingContext::GetInputStream(const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) {
|
||||
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
||||
enccid += aMimeType;
|
||||
|
|
|
@ -62,7 +62,7 @@ class ImageBitmapRenderingContext final
|
|||
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(
|
||||
int32_t* aFormat) override;
|
||||
NS_IMETHOD GetInputStream(const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) override;
|
||||
|
||||
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
||||
|
|
|
@ -1069,7 +1069,7 @@ UniquePtr<uint8_t[]> WebGLContext::GetImageBuffer(int32_t* out_format) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
WebGLContext::GetInputStream(const char* mimeType,
|
||||
const char16_t* encoderOptions,
|
||||
const nsAString& encoderOptions,
|
||||
nsIInputStream** out_stream) {
|
||||
NS_ASSERTION(gl, "GetInputStream on invalid context?");
|
||||
if (!gl) return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -369,7 +369,7 @@ class WebGLContext : public nsICanvasRenderingContextInternal,
|
|||
|
||||
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
|
||||
NS_IMETHOD GetInputStream(const char* mimeType,
|
||||
const char16_t* encoderOptions,
|
||||
const nsAString& encoderOptions,
|
||||
nsIInputStream** out_stream) override;
|
||||
|
||||
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
||||
|
|
|
@ -112,7 +112,7 @@ class nsICanvasRenderingContextInternal : public nsISupports,
|
|||
// is false, alpha will be discarded and the result will be the image
|
||||
// composited on black.
|
||||
NS_IMETHOD GetInputStream(const char* mimeType,
|
||||
const char16_t* encoderOptions,
|
||||
const nsAString& encoderOptions,
|
||||
nsIInputStream** stream) = 0;
|
||||
|
||||
// This gets an Azure SourceSurface for the canvas, this will be a snapshot
|
||||
|
|
|
@ -242,7 +242,7 @@ already_AddRefed<gfx::DataSourceSurface> AsyncCanvasRenderer::GetSurface() {
|
|||
}
|
||||
|
||||
nsresult AsyncCanvasRenderer::GetInputStream(const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
RefPtr<gfx::DataSourceSurface> surface = GetSurface();
|
||||
|
|
|
@ -89,7 +89,7 @@ class AsyncCanvasRenderer final {
|
|||
// function called GetSurface implicitly and GetSurface handles only get
|
||||
// called in the main thread. So this function can be called in main thread.
|
||||
nsresult GetInputStream(const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream);
|
||||
|
||||
gfx::IntSize GetSize() const { return gfx::IntSize(mWidth, mHeight); }
|
||||
|
|
|
@ -1343,7 +1343,7 @@ void gfxUtils::CopyAsDataURI(DrawTarget* aDT) {
|
|||
nsresult gfxUtils::GetInputStream(gfx::DataSourceSurface* aSurface,
|
||||
bool aIsAlphaPremultiplied,
|
||||
const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** outStream) {
|
||||
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
||||
enccid += aMimeType;
|
||||
|
|
|
@ -295,7 +295,7 @@ class gfxUtils {
|
|||
static nsresult GetInputStream(DataSourceSurface* aSurface,
|
||||
bool aIsAlphaPremultiplied,
|
||||
const char* aMimeType,
|
||||
const char16_t* aEncoderOptions,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** outStream);
|
||||
|
||||
static nsresult ThreadSafeGetFeatureStatus(
|
||||
|
|
Загрузка…
Ссылка в новой задаче