Bug 637852. Part 25: Add nsSize ScaleToNearestPixels. r=tnikkel
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 23 Jun 2011 00:11:28 +1200
changeset 71540 8b1e793fbf453feba15297386293b28b07cb4bc9
parent 71539 c18bdf8b0b761731e0f6de7d28a4e9ac57a6c5d3
child 71541 21a67ac790f182203db671c485118544e3970d58
push idunknown
push userunknown
push dateunknown
reviewerstnikkel
bugs637852
milestone7.0a1
Bug 637852. Part 25: Add nsSize ScaleToNearestPixels. r=tnikkel
gfx/src/nsSize.h
--- a/gfx/src/nsSize.h
+++ b/gfx/src/nsSize.h
@@ -39,33 +39,47 @@
 #define NSSIZE_H
 
 #include "nsCoord.h"
 #include "mozilla/BaseSize.h"
 
 // Maximum allowable size
 #define NS_MAXSIZE nscoord_MAX
 
+struct nsIntSize;
+
 struct nsSize : public mozilla::BaseSize<nscoord, nsSize> {
   typedef mozilla::BaseSize<nscoord, nsSize> Super;
 
   nsSize() : Super() {}
   nsSize(nscoord aWidth, nscoord aHeight) : Super(aWidth, aHeight) {}
 
+  inline nsIntSize ScaleToNearestPixels(float aXScale, float aYScale,
+                                        nscoord aAppUnitsPerPixel) const;
+
   // Converts this size from aFromAPP, an appunits per pixel ratio, to aToAPP.
   inline nsSize ConvertAppUnits(PRInt32 aFromAPP, PRInt32 aToAPP) const;
 };
 
 struct nsIntSize : public mozilla::BaseSize<PRInt32, nsIntSize> {
   typedef mozilla::BaseSize<PRInt32, nsIntSize> Super;
 
   nsIntSize() : Super() {}
   nsIntSize(PRInt32 aWidth, PRInt32 aHeight) : Super(aWidth, aHeight) {}
 };
 
+inline nsIntSize
+nsSize::ScaleToNearestPixels(float aXScale, float aYScale,
+                             nscoord aAppUnitsPerPixel) const
+{
+  return nsIntSize(
+      NSToIntRoundUp(NSAppUnitsToDoublePixels(width, aAppUnitsPerPixel) * aXScale),
+      NSToIntRoundUp(NSAppUnitsToDoublePixels(height, aAppUnitsPerPixel) * aYScale));
+}
+
 inline nsSize
 nsSize::ConvertAppUnits(PRInt32 aFromAPP, PRInt32 aToAPP) const {
   if (aFromAPP != aToAPP) {
     nsSize size;
     size.width = NSToCoordRound(NSCoordScale(width, aFromAPP, aToAPP));
     size.height = NSToCoordRound(NSCoordScale(height, aFromAPP, aToAPP));
     return size;
   }