Backed out 25 changesets (bug 1156742) for build bustage in SkOSLibrary_win.cpp CLOSED TREE

Backed out changeset 31c0aadae8e7 (bug 1156742)
Backed out changeset f08df57ff700 (bug 1156742)
Backed out changeset 90c026d5dcb1 (bug 1156742)
Backed out changeset 8c6d14d80238 (bug 1156742)
Backed out changeset 72d86b0471c9 (bug 1156742)
Backed out changeset 363829accc09 (bug 1156742)
Backed out changeset 16360fe94d54 (bug 1156742)
Backed out changeset 5355c636a81a (bug 1156742)
Backed out changeset 18844d26b873 (bug 1156742)
Backed out changeset 99df86591613 (bug 1156742)
Backed out changeset 7ac1c7e15a11 (bug 1156742)
Backed out changeset de352000aae1 (bug 1156742)
Backed out changeset 4dd34ea230c6 (bug 1156742)
Backed out changeset 48c6ce65a5c2 (bug 1156742)
Backed out changeset dd52947f73c6 (bug 1156742)
Backed out changeset 5fe429ee880c (bug 1156742)
Backed out changeset dedca8fb19b0 (bug 1156742)
Backed out changeset d748b1354f92 (bug 1156742)
Backed out changeset 7f8e59588518 (bug 1156742)
Backed out changeset b90d302c57f6 (bug 1156742)
Backed out changeset 7a4da453572c (bug 1156742)
Backed out changeset a40eea914519 (bug 1156742)
Backed out changeset 99a8859afcdb (bug 1156742)
Backed out changeset 4934e88b2d7a (bug 1156742)
Backed out changeset 79733166f05e (bug 1156742) for build bustage in SkOSLibrary_win.cpp CLOSED TREE

--HG--
extra : amend_source : beeb6abbcc724b79ac166e828efa78dc4c5301da
This commit is contained in:
Wes Kocher 2015-12-21 13:47:33 -08:00
Родитель c627bc38a1
Коммит a5249b6201
85 изменённых файлов: 715 добавлений и 3678 удалений

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

@ -5,7 +5,6 @@
include PPrintingTypes;
include protocol PPrinting;
include protocol PRemotePrintJob;
namespace mozilla {
namespace embedding {

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

@ -8,7 +8,6 @@ include protocol PContent;
include protocol PBrowser;
include protocol PPrintProgressDialog;
include protocol PPrintSettingsDialog;
include protocol PRemotePrintJob;
namespace mozilla {
namespace embedding {
@ -18,7 +17,6 @@ sync protocol PPrinting
manager PContent;
manages PPrintProgressDialog;
manages PPrintSettingsDialog;
manages PRemotePrintJob;
parent:
sync ShowProgress(PBrowser browser,
@ -39,7 +37,6 @@ parent:
returns(nsresult rv);
child:
async PRemotePrintJob();
__delete__();
};

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

@ -3,8 +3,6 @@
* 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 protocol PRemotePrintJob;
namespace mozilla {
namespace embedding {
@ -14,7 +12,6 @@ struct CStringKeyValue {
};
struct PrintData {
nullable PRemotePrintJob remotePrintJob;
int32_t startPageRange;
int32_t endPageRange;
double edgeTop;

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

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* vim: set sw=4 ts=8 et 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/. */
@ -19,11 +19,9 @@
#include "PrintDataUtils.h"
#include "PrintProgressDialogParent.h"
#include "PrintSettingsDialogParent.h"
#include "mozilla/layout/RemotePrintJobParent.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layout;
namespace mozilla {
namespace embedding {
@ -104,10 +102,6 @@ PrintingParent::ShowPrintDialog(PBrowserParent* aParent,
// And send it back.
rv = po->SerializeToPrintData(settings, nullptr, aResult);
PRemotePrintJobParent* remotePrintJob = new RemotePrintJobParent(settings);
aResult->remotePrintJobParent() = SendPRemotePrintJobConstructor(remotePrintJob);
return rv;
}
@ -189,20 +183,6 @@ PrintingParent::DeallocPPrintSettingsDialogParent(PPrintSettingsDialogParent* aD
return true;
}
PRemotePrintJobParent*
PrintingParent::AllocPRemotePrintJobParent()
{
MOZ_ASSERT_UNREACHABLE("No default constructors for implementations.");
return nullptr;
}
bool
PrintingParent::DeallocPRemotePrintJobParent(PRemotePrintJobParent* aDoomed)
{
delete aDoomed;
return true;
}
void
PrintingParent::ActorDestroy(ActorDestroyReason aWhy)
{

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

@ -15,10 +15,6 @@ class PPrintProgressDialogParent;
class PPrintSettingsDialogParent;
namespace mozilla {
namespace layout {
class PRemotePrintJobParent;
}
namespace embedding {
class PrintingParent final : public PPrintingParent
@ -53,12 +49,6 @@ public:
virtual bool
DeallocPPrintSettingsDialogParent(PPrintSettingsDialogParent* aActor);
virtual PRemotePrintJobParent*
AllocPRemotePrintJobParent();
virtual bool
DeallocPRemotePrintJobParent(PRemotePrintJobParent* aActor);
virtual void
ActorDestroy(ActorDestroyReason aWhy);
@ -79,3 +69,4 @@ private:
} // namespace mozilla
#endif

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

@ -4,17 +4,15 @@
* 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 "nsPrintingProxy.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/layout/RemotePrintJobChild.h"
#include "mozilla/unused.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIPrintingPromptService.h"
#include "nsPIDOMWindow.h"
#include "nsPrintingProxy.h"
#include "nsPrintOptionsImpl.h"
#include "PrintDataUtils.h"
#include "PrintProgressDialogChild.h"
@ -22,7 +20,6 @@
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::embedding;
using namespace mozilla::layout;
static StaticRefPtr<nsPrintingProxy> sPrintingProxyInstance;
@ -236,18 +233,3 @@ nsPrintingProxy::DeallocPPrintSettingsDialogChild(PPrintSettingsDialogChild* aAc
// will take itself out.
return true;
}
PRemotePrintJobChild*
nsPrintingProxy::AllocPRemotePrintJobChild()
{
RefPtr<RemotePrintJobChild> remotePrintJob = new RemotePrintJobChild();
return remotePrintJob.forget().take();
}
bool
nsPrintingProxy::DeallocPRemotePrintJobChild(PRemotePrintJobChild* aDoomed)
{
RemotePrintJobChild* remotePrintJob = static_cast<RemotePrintJobChild*>(aDoomed);
NS_RELEASE(remotePrintJob);
return true;
}

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

@ -9,12 +9,6 @@
#include "nsIPrintingPromptService.h"
#include "mozilla/embedding/PPrintingChild.h"
namespace mozilla {
namespace layout {
class PRemotePrintJobChild;
}
}
class nsPrintingProxy: public nsIPrintingPromptService,
public mozilla::embedding::PPrintingChild
{
@ -45,12 +39,6 @@ public:
virtual bool
DeallocPPrintSettingsDialogChild(PPrintSettingsDialogChild* aActor) override;
virtual PRemotePrintJobChild*
AllocPRemotePrintJobChild() override;
virtual bool
DeallocPRemotePrintJobChild(PRemotePrintJobChild* aActor) override;
};
#endif

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

@ -667,29 +667,6 @@ protected:
UserData mUserData;
};
/**
* Derived classes hold a native font resource from which to create
* ScaledFonts.
*/
class NativeFontResource : public RefCounted<NativeFontResource>
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResource)
/**
* Creates a ScaledFont using the font corresponding to the index and
* the given glyph size.
*
* @param aIndex index for the font within the resource.
* @param aGlyphSize the size of ScaledFont required.
* @return an already_addrefed ScaledFont, containing nullptr if failed.
*/
virtual already_AddRefed<ScaledFont>
CreateScaledFont(uint32_t aIndex, uint32_t aGlyphSize) = 0;
virtual ~NativeFontResource() {};
};
/** 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
@ -726,9 +703,6 @@ public:
virtual DrawTargetType GetType() const = 0;
virtual BackendType GetBackendType() const = 0;
virtual bool IsRecording() const { return false; }
/**
* Returns a SourceSurface which is a snapshot of the current contents of the DrawTarget.
* Multiple calls to Snapshot() without any drawing operations in between will
@ -1215,15 +1189,16 @@ public:
CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize);
/**
* This creates a NativeFontResource from TrueType data.
* This creates a ScaledFont from TrueType data.
*
* @param aData Pointer to the data
* @param aSize Size of the TrueType data
* @param aType Type of NativeFontResource that should be created.
* @return a NativeFontResource of nullptr if failed.
* @param aFaceIndex Index of the font face in the truetype data this ScaledFont needs to represent.
* @param aGlyphSize Size of the glyphs in this ScaledFont
* @param aType Type of ScaledFont that should be created.
*/
static already_AddRefed<NativeFontResource>
CreateNativeFontResource(uint8_t *aData, uint32_t aSize, FontType aType);
static already_AddRefed<ScaledFont>
CreateScaledFontForTrueTypeData(uint8_t *aData, uint32_t aSize, uint32_t aFaceIndex, Float aGlyphSize, FontType aType);
/**
* This creates a scaled font with an associated cairo_scaled_font_t, and

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

@ -1,86 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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/. */
#ifndef mozilla_gfx_AutoHelpersWin_h
#define mozilla_gfx_AutoHelpersWin_h
#include <windows.h>
namespace mozilla {
namespace gfx {
// Get the global device context, and auto-release it on destruction.
class AutoDC
{
public:
AutoDC() {
mDC = ::GetDC(nullptr);
}
~AutoDC() {
::ReleaseDC(nullptr, mDC);
}
HDC GetDC() {
return mDC;
}
private:
HDC mDC;
};
// Select a font into the given DC, and auto-restore.
class AutoSelectFont
{
public:
AutoSelectFont(HDC aDC, LOGFONTW *aLogFont)
: mOwnsFont(false)
{
mFont = ::CreateFontIndirectW(aLogFont);
if (mFont) {
mOwnsFont = true;
mDC = aDC;
mOldFont = (HFONT)::SelectObject(aDC, mFont);
} else {
mOldFont = nullptr;
}
}
AutoSelectFont(HDC aDC, HFONT aFont)
: mOwnsFont(false)
{
mDC = aDC;
mFont = aFont;
mOldFont = (HFONT)::SelectObject(aDC, aFont);
}
~AutoSelectFont() {
if (mOldFont) {
::SelectObject(mDC, mOldFont);
if (mOwnsFont) {
::DeleteObject(mFont);
}
}
}
bool IsValid() const {
return mFont != nullptr;
}
HFONT GetFont() const {
return mFont;
}
private:
HDC mDC;
HFONT mFont;
HFONT mOldFont;
bool mOwnsFont;
};
} // gfx
} // mozilla
#endif // mozilla_gfx_AutoHelpersWin_h

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

@ -1,80 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_BigEndianInts_h
#define mozilla_BigEndianInts_h
#include "mozilla/Endian.h"
namespace mozilla {
#pragma pack(push, 1)
struct BigEndianUint16
{
#ifdef __SUNPRO_CC
BigEndianUint16& operator=(const uint16_t aValue)
{
value = NativeEndian::swapToBigEndian(aValue);
return *this;
}
#else
MOZ_IMPLICIT BigEndianUint16(const uint16_t aValue)
{
value = NativeEndian::swapToBigEndian(aValue);
}
#endif
operator uint16_t() const
{
return NativeEndian::swapFromBigEndian(value);
}
friend inline bool
operator==(const BigEndianUint16& lhs, const BigEndianUint16& rhs)
{
return lhs.value == rhs.value;
}
friend inline bool
operator!=(const BigEndianUint16& lhs, const BigEndianUint16& rhs)
{
return !(lhs == rhs);
}
private:
uint16_t value;
};
struct BigEndianUint32
{
#ifdef __SUNPRO_CC
BigEndianUint32& operator=(const uint32_t aValue)
{
value = NativeEndian::swapToBigEndian(aValue);
return *this;
}
#else
MOZ_IMPLICIT BigEndianUint32(const uint32_t aValue)
{
value = NativeEndian::swapToBigEndian(aValue);
}
#endif
operator uint32_t() const
{
return NativeEndian::swapFromBigEndian(value);
}
private:
uint32_t value;
};
#pragma pack(pop)
} // mozilla
#endif // mozilla_BigEndianInts_h

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

@ -5,26 +5,19 @@
#include "DrawEventRecorder.h"
#include "PathRecording.h"
#include "RecordingTypes.h"
namespace mozilla {
namespace gfx {
using namespace std;
const uint32_t kMagicInt = 0xc001feed;
DrawEventRecorderPrivate::DrawEventRecorderPrivate(std::ostream *aStream)
: mOutputStream(aStream)
{
}
void
DrawEventRecorderPrivate::WriteHeader()
{
WriteElement(*mOutputStream, kMagicInt);
WriteElement(*mOutputStream, kMajorRevision);
WriteElement(*mOutputStream, kMinorRevision);
}
void
DrawEventRecorderPrivate::RecordEvent(const RecordedEvent &aEvent)
{
@ -41,7 +34,9 @@ DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename)
{
mOutputStream = &mOutputFile;
WriteHeader();
WriteElement(*mOutputStream, kMagicInt);
WriteElement(*mOutputStream, kMajorRevision);
WriteElement(*mOutputStream, kMinorRevision);
}
DrawEventRecorderFile::~DrawEventRecorderFile()
@ -55,40 +50,5 @@ DrawEventRecorderFile::Flush()
mOutputFile.flush();
}
DrawEventRecorderMemory::DrawEventRecorderMemory()
: DrawEventRecorderPrivate(nullptr)
{
mOutputStream = &mMemoryStream;
WriteHeader();
}
void
DrawEventRecorderMemory::Flush()
{
mOutputStream->flush();
}
size_t
DrawEventRecorderMemory::RecordingSize()
{
return mMemoryStream.tellp();
}
bool
DrawEventRecorderMemory::CopyRecording(char* aBuffer, size_t aBufferLen)
{
return !!mMemoryStream.read(aBuffer, aBufferLen);
}
void
DrawEventRecorderMemory::WipeRecording()
{
mMemoryStream.str(std::string());
mMemoryStream.clear();
WriteHeader();
}
} // namespace gfx
} // namespace mozilla

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

@ -29,29 +29,22 @@ public:
explicit DrawEventRecorderPrivate(std::ostream *aStream);
virtual ~DrawEventRecorderPrivate() { }
void WriteHeader();
void RecordEvent(const RecordedEvent &aEvent);
void WritePath(const PathRecording *aPath);
void AddStoredObject(const ReferencePtr aObject) {
mStoredObjects.insert(aObject);
void AddStoredPath(const ReferencePtr aPath) {
mStoredPaths.insert(aPath);
}
void RemoveStoredObject(const ReferencePtr aObject) {
mStoredObjects.erase(aObject);
void RemoveStoredPath(const ReferencePtr aPath) {
mStoredPaths.erase(aPath);
}
bool HasStoredObject(const ReferencePtr aObject) {
return mStoredObjects.find(aObject) != mStoredObjects.end();
}
void AddStoredFontData(const uint64_t aFontDataKey) {
mStoredFontData.insert(aFontDataKey);
}
bool HasStoredFontData(const uint64_t aFontDataKey) {
return mStoredFontData.find(aFontDataKey) != mStoredFontData.end();
bool HasStoredPath(const ReferencePtr aPath) {
if (mStoredPaths.find(aPath) != mStoredPaths.end()) {
return true;
}
return false;
}
protected:
@ -61,14 +54,12 @@ protected:
#if defined(_MSC_VER)
typedef std::unordered_set<const void*> ObjectSet;
typedef std::unordered_set<uint64_t> Uint64Set;
#else
typedef std::set<const void*> ObjectSet;
typedef std::set<uint64_t> Uint64Set;
#endif
ObjectSet mStoredObjects;
Uint64Set mStoredFontData;
ObjectSet mStoredPaths;
ObjectSet mStoredScaledFonts;
};
class DrawEventRecorderFile : public DrawEventRecorderPrivate
@ -84,45 +75,6 @@ private:
std::ofstream mOutputFile;
};
class DrawEventRecorderMemory final : public DrawEventRecorderPrivate
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderMemory)
/**
* Constructs a DrawEventRecorder that stores the recording in memory.
*/
DrawEventRecorderMemory();
/**
* @return the current size of the recording (in chars).
*/
size_t RecordingSize();
/**
* Copies at most aBufferLen chars of the recording into aBuffer.
*
* @param aBuffer buffer to receive the recording chars
* @param aBufferLen length of aBuffer
* @return true if copied successfully
*/
bool CopyRecording(char* aBuffer, size_t aBufferLen);
/**
* Wipes the internal recording buffer, but the recorder does NOT forget which
* objects it has recorded. This can be used so that a recording can be copied
* and processed in chunks, releasing memory as it goes.
*/
void WipeRecording();
private:
~DrawEventRecorderMemory() {};
void Flush() final;
std::stringstream mMemoryStream;
};
} // namespace gfx
} // namespace mozilla

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

@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 20; 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/. */
@ -11,70 +10,10 @@
#include "Logging.h"
#include "Tools.h"
#include "Filters.h"
#include "mozilla/UniquePtr.h"
#include "RecordingTypes.h"
namespace mozilla {
namespace gfx {
struct RecordingSourceSurfaceUserData
{
void *refPtr;
RefPtr<DrawEventRecorderPrivate> recorder;
};
void RecordingSourceSurfaceUserDataFunc(void *aUserData)
{
RecordingSourceSurfaceUserData *userData =
static_cast<RecordingSourceSurfaceUserData*>(aUserData);
userData->recorder->RemoveStoredObject(userData->refPtr);
userData->recorder->RecordEvent(
RecordedSourceSurfaceDestruction(userData->refPtr));
delete userData;
}
static void
StoreSourceSurface(DrawEventRecorderPrivate *aRecorder, SourceSurface *aSurface,
DataSourceSurface *aDataSurf, const char *reason)
{
if (!aDataSurf) {
gfxWarning() << "Recording failed to record SourceSurface for " << reason;
// Insert a bogus source surface.
int32_t stride = aSurface->GetSize().width * BytesPerPixel(aSurface->GetFormat());
UniquePtr<uint8_t[]> sourceData(new uint8_t[stride * aSurface->GetSize().height]());
aRecorder->RecordEvent(
RecordedSourceSurfaceCreation(aSurface, sourceData.get(), stride,
aSurface->GetSize(), aSurface->GetFormat()));
} else {
DataSourceSurface::ScopedMap map(aDataSurf, DataSourceSurface::READ);
aRecorder->RecordEvent(
RecordedSourceSurfaceCreation(aSurface, map.GetData(), map.GetStride(),
aDataSurf->GetSize(), aDataSurf->GetFormat()));
}
}
static void
EnsureSurfaceStored(DrawEventRecorderPrivate *aRecorder, SourceSurface *aSurface,
const char *reason)
{
if (aRecorder->HasStoredObject(aSurface)) {
return;
}
RefPtr<DataSourceSurface> dataSurf = aSurface->GetDataSurface();
StoreSourceSurface(aRecorder, aSurface, dataSurf, reason);
aRecorder->AddStoredObject(aSurface);
RecordingSourceSurfaceUserData *userData = new RecordingSourceSurfaceUserData;
userData->refPtr = aSurface;
userData->recorder = aRecorder;
aSurface->AddUserData(reinterpret_cast<UserDataKey*>(aRecorder),
userData, &RecordingSourceSurfaceUserDataFunc);
return;
}
class SourceSurfaceRecording : public SourceSurface
{
public:
@ -82,12 +21,10 @@ public:
SourceSurfaceRecording(SourceSurface *aFinalSurface, DrawEventRecorderPrivate *aRecorder)
: mFinalSurface(aFinalSurface), mRecorder(aRecorder)
{
mRecorder->AddStoredObject(this);
}
~SourceSurfaceRecording()
{
mRecorder->RemoveStoredObject(this);
mRecorder->RecordEvent(RecordedSourceSurfaceDestruction(this));
}
@ -107,12 +44,10 @@ public:
GradientStopsRecording(GradientStops *aFinalGradientStops, DrawEventRecorderPrivate *aRecorder)
: mFinalGradientStops(aFinalGradientStops), mRecorder(aRecorder)
{
mRecorder->AddStoredObject(this);
}
~GradientStopsRecording()
{
mRecorder->RemoveStoredObject(this);
mRecorder->RecordEvent(RecordedGradientStopsDestruction(this));
}
@ -151,39 +86,29 @@ public:
FilterNodeRecording(FilterNode *aFinalFilterNode, DrawEventRecorderPrivate *aRecorder)
: mFinalFilterNode(aFinalFilterNode), mRecorder(aRecorder)
{
mRecorder->AddStoredObject(this);
}
~FilterNodeRecording()
{
mRecorder->RemoveStoredObject(this);
mRecorder->RecordEvent(RecordedFilterNodeDestruction(this));
}
static FilterNode*
GetFilterNode(FilterNode* aNode)
{
if (aNode->GetBackendType() != FILTER_BACKEND_RECORDING) {
gfxWarning() << "Non recording filter node used with recording DrawTarget!";
return aNode;
}
return static_cast<FilterNodeRecording*>(aNode)->mFinalFilterNode;
}
virtual void SetInput(uint32_t aIndex, SourceSurface *aSurface) override
{
EnsureSurfaceStored(mRecorder, aSurface, "SetInput");
mRecorder->RecordEvent(RecordedFilterNodeSetInput(this, aIndex, aSurface));
mFinalFilterNode->SetInput(aIndex, GetSourceSurface(aSurface));
}
virtual void SetInput(uint32_t aIndex, FilterNode *aFilter) override
{
MOZ_ASSERT(mRecorder->HasStoredObject(aFilter));
FilterNode *finalNode = aFilter;
if (aFilter->GetBackendType() != FILTER_BACKEND_RECORDING) {
gfxWarning() << "Non recording filter node used with recording DrawTarget!";
} else {
finalNode = static_cast<FilterNodeRecording*>(aFilter)->mFinalFilterNode;
}
mRecorder->RecordEvent(RecordedFilterNodeSetInput(this, aIndex, aFilter));
mFinalFilterNode->SetInput(aIndex, GetFilterNode(aFilter));
mFinalFilterNode->SetInput(aIndex, finalNode);
}
@ -202,7 +127,6 @@ public:
FORWARD_SET_ATTRIBUTE(const Rect&, RECT);
FORWARD_SET_ATTRIBUTE(const IntRect&, INTRECT);
FORWARD_SET_ATTRIBUTE(const Point&, POINT);
FORWARD_SET_ATTRIBUTE(const Matrix&, MATRIX);
FORWARD_SET_ATTRIBUTE(const Matrix5x4&, MATRIX5X4);
FORWARD_SET_ATTRIBUTE(const Point3D&, POINT3D);
FORWARD_SET_ATTRIBUTE(const Color&, COLOR);
@ -220,6 +144,17 @@ public:
RefPtr<DrawEventRecorderPrivate> mRecorder;
};
static FilterNode*
GetFilterNode(FilterNode* aNode)
{
if (aNode->GetBackendType() != FILTER_BACKEND_RECORDING) {
gfxWarning() << "Non recording filter node used with recording DrawTarget!";
return aNode;
}
return static_cast<FilterNodeRecording*>(aNode)->mFinalFilterNode;
}
struct AdjustedPattern
{
explicit AdjustedPattern(const Pattern &aPattern)
@ -298,16 +233,6 @@ DrawTargetRecording::DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarge
mFormat = mFinalDT->GetFormat();
}
DrawTargetRecording::DrawTargetRecording(const DrawTargetRecording *aDT,
const IntSize &aSize,
SurfaceFormat aFormat)
: mRecorder(aDT->mRecorder)
, mFinalDT(aDT->mFinalDT->CreateSimilarDrawTarget(aSize, aFormat))
{
mRecorder->RecordEvent(RecordedCreateSimilarDrawTarget(this, aSize, aFormat));
mFormat = mFinalDT->GetFormat();
}
DrawTargetRecording::~DrawTargetRecording()
{
mRecorder->RecordEvent(RecordedDrawTargetDestruction(this));
@ -318,8 +243,6 @@ DrawTargetRecording::FillRect(const Rect &aRect,
const Pattern &aPattern,
const DrawOptions &aOptions)
{
EnsurePatternDependenciesStored(aPattern);
mRecorder->RecordEvent(RecordedFillRect(this, aRect, aPattern, aOptions));
mFinalDT->FillRect(aRect, *AdjustedPattern(aPattern), aOptions);
}
@ -330,8 +253,6 @@ DrawTargetRecording::StrokeRect(const Rect &aRect,
const StrokeOptions &aStrokeOptions,
const DrawOptions &aOptions)
{
EnsurePatternDependenciesStored(aPattern);
mRecorder->RecordEvent(RecordedStrokeRect(this, aRect, aPattern, aStrokeOptions, aOptions));
mFinalDT->StrokeRect(aRect, *AdjustedPattern(aPattern), aStrokeOptions, aOptions);
}
@ -343,22 +264,29 @@ DrawTargetRecording::StrokeLine(const Point &aBegin,
const StrokeOptions &aStrokeOptions,
const DrawOptions &aOptions)
{
EnsurePatternDependenciesStored(aPattern);
mRecorder->RecordEvent(RecordedStrokeLine(this, aBegin, aEnd, aPattern, aStrokeOptions, aOptions));
mFinalDT->StrokeLine(aBegin, aEnd, *AdjustedPattern(aPattern), aStrokeOptions, aOptions);
}
Path*
DrawTargetRecording::GetPathForPathRecording(const Path *aPath) const
{
if (aPath->GetBackendType() != BackendType::RECORDING) {
return nullptr;
}
return static_cast<const PathRecording*>(aPath)->mPath;
}
void
DrawTargetRecording::Fill(const Path *aPath,
const Pattern &aPattern,
const DrawOptions &aOptions)
{
RefPtr<PathRecording> pathRecording = EnsurePathStored(aPath);
EnsurePatternDependenciesStored(aPattern);
EnsureStored(aPath);
mRecorder->RecordEvent(RecordedFill(this, pathRecording, aPattern, aOptions));
mFinalDT->Fill(pathRecording->mPath, *AdjustedPattern(aPattern), aOptions);
mRecorder->RecordEvent(RecordedFill(this, const_cast<Path*>(aPath), aPattern, aOptions));
mFinalDT->Fill(GetPathForPathRecording(aPath), *AdjustedPattern(aPattern), aOptions);
}
struct RecordingFontUserData
@ -387,20 +315,10 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
const DrawOptions &aOptions,
const GlyphRenderingOptions *aRenderingOptions)
{
EnsurePatternDependenciesStored(aPattern);
if (!aFont->GetUserData(reinterpret_cast<UserDataKey*>(mRecorder.get()))) {
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
RecordedFontData fontData(aFont);
RecordedFontDetails fontDetails;
if (fontData.GetFontDetails(fontDetails)) {
if (!mRecorder->HasStoredFontData(fontDetails.fontDataKey)) {
mRecorder->RecordEvent(fontData);
mRecorder->AddStoredFontData(fontDetails.fontDataKey);
}
mRecorder->RecordEvent(RecordedScaledFontCreation(aFont, fontDetails));
}
mRecorder->RecordEvent(RecordedScaledFontCreation(aFont, aFont));
#endif
RecordingFontUserData *userData = new RecordingFontUserData;
userData->refPtr = aFont;
@ -421,9 +339,6 @@ DrawTargetRecording::Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions)
{
EnsurePatternDependenciesStored(aSource);
EnsurePatternDependenciesStored(aMask);
mRecorder->RecordEvent(RecordedMask(this, aSource, aMask, aOptions));
mFinalDT->Mask(*AdjustedPattern(aSource), *AdjustedPattern(aMask), aOptions);
}
@ -434,9 +349,6 @@ DrawTargetRecording::MaskSurface(const Pattern &aSource,
Point aOffset,
const DrawOptions &aOptions)
{
EnsurePatternDependenciesStored(aSource);
EnsureSurfaceStored(mRecorder, aMask, "MaskSurface");
mRecorder->RecordEvent(RecordedMaskSurface(this, aSource, aMask, aOffset, aOptions));
mFinalDT->MaskSurface(*AdjustedPattern(aSource), GetSourceSurface(aMask), aOffset, aOptions);
}
@ -447,11 +359,10 @@ DrawTargetRecording::Stroke(const Path *aPath,
const StrokeOptions &aStrokeOptions,
const DrawOptions &aOptions)
{
RefPtr<PathRecording> pathRecording = EnsurePathStored(aPath);
EnsurePatternDependenciesStored(aPattern);
EnsureStored(aPath);
mRecorder->RecordEvent(RecordedStroke(this, pathRecording, aPattern, aStrokeOptions, aOptions));
mFinalDT->Stroke(pathRecording->mPath, *AdjustedPattern(aPattern), aStrokeOptions, aOptions);
mRecorder->RecordEvent(RecordedStroke(this, const_cast<Path*>(aPath), aPattern, aStrokeOptions, aOptions));
mFinalDT->Stroke(GetPathForPathRecording(aPath), *AdjustedPattern(aPattern), aStrokeOptions, aOptions);
}
already_AddRefed<SourceSurface>
@ -473,8 +384,6 @@ DrawTargetRecording::DrawSurface(SourceSurface *aSurface,
const DrawSurfaceOptions &aSurfOptions,
const DrawOptions &aOptions)
{
EnsureSurfaceStored(mRecorder, aSurface, "DrawSurface");
mRecorder->RecordEvent(RecordedDrawSurface(this, aSurface, aDest, aSource, aSurfOptions, aOptions));
mFinalDT->DrawSurface(GetSourceSurface(aSurface), aDest, aSource, aSurfOptions, aOptions);
}
@ -487,8 +396,6 @@ DrawTargetRecording::DrawSurfaceWithShadow(SourceSurface *aSurface,
Float aSigma,
CompositionOp aOp)
{
EnsureSurfaceStored(mRecorder, aSurface, "DrawSurfaceWithShadow");
mRecorder->RecordEvent(RecordedDrawSurfaceWithShadow(this, aSurface, aDest, aColor, aOffset, aSigma, aOp));
mFinalDT->DrawSurfaceWithShadow(GetSourceSurface(aSurface), aDest, aColor, aOffset, aSigma, aOp);
}
@ -499,10 +406,8 @@ DrawTargetRecording::DrawFilter(FilterNode *aNode,
const Point &aDestPoint,
const DrawOptions &aOptions)
{
MOZ_ASSERT(mRecorder->HasStoredObject(aNode));
mRecorder->RecordEvent(RecordedDrawFilter(this, aNode, aSourceRect, aDestPoint, aOptions));
mFinalDT->DrawFilter(FilterNodeRecording::GetFilterNode(aNode), aSourceRect, aDestPoint, aOptions);
mFinalDT->DrawFilter(GetFilterNode(aNode), aSourceRect, aDestPoint, aOptions);
}
already_AddRefed<FilterNode>
@ -529,8 +434,6 @@ DrawTargetRecording::CopySurface(SourceSurface *aSurface,
const IntRect &aSourceRect,
const IntPoint &aDestination)
{
EnsureSurfaceStored(mRecorder, aSurface, "CopySurface");
mRecorder->RecordEvent(RecordedCopySurface(this, aSurface, aSourceRect, aDestination));
mFinalDT->CopySurface(GetSourceSurface(aSurface), aSourceRect, aDestination);
}
@ -538,10 +441,10 @@ DrawTargetRecording::CopySurface(SourceSurface *aSurface,
void
DrawTargetRecording::PushClip(const Path *aPath)
{
RefPtr<PathRecording> pathRecording = EnsurePathStored(aPath);
EnsureStored(aPath);
mRecorder->RecordEvent(RecordedPushClip(this, pathRecording));
mFinalDT->PushClip(pathRecording->mPath);
mRecorder->RecordEvent(RecordedPushClip(this, const_cast<Path*>(aPath)));
mFinalDT->PushClip(GetPathForPathRecording(aPath));
}
void
@ -587,7 +490,21 @@ DrawTargetRecording::OptimizeSourceSurface(SourceSurface *aSurface) const
dataSurf = aSurface->GetDataSurface();
}
StoreSourceSurface(mRecorder, retSurf, dataSurf, "OptimizeSourceSurface");
if (!dataSurf) {
gfxWarning() << "Recording failed to record SourceSurface created from OptimizeSourceSurface";
// Insert a bogus source surface.
uint8_t *sourceData = new uint8_t[surf->GetSize().width * surf->GetSize().height * BytesPerPixel(surf->GetFormat())];
memset(sourceData, 0, surf->GetSize().width * surf->GetSize().height * BytesPerPixel(surf->GetFormat()));
mRecorder->RecordEvent(
RecordedSourceSurfaceCreation(retSurf, sourceData,
surf->GetSize().width * BytesPerPixel(surf->GetFormat()),
surf->GetSize(), surf->GetFormat()));
delete [] sourceData;
} else {
mRecorder->RecordEvent(
RecordedSourceSurfaceCreation(retSurf, dataSurf->GetData(), dataSurf->Stride(),
dataSurf->GetSize(), dataSurf->GetFormat()));
}
return retSurf.forget();
}
@ -600,7 +517,22 @@ DrawTargetRecording::CreateSourceSurfaceFromNativeSurface(const NativeSurface &a
RefPtr<SourceSurface> retSurf = new SourceSurfaceRecording(surf, mRecorder);
RefPtr<DataSourceSurface> dataSurf = surf->GetDataSurface();
StoreSourceSurface(mRecorder, retSurf, dataSurf, "CreateSourceSurfaceFromNativeSurface");
if (!dataSurf) {
gfxWarning() << "Recording failed to record SourceSurface created from OptimizeSourceSurface";
// Insert a bogus source surface.
uint8_t *sourceData = new uint8_t[surf->GetSize().width * surf->GetSize().height * BytesPerPixel(surf->GetFormat())];
memset(sourceData, 0, surf->GetSize().width * surf->GetSize().height * BytesPerPixel(surf->GetFormat()));
mRecorder->RecordEvent(
RecordedSourceSurfaceCreation(retSurf, sourceData,
surf->GetSize().width * BytesPerPixel(surf->GetFormat()),
surf->GetSize(), surf->GetFormat()));
delete [] sourceData;
} else {
mRecorder->RecordEvent(
RecordedSourceSurfaceCreation(retSurf, dataSurf->GetData(), dataSurf->Stride(),
dataSurf->GetSize(), dataSurf->GetFormat()));
}
return retSurf.forget();
}
@ -608,7 +540,8 @@ DrawTargetRecording::CreateSourceSurfaceFromNativeSurface(const NativeSurface &a
already_AddRefed<DrawTarget>
DrawTargetRecording::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
{
return MakeAndAddRef<DrawTargetRecording>(this, aSize, aFormat);
RefPtr<DrawTarget> dt = mFinalDT->CreateSimilarDrawTarget(aSize, aFormat);
return MakeAndAddRef<DrawTargetRecording>(mRecorder.get(), dt);
}
already_AddRefed<PathBuilder>
@ -640,54 +573,17 @@ DrawTargetRecording::SetTransform(const Matrix &aTransform)
mFinalDT->SetTransform(aTransform);
}
already_AddRefed<PathRecording>
DrawTargetRecording::EnsurePathStored(const Path *aPath)
{
RefPtr<PathRecording> pathRecording;
if (aPath->GetBackendType() == BackendType::RECORDING) {
pathRecording = const_cast<PathRecording*>(static_cast<const PathRecording*>(aPath));
if (mRecorder->HasStoredObject(aPath)) {
return pathRecording.forget();
}
} else {
MOZ_ASSERT(!mRecorder->HasStoredObject(aPath));
FillRule fillRule = aPath->GetFillRule();
RefPtr<PathBuilder> builder = mFinalDT->CreatePathBuilder(fillRule);
RefPtr<PathBuilderRecording> builderRecording =
new PathBuilderRecording(builder, fillRule);
aPath->StreamToSink(builderRecording);
pathRecording = builderRecording->Finish().downcast<PathRecording>();
}
mRecorder->RecordEvent(RecordedPathCreation(pathRecording));
mRecorder->AddStoredObject(pathRecording);
pathRecording->mStoredRecorders.push_back(mRecorder);
return pathRecording.forget();
}
void
DrawTargetRecording::EnsurePatternDependenciesStored(const Pattern &aPattern)
DrawTargetRecording::EnsureStored(const Path *aPath)
{
switch (aPattern.GetType()) {
case PatternType::COLOR:
// No dependencies here.
return;
case PatternType::LINEAR_GRADIENT:
{
MOZ_ASSERT(mRecorder->HasStoredObject(static_cast<const LinearGradientPattern*>(&aPattern)->mStops));
return;
}
case PatternType::RADIAL_GRADIENT:
{
MOZ_ASSERT(mRecorder->HasStoredObject(static_cast<const RadialGradientPattern*>(&aPattern)->mStops));
return;
}
case PatternType::SURFACE:
{
const SurfacePattern *pat = static_cast<const SurfacePattern*>(&aPattern);
EnsureSurfaceStored(mRecorder, pat->mSurface, "EnsurePatternDependenciesStored");
return;
if (!mRecorder->HasStoredPath(aPath)) {
if (aPath->GetBackendType() != BackendType::RECORDING) {
gfxWarning() << "Cannot record this fill path properly!";
} else {
PathRecording *recPath = const_cast<PathRecording*>(static_cast<const PathRecording*>(aPath));
mRecorder->RecordEvent(RecordedPathCreation(recPath));
mRecorder->AddStoredPath(aPath);
recPath->mStoredRecorders.push_back(mRecorder);
}
}
}

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

@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 20; 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/. */
@ -18,22 +17,10 @@ class DrawTargetRecording : public DrawTarget
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override)
DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false);
/**
* Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
*
* @param aDT DrawTargetRecording on which CreateSimilarDrawTarget was called
* @param aSize size for the similar DrawTarget
* @param aFormat format for the similar DrawTarget
*/
DrawTargetRecording(const DrawTargetRecording *aDT, const IntSize &aSize,
SurfaceFormat aFormat);
~DrawTargetRecording();
virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); }
virtual BackendType GetBackendType() const override { return mFinalDT->GetBackendType(); }
virtual bool IsRecording() const override { return true; }
virtual already_AddRefed<SourceSurface> Snapshot() override;
@ -288,8 +275,7 @@ public:
private:
Path *GetPathForPathRecording(const Path *aPath) const;
already_AddRefed<PathRecording> EnsurePathStored(const Path *aPath);
void EnsurePatternDependenciesStored(const Pattern &aPattern);
void EnsureStored(const Path *aPath);
RefPtr<DrawEventRecorderPrivate> mRecorder;
RefPtr<DrawTarget> mFinalDT;

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

@ -21,7 +21,6 @@
#if defined(WIN32)
#include "ScaledFontWin.h"
#include "NativeFontResourceGDI.h"
#endif
#ifdef XP_DARWIN
@ -37,7 +36,6 @@
#include "DrawTargetD2D.h"
#include "DrawTargetD2D1.h"
#include "ScaledFontDWrite.h"
#include "NativeFontResourceDWrite.h"
#include <d3d10_1.h>
#include "HelpersD2D.h"
#endif
@ -50,7 +48,6 @@
#include "DrawEventRecorder.h"
#include "Preferences.h"
#include "Logging.h"
#include "mozilla/CheckedInt.h"
@ -155,9 +152,31 @@ HasCPUIDBit(unsigned int level, CPUIDRegister reg, unsigned int bit)
namespace mozilla {
namespace gfx {
int32_t LoggingPrefs::sGfxLogLevel =
PreferenceAccess::RegisterLivePref("gfx.logging.level", &sGfxLogLevel,
LOG_DEFAULT);
// These values we initialize with should match those in
// PreferenceAccess::RegisterAll method.
int32_t PreferenceAccess::sGfxLogLevel = LOG_DEFAULT;
PreferenceAccess* PreferenceAccess::sAccess = nullptr;
PreferenceAccess::~PreferenceAccess()
{
}
// Just a placeholder, the derived class will set the variable to default
// if the preference doesn't exist.
void PreferenceAccess::LivePref(const char* aName, int32_t* aVar, int32_t aDef)
{
*aVar = aDef;
}
// This will be called with the derived class, so we will want to register
// the callbacks with it.
void PreferenceAccess::SetAccess(PreferenceAccess* aAccess) {
sAccess = aAccess;
if (sAccess) {
RegisterAll();
}
}
#ifdef WIN32
ID3D10Device1 *Factory::mD3D10Device;
@ -542,35 +561,20 @@ Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSiz
}
}
already_AddRefed<NativeFontResource>
Factory::CreateNativeFontResource(uint8_t *aData, uint32_t aSize,
FontType aType)
already_AddRefed<ScaledFont>
Factory::CreateScaledFontForTrueTypeData(uint8_t *aData, uint32_t aSize,
uint32_t aFaceIndex, Float aGlyphSize,
FontType aType)
{
switch (aType) {
#ifdef WIN32
case FontType::DWRITE:
{
return NativeFontResourceDWrite::Create(aData, aSize,
/* aNeedsCairo = */ false);
return MakeAndAddRef<ScaledFontDWrite>(aData, aSize, aFaceIndex, aGlyphSize);
}
#endif
case FontType::CAIRO:
{
#ifdef WIN32
if (GetDirect3D11Device()) {
return NativeFontResourceDWrite::Create(aData, aSize,
/* aNeedsCairo = */ true);
} else {
return NativeFontResourceGDI::Create(aData, aSize,
/* aNeedsCairo = */ true);
}
#else
gfxWarning() << "Unable to create cairo scaled font from truetype data";
return nullptr;
#endif
}
default:
gfxWarning() << "Unable to create requested font resource from truetype data";
gfxWarning() << "Unable to create requested font type from truetype data";
return nullptr;
}
}

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

@ -62,9 +62,24 @@ inline mozilla::LogLevel PRLogLevelForLevel(int aLevel) {
}
#endif
class LoggingPrefs
class PreferenceAccess
{
public:
virtual ~PreferenceAccess();
// This should connect the variable aVar to be updated whenever a preference
// aName is modified. aDefault would be used if the preference is undefined,
// so that we always get the valid value for aVar.
virtual void LivePref(const char* aName, int32_t* aVar, int32_t aDefault);
public:
static void SetAccess(PreferenceAccess* aAccess);
public:
// For each preference that needs to be accessed in Moz2D, add a variable
// to hold it, as well as the call to LivePref in the RegisterAll() method
// below.
// Used to choose the level of logging we get. The higher the number,
// the more logging we get. Value of zero will give you no logging,
// 1 just errors, 2 adds warnings and 3 adds logging/debug. 4 is used to
@ -73,6 +88,15 @@ public:
// in addition to setting the value to 4, you will need to set an
// environment variable NSPR_LOG_MODULES to gfx:4. See prlog.h for details.
static int32_t sGfxLogLevel;
private:
static void RegisterAll() {
// The default values (last parameter) should match the initialization
// values in Factory.cpp, otherwise the standalone Moz2D will get different
// defaults.
sAccess->LivePref("gfx.logging.level", &sGfxLogLevel, LOG_DEFAULT);
}
static PreferenceAccess* sAccess;
};
/// Graphics logging is available in both debug and release builds and is
@ -140,7 +164,7 @@ struct BasicLogger
// OutputMessage below. If making any changes here, also make it
// in the appropriate places in that method.
static bool ShouldOutputMessage(int aLevel) {
if (LoggingPrefs::sGfxLogLevel >= aLevel) {
if (PreferenceAccess::sGfxLogLevel >= aLevel) {
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
return true;
#else
@ -149,7 +173,7 @@ struct BasicLogger
return true;
} else
#endif
if ((LoggingPrefs::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
if ((PreferenceAccess::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
(aLevel < LOG_DEBUG)) {
return true;
}
@ -173,7 +197,7 @@ struct BasicLogger
// If making any logic changes to this method, you should probably
// make the corresponding change in the ShouldOutputMessage method
// above.
if (LoggingPrefs::sGfxLogLevel >= aLevel) {
if (PreferenceAccess::sGfxLogLevel >= aLevel) {
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
printf_stderr("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
#else
@ -182,7 +206,7 @@ struct BasicLogger
PR_LogPrint("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
} else
#endif
if ((LoggingPrefs::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
if ((PreferenceAccess::sGfxLogLevel >= LOG_DEBUG_PRLOG) ||
(aLevel < LOG_DEBUG)) {
printf("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
}

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

@ -1,287 +0,0 @@
/* -*- 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/. */
#include "NativeFontResourceDWrite.h"
#include <unordered_map>
#include "DrawTargetD2D.h"
#include "Logging.h"
#include "mozilla/RefPtr.h"
namespace mozilla {
namespace gfx {
static Atomic<uint64_t> sNextFontFileKey;
static std::unordered_map<uint64_t, IDWriteFontFileStream*> sFontFileStreams;
class DWriteFontFileLoader : public IDWriteFontFileLoader
{
public:
DWriteFontFileLoader()
{
}
// IUnknown interface
IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
{
if (iid == __uuidof(IDWriteFontFileLoader)) {
*ppObject = static_cast<IDWriteFontFileLoader*>(this);
return S_OK;
} else if (iid == __uuidof(IUnknown)) {
*ppObject = static_cast<IUnknown*>(this);
return S_OK;
} else {
return E_NOINTERFACE;
}
}
IFACEMETHOD_(ULONG, AddRef)()
{
return 1;
}
IFACEMETHOD_(ULONG, Release)()
{
return 1;
}
// IDWriteFontFileLoader methods
/**
* Important! Note the key here has to be a uint64_t that will have been
* generated by incrementing sNextFontFileKey.
*/
virtual HRESULT STDMETHODCALLTYPE
CreateStreamFromKey(void const* fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
OUT IDWriteFontFileStream** fontFileStream);
/**
* Gets the singleton loader instance. Note that when using this font
* loader, the key must be a uint64_t that has been generated by incrementing
* sNextFontFileKey.
* Also note that this is _not_ threadsafe.
*/
static IDWriteFontFileLoader* Instance()
{
if (!mInstance) {
mInstance = new DWriteFontFileLoader();
DrawTargetD2D::GetDWriteFactory()->
RegisterFontFileLoader(mInstance);
}
return mInstance;
}
private:
static IDWriteFontFileLoader* mInstance;
};
class DWriteFontFileStream : public IDWriteFontFileStream
{
public:
/**
* Used by the FontFileLoader to create a new font stream,
* this font stream is created from data in memory. The memory
* passed may be released after object creation, it will be
* copied internally.
*
* @param aData Font data
*/
DWriteFontFileStream(uint8_t *aData, uint32_t aSize, uint64_t aFontFileKey);
~DWriteFontFileStream();
// IUnknown interface
IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
{
if (iid == __uuidof(IDWriteFontFileStream)) {
*ppObject = static_cast<IDWriteFontFileStream*>(this);
return S_OK;
} else if (iid == __uuidof(IUnknown)) {
*ppObject = static_cast<IUnknown*>(this);
return S_OK;
} else {
return E_NOINTERFACE;
}
}
IFACEMETHOD_(ULONG, AddRef)()
{
++mRefCnt;
return mRefCnt;
}
IFACEMETHOD_(ULONG, Release)()
{
--mRefCnt;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// IDWriteFontFileStream methods
virtual HRESULT STDMETHODCALLTYPE ReadFileFragment(void const** fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
OUT void** fragmentContext);
virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext);
virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize);
virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime);
private:
std::vector<uint8_t> mData;
uint32_t mRefCnt;
uint64_t mFontFileKey;
};
IDWriteFontFileLoader* DWriteFontFileLoader::mInstance = nullptr;
HRESULT STDMETHODCALLTYPE
DWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
IDWriteFontFileStream **fontFileStream)
{
if (!fontFileReferenceKey || !fontFileStream) {
return E_POINTER;
}
uint64_t fontFileKey = *static_cast<const uint64_t*>(fontFileReferenceKey);
auto found = sFontFileStreams.find(fontFileKey);
if (found == sFontFileStreams.end()) {
*fontFileStream = nullptr;
return E_FAIL;
}
found->second->AddRef();
*fontFileStream = found->second;
return S_OK;
}
DWriteFontFileStream::DWriteFontFileStream(uint8_t *aData, uint32_t aSize,
uint64_t aFontFileKey)
: mRefCnt(0)
, mFontFileKey(aFontFileKey)
{
mData.resize(aSize);
memcpy(&mData.front(), aData, aSize);
}
DWriteFontFileStream::~DWriteFontFileStream()
{
sFontFileStreams.erase(mFontFileKey);
}
HRESULT STDMETHODCALLTYPE
DWriteFontFileStream::GetFileSize(UINT64 *fileSize)
{
*fileSize = mData.size();
return S_OK;
}
HRESULT STDMETHODCALLTYPE
DWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE
DWriteFontFileStream::ReadFileFragment(const void **fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
void **fragmentContext)
{
// We are required to do bounds checking.
if (fileOffset + fragmentSize > mData.size()) {
return E_FAIL;
}
// truncate the 64 bit fileOffset to size_t sized index into mData
size_t index = static_cast<size_t>(fileOffset);
// We should be alive for the duration of this.
*fragmentStart = &mData[index];
*fragmentContext = nullptr;
return S_OK;
}
void STDMETHODCALLTYPE
DWriteFontFileStream::ReleaseFileFragment(void *fragmentContext)
{
}
/* static */
already_AddRefed<NativeFontResourceDWrite>
NativeFontResourceDWrite::Create(uint8_t *aFontData, uint32_t aDataLength,
bool aNeedsCairo)
{
IDWriteFactory *factory = DrawTargetD2D::GetDWriteFactory();
if (!factory) {
gfxWarning() << "Failed to get DWrite Factory.";
return nullptr;
}
uint64_t fontFileKey = sNextFontFileKey++;
RefPtr<IDWriteFontFileStream> ffsRef =
new DWriteFontFileStream(aFontData, aDataLength, fontFileKey);
sFontFileStreams[fontFileKey] = ffsRef;
RefPtr<IDWriteFontFile> fontFile;
HRESULT hr =
factory->CreateCustomFontFileReference(&fontFileKey, sizeof(fontFileKey),
DWriteFontFileLoader::Instance(),
getter_AddRefs(fontFile));
if (FAILED(hr)) {
gfxWarning() << "Failed to load font file from data!";
return nullptr;
}
BOOL isSupported;
DWRITE_FONT_FILE_TYPE fileType;
DWRITE_FONT_FACE_TYPE faceType;
UINT32 numberOfFaces;
hr = fontFile->Analyze(&isSupported, &fileType, &faceType, &numberOfFaces);
if (FAILED(hr) || !isSupported) {
gfxWarning() << "Font file is not supported.";
return nullptr;
}
RefPtr<NativeFontResourceDWrite> fontResource =
new NativeFontResourceDWrite(factory, fontFile.forget(), faceType,
numberOfFaces, aNeedsCairo);
return fontResource.forget();
}
already_AddRefed<ScaledFont>
NativeFontResourceDWrite::CreateScaledFont(uint32_t aIndex, uint32_t aGlyphSize)
{
if (aIndex >= mNumberOfFaces) {
gfxWarning() << "Font face index is too high for font resource.";
return nullptr;
}
IDWriteFontFile *fontFile = mFontFile;
RefPtr<IDWriteFontFace> fontFace;
if (FAILED(mFactory->CreateFontFace(mFaceType, 1, &fontFile, aIndex,
DWRITE_FONT_SIMULATIONS_NONE, getter_AddRefs(fontFace)))) {
gfxWarning() << "Failed to create font face from font file data.";
return nullptr;
}
RefPtr<ScaledFontBase> scaledFont = new ScaledFontDWrite(fontFace, aGlyphSize);
if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) {
gfxWarning() << "Unable to create cairo scaled font DWrite font.";
return nullptr;
}
return scaledFont.forget();
}
} // gfx
} // mozilla

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

@ -1,56 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_gfx_NativeFontResourceDWrite_h
#define mozilla_gfx_NativeFontResourceDWrite_h
#include <dwrite.h>
#include "2D.h"
#include "mozilla/AlreadyAddRefed.h"
namespace mozilla {
namespace gfx {
class NativeFontResourceDWrite final : public NativeFontResource
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceDWrite)
/**
* Creates a NativeFontResourceDWrite if data is valid. Note aFontData will be
* copied if required and so can be released after calling.
*
* @param aFontData the SFNT data.
* @param aDataLength length of data.
* @param aNeedsCairo whether the ScaledFont created needs a cairo scaled font
* @return Referenced NativeFontResourceDWrite or nullptr if invalid.
*/
static already_AddRefed<NativeFontResourceDWrite>
Create(uint8_t *aFontData, uint32_t aDataLength, bool aNeedsCairo);
already_AddRefed<ScaledFont>
CreateScaledFont(uint32_t aIndex, uint32_t aGlyphSize) final;
private:
NativeFontResourceDWrite(IDWriteFactory *aFactory,
already_AddRefed<IDWriteFontFile> aFontFile,
DWRITE_FONT_FACE_TYPE aFaceType,
uint32_t aNumberOfFaces, bool aNeedsCairo)
: mFactory(aFactory), mFontFile(aFontFile), mFaceType(aFaceType)
, mNumberOfFaces(aNumberOfFaces), mNeedsCairo(aNeedsCairo)
{}
IDWriteFactory *mFactory;
RefPtr<IDWriteFontFile> mFontFile;
DWRITE_FONT_FACE_TYPE mFaceType;
uint32_t mNumberOfFaces;
bool mNeedsCairo;
};
} // gfx
} // mozilla
#endif // mozilla_gfx_NativeFontResourceDWrite_h

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

@ -1,112 +0,0 @@
/* -*- 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/. */
#include "NativeFontResourceGDI.h"
#include "Logging.h"
#include "mozilla/RefPtr.h"
#include "ScaledFontWin.h"
#include "SFNTData.h"
namespace mozilla {
namespace gfx {
/* static */
already_AddRefed<NativeFontResourceGDI>
NativeFontResourceGDI::Create(uint8_t *aFontData, uint32_t aDataLength,
bool aNeedsCairo)
{
UniquePtr<SFNTData> sfntData = SFNTData::Create(aFontData, aDataLength);
if (!sfntData) {
gfxWarning() << "Failed to create SFNTData for ScaledFontWin.";
return nullptr;
}
Vector<mozilla::u16string> fontNames;
if (!sfntData->GetU16FullNames(fontNames)) {
gfxWarning() << "Failed to get font names from font.";
return nullptr;
}
// lfFaceName has a maximum length including null.
for (size_t i = 0; i < fontNames.length(); ++i) {
if (fontNames[i].size() > LF_FACESIZE - 1) {
fontNames[i].resize(LF_FACESIZE - 1);
}
// Add null to end for easy copying later.
fontNames[i].append(1, '\0');
}
DWORD numberOfFontsAdded;
HANDLE fontResourceHandle = ::AddFontMemResourceEx(aFontData, aDataLength,
0, &numberOfFontsAdded);
if (!fontResourceHandle) {
gfxWarning() << "Failed to add memory font resource.";
return nullptr;
}
if (numberOfFontsAdded != fontNames.length()) {
gfxWarning() <<
"Number of fonts added doesn't match number of names extracted.";
}
RefPtr<NativeFontResourceGDI> fontResouce =
new NativeFontResourceGDI(fontResourceHandle, Move(fontNames), aNeedsCairo);
return fontResouce.forget();
}
NativeFontResourceGDI::~NativeFontResourceGDI()
{
::RemoveFontMemResourceEx(mFontResourceHandle);
}
already_AddRefed<ScaledFont>
NativeFontResourceGDI::CreateScaledFont(uint32_t aIndex, uint32_t aGlyphSize)
{
if (aIndex >= mFontNames.length()) {
gfxWarning() << "Font index is too high for font resource.";
return nullptr;
}
if (mFontNames[aIndex].empty()) {
gfxWarning() << "Font name for index is empty.";
return nullptr;
}
LOGFONT logFont;
logFont.lfHeight = 0;
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = FW_DONTCARE;
logFont.lfItalic = FALSE;
logFont.lfUnderline = FALSE;
logFont.lfStrikeOut = FALSE;
logFont.lfCharSet = DEFAULT_CHARSET;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = DEFAULT_QUALITY;
logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
// Copy name to mLogFont (null already included in font name). We cast here
// because for VS2015 char16_t != wchar_t, even though they are both 16 bit.
mFontNames[aIndex].copy(reinterpret_cast<char16_t*>(logFont.lfFaceName),
mFontNames[aIndex].length());
// Constructor for ScaledFontWin dereferences and copies the LOGFONT, so we
// are safe to pass this reference.
RefPtr<ScaledFontBase> scaledFont = new ScaledFontWin(&logFont, aGlyphSize);
if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) {
gfxWarning() << "Unable to create cairo scaled font DWrite font.";
return nullptr;
}
return scaledFont.forget();
}
} // gfx
} // mozilla

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

@ -1,57 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_gfx_NativeFontResourceGDI_h
#define mozilla_gfx_NativeFontResourceGDI_h
#include <windows.h>
#include "2D.h"
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Vector.h"
#include "u16string.h"
namespace mozilla {
namespace gfx {
class NativeFontResourceGDI final : public NativeFontResource
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceGDI)
/**
* Creates a NativeFontResourceGDI if data is valid. Note aFontData will be
* copied if required and so can be released after calling.
*
* @param aFontData the SFNT data.
* @param aDataLength length of data.
* @param aNeedsCairo whether the ScaledFont created need a cairo scaled font
* @return Referenced NativeFontResourceGDI or nullptr if invalid.
*/
static already_AddRefed<NativeFontResourceGDI>
Create(uint8_t *aFontData, uint32_t aDataLength, bool aNeedsCairo);
~NativeFontResourceGDI();
already_AddRefed<ScaledFont>
CreateScaledFont(uint32_t aIndex, uint32_t aGlyphSize) final;
private:
NativeFontResourceGDI(HANDLE aFontResourceHandle,
Vector<mozilla::u16string>&& aFontNames,
bool aNeedsCairo)
: mFontResourceHandle(aFontResourceHandle), mFontNames(Move(aFontNames))
, mNeedsCairo(aNeedsCairo)
{}
HANDLE mFontResourceHandle;
Vector<mozilla::u16string> mFontNames;
bool mNeedsCairo;
};
} // gfx
} // mozilla
#endif // mozilla_gfx_NativeFontResourceGDI_h

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

@ -79,7 +79,7 @@ PathBuilderRecording::Finish()
PathRecording::~PathRecording()
{
for (size_t i = 0; i < mStoredRecorders.size(); i++) {
mStoredRecorders[i]->RemoveStoredObject(this);
mStoredRecorders[i]->RemoveStoredPath(this);
mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this));
}
}

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

@ -1,60 +0,0 @@
/* -*- 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/. */
#include "Preferences.h"
#include "mozilla/Assertions.h"
#include "mozilla/Vector.h"
namespace mozilla {
namespace gfx {
static PreferenceAccess* sAccess = nullptr;
struct Int32Pref
{
const char* name;
int32_t* varPtr;
};
static Vector<Int32Pref>& Int32Prefs()
{
static Vector<Int32Pref>* sInt32Prefs = new Vector<Int32Pref>();
return *sInt32Prefs;
}
/* static */
int32_t
PreferenceAccess::RegisterLivePref(const char* aName, int32_t* aVar,
int32_t aDefault)
{
Int32Prefs().append(Int32Pref{ aName, aVar });
return aDefault;
}
/* static */
void
PreferenceAccess::SetAccess(PreferenceAccess* aAccess)
{
sAccess = aAccess;
if (!sAccess) {
return;
}
#if defined(DEBUG)
static uint32_t sProvideAccessCount;
MOZ_ASSERT(!sProvideAccessCount++,
"ProvideAccess must only be called with non-nullptr once.");
#endif
for (Int32Pref pref : Int32Prefs()) {
sAccess->LivePref(pref.name, pref.varPtr, *pref.varPtr);
}
Int32Prefs().clearAndFree();
}
} // namespace gfx
} // namespace mozilla

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

@ -1,34 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_gfx_Preferences_h
#define mozilla_gfx_Preferences_h
namespace mozilla {
namespace gfx {
class PreferenceAccess
{
public:
virtual ~PreferenceAccess() {};
// This will be called with the derived class, so we will can register the
// callbacks with it.
static void SetAccess(PreferenceAccess* aAccess);
static int32_t RegisterLivePref(const char* aName, int32_t* aVar,
int32_t aDefault);
protected:
// This should connect the variable aVar to be updated whenever a preference
// aName is modified. aDefault would be used if the preference is undefined,
// so that we always get the valid value for aVar.
virtual void LivePref(const char* aName, int32_t* aVar, int32_t aDefault) = 0;
};
} // namespace gfx
} // namespace mozilla
#endif // mozilla_gfx_Preferences_h

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

@ -4,13 +4,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RecordedEvent.h"
#include "PathRecording.h"
#include "RecordingTypes.h"
#include "Tools.h"
#include "Filters.h"
#include "Logging.h"
#include "SFNTData.h"
namespace mozilla {
namespace gfx {
@ -29,16 +27,6 @@ static std::string NameFromBackend(BackendType aType)
}
}
already_AddRefed<DrawTarget>
Translator::CreateDrawTarget(ReferencePtr aRefPtr, const IntSize &aSize,
SurfaceFormat aFormat)
{
RefPtr<DrawTarget> newDT =
GetReferenceDrawTarget()->CreateSimilarDrawTarget(aSize, aFormat);
AddDrawTarget(aRefPtr, newDT);
return newDT.forget();
}
#define LOAD_EVENT_TYPE(_typeenum, _class) \
case _typeenum: return new _class(aStream)
@ -78,8 +66,6 @@ RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType)
LOAD_EVENT_TYPE(MASKSURFACE, RecordedMaskSurface);
LOAD_EVENT_TYPE(FILTERNODESETATTRIBUTE, RecordedFilterNodeSetAttribute);
LOAD_EVENT_TYPE(FILTERNODESETINPUT, RecordedFilterNodeSetInput);
LOAD_EVENT_TYPE(CREATESIMILARDRAWTARGET, RecordedCreateSimilarDrawTarget);
LOAD_EVENT_TYPE(FONTDATA, RecordedFontData);
default:
return nullptr;
}
@ -153,10 +139,6 @@ RecordedEvent::GetEventName(EventType aType)
return "SetAttribute";
case FILTERNODESETINPUT:
return "SetInput";
case CREATESIMILARDRAWTARGET:
return "CreateSimilarDrawTarget";
case FONTDATA:
return "FontData";
default:
return "Unknown";
}
@ -384,9 +366,10 @@ void
RecordedDrawTargetCreation::PlayEvent(Translator *aTranslator) const
{
RefPtr<DrawTarget> newDT =
aTranslator->CreateDrawTarget(mRefPtr, mSize, mFormat);
aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
aTranslator->AddDrawTarget(mRefPtr, newDT);
if (newDT && mHasExistingData) {
if (mHasExistingData) {
Rect dataRect(0, 0, mExistingData->GetSize().width, mExistingData->GetSize().height);
newDT->DrawSurface(mExistingData, dataRect, dataRect);
}
@ -469,36 +452,6 @@ RecordedDrawTargetDestruction::OutputSimpleEventInfo(stringstream &aStringStream
aStringStream << "[" << mRefPtr << "] DrawTarget Destruction";
}
void
RecordedCreateSimilarDrawTarget::PlayEvent(Translator *aTranslator) const
{
RefPtr<DrawTarget> newDT =
aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
aTranslator->AddDrawTarget(mRefPtr, newDT);
}
void
RecordedCreateSimilarDrawTarget::RecordToStream(ostream &aStream) const
{
WriteElement(aStream, mRefPtr);
WriteElement(aStream, mSize);
WriteElement(aStream, mFormat);
}
RecordedCreateSimilarDrawTarget::RecordedCreateSimilarDrawTarget(istream &aStream)
: RecordedEvent(CREATESIMILARDRAWTARGET)
{
ReadElement(aStream, mRefPtr);
ReadElement(aStream, mSize);
ReadElement(aStream, mFormat);
}
void
RecordedCreateSimilarDrawTarget::OutputSimpleEventInfo(stringstream &aStringStream) const
{
aStringStream << "[" << mRefPtr << "] CreateSimilarDrawTarget (Size: " << mSize.width << "x" << mSize.height << ")";
}
struct GenericPattern
{
GenericPattern(const PatternStorage &aStorage, Translator *aTranslator)
@ -1391,75 +1344,17 @@ RecordedSnapshot::OutputSimpleEventInfo(stringstream &aStringStream) const
aStringStream << "[" << mRefPtr << "] Snapshot Created (DT: " << mDT << ")";
}
RecordedFontData::~RecordedFontData()
RecordedScaledFontCreation::~RecordedScaledFontCreation()
{
delete[] mData;
}
void
RecordedFontData::PlayEvent(Translator *aTranslator) const
{
RefPtr<NativeFontResource> fontResource =
Factory::CreateNativeFontResource(mData, mFontDetails.size,
aTranslator->GetDesiredFontType());
aTranslator->AddNativeFontResource(mFontDetails.fontDataKey, fontResource);
}
void
RecordedFontData::RecordToStream(std::ostream &aStream) const
{
MOZ_ASSERT(mGetFontFileDataSucceeded);
WriteElement(aStream, mFontDetails.fontDataKey);
WriteElement(aStream, mFontDetails.size);
aStream.write((const char*)mData, mFontDetails.size);
}
void
RecordedFontData::OutputSimpleEventInfo(stringstream &aStringStream) const
{
aStringStream << "Font Data of size " << mFontDetails.size;
}
void
RecordedFontData::SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize)
{
mData = new uint8_t[aSize];
memcpy(mData, aData, aSize);
mFontDetails.fontDataKey = SFNTData::GetUniqueKey(aData, aSize);
mFontDetails.size = aSize;
mFontDetails.index = aIndex;
mFontDetails.glyphSize = aGlyphSize;
}
bool
RecordedFontData::GetFontDetails(RecordedFontDetails& fontDetails)
{
if (!mGetFontFileDataSucceeded) {
return false;
}
fontDetails.fontDataKey = mFontDetails.fontDataKey;
fontDetails.size = mFontDetails.size;
fontDetails.glyphSize = mFontDetails.glyphSize;
fontDetails.index = mFontDetails.index;
return true;
}
RecordedFontData::RecordedFontData(istream &aStream)
: RecordedEvent(FONTDATA)
{
ReadElement(aStream, mFontDetails.fontDataKey);
ReadElement(aStream, mFontDetails.size);
mData = new uint8_t[mFontDetails.size];
aStream.read((char*)mData, mFontDetails.size);
delete [] mData;
}
void
RecordedScaledFontCreation::PlayEvent(Translator *aTranslator) const
{
NativeFontResource *fontResource = aTranslator->LookupNativeFontResource(mFontDataKey);
RefPtr<ScaledFont> scaledFont = fontResource->CreateScaledFont(mIndex, mGlyphSize);
RefPtr<ScaledFont> scaledFont =
Factory::CreateScaledFontForTrueTypeData(mData, mSize, mIndex, mGlyphSize,
aTranslator->GetDesiredFontType());
aTranslator->AddScaledFont(mRefPtr, scaledFont);
}
@ -1467,9 +1362,10 @@ void
RecordedScaledFontCreation::RecordToStream(std::ostream &aStream) const
{
WriteElement(aStream, mRefPtr);
WriteElement(aStream, mFontDataKey);
WriteElement(aStream, mIndex);
WriteElement(aStream, mGlyphSize);
WriteElement(aStream, mSize);
aStream.write((const char*)mData, mSize);
}
void
@ -1478,13 +1374,25 @@ RecordedScaledFontCreation::OutputSimpleEventInfo(stringstream &aStringStream) c
aStringStream << "[" << mRefPtr << "] ScaledFont Created";
}
void
RecordedScaledFontCreation::SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize)
{
mData = new uint8_t[aSize];
memcpy(mData, aData, aSize);
mSize = aSize;
mIndex = aIndex;
mGlyphSize = aGlyphSize;
}
RecordedScaledFontCreation::RecordedScaledFontCreation(istream &aStream)
: RecordedEvent(SCALEDFONTCREATION)
{
ReadElement(aStream, mRefPtr);
ReadElement(aStream, mFontDataKey);
ReadElement(aStream, mIndex);
ReadElement(aStream, mGlyphSize);
ReadElement(aStream, mSize);
mData = new uint8_t[mSize];
aStream.read((char*)mData, mSize);
}
void
@ -1571,7 +1479,6 @@ RecordedFilterNodeSetAttribute::PlayEvent(Translator *aTranslator) const
REPLAY_SET_ATTRIBUTE(Rect, RECT);
REPLAY_SET_ATTRIBUTE(IntRect, INTRECT);
REPLAY_SET_ATTRIBUTE(Point, POINT);
REPLAY_SET_ATTRIBUTE(Matrix, MATRIX);
REPLAY_SET_ATTRIBUTE(Matrix5x4, MATRIX5X4);
REPLAY_SET_ATTRIBUTE(Point3D, POINT3D);
REPLAY_SET_ATTRIBUTE(Color, COLOR);

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

@ -10,24 +10,20 @@
#include <ostream>
#include <sstream>
#include <cstring>
#include <vector>
#include "RecordingTypes.h"
#include "PathRecording.h"
namespace mozilla {
namespace gfx {
struct PathOp;
class PathRecording;
const uint32_t kMagicInt = 0xc001feed;
// A change in major revision means a change in event binary format, causing
// loss of backwards compatibility. Old streams will not work in a player
// using a newer major revision. And new streams will not work in a player
// using an older major revision.
const uint16_t kMajorRevision = 4;
const uint16_t kMajorRevision = 3;
// A change in minor revision means additions of new events. New streams will
// not play in older players.
const uint16_t kMinorRevision = 0;
const uint16_t kMinorRevision = 2;
struct ReferencePtr
{
@ -62,14 +58,6 @@ struct ReferencePtr
uint64_t mLongPtr;
};
struct RecordedFontDetails
{
uint64_t fontDataKey;
uint32_t size;
uint32_t index;
Float glyphSize;
};
// Used by the Azure drawing debugger (player2d)
inline std::string StringFromPtr(ReferencePtr aPtr)
{
@ -89,7 +77,6 @@ public:
virtual FilterNode *LookupFilterNode(ReferencePtr aRefPtr) = 0;
virtual GradientStops *LookupGradientStops(ReferencePtr aRefPtr) = 0;
virtual ScaledFont *LookupScaledFont(ReferencePtr aRefPtr) = 0;
virtual NativeFontResource *LookupNativeFontResource(uint64_t aKey) = 0;
virtual void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) = 0;
virtual void RemoveDrawTarget(ReferencePtr aRefPtr) = 0;
virtual void AddPath(ReferencePtr aRefPtr, Path *aPath) = 0;
@ -102,12 +89,7 @@ public:
virtual void RemoveGradientStops(ReferencePtr aRefPtr) = 0;
virtual void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) = 0;
virtual void RemoveScaledFont(ReferencePtr aRefPtr) = 0;
virtual void AddNativeFontResource(uint64_t aKey,
NativeFontResource *aNativeFontResource) = 0;
virtual already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
const IntSize &aSize,
SurfaceFormat aFormat);
virtual DrawTarget *GetReferenceDrawTarget() = 0;
virtual FontType GetDesiredFontType() = 0;
};
@ -189,14 +171,10 @@ public:
FILTERNODEDESTRUCTION,
DRAWFILTER,
FILTERNODESETATTRIBUTE,
FILTERNODESETINPUT,
CREATESIMILARDRAWTARGET,
FONTDATA,
FILTERNODESETINPUT
};
static const uint32_t kTotalEventTypes = RecordedEvent::FILTERNODESETINPUT + 1;
virtual ~RecordedEvent() {}
static std::string GetEventName(EventType aType);
virtual void PlayEvent(Translator *aTranslator) const {}
@ -303,34 +281,6 @@ private:
MOZ_IMPLICIT RecordedDrawTargetDestruction(std::istream &aStream);
};
class RecordedCreateSimilarDrawTarget : public RecordedEvent
{
public:
RecordedCreateSimilarDrawTarget(ReferencePtr aRefPtr, const IntSize &aSize,
SurfaceFormat aFormat)
: RecordedEvent(CREATESIMILARDRAWTARGET)
, mRefPtr(aRefPtr) , mSize(aSize), mFormat(aFormat)
{
}
virtual void PlayEvent(Translator *aTranslator) const;
virtual void RecordToStream(std::ostream &aStream) const;
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
virtual std::string GetName() const { return "CreateSimilarDrawTarget"; }
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
ReferencePtr mRefPtr;
IntSize mSize;
SurfaceFormat mFormat;
private:
friend class RecordedEvent;
MOZ_IMPLICIT RecordedCreateSimilarDrawTarget(std::istream &aStream);
};
class RecordedFillRect : public RecordedDrawingEvent {
public:
RecordedFillRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions)
@ -949,59 +899,21 @@ private:
MOZ_IMPLICIT RecordedSnapshot(std::istream &aStream);
};
class RecordedFontData : public RecordedEvent {
public:
static void FontDataProc(const uint8_t *aData, uint32_t aSize,
uint32_t aIndex, Float aGlyphSize, void* aBaton)
{
auto recordedFontData = static_cast<RecordedFontData*>(aBaton);
recordedFontData->SetFontData(aData, aSize, aIndex, aGlyphSize);
}
explicit RecordedFontData(ScaledFont *aScaledFont)
: RecordedEvent(FONTDATA), mData(nullptr)
{
mGetFontFileDataSucceeded = aScaledFont->GetFontFileData(&FontDataProc, this);
}
~RecordedFontData();
virtual void PlayEvent(Translator *aTranslator) const;
virtual void RecordToStream(std::ostream &aStream) const;
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
virtual std::string GetName() const { return "Font Data"; }
virtual ReferencePtr GetObjectRef() const { return nullptr; };
void SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex,
Float aGlyphSize);
bool GetFontDetails(RecordedFontDetails& fontDetails);
private:
friend class RecordedEvent;
uint8_t *mData;
RecordedFontDetails mFontDetails;
bool mGetFontFileDataSucceeded = false;
MOZ_IMPLICIT RecordedFontData(std::istream &aStream);
};
class RecordedScaledFontCreation : public RecordedEvent {
public:
RecordedScaledFontCreation(ReferencePtr aRefPtr,
RecordedFontDetails aFontDetails)
: RecordedEvent(SCALEDFONTCREATION), mRefPtr(aRefPtr)
, mFontDataKey(aFontDetails.fontDataKey)
, mGlyphSize(aFontDetails.glyphSize) , mIndex(aFontDetails.index)
static void FontDataProc(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize, void* aBaton)
{
static_cast<RecordedScaledFontCreation*>(aBaton)->SetFontData(aData, aSize, aIndex, aGlyphSize);
}
RecordedScaledFontCreation(ReferencePtr aRefPtr, ScaledFont *aScaledFont)
: RecordedEvent(SCALEDFONTCREATION), mRefPtr(aRefPtr), mData(nullptr)
{
aScaledFont->GetFontFileData(&FontDataProc, this);
}
~RecordedScaledFontCreation();
virtual void PlayEvent(Translator *aTranslator) const;
virtual void RecordToStream(std::ostream &aStream) const;
@ -1010,11 +922,14 @@ public:
virtual std::string GetName() const { return "ScaledFont Creation"; }
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
void SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize);
private:
friend class RecordedEvent;
ReferencePtr mRefPtr;
uint64_t mFontDataKey;
uint8_t *mData;
uint32_t mSize;
Float mGlyphSize;
uint32_t mIndex;
@ -1083,7 +998,6 @@ public:
ARGTYPE_RECT,
ARGTYPE_INTRECT,
ARGTYPE_POINT,
ARGTYPE_MATRIX,
ARGTYPE_MATRIX5X4,
ARGTYPE_POINT3D,
ARGTYPE_COLOR,

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

@ -1,240 +0,0 @@
/* -*- 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/. */
#include "SFNTData.h"
#include <algorithm>
#include "BigEndianInts.h"
#include "Logging.h"
#include "mozilla/HashFunctions.h"
#include "SFNTNameTable.h"
namespace mozilla {
namespace gfx {
#define TRUETYPE_TAG(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
#pragma pack(push, 1)
struct TTCHeader
{
BigEndianUint32 ttcTag; // Always 'ttcf'
BigEndianUint32 version; // Fixed, 0x00010000
BigEndianUint32 numFonts;
};
struct OffsetTable
{
BigEndianUint32 sfntVersion; // Fixed, 0x00010000 for version 1.0.
BigEndianUint16 numTables;
BigEndianUint16 searchRange; // (Maximum power of 2 <= numTables) x 16.
BigEndianUint16 entrySelector; // Log2(maximum power of 2 <= numTables).
BigEndianUint16 rangeShift; // NumTables x 16-searchRange.
};
struct TableDirEntry
{
BigEndianUint32 tag; // 4 -byte identifier.
BigEndianUint32 checkSum; // CheckSum for this table.
BigEndianUint32 offset; // Offset from beginning of TrueType font file.
BigEndianUint32 length; // Length of this table.
friend bool operator<(const TableDirEntry& lhs, const uint32_t aTag)
{
return lhs.tag < aTag;
}
};
#pragma pack(pop)
class SFNTData::Font
{
public:
Font(const OffsetTable *aOffsetTable, const uint8_t *aFontData,
uint32_t aDataLength)
: mFontData(aFontData)
, mFirstDirEntry(reinterpret_cast<const TableDirEntry*>(aOffsetTable + 1))
, mEndOfDirEntries(mFirstDirEntry + aOffsetTable->numTables)
, mDataLength(aDataLength)
{
}
bool GetU16FullName(mozilla::u16string& aU16FullName)
{
const TableDirEntry* dirEntry =
GetDirEntry(TRUETYPE_TAG('n', 'a', 'm', 'e'));
if (!dirEntry) {
gfxWarning() << "Name table entry not found.";
return false;
}
UniquePtr<SFNTNameTable> nameTable =
SFNTNameTable::Create((mFontData + dirEntry->offset), dirEntry->length);
if (!nameTable) {
return false;
}
return nameTable->GetU16FullName(aU16FullName);
}
private:
const TableDirEntry*
GetDirEntry(const uint32_t aTag)
{
const TableDirEntry* foundDirEntry =
std::lower_bound(mFirstDirEntry, mEndOfDirEntries, aTag);
if (foundDirEntry == mEndOfDirEntries || foundDirEntry->tag != aTag) {
gfxWarning() << "Font data does not contain tag.";
return nullptr;
}
if (mDataLength < (foundDirEntry->offset + foundDirEntry->length)) {
gfxWarning() << "Font data too short to contain table.";
return nullptr;
}
return foundDirEntry;
}
const uint8_t *mFontData;
const TableDirEntry *mFirstDirEntry;
const TableDirEntry *mEndOfDirEntries;
uint32_t mDataLength;
};
/* static */
UniquePtr<SFNTData>
SFNTData::Create(const uint8_t *aFontData, uint32_t aDataLength)
{
MOZ_ASSERT(aFontData);
// Check to see if this is a font collection.
if (aDataLength < sizeof(TTCHeader)) {
gfxWarning() << "Font data too short.";
return nullptr;
}
const TTCHeader *ttcHeader = reinterpret_cast<const TTCHeader*>(aFontData);
if (ttcHeader->ttcTag == TRUETYPE_TAG('t', 't', 'c', 'f')) {
uint32_t numFonts = ttcHeader->numFonts;
if (aDataLength < sizeof(TTCHeader) + (numFonts * sizeof(BigEndianUint32))) {
gfxWarning() << "Font data too short to contain full TTC Header.";
return nullptr;
}
UniquePtr<SFNTData> sfntData(new SFNTData);
const BigEndianUint32* offset =
reinterpret_cast<const BigEndianUint32*>(aFontData + sizeof(TTCHeader));
const BigEndianUint32* endOfOffsets = offset + numFonts;
while (offset != endOfOffsets) {
if (!sfntData->AddFont(aFontData, aDataLength, *offset)) {
return nullptr;
}
++offset;
}
return Move(sfntData);
}
UniquePtr<SFNTData> sfntData(new SFNTData);
if (!sfntData->AddFont(aFontData, aDataLength, 0)) {
return nullptr;
}
return Move(sfntData);
}
/* static */
uint64_t
SFNTData::GetUniqueKey(const uint8_t *aFontData, uint32_t aDataLength)
{
uint64_t hash;
UniquePtr<SFNTData> sfntData = SFNTData::Create(aFontData, aDataLength);
mozilla::u16string firstName;
if (sfntData && sfntData->GetU16FullName(0, firstName)) {
hash = HashString(firstName.c_str(), firstName.length());
} else {
gfxWarning() << "Failed to get name from font data hashing whole font.";
hash = HashString(aFontData, aDataLength);
}
return hash << 32 | aDataLength;;
}
SFNTData::~SFNTData()
{
for (size_t i = 0; i < mFonts.length(); ++i) {
delete mFonts[i];
}
}
bool
SFNTData::GetU16FullName(uint32_t aIndex, mozilla::u16string& aU16FullName)
{
if (aIndex >= mFonts.length()) {
gfxWarning() << "aIndex to font data too high.";
return false;
}
return mFonts[aIndex]->GetU16FullName(aU16FullName);
}
bool
SFNTData::GetU16FullNames(Vector<mozilla::u16string>& aU16FullNames)
{
bool fontFound = false;
for (size_t i = 0; i < mFonts.length(); ++i) {
mozilla::u16string name;
if (mFonts[i]->GetU16FullName(name)) {
fontFound = true;
}
aU16FullNames.append(Move(name));
}
return fontFound;
}
bool
SFNTData::GetIndexForU16Name(const mozilla::u16string& aU16FullName,
uint32_t* aIndex)
{
for (size_t i = 0; i < mFonts.length(); ++i) {
mozilla::u16string name;
if (mFonts[i]->GetU16FullName(name) && name == aU16FullName) {
*aIndex = i;
return true;
}
}
return false;
}
bool
SFNTData::AddFont(const uint8_t *aFontData, uint32_t aDataLength,
uint32_t aOffset)
{
uint32_t remainingLength = aDataLength - aOffset;
if (remainingLength < sizeof(OffsetTable)) {
gfxWarning() << "Font data too short to contain OffsetTable " << aOffset;
return false;
}
const OffsetTable *offsetTable =
reinterpret_cast<const OffsetTable*>(aFontData + aOffset);
if (remainingLength <
sizeof(OffsetTable) + (offsetTable->numTables * sizeof(TableDirEntry))) {
gfxWarning() << "Font data too short to contain tables.";
return false;
}
return mFonts.append(new Font(offsetTable, aFontData, aDataLength));
}
} // gfx
} // mozilla

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

@ -1,93 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_gfx_SFNTData_h
#define mozilla_gfx_SFNTData_h
#include "mozilla/UniquePtr.h"
#include "mozilla/Vector.h"
#include "u16string.h"
namespace mozilla {
namespace gfx {
class SFNTData final
{
public:
/**
* Creates an SFNTData if the header is a format that we understand and
* aDataLength is sufficient for the length information in the header data.
* Note that the data is NOT copied, so must exist the SFNTData's lifetime.
*
* @param aFontData the SFNT data.
* @param aDataLength length
* @return UniquePtr to a SFNTData or nullptr if the header is invalid.
*/
static UniquePtr<SFNTData> Create(const uint8_t *aFontData,
uint32_t aDataLength);
/**
* Creates a unique key for the given font data.
*
* @param aFontData the SFNT data
* @param aDataLength length
* @return unique key to be used for caching
*/
static uint64_t GetUniqueKey(const uint8_t *aFontData, uint32_t aDataLength);
~SFNTData();
/**
* Gets the full name from the name table of the font corresponding to the
* index. If the full name string is not present it will use the family space
* concatenated with the style.
* This will only read names that are already UTF16.
*
* @param aFontData SFNT data.
* @param aDataLength length of aFontData.
* @param aU16FullName string to be populated with the full name.
* @return true if the full name is successfully read.
*/
bool GetU16FullName(uint32_t aIndex, mozilla::u16string& aU16FullName);
/**
* Populate a Vector with the first UTF16 full name from each name table of
* the fonts. If the full name string is not present it will use the family
* space concatenated with the style.
* This will only read names that are already UTF16.
*
* @param aU16FullNames the Vector to be populated.
* @return true if at least one name found otherwise false.
*/
bool GetU16FullNames(Vector<mozilla::u16string>& aU16FullNames);
/**
* Returns the index for the first UTF16 name matching aU16FullName.
*
* @param aU16FullName full name to find.
* @param aIndex out param for the index if found.
* @return true if the full name is successfully read.
*/
bool GetIndexForU16Name(const mozilla::u16string& aU16FullName, uint32_t* aIndex);
private:
SFNTData() {}
bool AddFont(const uint8_t *aFontData, uint32_t aDataLength,
uint32_t aOffset);
// Internal representation of single font in font file.
class Font;
Vector<Font*> mFonts;
};
} // gfx
} // mozilla
#endif // mozilla_gfx_SFNTData_h

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

@ -1,257 +0,0 @@
/* -*- 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/. */
#include "SFNTNameTable.h"
#include "BigEndianInts.h"
#include "Logging.h"
#include "mozilla/Move.h"
namespace mozilla {
namespace gfx {
static const BigEndianUint16 FORMAT_0 = 0;
static const BigEndianUint16 NAME_ID_FAMILY = 1;
static const BigEndianUint16 NAME_ID_STYLE = 2;
static const BigEndianUint16 NAME_ID_FULL = 4;
static const BigEndianUint16 PLATFORM_ID_UNICODE = 0;
static const BigEndianUint16 PLATFORM_ID_MAC = 1;
static const BigEndianUint16 PLATFORM_ID_MICROSOFT = 3;
static const BigEndianUint16 ENCODING_ID_MICROSOFT_SYMBOL = 0;
static const BigEndianUint16 ENCODING_ID_MICROSOFT_UNICODEBMP = 1;
static const BigEndianUint16 ENCODING_ID_MICROSOFT_UNICODEFULL = 10;
static const BigEndianUint16 LANG_ID_MAC_ENGLISH = 0;
static const BigEndianUint16 LANG_ID_MICROSOFT_EN_US = 0x0409;
#pragma pack(push, 1)
// Name table has a header, followed by name records, followed by string data.
struct NameHeader
{
BigEndianUint16 format; // Format selector (=0).
BigEndianUint16 count; // Number of name records.
BigEndianUint16 stringOffset; // Offset to string storage from start of table.
};
struct NameRecord
{
BigEndianUint16 platformID;
BigEndianUint16 encodingID; // Platform-specific encoding ID
BigEndianUint16 languageID;
BigEndianUint16 nameID;
BigEndianUint16 length; // String length in bytes.
BigEndianUint16 offset; // String offset from start of storage in bytes.
};
#pragma pack(pop)
/* static */
UniquePtr<SFNTNameTable>
SFNTNameTable::Create(const uint8_t *aNameData, uint32_t aDataLength)
{
MOZ_ASSERT(aNameData);
if (aDataLength < sizeof(NameHeader)) {
gfxWarning() << "Name data too short to contain NameHeader.";
return nullptr;
}
const NameHeader *nameHeader = reinterpret_cast<const NameHeader*>(aNameData);
if (nameHeader->format != FORMAT_0) {
gfxWarning() << "Only Name Table Format 0 is supported.";
return nullptr;
}
uint16_t stringOffset = nameHeader->stringOffset;
if (stringOffset !=
sizeof(NameHeader) + (nameHeader->count * sizeof(NameRecord))) {
gfxWarning() << "Name table string offset is incorrect.";
return nullptr;
}
if (aDataLength < stringOffset) {
gfxWarning() << "Name data too short to contain name records.";
return nullptr;
}
return UniquePtr<SFNTNameTable>(
new SFNTNameTable(nameHeader, aNameData, aDataLength));
}
SFNTNameTable::SFNTNameTable(const NameHeader *aNameHeader,
const uint8_t *aNameData, uint32_t aDataLength)
: mFirstRecord(reinterpret_cast<const NameRecord*>(aNameData
+ sizeof(NameHeader)))
, mEndOfRecords(mFirstRecord + aNameHeader->count)
, mStringData(aNameData + aNameHeader->stringOffset)
, mStringDataLength(aDataLength - aNameHeader->stringOffset)
{
MOZ_ASSERT(reinterpret_cast<const uint8_t*>(aNameHeader) == aNameData);
}
#if defined(XP_MACOSX)
static const BigEndianUint16 CANONICAL_LANG_ID = LANG_ID_MAC_ENGLISH;
static const BigEndianUint16 PLATFORM_ID = PLATFORM_ID_MAC;
#else
static const BigEndianUint16 CANONICAL_LANG_ID = LANG_ID_MICROSOFT_EN_US;
static const BigEndianUint16 PLATFORM_ID = PLATFORM_ID_MICROSOFT;
#endif
static bool
IsUTF16Encoding(const NameRecord *aNameRecord)
{
if (aNameRecord->platformID == PLATFORM_ID_MICROSOFT &&
(aNameRecord->encodingID == ENCODING_ID_MICROSOFT_UNICODEBMP ||
aNameRecord->encodingID == ENCODING_ID_MICROSOFT_SYMBOL)) {
return true;
}
if (aNameRecord->platformID == PLATFORM_ID_UNICODE) {
return true;
}
return false;
}
static NameRecordMatchers*
CreateCanonicalU16Matchers(const BigEndianUint16& aNameID)
{
NameRecordMatchers *matchers = new NameRecordMatchers();
// First, look for the English name (this will normally succeed).
matchers->append(
[=](const NameRecord *aNameRecord) {
return aNameRecord->nameID == aNameID &&
aNameRecord->languageID == CANONICAL_LANG_ID &&
aNameRecord->platformID == PLATFORM_ID &&
IsUTF16Encoding(aNameRecord);
});
// Second, look for all languages.
matchers->append(
[=](const NameRecord *aNameRecord) {
return aNameRecord->nameID == aNameID &&
aNameRecord->platformID == PLATFORM_ID &&
IsUTF16Encoding(aNameRecord);
});
#if defined(XP_MACOSX)
// On Mac may be dealing with font that only has Microsoft name entries.
matchers->append(
[=](const NameRecord *aNameRecord) {
return aNameRecord->nameID == aNameID &&
aNameRecord->languageID == LANG_ID_MICROSOFT_EN_US &&
aNameRecord->platformID == PLATFORM_ID_MICROSOFT &&
IsUTF16Encoding(aNameRecord);
});
matchers->append(
[=](const NameRecord *aNameRecord) {
return aNameRecord->nameID == aNameID &&
aNameRecord->platformID == PLATFORM_ID_MICROSOFT &&
IsUTF16Encoding(aNameRecord);
});
#endif
return matchers;
}
static const NameRecordMatchers&
FullNameMatchers()
{
static const NameRecordMatchers *sFullNameMatchers =
CreateCanonicalU16Matchers(NAME_ID_FULL);
return *sFullNameMatchers;
}
static const NameRecordMatchers&
FamilyMatchers()
{
static const NameRecordMatchers *sFamilyMatchers =
CreateCanonicalU16Matchers(NAME_ID_FAMILY);
return *sFamilyMatchers;
}
static const NameRecordMatchers&
StyleMatchers()
{
static const NameRecordMatchers *sStyleMatchers =
CreateCanonicalU16Matchers(NAME_ID_STYLE);
return *sStyleMatchers;
}
bool
SFNTNameTable::GetU16FullName(mozilla::u16string& aU16FullName)
{
if (ReadU16Name(FullNameMatchers(), aU16FullName)) {
return true;
}
// If the full name record doesn't exist create the name from the family space
// concatenated with the style.
mozilla::u16string familyName;
if (!ReadU16Name(FamilyMatchers(), familyName)) {
return false;
}
mozilla::u16string styleName;
if (!ReadU16Name(StyleMatchers(), styleName)) {
return false;
}
aU16FullName.assign(Move(familyName));
aU16FullName.append(MOZ_UTF16(" "));
aU16FullName.append(styleName);
return true;
}
bool
SFNTNameTable::ReadU16Name(const NameRecordMatchers& aMatchers,
mozilla::u16string& aU16Name)
{
MOZ_ASSERT(!aMatchers.empty());
for (size_t i = 0; i < aMatchers.length(); ++i) {
const NameRecord* record = mFirstRecord;
while (record != mEndOfRecords) {
if (aMatchers[i](record)) {
return ReadU16NameFromRecord(record, aU16Name);
}
++record;
}
}
return false;
}
bool
SFNTNameTable::ReadU16NameFromRecord(const NameRecord *aNameRecord,
mozilla::u16string& aU16Name)
{
uint32_t offset = aNameRecord->offset;
uint32_t length = aNameRecord->length;
if (mStringDataLength < offset + length) {
gfxWarning() << "Name data too short to contain name string.";
return false;
}
const uint8_t *startOfName = mStringData + offset;
size_t actualLength = length / sizeof(char16_t);
UniquePtr<char16_t[]> nameData(new char16_t[actualLength]);
NativeEndian::copyAndSwapFromBigEndian(nameData.get(), startOfName,
actualLength);
aU16Name.assign(nameData.get(), actualLength);
return true;
}
} // gfx
} // mozilla

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

@ -1,67 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_gfx_SFNTNameTable_h
#define mozilla_gfx_SFNTNameTable_h
#include "mozilla/Function.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Vector.h"
#include "u16string.h"
namespace mozilla {
namespace gfx {
struct NameHeader;
struct NameRecord;
typedef Vector<Function<bool(const NameRecord*)>> NameRecordMatchers;
class SFNTNameTable final
{
public:
/**
* Creates a SFNTNameTable if the header data is valid. Note that the data is
* NOT copied, so must exist for the lifetime of the table.
*
* @param aNameData the Name Table data.
* @param aDataLength length
* @return UniquePtr to a SFNTNameTable or nullptr if the header is invalid.
*/
static UniquePtr<SFNTNameTable> Create(const uint8_t *aNameData,
uint32_t aDataLength);
/**
* Gets the full name from the name table. If the full name string is not
* present it will use the family space concatenated with the style.
* This will only read names that are already UTF16.
*
* @param aU16FullName string to be populated with the full name.
* @return true if the full name is successfully read.
*/
bool GetU16FullName(mozilla::u16string& aU16FullName);
private:
SFNTNameTable(const NameHeader *aNameHeader, const uint8_t *aNameData,
uint32_t aDataLength);
bool ReadU16Name(const NameRecordMatchers& aMatchers, mozilla::u16string& aU16Name);
bool ReadU16NameFromRecord(const NameRecord *aNameRecord,
mozilla::u16string& aU16Name);
const NameRecord *mFirstRecord;
const NameRecord *mEndOfRecords;
const uint8_t *mStringData;
const uint32_t mStringDataLength;
};
} // gfx
} // mozilla
#endif // mozilla_gfx_SFNTNameTable_h

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

@ -45,33 +45,6 @@ ScaledFontBase::ScaledFontBase(Float aSize)
#endif
}
#ifdef USE_CAIRO_SCALED_FONT
bool
ScaledFontBase::PopulateCairoScaledFont()
{
cairo_font_face_t* cairoFontFace = GetCairoFontFace();
if (!cairoFontFace) {
return false;
}
cairo_matrix_t sizeMatrix;
cairo_matrix_t identityMatrix;
cairo_matrix_init_scale(&sizeMatrix, mSize, mSize);
cairo_matrix_init_identity(&identityMatrix);
cairo_font_options_t *fontOptions = cairo_font_options_create();
mScaledFont = cairo_scaled_font_create(cairoFontFace, &sizeMatrix,
&identityMatrix, fontOptions);
cairo_font_options_destroy(fontOptions);
cairo_font_face_destroy(cairoFontFace);
return (cairo_scaled_font_status(mScaledFont) == CAIRO_STATUS_SUCCESS);
}
#endif
#ifdef USE_SKIA
SkPath
ScaledFontBase::GetSkiaPathForGlyphs(const GlyphBuffer &aBuffer)

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

@ -45,7 +45,6 @@ public:
virtual FontType GetType() const { return FontType::SKIA; }
#ifdef USE_CAIRO_SCALED_FONT
bool PopulateCairoScaledFont();
cairo_scaled_font_t* GetCairoScaledFont() { return mScaledFont; }
void SetCairoScaledFont(cairo_scaled_font_t* font);
#endif
@ -57,8 +56,6 @@ protected:
SkPath GetSkiaPathForGlyphs(const GlyphBuffer &aBuffer);
#endif
#ifdef USE_CAIRO_SCALED_FONT
// Overridders should ensure the cairo_font_face_t has been addrefed.
virtual cairo_font_face_t* GetCairoFontFace() { return nullptr; }
cairo_scaled_font_t* mScaledFont;
#endif
Float mSize;

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

@ -5,16 +5,141 @@
#include "ScaledFontDWrite.h"
#include "PathD2D.h"
#include "DrawTargetD2D.h"
#include "Logging.h"
#include <vector>
#ifdef USE_CAIRO_SCALED_FONT
#include "cairo-win32.h"
#endif
namespace mozilla {
namespace gfx {
struct ffReferenceKey
{
uint8_t *mData;
uint32_t mSize;
};
class DWriteFontFileLoader : public IDWriteFontFileLoader
{
public:
DWriteFontFileLoader()
{
}
// IUnknown interface
IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
{
if (iid == __uuidof(IDWriteFontFileLoader)) {
*ppObject = static_cast<IDWriteFontFileLoader*>(this);
return S_OK;
} else if (iid == __uuidof(IUnknown)) {
*ppObject = static_cast<IUnknown*>(this);
return S_OK;
} else {
return E_NOINTERFACE;
}
}
IFACEMETHOD_(ULONG, AddRef)()
{
return 1;
}
IFACEMETHOD_(ULONG, Release)()
{
return 1;
}
// IDWriteFontFileLoader methods
/**
* Important! Note the key here -has- to be a pointer to an
* ffReferenceKey object.
*/
virtual HRESULT STDMETHODCALLTYPE
CreateStreamFromKey(void const* fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
OUT IDWriteFontFileStream** fontFileStream);
/**
* Gets the singleton loader instance. Note that when using this font
* loader, the key must be a pointer to an FallibleTArray<uint8_t>. This
* array will be empty when the function returns.
*/
static IDWriteFontFileLoader* Instance()
{
if (!mInstance) {
mInstance = new DWriteFontFileLoader();
DrawTargetD2D::GetDWriteFactory()->
RegisterFontFileLoader(mInstance);
}
return mInstance;
}
private:
static IDWriteFontFileLoader* mInstance;
};
class DWriteFontFileStream : public IDWriteFontFileStream
{
public:
/**
* Used by the FontFileLoader to create a new font stream,
* this font stream is created from data in memory. The memory
* passed may be released after object creation, it will be
* copied internally.
*
* @param aData Font data
*/
DWriteFontFileStream(uint8_t *aData, uint32_t aSize);
~DWriteFontFileStream();
// IUnknown interface
IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
{
if (iid == __uuidof(IDWriteFontFileStream)) {
*ppObject = static_cast<IDWriteFontFileStream*>(this);
return S_OK;
} else if (iid == __uuidof(IUnknown)) {
*ppObject = static_cast<IUnknown*>(this);
return S_OK;
} else {
return E_NOINTERFACE;
}
}
IFACEMETHOD_(ULONG, AddRef)()
{
++mRefCnt;
return mRefCnt;
}
IFACEMETHOD_(ULONG, Release)()
{
--mRefCnt;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// IDWriteFontFileStream methods
virtual HRESULT STDMETHODCALLTYPE ReadFileFragment(void const** fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
OUT void** fragmentContext);
virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext);
virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize);
virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime);
private:
std::vector<uint8_t> mData;
uint32_t mRefCnt;
};
static BYTE
GetSystemTextQuality()
{
@ -88,6 +213,99 @@ DoGrayscale(IDWriteFontFace *aDWFace, Float ppem)
return true;
}
IDWriteFontFileLoader* DWriteFontFileLoader::mInstance = nullptr;
HRESULT STDMETHODCALLTYPE
DWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
IDWriteFontFileStream **fontFileStream)
{
if (!fontFileReferenceKey || !fontFileStream) {
return E_POINTER;
}
const ffReferenceKey *key = static_cast<const ffReferenceKey*>(fontFileReferenceKey);
*fontFileStream =
new DWriteFontFileStream(key->mData, key->mSize);
if (!*fontFileStream) {
return E_OUTOFMEMORY;
}
(*fontFileStream)->AddRef();
return S_OK;
}
DWriteFontFileStream::DWriteFontFileStream(uint8_t *aData, uint32_t aSize)
: mRefCnt(0)
{
mData.resize(aSize);
memcpy(&mData.front(), aData, aSize);
}
DWriteFontFileStream::~DWriteFontFileStream()
{
}
HRESULT STDMETHODCALLTYPE
DWriteFontFileStream::GetFileSize(UINT64 *fileSize)
{
*fileSize = mData.size();
return S_OK;
}
HRESULT STDMETHODCALLTYPE
DWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE
DWriteFontFileStream::ReadFileFragment(const void **fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
void **fragmentContext)
{
// We are required to do bounds checking.
if (fileOffset + fragmentSize > mData.size()) {
return E_FAIL;
}
// truncate the 64 bit fileOffset to size_t sized index into mData
size_t index = static_cast<size_t>(fileOffset);
// We should be alive for the duration of this.
*fragmentStart = &mData[index];
*fragmentContext = nullptr;
return S_OK;
}
void STDMETHODCALLTYPE
DWriteFontFileStream::ReleaseFileFragment(void *fragmentContext)
{
}
ScaledFontDWrite::ScaledFontDWrite(uint8_t *aData, uint32_t aSize,
uint32_t aIndex, Float aGlyphSize)
: ScaledFontBase(aGlyphSize)
{
IDWriteFactory *factory = DrawTargetD2D::GetDWriteFactory();
ffReferenceKey key;
key.mData = aData;
key.mSize = aSize;
RefPtr<IDWriteFontFile> fontFile;
if (FAILED(factory->CreateCustomFontFileReference(&key, sizeof(ffReferenceKey), DWriteFontFileLoader::Instance(), getter_AddRefs(fontFile)))) {
gfxWarning() << "Failed to load font file from data!";
return;
}
IDWriteFontFile *ff = fontFile;
if (FAILED(factory->CreateFontFace(DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, &ff, aIndex, DWRITE_FONT_SIMULATIONS_NONE, getter_AddRefs(mFontFace)))) {
gfxWarning() << "Failed to create font face from font file data!";
}
}
already_AddRefed<Path>
ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
{
@ -213,17 +431,5 @@ ScaledFontDWrite::GetDefaultAAMode()
return defaultMode;
}
#ifdef USE_CAIRO_SCALED_FONT
cairo_font_face_t*
ScaledFontDWrite::GetCairoFontFace()
{
if (!mFontFace) {
return nullptr;
}
return cairo_dwrite_font_face_create_for_dwrite_fontface(nullptr, mFontFace);
}
#endif
}
}

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

@ -22,6 +22,7 @@ public:
: ScaledFontBase(aSize)
, mFontFace(aFont)
{}
ScaledFontDWrite(uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize);
virtual FontType GetType() const { return FontType::DWRITE; }
@ -43,11 +44,6 @@ public:
#endif
RefPtr<IDWriteFontFace> mFontFace;
protected:
#ifdef USE_CAIRO_SCALED_FONT
cairo_font_face_t* GetCairoFontFace() override;
#endif
};
class GlyphRenderingOptionsDWrite : public GlyphRenderingOptions

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

@ -4,19 +4,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ScaledFontWin.h"
#include "AutoHelpersWin.h"
#include "Logging.h"
#include "SFNTData.h"
#include "ScaledFontBase.h"
#ifdef USE_SKIA
#include "skia/include/ports/SkTypeface_win.h"
#endif
#ifdef USE_CAIRO_SCALED_FONT
#include "cairo-win32.h"
#endif
namespace mozilla {
namespace gfx {
@ -26,55 +19,6 @@ ScaledFontWin::ScaledFontWin(LOGFONT* aFont, Float aSize)
{
}
bool
ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
{
AutoDC dc;
AutoSelectFont font(dc.GetDC(), &mLogFont);
// Check for a font collection first.
uint32_t table = 0x66637474; // 'ttcf'
uint32_t tableSize = ::GetFontData(dc.GetDC(), table, 0, nullptr, 0);
if (tableSize == GDI_ERROR) {
// Try as if just a single font.
table = 0;
tableSize = ::GetFontData(dc.GetDC(), table, 0, nullptr, 0);
if (tableSize == GDI_ERROR) {
return false;
}
}
UniquePtr<uint8_t[]> fontData(new uint8_t[tableSize]);
uint32_t sizeGot =
::GetFontData(dc.GetDC(), table, 0, fontData.get(), tableSize);
if (sizeGot != tableSize) {
return false;
}
// If it's a font collection then attempt to get the index.
uint32_t index = 0;
if (table != 0) {
UniquePtr<SFNTData> sfntData = SFNTData::Create(fontData.get(),
tableSize);
if (!sfntData) {
gfxWarning() << "Failed to create SFNTData for GetFontFileData.";
return false;
}
// We cast here because for VS2015 char16_t != wchar_t, even though they are
// both 16 bit.
if (!sfntData->GetIndexForU16Name(
reinterpret_cast<char16_t*>(mLogFont.lfFaceName), &index)) {
gfxWarning() << "Failed to get index for face name.";
return false;
}
}
aDataCallback(fontData.get(), tableSize, index, mSize, aBaton);
return true;
}
#ifdef USE_SKIA
SkTypeface* ScaledFontWin::GetSkTypeface()
{
@ -85,16 +29,6 @@ SkTypeface* ScaledFontWin::GetSkTypeface()
}
#endif
#ifdef USE_CAIRO_SCALED_FONT
cairo_font_face_t*
ScaledFontWin::GetCairoFontFace()
{
if (mLogFont.lfFaceName[0] == 0) {
return nullptr;
}
return cairo_win32_font_face_create_for_logfontw(&mLogFont);
}
#endif
}
}

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

@ -7,6 +7,7 @@
#define MOZILLA_GFX_SCALEDFONTWIN_H_
#include "ScaledFontBase.h"
#include <windows.h>
namespace mozilla {
namespace gfx {
@ -18,18 +19,9 @@ public:
ScaledFontWin(LOGFONT* aFont, Float aSize);
virtual FontType GetType() const { return FontType::GDI; }
bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) override;
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface();
#endif
protected:
#ifdef USE_CAIRO_SCALED_FONT
cairo_font_face_t* GetCairoFontFace() override;
#endif
private:
#ifdef USE_SKIA
friend class DrawTargetSkia;

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

@ -22,7 +22,6 @@ EXPORTS.mozilla.gfx += [
'Coord.h',
'CriticalSection.h',
'DataSurfaceHelpers.h',
'DrawEventRecorder.h',
'DrawTargetTiled.h',
'Filters.h',
'Helpers.h',
@ -38,10 +37,7 @@ EXPORTS.mozilla.gfx += [
'PathHelpers.h',
'PatternHelpers.h',
'Point.h',
'Preferences.h',
'Quaternion.h',
'RecordedEvent.h',
'RecordingTypes.h',
'Rect.h',
'Scale.h',
'ScaleFactor.h',
@ -71,8 +67,6 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
'ExtendInputEffectD2D1.cpp',
'FilterNodeD2D1.cpp',
'JobScheduler_win32.cpp',
'NativeFontResourceDWrite.cpp',
'NativeFontResourceGDI.cpp',
'PathD2D.cpp',
'RadialGradientEffectD2D1.cpp',
'ScaledFontDWrite.cpp',
@ -154,14 +148,11 @@ UNIFIED_SOURCES += [
'PathCairo.cpp',
'PathHelpers.cpp',
'PathRecording.cpp',
'Preferences.cpp',
'Quaternion.cpp',
'RecordedEvent.cpp',
'Scale.cpp',
'ScaledFontBase.cpp',
'ScaledFontCairo.cpp',
'SFNTData.cpp',
'SFNTNameTable.cpp',
'SourceSurfaceCairo.cpp',
'SourceSurfaceRawData.cpp',
]
@ -195,3 +186,10 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk', 'qt'):
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
if CONFIG['OS_ARCH'] == 'WINNT':
# Due to bug 796023, we can't have -DUNICODE and -D_UNICODE; defining those
# macros changes the type of LOGFONT to LOGFONTW instead of LOGFONTA. This
# changes the symbol names of exported C++ functions that use LOGFONT.
del DEFINES['UNICODE']
del DEFINES['_UNICODE']

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

@ -1,24 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_gfx_u16string_h
#define mozilla_gfx_u16string_h
#include <string>
#include "mozilla/Char16.h"
namespace mozilla {
#if defined(_MSC_VER)
typedef std::u16string u16string;
#else
typedef std::basic_string<char16_t> u16string;
#endif
} // mozilla
#endif // mozilla_gfx_u16string_h

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

@ -170,5 +170,8 @@ CFLAGS += CONFIG['TK_CFLAGS']
LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
if CONFIG['OS_ARCH'] == 'WINNT':
del DEFINES['UNICODE']
if CONFIG['CLANG_CXX']:
CXXFLAGS += ['-Wshadow']

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

@ -69,10 +69,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in {
} or CONFIG['MOZ_WIDGET_GTK']:
DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
DEFINES['UNICODE'] = True
DEFINES['_UNICODE'] = True
# We should autogenerate these SSE related flags.
if CONFIG['_MSC_VER']:

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

@ -680,10 +680,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in {
} or CONFIG['MOZ_WIDGET_GTK']:
DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
DEFINES['UNICODE'] = True
DEFINES['_UNICODE'] = True
# We should autogenerate these SSE related flags.
if CONFIG['_MSC_VER']:

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

@ -314,10 +314,30 @@ nsDeviceContext::SetDPI()
{
float dpi = -1.0f;
// Use the printing DC to determine DPI values, if we have one.
if (mDeviceContextSpec) {
dpi = mDeviceContextSpec->GetDPI();
mPrintingScale = mDeviceContextSpec->GetPrintingScale();
// PostScript, PDF and Mac (when printing) all use 72 dpi
// Use a printing DC to determine the other dpi values
if (mPrintingSurface) {
switch (mPrintingSurface->GetType()) {
case gfxSurfaceType::PDF:
case gfxSurfaceType::PS:
case gfxSurfaceType::Quartz:
dpi = 72.0f;
break;
#ifdef XP_WIN
case gfxSurfaceType::Win32:
case gfxSurfaceType::Win32Printing: {
HDC dc = reinterpret_cast<gfxWindowsSurface*>(mPrintingSurface.get())->GetDC();
int32_t OSVal = GetDeviceCaps(dc, LOGPIXELSY);
dpi = 144.0f;
mPrintingScale = float(OSVal) / dpi;
break;
}
#endif
default:
NS_NOTREACHED("Unexpected printing surface type");
break;
}
mAppUnitsPerDevPixelAtUnitFullZoom =
NS_lround((AppUnitsPerCSSPixel() * 96) / dpi);
} else {
@ -400,12 +420,6 @@ nsDeviceContext::CreateRenderingContext()
return nullptr;
}
RefPtr<DrawEventRecorder> recorder;
nsresult rv = mDeviceContextSpec->GetDrawEventRecorder(getter_AddRefs(recorder));
if (NS_SUCCEEDED(rv) && recorder) {
dt = gfx::Factory::CreateRecordingDrawTarget(recorder, dt);
}
#ifdef XP_MACOSX
dt->AddUserData(&gfxContext::sDontUseAsSourceKey, dt, nullptr);
#endif
@ -512,16 +526,18 @@ nsDeviceContext::InitForPrinting(nsIDeviceContextSpec *aDevice)
nsresult
nsDeviceContext::BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage)
{
nsresult rv = mPrintingSurface->BeginPrinting(aTitle, aPrintToFileName);
static const char16_t kEmpty[] = { '\0' };
nsresult rv;
if (NS_SUCCEEDED(rv) && mDeviceContextSpec) {
rv = mDeviceContextSpec->BeginDocument(aTitle, aPrintToFileName,
aStartPage, aEndPage);
}
rv = mPrintingSurface->BeginPrinting(aTitle,
nsDependentString(aPrintToFileName ? aPrintToFileName : kEmpty));
if (NS_SUCCEEDED(rv) && mDeviceContextSpec)
rv = mDeviceContextSpec->BeginDocument(aTitle, aPrintToFileName, aStartPage, aEndPage);
return rv;
}
@ -682,7 +698,34 @@ nsDeviceContext::CalcPrintingSize()
gfxSize size(0, 0);
switch (mPrintingSurface->GetType()) {
case gfxSurfaceType::Image:
inPoints = false;
size = reinterpret_cast<gfxImageSurface*>(mPrintingSurface.get())->GetSize();
break;
#if defined(MOZ_PDF_PRINTING)
case gfxSurfaceType::PDF:
inPoints = true;
size = reinterpret_cast<gfxPDFSurface*>(mPrintingSurface.get())->GetSize();
break;
#endif
#ifdef MOZ_WIDGET_GTK
case gfxSurfaceType::PS:
inPoints = true;
size = reinterpret_cast<gfxPSSurface*>(mPrintingSurface.get())->GetSize();
break;
#endif
#ifdef XP_MACOSX
case gfxSurfaceType::Quartz:
inPoints = true; // this is really only true when we're printing
size = reinterpret_cast<gfxQuartzSurface*>(mPrintingSurface.get())->GetSize();
break;
#endif
#ifdef XP_WIN
case gfxSurfaceType::Win32:
case gfxSurfaceType::Win32Printing:
{
inPoints = false;
@ -697,8 +740,10 @@ nsDeviceContext::CalcPrintingSize()
break;
}
#endif
default:
size = mPrintingSurface->GetSize();
gfxCriticalError() << "Printing to unknown surface type " << (int)mPrintingSurface->GetType();
NS_ERROR("trying to print to unknown surface type");
}
if (inPoints) {

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

@ -182,8 +182,8 @@ public:
* EndDocument() or AbortDocument().
*
* @param aTitle - title of Document
* @param aPrintToFileName - name of file to print to, if empty then don't
* print to file
* @param aPrintToFileName - name of file to print to, if nullptr
* then don't print to file
* @param aStartPage - starting page number (must be greater than zero)
* @param aEndPage - ending page number (must be less than or
* equal to number of pages)
@ -191,7 +191,7 @@ public:
* @return error status
*/
nsresult BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage);

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

@ -212,7 +212,6 @@ already_AddRefed<Path> gfxContext::GetPath()
void gfxContext::SetPath(Path* path)
{
MOZ_ASSERT(path->GetBackendType() == mDT->GetBackendType() ||
path->GetBackendType() == BackendType::RECORDING ||
(mDT->GetBackendType() == BackendType::DIRECT2D1_1 && path->GetBackendType() == BackendType::DIRECT2D));
mPath = path;
mPathBuilder = nullptr;

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

@ -5,128 +5,8 @@
#include "gfxDWriteCommon.h"
#include <unordered_map>
#include "mozilla/Atomics.h"
static mozilla::Atomic<uint64_t> sNextFontFileKey;
static std::unordered_map<uint64_t, IDWriteFontFileStream*> sFontFileStreams;
IDWriteFontFileLoader* gfxDWriteFontFileLoader::mInstance = nullptr;
class gfxDWriteFontFileStream final : public IDWriteFontFileStream
{
public:
/**
* Used by the FontFileLoader to create a new font stream,
* this font stream is created from data in memory. The memory
* passed may be released after object creation, it will be
* copied internally.
*
* @param aData Font data
*/
gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData,
uint64_t aFontFileKey);
~gfxDWriteFontFileStream();
// IUnknown interface
IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
{
if (iid == __uuidof(IDWriteFontFileStream)) {
*ppObject = static_cast<IDWriteFontFileStream*>(this);
return S_OK;
}
else if (iid == __uuidof(IUnknown)) {
*ppObject = static_cast<IUnknown*>(this);
return S_OK;
}
else {
return E_NOINTERFACE;
}
}
IFACEMETHOD_(ULONG, AddRef)()
{
NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
++mRefCnt;
return mRefCnt;
}
IFACEMETHOD_(ULONG, Release)()
{
NS_PRECONDITION(0 != mRefCnt, "dup release");
--mRefCnt;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// IDWriteFontFileStream methods
virtual HRESULT STDMETHODCALLTYPE ReadFileFragment(void const** fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
OUT void** fragmentContext);
virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext);
virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize);
virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime);
private:
FallibleTArray<uint8_t> mData;
nsAutoRefCnt mRefCnt;
uint64_t mFontFileKey;
};
gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData,
uint64_t aFontFileKey)
: mFontFileKey(aFontFileKey)
{
mData.SwapElements(*aData);
}
gfxDWriteFontFileStream::~gfxDWriteFontFileStream()
{
sFontFileStreams.erase(mFontFileKey);
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileStream::GetFileSize(UINT64 *fileSize)
{
*fileSize = mData.Length();
return S_OK;
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileStream::ReadFileFragment(const void **fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
void **fragmentContext)
{
// We are required to do bounds checking.
if (fileOffset + fragmentSize > (UINT64)mData.Length()) {
return E_FAIL;
}
// We should be alive for the duration of this.
*fragmentStart = &mData[fileOffset];
*fragmentContext = nullptr;
return S_OK;
}
void STDMETHODCALLTYPE
gfxDWriteFontFileStream::ReleaseFileFragment(void *fragmentContext)
{
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
@ -136,42 +16,56 @@ gfxDWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey,
return E_POINTER;
}
uint64_t fontFileKey = *static_cast<const uint64_t*>(fontFileReferenceKey);
auto found = sFontFileStreams.find(fontFileKey);
if (found == sFontFileStreams.end()) {
*fontFileStream = nullptr;
return E_FAIL;
}
*fontFileStream =
new gfxDWriteFontFileStream(
static_cast<const ffReferenceKey*>(fontFileReferenceKey)->mArray);
found->second->AddRef();
*fontFileStream = found->second;
if (!*fontFileStream) {
return E_OUTOFMEMORY;
}
(*fontFileStream)->AddRef();
return S_OK;
}
/* static */
HRESULT
gfxDWriteFontFileLoader::CreateCustomFontFile(FallibleTArray<uint8_t>& aFontData,
IDWriteFontFile** aFontFile,
IDWriteFontFileStream** aFontFileStream)
gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData)
{
mData.SwapElements(*aData);
}
gfxDWriteFontFileStream::~gfxDWriteFontFileStream()
{
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileStream::GetFileSize(UINT64 *fileSize)
{
*fileSize = mData.Length();
return S_OK;
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE
gfxDWriteFontFileStream::ReadFileFragment(const void **fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
void **fragmentContext)
{
// We are required to do bounds checking.
if (fileOffset + fragmentSize > (UINT64)mData.Length()) {
return E_FAIL;
}
// We should be alive for the duration of this.
*fragmentStart = &mData[fileOffset];
*fragmentContext = nullptr;
return S_OK;
}
void STDMETHODCALLTYPE
gfxDWriteFontFileStream::ReleaseFileFragment(void *fragmentContext)
{
MOZ_ASSERT(aFontFile);
MOZ_ASSERT(aFontFileStream);
IDWriteFactory *factory = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory();
uint64_t fontFileKey = sNextFontFileKey++;
RefPtr<IDWriteFontFileStream> ffsRef = new gfxDWriteFontFileStream(&aFontData, fontFileKey);
sFontFileStreams[fontFileKey] = ffsRef;
RefPtr<IDWriteFontFile> fontFile;
HRESULT hr = factory->CreateCustomFontFileReference(&fontFileKey, sizeof(fontFileKey), Instance(), getter_AddRefs(fontFile));
if (FAILED(hr)) {
NS_WARNING("Failed to load font file from data!");
return hr;
}
fontFile.forget(aFontFile);
ffsRef.forget(aFontFileStream);
return S_OK;
}

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

@ -113,7 +113,8 @@ public:
// IDWriteFontFileLoader methods
/**
* Important! Note the key here -has- to be a pointer to a uint64_t.
* Important! Note the key here -has- to be a pointer to an
* FallibleTArray<uint8_t>.
*/
virtual HRESULT STDMETHODCALLTYPE
CreateStreamFromKey(void const* fontFileReferenceKey,
@ -122,7 +123,8 @@ public:
/**
* Gets the singleton loader instance. Note that when using this font
* loader, the key must be a pointer to a unint64_t.
* loader, the key must be a pointer to an FallibleTArray<uint8_t>. This
* array will be empty when the function returns.
*/
static IDWriteFontFileLoader* Instance()
{
@ -134,21 +136,71 @@ public:
return mInstance;
}
/**
* Creates a IDWriteFontFile and IDWriteFontFileStream from aFontData.
* aFontData will be empty on return as it swaps out the data.
*
* @param aFontData the font data for the custom font file
* @param aFontFile out param for the created font file
* @param aFontFileStream out param for the corresponding stream
* @return HRESULT of internal calls
*/
static HRESULT CreateCustomFontFile(FallibleTArray<uint8_t>& aFontData,
IDWriteFontFile** aFontFile,
IDWriteFontFileStream** aFontFileStream);
private:
static IDWriteFontFileLoader* mInstance;
};
class gfxDWriteFontFileStream final : public IDWriteFontFileStream
{
public:
/**
* Used by the FontFileLoader to create a new font stream,
* this font stream is created from data in memory. The memory
* passed may be released after object creation, it will be
* copied internally.
*
* @param aData Font data
*/
gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData);
~gfxDWriteFontFileStream();
// IUnknown interface
IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
{
if (iid == __uuidof(IDWriteFontFileStream)) {
*ppObject = static_cast<IDWriteFontFileStream*>(this);
return S_OK;
} else if (iid == __uuidof(IUnknown)) {
*ppObject = static_cast<IUnknown*>(this);
return S_OK;
} else {
return E_NOINTERFACE;
}
}
IFACEMETHOD_(ULONG, AddRef)()
{
NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
++mRefCnt;
return mRefCnt;
}
IFACEMETHOD_(ULONG, Release)()
{
NS_PRECONDITION(0 != mRefCnt, "dup release");
--mRefCnt;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// IDWriteFontFileStream methods
virtual HRESULT STDMETHODCALLTYPE ReadFileFragment(void const** fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
OUT void** fragmentContext);
virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext);
virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize);
virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime);
private:
FallibleTArray<uint8_t> mData;
nsAutoRefCnt mRefCnt;
};
#endif /* GFX_DWRITECOMMON_H */

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

@ -789,12 +789,35 @@ gfxDWriteFontList::MakePlatformFont(const nsAString& aFontName,
return nullptr;
}
RefPtr<IDWriteFontFileStream> fontFileStream;
RefPtr<IDWriteFontFile> fontFile;
HRESULT hr =
gfxDWriteFontFileLoader::CreateCustomFontFile(newFontData,
getter_AddRefs(fontFile),
getter_AddRefs(fontFileStream));
HRESULT hr;
/**
* We pass in a pointer to a structure containing a pointer to the array
* containing the font data and a unique identifier. DWrite will
* internally copy what is at that pointer, and pass that to
* CreateStreamFromKey. The array will be empty when the function
* succesfully returns since it swaps out the data.
*/
ffReferenceKey key;
key.mArray = &newFontData;
nsCOMPtr<nsIUUIDGenerator> uuidgen =
do_GetService("@mozilla.org/uuid-generator;1");
if (!uuidgen) {
return nullptr;
}
rv = uuidgen->GenerateUUIDInPlace(&key.mGUID);
if (NS_FAILED(rv)) {
return nullptr;
}
hr = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()->
CreateCustomFontFileReference(&key,
sizeof(key),
gfxDWriteFontFileLoader::Instance(),
getter_AddRefs(fontFile));
if (FAILED(hr)) {
NS_WARNING("Failed to create custom font file reference.");
@ -808,7 +831,6 @@ gfxDWriteFontList::MakePlatformFont(const nsAString& aFontName,
gfxDWriteFontEntry *entry =
new gfxDWriteFontEntry(uniqueName,
fontFile,
fontFileStream,
aWeight,
aStretch,
aStyle);
@ -838,9 +860,9 @@ gfxDWriteFontList::InitFontList()
char nowTime[256], nowDate[256];
if (LOG_FONTINIT_ENABLED()) {
GetTimeFormatA(LOCALE_INVARIANT, TIME_FORCE24HOURFORMAT,
GetTimeFormat(LOCALE_INVARIANT, TIME_FORCE24HOURFORMAT,
nullptr, nullptr, nowTime, 256);
GetDateFormatA(LOCALE_INVARIANT, 0, nullptr, nullptr, nowDate, 256);
GetDateFormat(LOCALE_INVARIANT, 0, nullptr, nullptr, nowDate, 256);
upTime = (double) GetTickCount();
}
QueryPerformanceFrequency(&frequency);

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

@ -126,19 +126,17 @@ public:
*
* \param aFaceName The name of the corresponding font face.
* \param aFontFile DirectWrite fontfile object
* \param aFontFileStream DirectWrite fontfile stream object
* \param aWeight Weight of the font
* \param aStretch Stretch of the font
* \param aStyle italic or oblique of font
*/
gfxDWriteFontEntry(const nsAString& aFaceName,
IDWriteFontFile *aFontFile,
IDWriteFontFileStream *aFontFileStream,
uint16_t aWeight,
int16_t aStretch,
uint8_t aStyle)
: gfxFontEntry(aFaceName), mFont(nullptr), mFontFile(aFontFile),
mFontFileStream(aFontFileStream), mForceGDIClassic(false)
mForceGDIClassic(false)
{
mWeight = aWeight;
mStretch = aStretch;
@ -188,10 +186,6 @@ protected:
RefPtr<IDWriteFont> mFont;
RefPtr<IDWriteFontFile> mFontFile;
// For custom fonts, we hold a reference to the IDWriteFontFileStream for
// for the IDWriteFontFile, so that the data is available.
RefPtr<IDWriteFontFileStream> mFontFileStream;
// font face corresponding to the mFont/mFontFile *without* any DWrite
// style simulations applied
RefPtr<IDWriteFontFace> mFontFace;

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

@ -232,7 +232,7 @@ gfxDWriteFont::ComputeMetrics(AntialiasOption anAAOption)
UINT32 ucs = L' ';
UINT16 glyph;
HRESULT hr = mFontFace->GetGlyphIndicesW(&ucs, 1, &glyph);
HRESULT hr = mFontFace->GetGlyphIndicesA(&ucs, 1, &glyph);
if (FAILED(hr)) {
mMetrics->spaceWidth = 0;
} else {
@ -262,7 +262,7 @@ gfxDWriteFont::ComputeMetrics(AntialiasOption anAAOption)
if (mMetrics->aveCharWidth < 1) {
ucs = L'x';
if (SUCCEEDED(mFontFace->GetGlyphIndicesW(&ucs, 1, &glyph))) {
if (SUCCEEDED(mFontFace->GetGlyphIndicesA(&ucs, 1, &glyph))) {
mMetrics->aveCharWidth = MeasureGlyphWidth(glyph);
}
if (mMetrics->aveCharWidth < 1) {
@ -272,7 +272,7 @@ gfxDWriteFont::ComputeMetrics(AntialiasOption anAAOption)
}
ucs = L'0';
if (SUCCEEDED(mFontFace->GetGlyphIndicesW(&ucs, 1, &glyph))) {
if (SUCCEEDED(mFontFace->GetGlyphIndicesA(&ucs, 1, &glyph))) {
mMetrics->zeroOrAveCharWidth = MeasureGlyphWidth(glyph);
}
if (mMetrics->zeroOrAveCharWidth < 1) {

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

@ -1117,11 +1117,11 @@ gfxGDIFontList::ActivateBundledFonts()
if (!file) {
continue;
}
nsAutoString path;
if (NS_FAILED(file->GetPath(path))) {
nsCString path;
if (NS_FAILED(file->GetNativePath(path))) {
continue;
}
AddFontResourceExW(path.get(), FR_PRIVATE, nullptr);
AddFontResourceEx(path.get(), FR_PRIVATE, nullptr);
}
}

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

@ -197,13 +197,9 @@ gfxGradientCache::GetGradientStops(const DrawTarget *aDT, nsTArray<GradientStop>
return nullptr;
}
already_AddRefed<GradientStops>
GradientStops *
gfxGradientCache::GetOrCreateGradientStops(const DrawTarget *aDT, nsTArray<GradientStop>& aStops, ExtendMode aExtend)
{
if (aDT->IsRecording()) {
return aDT->CreateGradientStops(aStops.Elements(), aStops.Length(), aExtend);
}
RefPtr<GradientStops> gs = GetGradientStops(aDT, aStops, aExtend);
if (!gs) {
gs = aDT->CreateGradientStops(aStops.Elements(), aStops.Length(), aExtend);
@ -217,7 +213,7 @@ gfxGradientCache::GetOrCreateGradientStops(const DrawTarget *aDT, nsTArray<Gradi
delete cached;
}
}
return gs.forget();
return gs;
}
void

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

@ -21,7 +21,7 @@ public:
nsTArray<gfx::GradientStop>& aStops,
gfx::ExtendMode aExtend);
static already_AddRefed<gfx::GradientStops>
static gfx::GradientStops*
GetOrCreateGradientStops(const gfx::DrawTarget *aDT,
nsTArray<gfx::GradientStop>& aStops,
gfx::ExtendMode aExtend);

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

@ -7,7 +7,7 @@
#include "mozilla/Preferences.h"
#include "MainThreadUtils.h"
#include "mozilla/gfx/Preferences.h"
#include "mozilla/gfx/Logging.h"
using namespace mozilla;

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

@ -208,10 +208,6 @@ gfxWindowsSurface::BeginPrinting(const nsAString& aTitle,
{
#ifdef NS_PRINTING
#define DOC_TITLE_LENGTH (MAX_PATH-1)
if (!mForPrinting) {
return NS_OK;
}
DOCINFOW docinfo;
nsString titleStr(aTitle);
@ -239,10 +235,6 @@ nsresult
gfxWindowsSurface::EndPrinting()
{
#ifdef NS_PRINTING
if (!mForPrinting) {
return NS_OK;
}
int result = ::EndDoc(mDC);
if (result <= 0)
return NS_ERROR_FAILURE;
@ -257,10 +249,6 @@ nsresult
gfxWindowsSurface::AbortPrinting()
{
#ifdef NS_PRINTING
if (!mForPrinting) {
return NS_OK;
}
int result = ::AbortDoc(mDC);
if (result <= 0)
return NS_ERROR_FAILURE;
@ -274,10 +262,6 @@ nsresult
gfxWindowsSurface::BeginPage()
{
#ifdef NS_PRINTING
if (!mForPrinting) {
return NS_OK;
}
int result = ::StartPage(mDC);
if (result <= 0)
return NS_ERROR_FAILURE;
@ -291,11 +275,8 @@ nsresult
gfxWindowsSurface::EndPage()
{
#ifdef NS_PRINTING
if (!mForPrinting) {
return NS_OK;
}
cairo_surface_show_page(CairoSurface());
if (mForPrinting)
cairo_surface_show_page(CairoSurface());
int result = ::EndPage(mDC);
if (result <= 0)
return NS_ERROR_FAILURE;

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

@ -307,3 +307,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'qt'):
LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
DEFINES['GRAPHITE2_STATIC'] = True
if CONFIG['OS_ARCH'] == 'WINNT':
del DEFINES['UNICODE']

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

@ -1,102 +0,0 @@
/* -*- 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/. */
#include "PrintTranslator.h"
#include "gfxContext.h"
#include "nsDeviceContext.h"
#include "mozilla/gfx/RecordedEvent.h"
#include "mozilla/gfx/RecordingTypes.h"
#include "mozilla/UniquePtr.h"
using namespace mozilla::gfx;
namespace mozilla {
namespace layout {
PrintTranslator::PrintTranslator(nsDeviceContext* aDeviceContext)
: mDeviceContext(aDeviceContext)
{
RefPtr<gfxContext> context = mDeviceContext->CreateRenderingContext();
mBaseDT = context->GetDrawTarget();
}
bool
PrintTranslator::TranslateRecording(std::istream& aRecording)
{
uint32_t magicInt;
ReadElement(aRecording, magicInt);
if (magicInt != mozilla::gfx::kMagicInt) {
return false;
}
uint16_t majorRevision;
ReadElement(aRecording, majorRevision);
if (majorRevision != kMajorRevision) {
return false;
}
uint16_t minorRevision;
ReadElement(aRecording, minorRevision);
if (minorRevision > kMinorRevision) {
return false;
}
int32_t eventType;
ReadElement(aRecording, eventType);
while (aRecording.good()) {
UniquePtr<RecordedEvent> recordedEvent(
RecordedEvent::LoadEventFromStream(aRecording,
static_cast<RecordedEvent::EventType>(eventType)));
// Make sure that the whole event was read from the stream successfully.
if (!aRecording.good() || !recordedEvent) {
return false;
}
recordedEvent->PlayEvent(this);
ReadElement(aRecording, eventType);
}
return true;
}
already_AddRefed<DrawTarget>
PrintTranslator::CreateDrawTarget(ReferencePtr aRefPtr,
const gfx::IntSize &aSize,
gfx::SurfaceFormat aFormat)
{
RefPtr<gfxContext> context = mDeviceContext->CreateRenderingContext();
if (!context) {
NS_WARNING("Failed to create rendering context for print.");
return nullptr;
}
RefPtr<DrawTarget> drawTarget = context->GetDrawTarget();
AddDrawTarget(aRefPtr, drawTarget);
return drawTarget.forget();
}
FontType
PrintTranslator::GetDesiredFontType()
{
switch (mBaseDT->GetBackendType()) {
case BackendType::DIRECT2D:
return FontType::DWRITE;
case BackendType::CAIRO:
return FontType::CAIRO;
case BackendType::SKIA:
return FontType::SKIA;
case BackendType::COREGRAPHICS:
case BackendType::COREGRAPHICS_ACCELERATED:
return FontType::COREGRAPHICS;
default:
return FontType::CAIRO;
}
}
} // namespace layout
} // namespace mozilla

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

@ -1,178 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_layout_PrintTranslator_h
#define mozilla_layout_PrintTranslator_h
#include <istream>
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Filters.h"
#include "mozilla/gfx/RecordedEvent.h"
#include "nsRefPtrHashtable.h"
class nsDeviceContext;
namespace mozilla {
namespace layout {
using gfx::Translator;
using gfx::ReferencePtr;
using gfx::DrawTarget;
using gfx::Path;
using gfx::SourceSurface;
using gfx::FilterNode;
using gfx::GradientStops;
using gfx::ScaledFont;
using gfx::NativeFontResource;
class PrintTranslator final : public Translator
{
public:
explicit PrintTranslator(nsDeviceContext* aDeviceContext);
bool TranslateRecording(std::istream& aRecording);
DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final
{
DrawTarget* result = mDrawTargets.GetWeak(aRefPtr);
MOZ_ASSERT(result);
return result;
}
Path* LookupPath(ReferencePtr aRefPtr) final
{
Path* result = mPaths.GetWeak(aRefPtr);
MOZ_ASSERT(result);
return result;
}
SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final
{
SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr);
MOZ_ASSERT(result);
return result;
}
FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final
{
FilterNode* result = mFilterNodes.GetWeak(aRefPtr);
MOZ_ASSERT(result);
return result;
}
GradientStops* LookupGradientStops(ReferencePtr aRefPtr) final
{
GradientStops* result = mGradientStops.GetWeak(aRefPtr);
MOZ_ASSERT(result);
return result;
}
ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final
{
ScaledFont* result = mScaledFonts.GetWeak(aRefPtr);
MOZ_ASSERT(result);
return result;
}
NativeFontResource* LookupNativeFontResource(uint64_t aKey) final
{
NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
MOZ_ASSERT(result);
return result;
}
void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) final
{
mDrawTargets.Put(aRefPtr, aDT);
}
void AddPath(ReferencePtr aRefPtr, Path *aPath) final
{
mPaths.Put(aRefPtr, aPath);
}
void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aSurface) final
{
mSourceSurfaces.Put(aRefPtr, aSurface);
}
void AddFilterNode(ReferencePtr aRefPtr, FilterNode *aFilter) final
{
mFilterNodes.Put(aRefPtr, aFilter);
}
void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aStops) final
{
mGradientStops.Put(aRefPtr, aStops);
}
void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) final
{
mScaledFonts.Put(aRefPtr, aScaledFont);
}
void AddNativeFontResource(uint64_t aKey,
NativeFontResource *aScaledFontResouce) final
{
mNativeFontResources.Put(aKey, aScaledFontResouce);
}
void RemoveDrawTarget(ReferencePtr aRefPtr) final
{
mDrawTargets.Remove(aRefPtr);
}
void RemovePath(ReferencePtr aRefPtr) final
{
mPaths.Remove(aRefPtr);
}
void RemoveSourceSurface(ReferencePtr aRefPtr) final
{
mSourceSurfaces.Remove(aRefPtr);
}
void RemoveFilterNode(ReferencePtr aRefPtr) final
{
mFilterNodes.Remove(aRefPtr);
}
void RemoveGradientStops(ReferencePtr aRefPtr) final
{
mGradientStops.Remove(aRefPtr);
}
void RemoveScaledFont(ReferencePtr aRefPtr) final
{
mScaledFonts.Remove(aRefPtr);
}
already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
const gfx::IntSize &aSize,
gfx::SurfaceFormat aFormat) final;
mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; }
mozilla::gfx::FontType GetDesiredFontType() final;
private:
RefPtr<nsDeviceContext> mDeviceContext;
RefPtr<DrawTarget> mBaseDT;
nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes;
nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops;
nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts;
nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources;
};
} // namespace layout
} // namespace mozilla
#endif // mozilla_layout_PrintTranslator_h

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

@ -1,47 +0,0 @@
/* -*- 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/. */
include protocol PPrinting;
namespace mozilla {
namespace layout {
async protocol PRemotePrintJob
{
manager PPrinting;
both:
// Tell either side to abort printing and clean up.
async AbortPrint(nsresult aRv);
parent:
// Initialize the real print device with the given information.
async InitializePrint(nsString aDocumentTitle, nsString aPrintToFile,
int32_t aStartPage, int32_t aEndPage);
// Translate the stored page recording and play back the events to the real
// print device.
// This will always deallocate the shared memory.
async ProcessPage(Shmem aStoredPage);
// This informs the real print device that we've finished, so it can trigger
// the actual print.
async FinalizePrint();
child:
// Inform the child that the print has been initialized in the parent or has
// failed with result aRv.
async PrintInitializationResult(nsresult aRv);
// Inform the child that the latest page has been processed remotely.
async PageProcessed();
async __delete__();
};
} // namespace layout
} // namespace mozilla

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

@ -1,102 +0,0 @@
/* -*- 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/. */
#include "RemotePrintJobChild.h"
#include "mozilla/unused.h"
#include "nsPagePrintTimer.h"
#include "nsPrintEngine.h"
namespace mozilla {
namespace layout {
RemotePrintJobChild::RemotePrintJobChild()
{
MOZ_COUNT_CTOR(RemotePrintJobChild);
}
nsresult
RemotePrintJobChild::InitializePrint(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage)
{
// Print initialization can sometimes display a dialog in the parent, so we
// need to spin a nested event loop until initialization completes.
Unused << SendInitializePrint(aDocumentTitle, aPrintToFile, aStartPage,
aEndPage);
while (!mPrintInitialized) {
Unused << NS_ProcessNextEvent();
}
return mInitializationResult;
}
bool
RemotePrintJobChild::RecvPrintInitializationResult(const nsresult& aRv)
{
mPrintInitialized = true;
mInitializationResult = aRv;
return true;
}
void
RemotePrintJobChild::ProcessPage(Shmem& aStoredPage)
{
MOZ_ASSERT(mPagePrintTimer);
mPagePrintTimer->WaitForRemotePrint();
Unused << SendProcessPage(aStoredPage);
}
bool
RemotePrintJobChild::RecvPageProcessed()
{
MOZ_ASSERT(mPagePrintTimer);
mPagePrintTimer->RemotePrintFinished();
return true;
}
bool
RemotePrintJobChild::RecvAbortPrint(const nsresult& aRv)
{
MOZ_ASSERT(mPrintEngine);
mPrintEngine->CleanupOnFailure(aRv, true);
return true;
}
void
RemotePrintJobChild::SetPagePrintTimer(nsPagePrintTimer* aPagePrintTimer)
{
MOZ_ASSERT(aPagePrintTimer);
mPagePrintTimer = aPagePrintTimer;
}
void
RemotePrintJobChild::SetPrintEngine(nsPrintEngine* aPrintEngine)
{
MOZ_ASSERT(aPrintEngine);
mPrintEngine = aPrintEngine;
}
RemotePrintJobChild::~RemotePrintJobChild()
{
MOZ_COUNT_DTOR(RemotePrintJobChild);
}
void
RemotePrintJobChild::ActorDestroy(ActorDestroyReason aWhy)
{
mPagePrintTimer = nullptr;
mPrintEngine = nullptr;
}
} // namespace layout
} // namespace mozilla

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

@ -1,58 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_layout_RemotePrintJobChild_h
#define mozilla_layout_RemotePrintJobChild_h
#include "mozilla/layout/PRemotePrintJobChild.h"
#include "mozilla/RefPtr.h"
class nsPagePrintTimer;
class nsPrintEngine;
namespace mozilla {
namespace layout {
class RemotePrintJobChild final : public PRemotePrintJobChild
{
public:
NS_INLINE_DECL_REFCOUNTING(RemotePrintJobChild)
RemotePrintJobChild();
void ActorDestroy(ActorDestroyReason aWhy) final;
nsresult InitializePrint(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage);
bool RecvPrintInitializationResult(const nsresult& aRv) final;
void ProcessPage(Shmem& aStoredPage);
bool RecvPageProcessed() final;
bool RecvAbortPrint(const nsresult& aRv) final;
void SetPagePrintTimer(nsPagePrintTimer* aPagePrintTimer);
void SetPrintEngine(nsPrintEngine* aPrintEngine);
private:
~RemotePrintJobChild() final;
bool mPrintInitialized = false;
nsresult mInitializationResult = NS_OK;
RefPtr<nsPagePrintTimer> mPagePrintTimer;
RefPtr<nsPrintEngine> mPrintEngine;
};
} // namespace layout
} // namespace mozilla
#endif // mozilla_layout_RemotePrintJobChild_h

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

@ -1,165 +0,0 @@
/* -*- 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/. */
#include "RemotePrintJobParent.h"
#include <istream>
#include "gfxContext.h"
#include "mozilla/Attributes.h"
#include "mozilla/unused.h"
#include "nsComponentManagerUtils.h"
#include "nsDeviceContext.h"
#include "nsIDeviceContextSpec.h"
#include "nsIPrintSettings.h"
#include "PrintTranslator.h"
namespace mozilla {
namespace layout {
RemotePrintJobParent::RemotePrintJobParent(nsIPrintSettings* aPrintSettings)
: mPrintSettings(aPrintSettings)
{
MOZ_COUNT_CTOR(RemotePrintJobParent);
}
bool
RemotePrintJobParent::RecvInitializePrint(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage)
{
nsresult rv = InitializePrintDevice(aDocumentTitle, aPrintToFile, aStartPage,
aEndPage);
if (NS_FAILED(rv)) {
Unused << SendPrintInitializationResult(rv);
Unused << Send__delete__(this);
return true;
}
mPrintTranslator.reset(new PrintTranslator(mPrintDeviceContext));
Unused << SendPrintInitializationResult(NS_OK);
return true;
}
nsresult
RemotePrintJobParent::InitializePrintDevice(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage)
{
nsresult rv;
nsCOMPtr<nsIDeviceContextSpec> deviceContextSpec =
do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = deviceContextSpec->Init(nullptr, mPrintSettings, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mPrintDeviceContext = new nsDeviceContext();
rv = mPrintDeviceContext->InitForPrinting(deviceContextSpec);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = mPrintDeviceContext->BeginDocument(aDocumentTitle, aPrintToFile,
aStartPage, aEndPage);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
bool
RemotePrintJobParent::RecvProcessPage(Shmem&& aStoredPage)
{
nsresult rv = PrintPage(aStoredPage);
// Always deallocate the shared memory no matter what the result.
if (!DeallocShmem(aStoredPage)) {
NS_WARNING("Failed to deallocated shared memory, remote print will abort.");
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
Unused << SendAbortPrint(rv);
} else {
Unused << SendPageProcessed();
}
return true;
}
nsresult
RemotePrintJobParent::PrintPage(const Shmem& aStoredPage)
{
MOZ_ASSERT(mPrintDeviceContext);
nsresult rv = mPrintDeviceContext->BeginPage();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
std::istringstream recording(std::string(aStoredPage.get<char>(),
aStoredPage.Size<char>()));
mPrintTranslator->TranslateRecording(recording);
rv = mPrintDeviceContext->EndPage();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
bool
RemotePrintJobParent::RecvFinalizePrint()
{
// EndDocument is sometimes called in the child even when BeginDocument has
// not been called. See bug 1223332.
if (mPrintDeviceContext) {
nsresult rv = mPrintDeviceContext->EndDocument();
// Too late to abort the child just log.
NS_WARN_IF(NS_FAILED(rv));
}
Unused << Send__delete__(this);
return true;
}
bool
RemotePrintJobParent::RecvAbortPrint(const nsresult& aRv)
{
if (mPrintDeviceContext) {
Unused << mPrintDeviceContext->AbortDocument();
}
Unused << Send__delete__(this);
return true;
}
RemotePrintJobParent::~RemotePrintJobParent()
{
MOZ_COUNT_DTOR(RemotePrintJobParent);
}
void
RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy)
{
}
} // namespace layout
} // namespace mozilla

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

@ -1,59 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_layout_RemotePrintJobParent_h
#define mozilla_layout_RemotePrintJobParent_h
#include "mozilla/layout/PRemotePrintJobParent.h"
#include "nsCOMPtr.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
class nsDeviceContext;
class nsIPrintSettings;
class PrintTranslator;
namespace mozilla {
namespace layout {
class RemotePrintJobParent final : public PRemotePrintJobParent
{
public:
explicit RemotePrintJobParent(nsIPrintSettings* aPrintSettings);
void ActorDestroy(ActorDestroyReason aWhy) final;
bool RecvInitializePrint(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage) final;
bool RecvProcessPage(Shmem&& aStoredPage) final;
bool RecvFinalizePrint() final;
bool RecvAbortPrint(const nsresult& aRv) final;
private:
~RemotePrintJobParent() final;
nsresult InitializePrintDevice(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage);
nsresult PrintPage(const Shmem& aStoredPage);
nsCOMPtr<nsIPrintSettings> mPrintSettings;
RefPtr<nsDeviceContext> mPrintDeviceContext;
UniquePtr<PrintTranslator> mPrintTranslator;
};
} // namespace layout
} // namespace mozilla
#endif // mozilla_layout_RemotePrintJobParent_h

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

@ -10,34 +10,21 @@ XPIDL_SOURCES += [
'nsIPrintStatusFeedback.idl',
]
EXPORTS.mozilla.layout += [
'ipc/RemotePrintJobChild.h',
'ipc/RemotePrintJobParent.h',
]
XPIDL_MODULE = 'layout_printing'
UNIFIED_SOURCES += [
'ipc/RemotePrintJobChild.cpp',
'ipc/RemotePrintJobParent.cpp',
'nsPagePrintTimer.cpp',
'nsPrintData.cpp',
'nsPrintEngine.cpp',
'nsPrintObject.cpp',
'nsPrintPreviewListener.cpp',
'PrintTranslator.cpp',
]
IPDL_SOURCES = [
'ipc/PRemotePrintJob.ipdl',
]
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'../base',
'/dom/base',
]
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

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

@ -4,8 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsPagePrintTimer.h"
#include "mozilla/unused.h"
#include "nsIContentViewer.h"
#include "nsIServiceManager.h"
#include "nsPrintEngine.h"
@ -120,38 +118,25 @@ nsPagePrintTimer::Notify(nsITimer *timer)
return NS_OK;
}
// There are four things that call Notify with different values for timer:
// There are three things that call Notify with different values for timer:
// 1) the delay between pages (timer == mTimer)
// 2) canvasPrintState done (timer == null)
// 3) the watch dog timer (timer == mWatchDogTimer)
// 4) the waiting for remote print "timer" (timer == mWaitingForRemotePrint)
if (!timer) {
// Reset the counter since a mozPrintCallback has finished.
mWatchDogCount = 0;
} else if (timer == mTimer) {
// Reset the watchdog timer before the start of every page.
mWatchDogCount = 0;
mTimer = nullptr;
} else if (timer == mWaitingForRemotePrint) {
mWaitingForRemotePrint = nullptr;
// If we are still waiting for the page delay timer, don't let the
// notification from the remote print job trigger the next page.
if (mTimer) {
return NS_OK;
}
} else if (timer == mWatchDogTimer) {
if (timer && timer == mWatchDogTimer) {
mWatchDogCount++;
if (mWatchDogCount > WATCH_DOG_MAX_COUNT) {
Fail();
return NS_OK;
}
} else if(!timer) {
// Reset the counter since a mozPrintCallback has finished.
mWatchDogCount = 0;
}
if (mDocViewerPrint) {
bool donePrePrint = mPrintEngine->PrePrintPage();
if (donePrePrint && !mWaitingForRemotePrint) {
if (donePrePrint) {
StopWatchDogTimer();
NS_DispatchToMainThread(this);
} else {
@ -164,33 +149,11 @@ nsPagePrintTimer::Notify(nsITimer *timer)
return NS_OK;
}
void
nsPagePrintTimer::WaitForRemotePrint()
{
nsresult result;
mWaitingForRemotePrint = do_CreateInstance("@mozilla.org/timer;1", &result);
if (NS_FAILED(result)) {
NS_WARNING("Failed to wait for remote print, we might time-out.");
mWaitingForRemotePrint = nullptr;
}
}
void
nsPagePrintTimer::RemotePrintFinished()
{
if (!mWaitingForRemotePrint) {
return;
}
mozilla::Unused <<
mWaitingForRemotePrint->InitWithCallback(this, 0, nsITimer::TYPE_ONE_SHOT);
}
nsresult
nsPagePrintTimer::Start(nsPrintObject* aPO)
{
mPrintObj = aPO;
mWatchDogCount = 0;
mDone = false;
return StartTimer(false);
}

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

@ -47,9 +47,6 @@ public:
void Stop();
void WaitForRemotePrint();
void RemotePrintFinished();
private:
~nsPagePrintTimer();
@ -62,7 +59,6 @@ private:
nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsITimer> mWatchDogTimer;
nsCOMPtr<nsITimer> mWaitingForRemotePrint;
uint32_t mDelay;
uint32_t mFiringCount;
nsPrintObject * mPrintObj;

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

@ -75,8 +75,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
#include "nsISelectionController.h"
// Misc
#include "mozilla/gfx/DrawEventRecorder.h"
#include "mozilla/layout/RemotePrintJobChild.h"
#include "nsISupportsUtils.h"
#include "nsIScriptContext.h"
#include "nsIDOMDocument.h"
@ -92,7 +90,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
#include "nsWidgetsCID.h"
#include "nsIDeviceContextSpec.h"
#include "nsDeviceContextSpecProxy.h"
#include "nsViewManager.h"
#include "nsView.h"
#include "nsRenderingContext.h"
@ -571,13 +568,9 @@ nsPrintEngine::DoCommonPrint(bool aIsPrintPreview,
mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB,
isSelection || mPrt->mIsIFrameSelected);
nsCOMPtr<nsIDeviceContextSpec> devspec;
if (XRE_IsContentProcess() && Preferences::GetBool("print.print_via_parent")) {
devspec = new nsDeviceContextSpecProxy();
} else {
devspec = do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIDeviceContextSpec> devspec
(do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsScriptSuppressor scriptSuppressor(this);
if (!aIsPrintPreview) {
@ -1685,15 +1678,14 @@ nsPrintEngine::SetupToPrintContent()
mPrt->OnStartPrinting();
}
nsAutoString fileNameStr;
char16_t* fileName = nullptr;
// check to see if we are printing to a file
bool isPrintToFile = false;
mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile);
if (isPrintToFile) {
// On some platforms The BeginDocument needs to know the name of the file.
char16_t* fileName = nullptr;
// On some platforms The BeginDocument needs to know the name of the file
// and it uses the PrintService to get it, so we need to set it into the PrintService here
mPrt->mPrintSettings->GetToFileName(&fileName);
fileNameStr = fileName;
}
nsAutoString docTitleStr;
@ -1719,8 +1711,7 @@ nsPrintEngine::SetupToPrintContent()
// to the "File Name" dialog, this comes back as an error
// Don't start printing when regression test are executed
if (!mPrt->mDebugFilePtr && mIsDoingPrinting) {
rv = mPrt->mPrintDC->BeginDocument(docTitleStr, fileNameStr, startPage,
endPage);
rv = mPrt->mPrintDC->BeginDocument(docTitleStr, fileName, startPage, endPage);
}
if (mIsCreatingPrintPreview) {
@ -3489,17 +3480,6 @@ nsPrintEngine::StartPagePrintTimer(nsPrintObject* aPO)
RefPtr<nsPagePrintTimer> timer =
new nsPagePrintTimer(this, mDocViewerPrint, printPageDelay);
timer.forget(&mPagePrintTimer);
nsCOMPtr<nsIPrintSession> printSession;
nsresult rv = mPrt->mPrintSettings->GetPrintSession(getter_AddRefs(printSession));
if (NS_SUCCEEDED(rv) && printSession) {
RefPtr<mozilla::layout::RemotePrintJobChild> remotePrintJob;
printSession->GetRemotePrintJob(getter_AddRefs(remotePrintJob));
if (NS_SUCCEEDED(rv) && remotePrintJob) {
remotePrintJob->SetPagePrintTimer(mPagePrintTimer);
remotePrintJob->SetPrintEngine(this);
}
}
}
return mPagePrintTimer->Start(aPO);

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

@ -1011,13 +1011,6 @@ pref("print.print_edge_left", 0);
pref("print.print_edge_right", 0);
pref("print.print_edge_bottom", 0);
// Print via the parent process. This is only used when e10s is enabled.
#if defined(XP_WIN)
pref("print.print_via_parent", true);
#else
pref("print.print_via_parent", false);
#endif
// Pref used by the spellchecker extension to control the
// maximum number of misspelled words that will be underlined
// in a document.

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

@ -52,7 +52,7 @@ nsDeviceContextSpecAndroid::Init(nsIWidget* aWidget,
NS_IMETHODIMP
nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage)
{

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

@ -19,7 +19,7 @@ public:
nsIPrintSettings* aPS,
bool aIsPrintPreview) override;
NS_IMETHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage) override;
NS_IMETHOD EndDocument() override;

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

@ -20,7 +20,7 @@ public:
NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS, bool aIsPrintPreview) override;
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface) override;
NS_IMETHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage) override;
NS_IMETHOD EndDocument() override;

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

@ -59,7 +59,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIWidget *aWidget,
}
NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage)
{

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

@ -300,10 +300,8 @@ nsDeviceContextSpecGTK::EnumeratePrinters()
nullptr, TRUE);
}
NS_IMETHODIMP
nsDeviceContextSpecGTK::BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
int32_t aStartPage, int32_t aEndPage)
NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(const nsAString& aTitle, char16_t * aPrintToFileName,
int32_t aStartPage, int32_t aEndPage)
{
mTitle.Truncate();
AppendUTF16toUTF8(aTitle, mTitle);

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

@ -34,8 +34,7 @@ public:
NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS,
bool aIsPrintPreview) override;
NS_IMETHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
NS_IMETHOD BeginDocument(const nsAString& aTitle, char16_t * aPrintToFileName,
int32_t aStartPage, int32_t aEndPage) override;
NS_IMETHOD EndDocument() override;
NS_IMETHOD BeginPage() override { return NS_OK; }

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

@ -95,7 +95,6 @@ EXPORTS += [
'InputData.h',
'nsBaseScreen.h',
'nsBaseWidget.h',
'nsDeviceContextSpecProxy.h',
'nsIDeviceContextSpec.h',
'nsIPluginWidget.h',
'nsIRollupListener.h',
@ -149,7 +148,6 @@ UNIFIED_SOURCES += [
'nsClipboardProxy.cpp',
'nsColorPickerProxy.cpp',
'nsContentProcessWidgetFactory.cpp',
'nsDeviceContextSpecProxy.cpp',
'nsDragServiceProxy.cpp',
'nsFilePickerProxy.cpp',
'nsHTMLFormatConverter.cpp',

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

@ -1,178 +0,0 @@
/* -*- 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/. */
#include "nsDeviceContextSpecProxy.h"
#include "gfxASurface.h"
#include "gfxPlatform.h"
#include "mozilla/gfx/DrawEventRecorder.h"
#include "mozilla/layout/RemotePrintJobChild.h"
#include "mozilla/RefPtr.h"
#include "mozilla/unused.h"
#include "nsComponentManagerUtils.h"
#include "nsIPrintSession.h"
#include "nsIPrintSettings.h"
using mozilla::Unused;
NS_IMPL_ISUPPORTS(nsDeviceContextSpecProxy, nsIDeviceContextSpec)
NS_IMETHODIMP
nsDeviceContextSpecProxy::Init(nsIWidget* aWidget,
nsIPrintSettings* aPrintSettings,
bool aIsPrintPreview)
{
nsresult rv;
mRealDeviceContextSpec =
do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mRealDeviceContextSpec->Init(nullptr, aPrintSettings, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
mRealDeviceContextSpec = nullptr;
return rv;
}
mPrintSettings = aPrintSettings;
if (aIsPrintPreview) {
return NS_OK;
}
// nsIPrintSettings only has a weak reference to nsIPrintSession, so we hold
// it to make sure it's available for the lifetime of the print.
rv = mPrintSettings->GetPrintSession(getter_AddRefs(mPrintSession));
if (NS_FAILED(rv) || !mPrintSession) {
NS_WARNING("We can't print via the parent without an nsIPrintSession.");
return rv;
}
rv = mPrintSession->GetRemotePrintJob(getter_AddRefs(mRemotePrintJob));
if (NS_FAILED(rv) || !mRemotePrintJob) {
NS_WARNING("We can't print via the parent without a RemotePrintJobChild.");
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::GetSurfaceForPrinter(gfxASurface** aSurface)
{
MOZ_ASSERT(aSurface);
MOZ_ASSERT(mRealDeviceContextSpec);
// The real device context may need to have created a real printing surface
// even though we're not using it directly.
nsresult rv = mRealDeviceContextSpec->GetSurfaceForPrinter(aSurface);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
double width, height;
rv = mPrintSettings->GetEffectivePageSize(&width, &height);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// convert twips to points
width /= TWIPS_PER_POINT_FLOAT;
height /= TWIPS_PER_POINT_FLOAT;
RefPtr<gfxASurface> surface = gfxPlatform::GetPlatform()->
CreateOffscreenSurface(mozilla::gfx::IntSize(width, height),
gfxImageFormat::ARGB32);
surface.forget(aSurface);
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::GetDrawEventRecorder(mozilla::gfx::DrawEventRecorder** aDrawEventRecorder)
{
MOZ_ASSERT(aDrawEventRecorder);
RefPtr<mozilla::gfx::DrawEventRecorder> result = mRecorder;
result.forget(aDrawEventRecorder);
return NS_OK;
}
float
nsDeviceContextSpecProxy::GetDPI()
{
MOZ_ASSERT(mRealDeviceContextSpec);
return mRealDeviceContextSpec->GetDPI();
}
float
nsDeviceContextSpecProxy::GetPrintingScale()
{
MOZ_ASSERT(mRealDeviceContextSpec);
return mRealDeviceContextSpec->GetPrintingScale();
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
int32_t aStartPage, int32_t aEndPage)
{
mRecorder = new DrawEventRecorderMemory();
return mRemotePrintJob->InitializePrint(nsString(aTitle),
nsString(aPrintToFileName),
aStartPage, aEndPage);
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::EndDocument()
{
Unused << mRemotePrintJob->SendFinalizePrint();
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::AbortDocument()
{
Unused << mRemotePrintJob->SendAbortPrint(NS_OK);
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::BeginPage()
{
return NS_OK;
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::EndPage()
{
// Save the current page recording to shared memory.
mozilla::ipc::Shmem storedPage;
size_t recordingSize = mRecorder->RecordingSize();
if (!mRemotePrintJob->AllocShmem(recordingSize,
mozilla::ipc::SharedMemory::TYPE_BASIC,
&storedPage)) {
NS_WARNING("Failed to create shared memory for remote printing.");
return NS_ERROR_FAILURE;
}
bool success = mRecorder->CopyRecording(storedPage.get<char>(), recordingSize);
if (!success) {
NS_WARNING("Copying recording to shared memory was not succesful.");
return NS_ERROR_FAILURE;
}
// Wipe the recording to free memory. The recorder does not forget which data
// backed objects that it has stored.
mRecorder->WipeRecording();
// Send the page recording to the parent.
mRemotePrintJob->ProcessPage(storedPage);
return NS_OK;
}

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

@ -1,63 +0,0 @@
/* -*- 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/. */
#ifndef nsDeviceContextSpecProxy_h
#define nsDeviceContextSpecProxy_h
#include "nsIDeviceContextSpec.h"
#include "nsCOMPtr.h"
class nsIPrintSession;
namespace mozilla {
namespace gfx {
class DrawEventRecorderMemory;
}
namespace layout {
class RemotePrintJobChild;
}
}
class nsDeviceContextSpecProxy final : public nsIDeviceContextSpec
{
public:
NS_DECL_ISUPPORTS
NS_METHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPrintSettings,
bool aIsPrintPreview) final;
NS_METHOD GetSurfaceForPrinter(gfxASurface** aSurface) final;
NS_METHOD GetDrawEventRecorder(mozilla::gfx::DrawEventRecorder** aDrawEventRecorder) final;
float GetDPI() final;
float GetPrintingScale() final;
NS_METHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
int32_t aStartPage, int32_t aEndPage) final;
NS_METHOD EndDocument() final;
NS_METHOD AbortDocument() final;
NS_METHOD BeginPage() final;
NS_METHOD EndPage() final;
private:
~nsDeviceContextSpecProxy() {}
nsCOMPtr<nsIPrintSettings> mPrintSettings;
nsCOMPtr<nsIPrintSession> mPrintSession;
nsCOMPtr<nsIDeviceContextSpec> mRealDeviceContextSpec;
RefPtr<mozilla::layout::RemotePrintJobChild> mRemotePrintJob;
RefPtr<mozilla::gfx::DrawEventRecorderMemory> mRecorder;
};
#endif // nsDeviceContextSpecProxy_h

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

@ -12,15 +12,9 @@ class nsIWidget;
class nsIPrintSettings;
class gfxASurface;
namespace mozilla {
namespace gfx{
class DrawEventRecorder;
}
}
#define NS_IDEVICE_CONTEXT_SPEC_IID \
{ 0xf407cfba, 0xbe28, 0x46c9, \
{ 0x8a, 0xba, 0x04, 0x2d, 0xae, 0xbb, 0x4f, 0x23 } }
{ 0xb5548fb1, 0xf43e, 0x4921, \
{ 0x82, 0x19, 0xc3, 0x82, 0x06, 0xee, 0x74, 0x5c } }
class nsIDeviceContextSpec : public nsISupports
{
@ -40,40 +34,12 @@ public:
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **nativeSurface) = 0;
/**
* If required override to return a recorder to record the print.
*
* @param aDrawEventRecorder out param for the recorder to use
* @return NS_OK or a suitable error code
*/
NS_IMETHOD GetDrawEventRecorder(mozilla::gfx::DrawEventRecorder** aDrawEventRecorder)
{
MOZ_ASSERT(aDrawEventRecorder);
*aDrawEventRecorder = nullptr;
return NS_OK;
}
/**
* Override to return something other than the default.
*
* @return DPI for printing.
*/
virtual float GetDPI() { return 72.0f; }
/**
* Override to return something other than the default.
*
* @return the printing scale to be applied to the context for printing.
*/
virtual float GetPrintingScale() { return 1.0f; }
NS_IMETHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage) = 0;
NS_IMETHOD EndDocument() = 0;
NS_IMETHOD AbortDocument() { return EndDocument(); }
NS_IMETHOD BeginPage() = 0;
NS_IMETHOD EndPage() = 0;
};

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

@ -12,6 +12,11 @@
* differs from nsIPrintSettings, which stores data which may
* be valid across a number of jobs.
*
* This interface is currently empty since, at this point, only
* platform-specific derived interfaces offer any functionality.
* It is here as a placeholder for when the printing session has
* XP functionality.
*
* The creation of a component which implements this interface
* will begin the session. Likewise, destruction of that object
* will end the session.
@ -19,22 +24,8 @@
* @status
*/
%{ C++
namespace mozilla {
namespace layout {
class RemotePrintJobChild;
}
}
%}
[ptr] native RemotePrintJobChildPtr(mozilla::layout::RemotePrintJobChild);
[uuid(424ae4bb-10ca-4f35-b84e-eab893322df4)]
[uuid(2f977d52-5485-11d4-87e2-0010a4e75ef2)]
interface nsIPrintSession : nsISupports
{
/**
* The remote print job is used for printing via the parent process.
*/
[noscript] attribute RemotePrintJobChildPtr remotePrintJob;
};

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

@ -21,9 +21,6 @@
#include "nsPrimitiveHelpers.h"
#include "mozilla/UniquePtr.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
@ -63,7 +60,7 @@ nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, const void*
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
if (primitive ) {
if (aDataLen % 2) {
auto buffer = mozilla::MakeUnique<char[]>(aDataLen + 1);
auto buffer = MakeUnique<char[]>(aDataLen + 1);
if (!MOZ_LIKELY(buffer))
return;

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

@ -3,14 +3,11 @@
* 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 "nsPrintOptionsImpl.h"
#include "mozilla/embedding/PPrinting.h"
#include "mozilla/layout/RemotePrintJobChild.h"
#include "nsPrintingProxy.h"
#include "nsPrintOptionsImpl.h"
#include "nsReadableUtils.h"
#include "nsPrintSettingsImpl.h"
#include "nsIPrintSession.h"
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
@ -32,8 +29,6 @@
using namespace mozilla;
using namespace mozilla::embedding;
typedef mozilla::layout::RemotePrintJobChild RemotePrintJobChild;
NS_IMPL_ISUPPORTS(nsPrintOptions, nsIPrintOptions, nsIPrintSettingsService)
// Pref Constants
@ -238,12 +233,6 @@ NS_IMETHODIMP
nsPrintOptions::DeserializeToPrintSettings(const PrintData& data,
nsIPrintSettings* settings)
{
nsCOMPtr<nsIPrintSession> session;
nsresult rv = settings->GetPrintSession(getter_AddRefs(session));
if (NS_SUCCEEDED(rv) && session) {
session->SetRemotePrintJob(
static_cast<RemotePrintJobChild*>(data.remotePrintJobChild()));
}
settings->SetStartPageRange(data.startPageRange());
settings->SetEndPageRange(data.endPageRange());

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

@ -5,10 +5,6 @@
#include "nsPrintSession.h"
#include "mozilla/layout/RemotePrintJobChild.h"
typedef mozilla::layout::RemotePrintJobChild RemotePrintJobChild;
//*****************************************************************************
//*** nsPrintSession
//*****************************************************************************
@ -30,19 +26,3 @@ nsresult nsPrintSession::Init()
{
return NS_OK;
}
NS_IMETHODIMP
nsPrintSession::GetRemotePrintJob(RemotePrintJobChild** aRemotePrintJob)
{
MOZ_ASSERT(aRemotePrintJob);
RefPtr<RemotePrintJobChild> result = mRemotePrintJob;
result.forget(aRemotePrintJob);
return NS_OK;
}
NS_IMETHODIMP
nsPrintSession::SetRemotePrintJob(RemotePrintJobChild* aRemotePrintJob)
{
mRemotePrintJob = aRemotePrintJob;
return NS_OK;
}

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

@ -7,17 +7,8 @@
#define nsPrintSession_h__
#include "nsIPrintSession.h"
#include "mozilla/RefPtr.h"
#include "nsWeakReference.h"
namespace mozilla {
namespace layout {
class RemotePrintJobChild;
}
}
//*****************************************************************************
//*** nsPrintSession
//*****************************************************************************
@ -34,9 +25,6 @@ public:
nsPrintSession();
virtual nsresult Init();
private:
RefPtr<mozilla::layout::RemotePrintJobChild> mRemotePrintJob;
};
#endif // nsPrintSession_h__

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

@ -151,7 +151,7 @@ NS_IMETHODIMP nsDeviceContextSpecQt::Init(nsIWidget* aWidget,
NS_IMETHODIMP nsDeviceContextSpecQt::BeginDocument(
const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage)
{

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

@ -28,7 +28,7 @@ public:
nsIPrintSettings* aPS,
bool aIsPrintPreview);
NS_IMETHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage);
NS_IMETHOD EndDocument();

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

@ -270,7 +270,6 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface
{
NS_ASSERTION(mDevMode, "DevMode can't be NULL here");
*surface = nullptr;
RefPtr<gfxASurface> newSurface;
int16_t outputFormat = 0;
@ -316,24 +315,19 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface
newSurface = new gfxWindowsSurface(dc, gfxWindowsSurface::FLAG_TAKE_DC | gfxWindowsSurface::FLAG_FOR_PRINTING);
if (newSurface->GetType() == (gfxSurfaceType)-1) {
gfxCriticalError() << "Invalid windows surface from " << gfx::hexa(dc);
return NS_ERROR_FAILURE;
newSurface = nullptr;
}
}
}
mPrintingSurface = newSurface;
newSurface.forget(surface);
return NS_OK;
}
if (newSurface) {
*surface = newSurface;
NS_ADDREF(*surface);
return NS_OK;
}
float
nsDeviceContextSpecWin::GetPrintingScale()
{
MOZ_ASSERT(mPrintingSurface);
HDC dc = reinterpret_cast<gfxWindowsSurface*>(mPrintingSurface.get())->GetDC();
int32_t OSVal = GetDeviceCaps(dc, LOGPIXELSY);
return float(OSVal) / GetDPI();
*surface = nullptr;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------------------

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

@ -13,7 +13,6 @@
#include "nsISupportsPrimitives.h"
#include <windows.h>
#include "mozilla/Attributes.h"
#include "mozilla/RefPtr.h"
class nsIWidget;
@ -26,7 +25,7 @@ public:
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface);
NS_IMETHOD BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage) { return NS_OK; }
NS_IMETHOD EndDocument() { return NS_OK; }
@ -35,10 +34,6 @@ public:
NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS, bool aIsPrintPreview);
float GetDPI() final { return 144.0f; }
float GetPrintingScale() final;
void GetDriverName(wchar_t *&aDriverName) const { aDriverName = mDriverName; }
void GetDeviceName(wchar_t *&aDeviceName) const { aDeviceName = mDeviceName; }
@ -69,7 +64,6 @@ protected:
LPDEVMODEW mDevMode;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
RefPtr<gfxASurface> mPrintingSurface;
};