Bug 1497294 - P2. Move type related constant methods to Types.h r=nical
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 09 Oct 2018 12:56:25 +0000
changeset 496483 da3c96e21a15be08c937560c203b7abd2125ea1e
parent 496482 a6481e1de633ece58bf7ad14bdd9b1159c2d2eca
child 496484 45cbc8ce2df1db1311fa5b6e9e505d103ebed1cf
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1497294
milestone64.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 1497294 - P2. Move type related constant methods to Types.h r=nical The methods BytesPerPixel, SurfaceFormatForColorDepth, BitDepthForColorDepth, ColorDepthForBitDepth and RescalingFactorForColorDepth all directly depends on the types defined in Types.h, they also return constant values. As such it makes more sense to have them defined at the same level where the types themselves are declared. Depends on D8065 Differential Revision: https://phabricator.services.mozilla.com/D8073
gfx/2d/DrawTargetD2D1.cpp
gfx/2d/HelpersD2D.h
gfx/2d/SourceSurfaceD2D1.cpp
gfx/2d/Tools.h
gfx/2d/Types.h
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -11,17 +11,16 @@
 #include "SourceSurfaceCapture.h"
 #include "SourceSurfaceD2D1.h"
 #include "SourceSurfaceDual.h"
 #include "RadialGradientEffectD2D1.h"
 
 #include "HelpersD2D.h"
 #include "FilterNodeD2D1.h"
 #include "ExtendInputEffectD2D1.h"
-#include "Tools.h"
 #include "nsAppRunner.h"
 #include "MainThreadUtils.h"
 
 #include "mozilla/Mutex.h"
 
 using namespace std;
 
 // decltype is not usable for overloaded functions.
--- a/gfx/2d/HelpersD2D.h
+++ b/gfx/2d/HelpersD2D.h
@@ -10,17 +10,16 @@
 #include <d2d1_1.h>
 
 #include <vector>
 
 #include <dwrite.h>
 #include <versionhelpers.h>
 #include "2D.h"
 #include "Logging.h"
-#include "Tools.h"
 #include "ImageScaling.h"
 
 #include "ScaledFontDWrite.h"
 
 #undef min
 #undef max
 
 namespace mozilla {
@@ -325,17 +324,17 @@ static inline D2D1_PRIMITIVE_BLEND D2DPr
 static inline bool IsPatternSupportedByD2D(const Pattern &aPattern)
 {
   if (aPattern.GetType() != PatternType::RADIAL_GRADIENT) {
     return true;
   }
 
   const RadialGradientPattern *pat =
     static_cast<const RadialGradientPattern*>(&aPattern);
-  
+
   if (pat->mRadius1 != 0) {
     return false;
   }
 
   Point diff = pat->mCenter2 - pat->mCenter1;
 
   if (sqrt(diff.x * diff.x + diff.y * diff.y) >= pat->mRadius2) {
     // Inner point lies outside the circle.
@@ -422,17 +421,17 @@ DWriteGlyphRunFromGlyphs(const GlyphBuff
   DWRITE_GLYPH_OFFSET *offsets = const_cast<DWRITE_GLYPH_OFFSET*>(run->glyphOffsets);
 
   memset(advances, 0, sizeof(FLOAT) * aGlyphs.mNumGlyphs);
   for (unsigned int i = 0; i < aGlyphs.mNumGlyphs; i++) {
     indices[i] = aGlyphs.mGlyphs[i].mIndex;
     offsets[i].advanceOffset = aGlyphs.mGlyphs[i].mPosition.x;
     offsets[i].ascenderOffset = -aGlyphs.mGlyphs[i].mPosition.y;
   }
-    
+
   run->bidiLevel = 0;
   run->fontFace = aFont->mFontFace;
   run->fontEmSize = aFont->GetSize();
   run->glyphCount = aGlyphs.mNumGlyphs;
   run->isSideways = FALSE;
 }
 
 static inline already_AddRefed<ID2D1Geometry>
@@ -577,17 +576,17 @@ CreatePartialBitmapForSurface(DataSource
 
   IntSize size = aSurface->GetSize();
 
   Rect uploadRect(0, 0, Float(size.width), Float(size.height));
   if (aSourceRect) {
     uploadRect = Rect(aSourceRect->X(), aSourceRect->Y(), aSourceRect->Width(), aSourceRect->Height());
   }
 
-  // Limit the uploadRect as much as possible without supporting discontiguous uploads 
+  // Limit the uploadRect as much as possible without supporting discontiguous uploads
   //
   //                               region we will paint from
   //   uploadRect
   //   .---------------.              .---------------.         resulting uploadRect
   //   |               |rect          |               |
   //   |          .---------.         .----.     .----.          .---------------.
   //   |          |         |  ---->  |    |     |    |   ---->  |               |
   //   |          '---------'         '----'     '----'          '---------------'
--- a/gfx/2d/SourceSurfaceD2D1.cpp
+++ b/gfx/2d/SourceSurfaceD2D1.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "SourceSurfaceD2D1.h"
 #include "DrawTargetD2D1.h"
-#include "Tools.h"
 
 namespace mozilla {
 namespace gfx {
 
 SourceSurfaceD2D1::SourceSurfaceD2D1(ID2D1Image *aImage, ID2D1DeviceContext *aDC,
                                      SurfaceFormat aFormat, const IntSize &aSize,
                                      DrawTargetD2D1 *aDT)
   : mImage(aImage)
@@ -65,17 +64,17 @@ SourceSurfaceD2D1::GetDataSurface()
 
   if (FAILED(hr)) {
     gfxCriticalError() << "Failed to create software bitmap: " << mSize << " Code: " << hexa(hr);
     return nullptr;
   }
 
   D2D1_POINT_2U point = D2D1::Point2U(0, 0);
   D2D1_RECT_U rect = D2D1::RectU(0, 0, mSize.width, mSize.height);
-  
+
   hr = softwareBitmap->CopyFromBitmap(&point, mRealizedBitmap, &rect);
 
   if (FAILED(hr)) {
     gfxWarning() << "Failed to readback into software bitmap. Code: " << hexa(hr);
     return nullptr;
   }
 
   return MakeAndAddRef<DataSourceSurfaceD2D1>(softwareBitmap, mFormat);
--- a/gfx/2d/Tools.h
+++ b/gfx/2d/Tools.h
@@ -82,123 +82,16 @@ NudgeToInteger(double *aVal)
 }
 
 static inline Float
 Distance(Point aA, Point aB)
 {
   return hypotf(aB.x - aA.x, aB.y - aA.y);
 }
 
-static inline int
-BytesPerPixel(SurfaceFormat aFormat)
-{
-  switch (aFormat) {
-  case SurfaceFormat::A8:
-    return 1;
-  case SurfaceFormat::R5G6B5_UINT16:
-  case SurfaceFormat::A16:
-    return 2;
-  case SurfaceFormat::R8G8B8:
-  case SurfaceFormat::B8G8R8:
-    return 3;
-  case SurfaceFormat::HSV:
-  case SurfaceFormat::Lab:
-    return 3 * sizeof(float);
-  case SurfaceFormat::Depth:
-    return sizeof(uint16_t);
-  default:
-    return 4;
-  }
-}
-
-static inline SurfaceFormat
-SurfaceFormatForColorDepth(ColorDepth aColorDepth)
-{
-  SurfaceFormat format = SurfaceFormat::A8;
-  switch (aColorDepth) {
-    case ColorDepth::COLOR_8:
-      break;
-    case ColorDepth::COLOR_10:
-    case ColorDepth::COLOR_12:
-    case ColorDepth::COLOR_16:
-      format = SurfaceFormat::A16;
-      break;
-    case ColorDepth::UNKNOWN:
-      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
-  }
-  return format;
-}
-
-static inline uint32_t
-BitDepthForColorDepth(ColorDepth aColorDepth)
-{
-  uint32_t depth = 8;
-  switch (aColorDepth) {
-    case ColorDepth::COLOR_8:
-      break;
-    case ColorDepth::COLOR_10:
-      depth = 10;
-      break;
-    case ColorDepth::COLOR_12:
-      depth = 12;
-      break;
-    case ColorDepth::COLOR_16:
-      depth = 16;
-      break;
-    case ColorDepth::UNKNOWN:
-      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
-  }
-  return depth;
-}
-
-static inline ColorDepth
-ColorDepthForBitDepth(uint8_t aBitDepth)
-{
-  ColorDepth depth = ColorDepth::COLOR_8;
-  switch (aBitDepth) {
-    case 8:
-      break;
-    case 10:
-      depth = ColorDepth::COLOR_10;
-      break;
-    case 12:
-      depth = ColorDepth::COLOR_12;
-      break;
-    case 16:
-      depth = ColorDepth::COLOR_16;
-      break;
-    default:
-      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
-  }
-  return depth;
-}
-
-// 10 and 12 bits color depth image are using 16 bits integers for storage
-// As such we need to rescale the value from 10 or 12 bits to 16.
-static inline uint32_t
-RescalingFactorForColorDepth(ColorDepth aColorDepth)
-{
-  uint32_t factor = 1;
-  switch (aColorDepth) {
-    case ColorDepth::COLOR_8:
-      break;
-    case ColorDepth::COLOR_10:
-      factor = 64;
-      break;
-    case ColorDepth::COLOR_12:
-      factor = 16;
-      break;
-    case ColorDepth::COLOR_16:
-      break;
-    case ColorDepth::UNKNOWN:
-      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
-  }
-  return factor;
-}
-
 template<typename T, int alignment = 16>
 struct AlignedArray
 {
   typedef T value_type;
 
   AlignedArray()
     : mPtr(nullptr)
     , mStorage(nullptr)
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -82,16 +82,38 @@ enum class SurfaceFormat : int8_t {
 #elif MOZ_BIG_ENDIAN
   A8R8G8B8_UINT32 = A8R8G8B8,       // 0xAARRGGBB
   X8R8G8B8_UINT32 = X8R8G8B8        // 0x00RRGGBB
 #else
 # error "bad endianness"
 #endif
 };
 
+static inline int
+BytesPerPixel(SurfaceFormat aFormat)
+{
+  switch (aFormat) {
+  case SurfaceFormat::A8:
+    return 1;
+  case SurfaceFormat::R5G6B5_UINT16:
+  case SurfaceFormat::A16:
+    return 2;
+  case SurfaceFormat::R8G8B8:
+  case SurfaceFormat::B8G8R8:
+    return 3;
+  case SurfaceFormat::HSV:
+  case SurfaceFormat::Lab:
+    return 3 * sizeof(float);
+  case SurfaceFormat::Depth:
+    return sizeof(uint16_t);
+  default:
+    return 4;
+  }
+}
+
 inline bool IsOpaque(SurfaceFormat aFormat)
 {
   switch (aFormat) {
   case SurfaceFormat::B8G8R8X8:
   case SurfaceFormat::R8G8B8X8:
   case SurfaceFormat::X8R8G8B8:
   case SurfaceFormat::R5G6B5_UINT16:
   case SurfaceFormat::R8G8B8:
@@ -112,16 +134,101 @@ inline bool IsOpaque(SurfaceFormat aForm
 enum class ColorDepth : uint8_t {
   COLOR_8,
   COLOR_10,
   COLOR_12,
   COLOR_16,
   UNKNOWN
 };
 
+static inline SurfaceFormat
+SurfaceFormatForColorDepth(ColorDepth aColorDepth)
+{
+  SurfaceFormat format = SurfaceFormat::A8;
+  switch (aColorDepth) {
+    case ColorDepth::COLOR_8:
+      break;
+    case ColorDepth::COLOR_10:
+    case ColorDepth::COLOR_12:
+    case ColorDepth::COLOR_16:
+      format = SurfaceFormat::A16;
+      break;
+    case ColorDepth::UNKNOWN:
+      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
+  }
+  return format;
+}
+
+static inline uint32_t
+BitDepthForColorDepth(ColorDepth aColorDepth)
+{
+  uint32_t depth = 8;
+  switch (aColorDepth) {
+    case ColorDepth::COLOR_8:
+      break;
+    case ColorDepth::COLOR_10:
+      depth = 10;
+      break;
+    case ColorDepth::COLOR_12:
+      depth = 12;
+      break;
+    case ColorDepth::COLOR_16:
+      depth = 16;
+      break;
+    case ColorDepth::UNKNOWN:
+      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
+  }
+  return depth;
+}
+
+static inline ColorDepth
+ColorDepthForBitDepth(uint8_t aBitDepth)
+{
+  ColorDepth depth = ColorDepth::COLOR_8;
+  switch (aBitDepth) {
+    case 8:
+      break;
+    case 10:
+      depth = ColorDepth::COLOR_10;
+      break;
+    case 12:
+      depth = ColorDepth::COLOR_12;
+      break;
+    case 16:
+      depth = ColorDepth::COLOR_16;
+      break;
+    default:
+      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
+  }
+  return depth;
+}
+
+// 10 and 12 bits color depth image are using 16 bits integers for storage
+// As such we need to rescale the value from 10 or 12 bits to 16.
+static inline uint32_t
+RescalingFactorForColorDepth(ColorDepth aColorDepth)
+{
+  uint32_t factor = 1;
+  switch (aColorDepth) {
+    case ColorDepth::COLOR_8:
+      break;
+    case ColorDepth::COLOR_10:
+      factor = 64;
+      break;
+    case ColorDepth::COLOR_12:
+      factor = 16;
+      break;
+    case ColorDepth::COLOR_16:
+      break;
+    case ColorDepth::UNKNOWN:
+      MOZ_ASSERT_UNREACHABLE("invalid color depth value");
+  }
+  return factor;
+}
+
 enum class FilterType : int8_t {
   BLEND = 0,
   TRANSFORM,
   MORPHOLOGY,
   COLOR_MATRIX,
   FLOOD,
   TILE,
   TABLE_TRANSFER,