diff --git a/gfx/2d/DrawTargetRecording.cpp b/gfx/2d/DrawTargetRecording.cpp index aa19821f84cc..867a442e7049 100644 --- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -75,6 +75,31 @@ EnsureSurfaceStored(DrawEventRecorderPrivate *aRecorder, SourceSurface *aSurface 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 GetDataSurface() { return mFinalSurface->GetDataSurface(); } + + RefPtr mFinalSurface; + RefPtr mRecorder; +}; + class GradientStopsRecording : public GradientStops { public: diff --git a/gfx/2d/DrawTargetRecording.h b/gfx/2d/DrawTargetRecording.h index fc7215a67cc5..359d1f6bec8e 100644 --- a/gfx/2d/DrawTargetRecording.h +++ b/gfx/2d/DrawTargetRecording.h @@ -331,31 +331,6 @@ private: RefPtr mFinalDT; }; -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 GetDataSurface() { return mFinalSurface->GetDataSurface(); } - - RefPtr mFinalSurface; - RefPtr mRecorder; -}; - } // namespace gfx } // namespace mozilla diff --git a/gfx/2d/InlineTranslator.cpp b/gfx/2d/InlineTranslator.cpp deleted file mode 100644 index 715493b709c0..000000000000 --- a/gfx/2d/InlineTranslator.cpp +++ /dev/null @@ -1,99 +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 "InlineTranslator.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 gfx { - -InlineTranslator::InlineTranslator(DrawTarget* aDT, Matrix aMatrix) -{ - mBaseDT = aDT; - mBaseTransform = aMatrix; -} - -bool -InlineTranslator::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::LoadEventFromStream(aRecording, - static_cast(eventType))); - - // Make sure that the whole event was read from the stream successfully. - if (!aRecording.good() || !recordedEvent) { - return false; - } - - if (recordedEvent->GetType() == RecordedEvent::SETTRANSFORM) { - RecordedSetTransform* event = static_cast(recordedEvent.get()); - mBaseDT->SetTransform(event->mTransform * mBaseTransform); - } else { - if (!recordedEvent->PlayEvent(this)) { - return false; - } - } - - ReadElement(aRecording, eventType); - } - - return true; -} - -already_AddRefed -InlineTranslator::CreateDrawTarget(ReferencePtr aRefPtr, - const gfx::IntSize &aSize, - gfx::SurfaceFormat aFormat) -{ - RefPtr drawTarget = mBaseDT; - return drawTarget.forget(); -} - -FontType -InlineTranslator::GetDesiredFontType() -{ - switch (mBaseDT->GetBackendType()) { - case BackendType::DIRECT2D: - return FontType::DWRITE; - case BackendType::CAIRO: - return FontType::CAIRO; - case BackendType::SKIA: - return FontType::SKIA; - default: - return FontType::CAIRO; - } -} - -} // namespace gfx -} // namespace mozilla diff --git a/gfx/2d/InlineTranslator.h b/gfx/2d/InlineTranslator.h deleted file mode 100644 index 46f93c627753..000000000000 --- a/gfx/2d/InlineTranslator.h +++ /dev/null @@ -1,167 +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_InlineTranslator_h -#define mozilla_layout_InlineTranslator_h - -#include - -#include "mozilla/gfx/2D.h" -#include "mozilla/gfx/Filters.h" -#include "mozilla/gfx/RecordedEvent.h" -#include "nsRefPtrHashtable.h" - -namespace mozilla { -namespace gfx { - -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 InlineTranslator final : public Translator -{ -public: - explicit InlineTranslator(DrawTarget* aDT, Matrix aMatrix); - - bool TranslateRecording(std::istream& aRecording); - - DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final - { - return mBaseDT; - } - - 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 { } - - 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 { } - - 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 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 mBaseDT; - Matrix mBaseTransform; - - nsRefPtrHashtable, Path> mPaths; - nsRefPtrHashtable, SourceSurface> mSourceSurfaces; - nsRefPtrHashtable, FilterNode> mFilterNodes; - nsRefPtrHashtable, GradientStops> mGradientStops; - nsRefPtrHashtable, ScaledFont> mScaledFonts; - nsRefPtrHashtable mNativeFontResources; -}; - -} // namespace gfx -} // namespace mozilla - -#endif // mozilla_layout_InlineTranslator_h diff --git a/gfx/2d/RecordedEvent.h b/gfx/2d/RecordedEvent.h index e6958cc341eb..dcf4d9e36e02 100644 --- a/gfx/2d/RecordedEvent.h +++ b/gfx/2d/RecordedEvent.h @@ -698,12 +698,12 @@ public: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; virtual std::string GetName() const { return "SetTransform"; } - - Matrix mTransform; private: friend class RecordedEvent; MOZ_IMPLICIT RecordedSetTransform(std::istream &aStream); + + Matrix mTransform; }; class RecordedDrawSurface : public RecordedDrawingEvent { diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build index f4a3af716df5..8f7c18ade9b1 100644 --- a/gfx/2d/moz.build +++ b/gfx/2d/moz.build @@ -24,12 +24,10 @@ EXPORTS.mozilla.gfx += [ 'CriticalSection.h', 'DataSurfaceHelpers.h', 'DrawEventRecorder.h', - 'DrawTargetRecording.h', 'DrawTargetTiled.h', 'Filters.h', 'Helpers.h', 'HelpersCairo.h', - 'InlineTranslator.h', 'IterableArena.h', 'JobScheduler.h', 'JobScheduler_posix.h', @@ -181,7 +179,6 @@ UNIFIED_SOURCES += [ SOURCES += [ 'Factory.cpp', # Need to suppress warnings in Skia header files. - 'InlineTranslator.cpp', ] if CONFIG['CLANG_CXX']: diff --git a/gfx/layers/basic/BasicCanvasLayer.cpp b/gfx/layers/basic/BasicCanvasLayer.cpp index 0717600728ee..83c5c272e568 100644 --- a/gfx/layers/basic/BasicCanvasLayer.cpp +++ b/gfx/layers/basic/BasicCanvasLayer.cpp @@ -110,8 +110,8 @@ BasicCanvasLayer::Paint(DrawTarget* aDT, if (needsYFlip) { oldTM = aDT->GetTransform(); aDT->SetTransform(Matrix(oldTM). - PreTranslate(0.0f, mBounds.height). - PreScale(1.0f, -1.0f)); + PreTranslate(0.0f, mBounds.height). + PreScale(1.0f, -1.0f)); } FillRectWithMask(aDT, aDeviceOffset, diff --git a/gfx/layers/basic/BasicLayersImpl.cpp b/gfx/layers/basic/BasicLayersImpl.cpp index 86e16d18484d..c2262c512f55 100644 --- a/gfx/layers/basic/BasicLayersImpl.cpp +++ b/gfx/layers/basic/BasicLayersImpl.cpp @@ -12,8 +12,6 @@ #include "mozilla/layers/CompositorTypes.h" #include "mozilla/layers/ISurfaceAllocator.h" #include "AutoMaskData.h" -#include "mozilla/gfx/InlineTranslator.h" -#include "mozilla/gfx/DrawTargetRecording.h" namespace mozilla { namespace layers { @@ -124,10 +122,6 @@ FillRectWithMask(DrawTarget* aDT, const Matrix* aMaskTransform, const Matrix* aSurfaceTransform) { - MOZ_ASSERT((aMaskSource && aMaskTransform) || - (!aMaskSource && !aMaskTransform), - "Either both or neither must be specified"); - if (aMaskSource && aMaskTransform) { aDT->PushClipRect(aRect); Matrix oldTransform = aDT->GetTransform(); @@ -144,35 +138,6 @@ FillRectWithMask(DrawTarget* aDT, aDT->SetTransform(*aMaskTransform); aDT->MaskSurface(source, aMaskSource, Point(0, 0), aOptions); - - aDT->SetTransform(oldTransform); - aDT->PopClip(); - return; - } - - if (aSurface->GetType() == SurfaceType::RECORDING) { - MOZ_ASSERT(aOptions.mAlpha == 1.0 && - aOptions.mCompositionOp == CompositionOp::OP_OVER); - - aDT->PushClipRect(aRect); - Matrix oldTransform = aDT->GetTransform(); - - Matrix transform = oldTransform; - if (aSurfaceTransform) { - transform = (*aSurfaceTransform) * transform; - } - - InlineTranslator* translator = new InlineTranslator(aDT, transform); - SourceSurfaceRecording* ss = static_cast(aSurface); - DrawEventRecorderMemory* mr = static_cast(ss->mRecorder.get()); - - size_t size = mr->RecordingSize(); - char* buffer = new char[size]; - mr->CopyRecording(buffer, size); - std::istringstream recording(std::string(buffer, size)); - - translator->TranslateRecording(recording); - aDT->SetTransform(oldTransform); aDT->PopClip(); return; diff --git a/layout/generic/nsSimplePageSequenceFrame.cpp b/layout/generic/nsSimplePageSequenceFrame.cpp index 293b400d15f7..6898716aa9f8 100644 --- a/layout/generic/nsSimplePageSequenceFrame.cpp +++ b/layout/generic/nsSimplePageSequenceFrame.cpp @@ -22,7 +22,6 @@ #include "nsDisplayList.h" #include "nsHTMLCanvasFrame.h" #include "mozilla/dom/HTMLCanvasElement.h" -#include "mozilla/gfx/DrawEventRecorder.h" #include "nsICanvasRenderingContextInternal.h" #include "nsServiceManagerUtils.h" #include @@ -630,12 +629,8 @@ nsSimplePageSequenceFrame::PrePrintNextPage(nsITimerCallback* aCallback, bool* a HTMLCanvasElement* canvas = mCurrentCanvasList[i]; nsIntSize size = canvas->GetSize(); - RefPtr recorder = - new mozilla::gfx::DrawEventRecorderMemory(); RefPtr canvasTarget = drawTarget->CreateSimilarDrawTarget(size, drawTarget->GetFormat()); - canvasTarget = - mozilla::gfx::Factory::CreateRecordingDrawTarget(recorder, canvasTarget); if (!canvasTarget) { continue; }