Bug 1248708 - Part2.1: use mfbt/TypedEnumBits.h for DrawMode. r=jwatt
authorJeremy Chen <jeremychen@mozilla.com>
Thu, 21 Apr 2016 23:27:39 +0800
changeset 332212 954e40c927979cc5569e2247ad632d5c0874a5f6
parent 332211 b41c3ceb94d42a39b31349e6e29b227521fc15b8
child 332213 8222fad19eab75e7e68178ab8d4071be10df689e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1248708
milestone48.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 1248708 - Part2.1: use mfbt/TypedEnumBits.h for DrawMode. r=jwatt
gfx/thebes/DrawMode.h
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxTextRun.cpp
layout/svg/SVGTextFrame.cpp
--- a/gfx/thebes/DrawMode.h
+++ b/gfx/thebes/DrawMode.h
@@ -1,25 +1,26 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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/. */
 
 #ifndef DrawMode_h
 #define DrawMode_h
 
+#include "mozilla/TypedEnumBits.h"
+
 // Options for how the text should be drawn
 enum class DrawMode : int {
   // GLYPH_FILL and GLYPH_STROKE draw into the current context
   //  and may be used together with bitwise OR.
-  GLYPH_FILL = 1,
+  GLYPH_FILL = 1 << 0,
   // Note: using GLYPH_STROKE will destroy the current path.
-  GLYPH_STROKE = 2,
+  GLYPH_STROKE = 1 << 1,
   // Appends glyphs to the current path. Can NOT be used with
   //  GLYPH_FILL or GLYPH_STROKE.
-  GLYPH_PATH = 4,
+  GLYPH_PATH = 1 << 2,
   // When GLYPH_FILL and GLYPH_STROKE are both set, draws the
   //  stroke underneath the fill.
-  GLYPH_STROKE_UNDERNEATH = 8
+  GLYPH_STROKE_UNDERNEATH = 1 << 3
 };
-
+MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DrawMode)
 #endif
-
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -1605,22 +1605,22 @@ private:
             std::reverse(begin, end);
         }
 
         gfx::GlyphBuffer buf;
         buf.mGlyphs = mGlyphBuffer;
         buf.mNumGlyphs = mNumGlyphs;
 
         gfxContext::AzureState state = mRunParams.context->CurrentState();
-        if ((int(mRunParams.drawMode) &
-            (int(DrawMode::GLYPH_STROKE) | int(DrawMode::GLYPH_STROKE_UNDERNEATH))) ==
-            (int(DrawMode::GLYPH_STROKE) | int(DrawMode::GLYPH_STROKE_UNDERNEATH))) {
+        if ((mRunParams.drawMode &
+             (DrawMode::GLYPH_STROKE | DrawMode::GLYPH_STROKE_UNDERNEATH)) ==
+            (DrawMode::GLYPH_STROKE | DrawMode::GLYPH_STROKE_UNDERNEATH)) {
             FlushStroke(buf, state);
         }
-        if (int(mRunParams.drawMode) & int(DrawMode::GLYPH_FILL)) {
+        if (mRunParams.drawMode & DrawMode::GLYPH_FILL) {
             if (state.pattern || mFontParams.contextPaint) {
                 Pattern *pat;
 
                 RefPtr<gfxPattern> fillPattern;
                 if (!mFontParams.contextPaint ||
                     !(fillPattern = mFontParams.contextPaint->GetFillPattern(
                                         mRunParams.context->GetDrawTarget(),
                                         mRunParams.context->CurrentMatrix()))) {
@@ -1677,26 +1677,26 @@ private:
                                           mFontParams.renderingOptions);
             } else {
                 mRunParams.dt->FillGlyphs(mFontParams.scaledFont, buf,
                                           ColorPattern(state.color),
                                           mFontParams.drawOptions,
                                           mFontParams.renderingOptions);
             }
         }
-        if (int(mRunParams.drawMode) & int(DrawMode::GLYPH_PATH)) {
+        if (mRunParams.drawMode & DrawMode::GLYPH_PATH) {
             mRunParams.context->EnsurePathBuilder();
             Matrix mat = mRunParams.dt->GetTransform();
             mFontParams.scaledFont->CopyGlyphsToBuilder(
                 buf, mRunParams.context->mPathBuilder,
                 mRunParams.dt->GetBackendType(), &mat);
         }
-        if ((int(mRunParams.drawMode) &
-            (int(DrawMode::GLYPH_STROKE) | int(DrawMode::GLYPH_STROKE_UNDERNEATH))) ==
-             int(DrawMode::GLYPH_STROKE)) {
+        if ((mRunParams.drawMode &
+             (DrawMode::GLYPH_STROKE | DrawMode::GLYPH_STROKE_UNDERNEATH)) ==
+            DrawMode::GLYPH_STROKE) {
             FlushStroke(buf, state);
         }
 
         mNumGlyphs = 0;
     }
 
     void FlushStroke(gfx::GlyphBuffer& aBuf, gfxContext::AzureState& aState)
     {
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -564,17 +564,17 @@ struct BufferAlphaColor {
     gfxContext *mContext;
 };
 
 void
 gfxTextRun::Draw(Range aRange, gfxPoint aPt, const DrawParams& aParams)
 {
     NS_ASSERTION(aRange.end <= GetLength(), "Substring out of range");
     NS_ASSERTION(aParams.drawMode == DrawMode::GLYPH_PATH ||
-                 !(int(aParams.drawMode) & int(DrawMode::GLYPH_PATH)),
+                 !(aParams.drawMode & DrawMode::GLYPH_PATH),
                  "GLYPH_PATH cannot be used with GLYPH_FILL, GLYPH_STROKE or GLYPH_STROKE_UNDERNEATH");
     NS_ASSERTION(aParams.drawMode == DrawMode::GLYPH_PATH || !aParams.callbacks,
                  "callback must not be specified unless using GLYPH_PATH");
 
     bool skipDrawing = mSkipDrawing;
     if (aParams.drawMode == DrawMode::GLYPH_FILL) {
         Color currentColor;
         if (aParams.context->GetDeviceColor(currentColor) &&
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3734,17 +3734,17 @@ SVGTextFrame::PaintSVG(gfxContext& aCont
     // when they use context-fill etc.
     aContext.SetMatrix(initialMatrix);
 
     SVGTextContextPaint contextPaint;
     DrawMode drawMode =
       SetupContextPaint(&aDrawTarget, aContext.CurrentMatrix(),
                         frame, outerContextPaint, &contextPaint);
 
-    if (int(drawMode) & int(DrawMode::GLYPH_STROKE)) {
+    if (drawMode & DrawMode::GLYPH_STROKE) {
       // This may change the gfxContext's transform (for non-scaling stroke),
       // in which case this needs to happen before we call SetMatrix() below.
       nsSVGUtils::SetupCairoStrokeGeometry(frame, &aContext, outerContextPaint);
     }
 
     // Set up the transform for painting the text frame for the substring
     // indicated by the run.
     gfxMatrix runTransform =
@@ -5800,17 +5800,17 @@ SVGTextFrame::SetupContextPaint(const Dr
 
     SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
                           opacity, aOuterContextPaint,
                           aThisContextPaint->mFillPaint, &nsStyleSVG::mFill,
                           nsSVGEffects::FillProperty());
 
     aThisContextPaint->SetFillOpacity(opacity);
 
-    toDraw = DrawMode(int(toDraw) | int(DrawMode::GLYPH_FILL));
+    toDraw |= DrawMode::GLYPH_FILL;
   }
 
   // stroke:
   if (style->mStroke.mType == eStyleSVGPaintType_None) {
     aThisContextPaint->SetStrokeOpacity(0.0f);
   } else {
     float opacity = nsSVGUtils::GetOpacity(style->mStrokeOpacitySource,
                                            style->mStrokeOpacity,
@@ -5818,13 +5818,13 @@ SVGTextFrame::SetupContextPaint(const Dr
 
     SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
                           opacity, aOuterContextPaint,
                           aThisContextPaint->mStrokePaint, &nsStyleSVG::mStroke,
                           nsSVGEffects::StrokeProperty());
 
     aThisContextPaint->SetStrokeOpacity(opacity);
 
-    toDraw = DrawMode(int(toDraw) | int(DrawMode::GLYPH_STROKE));
+    toDraw |= DrawMode::GLYPH_STROKE;
   }
 
   return toDraw;
 }