LCOV - code coverage report
Current view: top level - gfx/src - nsPoint.h (source / functions) Hit Total Coverage
Test: output.info Lines: 15 33 45.5 %
Date: 2017-07-14 16:53:18 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef NSPOINT_H
       7             : #define NSPOINT_H
       8             : 
       9             : #include "nsCoord.h"
      10             : #include "mozilla/gfx/BaseSize.h"
      11             : #include "mozilla/gfx/BasePoint.h"
      12             : #include "nsSize.h"
      13             : #include "mozilla/gfx/Point.h"
      14             : 
      15             : // nsIntPoint represents a point in one of the types of pixels.
      16             : // Uses of nsIntPoint should eventually be converted to CSSIntPoint,
      17             : // LayoutDeviceIntPoint, etc. (see layout/base/Units.h).
      18             : typedef mozilla::gfx::IntPoint nsIntPoint;
      19             : 
      20             : // nsPoint represents a point in app units.
      21             : 
      22             : struct nsPoint : public mozilla::gfx::BasePoint<nscoord, nsPoint> {
      23             :   typedef mozilla::gfx::BasePoint<nscoord, nsPoint> Super;
      24             : 
      25        9770 :   nsPoint() : Super() {}
      26        9525 :   nsPoint(const nsPoint& aPoint) : Super(aPoint) {}
      27       75736 :   nsPoint(nscoord aX, nscoord aY) : Super(aX, aY) {}
      28             : 
      29             :   inline nsIntPoint ScaleToNearestPixels(float aXScale, float aYScale,
      30             :                                          nscoord aAppUnitsPerPixel) const;
      31             :   inline nsIntPoint ToNearestPixels(nscoord aAppUnitsPerPixel) const;
      32             : 
      33             :   /**
      34             :    * Return this point scaled to a different appunits per pixel (APP) ratio.
      35             :    * @param aFromAPP the APP to scale from
      36             :    * @param aToAPP the APP to scale to
      37             :    */
      38             :   MOZ_MUST_USE inline nsPoint
      39             :     ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const;
      40             : 
      41             :   MOZ_MUST_USE inline nsPoint
      42             :     RemoveResolution(const float resolution) const;
      43             :   MOZ_MUST_USE inline nsPoint
      44             :     ApplyResolution(const float resolution) const;
      45             : };
      46             : 
      47             : inline nsPoint ToAppUnits(const nsIntPoint& aPoint, nscoord aAppUnitsPerPixel);
      48             : 
      49             : inline nsIntPoint
      50          38 : nsPoint::ScaleToNearestPixels(float aXScale, float aYScale,
      51             :                               nscoord aAppUnitsPerPixel) const
      52             : {
      53         114 :   return nsIntPoint(
      54          38 :       NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel) * aXScale),
      55         114 :       NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel) * aYScale));
      56             : }
      57             : 
      58             : inline nsIntPoint
      59          38 : nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const
      60             : {
      61          38 :   return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel);
      62             : }
      63             : 
      64             : inline nsPoint
      65        3634 : nsPoint::ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const
      66             : {
      67        3634 :   if (aFromAPP != aToAPP) {
      68           0 :     nsPoint point;
      69           0 :     point.x = NSToCoordRound(NSCoordScale(x, aFromAPP, aToAPP));
      70           0 :     point.y = NSToCoordRound(NSCoordScale(y, aFromAPP, aToAPP));
      71           0 :     return point;
      72             :   }
      73        3634 :   return *this;
      74             : }
      75             : 
      76             : inline nsPoint
      77          80 : nsPoint::RemoveResolution(const float resolution) const {
      78          80 :   if (resolution != 1.0f) {
      79           0 :     nsPoint point;
      80           0 :     point.x = NSToCoordRound(NSCoordToFloat(x) / resolution);
      81           0 :     point.y = NSToCoordRound(NSCoordToFloat(y) / resolution);
      82           0 :     return point;
      83             :   }
      84          80 :   return *this;
      85             : }
      86             : 
      87             : inline nsPoint
      88           0 : nsPoint::ApplyResolution(const float resolution) const {
      89           0 :   if (resolution != 1.0f) {
      90           0 :     nsPoint point;
      91           0 :     point.x = NSToCoordRound(NSCoordToFloat(x) * resolution);
      92           0 :     point.y = NSToCoordRound(NSCoordToFloat(y) * resolution);
      93           0 :     return point;
      94             :   }
      95           0 :   return *this;
      96             : }
      97             : 
      98             : // app units are integer multiples of pixels, so no rounding needed
      99             : inline nsPoint
     100           0 : ToAppUnits(const nsIntPoint& aPoint, nscoord aAppUnitsPerPixel)
     101             : {
     102           0 :   return nsPoint(NSIntPixelsToAppUnits(aPoint.x, aAppUnitsPerPixel),
     103           0 :                  NSIntPixelsToAppUnits(aPoint.y, aAppUnitsPerPixel));
     104             : }
     105             : 
     106             : #endif /* NSPOINT_H */

Generated by: LCOV version 1.13