Bug 1058040, part 7 - Make SVGContextPaint a ref counted class. r=dholbert

This commit is contained in:
Jonathan Watt 2017-01-09 19:12:02 +00:00
parent 927266bad9
commit de51524080
3 changed files with 20 additions and 9 deletions

View File

@ -2073,15 +2073,15 @@ gfxFont::Draw(const gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
aRunParams.context->SetMatrix(mat);
}
UniquePtr<SVGContextPaint> contextPaint;
RefPtr<SVGContextPaint> contextPaint;
if (fontParams.haveSVGGlyphs && !fontParams.contextPaint) {
// If no pattern is specified for fill, use the current pattern
NS_ASSERTION((int(aRunParams.drawMode) & int(DrawMode::GLYPH_STROKE)) == 0,
"no pattern supplied for stroking text");
RefPtr<gfxPattern> fillPattern = aRunParams.context->GetPattern();
contextPaint.reset(
contextPaint =
new SimpleTextContextPaint(fillPattern, nullptr,
aRunParams.context->CurrentMatrix()));
aRunParams.context->CurrentMatrix());
fontParams.contextPaint = contextPaint.get();
}

View File

@ -32,8 +32,17 @@ namespace mozilla {
* computed style for the text that is being drawn, for example, or for color
* in an SVG embedded by an <img> element to come from the embedding <img>
* element.
*
* This class is reference counted so that it can be shared among many similar
* SVGImageContext objects. (SVGImageContext objects are frequently
* copy-constructed with small modifications, and we'd like for those copies to
* be able to share their context-paint data cheaply.) However, in most cases,
* SVGContextPaint instances are stored in a local RefPtr and only last for the
* duration of a function call.
* XXX Note: SVGImageContext doesn't actually have a SVGContextPaint member yet,
* but it will in a later patch in the patch series that added this comment.
*/
class SVGContextPaint
class SVGContextPaint : public RefCounted<SVGContextPaint>
{
protected:
typedef mozilla::gfx::DrawTarget DrawTarget;
@ -41,6 +50,8 @@ protected:
SVGContextPaint() {}
public:
MOZ_DECLARE_REFCOUNTED_TYPENAME(SVGContextPaint)
virtual ~SVGContextPaint() {}
virtual already_AddRefed<gfxPattern> GetFillPattern(const DrawTarget* aDrawTarget,

View File

@ -3657,10 +3657,10 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
// when they use context-fill etc.
aContext.SetMatrix(initialMatrix);
SVGContextPaintImpl contextPaint;
DrawMode drawMode = contextPaint.Init(&aDrawTarget,
aContext.CurrentMatrix(),
frame, outerContextPaint);
RefPtr<SVGContextPaintImpl> contextPaint = new SVGContextPaintImpl();
DrawMode drawMode = contextPaint->Init(&aDrawTarget,
aContext.CurrentMatrix(),
frame, outerContextPaint);
if (drawMode & DrawMode::GLYPH_STROKE) {
// This may change the gfxContext's transform (for non-scaling stroke),
@ -3681,7 +3681,7 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
params.framePt = gfxPoint();
params.dirtyRect = LayoutDevicePixel::
FromAppUnits(frame->GetVisualOverflowRect(), auPerDevPx);
params.contextPaint = &contextPaint;
params.contextPaint = contextPaint;
if (ShouldRenderAsPath(frame, paintSVGGlyphs)) {
SVGTextDrawPathCallbacks callbacks(&rendCtx, frame,
matrixForPaintServers,