--- a/embedding/components/printingui/ipc/PPrintSettingsDialog.ipdl +++ b/embedding/components/printingui/ipc/PPrintSettingsDialog.ipdl @@ -1,16 +1,15 @@ /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ /* 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 PPrintingTypes; include protocol PPrinting; -include protocol PRemotePrintJob; namespace mozilla { namespace embedding { // A PrintData for success, a failure nsresult for failure. union PrintDataOrNSResult { PrintData;
--- a/embedding/components/printingui/ipc/PPrinting.ipdl +++ b/embedding/components/printingui/ipc/PPrinting.ipdl @@ -3,27 +3,25 @@ * 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 PPrintingTypes; include protocol PContent; include protocol PBrowser; include protocol PPrintProgressDialog; include protocol PPrintSettingsDialog; -include protocol PRemotePrintJob; namespace mozilla { namespace embedding { sync protocol PPrinting { manager PContent; manages PPrintProgressDialog; manages PPrintSettingsDialog; - manages PRemotePrintJob; parent: sync ShowProgress(PBrowser browser, PPrintProgressDialog printProgressDialog, bool isForPrinting) returns(bool notifyOnOpen, nsresult rv); @@ -34,14 +32,13 @@ parent: PPrintProgressDialog(); PPrintSettingsDialog(); sync SavePrintSettings(PrintData settings, bool usePrinterNamePrefix, uint32_t flags) returns(nsresult rv); child: - async PRemotePrintJob(); __delete__(); }; } // namespace embedding } // namespace mozilla
--- a/embedding/components/printingui/ipc/PPrintingTypes.ipdlh +++ b/embedding/components/printingui/ipc/PPrintingTypes.ipdlh @@ -1,25 +1,22 @@ /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ /* 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 PRemotePrintJob; - namespace mozilla { namespace embedding { struct CStringKeyValue { nsCString key; nsCString value; }; struct PrintData { - nullable PRemotePrintJob remotePrintJob; int32_t startPageRange; int32_t endPageRange; double edgeTop; double edgeLeft; double edgeBottom; double edgeRight; double marginTop; double marginLeft;
--- a/embedding/components/printingui/ipc/PrintingParent.cpp +++ b/embedding/components/printingui/ipc/PrintingParent.cpp @@ -1,10 +1,10 @@ /* -*- 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/. */ #include "mozilla/dom/Element.h" #include "mozilla/dom/TabParent.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -14,21 +14,19 @@ #include "nsIPrintProgressParams.h" #include "nsIPrintSettingsService.h" #include "nsIServiceManager.h" #include "nsIWebProgressListener.h" #include "PrintingParent.h" #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 { bool PrintingParent::RecvShowProgress(PBrowserParent* parent, PPrintProgressDialogParent* printProgressDialog, const bool& isForPrinting, bool* notifyOnOpen, @@ -99,20 +97,16 @@ PrintingParent::ShowPrintDialog(PBrowser rv = po->DeserializeToPrintSettings(aData, settings); NS_ENSURE_SUCCESS(rv, rv); rv = pps->ShowPrintDialog(parentWin, wbp, settings); NS_ENSURE_SUCCESS(rv, rv); // And send it back. rv = po->SerializeToPrintData(settings, nullptr, aResult); - - PRemotePrintJobParent* remotePrintJob = new RemotePrintJobParent(settings); - aResult->remotePrintJobParent() = SendPRemotePrintJobConstructor(remotePrintJob); - return rv; } bool PrintingParent::RecvShowPrintDialog(PPrintSettingsDialogParent* aDialog, PBrowserParent* aParent, const PrintData& aData) { @@ -184,30 +178,16 @@ PrintingParent::AllocPPrintSettingsDialo bool PrintingParent::DeallocPPrintSettingsDialogParent(PPrintSettingsDialogParent* aDoomed) { delete aDoomed; 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) { } nsIDOMWindow* PrintingParent::DOMWindowFromBrowserParent(PBrowserParent* parent) {
--- a/embedding/components/printingui/ipc/PrintingParent.h +++ b/embedding/components/printingui/ipc/PrintingParent.h @@ -10,20 +10,16 @@ #include "mozilla/dom/PBrowserParent.h" #include "mozilla/embedding/PPrintingParent.h" class nsIDOMWindow; class PPrintProgressDialogParent; class PPrintSettingsDialogParent; namespace mozilla { -namespace layout { -class PRemotePrintJobParent; -} - namespace embedding { class PrintingParent final : public PPrintingParent { public: virtual bool RecvShowProgress(PBrowserParent* parent, PPrintProgressDialogParent* printProgressDialog, @@ -48,22 +44,16 @@ public: DeallocPPrintProgressDialogParent(PPrintProgressDialogParent* aActor); virtual PPrintSettingsDialogParent* AllocPPrintSettingsDialogParent(); virtual bool DeallocPPrintSettingsDialogParent(PPrintSettingsDialogParent* aActor); - virtual PRemotePrintJobParent* - AllocPRemotePrintJobParent(); - - virtual bool - DeallocPRemotePrintJobParent(PRemotePrintJobParent* aActor); - virtual void ActorDestroy(ActorDestroyReason aWhy); MOZ_IMPLICIT PrintingParent(); virtual ~PrintingParent(); private: nsIDOMWindow* @@ -74,8 +64,9 @@ private: const PrintData& data, PrintData* result); }; } // namespace embedding } // namespace mozilla #endif +
--- a/embedding/components/printingui/ipc/nsPrintingProxy.cpp +++ b/embedding/components/printingui/ipc/nsPrintingProxy.cpp @@ -1,33 +1,30 @@ /* -*- Mode: C++; tab-width: 4; 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/. */ -#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" using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::embedding; -using namespace mozilla::layout; static StaticRefPtr<nsPrintingProxy> sPrintingProxyInstance; NS_IMPL_ISUPPORTS(nsPrintingProxy, nsIPrintingPromptService) nsPrintingProxy::nsPrintingProxy() { } @@ -231,23 +228,8 @@ nsPrintingProxy::AllocPPrintSettingsDial bool nsPrintingProxy::DeallocPPrintSettingsDialogChild(PPrintSettingsDialogChild* aActor) { // The PrintSettingsDialogChild implements refcounting, and // 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; -}
--- a/embedding/components/printingui/ipc/nsPrintingProxy.h +++ b/embedding/components/printingui/ipc/nsPrintingProxy.h @@ -4,22 +4,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef __nsPrintingProxy_h #define __nsPrintingProxy_h #include "nsIPrintingPromptService.h" #include "mozilla/embedding/PPrintingChild.h" -namespace mozilla { -namespace layout { -class PRemotePrintJobChild; -} -} - class nsPrintingProxy: public nsIPrintingPromptService, public mozilla::embedding::PPrintingChild { virtual ~nsPrintingProxy(); public: nsPrintingProxy(); @@ -40,18 +34,12 @@ public: virtual bool DeallocPPrintProgressDialogChild(PPrintProgressDialogChild* aActor) override; virtual PPrintSettingsDialogChild* AllocPPrintSettingsDialogChild() override; virtual bool DeallocPPrintSettingsDialogChild(PPrintSettingsDialogChild* aActor) override; - - virtual PRemotePrintJobChild* - AllocPRemotePrintJobChild() override; - - virtual bool - DeallocPRemotePrintJobChild(PRemotePrintJobChild* aActor) override; }; #endif
--- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -662,39 +662,16 @@ public: } protected: ScaledFont() {} 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 * parameters. This is because different platforms have unique rendering * parameters. */ class GlyphRenderingOptions : public RefCounted<GlyphRenderingOptions> { @@ -721,19 +698,16 @@ public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTarget) DrawTarget() : mTransformDirty(false), mPermitSubpixelAA(false) {} virtual ~DrawTarget() {} virtual bool IsValid() const { return true; }; 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 * normally return the same SourceSurface object. */ virtual already_AddRefed<SourceSurface> Snapshot() = 0; virtual IntSize GetSize() = 0; @@ -1210,25 +1184,26 @@ public: static already_AddRefed<DrawTarget> CreateDrawTargetForData(BackendType aBackend, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat); static already_AddRefed<ScaledFont> 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 * must be used when using the Cairo backend. The NativeFont and * cairo_scaled_font_t* parameters must correspond to the same font. */ static already_AddRefed<ScaledFont> CreateScaledFontWithCairo(const NativeFont &aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont);
deleted file mode 100644 --- a/gfx/2d/AutoHelpersWin.h +++ /dev/null @@ -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
deleted file mode 100644 --- a/gfx/2d/BigEndianInts.h +++ /dev/null @@ -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 \ No newline at end of file
--- a/gfx/2d/DrawEventRecorder.cpp +++ b/gfx/2d/DrawEventRecorder.cpp @@ -1,94 +1,54 @@ /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "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) { WriteElement(*mOutputStream, aEvent.mType); aEvent.RecordToStream(*mOutputStream); Flush(); } DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename) : DrawEventRecorderPrivate(nullptr) , mOutputFile(aFilename, ofstream::binary) { mOutputStream = &mOutputFile; - WriteHeader(); + WriteElement(*mOutputStream, kMagicInt); + WriteElement(*mOutputStream, kMajorRevision); + WriteElement(*mOutputStream, kMinorRevision); } DrawEventRecorderFile::~DrawEventRecorderFile() { mOutputFile.close(); } void 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
--- a/gfx/2d/DrawEventRecorder.h +++ b/gfx/2d/DrawEventRecorder.h @@ -24,106 +24,58 @@ class PathRecording; class DrawEventRecorderPrivate : public DrawEventRecorder { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderPrivate) 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 RemoveStoredObject(const ReferencePtr aObject) { - mStoredObjects.erase(aObject); + void AddStoredPath(const ReferencePtr aPath) { + mStoredPaths.insert(aPath); } - bool HasStoredObject(const ReferencePtr aObject) { - return mStoredObjects.find(aObject) != mStoredObjects.end(); + void RemoveStoredPath(const ReferencePtr aPath) { + mStoredPaths.erase(aPath); } - 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: std::ostream *mOutputStream; virtual void Flush() = 0; #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 { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderFile) explicit DrawEventRecorderFile(const char *aFilename); ~DrawEventRecorderFile(); private: virtual void Flush(); 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 #endif /* MOZILLA_GFX_DRAWEVENTRECORDER_H_ */
--- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -1,98 +1,35 @@ /* -*- 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/. */ #include "DrawTargetRecording.h" #include "PathRecording.h" #include <stdio.h> #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: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceRecording) SourceSurfaceRecording(SourceSurface *aFinalSurface, DrawEventRecorderPrivate *aRecorder) : mFinalSurface(aFinalSurface), mRecorder(aRecorder) { - mRecorder->AddStoredObject(this); } ~SourceSurfaceRecording() { - mRecorder->RemoveStoredObject(this); mRecorder->RecordEvent(RecordedSourceSurfaceDestruction(this)); } virtual SurfaceType GetType() const { return SurfaceType::RECORDING; } virtual IntSize GetSize() const { return mFinalSurface->GetSize(); } virtual SurfaceFormat GetFormat() const { return mFinalSurface->GetFormat(); } virtual already_AddRefed<DataSourceSurface> GetDataSurface() { return mFinalSurface->GetDataSurface(); } @@ -102,22 +39,20 @@ public: class GradientStopsRecording : public GradientStops { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsRecording) GradientStopsRecording(GradientStops *aFinalGradientStops, DrawEventRecorderPrivate *aRecorder) : mFinalGradientStops(aFinalGradientStops), mRecorder(aRecorder) { - mRecorder->AddStoredObject(this); } ~GradientStopsRecording() { - mRecorder->RemoveStoredObject(this); mRecorder->RecordEvent(RecordedGradientStopsDestruction(this)); } virtual BackendType GetBackendType() const { return BackendType::RECORDING; } RefPtr<GradientStops> mFinalGradientStops; RefPtr<DrawEventRecorderPrivate> mRecorder; }; @@ -146,49 +81,39 @@ class FilterNodeRecording : public Filte { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeRecording, override) using FilterNode::SetAttribute; 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); } #define FORWARD_SET_ATTRIBUTE(type, argtype) \ virtual void SetAttribute(uint32_t aIndex, type aValue) override { \ mRecorder->RecordEvent(RecordedFilterNodeSetAttribute(this, aIndex, aValue, RecordedFilterNodeSetAttribute::ARGTYPE_##argtype)); \ mFinalFilterNode->SetAttribute(aIndex, aValue); \ } @@ -197,17 +122,16 @@ public: FORWARD_SET_ATTRIBUTE(uint32_t, UINT32); FORWARD_SET_ATTRIBUTE(Float, FLOAT); FORWARD_SET_ATTRIBUTE(const Size&, SIZE); FORWARD_SET_ATTRIBUTE(const IntSize&, INTSIZE); FORWARD_SET_ATTRIBUTE(const IntPoint&, INTPOINT); 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); #undef FORWARD_SET_ATTRIBUTE virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) override { mRecorder->RecordEvent(RecordedFilterNodeSetAttribute(this, aIndex, aFloat, aSize)); @@ -215,16 +139,27 @@ public: } virtual FilterBackend GetBackendType() override { return FILTER_BACKEND_RECORDING; } RefPtr<FilterNode> mFinalFilterNode; 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) : mPattern(nullptr) { mOrigPattern = const_cast<Pattern*>(&aPattern); } @@ -293,77 +228,70 @@ DrawTargetRecording::DrawTargetRecording mRecorder->RecordEvent(RecordedDrawTargetCreation(this, mFinalDT->GetBackendType(), mFinalDT->GetSize(), mFinalDT->GetFormat(), aHasData, snapshot)); 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)); } void 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); } void DrawTargetRecording::StrokeRect(const Rect &aRect, const Pattern &aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) { - EnsurePatternDependenciesStored(aPattern); - mRecorder->RecordEvent(RecordedStrokeRect(this, aRect, aPattern, aStrokeOptions, aOptions)); mFinalDT->StrokeRect(aRect, *AdjustedPattern(aPattern), aStrokeOptions, aOptions); } void DrawTargetRecording::StrokeLine(const Point &aBegin, const Point &aEnd, const Pattern &aPattern, 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 { void *refPtr; RefPtr<DrawEventRecorderPrivate> recorder; }; @@ -382,30 +310,20 @@ void RecordingFontUserDataDestroyFunc(vo void DrawTargetRecording::FillGlyphs(ScaledFont *aFont, const GlyphBuffer &aBuffer, const Pattern &aPattern, 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; userData->recorder = mRecorder; aFont->AddUserData(reinterpret_cast<UserDataKey*>(mRecorder.get()), userData, &RecordingFontUserDataDestroyFunc); } @@ -416,47 +334,40 @@ DrawTargetRecording::FillGlyphs(ScaledFo mFinalDT->FillGlyphs(aFont, aBuffer, aPattern, aOptions, aRenderingOptions); } void 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); } void DrawTargetRecording::MaskSurface(const Pattern &aSource, SourceSurface *aMask, 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); } void DrawTargetRecording::Stroke(const Path *aPath, const Pattern &aPattern, 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> DrawTargetRecording::Snapshot() { RefPtr<SourceSurface> surf = mFinalDT->Snapshot(); RefPtr<SourceSurface> retSurf = new SourceSurfaceRecording(surf, mRecorder); @@ -468,46 +379,40 @@ DrawTargetRecording::Snapshot() void DrawTargetRecording::DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect &aSource, 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); } void DrawTargetRecording::DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest, const Color &aColor, const Point &aOffset, 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); } void DrawTargetRecording::DrawFilter(FilterNode *aNode, const Rect &aSourceRect, 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> DrawTargetRecording::CreateFilter(FilterType aType) { RefPtr<FilterNode> node = mFinalDT->CreateFilter(aType); RefPtr<FilterNode> retNode = new FilterNodeRecording(node, mRecorder); @@ -524,29 +429,27 @@ DrawTargetRecording::ClearRect(const Rec mFinalDT->ClearRect(aRect); } void 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); } 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 DrawTargetRecording::PushClipRect(const Rect &aRect) { mRecorder->RecordEvent(RecordedPushClipRect(this, aRect)); mFinalDT->PushClipRect(aRect); } @@ -582,38 +485,68 @@ DrawTargetRecording::OptimizeSourceSurfa RefPtr<DataSourceSurface> dataSurf = surf->GetDataSurface(); if (!dataSurf) { // Let's try get it off the original surface. 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(); } already_AddRefed<SourceSurface> DrawTargetRecording::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const { RefPtr<SourceSurface> surf = mFinalDT->CreateSourceSurfaceFromNativeSurface(aSurface); 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(); } 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> DrawTargetRecording::CreatePathBuilder(FillRule aFillRule) const { RefPtr<PathBuilder> builder = mFinalDT->CreatePathBuilder(aFillRule); return MakeAndAddRef<PathBuilderRecording>(builder, aFillRule); } @@ -635,62 +568,25 @@ DrawTargetRecording::CreateGradientStops void DrawTargetRecording::SetTransform(const Matrix &aTransform) { mRecorder->RecordEvent(RecordedSetTransform(this, aTransform)); DrawTarget::SetTransform(aTransform); mFinalDT->SetTransform(aTransform); } -already_AddRefed<PathRecording> -DrawTargetRecording::EnsurePathStored(const Path *aPath) +void +DrawTargetRecording::EnsureStored(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) -{ - 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); } } } } // namespace gfx } // namespace mozilla
--- a/gfx/2d/DrawTargetRecording.h +++ b/gfx/2d/DrawTargetRecording.h @@ -1,10 +1,9 @@ /* -*- 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/. */ #ifndef MOZILLA_GFX_DRAWTARGETRECORDING_H_ #define MOZILLA_GFX_DRAWTARGETRECORDING_H_ #include "2D.h" @@ -13,32 +12,20 @@ namespace mozilla { namespace gfx { 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; virtual IntSize GetSize() override { return mFinalDT->GetSize(); } /* Ensure that the DrawTarget backend has flushed all drawing operations to * this draw target. This must be called before using the backing surface of * this draw target outside of GFX 2D code. @@ -283,18 +270,17 @@ public: /* Tries to get a native surface for a DrawTarget, this may fail if the * draw target cannot convert to this surface type. */ virtual void *GetNativeSurface(NativeSurfaceType aType) override { return mFinalDT->GetNativeSurface(aType); } 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; }; } // namespace gfx } // namespace mozilla
--- a/gfx/2d/Factory.cpp +++ b/gfx/2d/Factory.cpp @@ -16,46 +16,43 @@ #ifdef MOZ_ENABLE_FREETYPE #define USE_SKIA_FREETYPE #include "ScaledFontCairo.h" #endif #endif #if defined(WIN32) #include "ScaledFontWin.h" -#include "NativeFontResourceGDI.h" #endif #ifdef XP_DARWIN #include "ScaledFontMac.h" #endif #ifdef XP_DARWIN #include "DrawTargetCG.h" #endif #ifdef WIN32 #include "DrawTargetD2D.h" #include "DrawTargetD2D1.h" #include "ScaledFontDWrite.h" -#include "NativeFontResourceDWrite.h" #include <d3d10_1.h> #include "HelpersD2D.h" #endif #include "DrawTargetDual.h" #include "DrawTargetTiled.h" #include "DrawTargetRecording.h" #include "SourceSurfaceRawData.h" #include "DrawEventRecorder.h" -#include "Preferences.h" #include "Logging.h" #include "mozilla/CheckedInt.h" #if defined(MOZ_LOGGING) GFX2D_API mozilla::LogModule* GetGFX2DLog() { @@ -150,19 +147,41 @@ HasCPUIDBit(unsigned int level, CPUIDReg return !!(unsigned(regs[reg]) & bit); } #endif #endif 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; ID3D11Device *Factory::mD3D11Device; ID2D1Device *Factory::mD2D1Device; #endif DrawEventRecorder *Factory::mRecorder; @@ -537,45 +556,30 @@ Factory::CreateScaledFontForNativeFont(c } #endif default: gfxWarning() << "Invalid native font type specified."; return nullptr; } } -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; } } already_AddRefed<ScaledFont> Factory::CreateScaledFontWithCairo(const NativeFont& aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont) { #ifdef USE_CAIRO
--- a/gfx/2d/Logging.h +++ b/gfx/2d/Logging.h @@ -57,27 +57,51 @@ inline mozilla::LogLevel PRLogLevelForLe return LogLevel::Debug; case LOG_EVERYTHING: return LogLevel::Error; } return LogLevel::Debug; } #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 // selectively enable logging on the configurations that // support prlog (on other systems, 3 and 4 are the same.) For prlog, // 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 /// controlled with a gfx.logging.level preference. If not set, the default /// for the preference is 5 in the debug builds, 1 in the release builds. /// /// gfxDebug only works in the debug builds, and is used for information /// level messages, helping with debugging. In addition to only working @@ -135,26 +159,26 @@ enum class LogReason : int { }; struct BasicLogger { // For efficiency, this method exists and copies the logic of the // 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 #if defined(MOZ_LOGGING) if (MOZ_LOG_TEST(GetGFX2DLog(), PRLogLevelForLevel(aLevel))) { return true; } else #endif - if ((LoggingPrefs::sGfxLogLevel >= LOG_DEBUG_PRLOG) || + if ((PreferenceAccess::sGfxLogLevel >= LOG_DEBUG_PRLOG) || (aLevel < LOG_DEBUG)) { return true; } #endif } return false; } @@ -168,26 +192,26 @@ struct BasicLogger // is consistent with what prlog does in general. Note that if prlog // is in the build, but disabled, we will printf if the preferences // requires us to log something (see sGfxLogLevel for the special // treatment of LOG_DEBUG and LOG_DEBUG_PRLOG) // // 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 #if defined(MOZ_LOGGING) if (MOZ_LOG_TEST(GetGFX2DLog(), PRLogLevelForLevel(aLevel))) { 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"); } #endif } } };
deleted file mode 100644 --- a/gfx/2d/NativeFontResourceDWrite.cpp +++ /dev/null @@ -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
deleted file mode 100644 --- a/gfx/2d/NativeFontResourceDWrite.h +++ /dev/null @@ -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 \ No newline at end of file
deleted file mode 100644 --- a/gfx/2d/NativeFontResourceGDI.cpp +++ /dev/null @@ -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
deleted file mode 100644 --- a/gfx/2d/NativeFontResourceGDI.h +++ /dev/null @@ -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 \ No newline at end of file
--- a/gfx/2d/PathRecording.cpp +++ b/gfx/2d/PathRecording.cpp @@ -74,17 +74,17 @@ PathBuilderRecording::Finish() { RefPtr<Path> path = mPathBuilder->Finish(); return MakeAndAddRef<PathRecording>(path, mPathOps, mFillRule); } PathRecording::~PathRecording() { for (size_t i = 0; i < mStoredRecorders.size(); i++) { - mStoredRecorders[i]->RemoveStoredObject(this); + mStoredRecorders[i]->RemoveStoredPath(this); mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this)); } } already_AddRefed<PathBuilder> PathRecording::CopyToBuilder(FillRule aFillRule) const { RefPtr<PathBuilder> pathBuilder = mPath->CopyToBuilder(aFillRule);
deleted file mode 100644 --- a/gfx/2d/Preferences.cpp +++ /dev/null @@ -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 \ No newline at end of file
deleted file mode 100644 --- a/gfx/2d/Preferences.h +++ /dev/null @@ -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
--- a/gfx/2d/RecordedEvent.cpp +++ b/gfx/2d/RecordedEvent.cpp @@ -1,21 +1,19 @@ /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "RecordedEvent.h" +#include "PathRecording.h" -#include "PathRecording.h" -#include "RecordingTypes.h" #include "Tools.h" #include "Filters.h" #include "Logging.h" -#include "SFNTData.h" namespace mozilla { namespace gfx { using namespace std; static std::string NameFromBackend(BackendType aType) { @@ -24,26 +22,16 @@ static std::string NameFromBackend(Backe return "None"; case BackendType::DIRECT2D: return "Direct2D"; default: return "Unknown"; } } -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) RecordedEvent * RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType) { switch (aType) { LOAD_EVENT_TYPE(DRAWTARGETCREATION, RecordedDrawTargetCreation); @@ -73,18 +61,16 @@ RecordedEvent::LoadEventFromStream(std:: LOAD_EVENT_TYPE(GRADIENTSTOPSCREATION, RecordedGradientStopsCreation); LOAD_EVENT_TYPE(GRADIENTSTOPSDESTRUCTION, RecordedGradientStopsDestruction); LOAD_EVENT_TYPE(SNAPSHOT, RecordedSnapshot); LOAD_EVENT_TYPE(SCALEDFONTCREATION, RecordedScaledFontCreation); LOAD_EVENT_TYPE(SCALEDFONTDESTRUCTION, RecordedScaledFontDestruction); 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; } } string RecordedEvent::GetEventName(EventType aType) { @@ -148,20 +134,16 @@ RecordedEvent::GetEventName(EventType aT case SCALEDFONTDESTRUCTION: return "ScaledFontDestruction"; case MASKSURFACE: return "MaskSurface"; case FILTERNODESETATTRIBUTE: return "SetAttribute"; case FILTERNODESETINPUT: return "SetInput"; - case CREATESIMILARDRAWTARGET: - return "CreateSimilarDrawTarget"; - case FONTDATA: - return "FontData"; default: return "Unknown"; } } void RecordedEvent::RecordPatternData(std::ostream &aStream, const PatternStorage &aPattern) const { @@ -379,19 +361,20 @@ RecordedDrawingEvent::GetObjectRef() con { return mDT; } 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); } } void RecordedDrawTargetCreation::RecordToStream(ostream &aStream) const { @@ -464,46 +447,16 @@ RecordedDrawTargetDestruction::RecordedD } void RecordedDrawTargetDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const { 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) : mPattern(nullptr), mTranslator(aTranslator) { mStorage = const_cast<PatternStorage*>(&aStorage); } @@ -1386,110 +1339,65 @@ RecordedSnapshot::RecordedSnapshot(istre } void RecordedSnapshot::OutputSimpleEventInfo(stringstream &aStringStream) const { aStringStream << "[" << mRefPtr << "] Snapshot Created (DT: " << mDT << ")"; } -RecordedFontData::~RecordedFontData() -{ - 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 +RecordedScaledFontCreation::~RecordedScaledFontCreation() { - 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); } 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 RecordedScaledFontCreation::OutputSimpleEventInfo(stringstream &aStringStream) const { 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 RecordedScaledFontDestruction::PlayEvent(Translator *aTranslator) const { aTranslator->RemoveScaledFont(mRefPtr); } @@ -1566,17 +1474,16 @@ RecordedFilterNodeSetAttribute::PlayEven REPLAY_SET_ATTRIBUTE(uint32_t, UINT32); REPLAY_SET_ATTRIBUTE(Float, FLOAT); REPLAY_SET_ATTRIBUTE(Size, SIZE); REPLAY_SET_ATTRIBUTE(IntSize, INTSIZE); REPLAY_SET_ATTRIBUTE(IntPoint, INTPOINT); 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); case ARGTYPE_FLOAT_ARRAY: aTranslator->LookupFilterNode(mNode)->SetAttribute( mIndex, reinterpret_cast<const Float*>(&mPayload.front()), mPayload.size() / sizeof(Float));
--- a/gfx/2d/RecordedEvent.h +++ b/gfx/2d/RecordedEvent.h @@ -5,34 +5,30 @@ #ifndef MOZILLA_GFX_RECORDEDEVENT_H_ #define MOZILLA_GFX_RECORDEDEVENT_H_ #include "2D.h" #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 { ReferencePtr() : mLongPtr(0) {} MOZ_IMPLICIT ReferencePtr(const void* aLongPtr) @@ -57,24 +53,16 @@ struct ReferencePtr operator void*() const { return (void*)mLongPtr; } 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) { std::stringstream stream; stream << aPtr; return stream.str(); } @@ -84,35 +72,29 @@ public: virtual ~Translator() {} virtual DrawTarget *LookupDrawTarget(ReferencePtr aRefPtr) = 0; virtual Path *LookupPath(ReferencePtr aRefPtr) = 0; virtual SourceSurface *LookupSourceSurface(ReferencePtr aRefPtr) = 0; 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; virtual void RemovePath(ReferencePtr aRefPtr) = 0; virtual void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aPath) = 0; virtual void RemoveSourceSurface(ReferencePtr aRefPtr) = 0; virtual void AddFilterNode(mozilla::gfx::ReferencePtr aRefPtr, FilterNode *aSurface) = 0; virtual void RemoveFilterNode(mozilla::gfx::ReferencePtr aRefPtr) = 0; virtual void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aPath) = 0; 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; }; struct ColorPatternStorage { Color mColor; }; @@ -184,24 +166,20 @@ public: SNAPSHOT, SCALEDFONTCREATION, SCALEDFONTDESTRUCTION, MASKSURFACE, FILTERNODECREATION, 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 {} virtual void RecordToStream(std::ostream &aStream) const {} virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const { } @@ -298,44 +276,16 @@ public: BackendType mBackendType; private: friend class RecordedEvent; 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) : RecordedDrawingEvent(FILLRECT, aDT), mRect(aRect), mOptions(aOptions) { StorePattern(mPattern, aPattern); } @@ -944,82 +894,47 @@ private: friend class RecordedEvent; ReferencePtr mRefPtr; ReferencePtr mDT; MOZ_IMPLICIT RecordedSnapshot(std::istream &aStream); }; -class RecordedFontData : public RecordedEvent { +class RecordedScaledFontCreation : public RecordedEvent { public: - - static void FontDataProc(const uint8_t *aData, uint32_t aSize, - uint32_t aIndex, Float aGlyphSize, void* aBaton) + 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); + static_cast<RecordedScaledFontCreation*>(aBaton)->SetFontData(aData, aSize, aIndex, aGlyphSize); } - ~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; + RecordedScaledFontCreation(ReferencePtr aRefPtr, ScaledFont *aScaledFont) + : RecordedEvent(SCALEDFONTCREATION), mRefPtr(aRefPtr), mData(nullptr) + { + aScaledFont->GetFontFileData(&FontDataProc, this); + } - 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) - { - } + ~RecordedScaledFontCreation(); 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 "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; MOZ_IMPLICIT RecordedScaledFontCreation(std::istream &aStream); }; class RecordedScaledFontDestruction : public RecordedEvent { public: @@ -1078,17 +993,16 @@ public: ARGTYPE_BOOL, ARGTYPE_FLOAT, ARGTYPE_SIZE, ARGTYPE_INTSIZE, ARGTYPE_INTPOINT, ARGTYPE_RECT, ARGTYPE_INTRECT, ARGTYPE_POINT, - ARGTYPE_MATRIX, ARGTYPE_MATRIX5X4, ARGTYPE_POINT3D, ARGTYPE_COLOR, ARGTYPE_FLOAT_ARRAY }; template<typename T> RecordedFilterNodeSetAttribute(FilterNode *aNode, uint32_t aIndex, T aArgument, ArgType aArgType)
deleted file mode 100644 --- a/gfx/2d/SFNTData.cpp +++ /dev/null @@ -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
deleted file mode 100644 --- a/gfx/2d/SFNTData.h +++ /dev/null @@ -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
deleted file mode 100644 --- a/gfx/2d/SFNTNameTable.cpp +++ /dev/null @@ -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
deleted file mode 100644 --- a/gfx/2d/SFNTNameTable.h +++ /dev/null @@ -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
--- a/gfx/2d/ScaledFontBase.cpp +++ b/gfx/2d/ScaledFontBase.cpp @@ -40,43 +40,16 @@ ScaledFontBase::ScaledFontBase(Float aSi #ifdef USE_SKIA mTypeface = nullptr; #endif #ifdef USE_CAIRO_SCALED_FONT mScaledFont = nullptr; #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) { SkTypeface *typeFace = GetSkTypeface(); MOZ_ASSERT(typeFace); SkPaint paint;
--- a/gfx/2d/ScaledFontBase.h +++ b/gfx/2d/ScaledFontBase.h @@ -40,30 +40,27 @@ public: #ifdef USE_SKIA virtual SkTypeface* GetSkTypeface() { return mTypeface; } #endif // Not true, but required to instantiate a ScaledFontBase. 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 protected: friend class DrawTargetSkia; #ifdef USE_SKIA SkTypeface* mTypeface; 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; }; } // namespace gfx } // namespace mozilla
--- a/gfx/2d/ScaledFontDWrite.cpp +++ b/gfx/2d/ScaledFontDWrite.cpp @@ -1,25 +1,150 @@ /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "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() { BOOL font_smoothing; UINT smoothing_type; if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0)) { return DEFAULT_QUALITY; @@ -83,16 +208,109 @@ DoGrayscale(IDWriteFontFace *aDWFace, Fl break; } } aDWFace->ReleaseFontTable(tableContext); } 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) { if (aTarget->GetBackendType() != BackendType::DIRECT2D && aTarget->GetBackendType() != BackendType::DIRECT2D1_1) { return ScaledFontBase::GetPathForGlyphs(aBuffer, aTarget); } RefPtr<PathBuilder> pathBuilder = aTarget->CreatePathBuilder(); @@ -208,22 +426,10 @@ ScaledFontDWrite::GetDefaultAAMode() if (defaultMode == AntialiasMode::GRAY) { if (!DoGrayscale(mFontFace, mSize)) { defaultMode = AntialiasMode::NONE; } } 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 - } }
--- a/gfx/2d/ScaledFontDWrite.h +++ b/gfx/2d/ScaledFontDWrite.h @@ -17,16 +17,17 @@ namespace gfx { class ScaledFontDWrite final : public ScaledFontBase { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontDwrite) ScaledFontDWrite(IDWriteFontFace *aFont, Float aSize) : ScaledFontBase(aSize) , mFontFace(aFont) {} + ScaledFontDWrite(uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize); virtual FontType GetType() const { return FontType::DWRITE; } virtual already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget); virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint); void CopyGlyphsToSink(const GlyphBuffer &aBuffer, ID2D1GeometrySink *aSink); @@ -38,21 +39,16 @@ public: virtual SkTypeface* GetSkTypeface() { MOZ_ASSERT(false, "Skia and DirectWrite do not mix"); return nullptr; } #endif RefPtr<IDWriteFontFace> mFontFace; - -protected: -#ifdef USE_CAIRO_SCALED_FONT - cairo_font_face_t* GetCairoFontFace() override; -#endif }; class GlyphRenderingOptionsDWrite : public GlyphRenderingOptions { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GlyphRenderingOptionsDWrite) GlyphRenderingOptionsDWrite(IDWriteRenderingParams *aParams) : mParams(aParams)
--- a/gfx/2d/ScaledFontWin.cpp +++ b/gfx/2d/ScaledFontWin.cpp @@ -1,100 +1,34 @@ /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "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 { ScaledFontWin::ScaledFontWin(LOGFONT* aFont, Float aSize) : ScaledFontBase(aSize) , mLogFont(*aFont) { } -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() { if (!mTypeface) { mTypeface = SkCreateTypefaceFromLOGFONT(mLogFont); } return mTypeface; } #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 } }
--- a/gfx/2d/ScaledFontWin.h +++ b/gfx/2d/ScaledFontWin.h @@ -2,39 +2,31 @@ * 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_SCALEDFONTWIN_H_ #define MOZILLA_GFX_SCALEDFONTWIN_H_ #include "ScaledFontBase.h" +#include <windows.h> namespace mozilla { namespace gfx { class ScaledFontWin : public ScaledFontBase { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontWin) 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; #endif LOGFONT mLogFont; }; }
--- a/gfx/2d/moz.build +++ b/gfx/2d/moz.build @@ -17,36 +17,32 @@ EXPORTS.mozilla.gfx += [ 'BasePoint4D.h', 'BaseRect.h', 'BaseSize.h', 'Blur.h', 'BorrowedContext.h', 'Coord.h', 'CriticalSection.h', 'DataSurfaceHelpers.h', - 'DrawEventRecorder.h', 'DrawTargetTiled.h', 'Filters.h', 'Helpers.h', 'HelpersCairo.h', 'IterableArena.h', 'JobScheduler.h', 'JobScheduler_posix.h', 'JobScheduler_win32.h', 'Logging.h', 'Matrix.h', 'MatrixFwd.h', 'NumericTools.h', 'PathHelpers.h', 'PatternHelpers.h', 'Point.h', - 'Preferences.h', 'Quaternion.h', - 'RecordedEvent.h', - 'RecordingTypes.h', 'Rect.h', 'Scale.h', 'ScaleFactor.h', 'ScaleFactors2D.h', 'SourceSurfaceCairo.h', 'SourceSurfaceRawData.h', 'StackArray.h', 'Tools.h', @@ -66,18 +62,16 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('coc ] elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': SOURCES += [ 'DrawTargetD2D.cpp', 'DrawTargetD2D1.cpp', 'ExtendInputEffectD2D1.cpp', 'FilterNodeD2D1.cpp', 'JobScheduler_win32.cpp', - 'NativeFontResourceDWrite.cpp', - 'NativeFontResourceGDI.cpp', 'PathD2D.cpp', 'RadialGradientEffectD2D1.cpp', 'ScaledFontDWrite.cpp', 'ScaledFontWin.cpp', 'SourceSurfaceD2D.cpp', 'SourceSurfaceD2D1.cpp', 'SourceSurfaceD2DTarget.cpp', ] @@ -149,24 +143,21 @@ UNIFIED_SOURCES += [ 'FilterProcessingScalar.cpp', 'ImageScaling.cpp', 'JobScheduler.cpp', 'Matrix.cpp', 'Path.cpp', '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', ] if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': EXPORTS.mozilla.gfx += [ 'QuartzSupport.h', ] @@ -190,8 +181,15 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('and DEFINES['MOZ_ENABLE_FREETYPE'] = True CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] 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']
deleted file mode 100644 --- a/gfx/2d/u16string.h +++ /dev/null @@ -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
--- a/gfx/gl/moz.build +++ b/gfx/gl/moz.build @@ -165,10 +165,13 @@ if CONFIG['MOZ_D3DCOMPILER_XP_DLL']: CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] CXXFLAGS += CONFIG['TK_CFLAGS'] CFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] CFLAGS += CONFIG['TK_CFLAGS'] LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES'] +if CONFIG['OS_ARCH'] == 'WINNT': + del DEFINES['UNICODE'] + if CONFIG['CLANG_CXX']: CXXFLAGS += ['-Wshadow']
--- a/gfx/skia/generate_mozbuild.py +++ b/gfx/skia/generate_mozbuild.py @@ -64,20 +64,16 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in { 'android', 'cocoa', 'uikit', 'gonk', 'qt', } 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']: # MSVC doesn't need special compiler flags, but Skia needs to be told that these files should # be built with the required SSE level or it will simply compile in stubs and cause runtime crashes SOURCES['skia/src/opts/SkBitmapFilter_opts_SSE2.cpp'].flags += ['/arch:SSE2 -DSK_CPU_SSE_LEVEL=20'] SOURCES['skia/src/opts/SkBitmapProcState_opts_SSE2.cpp'].flags += ['/arch:SSE2 -DSK_CPU_SSE_LEVEL=20'] SOURCES['skia/src/opts/SkBitmapProcState_opts_SSSE3.cpp'].flags += ['/arch:SSE2 -DSK_CPU_SSE_LEVEL=31']
--- a/gfx/skia/moz.build +++ b/gfx/skia/moz.build @@ -675,20 +675,16 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in { 'android', 'cocoa', 'uikit', 'gonk', 'qt', } 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']: # MSVC doesn't need special compiler flags, but Skia needs to be told that these files should # be built with the required SSE level or it will simply compile in stubs and cause runtime crashes SOURCES['skia/src/opts/SkBitmapFilter_opts_SSE2.cpp'].flags += ['/arch:SSE2 -DSK_CPU_SSE_LEVEL=20'] SOURCES['skia/src/opts/SkBitmapProcState_opts_SSE2.cpp'].flags += ['/arch:SSE2 -DSK_CPU_SSE_LEVEL=20'] SOURCES['skia/src/opts/SkBitmapProcState_opts_SSSE3.cpp'].flags += ['/arch:SSE2 -DSK_CPU_SSE_LEVEL=31']
--- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -309,20 +309,40 @@ nsDeviceContext::IsPrinterSurface() return mPrintingSurface != nullptr; } void 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 { // A value of -1 means use the maximum of 96 and the system DPI. // A value of 0 means use the system DPI. A positive value is used as the DPI. // This sets the physical size of a device pixel and thus controls the // interpretation of physical units. int32_t prefDPI = Preferences::GetInt("layout.css.dpi", -1); @@ -395,22 +415,16 @@ nsDeviceContext::CreateRenderingContext( // This can legitimately happen - CreateDrawTargetForSurface will fail // to create a draw target if the size is too large, for instance. if (!dt) { gfxCriticalNote << "Failed to create draw target in device context sized " << mWidth << "x" << mHeight << " and pointers " << hexa(mPrintingSurface) << " and " << hexa(printingSurface); 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 dt->AddUserData(&sDisablePixelSnapping, (void*)0x1, nullptr); RefPtr<gfxContext> pContext = new gfxContext(dt); gfxMatrix transform; @@ -507,26 +521,28 @@ nsDeviceContext::InitForPrinting(nsIDevi return NS_ERROR_FAILURE; } return NS_OK; } 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; } nsresult nsDeviceContext::EndDocument(void) { @@ -677,33 +693,62 @@ nsDeviceContext::CalcPrintingSize() if (!mPrintingSurface) { return (mWidth > 0 && mHeight > 0); } bool inPoints = true; 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; HDC dc = reinterpret_cast<gfxWindowsSurface*>(mPrintingSurface.get())->GetDC(); if (!dc) dc = GetDC((HWND)mWidget->GetNativeData(NS_NATIVE_WIDGET)); size.width = NSFloatPixelsToAppUnits(::GetDeviceCaps(dc, HORZRES)/mPrintingScale, AppUnitsPerDevPixel()); size.height = NSFloatPixelsToAppUnits(::GetDeviceCaps(dc, VERTRES)/mPrintingScale, AppUnitsPerDevPixel()); mDepth = (uint32_t)::GetDeviceCaps(dc, BITSPIXEL); if (dc != reinterpret_cast<gfxWindowsSurface*>(mPrintingSurface.get())->GetDC()) ReleaseDC((HWND)mWidget->GetNativeData(NS_NATIVE_WIDGET), dc); 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) { // For printing, CSS inches and physical inches are identical // so it doesn't matter which we use here mWidth = NSToCoordRound(float(size.width) * AppUnitsPerPhysicalInch() / 72); mHeight = NSToCoordRound(float(size.height) * AppUnitsPerPhysicalInch() / 72); } else {
--- a/gfx/src/nsDeviceContext.h +++ b/gfx/src/nsDeviceContext.h @@ -177,26 +177,26 @@ public: nsresult GetClientRect(nsRect& aRect); /** * Inform the output device that output of a document is beginning * Used for print related device contexts. Must be matched 1:1 with * 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) * * @return error status */ nsresult BeginDocument(const nsAString& aTitle, - const nsAString& aPrintToFileName, + char16_t* aPrintToFileName, int32_t aStartPage, int32_t aEndPage); /** * Inform the output device that output of a document is ending. * Used for print related device contexts. Must be matched 1:1 with * BeginDocument() * @return error status
--- a/gfx/thebes/gfxContext.cpp +++ b/gfx/thebes/gfxContext.cpp @@ -207,17 +207,16 @@ already_AddRefed<Path> gfxContext::GetPa EnsurePath(); RefPtr<Path> path(mPath); return path.forget(); } 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; mPathIsRect = false; mTransformChanged = false; } gfxPoint
--- a/gfx/thebes/gfxDWriteCommon.cpp +++ b/gfx/thebes/gfxDWriteCommon.cpp @@ -1,177 +1,71 @@ /* -*- 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/. */ #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, 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; + *fontFileStream = + new gfxDWriteFontFileStream( + static_cast<const ffReferenceKey*>(fontFileReferenceKey)->mArray); + + if (!*fontFileStream) { + return E_OUTOFMEMORY; } + (*fontFileStream)->AddRef(); + return S_OK; +} - found->second->AddRef(); - *fontFileStream = found->second; +gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData) +{ + mData.SwapElements(*aData); +} + +gfxDWriteFontFileStream::~gfxDWriteFontFileStream() +{ +} + +HRESULT STDMETHODCALLTYPE +gfxDWriteFontFileStream::GetFileSize(UINT64 *fileSize) +{ + *fileSize = mData.Length(); return S_OK; } -/* static */ -HRESULT -gfxDWriteFontFileLoader::CreateCustomFontFile(FallibleTArray<uint8_t>& aFontData, - IDWriteFontFile** aFontFile, - IDWriteFontFileStream** aFontFileStream) +HRESULT STDMETHODCALLTYPE +gfxDWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime) { - MOZ_ASSERT(aFontFile); - MOZ_ASSERT(aFontFileStream); - - IDWriteFactory *factory = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory(); + return E_NOTIMPL; +} - uint64_t fontFileKey = sNextFontFileKey++; - RefPtr<IDWriteFontFileStream> ffsRef = new gfxDWriteFontFileStream(&aFontData, fontFileKey); - sFontFileStreams[fontFileKey] = ffsRef; +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; +} - 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; +void STDMETHODCALLTYPE +gfxDWriteFontFileStream::ReleaseFileFragment(void *fragmentContext) +{ }
--- a/gfx/thebes/gfxDWriteCommon.h +++ b/gfx/thebes/gfxDWriteCommon.h @@ -108,47 +108,99 @@ public: IFACEMETHOD_(ULONG, Release)() { return 1; } // 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, UINT32 fontFileReferenceKeySize, OUT IDWriteFontFileStream** fontFileStream); /** * 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() { if (!mInstance) { mInstance = new gfxDWriteFontFileLoader(); gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()-> RegisterFontFileLoader(mInstance); } 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 */
--- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -784,36 +784,58 @@ gfxDWriteFontList::MakePlatformFont(cons rv = gfxFontUtils::RenameFont(uniqueName, aFontData, aLength, &newFontData); free((void*)aFontData); if (NS_FAILED(rv)) { 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."); return nullptr; } BOOL isSupported; DWRITE_FONT_FILE_TYPE fileType; UINT32 numFaces; gfxDWriteFontEntry *entry = new gfxDWriteFontEntry(uniqueName, fontFile, - fontFileStream, aWeight, aStretch, aStyle); fontFile->Analyze(&isSupported, &fileType, &entry->mFaceType, &numFaces); if (!isSupported || numFaces > 1) { // We don't know how to deal with 0 faces either. delete entry; @@ -833,19 +855,19 @@ nsresult gfxDWriteFontList::InitFontList() { LARGE_INTEGER frequency; // ticks per second LARGE_INTEGER t1, t2, t3, t4, t5; // ticks double elapsedTime, upTime; 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); QueryPerformanceCounter(&t1); // start HRESULT hr; mGDIFontTableAccess = Preferences::GetBool("gfx.font_rendering.directwrite.use_gdi_table_loading",
--- a/gfx/thebes/gfxDWriteFontList.h +++ b/gfx/thebes/gfxDWriteFontList.h @@ -121,29 +121,27 @@ public: mIsCJK = UNINITIALIZED_VALUE; } /** * Constructs a font entry using a font file. * * \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; mStyle = aStyle; mIsDataUserFont = true; mIsCJK = UNINITIALIZED_VALUE; } @@ -183,20 +181,16 @@ protected: /** * A fontentry only needs to have either of these. If it has both only * the IDWriteFont will be used. */ 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; DWRITE_FONT_FACE_TYPE mFaceType; int8_t mIsCJK; bool mForceGDIClassic;
--- a/gfx/thebes/gfxDWriteFonts.cpp +++ b/gfx/thebes/gfxDWriteFonts.cpp @@ -227,17 +227,17 @@ gfxDWriteFont::ComputeMetrics(AntialiasO } } mMetrics->internalLeading = std::max(mMetrics->maxHeight - mMetrics->emHeight, 0.0); mMetrics->externalLeading = ceil(fontMetrics.lineGap * mFUnitsConvFactor); 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 { mSpaceGlyph = glyph; mMetrics->spaceWidth = MeasureGlyphWidth(glyph); } // try to get aveCharWidth from the OS/2 table, fall back to measuring 'x' @@ -257,27 +257,27 @@ gfxDWriteFont::ComputeMetrics(AntialiasO mMetrics->aveCharWidth = int16_t(os2->xAvgCharWidth) * mFUnitsConvFactor; } } } 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) { // Let's just assume the X is square. mMetrics->aveCharWidth = fontMetrics.xHeight * mFUnitsConvFactor; } } 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) { mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth; } mMetrics->underlineOffset = fontMetrics.underlinePosition * mFUnitsConvFactor;
--- a/gfx/thebes/gfxGDIFontList.cpp +++ b/gfx/thebes/gfxGDIFontList.cpp @@ -1112,17 +1112,17 @@ gfxGDIFontList::ActivateBundledFonts() nsCOMPtr<nsISupports> entry; if (NS_FAILED(e->GetNext(getter_AddRefs(entry)))) { break; } nsCOMPtr<nsIFile> file = do_QueryInterface(entry); 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); } } #endif
--- a/gfx/thebes/gfxGradientCache.cpp +++ b/gfx/thebes/gfxGradientCache.cpp @@ -192,37 +192,33 @@ gfxGradientCache::GetGradientStops(const } else { return cached->mStops; } } 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); if (!gs) { return nullptr; } GradientCacheData *cached = new GradientCacheData(gs, GradientCacheKey(aStops, aExtend, aDT->GetBackendType())); if (!gGradientCache->RegisterEntry(cached)) { delete cached; } } - return gs.forget(); + return gs; } void gfxGradientCache::PurgeAllCaches() { if (gGradientCache) { gGradientCache->AgeAllGenerations(); }
--- a/gfx/thebes/gfxGradientCache.h +++ b/gfx/thebes/gfxGradientCache.h @@ -16,17 +16,17 @@ namespace gfx { class gfxGradientCache { public: static gfx::GradientStops* GetGradientStops(const gfx::DrawTarget *aDT, 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); static void PurgeAllCaches(); static void Shutdown(); };
--- a/gfx/thebes/gfxPrefs.cpp +++ b/gfx/thebes/gfxPrefs.cpp @@ -2,17 +2,17 @@ * 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 "gfxPrefs.h" #include "mozilla/Preferences.h" #include "MainThreadUtils.h" -#include "mozilla/gfx/Preferences.h" +#include "mozilla/gfx/Logging.h" using namespace mozilla; gfxPrefs* gfxPrefs::sInstance = nullptr; bool gfxPrefs::sInstanceHasBeenDestroyed = false; class PreferenceAccessImpl : public mozilla::gfx::PreferenceAccess {
--- a/gfx/thebes/gfxWindowsSurface.cpp +++ b/gfx/thebes/gfxWindowsSurface.cpp @@ -203,20 +203,16 @@ gfxWindowsSurface::GetAsImageSurface() } nsresult gfxWindowsSurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName) { #ifdef NS_PRINTING #define DOC_TITLE_LENGTH (MAX_PATH-1) - if (!mForPrinting) { - return NS_OK; - } - DOCINFOW docinfo; nsString titleStr(aTitle); if (titleStr.Length() > DOC_TITLE_LENGTH) { titleStr.SetLength(DOC_TITLE_LENGTH-3); titleStr.AppendLiteral("..."); } @@ -234,73 +230,58 @@ gfxWindowsSurface::BeginPrinting(const n return NS_ERROR_FAILURE; #endif } nsresult gfxWindowsSurface::EndPrinting() { #ifdef NS_PRINTING - if (!mForPrinting) { - return NS_OK; - } - int result = ::EndDoc(mDC); if (result <= 0) return NS_ERROR_FAILURE; return NS_OK; #else return NS_ERROR_FAILURE; #endif } nsresult gfxWindowsSurface::AbortPrinting() { #ifdef NS_PRINTING - if (!mForPrinting) { - return NS_OK; - } - int result = ::AbortDoc(mDC); if (result <= 0) return NS_ERROR_FAILURE; return NS_OK; #else return NS_ERROR_FAILURE; #endif } nsresult gfxWindowsSurface::BeginPage() { #ifdef NS_PRINTING - if (!mForPrinting) { - return NS_OK; - } - int result = ::StartPage(mDC); if (result <= 0) return NS_ERROR_FAILURE; return NS_OK; #else return NS_ERROR_FAILURE; #endif } 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; return NS_OK; #else return NS_ERROR_FAILURE; #endif }
--- a/gfx/thebes/moz.build +++ b/gfx/thebes/moz.build @@ -302,8 +302,11 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr DEFINES['MOZ_USING_ANDROID_JAVA_WIDGETS'] = True if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'qt'): CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS'] LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES'] DEFINES['GRAPHITE2_STATIC'] = True + +if CONFIG['OS_ARCH'] == 'WINNT': + del DEFINES['UNICODE']
deleted file mode 100644 --- a/layout/printing/PrintTranslator.cpp +++ /dev/null @@ -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 \ No newline at end of file
deleted file mode 100644 --- a/layout/printing/PrintTranslator.h +++ /dev/null @@ -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
deleted file mode 100644 --- a/layout/printing/ipc/PRemotePrintJob.ipdl +++ /dev/null @@ -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
deleted file mode 100644 --- a/layout/printing/ipc/RemotePrintJobChild.cpp +++ /dev/null @@ -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
deleted file mode 100644 --- a/layout/printing/ipc/RemotePrintJobChild.h +++ /dev/null @@ -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
deleted file mode 100644 --- a/layout/printing/ipc/RemotePrintJobParent.cpp +++ /dev/null @@ -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 - -
deleted file mode 100644 --- a/layout/printing/ipc/RemotePrintJobParent.h +++ /dev/null @@ -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
--- a/layout/printing/moz.build +++ b/layout/printing/moz.build @@ -5,39 +5,26 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. XPIDL_SOURCES += [ 'nsIPrintProgress.idl', 'nsIPrintProgressParams.idl', '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']
--- a/layout/printing/nsPagePrintTimer.cpp +++ b/layout/printing/nsPagePrintTimer.cpp @@ -1,16 +1,14 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsPagePrintTimer.h" - -#include "mozilla/unused.h" #include "nsIContentViewer.h" #include "nsIServiceManager.h" #include "nsPrintEngine.h" NS_IMPL_ISUPPORTS_INHERITED(nsPagePrintTimer, nsRunnable, nsITimerCallback) nsPagePrintTimer::~nsPagePrintTimer() { @@ -115,87 +113,52 @@ NS_IMETHODIMP nsPagePrintTimer::Notify(nsITimer *timer) { // When finished there may be still pending notifications, which we can just // ignore. if (mDone) { 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 { // Start the watch dog if we're waiting for preprint to ensure that if any // mozPrintCallbacks take to long we error out. StartWatchDogTimer(); } } 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); } void nsPagePrintTimer::Stop() {
--- a/layout/printing/nsPagePrintTimer.h +++ b/layout/printing/nsPagePrintTimer.h @@ -42,32 +42,28 @@ public: NS_DECL_NSITIMERCALLBACK nsresult Start(nsPrintObject* aPO); NS_IMETHOD Run() override; void Stop(); - void WaitForRemotePrint(); - void RemotePrintFinished(); - private: ~nsPagePrintTimer(); nsresult StartTimer(bool aUseDelay); nsresult StartWatchDogTimer(); void StopWatchDogTimer(); void Fail(); nsPrintEngine* mPrintEngine; nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint; nsCOMPtr<nsITimer> mTimer; nsCOMPtr<nsITimer> mWatchDogTimer; - nsCOMPtr<nsITimer> mWaitingForRemotePrint; uint32_t mDelay; uint32_t mFiringCount; nsPrintObject * mPrintObj; uint32_t mWatchDogCount; bool mDone; static const uint32_t WATCH_DOG_INTERVAL = 1000; static const uint32_t WATCH_DOG_MAX_COUNT = 10;
--- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -70,34 +70,31 @@ static const char kPrintingPromptService // FrameSet #include "nsIDocument.h" // Focus #include "nsISelectionController.h" // Misc -#include "mozilla/gfx/DrawEventRecorder.h" -#include "mozilla/layout/RemotePrintJobChild.h" #include "nsISupportsUtils.h" #include "nsIScriptContext.h" #include "nsIDOMDocument.h" #include "nsISelectionListener.h" #include "nsISelectionPrivate.h" #include "nsIDOMRange.h" #include "nsContentCID.h" #include "nsLayoutCID.h" #include "nsContentUtils.h" #include "nsIPresShell.h" #include "nsLayoutUtils.h" #include "mozilla/Preferences.h" #include "nsWidgetsCID.h" #include "nsIDeviceContextSpec.h" -#include "nsDeviceContextSpecProxy.h" #include "nsViewManager.h" #include "nsView.h" #include "nsRenderingContext.h" #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsIContentViewerEdit.h" #include "nsIContentViewerFile.h" @@ -566,23 +563,19 @@ nsPrintEngine::DoCommonPrint(bool } } else { mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); } // Now determine how to set up the Frame print UI 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) { #ifdef DEBUG mPrt->mDebugFilePtr = mDebugFile; #endif scriptSuppressor.Suppress(); @@ -1680,25 +1673,24 @@ nsPrintEngine::SetupToPrintContent() PR_PL(("--- Printing %d pages\n", mPrt->mNumPrintablePages)); DUMP_DOC_TREELAYOUT; // Print listener setup... if (mPrt != nullptr) { 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; nsAutoString docURLStr; GetDisplayTitleAndURL(mPrt->mPrintObject, docTitleStr, docURLStr, eDocTitleDefURLDoc); int32_t startPage = 1; int32_t endPage = mPrt->mNumPrintablePages; @@ -1714,18 +1706,17 @@ nsPrintEngine::SetupToPrintContent() } rv = NS_OK; // BeginDocument may pass back a FAILURE code // i.e. On Windows, if you are printing to a file and hit "Cancel" // 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) { // Copy docTitleStr and docURLStr to the pageSequenceFrame, to be displayed // in the header nsIPageSequenceFrame *seqFrame = mPrt->mPrintObject->mPresShell->GetPageSequenceFrame(); if (seqFrame) { seqFrame->StartPrint(mPrt->mPrintObject->mPresContext, @@ -3484,27 +3475,16 @@ nsPrintEngine::StartPagePrintTimer(nsPri // Get the delay time in between the printing of each page // this gives the user more time to press cancel int32_t printPageDelay = 50; mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); 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); } /*=============== nsIObserver Interface ======================*/ NS_IMETHODIMP nsPrintEngine::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData)
--- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1006,23 +1006,16 @@ pref("print.print_unwriteable_margin_bot // unwriteable area to the margin. // This is used by both Printing and Print Preview // Units are in 1/100ths of an inch. pref("print.print_edge_top", 0); 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. pref("extensions.spellcheck.inline.max-misspellings", 500); // Prefs used by libeditor. Prefs specific to seamonkey composer // belong in comm-central/editor/ui/composer.js
--- a/widget/android/nsDeviceContextAndroid.cpp +++ b/widget/android/nsDeviceContextAndroid.cpp @@ -47,17 +47,17 @@ nsDeviceContextSpecAndroid::Init(nsIWidg bool aIsPrintPreview) { mPrintSettings = aPS; return NS_OK; } NS_IMETHODIMP nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle, - const nsAString& aPrintToFileName, + char16_t* aPrintToFileName, int32_t aStartPage, int32_t aEndPage) { return NS_OK; } NS_IMETHODIMP nsDeviceContextSpecAndroid::EndDocument()
--- a/widget/android/nsDeviceContextAndroid.h +++ b/widget/android/nsDeviceContextAndroid.h @@ -14,17 +14,17 @@ public: NS_DECL_ISUPPORTS NS_IMETHOD GetSurfaceForPrinter(gfxASurface** surface) override; NS_IMETHOD Init(nsIWidget* aWidget, 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; NS_IMETHOD BeginPage() override { return NS_OK; } NS_IMETHOD EndPage() override { return NS_OK; } private: nsCOMPtr<nsIPrintSettings> mPrintSettings;
--- a/widget/cocoa/nsDeviceContextSpecX.h +++ b/widget/cocoa/nsDeviceContextSpecX.h @@ -15,17 +15,17 @@ class nsDeviceContextSpecX : public nsID public: NS_DECL_ISUPPORTS nsDeviceContextSpecX(); 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; NS_IMETHOD BeginPage() override; NS_IMETHOD EndPage() override; void GetPaperRect(double* aTop, double* aLeft, double* aBottom, double* aRight);
--- a/widget/cocoa/nsDeviceContextSpecX.mm +++ b/widget/cocoa/nsDeviceContextSpecX.mm @@ -54,17 +54,17 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init mPrintSettings = settings->GetPMPrintSettings(); return NS_OK; NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle, - const nsAString& aPrintToFileName, + char16_t* aPrintToFileName, int32_t aStartPage, int32_t aEndPage) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; if (!aTitle.IsEmpty()) { CFStringRef cfString = ::CFStringCreateWithCharacters(NULL, reinterpret_cast<const UniChar*>(aTitle.BeginReading()),
--- a/widget/gtk/nsDeviceContextSpecG.cpp +++ b/widget/gtk/nsDeviceContextSpecG.cpp @@ -295,20 +295,18 @@ void nsDeviceContextSpecGTK::StartPrintJ void nsDeviceContextSpecGTK::EnumeratePrinters() { gtk_enumerate_printers(&nsDeviceContextSpecGTK::PrinterEnumerator, this, 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); return NS_OK; } NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument() {
--- a/widget/gtk/nsDeviceContextSpecG.h +++ b/widget/gtk/nsDeviceContextSpecG.h @@ -29,18 +29,17 @@ public: nsDeviceContextSpecGTK(); NS_DECL_ISUPPORTS NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface) override; 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; } NS_IMETHOD EndPage() override { return NS_OK; } protected: virtual ~nsDeviceContextSpecGTK(); nsCOMPtr<nsPrintSettingsGTK> mPrintSettings;
--- a/widget/moz.build +++ b/widget/moz.build @@ -90,17 +90,16 @@ XPIDL_MODULE = 'widget' EXPORTS += [ 'ContentHelper.h', 'GfxDriverInfo.h', 'GfxInfoBase.h', 'GfxInfoCollector.h', 'InputData.h', 'nsBaseScreen.h', 'nsBaseWidget.h', - 'nsDeviceContextSpecProxy.h', 'nsIDeviceContextSpec.h', 'nsIPluginWidget.h', 'nsIRollupListener.h', 'nsIWidget.h', 'nsIWidgetListener.h', 'nsWidgetInitData.h', 'nsWidgetsCID.h', 'PluginWidgetProxy.h', @@ -144,17 +143,16 @@ UNIFIED_SOURCES += [ 'InputData.cpp', 'nsBaseAppShell.cpp', 'nsBaseDragService.cpp', 'nsBaseScreen.cpp', 'nsClipboardHelper.cpp', 'nsClipboardProxy.cpp', 'nsColorPickerProxy.cpp', 'nsContentProcessWidgetFactory.cpp', - 'nsDeviceContextSpecProxy.cpp', 'nsDragServiceProxy.cpp', 'nsFilePickerProxy.cpp', 'nsHTMLFormatConverter.cpp', 'nsIdleService.cpp', 'nsIWidgetListener.cpp', 'nsPrimitiveHelpers.cpp', 'nsPrintSession.cpp', 'nsPrintSettingsImpl.cpp',
deleted file mode 100644 --- a/widget/nsDeviceContextSpecProxy.cpp +++ /dev/null @@ -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; -}
deleted file mode 100644 --- a/widget/nsDeviceContextSpecProxy.h +++ /dev/null @@ -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
--- a/widget/nsIDeviceContextSpec.h +++ b/widget/nsIDeviceContextSpec.h @@ -7,25 +7,19 @@ #define nsIDeviceContextSpec_h___ #include "nsISupports.h" 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 { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_SPEC_IID) /** * Initialize the device context spec. @@ -35,49 +29,21 @@ public: * @return NS_OK or a suitable error code. */ NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPrintSettings, bool aIsPrintPreview) = 0; 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; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContextSpec, NS_IDEVICE_CONTEXT_SPEC_IID) #endif
--- a/widget/nsIPrintSession.idl +++ b/widget/nsIPrintSession.idl @@ -7,34 +7,25 @@ /** * nsIPrintSession * * Stores data pertaining only to a single print job. This * 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. * * @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; };
--- a/widget/nsPrimitiveHelpers.cpp +++ b/widget/nsPrimitiveHelpers.cpp @@ -16,19 +16,16 @@ // // For now, this is the assumption that we are making: // - text/plain is always a char* // - anything else is a char16_t* // #include "nsPrimitiveHelpers.h" - -#include "mozilla/UniquePtr.h" -#include "nsAutoPtr.h" #include "nsCOMPtr.h" #include "nsXPCOM.h" #include "nsISupportsPrimitives.h" #include "nsITransferable.h" #include "nsIComponentManager.h" #include "nsLinebreakConverter.h" #include "nsReadableUtils.h" @@ -58,17 +55,17 @@ nsPrimitiveHelpers :: CreatePrimitiveFor NS_ADDREF(*aPrimitive = primitive); } } else { nsCOMPtr<nsISupportsString> primitive = 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; memcpy(buffer.get(), aDataBuff, aDataLen); buffer[aDataLen] = 0; const char16_t* start = reinterpret_cast<const char16_t*>(buffer.get()); // recall that length takes length as characters, not bytes primitive->SetData(Substring(start, start + (aDataLen + 1) / 2));
--- a/widget/nsPrintOptionsImpl.cpp +++ b/widget/nsPrintOptionsImpl.cpp @@ -1,21 +1,18 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/embedding/PPrinting.h" +#include "nsPrintingProxy.h" #include "nsPrintOptionsImpl.h" - -#include "mozilla/embedding/PPrinting.h" -#include "mozilla/layout/RemotePrintJobChild.h" -#include "nsPrintingProxy.h" #include "nsReadableUtils.h" #include "nsPrintSettingsImpl.h" -#include "nsIPrintSession.h" #include "nsIDOMWindow.h" #include "nsIServiceManager.h" #include "nsIDialogParamBlock.h" #include "nsXPCOM.h" #include "nsISupportsPrimitives.h" #include "nsIWindowWatcher.h" #include "nsISupportsArray.h" @@ -27,18 +24,16 @@ #include "nsAutoPtr.h" #include "mozilla/Preferences.h" #include "nsPrintfCString.h" #include "nsIWebBrowserPrint.h" using namespace mozilla; using namespace mozilla::embedding; -typedef mozilla::layout::RemotePrintJobChild RemotePrintJobChild; - NS_IMPL_ISUPPORTS(nsPrintOptions, nsIPrintOptions, nsIPrintSettingsService) // Pref Constants static const char kMarginTop[] = "print_margin_top"; static const char kMarginLeft[] = "print_margin_left"; static const char kMarginBottom[] = "print_margin_bottom"; static const char kMarginRight[] = "print_margin_right"; static const char kEdgeTop[] = "print_edge_top"; @@ -233,22 +228,16 @@ nsPrintOptions::SerializeToPrintData(nsI return NS_OK; } 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()); settings->SetEdgeTop(data.edgeTop()); settings->SetEdgeLeft(data.edgeLeft()); settings->SetEdgeBottom(data.edgeBottom()); settings->SetEdgeRight(data.edgeRight());
--- a/widget/nsPrintSession.cpp +++ b/widget/nsPrintSession.cpp @@ -1,19 +1,15 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsPrintSession.h" -#include "mozilla/layout/RemotePrintJobChild.h" - -typedef mozilla::layout::RemotePrintJobChild RemotePrintJobChild; - //***************************************************************************** //*** nsPrintSession //***************************************************************************** NS_IMPL_ISUPPORTS(nsPrintSession, nsIPrintSession, nsISupportsWeakReference) //----------------------------------------------------------------------------- nsPrintSession::nsPrintSession() @@ -25,24 +21,8 @@ nsPrintSession::~nsPrintSession() { } //----------------------------------------------------------------------------- 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; -}
--- a/widget/nsPrintSession.h +++ b/widget/nsPrintSession.h @@ -2,41 +2,29 @@ /* 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 nsPrintSession_h__ #define nsPrintSession_h__ #include "nsIPrintSession.h" - -#include "mozilla/RefPtr.h" #include "nsWeakReference.h" -namespace mozilla { -namespace layout { -class RemotePrintJobChild; -} -} - - //***************************************************************************** //*** nsPrintSession //***************************************************************************** class nsPrintSession : public nsIPrintSession, public nsSupportsWeakReference { virtual ~nsPrintSession(); public: NS_DECL_ISUPPORTS NS_DECL_NSIPRINTSESSION nsPrintSession(); virtual nsresult Init(); - -private: - RefPtr<mozilla::layout::RemotePrintJobChild> mRemotePrintJob; }; #endif // nsPrintSession_h__
--- a/widget/qt/nsDeviceContextSpecQt.cpp +++ b/widget/qt/nsDeviceContextSpecQt.cpp @@ -146,17 +146,17 @@ NS_IMETHODIMP nsDeviceContextSpecQt::Ini nsCOMPtr<nsPrintSettingsQt> printSettingsQt(do_QueryInterface(aPS)); if (!printSettingsQt) return NS_ERROR_NO_INTERFACE; return NS_OK; } NS_IMETHODIMP nsDeviceContextSpecQt::BeginDocument( const nsAString& aTitle, - const nsAString& aPrintToFileName, + char16_t* aPrintToFileName, int32_t aStartPage, int32_t aEndPage) { if (mToPrinter) { return NS_ERROR_NOT_IMPLEMENTED; } return NS_OK; }
--- a/widget/qt/nsDeviceContextSpecQt.h +++ b/widget/qt/nsDeviceContextSpecQt.h @@ -23,17 +23,17 @@ public: NS_DECL_ISUPPORTS NS_IMETHOD GetSurfaceForPrinter(gfxASurface** surface); NS_IMETHOD Init(nsIWidget* aWidget, 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(); NS_IMETHOD BeginPage() { return NS_OK; } NS_IMETHOD EndPage() { return NS_OK; } protected: virtual ~nsDeviceContextSpecQt();
--- a/widget/windows/nsDeviceContextSpecWin.cpp +++ b/widget/windows/nsDeviceContextSpecWin.cpp @@ -265,17 +265,16 @@ static void CleanAndCopyString(wchar_t*& wcscpy(aStr, aNewStr); } } NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface) { NS_ASSERTION(mDevMode, "DevMode can't be NULL here"); - *surface = nullptr; RefPtr<gfxASurface> newSurface; int16_t outputFormat = 0; if (mPrintSettings) { mPrintSettings->GetOutputFormat(&outputFormat); } if (outputFormat == nsIPrintSettings::kOutputFormatPDF) { @@ -311,34 +310,29 @@ NS_IMETHODIMP nsDeviceContextSpecWin::Ge gfxCriticalError(gfxCriticalError::DefaultOptions(false)) << "Failed to create device context in GetSurfaceForPrinter"; return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND; } // have this surface take over ownership of this DC 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; } //---------------------------------------------------------------------------------- void nsDeviceContextSpecWin::SetDeviceName(char16ptr_t aDeviceName) { CleanAndCopyString(mDeviceName, aDeviceName); }
--- a/widget/windows/nsDeviceContextSpecWin.h +++ b/widget/windows/nsDeviceContextSpecWin.h @@ -8,42 +8,37 @@ #include "nsCOMPtr.h" #include "nsIDeviceContextSpec.h" #include "nsIPrintOptions.h" // For nsIPrinterEnumerator #include "nsIPrintSettings.h" #include "nsISupportsPrimitives.h" #include <windows.h> #include "mozilla/Attributes.h" -#include "mozilla/RefPtr.h" class nsIWidget; class nsDeviceContextSpecWin : public nsIDeviceContextSpec { public: nsDeviceContextSpecWin(); NS_DECL_ISUPPORTS 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; } NS_IMETHOD BeginPage() { return NS_OK; } NS_IMETHOD EndPage() { return NS_OK; } 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; } // The GetDevMode will return a pointer to a DevMode // whether it is from the Global memory handle or just the DevMode // To get the DevMode from the Global memory Handle it must lock it // So this call must be paired with a call to UnlockGlobalHandle void GetDevMode(LPDEVMODEW &aDevMode); @@ -64,17 +59,16 @@ protected: virtual ~nsDeviceContextSpecWin(); wchar_t* mDriverName; wchar_t* mDeviceName; LPDEVMODEW mDevMode; nsCOMPtr<nsIPrintSettings> mPrintSettings; - RefPtr<gfxASurface> mPrintingSurface; }; //------------------------------------------------------------------------- // Printer Enumerator //------------------------------------------------------------------------- class nsPrinterEnumeratorWin final : public nsIPrinterEnumerator {