Bug 1232576 (part 1) - Move the reference |cairo_t*| from gfxContext to DrawTarget (as user data). r=jfkthame.

--HG--
extra : rebase_source : 5f4be8b9cb4a24527ee95468239ff6ff26d4a279
This commit is contained in:
Nicholas Nethercote 2015-12-14 22:23:51 -08:00
Родитель 1bb73d77f3
Коммит 922099a41a
4 изменённых файлов: 28 добавлений и 21 удалений

Просмотреть файл

@ -55,6 +55,7 @@ static void DrawDebugOverlay(mozilla::gfx::DrawTarget* dt, int x, int y, int wid
ss << x << ", " << y;
// 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_set_font_size(cr, 25);
cairo_text_extents_t extents;

Просмотреть файл

@ -1,5 +1,6 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
@ -68,7 +69,6 @@ PatternFromState::operator mozilla::gfx::Pattern&()
gfxContext::gfxContext(DrawTarget *aTarget, const Point& aDeviceOffset)
: mPathIsRect(false)
, mTransformChanged(false)
, mRefCairo(nullptr)
, mDT(aTarget)
, mOriginalDT(aTarget)
{
@ -98,9 +98,6 @@ gfxContext::ContextForDrawTarget(DrawTarget* aTarget)
gfxContext::~gfxContext()
{
if (mRefCairo) {
cairo_destroy(mRefCairo);
}
for (int i = mStateStack.Length() - 1; i >= 0; i--) {
for (unsigned int c = 0; c < mStateStack[i].pushedClips.Length(); c++) {
mDT->PopClip();
@ -132,25 +129,38 @@ gfxContext::CurrentSurface(gfxFloat *dx, gfxFloat *dy)
return nullptr;
}
static void
DestroyRefCairo(void* aData)
{
cairo_t* refCairo = static_cast<cairo_t*>(aData);
MOZ_ASSERT(refCairo);
cairo_destroy(refCairo);
}
cairo_t *
gfxContext::GetCairo()
{
// 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
// operations.
static UserDataKey sRefCairo;
cairo_t* refCairo = nullptr;
if (mDT->GetBackendType() == BackendType::CAIRO) {
cairo_t *ctx =
(cairo_t*)mDT->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT);
if (ctx) {
return ctx;
refCairo = static_cast<cairo_t*>
(mDT->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
if (refCairo) {
return refCairo;
}
}
if (mRefCairo) {
// Set transform!
return mRefCairo;
refCairo = static_cast<cairo_t*>(mDT->GetUserData(&sRefCairo));
if (!refCairo) {
refCairo = cairo_create(gfxPlatform::GetPlatform()->ScreenReferenceSurface()->CairoSurface());
mDT->AddUserData(&sRefCairo, refCairo, DestroyRefCairo);
}
mRefCairo = cairo_create(gfxPlatform::GetPlatform()->ScreenReferenceSurface()->CairoSurface());
return mRefCairo;
return refCairo;
}
void

Просмотреть файл

@ -548,8 +548,6 @@ private:
AzureState &CurrentState() { return mStateStack[mStateStack.Length() - 1]; }
const AzureState &CurrentState() const { return mStateStack[mStateStack.Length() - 1]; }
cairo_t *mRefCairo;
RefPtr<DrawTarget> mDT;
RefPtr<DrawTarget> mOriginalDT;
};

Просмотреть файл

@ -178,8 +178,6 @@ gfxFT2FontBase::GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID)
bool
gfxFT2FontBase::SetupCairoFont(gfxContext *aContext)
{
cairo_t *cr = aContext->GetCairo();
// The scaled font ctm is not relevant right here because
// cairo_set_scaled_font does not record the scaled font itself, but
// merely the font_face, font_matrix, font_options. The scaled_font used
@ -212,6 +210,6 @@ 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(cr, cairoFont);
cairo_set_scaled_font(aContext->GetCairo(), cairoFont);
return true;
}