Bug 1232576 (part 2) - Rename gfxContext::GetCairo() as GetRefCairo() and make it static. r=jfkthame.

This means its callers now need a DrawTarget instead of a gfxContext.
This commit is contained in:
Nicholas Nethercote 2015-12-14 22:26:23 -08:00
parent f0f8f6f4ec
commit d56b59cf31
9 changed files with 23 additions and 17 deletions

View File

@ -56,7 +56,7 @@ static void DrawDebugOverlay(mozilla::gfx::DrawTarget* dt, int x, int y, int wid
// Draw text using cairo toy text API
// XXX: this drawing will silently fail if |dt| doesn't have a Cairo backend
cairo_t* cr = c.GetCairo();
cairo_t* cr = gfxContext::RefCairo(dt);
cairo_set_font_size(cr, 25);
cairo_text_extents_t extents;
cairo_text_extents(cr, ss.str().c_str(), &extents);

View File

@ -137,8 +137,8 @@ DestroyRefCairo(void* aData)
cairo_destroy(refCairo);
}
cairo_t *
gfxContext::GetCairo()
/* static */ cairo_t *
gfxContext::RefCairo(DrawTarget* aDT)
{
// DrawTargets that don't use a Cairo backend can be given a 1x1 "reference"
// |cairo_t*|, stored in the DrawTarget's user data, for doing font-related
@ -146,18 +146,18 @@ gfxContext::GetCairo()
static UserDataKey sRefCairo;
cairo_t* refCairo = nullptr;
if (mDT->GetBackendType() == BackendType::CAIRO) {
if (aDT->GetBackendType() == BackendType::CAIRO) {
refCairo = static_cast<cairo_t*>
(mDT->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
(aDT->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
if (refCairo) {
return refCairo;
}
}
refCairo = static_cast<cairo_t*>(mDT->GetUserData(&sRefCairo));
refCairo = static_cast<cairo_t*>(aDT->GetUserData(&sRefCairo));
if (!refCairo) {
refCairo = cairo_create(gfxPlatform::GetPlatform()->ScreenReferenceSurface()->CairoSurface());
mDT->AddUserData(&sRefCairo, refCairo, DestroyRefCairo);
aDT->AddUserData(&sRefCairo, refCairo, DestroyRefCairo);
}
return refCairo;
@ -1322,7 +1322,7 @@ gfxContext::GetRoundOffsetsToPixels(bool *aRoundX, bool *aRoundY)
// Print backends set CAIRO_HINT_METRICS_OFF.
*aRoundY = true;
cairo_t *cr = GetCairo();
cairo_t *cr = gfxContext::RefCairo(GetDrawTarget());
cairo_scaled_font_t *scaled_font = cairo_get_scaled_font(cr);
// bug 1198921 - this sometimes fails under Windows for whatver reason

View File

@ -86,10 +86,10 @@ public:
}
/**
* Return the raw cairo_t object.
* XXX this should go away at some point.
* Return the reference cairo_t object from aDT.
* XXX this should be moved into gfxFont at some point.
*/
cairo_t *GetCairo();
static cairo_t* RefCairo(mozilla::gfx::DrawTarget* aDT);
mozilla::gfx::DrawTarget *GetDrawTarget() { return mDT; }

View File

@ -462,7 +462,8 @@ gfxDWriteFont::SetupCairoFont(gfxContext *aContext)
// the cairo_t, precluding any further drawing.
return false;
}
cairo_set_scaled_font(aContext->GetCairo(), scaledFont);
cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()),
scaledFont);
return true;
}

View File

@ -210,6 +210,7 @@ gfxFT2FontBase::SetupCairoFont(gfxContext *aContext)
// what is set here. It's too late to change things here as measuring has
// already taken place. We should really be measuring with a different
// font for pdf and ps surfaces (bug 403513).
cairo_set_scaled_font(aContext->GetCairo(), cairoFont);
cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()),
cairoFont);
return true;
}

View File

@ -3213,7 +3213,8 @@ gfxFont::SetupGlyphExtents(gfxContext *aContext,
glyph.x = 0;
glyph.y = 0;
cairo_text_extents_t extents;
cairo_glyph_extents(aContext->GetCairo(), &glyph, 1, &extents);
cairo_glyph_extents(gfxContext::RefCairo(aContext->GetDrawTarget()),
&glyph, 1, &extents);
const Metrics& fontMetrics = GetMetrics(eHorizontal);
int32_t appUnitsPerDevUnit = aExtents->GetAppUnitsPerDevUnit();

View File

@ -342,7 +342,8 @@ gfxFontEntry::GetSVGGlyphExtents(gfxContext *aContext, uint32_t aGlyphId,
"font has invalid unitsPerEm");
cairo_matrix_t fontMatrix;
cairo_get_font_matrix(aContext->GetCairo(), &fontMatrix);
cairo_get_font_matrix(gfxContext::RefCairo(aContext->GetDrawTarget()),
&fontMatrix);
gfxMatrix svgToAppSpace(fontMatrix.xx, fontMatrix.yx,
fontMatrix.xy, fontMatrix.yy,

View File

@ -136,7 +136,8 @@ gfxGDIFont::SetupCairoFont(gfxContext *aContext)
// the cairo_t, precluding any further drawing.
return false;
}
cairo_set_scaled_font(aContext->GetCairo(), mScaledFont);
cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()),
mScaledFont);
return true;
}

View File

@ -160,7 +160,8 @@ gfxMacFont::SetupCairoFont(gfxContext *aContext)
// the cairo_t, precluding any further drawing.
return false;
}
cairo_set_scaled_font(aContext->GetCairo(), mScaledFont);
cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()),
mScaledFont);
return true;
}