diff --git a/gfx/2d/DrawTargetRecording.cpp b/gfx/2d/DrawTargetRecording.cpp index 51460e5b79ea..01599eb4247d 100644 --- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -503,13 +503,25 @@ DrawTargetRecording::CreateSourceSurfaceFromData(unsigned char* aData, SurfaceFormat aFormat) const { RefPtr surf = DataSourceSurfaceRecording::Init( aData, aSize, aStride, aFormat, mRecorder); + mRecorder->RecordEvent(RecordedOptimizeSourceSurface(surf, this, surf)); return surf.forget(); } already_AddRefed DrawTargetRecording::OptimizeSourceSurface( SourceSurface* aSurface) const { - RefPtr surf(aSurface); - return surf.forget(); + if (aSurface->GetType() == SurfaceType::RECORDING) { + return do_AddRef(aSurface); + } + + EnsureSurfaceStoredRecording(mRecorder, aSurface, "OptimizeSourceSurface"); + + RefPtr retSurf = new SourceSurfaceRecording( + aSurface->GetSize(), aSurface->GetFormat(), mRecorder); + + mRecorder->RecordEvent( + RecordedOptimizeSourceSurface(aSurface, this, retSurf)); + + return retSurf.forget(); } already_AddRefed diff --git a/gfx/2d/RecordedEvent.h b/gfx/2d/RecordedEvent.h index a7a82dd62a83..e946cb453e35 100644 --- a/gfx/2d/RecordedEvent.h +++ b/gfx/2d/RecordedEvent.h @@ -27,7 +27,7 @@ const uint32_t kMagicInt = 0xc001feed; const uint16_t kMajorRevision = 10; // 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 = 1; struct ReferencePtr { ReferencePtr() : mLongPtr(0) {} @@ -319,6 +319,7 @@ class RecordedEvent { EXTERNALSURFACECREATION, FLUSH, DETACHALLSNAPSHOTS, + OPTIMIZESOURCESURFACE, LAST, }; diff --git a/gfx/2d/RecordedEventImpl.h b/gfx/2d/RecordedEventImpl.h index 9a7686394b42..4b5b35061fa3 100644 --- a/gfx/2d/RecordedEventImpl.h +++ b/gfx/2d/RecordedEventImpl.h @@ -911,6 +911,35 @@ class RecordedSourceSurfaceDestruction MOZ_IMPLICIT RecordedSourceSurfaceDestruction(S& aStream); }; +class RecordedOptimizeSourceSurface + : public RecordedEventDerived { + public: + RecordedOptimizeSourceSurface(ReferencePtr aSurface, ReferencePtr aDT, + ReferencePtr aOptimizedSurface) + : RecordedEventDerived(OPTIMIZESOURCESURFACE), + mSurface(aSurface), + mDT(aDT), + mOptimizedSurface(aOptimizedSurface) {} + + bool PlayEvent(Translator* aTranslator) const override; + + template + void Record(S& aStream) const; + void OutputSimpleEventInfo(std::stringstream& aStringStream) const override; + + std::string GetName() const override { return "OptimizeSourceSurface"; } + + private: + friend class RecordedEvent; + + ReferencePtr mSurface; + ReferencePtr mDT; + ReferencePtr mOptimizedSurface; + + template + MOZ_IMPLICIT RecordedOptimizeSourceSurface(S& aStream); +}; + class RecordedExternalSurfaceCreation : public RecordedEventDerived { public: @@ -2869,6 +2898,35 @@ inline void RecordedSourceSurfaceDestruction::OutputSimpleEventInfo( aStringStream << "[" << mRefPtr << "] SourceSurface Destroyed"; } +inline bool RecordedOptimizeSourceSurface::PlayEvent( + Translator* aTranslator) const { + RefPtr src = + aTranslator->LookupDrawTarget(mDT)->OptimizeSourceSurface( + aTranslator->LookupSourceSurface(mSurface)); + aTranslator->AddSourceSurface(mOptimizedSurface, src); + return true; +} + +template +void RecordedOptimizeSourceSurface::Record(S& aStream) const { + WriteElement(aStream, mSurface); + WriteElement(aStream, mDT); + WriteElement(aStream, mOptimizedSurface); +} + +template +RecordedOptimizeSourceSurface::RecordedOptimizeSourceSurface(S& aStream) + : RecordedEventDerived(OPTIMIZESOURCESURFACE) { + ReadElement(aStream, mSurface); + ReadElement(aStream, mDT); + ReadElement(aStream, mOptimizedSurface); +} + +inline void RecordedOptimizeSourceSurface::OutputSimpleEventInfo( + std::stringstream& aStringStream) const { + aStringStream << "[" << mSurface << "] Surface Optimized (DT: " << mDT << ")"; +} + inline bool RecordedExternalSurfaceCreation::PlayEvent( Translator* aTranslator) const { RefPtr surface = aTranslator->LookupExternalSurface(mKey); @@ -3574,7 +3632,8 @@ inline void RecordedFilterNodeSetInput::OutputSimpleEventInfo( f(INTOLUMINANCE, RecordedIntoLuminanceSource); \ f(EXTERNALSURFACECREATION, RecordedExternalSurfaceCreation); \ f(FLUSH, RecordedFlush); \ - f(DETACHALLSNAPSHOTS, RecordedDetachAllSnapshots); + f(DETACHALLSNAPSHOTS, RecordedDetachAllSnapshots); \ + f(OPTIMIZESOURCESURFACE, RecordedOptimizeSourceSurface); #define DO_WITH_EVENT_TYPE(_typeenum, _class) \ case _typeenum: { \