/* -*- 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 * 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/. */
#include"PrintTarget.h"
#include"cairo.h" #ifdef CAIRO_HAS_QUARTZ_SURFACE # include "cairo-quartz.h" #endif #ifdef CAIRO_HAS_WIN32_SURFACE # include "cairo-win32.h" #endif #include"mozilla/gfx/2D.h" #include"mozilla/gfx/HelpersCairo.h" #include"mozilla/gfx/Logging.h" #include"mozilla/StaticPrefs_gfx.h" #include"nsReadableUtils.h" #include"nsString.h" #include"nsUTF8Utils.h"
{ #if 0 // aCairoSurface is null when our PrintTargetThebes subclass's ctor calls us. // Once PrintTargetThebes is removed, enable this assertion.
MOZ_ASSERT(aCairoSurface && !cairo_surface_status(aCairoSurface), "CreateOrNull factory methods should not call us without a " "valid cairo_surface_t*"); #endif
// CreateOrNull factory methods hand over ownership of aCairoSurface, // so we don't call cairo_surface_reference(aSurface) here.
// This code was copied from gfxASurface::Init: if (mCairoSurface &&
cairo_surface_get_content(mCairoSurface) != CAIRO_CONTENT_COLOR) {
cairo_surface_set_subpixel_antialiasing(
mCairoSurface, CAIRO_SUBPIXEL_ANTIALIASING_DISABLED);
}
}
PrintTarget::~PrintTarget() { // null surfaces are allowed here
cairo_surface_destroy(mCairoSurface);
mCairoSurface = nullptr;
}
already_AddRefed<DrawTarget> PrintTarget::MakeDrawTarget( const IntSize& aSize, DrawEventRecorder* aRecorder) {
MOZ_ASSERT(mCairoSurface, "We shouldn't have been constructed without a cairo surface");
// This should not be called outside of BeginPage()/EndPage() calls since // some backends can only provide a valid DrawTarget at that time.
MOZ_ASSERT(mHasActivePage, "We can't guarantee a valid DrawTarget");
if (cairo_surface_status(mCairoSurface)) { return nullptr;
}
// Note than aSize may not be the same as mSize (the size of mCairoSurface). // See the comments in our header. If the sizes are different a clip will // be applied to mCairoSurface.
RefPtr<DrawTarget> dt =
Factory::CreateDrawTargetForCairoSurface(mCairoSurface, aSize); if (!dt || !dt->IsValid()) { return nullptr;
}
if (aRecorder) {
dt = CreateRecordingDrawTarget(aRecorder, dt); if (!dt || !dt->IsValid()) { return nullptr;
}
}
return dt.forget();
}
already_AddRefed<DrawTarget> PrintTarget::GetReferenceDrawTarget() { if (!mRefDT) { const IntSize size(1, 1);
cairo_surface_t* similar; switch (cairo_surface_get_type(mCairoSurface)) { #ifdef CAIRO_HAS_WIN32_SURFACE case CAIRO_SURFACE_TYPE_WIN32:
similar = cairo_win32_surface_create_with_dib(
CairoContentToCairoFormat(cairo_surface_get_content(mCairoSurface)),
size.width, size.height); break; #endif #ifdef CAIRO_HAS_QUARTZ_SURFACE case CAIRO_SURFACE_TYPE_QUARTZ: if (StaticPrefs::gfx_cairo_quartz_cg_layer_enabled()) {
similar = cairo_quartz_surface_create_cg_layer(
mCairoSurface, cairo_surface_get_content(mCairoSurface),
size.width, size.height); break;
}
[[fallthrough]]; #endif default:
similar = cairo_surface_create_similar(
mCairoSurface, cairo_surface_get_content(mCairoSurface), size.width,
size.height); break;
}
if (cairo_surface_status(similar)) { return nullptr;
}
if (aRecorder) { // It doesn't really matter what we pass as the DrawTarget here.
dt = gfx::Factory::CreateRecordingDrawTarget(aRecorder, aDrawTarget,
aDrawTarget->GetRect());
}
if (!dt || !dt->IsValid()) {
gfxCriticalNote
<< "Failed to create a recording DrawTarget for PrintTarget"; return nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.