Bug 738691 - Part 1: Add CopyGlyphsToBuilder API. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Thu, 29 Mar 2012 20:53:44 +0200
changeset 93963 89dfa68488e46e07149f030d3886b830ec07902d
parent 93962 23fb4940211498334437a9db79d202763736445d
child 93964 1b468e61ac0257d7004381811135cd65a1d1a964
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs738691
milestone14.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 738691 - Part 1: Add CopyGlyphsToBuilder API. r=jrmuizel
gfx/2d/2D.h
gfx/2d/ScaledFontBase.cpp
gfx/2d/ScaledFontBase.h
gfx/2d/ScaledFontDWrite.cpp
gfx/2d/ScaledFontDWrite.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -480,16 +480,23 @@ public:
 
   /* This allows getting a path that describes the outline of a set of glyphs.
    * A target is passed in so that the guarantee is made the returned path
    * can be used with any DrawTarget that has the same backend as the one
    * passed in.
    */
   virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget) = 0;
 
+  /* This copies the path describing the glyphs into a PathBuilder. We use this
+   * API rather than a generic API to append paths because it allows easier
+   * implementation in some backends, and more efficient implementation in
+   * others.
+   */
+  virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder) = 0;
+
 protected:
   ScaledFont() {}
 };
 
 /* This class is designed to allow passing additional glyph rendering
  * parameters to the glyph drawing functions. This is an empty wrapper class
  * merely used to allow holding on to and passing around platform specific
  * parameters. This is because different platforms have unique rendering
--- a/gfx/2d/ScaledFontBase.cpp
+++ b/gfx/2d/ScaledFontBase.cpp
@@ -127,16 +127,24 @@ ScaledFontBase::GetPathForGlyphs(const G
     cairo_glyph_path(*context, &glyphs[0], aBuffer.mNumGlyphs);
 
     return builder->Finish();
   }
 #endif
   return NULL;
 }
 
+void
+ScaledFontBase::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder)
+{
+  // XXX - implement me
+  MOZ_ASSERT(false);
+  return;
+}
+
 #ifdef USE_CAIRO
 void
 ScaledFontBase::SetCairoScaledFont(cairo_scaled_font_t* font)
 {
   MOZ_ASSERT(!mScaledFont);
 
   mScaledFont = font;
   cairo_scaled_font_reference(mScaledFont);
--- a/gfx/2d/ScaledFontBase.h
+++ b/gfx/2d/ScaledFontBase.h
@@ -54,16 +54,19 @@ namespace gfx {
 
 class ScaledFontBase : public ScaledFont
 {
 public:
   ScaledFontBase(Float aSize);
   virtual ~ScaledFontBase();
 
   virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
+
+  virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder);
+
 #ifdef USE_SKIA
   virtual SkTypeface* GetSkTypeface() { return mTypeface; }
 #endif
 
   // Not true, but required to instantiate a ScaledFontBase.
   virtual FontType GetType() const { return FONT_SKIA; }
 
 #ifdef USE_CAIRO
--- a/gfx/2d/ScaledFontDWrite.cpp
+++ b/gfx/2d/ScaledFontDWrite.cpp
@@ -51,31 +51,47 @@ ScaledFontDWrite::GetPathForGlyphs(const
     return NULL;
   }
 
   RefPtr<PathBuilder> pathBuilder = aTarget->CreatePathBuilder();
 
   PathBuilderD2D *pathBuilderD2D =
     static_cast<PathBuilderD2D*>(pathBuilder.get());
 
+  CopyGlyphsToSink(aBuffer, pathBuilderD2D->GetSink());
+
+  return pathBuilder->Finish();
+}
+
+void
+ScaledFontDWrite::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder)
+{
+  // XXX - Check path builder type!
+  PathBuilderD2D *pathBuilderD2D =
+    static_cast<PathBuilderD2D*>(aBuilder);
+
+  CopyGlyphsToSink(aBuffer, pathBuilderD2D->GetSink());
+}
+
+void
+ScaledFontDWrite::CopyGlyphsToSink(const GlyphBuffer &aBuffer, ID2D1GeometrySink *aSink)
+{
   std::vector<UINT16> indices;
   std::vector<FLOAT> advances;
   std::vector<DWRITE_GLYPH_OFFSET> offsets;
   indices.resize(aBuffer.mNumGlyphs);
   advances.resize(aBuffer.mNumGlyphs);
   offsets.resize(aBuffer.mNumGlyphs);
 
   memset(&advances.front(), 0, sizeof(FLOAT) * aBuffer.mNumGlyphs);
   for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
     indices[i] = aBuffer.mGlyphs[i].mIndex;
     offsets[i].advanceOffset = aBuffer.mGlyphs[i].mPosition.x;
     offsets[i].ascenderOffset = -aBuffer.mGlyphs[i].mPosition.y;
   }
 
   mFontFace->GetGlyphRunOutline(mSize, &indices.front(), &advances.front(),
                                 &offsets.front(), aBuffer.mNumGlyphs,
-                                FALSE, FALSE, pathBuilderD2D->GetSink());
-
-  return pathBuilder->Finish();
+                                FALSE, FALSE, aSink);
 }
 
 }
 }
--- a/gfx/2d/ScaledFontDWrite.h
+++ b/gfx/2d/ScaledFontDWrite.h
@@ -36,34 +36,39 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef MOZILLA_GFX_SCALEDFONTDWRITE_H_
 #define MOZILLA_GFX_SCALEDFONTDWRITE_H_
 
 #include "2D.h"
 #include <dwrite.h>
 
+struct ID2D1GeometrySink;
+
 namespace mozilla {
 namespace gfx {
 
 class ScaledFontDWrite : public ScaledFont
 {
 public:
   ScaledFontDWrite(IDWriteFontFace *aFont, Float aSize)
     : mFontFace(aFont)
     , mSize(aSize)
   {}
 
   virtual FontType GetType() const { return FONT_DWRITE; }
 
   virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
+  virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder);
 
 private:
   friend class DrawTargetD2D;
 
+  void CopyGlyphsToSink(const GlyphBuffer &aBuffer, ID2D1GeometrySink *aSink);
+
   RefPtr<IDWriteFontFace> mFontFace;
   Float mSize;
 };
 
 class GlyphRenderingOptionsDWrite : public GlyphRenderingOptions
 {
 public:
   GlyphRenderingOptionsDWrite(IDWriteRenderingParams *aParams)