Bug 944646 - Implement Skia path in ScaledFontBase::CopyGlyphsToBuilder. r=mattwoodrow
authorKevin Simons <kevin@comoyo.com>
Thu, 12 Dec 2013 17:37:00 -0500
changeset 160288 1f6ecbf2aac3a612b1df30b6f37e453cea83ae13
parent 160287 064eb6b0604d11a411cef41d9f9cef4c2b53f748
child 160289 a9804d9b47c7fcbcf2f1cb3e0b43e12e6bbaca3b
push id25827
push userkwierso@gmail.com
push dateFri, 13 Dec 2013 03:13:04 +0000
treeherdermozilla-central@1bc33fa19b24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs944646
milestone29.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 944646 - Implement Skia path in ScaledFontBase::CopyGlyphsToBuilder. r=mattwoodrow Handle PathBuilderSkia with a separate path specifically for BACKEND_SKIA DrawTarget instances.
gfx/2d/PathSkia.cpp
gfx/2d/PathSkia.h
gfx/2d/ScaledFontBase.cpp
gfx/2d/ScaledFontBase.h
--- a/gfx/2d/PathSkia.cpp
+++ b/gfx/2d/PathSkia.cpp
@@ -104,16 +104,22 @@ PathBuilderSkia::CurrentPoint() const
 
 TemporaryRef<Path>
 PathBuilderSkia::Finish()
 {
   RefPtr<PathSkia> path = new PathSkia(mPath, mFillRule);
   return path;
 }
 
+void
+PathBuilderSkia::AppendPath(const SkPath &aPath)
+{
+  mPath.addPath(aPath);
+}
+
 TemporaryRef<PathBuilder>
 PathSkia::CopyToBuilder(FillRule aFillRule) const
 {
   return TransformedCopyToBuilder(Matrix(), aFillRule);
 }
 
 TemporaryRef<PathBuilder>
 PathSkia::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
--- a/gfx/2d/PathSkia.h
+++ b/gfx/2d/PathSkia.h
@@ -28,17 +28,20 @@ public:
   virtual void QuadraticBezierTo(const Point &aCP1,
                                  const Point &aCP2);
   virtual void Close();
   virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
                    float aEndAngle, bool aAntiClockwise = false);
   virtual Point CurrentPoint() const;
   virtual TemporaryRef<Path> Finish();
 
+  void AppendPath(const SkPath &aPath);
+
 private:
+
   void SetFillRule(FillRule aFillRule);
 
   SkPath mPath;
   FillRule mFillRule;
 };
 
 class PathSkia : public Path
 {
--- a/gfx/2d/ScaledFontBase.cpp
+++ b/gfx/2d/ScaledFontBase.cpp
@@ -2,18 +2,18 @@
  * 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 "ScaledFontBase.h"
 
 #ifdef USE_SKIA
 #include "PathSkia.h"
+#include "skia/SkEmptyShader.h"
 #include "skia/SkPaint.h"
-#include "skia/SkPath.h"
 #endif
 
 #ifdef USE_CAIRO
 #include "PathCairo.h"
 #include "DrawTargetCairo.h"
 #include "HelpersCairo.h"
 #endif
 
@@ -41,39 +41,51 @@ ScaledFontBase::ScaledFontBase(Float aSi
 #ifdef USE_SKIA
   mTypeface = nullptr;
 #endif
 #ifdef USE_CAIRO_SCALED_FONT
   mScaledFont = nullptr;
 #endif
 }
 
+#ifdef USE_SKIA
+SkPath
+ScaledFontBase::GetSkiaPathForGlyphs(const GlyphBuffer &aBuffer)
+{
+  SkTypeface *typeFace = GetSkTypeface();
+  MOZ_ASSERT(typeFace);
+
+  SkPaint paint;
+  paint.setTypeface(typeFace);
+  paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+  paint.setTextSize(SkFloatToScalar(mSize));
+
+  std::vector<uint16_t> indices;
+  std::vector<SkPoint> offsets;
+  indices.resize(aBuffer.mNumGlyphs);
+  offsets.resize(aBuffer.mNumGlyphs);
+
+  for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
+    indices[i] = aBuffer.mGlyphs[i].mIndex;
+    offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
+    offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
+  }
+
+  SkPath path;
+  paint.getPosTextPath(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), &path);
+  return path;
+}
+#endif
+
 TemporaryRef<Path>
 ScaledFontBase::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
 {
 #ifdef USE_SKIA
   if (aTarget->GetType() == BACKEND_SKIA) {
-    SkPaint paint;
-    paint.setTypeface(GetSkTypeface());
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-    paint.setTextSize(SkFloatToScalar(mSize));
-
-    std::vector<uint16_t> indices;
-    std::vector<SkPoint> offsets;
-    indices.resize(aBuffer.mNumGlyphs);
-    offsets.resize(aBuffer.mNumGlyphs);
-
-    for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
-      indices[i] = aBuffer.mGlyphs[i].mIndex;
-      offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
-      offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
-    }
-
-    SkPath path;
-    paint.getPosTextPath(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), &path);
+    SkPath path = GetSkiaPathForGlyphs(aBuffer);
     return new PathSkia(path, FILL_WINDING);
   }
 #endif
 #ifdef USE_CAIRO
   if (aTarget->GetType() == BACKEND_CAIRO) {
     MOZ_ASSERT(mScaledFont);
 
     DrawTarget *dt = const_cast<DrawTarget*>(aTarget);
@@ -110,16 +122,23 @@ ScaledFontBase::GetPathForGlyphs(const G
   }
 #endif
   return nullptr;
 }
 
 void
 ScaledFontBase::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint)
 {
+#ifdef USE_SKIA
+  if (aBackendType == BACKEND_SKIA) {
+    PathBuilderSkia *builder = static_cast<PathBuilderSkia*>(aBuilder);
+    builder->AppendPath(GetSkiaPathForGlyphs(aBuffer));
+    return;
+  }
+#endif
 #ifdef USE_CAIRO
   if (aBackendType == BACKEND_CAIRO) {
     MOZ_ASSERT(mScaledFont);
 
     PathBuilderCairo* builder = static_cast<PathBuilderCairo*>(aBuilder);
     cairo_t *ctx = cairo_create(DrawTargetCairo::GetDummySurface());
 
     if (aTransformHint) {
--- a/gfx/2d/ScaledFontBase.h
+++ b/gfx/2d/ScaledFontBase.h
@@ -9,16 +9,17 @@
 #include "2D.h"
 
 // Skia uses cairo_scaled_font_t as the internal font type in ScaledFont
 #if defined(USE_SKIA) || defined(USE_CAIRO)
 #define USE_CAIRO_SCALED_FONT
 #endif
 
 #ifdef USE_SKIA
+#include "skia/SkPath.h"
 #include "skia/SkTypeface.h"
 #endif
 #ifdef USE_CAIRO_SCALED_FONT
 #include "cairo.h"
 #endif
 
 class gfxFont;
 
@@ -48,16 +49,17 @@ public:
   cairo_scaled_font_t* GetCairoScaledFont() { return mScaledFont; }
   void SetCairoScaledFont(cairo_scaled_font_t* font);
 #endif
 
 protected:
   friend class DrawTargetSkia;
 #ifdef USE_SKIA
   SkTypeface* mTypeface;
+  SkPath GetSkiaPathForGlyphs(const GlyphBuffer &aBuffer);
 #endif
 #ifdef USE_CAIRO_SCALED_FONT
   cairo_scaled_font_t* mScaledFont;
 #endif
   Float mSize;
 };
 
 }