mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
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:
parent
4e774a774b
commit
ebdc4b2408
@ -285,11 +285,11 @@ nsresult ImageEncoder::ExtractDataAsync(
|
|||||||
nsresult ImageEncoder::GetInputStream(int32_t aWidth, int32_t aHeight,
|
nsresult ImageEncoder::GetInputStream(int32_t aWidth, int32_t aHeight,
|
||||||
uint8_t* aImageBuffer, int32_t aFormat,
|
uint8_t* aImageBuffer, int32_t aFormat,
|
||||||
imgIEncoder* aEncoder,
|
imgIEncoder* aEncoder,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream) {
|
nsIInputStream** aStream) {
|
||||||
nsresult rv = aEncoder->InitFromData(aImageBuffer, aWidth * aHeight * 4,
|
nsresult rv = aEncoder->InitFromData(aImageBuffer, aWidth * aHeight * 4,
|
||||||
aWidth, aHeight, aWidth * 4, aFormat,
|
aWidth, aHeight, aWidth * 4, aFormat,
|
||||||
nsDependentString(aEncoderOptions));
|
aEncoderOptions);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCOMPtr<imgIEncoder> encoder(aEncoder);
|
nsCOMPtr<imgIEncoder> encoder(aEncoder);
|
||||||
@ -319,16 +319,14 @@ nsresult ImageEncoder::ExtractDataInternal(
|
|||||||
|
|
||||||
rv = ImageEncoder::GetInputStream(
|
rv = ImageEncoder::GetInputStream(
|
||||||
aSize.width, aSize.height, aImageBuffer, aFormat, aEncoder,
|
aSize.width, aSize.height, aImageBuffer, aFormat, aEncoder,
|
||||||
nsPromiseFlatString(aOptions).get(), getter_AddRefs(imgStream));
|
aOptions, getter_AddRefs(imgStream));
|
||||||
} else if (aContext && !aUsePlaceholder) {
|
} else if (aContext && !aUsePlaceholder) {
|
||||||
NS_ConvertUTF16toUTF8 encoderType(aType);
|
NS_ConvertUTF16toUTF8 encoderType(aType);
|
||||||
rv = aContext->GetInputStream(encoderType.get(),
|
rv = aContext->GetInputStream(encoderType.get(), aOptions,
|
||||||
nsPromiseFlatString(aOptions).get(),
|
|
||||||
getter_AddRefs(imgStream));
|
getter_AddRefs(imgStream));
|
||||||
} else if (aRenderer && !aUsePlaceholder) {
|
} else if (aRenderer && !aUsePlaceholder) {
|
||||||
NS_ConvertUTF16toUTF8 encoderType(aType);
|
NS_ConvertUTF16toUTF8 encoderType(aType);
|
||||||
rv = aRenderer->GetInputStream(encoderType.get(),
|
rv = aRenderer->GetInputStream(encoderType.get(), aOptions,
|
||||||
nsPromiseFlatString(aOptions).get(),
|
|
||||||
getter_AddRefs(imgStream));
|
getter_AddRefs(imgStream));
|
||||||
} else if (aImage && !aUsePlaceholder) {
|
} else if (aImage && !aUsePlaceholder) {
|
||||||
// It is safe to convert PlanarYCbCr format from YUV to RGB off-main-thread.
|
// 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,
|
static nsresult GetInputStream(int32_t aWidth, int32_t aHeight,
|
||||||
uint8_t* aImageBuffer, int32_t aFormat,
|
uint8_t* aImageBuffer, int32_t aFormat,
|
||||||
imgIEncoder* aEncoder,
|
imgIEncoder* aEncoder,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream);
|
nsIInputStream** aStream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1648,7 +1648,7 @@ nsString CanvasRenderingContext2D::GetHitRegion(
|
|||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
CanvasRenderingContext2D::GetInputStream(const char* aMimeType,
|
CanvasRenderingContext2D::GetInputStream(const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream) {
|
nsIInputStream** aStream) {
|
||||||
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
||||||
enccid += aMimeType;
|
enccid += aMimeType;
|
||||||
|
@ -405,7 +405,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
|
|||||||
nsIDocShell* aShell, NotNull<gfx::DrawTarget*> aTarget) override;
|
nsIDocShell* aShell, NotNull<gfx::DrawTarget*> aTarget) override;
|
||||||
|
|
||||||
NS_IMETHOD GetInputStream(const char* aMimeType,
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream) override;
|
nsIInputStream** aStream) override;
|
||||||
|
|
||||||
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
||||||
|
@ -139,7 +139,7 @@ mozilla::UniquePtr<uint8_t[]> ImageBitmapRenderingContext::GetImageBuffer(
|
|||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
ImageBitmapRenderingContext::GetInputStream(const char* aMimeType,
|
ImageBitmapRenderingContext::GetInputStream(const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream) {
|
nsIInputStream** aStream) {
|
||||||
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
||||||
enccid += aMimeType;
|
enccid += aMimeType;
|
||||||
|
@ -62,7 +62,7 @@ class ImageBitmapRenderingContext final
|
|||||||
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(
|
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(
|
||||||
int32_t* aFormat) override;
|
int32_t* aFormat) override;
|
||||||
NS_IMETHOD GetInputStream(const char* aMimeType,
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream) override;
|
nsIInputStream** aStream) override;
|
||||||
|
|
||||||
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
||||||
|
@ -1069,7 +1069,7 @@ UniquePtr<uint8_t[]> WebGLContext::GetImageBuffer(int32_t* out_format) {
|
|||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
WebGLContext::GetInputStream(const char* mimeType,
|
WebGLContext::GetInputStream(const char* mimeType,
|
||||||
const char16_t* encoderOptions,
|
const nsAString& encoderOptions,
|
||||||
nsIInputStream** out_stream) {
|
nsIInputStream** out_stream) {
|
||||||
NS_ASSERTION(gl, "GetInputStream on invalid context?");
|
NS_ASSERTION(gl, "GetInputStream on invalid context?");
|
||||||
if (!gl) return NS_ERROR_FAILURE;
|
if (!gl) return NS_ERROR_FAILURE;
|
||||||
|
@ -369,7 +369,7 @@ class WebGLContext : public nsICanvasRenderingContextInternal,
|
|||||||
|
|
||||||
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
|
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
|
||||||
NS_IMETHOD GetInputStream(const char* mimeType,
|
NS_IMETHOD GetInputStream(const char* mimeType,
|
||||||
const char16_t* encoderOptions,
|
const nsAString& encoderOptions,
|
||||||
nsIInputStream** out_stream) override;
|
nsIInputStream** out_stream) override;
|
||||||
|
|
||||||
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
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
|
// is false, alpha will be discarded and the result will be the image
|
||||||
// composited on black.
|
// composited on black.
|
||||||
NS_IMETHOD GetInputStream(const char* mimeType,
|
NS_IMETHOD GetInputStream(const char* mimeType,
|
||||||
const char16_t* encoderOptions,
|
const nsAString& encoderOptions,
|
||||||
nsIInputStream** stream) = 0;
|
nsIInputStream** stream) = 0;
|
||||||
|
|
||||||
// This gets an Azure SourceSurface for the canvas, this will be a snapshot
|
// 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,
|
nsresult AsyncCanvasRenderer::GetInputStream(const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream) {
|
nsIInputStream** aStream) {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
RefPtr<gfx::DataSourceSurface> surface = GetSurface();
|
RefPtr<gfx::DataSourceSurface> surface = GetSurface();
|
||||||
|
@ -89,7 +89,7 @@ class AsyncCanvasRenderer final {
|
|||||||
// function called GetSurface implicitly and GetSurface handles only get
|
// function called GetSurface implicitly and GetSurface handles only get
|
||||||
// called in the main thread. So this function can be called in main thread.
|
// called in the main thread. So this function can be called in main thread.
|
||||||
nsresult GetInputStream(const char* aMimeType,
|
nsresult GetInputStream(const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** aStream);
|
nsIInputStream** aStream);
|
||||||
|
|
||||||
gfx::IntSize GetSize() const { return gfx::IntSize(mWidth, mHeight); }
|
gfx::IntSize GetSize() const { return gfx::IntSize(mWidth, mHeight); }
|
||||||
|
@ -1343,7 +1343,7 @@ void gfxUtils::CopyAsDataURI(DrawTarget* aDT) {
|
|||||||
nsresult gfxUtils::GetInputStream(gfx::DataSourceSurface* aSurface,
|
nsresult gfxUtils::GetInputStream(gfx::DataSourceSurface* aSurface,
|
||||||
bool aIsAlphaPremultiplied,
|
bool aIsAlphaPremultiplied,
|
||||||
const char* aMimeType,
|
const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** outStream) {
|
nsIInputStream** outStream) {
|
||||||
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
nsCString enccid("@mozilla.org/image/encoder;2?type=");
|
||||||
enccid += aMimeType;
|
enccid += aMimeType;
|
||||||
|
@ -295,7 +295,7 @@ class gfxUtils {
|
|||||||
static nsresult GetInputStream(DataSourceSurface* aSurface,
|
static nsresult GetInputStream(DataSourceSurface* aSurface,
|
||||||
bool aIsAlphaPremultiplied,
|
bool aIsAlphaPremultiplied,
|
||||||
const char* aMimeType,
|
const char* aMimeType,
|
||||||
const char16_t* aEncoderOptions,
|
const nsAString& aEncoderOptions,
|
||||||
nsIInputStream** outStream);
|
nsIInputStream** outStream);
|
||||||
|
|
||||||
static nsresult ThreadSafeGetFeatureStatus(
|
static nsresult ThreadSafeGetFeatureStatus(
|
||||||
|
Loading…
Reference in New Issue
Block a user