Bug 736134 - Part 1: Add GlyphRenderingOptions API to Azure. r=jrmuizel

This commit is contained in:
Bas Schouten 2012-03-19 19:20:17 +00:00
parent f84a537689
commit ef709193e2
11 changed files with 76 additions and 9 deletions

View File

@ -55,6 +55,7 @@ typedef _cairo_scaled_font cairo_scaled_font_t;
struct ID3D10Device1;
struct ID3D10Texture2D;
struct IDWriteRenderingParams;
namespace mozilla {
namespace gfx {
@ -488,6 +489,23 @@ 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
* parameters.
*/
class GlyphRenderingOptions : public RefCounted<GlyphRenderingOptions>
{
public:
virtual ~GlyphRenderingOptions() {}
virtual FontType GetType() const = 0;
protected:
GlyphRenderingOptions() {}
};
/* This is the main class used for all the drawing. It is created through the
* factory and accepts drawing commands. The results of drawing to a target
* may be used either through a Snapshot or by flushing the target and directly
@ -640,7 +658,8 @@ public:
virtual void FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions = DrawOptions()) = 0;
const DrawOptions &aOptions = DrawOptions(),
const GlyphRenderingOptions *aRenderingOptions = NULL) = 0;
/*
* This takes a source pattern and a mask, and composites the source pattern
@ -806,6 +825,9 @@ public:
static void SetDirect3D10Device(ID3D10Device1 *aDevice);
static ID3D10Device1 *GetDirect3D10Device();
static TemporaryRef<GlyphRenderingOptions>
CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams);
private:
static ID3D10Device1 *mD3D10Device;
#endif

View File

@ -699,7 +699,8 @@ DrawTargetCG::Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions
void
DrawTargetCG::FillGlyphs(ScaledFont *aFont, const GlyphBuffer &aBuffer, const Pattern &aPattern, const DrawOptions &aDrawOptions)
DrawTargetCG::FillGlyphs(ScaledFont *aFont, const GlyphBuffer &aBuffer, const Pattern &aPattern, const DrawOptions &aDrawOptions,
const GlyphRenderingOptions*)
{
MarkChanged();

View File

@ -147,7 +147,7 @@ public:
virtual void StrokeLine(const Point &, const Point &, const Pattern &, const StrokeOptions &, const DrawOptions &);
virtual void Stroke(const Path *, const Pattern &, const StrokeOptions &, const DrawOptions &);
virtual void Fill(const Path *, const Pattern &, const DrawOptions &);
virtual void FillGlyphs(ScaledFont *, const GlyphBuffer&, const Pattern &, const DrawOptions &);
virtual void FillGlyphs(ScaledFont *, const GlyphBuffer&, const Pattern &, const DrawOptions &, const GlyphRenderingOptions *);
virtual void Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions = DrawOptions());

View File

@ -587,7 +587,8 @@ void
DrawTargetCairo::FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions)
const DrawOptions &aOptions,
const GlyphRenderingOptions*)
{
AutoPrepareForDrawing prep(this, mContext);

View File

@ -125,7 +125,8 @@ public:
virtual void FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions);
const DrawOptions &aOptions,
const GlyphRenderingOptions *aRenderingOptions = NULL);
virtual void Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions = DrawOptions());

View File

@ -880,7 +880,8 @@ void
DrawTargetD2D::FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions)
const DrawOptions &aOptions,
const GlyphRenderingOptions* aRenderOptions)
{
if (aFont->GetType() != FONT_DWRITE) {
gfxDebug() << *this << ": Ignoring drawing call for incompatible font.";
@ -893,6 +894,19 @@ DrawTargetD2D::FillGlyphs(ScaledFont *aFont,
PrepareForDrawing(rt);
IDWriteRenderingParams *params = NULL;
if (aRenderOptions) {
if (aRenderOptions->GetType() != FONT_DWRITE) {
gfxDebug() << *this << ": Ignoring incompatible GlyphRenderingOptions.";
// This should never happen.
MOZ_ASSERT(false);
} else {
params = static_cast<const GlyphRenderingOptionsDWrite*>(aRenderOptions)->mParams;
}
}
rt->SetTextRenderingParams(params);
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
DWRITE_GLYPH_RUN glyphRun;

View File

@ -117,7 +117,8 @@ public:
virtual void FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions = DrawOptions());
const DrawOptions &aOptions = DrawOptions(),
const GlyphRenderingOptions *aRenderingOptions = NULL);
virtual void Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions = DrawOptions());

View File

@ -543,7 +543,8 @@ void
DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions)
const DrawOptions &aOptions,
const GlyphRenderingOptions*)
{
if (aFont->GetType() != FONT_MAC && aFont->GetType() != FONT_SKIA) {
return;

View File

@ -98,7 +98,8 @@ public:
virtual void FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions = DrawOptions());
const DrawOptions &aOptions = DrawOptions(),
const GlyphRenderingOptions *aRenderingOptions = NULL);
virtual void Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions = DrawOptions());

View File

@ -217,6 +217,15 @@ Factory::GetDirect3D10Device()
return mD3D10Device;
}
TemporaryRef<GlyphRenderingOptions>
Factory::CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams)
{
RefPtr<GlyphRenderingOptions> options =
new GlyphRenderingOptionsDWrite(aParams);
return options;
}
#endif // XP_WIN
#ifdef USE_CAIRO

View File

@ -63,6 +63,22 @@ private:
Float mSize;
};
class GlyphRenderingOptionsDWrite : public GlyphRenderingOptions
{
public:
GlyphRenderingOptionsDWrite(IDWriteRenderingParams *aParams)
: mParams(aParams)
{
}
virtual FontType GetType() const { return FONT_DWRITE; }
private:
friend class DrawTargetD2D;
RefPtr<IDWriteRenderingParams> mParams;
};
}
}