Bug 1875222 - Implement RecordedSetPermitSubpixelAA. r=aosmond

Certain users of DrawTargetRecording need accurate tracking of SetPermitSubpixelAA.
This ensures the values are properly tracked locally in DrawTargetRecording as well
as forwards any necessary changes to the remote end.

Differential Revision: https://phabricator.services.mozilla.com/D198919
This commit is contained in:
Lee Salzman 2024-01-18 17:16:08 +00:00
parent dd77d1380c
commit f4bc982d58
6 changed files with 89 additions and 0 deletions

View File

@ -4797,6 +4797,7 @@ void DrawTargetWebgl::PushLayerWithBlend(bool aOpaque, Float aOpacity,
mSkia->PushLayerWithBlend(aOpaque, aOpacity, aMask, aMaskTransform, aBounds,
aCopyBackground, aCompositionOp);
++mLayerDepth;
SetPermitSubpixelAA(mSkia->GetPermitSubpixelAA());
}
void DrawTargetWebgl::PopLayer() {
@ -4804,6 +4805,7 @@ void DrawTargetWebgl::PopLayer() {
MOZ_ASSERT(mLayerDepth > 0);
--mLayerDepth;
mSkia->PopLayer();
SetPermitSubpixelAA(mSkia->GetPermitSubpixelAA());
}
} // namespace mozilla::gfx

View File

@ -201,6 +201,7 @@ DrawTargetRecording::DrawTargetRecording(
this, aTextureId, aTextureOwnerId, mFinalDT->GetBackendType(), aSize,
mFinalDT->GetFormat()));
mFormat = mFinalDT->GetFormat();
DrawTarget::SetPermitSubpixelAA(IsOpaque(mFormat));
}
DrawTargetRecording::DrawTargetRecording(DrawEventRecorder* aRecorder,
@ -215,12 +216,14 @@ DrawTargetRecording::DrawTargetRecording(DrawEventRecorder* aRecorder,
RecordedDrawTargetCreation(this, mFinalDT->GetBackendType(), mRect,
mFinalDT->GetFormat(), aHasData, snapshot));
mFormat = mFinalDT->GetFormat();
DrawTarget::SetPermitSubpixelAA(IsOpaque(mFormat));
}
DrawTargetRecording::DrawTargetRecording(const DrawTargetRecording* aDT,
IntRect aRect, SurfaceFormat aFormat)
: mRecorder(aDT->mRecorder), mFinalDT(aDT->mFinalDT), mRect(aRect) {
mFormat = aFormat;
DrawTarget::SetPermitSubpixelAA(IsOpaque(mFormat));
}
DrawTargetRecording::~DrawTargetRecording() {
@ -587,6 +590,10 @@ void DrawTargetRecording::PushLayer(bool aOpaque, Float aOpacity,
mRecorder->RecordEvent(
this, RecordedPushLayer(aOpaque, aOpacity, aMask, aMaskTransform, aBounds,
aCopyBackground));
PushedLayer layer(GetPermitSubpixelAA());
mPushedLayers.push_back(layer);
DrawTarget::SetPermitSubpixelAA(aOpaque);
}
void DrawTargetRecording::PushLayerWithBlend(bool aOpaque, Float aOpacity,
@ -602,10 +609,18 @@ void DrawTargetRecording::PushLayerWithBlend(bool aOpaque, Float aOpacity,
mRecorder->RecordEvent(this, RecordedPushLayerWithBlend(
aOpaque, aOpacity, aMask, aMaskTransform,
aBounds, aCopyBackground, aCompositionOp));
PushedLayer layer(GetPermitSubpixelAA());
mPushedLayers.push_back(layer);
DrawTarget::SetPermitSubpixelAA(aOpaque);
}
void DrawTargetRecording::PopLayer() {
mRecorder->RecordEvent(this, RecordedPopLayer());
const PushedLayer& layer = mPushedLayers.back();
DrawTarget::SetPermitSubpixelAA(layer.mOldPermitSubpixelAA);
mPushedLayers.pop_back();
}
already_AddRefed<SourceSurface>
@ -776,6 +791,14 @@ void DrawTargetRecording::SetTransform(const Matrix& aTransform) {
mRecorder->RecordEvent(this, RecordedSetTransform(aTransform));
}
void DrawTargetRecording::SetPermitSubpixelAA(bool aPermitSubpixelAA) {
if (aPermitSubpixelAA == mPermitSubpixelAA) {
return;
}
DrawTarget::SetPermitSubpixelAA(aPermitSubpixelAA);
mRecorder->RecordEvent(this, RecordedSetPermitSubpixelAA(aPermitSubpixelAA));
}
already_AddRefed<PathRecording> DrawTargetRecording::EnsurePathStored(
const Path* aPath) {
RefPtr<PathRecording> pathRecording;

View File

@ -352,6 +352,8 @@ class DrawTargetRecording : public DrawTarget {
*/
virtual void SetTransform(const Matrix& aTransform) override;
virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override;
/* Tries to get a native surface for a DrawTarget, this may fail if the
* draw target cannot convert to this surface type.
*/
@ -386,6 +388,13 @@ class DrawTargetRecording : public DrawTarget {
RefPtr<DrawEventRecorderPrivate> mRecorder;
RefPtr<DrawTarget> mFinalDT;
IntRect mRect;
struct PushedLayer {
explicit PushedLayer(bool aOldPermitSubpixelAA)
: mOldPermitSubpixelAA(aOldPermitSubpixelAA) {}
bool mOldPermitSubpixelAA;
};
std::vector<PushedLayer> mPushedLayers;
};
} // namespace gfx

View File

@ -48,6 +48,8 @@ std::string RecordedEvent::GetEventName(EventType aType) {
return "ClearRect";
case COPYSURFACE:
return "CopySurface";
case SETPERMITSUBPIXELAA:
return "SetPermitSubpixelAA";
case SETTRANSFORM:
return "SetTransform";
case PUSHCLIP:

View File

@ -377,6 +377,7 @@ class RecordedEvent {
STROKECIRCLE,
CLEARRECT,
COPYSURFACE,
SETPERMITSUBPIXELAA,
SETTRANSFORM,
PUSHCLIP,
PUSHCLIPRECT,

View File

@ -773,6 +773,30 @@ class RecordedPopLayer : public RecordedEventDerived<RecordedPopLayer> {
MOZ_IMPLICIT RecordedPopLayer(S& aStream);
};
class RecordedSetPermitSubpixelAA
: public RecordedEventDerived<RecordedSetPermitSubpixelAA> {
public:
explicit RecordedSetPermitSubpixelAA(bool aPermitSubpixelAA)
: RecordedEventDerived(SETPERMITSUBPIXELAA),
mPermitSubpixelAA(aPermitSubpixelAA) {}
bool PlayEvent(Translator* aTranslator) const override;
template <class S>
void Record(S& aStream) const;
void OutputSimpleEventInfo(std::stringstream& aStringStream) const override;
std::string GetName() const override { return "SetPermitSubpixelAA"; }
private:
friend class RecordedEvent;
template <class S>
MOZ_IMPLICIT RecordedSetPermitSubpixelAA(S& aStream);
bool mPermitSubpixelAA = false;
};
class RecordedSetTransform : public RecordedEventDerived<RecordedSetTransform> {
public:
explicit RecordedSetTransform(const Matrix& aTransform)
@ -2985,6 +3009,33 @@ inline void RecordedPopLayer::OutputSimpleEventInfo(
aStringStream << "PopLayer";
}
inline bool RecordedSetPermitSubpixelAA::PlayEvent(
Translator* aTranslator) const {
DrawTarget* dt = aTranslator->GetCurrentDrawTarget();
if (!dt) {
return false;
}
dt->SetPermitSubpixelAA(mPermitSubpixelAA);
return true;
}
template <class S>
void RecordedSetPermitSubpixelAA::Record(S& aStream) const {
WriteElement(aStream, mPermitSubpixelAA);
}
template <class S>
RecordedSetPermitSubpixelAA::RecordedSetPermitSubpixelAA(S& aStream)
: RecordedEventDerived(SETPERMITSUBPIXELAA) {
ReadElement(aStream, mPermitSubpixelAA);
}
inline void RecordedSetPermitSubpixelAA::OutputSimpleEventInfo(
std::stringstream& aStringStream) const {
aStringStream << "SetPermitSubpixelAA (" << mPermitSubpixelAA << ")";
}
inline bool RecordedSetTransform::PlayEvent(Translator* aTranslator) const {
DrawTarget* dt = aTranslator->GetCurrentDrawTarget();
if (!dt) {
@ -4243,6 +4294,7 @@ inline void RecordedDestination::OutputSimpleEventInfo(
f(STROKECIRCLE, RecordedStrokeCircle); \
f(CLEARRECT, RecordedClearRect); \
f(COPYSURFACE, RecordedCopySurface); \
f(SETPERMITSUBPIXELAA, RecordedSetPermitSubpixelAA); \
f(SETTRANSFORM, RecordedSetTransform); \
f(PUSHCLIPRECT, RecordedPushClipRect); \
f(PUSHCLIP, RecordedPushClip); \