Bug 1528881 - Part 3: gfx: Move FAST_DIVIDE_BY_255 macro definition to nsColor.cpp. r=jrmuizel
authorChris Peterson <cpeterson@mozilla.com>
Tue, 21 Aug 2018 22:04:13 -0700
changeset 519494 43d876b370317974ccc221278551be1b509d1647
parent 519493 d87672a996677236c209cc6a067a84b9fb92e0e5
child 519495 53e277d161b2d43dccbc3b294ef14212bd4f9314
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1528881
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1528881 - Part 3: gfx: Move FAST_DIVIDE_BY_255 macro definition to nsColor.cpp. r=jrmuizel FAST_DIVIDE_BY_255 was defined in nsColor.h but only used in nsColor.cpp. Differential Revision: https://phabricator.services.mozilla.com/D20262
gfx/src/nsColor.cpp
gfx/src/nsColor.h
--- a/gfx/src/nsColor.cpp
+++ b/gfx/src/nsColor.cpp
@@ -201,16 +201,28 @@ bool NS_ColorNameToRGB(const nsAString& 
     if (aResult) {
       *aResult = kColors[id];
     }
     return true;
   }
   return false;
 }
 
+// Fast approximate division by 255. It has the property that
+// for all 0 <= n <= 255*255, FAST_DIVIDE_BY_255(n) == n/255.
+// But it only uses two adds and two shifts instead of an
+// integer division (which is expensive on many processors).
+//
+// equivalent to target=v/255
+#define FAST_DIVIDE_BY_255(target, v)        \
+  PR_BEGIN_MACRO                             \
+  unsigned tmp_ = v;                         \
+  target = ((tmp_ << 8) + tmp_ + 255) >> 16; \
+  PR_END_MACRO
+
 // Macro to blend two colors
 //
 // equivalent to target = (bg*(255-fgalpha) + fg*fgalpha)/255
 #define MOZ_BLEND(target, bg, fg, fgalpha) \
   FAST_DIVIDE_BY_255(target, (bg) * (255 - fgalpha) + (fg) * (fgalpha))
 
 nscolor NS_ComposeColors(nscolor aBG, nscolor aFG) {
   // This function uses colors that are non premultiplied alpha.
--- a/gfx/src/nsColor.h
+++ b/gfx/src/nsColor.h
@@ -43,28 +43,16 @@ inline uint8_t ClampColor(T aColor) {
   if (aColor <= 0) {
     return 0;
   }
   return NSToIntRound(aColor);
 }
 
 }  // namespace mozilla
 
-// Fast approximate division by 255. It has the property that
-// for all 0 <= n <= 255*255, FAST_DIVIDE_BY_255(n) == n/255.
-// But it only uses two adds and two shifts instead of an
-// integer division (which is expensive on many processors).
-//
-// equivalent to target=v/255
-#define FAST_DIVIDE_BY_255(target, v)        \
-  PR_BEGIN_MACRO                             \
-  unsigned tmp_ = v;                         \
-  target = ((tmp_ << 8) + tmp_ + 255) >> 16; \
-  PR_END_MACRO
-
 enum class nsHexColorType : uint8_t {
   NoAlpha,     // 3 or 6 digit hex colors only
   AllowAlpha,  // 3, 4, 6, or 8 digit hex colors
 };
 
 // Translate a hex string to a color. Return true if it parses ok,
 // otherwise return false.
 // This accepts the number of digits specified by aType.