Skip to content

Commit

Permalink
Bug 1102048 (Part 04, ClippedImage) - Make image/src files comply wit…
Browse files Browse the repository at this point in the history
…h the Mozilla Coding Style Guide. r=seth
  • Loading branch information
glennrp committed Apr 4, 2015
1 parent 3eda954 commit bcf05b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
42 changes: 25 additions & 17 deletions image/src/ClippedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,17 @@ 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.
// 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.
// 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) {
Expand All @@ -146,11 +147,12 @@ ClippedImage::ShouldClip()

// 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)));
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 memoizing
// clipping with be needed or not for now. Just return without memorizing
// anything.
return false;
} else {
Expand Down Expand Up @@ -279,7 +281,7 @@ ClippedImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
return InnerImage()->GetImageContainer(aManager, aFlags);
}

return nullptr;
return (nullptr);
}

static bool
Expand Down Expand Up @@ -347,7 +349,8 @@ UnclipViewport(const SVGImageContext& aOldContext,
// 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);
vSize.height =
ceil(vSize.height * double(innerSize.height) / clipSize.height);

return SVGImageContext(vSize,
aOldContext.GetPreserveAspectRatio());
Expand All @@ -371,13 +374,14 @@ ClippedImage::DrawSingleTile(gfxContext* aContext,
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");
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
Expand Down Expand Up @@ -414,11 +418,13 @@ ClippedImage::GetOrientation()
}

nsIntSize
ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest,
uint32_t aWhichFrame,
GraphicsFilter aFilter, uint32_t aFlags)
{
if (!ShouldClip()) {
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame, aFilter, aFlags);
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame, aFilter,
aFlags);
}

int32_t imgWidth, imgHeight;
Expand All @@ -427,8 +433,8 @@ ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame
// 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.
// 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));

Expand All @@ -446,8 +452,10 @@ ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame
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);
MOZ_ASSERT(false,
"If ShouldClip() led us to draw then we should never get here");
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame, aFilter,
aFlags);
}
}

Expand Down
9 changes: 5 additions & 4 deletions image/src/ClippedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* 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/. */

#ifndef MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_
#define MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_
#ifndef mozilla_image_src_ClippedImage_h
#define mozilla_image_src_ClippedImage_h

#include "ImageWrapper.h"
#include "mozilla/gfx/2D.h"
Expand Down Expand Up @@ -49,7 +49,8 @@ class ClippedImage : public ImageWrapper
uint32_t aFlags) override;
NS_IMETHOD RequestDiscard() override;
NS_IMETHOD_(Orientation) GetOrientation() override;
NS_IMETHOD_(nsIntRect) GetImageSpaceInvalidationRect(const nsIntRect& aRect) override;
NS_IMETHOD_(nsIntRect) GetImageSpaceInvalidationRect(const nsIntRect& aRect)
override;
nsIntSize OptimalImageSizeForDest(const gfxSize& aDest,
uint32_t aWhichFrame,
GraphicsFilter aFilter,
Expand Down Expand Up @@ -88,4 +89,4 @@ class ClippedImage : public ImageWrapper
} // namespace image
} // namespace mozilla

#endif // MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_
#endif // mozilla_image_src_ClippedImage_h

0 comments on commit bcf05b9

Please sign in to comment.