mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 05:11:03 +00:00
e1776c67f8
- Bug 1199885 - Part 2: Add AsyncDragMetrics. r=kats (220a4f445e)
- Bug 1149482 - Localize the 'none' string for APZ in about:support. r=dvander (3e0128f62e)
- Bug 1199885 - Part 3: Add 'apz.drag.enabled' preference for async scrollbars. r=kats (5133061d3f)
- Bug 1199885 - Part 4: Let the hit testing tree know about the scroll thumb. r=kats (26a9a69443)
- Bug 1199885 - Part 5: Make mRootLayerTreeID const to prove that there's no data races. r=kats (88e2eb80f1)
- Bug 1199885 - Part 8: Add FindScrollNode to locate the scrollbar thumb. r=kats (a545ec9569)
- Bug 1199885 - Part 9: Let APZC handle the drag events. r=kats (4cc0f88153)
- Bug 1199885 - Part 9.5: Make the mouse events APZC aware. r=kats (69bd4caf94)
- Bug 1199885 - Part 10: Add APZTeeManager API to start an async scroll. r=kats (e212ee2750)
- Bug 1199885 - Part 12: Add StartScrollbarDrag IPC message. r=kats (705af3b233)
- Bug 1199885 - Part 13: Let nsSliderFrame trigger async scrolling via StartScrollbarDrag. r=kats (d31b5a790d)
- put in gstreamer as of 2015-10-05 Bug 1146482 (7cca45858c)
- pointer style (f8041af438)
- Bug 1197097 - Don't use a context-wide cycle-detection mechanism for detecting cycles during JSON.stringify. This prevents nested (yet separate) JSON.stringify, and it causes that algorithm to be affected by specification-unrelated operations like toSource. r=jonco (09652471c1)
- align to ugly grammaer of 1114782 (c760693693)
- remove space (7158a0c2bf)
- align to FF/TFF (27138a55bb)
- Bug 1205887 - Verify that MOZILLA_VERSION was set correctly, r=glandium (2269e8f31b)
- Bug 1205012 - Allow rust source code in SpiderMonkey; r=mshal (9ebca9ed28)
- Bug 1197281 - Use MOZ_FIND_WINSDK_VERSION for MOZ_WINSDK_MAXVER on mingw. r=glandium (2910b2160e)
- Bug 1207893 - Refactor how build backend execution is summarized. r=gps (56d8fecbc2)
- Bug 1207893 - Allow to create multiple build backends at once. r=gps (d8cba87d2b)
- Bug 1207897 - Add a configure option to build multiple build backends. r=gps (f9c7851d02)
- Bug 1188555 - part 1 - remove write-only configure.in variable NO_LD_ARCHIVE_FLAGS; r=mshal (461958b100)
- Bug 1188555 - part 2 - remove write-only configure.in variables MKSHLIB_{UN,}FORCE_ALL; r=mshal (1813210dda)
- Bug 1207882 - Ensure chrome manifests are created in a directory that exists when processing jar manifests. r=gps (59165a64cb)
- Bug 1204712 - Handle wildcards properly for localized content in jar manifests. r=gps (54dfb632c7)
- Bug 1188551: treat assertion failures as bad mozconfig; r=mshal (e307769de7)
- Bug 1181040 - Set ${var}_IS_SET variables for mk_add_options-defined variables. r=gps (19f169556b)
- Bug 1193015 - Require MOZ_GLX_USE_SURFACE_SHARING to enable WebGL surface sharing on GLX. r=jgilbert (9aa4fa8f41)
- Bug 1211324 (part 1) - Remove BILINEAR and GAUSSIAN filter constants. (3d9290ef02)
- Bug 1211324 (part 2) - Make gfx::FILTER::GOOD convert to GraphicsFilter::FILTER_GOOD. r=mattwoodrow. (16e7607c70)
- Bug 1208365 (part 1) - Remove unused EXTEND_PAD_EDGE. r=Bas. (10920e2bb6)
- Bug 1208365 (part 2) - Remove gfxPattern::Extend(). r=bas. (3703b9748a)
- Bug 1208365 (part 3) - Change gfxPattern::mExtend from a GraphicsExtend to a gfx::ExtendMode. r=bas. (b105d06e91)
- Bug 1208365 (part 4) - Remove gfxPattern::GraphicsExtend. r=bas. (7a16d48995)
- Bug 1211324 (part 3) - Remove GraphicsFilter::FILTER_FAST and replace it with FILTER_BEST. r=mattwoodrow. (b5101e049f)
- Bug 1211324 (part 4) - Replace GraphicsFilter constants with gfx::Filter equivalents. r=mattwoodrow. (c19b6b030e)
- Bug 1190117 - Track mLastProducerID and mLastFrameID explicitly in ImageLayerProperties. r=roc (ed9a5c777f)
- Bug 1211324 (part 5) - Remove GraphicsFilter and gfxGraphicsFilter. r=mattwoodrow. (0bd4ce7160)
- Bug 1194954 - Fix -Wunreachable-code warnings in gfx/layers and gfx/thebes. r=BenWa (1a3d68c490)
- Bug 1180509 - Fix judder of icons in Australis doorhanger menu at the end of its scale-in animation. r=roc (9b4df470fa)
- Bug 1206915 - Make paint dumping to a file e10s-friendly. r=mattwoodrow (87d2e12c2b)
- Bug 1206915 - Handle nested PaintFrame() calls correctly during paint dumping. r=mattwoodrow,BenWa (d30f77fbdd)
- Fix max texture size handling in displayport clamping. (bug 1135907 follow-up, r=kats) (a791894332)
- Fix bogus assertion in nsLayoutUtils::SetDisplayPortMargins. (bug 1156409, r=botond, a=philor) (b635b21c34)
- Bug 1169879 - Use only the critical displayport when computing image visibility. r=tn (9ec91c9527)
- Bug 1169881 - Recompute image visibility when display port margins change. r=tn (35a5bd3a51)
- Bug 1197765 - Compare text content inside frame instead of the content node for ruby autohiding. r=dbaron (00cf5b7674)
- Bug 1173580 - Record content descriptions in APZ test data. r=kats (7a72d1ac0a)
- Bug 1178971 - Changed line snapping behaviour depending on even/odd-ness of stroke width. r=mstange (495b32dc23)
- Bug 1208953: [mp3] Don't parse data we've already parsed. r=cpearce (72eed4309f)
- Bug 1137151: Marked destructor of |android::MediaCodecReader| as protected, r=sotaro (0632b34bc5)
- Bug 1205351 - Replace nsBaseHashtable::Enumerate() calls in dom/media/ with iterators r=cpearce (45976c24c0)
- Bug 1133624 - Add lang-specific ruby rules to ua.css. r=dbaron (46788cc220)
- Bug 1133624 - followup add fuzzy maxdiff on CLOSED TREE (1b6b62aded)
- Bug 1180443 - Consider whitespace collapse when calculating intrinsic isize of ruby. r=dbaron (3862184acd)
- Bug 1153764 - Avoid explicitly doing break before when there is ruby span. r=roc (71b4ec7749)
- add gstreamer parts (7e562556be)
- some preferences aligned to FF (b26d0b389c)
- Bug 1166301 - If APZ is enabled, clip fixed background images at the layer level rather than the display item level. r=mattwoodrow (5644e22090)
- Bug 1144990 - Dump display items with class id and name, r=roc (aa2e227e35)
- Bug 1205087 - Remove LayerManager parameter for ShouldFixToViewport. r=roc (00a1f2e36f)
- Bug 1205087 - Make nsSVGIntegrationUtils paint frame continuations manually since combining them meant that our reference frame wasn't an ancestor of all painted frames. r=roc (e40f6b7b81)
- Bug 1195400 - Check ancestor geometry roots when determining scrollability of a layer. r=mattwoodrow (4699b7e935)
- Bug 1205087 - Cache the AnimatedGeometryRoot on DisplayItem. r=roc (06bba311c3)
- Back out the bits of bug 1205087 that cache the AnimatedGeometryRoot on DisplayItem. r=backout (254057a6b6)
- Bug 1203190 - Don't intersect with the visible rect for fixed background images. r=mattwoodrow (1c5a432459)
- Bug 1208438 - Don't allow layers with scrolling clips to occlusion-cull layers behind them. r=mattwoodrow (c3d77a9846)
- Bug 1205630 - Translate a fixed background display item's clip rect correctly when setting it on the layer. r=mstange (49039f0e2d)
- Bug 1205630 - Reftest. r=mstange (a8db59eaee)
- Bug 1105832 - Also dump inactive layer managers when display list dumping is enabled. r=mattwoodrow (564fe5fcbc)
- Bug 1208661 - Move Dump() up from ContentClient to CompositableClient. r=BenWa (37915312b3)
497 lines
16 KiB
C++
497 lines
16 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 <new> // Workaround for bug in VS10; see bug 981264.
|
|
#include <cmath>
|
|
#include <utility>
|
|
|
|
#include "gfxDrawable.h"
|
|
#include "gfxPlatform.h"
|
|
#include "gfxUtils.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "ImageRegion.h"
|
|
#include "Orientation.h"
|
|
#include "SVGImageContext.h"
|
|
|
|
#include "ClippedImage.h"
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace gfx;
|
|
using layers::LayerManager;
|
|
using layers::ImageContainer;
|
|
using std::make_pair;
|
|
using std::modf;
|
|
using std::pair;
|
|
|
|
namespace image {
|
|
|
|
class ClippedImageCachedSurface
|
|
{
|
|
public:
|
|
ClippedImageCachedSurface(already_AddRefed<SourceSurface> aSurface,
|
|
const nsIntSize& aSize,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
float aFrame,
|
|
uint32_t aFlags)
|
|
: mSurface(aSurface)
|
|
, mSize(aSize)
|
|
, mFrame(aFrame)
|
|
, mFlags(aFlags)
|
|
{
|
|
MOZ_ASSERT(mSurface, "Must have a valid surface");
|
|
if (aSVGContext) {
|
|
mSVGContext.emplace(*aSVGContext);
|
|
}
|
|
}
|
|
|
|
bool Matches(const nsIntSize& aSize,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
float aFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
return mSize == aSize &&
|
|
mSVGContext == aSVGContext &&
|
|
mFrame == aFrame &&
|
|
mFlags == aFlags;
|
|
}
|
|
|
|
already_AddRefed<SourceSurface> Surface() {
|
|
RefPtr<SourceSurface> surf(mSurface);
|
|
return surf.forget();
|
|
}
|
|
|
|
private:
|
|
RefPtr<SourceSurface> mSurface;
|
|
const nsIntSize mSize;
|
|
Maybe<SVGImageContext> mSVGContext;
|
|
const float mFrame;
|
|
const uint32_t mFlags;
|
|
};
|
|
|
|
class DrawSingleTileCallback : public gfxDrawingCallback
|
|
{
|
|
public:
|
|
DrawSingleTileCallback(ClippedImage* aImage,
|
|
const nsIntSize& aSize,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
: mImage(aImage)
|
|
, mSize(aSize)
|
|
, mSVGContext(aSVGContext)
|
|
, mWhichFrame(aWhichFrame)
|
|
, mFlags(aFlags)
|
|
{
|
|
MOZ_ASSERT(mImage, "Must have an image to clip");
|
|
}
|
|
|
|
virtual bool operator()(gfxContext* aContext,
|
|
const gfxRect& aFillRect,
|
|
const Filter& aFilter,
|
|
const gfxMatrix& aTransform)
|
|
{
|
|
MOZ_ASSERT(aTransform.IsIdentity(),
|
|
"Caller is probably CreateSamplingRestrictedDrawable, "
|
|
"which should not happen");
|
|
|
|
// Draw the image. |gfxCallbackDrawable| always calls this function with
|
|
// arguments that guarantee we never tile.
|
|
mImage->DrawSingleTile(aContext, mSize, ImageRegion::Create(aFillRect),
|
|
mWhichFrame, aFilter, mSVGContext, mFlags);
|
|
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
nsRefPtr<ClippedImage> mImage;
|
|
const nsIntSize mSize;
|
|
const Maybe<SVGImageContext>& mSVGContext;
|
|
const uint32_t mWhichFrame;
|
|
const uint32_t mFlags;
|
|
};
|
|
|
|
ClippedImage::ClippedImage(Image* aImage,
|
|
nsIntRect aClip)
|
|
: ImageWrapper(aImage)
|
|
, mClip(aClip)
|
|
{
|
|
MOZ_ASSERT(aImage != nullptr, "ClippedImage requires an existing Image");
|
|
}
|
|
|
|
ClippedImage::~ClippedImage()
|
|
{ }
|
|
|
|
bool
|
|
ClippedImage::ShouldClip()
|
|
{
|
|
// We need to evaluate the clipping region against the image's width and
|
|
// height once they're available to determine if it's valid and whether we
|
|
// actually need to do any work. We may fail if the image's width and height
|
|
// aren't available yet, in which case we'll try again later.
|
|
if (mShouldClip.isNothing()) {
|
|
int32_t width, height;
|
|
nsRefPtr<ProgressTracker> progressTracker =
|
|
InnerImage()->GetProgressTracker();
|
|
if (InnerImage()->HasError()) {
|
|
// If there's a problem with the inner image we'll let it handle
|
|
// everything.
|
|
mShouldClip.emplace(false);
|
|
} else if (NS_SUCCEEDED(InnerImage()->GetWidth(&width)) && width > 0 &&
|
|
NS_SUCCEEDED(InnerImage()->GetHeight(&height)) && height > 0) {
|
|
// Clamp the clipping region to the size of the underlying image.
|
|
mClip = mClip.Intersect(nsIntRect(0, 0, width, height));
|
|
|
|
// If the clipping region is the same size as the underlying image we
|
|
// don't have to do anything.
|
|
mShouldClip.emplace(!mClip.IsEqualInterior(nsIntRect(0, 0, width,
|
|
height)));
|
|
} else if (progressTracker &&
|
|
!(progressTracker->GetProgress() & FLAG_LOAD_COMPLETE)) {
|
|
// The image just hasn't finished loading yet. We don't yet know whether
|
|
// clipping with be needed or not for now. Just return without memorizing
|
|
// anything.
|
|
return false;
|
|
} else {
|
|
// We have a fully loaded image without a clearly defined width and
|
|
// height. This can happen with SVG images.
|
|
mShouldClip.emplace(false);
|
|
}
|
|
}
|
|
|
|
MOZ_ASSERT(mShouldClip.isSome(), "Should have computed a result");
|
|
return *mShouldClip;
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(ClippedImage, ImageWrapper)
|
|
|
|
NS_IMETHODIMP
|
|
ClippedImage::GetWidth(int32_t* aWidth)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->GetWidth(aWidth);
|
|
}
|
|
|
|
*aWidth = mClip.width;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
ClippedImage::GetHeight(int32_t* aHeight)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->GetHeight(aHeight);
|
|
}
|
|
|
|
*aHeight = mClip.height;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
ClippedImage::GetIntrinsicSize(nsSize* aSize)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->GetIntrinsicSize(aSize);
|
|
}
|
|
|
|
*aSize = nsSize(mClip.width, mClip.height);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
ClippedImage::GetIntrinsicRatio(nsSize* aRatio)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->GetIntrinsicRatio(aRatio);
|
|
}
|
|
|
|
*aRatio = nsSize(mClip.width, mClip.height);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
ClippedImage::GetFrame(uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
return GetFrameInternal(mClip.Size(), Nothing(), aWhichFrame, aFlags);
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
ClippedImage::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);
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
ClippedImage::GetFrameInternal(const nsIntSize& aSize,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->GetFrame(aWhichFrame, aFlags);
|
|
}
|
|
|
|
float frameToDraw = InnerImage()->GetFrameIndex(aWhichFrame);
|
|
if (!mCachedSurface || !mCachedSurface->Matches(aSize,
|
|
aSVGContext,
|
|
frameToDraw,
|
|
aFlags)) {
|
|
// Create a surface to draw into.
|
|
RefPtr<DrawTarget> target = gfxPlatform::GetPlatform()->
|
|
CreateOffscreenContentDrawTarget(IntSize(aSize.width, aSize.height),
|
|
SurfaceFormat::B8G8R8A8);
|
|
if (!target) {
|
|
NS_ERROR("Could not create a DrawTarget");
|
|
return nullptr;
|
|
}
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(target);
|
|
|
|
// Create our callback.
|
|
nsRefPtr<gfxDrawingCallback> drawTileCallback =
|
|
new DrawSingleTileCallback(this, aSize, aSVGContext, aWhichFrame, aFlags);
|
|
nsRefPtr<gfxDrawable> drawable =
|
|
new gfxCallbackDrawable(drawTileCallback, aSize);
|
|
|
|
// Actually draw. The callback will end up invoking DrawSingleTile.
|
|
gfxUtils::DrawPixelSnapped(ctx, drawable, aSize,
|
|
ImageRegion::Create(aSize),
|
|
SurfaceFormat::B8G8R8A8,
|
|
Filter::LINEAR,
|
|
imgIContainer::FLAG_CLAMP);
|
|
|
|
// Cache the resulting surface.
|
|
mCachedSurface = new ClippedImageCachedSurface(target->Snapshot(), aSize,
|
|
aSVGContext, frameToDraw,
|
|
aFlags);
|
|
}
|
|
|
|
MOZ_ASSERT(mCachedSurface, "Should have a cached surface now");
|
|
return mCachedSurface->Surface();
|
|
}
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
ClippedImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->IsImageContainerAvailable(aManager, aFlags);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
ClippedImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
|
{
|
|
// XXX(seth): We currently don't have a way of clipping the result of
|
|
// GetImageContainer. We work around this by always returning null, but if it
|
|
// ever turns out that ClippedImage 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 (!ShouldClip()) {
|
|
return InnerImage()->GetImageContainer(aManager, aFlags);
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
static bool
|
|
MustCreateSurface(gfxContext* aContext,
|
|
const nsIntSize& aSize,
|
|
const ImageRegion& aRegion,
|
|
const uint32_t aFlags)
|
|
{
|
|
gfxRect imageRect(0, 0, aSize.width, aSize.height);
|
|
bool willTile = !imageRect.Contains(aRegion.Rect()) &&
|
|
!(aFlags & imgIContainer::FLAG_CLAMP);
|
|
bool willResample = aContext->CurrentMatrix().HasNonIntegerTranslation() &&
|
|
(willTile || !aRegion.RestrictionContains(imageRect));
|
|
return willTile || willResample;
|
|
}
|
|
|
|
NS_IMETHODIMP_(DrawResult)
|
|
ClippedImage::Draw(gfxContext* aContext,
|
|
const nsIntSize& aSize,
|
|
const ImageRegion& aRegion,
|
|
uint32_t aWhichFrame,
|
|
Filter aFilter,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
uint32_t aFlags)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->Draw(aContext, aSize, aRegion, aWhichFrame,
|
|
aFilter, aSVGContext, aFlags);
|
|
}
|
|
|
|
// Check for tiling. If we need to tile then we need to create a
|
|
// gfxCallbackDrawable to handle drawing for us.
|
|
if (MustCreateSurface(aContext, aSize, aRegion, aFlags)) {
|
|
// Create a temporary surface containing a single tile of this image.
|
|
// GetFrame will call DrawSingleTile internally.
|
|
RefPtr<SourceSurface> surface =
|
|
GetFrameInternal(aSize, aSVGContext, aWhichFrame, aFlags);
|
|
if (!surface) {
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
}
|
|
|
|
// Create a drawable from that surface.
|
|
nsRefPtr<gfxSurfaceDrawable> drawable =
|
|
new gfxSurfaceDrawable(surface, aSize);
|
|
|
|
// Draw.
|
|
gfxUtils::DrawPixelSnapped(aContext, drawable, aSize, aRegion,
|
|
SurfaceFormat::B8G8R8A8, aFilter);
|
|
|
|
return DrawResult::SUCCESS;
|
|
}
|
|
|
|
return DrawSingleTile(aContext, aSize, aRegion, aWhichFrame,
|
|
aFilter, aSVGContext, aFlags);
|
|
}
|
|
|
|
static SVGImageContext
|
|
UnclipViewport(const SVGImageContext& aOldContext,
|
|
const pair<nsIntSize, nsIntSize>& aInnerAndClipSize)
|
|
{
|
|
nsIntSize innerSize(aInnerAndClipSize.first);
|
|
nsIntSize clipSize(aInnerAndClipSize.second);
|
|
|
|
// Map the viewport to the inner image. (Note that we don't take the aSize
|
|
// parameter of Draw into account, just the clipping region.)
|
|
CSSIntSize vSize(aOldContext.GetViewportSize());
|
|
vSize.width = ceil(vSize.width * double(innerSize.width) / clipSize.width);
|
|
vSize.height =
|
|
ceil(vSize.height * double(innerSize.height) / clipSize.height);
|
|
|
|
return SVGImageContext(vSize,
|
|
aOldContext.GetPreserveAspectRatio());
|
|
}
|
|
|
|
DrawResult
|
|
ClippedImage::DrawSingleTile(gfxContext* aContext,
|
|
const nsIntSize& aSize,
|
|
const ImageRegion& aRegion,
|
|
uint32_t aWhichFrame,
|
|
Filter aFilter,
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(!MustCreateSurface(aContext, aSize, aRegion, aFlags),
|
|
"Shouldn't need to create a surface");
|
|
|
|
gfxRect clip(mClip.x, mClip.y, mClip.width, mClip.height);
|
|
nsIntSize size(aSize), innerSize(aSize);
|
|
if (NS_SUCCEEDED(InnerImage()->GetWidth(&innerSize.width)) &&
|
|
NS_SUCCEEDED(InnerImage()->GetHeight(&innerSize.height))) {
|
|
double scaleX = aSize.width / clip.width;
|
|
double scaleY = aSize.height / clip.height;
|
|
|
|
// Map the clip and size to the scale requested by the caller.
|
|
clip.Scale(scaleX, scaleY);
|
|
size = innerSize;
|
|
size.Scale(scaleX, scaleY);
|
|
} else {
|
|
MOZ_ASSERT(false,
|
|
"If ShouldClip() led us to draw then we should never get here");
|
|
}
|
|
|
|
// We restrict our drawing to only the clipping region, and translate so that
|
|
// the clipping region is placed at the position the caller expects.
|
|
ImageRegion region(aRegion);
|
|
region.MoveBy(clip.x, clip.y);
|
|
region = region.Intersect(clip);
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
|
aContext->Multiply(gfxMatrix::Translation(-clip.x, -clip.y));
|
|
|
|
return InnerImage()->Draw(aContext, size, region,
|
|
aWhichFrame, aFilter,
|
|
aSVGContext.map(UnclipViewport,
|
|
make_pair(innerSize, mClip.Size())),
|
|
aFlags);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
ClippedImage::RequestDiscard()
|
|
{
|
|
// We're very aggressive about discarding.
|
|
mCachedSurface = nullptr;
|
|
|
|
return InnerImage()->RequestDiscard();
|
|
}
|
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
ClippedImage::GetOrientation()
|
|
{
|
|
// XXX(seth): This should not actually be here; this is just to work around a
|
|
// what appears to be a bug in MSVC's linker.
|
|
return InnerImage()->GetOrientation();
|
|
}
|
|
|
|
nsIntSize
|
|
ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
uint32_t aWhichFrame,
|
|
Filter aFilter, uint32_t aFlags)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame, aFilter,
|
|
aFlags);
|
|
}
|
|
|
|
int32_t imgWidth, imgHeight;
|
|
if (NS_SUCCEEDED(InnerImage()->GetWidth(&imgWidth)) &&
|
|
NS_SUCCEEDED(InnerImage()->GetHeight(&imgHeight))) {
|
|
// To avoid ugly sampling artifacts, ClippedImage needs the image size to
|
|
// be chosen such that the clipping region lies on pixel boundaries.
|
|
|
|
// First, we select a scale that's good for ClippedImage. An integer
|
|
// multiple of the size of the clipping region is always fine.
|
|
nsIntSize scale(ceil(aDest.width / mClip.width),
|
|
ceil(aDest.height / mClip.height));
|
|
|
|
// Determine the size we'd prefer to render the inner image at, and ask the
|
|
// inner image what size we should actually use.
|
|
gfxSize desiredSize(imgWidth * scale.width, imgHeight * scale.height);
|
|
nsIntSize innerDesiredSize =
|
|
InnerImage()->OptimalImageSizeForDest(desiredSize, aWhichFrame,
|
|
aFilter, aFlags);
|
|
|
|
// To get our final result, we take the inner image's desired size and
|
|
// determine how large the clipped region would be at that scale. (Again, we
|
|
// ensure an integer multiple of the size of the clipping region.)
|
|
nsIntSize finalScale(ceil(double(innerDesiredSize.width) / imgWidth),
|
|
ceil(double(innerDesiredSize.height) / imgHeight));
|
|
return mClip.Size() * finalScale;
|
|
} else {
|
|
MOZ_ASSERT(false,
|
|
"If ShouldClip() led us to draw then we should never get here");
|
|
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame, aFilter,
|
|
aFlags);
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP_(nsIntRect)
|
|
ClippedImage::GetImageSpaceInvalidationRect(const nsIntRect& aRect)
|
|
{
|
|
if (!ShouldClip()) {
|
|
return InnerImage()->GetImageSpaceInvalidationRect(aRect);
|
|
}
|
|
|
|
nsIntRect rect(InnerImage()->GetImageSpaceInvalidationRect(aRect));
|
|
rect = rect.Intersect(mClip);
|
|
rect.MoveBy(-mClip.x, -mClip.y);
|
|
return rect;
|
|
}
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|