mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
9af8eeaf15
- Bug 1125514 - Use jemalloc's metadata statistics to compute bookkeeping. r=glandium (541dbcfc6f) - Bug 1201462 - Don't count arena allocated metadata once per bin. r=glandium (57e7c31081) - back some warnings (377df69d65) - Bug 1219501. In imagelib, initialize the number of cores to at least 1 in case of error. r=seth (3d7d1635f0) - Bug 1219501. Limit total number of image decoding threads to 32 regardless of number asked for. r=seth (829a7a623d) - Bug 1213744 (Part 1) - Support zero-size frame rects and detecting the end of the frame in Downscaler. r=tn (05e29075cc) - Bug 1213744 (Part 2) - Clamp the GIF frame rect to the visible rect for DDD and don't decode outside it. r=tn (8a25e10a3e) - Bug 1194837. Don't use the inverse orientation matrix when computing the image space invalidate rect. r=seth (cb5e4c2643) - Bug 1214054 - Don't fire DECODE_COMPLETE in VectorImage::OnSVGDocumetError(). r=dholbert (bb7c34e46f) - Bug 1195878 - If we detect animation during a full decode, drop the results of the full decode on the floor. r=tn (a765af2b68) - Bug 1210553 - Remove the alternate flags arguments from SurfaceCache's Lookup functions. r=dholbert (15c6124f98) - Bug 1217320 - Remove more XPIDL signature comments in .cpp files. r=froydnj (411ac93047) - Bug 1186796 - Replace nsBaseHashtable::EnumerateRead() calls in image/ with iterators r=njn (665773ae6d) - Bug 1186792 - Replace nsBaseHashtable::EnumerateRead() calls in hal/ with iterators. r=dhylands. (d57c6b11da) - Bug 1187142 - Replace nsBaseHashtable::Enumerate() calls in hal/ with iterators. r=dhylands. (ec05c5b125) - Bug 1186793 - Replace nsBaseHashtable::EnumerateRead() calls in gfx/ with iterators r=njn (9b3cdd92ce) - Bug 1215900 - Fix clang's -Wimplicit-fallthrough warnings in gfx/ipc/ GfxMessageUtils.h. r=mstange (f55605f1fe) - Bug 618898 - Part 1: Add WGL_NV_DX_interop. r=jgilbert (73390398ed) - Bug 618898 - Add D3D11SharedSurfaceInterop. r=jgilbert (3dde956b85) - Bug 1208513 - Resurrect SharedSurface_GLTexture for use on iOS r=jgilbert (b0fdc90414) - Bug 1150760 - Don't call workaround unless necessary. - r=kamidphish (9bdd135931) - Bug 1151106 - let debugger stop on each iteration of a "for(;;)" loop; r=jimb (b1b921c3a7) - Bug 1223652 - Remove redundant else block after return statement in CGBlockScopeList::findEnclosingScope. r=arai (f1368bfc73) - Bug 1219515 - IonMonkey: Fix ThrowIfNotConstructing was not declared. r=evilpie (1d6cedad10) - Bug 1224044 - Use stable hashing in SavedFramePtrHasher r=terrence (4389cf1b70) - Bug 1206596: Change js::SavedStacks to use mozilla::FastBernoulliTrial. r=fitzgen (1c4a8d1929) - Bug 1206357: Add mfbt/FastBernoulliTrial.h, implementing efficient random sampling. r=waldo (7143e53dba) - No bug: Fix comment in mfbt/FastBernoulliTrial.h. DONTBUILD r=me (e3343f8d9d) - Bug 1217919 - Separate dynamic module scopes from those of function calls r=shu (521f6826e5) - Bug 1202568 - Cherry-pick warning fixes from upstream double-conversion. r=Ms2ger (ef738f753b) - add back some disabled android stuff (0351b0c518) - Bug 1135261 - return new window from window.open in desktop runtime; r=marco,smaug,junior,wesj (fa4d8f2468) - Bug 898075 - Remove the mozbrowserasyncscroll event from Gecko. r=botond,kanru,sicking (b1fdcb7630) - namespace (91374d2db8)
357 lines
10 KiB
C++
357 lines
10 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include <algorithm>
|
|
|
|
#include "gfx2DGlue.h"
|
|
#include "gfxDrawable.h"
|
|
#include "gfxPlatform.h"
|
|
#include "gfxUtils.h"
|
|
#include "ImageRegion.h"
|
|
#include "SVGImageContext.h"
|
|
|
|
#include "OrientedImage.h"
|
|
|
|
using std::swap;
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace gfx;
|
|
using layers::LayerManager;
|
|
using layers::ImageContainer;
|
|
|
|
namespace image {
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(OrientedImage, ImageWrapper)
|
|
|
|
NS_IMETHODIMP
|
|
OrientedImage::GetWidth(int32_t* aWidth)
|
|
{
|
|
if (mOrientation.SwapsWidthAndHeight()) {
|
|
return InnerImage()->GetHeight(aWidth);
|
|
} else {
|
|
return InnerImage()->GetWidth(aWidth);
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
OrientedImage::GetHeight(int32_t* aHeight)
|
|
{
|
|
if (mOrientation.SwapsWidthAndHeight()) {
|
|
return InnerImage()->GetWidth(aHeight);
|
|
} else {
|
|
return InnerImage()->GetHeight(aHeight);
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
OrientedImage::GetIntrinsicSize(nsSize* aSize)
|
|
{
|
|
nsresult rv = InnerImage()->GetIntrinsicSize(aSize);
|
|
|
|
if (mOrientation.SwapsWidthAndHeight()) {
|
|
swap(aSize->width, aSize->height);
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
OrientedImage::GetIntrinsicRatio(nsSize* aRatio)
|
|
{
|
|
nsresult rv = InnerImage()->GetIntrinsicRatio(aRatio);
|
|
|
|
if (mOrientation.SwapsWidthAndHeight()) {
|
|
swap(aRatio->width, aRatio->height);
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
OrientedImage::GetFrame(uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
nsresult rv;
|
|
|
|
if (mOrientation.IsIdentity()) {
|
|
return InnerImage()->GetFrame(aWhichFrame, aFlags);
|
|
}
|
|
|
|
// Get the underlying dimensions.
|
|
IntSize size;
|
|
rv = InnerImage()->GetWidth(&size.width);
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
rv = InnerImage()->GetHeight(&size.height);
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
// Determine an appropriate format for the surface.
|
|
gfx::SurfaceFormat surfaceFormat;
|
|
if (InnerImage()->IsOpaque()) {
|
|
surfaceFormat = gfx::SurfaceFormat::B8G8R8X8;
|
|
} else {
|
|
surfaceFormat = gfx::SurfaceFormat::B8G8R8A8;
|
|
}
|
|
|
|
// Create a surface to draw into.
|
|
RefPtr<DrawTarget> target =
|
|
gfxPlatform::GetPlatform()->
|
|
CreateOffscreenContentDrawTarget(size, surfaceFormat);
|
|
if (!target) {
|
|
NS_ERROR("Could not create a DrawTarget");
|
|
return nullptr;
|
|
}
|
|
|
|
|
|
// Create our drawable.
|
|
RefPtr<SourceSurface> innerSurface =
|
|
InnerImage()->GetFrame(aWhichFrame, aFlags);
|
|
NS_ENSURE_TRUE(innerSurface, nullptr);
|
|
RefPtr<gfxDrawable> drawable =
|
|
new gfxSurfaceDrawable(innerSurface, size);
|
|
|
|
// Draw.
|
|
RefPtr<gfxContext> ctx = new gfxContext(target);
|
|
ctx->Multiply(OrientationMatrix(size));
|
|
gfxUtils::DrawPixelSnapped(ctx, drawable, size, ImageRegion::Create(size),
|
|
surfaceFormat, Filter::LINEAR);
|
|
|
|
return target->Snapshot();
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
OrientedImage::GetFrameAtSize(const IntSize& aSize,
|
|
uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
// XXX(seth): It'd be nice to support downscale-during-decode for this case,
|
|
// but right now we just fall back to the intrinsic size.
|
|
return GetFrame(aWhichFrame, aFlags);
|
|
}
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
OrientedImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
{
|
|
if (mOrientation.IsIdentity()) {
|
|
return InnerImage()->IsImageContainerAvailable(aManager, aFlags);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
OrientedImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
|
{
|
|
// XXX(seth): We currently don't have a way of orienting the result of
|
|
// GetImageContainer. We work around this by always returning null, but if it
|
|
// ever turns out that OrientedImage is widely used on codepaths that can
|
|
// actually benefit from GetImageContainer, it would be a good idea to fix
|
|
// that method for performance reasons.
|
|
|
|
if (mOrientation.IsIdentity()) {
|
|
return InnerImage()->GetImageContainer(aManager, aFlags);
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
struct MatrixBuilder
|
|
{
|
|
explicit MatrixBuilder(bool aInvert) : mInvert(aInvert) { }
|
|
|
|
gfxMatrix Build() { return mMatrix; }
|
|
|
|
void Scale(gfxFloat aX, gfxFloat aY)
|
|
{
|
|
if (mInvert) {
|
|
mMatrix *= gfxMatrix::Scaling(1.0 / aX, 1.0 / aY);
|
|
} else {
|
|
mMatrix.Scale(aX, aY);
|
|
}
|
|
}
|
|
|
|
void Rotate(gfxFloat aPhi)
|
|
{
|
|
if (mInvert) {
|
|
mMatrix *= gfxMatrix::Rotation(-aPhi);
|
|
} else {
|
|
mMatrix.Rotate(aPhi);
|
|
}
|
|
}
|
|
|
|
void Translate(gfxPoint aDelta)
|
|
{
|
|
if (mInvert) {
|
|
mMatrix *= gfxMatrix::Translation(-aDelta);
|
|
} else {
|
|
mMatrix.Translate(aDelta);
|
|
}
|
|
}
|
|
|
|
private:
|
|
gfxMatrix mMatrix;
|
|
bool mInvert;
|
|
};
|
|
|
|
/*
|
|
* OrientationMatrix() computes a matrix that applies the rotation and
|
|
* reflection specified by mOrientation, or that matrix's inverse if aInvert is
|
|
* true.
|
|
*
|
|
* @param aSize The scaled size of the inner image. (When outside code specifies
|
|
* the scaled size, as with imgIContainer::Draw and its aSize
|
|
* parameter, it's necessary to swap the width and height if
|
|
* mOrientation.SwapsWidthAndHeight() is true.)
|
|
* @param aInvert If true, compute the inverse of the orientation matrix. Prefer
|
|
* this approach to OrientationMatrix(..).Invert(), because it's
|
|
* more numerically accurate.
|
|
*/
|
|
gfxMatrix
|
|
OrientedImage::OrientationMatrix(const nsIntSize& aSize,
|
|
bool aInvert /* = false */)
|
|
{
|
|
MatrixBuilder builder(aInvert);
|
|
|
|
// Apply reflection, if present. (This logically happens second, but we
|
|
// apply it first because these transformations are all premultiplied.) A
|
|
// translation is necessary to place the image back in the first quadrant.
|
|
switch (mOrientation.flip) {
|
|
case Flip::Unflipped:
|
|
break;
|
|
case Flip::Horizontal:
|
|
if (mOrientation.SwapsWidthAndHeight()) {
|
|
builder.Translate(gfxPoint(aSize.height, 0));
|
|
} else {
|
|
builder.Translate(gfxPoint(aSize.width, 0));
|
|
}
|
|
builder.Scale(-1.0, 1.0);
|
|
break;
|
|
default:
|
|
MOZ_ASSERT(false, "Invalid flip value");
|
|
}
|
|
|
|
// Apply rotation, if present. Again, a translation is used to place the
|
|
// image back in the first quadrant.
|
|
switch (mOrientation.rotation) {
|
|
case Angle::D0:
|
|
break;
|
|
case Angle::D90:
|
|
builder.Translate(gfxPoint(aSize.height, 0));
|
|
builder.Rotate(-1.5 * M_PI);
|
|
break;
|
|
case Angle::D180:
|
|
builder.Translate(gfxPoint(aSize.width, aSize.height));
|
|
builder.Rotate(-1.0 * M_PI);
|
|
break;
|
|
case Angle::D270:
|
|
builder.Translate(gfxPoint(0, aSize.width));
|
|
builder.Rotate(-0.5 * M_PI);
|
|
break;
|
|
default:
|
|
MOZ_ASSERT(false, "Invalid rotation value");
|
|
}
|
|
|
|
return builder.Build();
|
|
}
|
|
|
|
static SVGImageContext
|
|
OrientViewport(const SVGImageContext& aOldContext,
|
|
const Orientation& aOrientation)
|
|
{
|
|
CSSIntSize viewportSize(aOldContext.GetViewportSize());
|
|
if (aOrientation.SwapsWidthAndHeight()) {
|
|
swap(viewportSize.width, viewportSize.height);
|
|
}
|
|
return SVGImageContext(viewportSize,
|
|
aOldContext.GetPreserveAspectRatio());
|
|
}
|
|
|
|
NS_IMETHODIMP_(DrawResult)
|
|
OrientedImage::Draw(gfxContext* aContext,
|
|
const nsIntSize& aSize,
|
|
const ImageRegion& aRegion,
|
|
uint32_t aWhichFrame,
|
|
Filter aFilter,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
uint32_t aFlags)
|
|
{
|
|
if (mOrientation.IsIdentity()) {
|
|
return InnerImage()->Draw(aContext, aSize, aRegion,
|
|
aWhichFrame, aFilter, aSVGContext, aFlags);
|
|
}
|
|
|
|
// Update the image size to match the image's coordinate system. (This could
|
|
// be done using TransformBounds but since it's only a size a swap is enough.)
|
|
nsIntSize size(aSize);
|
|
if (mOrientation.SwapsWidthAndHeight()) {
|
|
swap(size.width, size.height);
|
|
}
|
|
|
|
// Update the matrix so that we transform the image into the orientation
|
|
// expected by the caller before drawing.
|
|
gfxMatrix matrix(OrientationMatrix(size));
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
|
aContext->Multiply(matrix);
|
|
|
|
// The region is already in the orientation expected by the caller, but we
|
|
// need it to be in the image's coordinate system, so we transform it using
|
|
// the inverse of the orientation matrix.
|
|
gfxMatrix inverseMatrix(OrientationMatrix(size, /* aInvert = */ true));
|
|
ImageRegion region(aRegion);
|
|
region.TransformBoundsBy(inverseMatrix);
|
|
|
|
return InnerImage()->Draw(aContext, size, region, aWhichFrame, aFilter,
|
|
aSVGContext.map(OrientViewport, mOrientation),
|
|
aFlags);
|
|
}
|
|
|
|
nsIntSize
|
|
OrientedImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
uint32_t aWhichFrame,
|
|
Filter aFilter, uint32_t aFlags)
|
|
{
|
|
if (!mOrientation.SwapsWidthAndHeight()) {
|
|
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame, aFilter,
|
|
aFlags);
|
|
}
|
|
|
|
// Swap the size for the calculation, then swap it back for the caller.
|
|
gfxSize destSize(aDest.height, aDest.width);
|
|
nsIntSize innerImageSize(InnerImage()->OptimalImageSizeForDest(destSize,
|
|
aWhichFrame,
|
|
aFilter,
|
|
aFlags));
|
|
return nsIntSize(innerImageSize.height, innerImageSize.width);
|
|
}
|
|
|
|
NS_IMETHODIMP_(nsIntRect)
|
|
OrientedImage::GetImageSpaceInvalidationRect(const nsIntRect& aRect)
|
|
{
|
|
nsIntRect rect(InnerImage()->GetImageSpaceInvalidationRect(aRect));
|
|
|
|
if (mOrientation.IsIdentity()) {
|
|
return rect;
|
|
}
|
|
|
|
nsIntSize innerSize;
|
|
nsresult rv = InnerImage()->GetWidth(&innerSize.width);
|
|
rv = NS_FAILED(rv) ? rv : InnerImage()->GetHeight(&innerSize.height);
|
|
if (NS_FAILED(rv)) {
|
|
// Fall back to identity if the width and height aren't available.
|
|
return rect;
|
|
}
|
|
|
|
// Transform the invalidation rect into the correct orientation.
|
|
gfxMatrix matrix(OrientationMatrix(innerSize));
|
|
gfxRect invalidRect(matrix.TransformBounds(gfxRect(rect.x, rect.y,
|
|
rect.width, rect.height)));
|
|
invalidRect.RoundOut();
|
|
|
|
return nsIntRect(invalidRect.x, invalidRect.y,
|
|
invalidRect.width, invalidRect.height);
|
|
}
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|