Bug 1416864 - Synchronize how snapshots detach in DrawTargetD2D1. r=bas

This commit is contained in:
David Anderson 2017-11-21 10:52:38 -05:00
parent 5485f27c35
commit 4d9d8d5d59
4 changed files with 13 additions and 0 deletions

View File

@ -57,6 +57,7 @@ DrawTargetD2D1::~DrawTargetD2D1()
PopAllClips();
if (mSnapshot) {
MutexAutoLock lock(*mSnapshotLock);
// We may hold the only reference. MarkIndependent will clear mSnapshot;
// keep the snapshot object alive so it doesn't get destroyed while
// MarkIndependent is running.
@ -90,6 +91,9 @@ DrawTargetD2D1::~DrawTargetD2D1()
already_AddRefed<SourceSurface>
DrawTargetD2D1::Snapshot()
{
if (!mSnapshotLock) {
mSnapshotLock = make_shared<Mutex>("DrawTargetD2D1::mSnapshotLock");
}
if (mSnapshot) {
RefPtr<SourceSurface> snapshot(mSnapshot);
return snapshot.forget();
@ -1274,6 +1278,7 @@ void
DrawTargetD2D1::MarkChanged()
{
if (mSnapshot) {
MutexAutoLock lock(*mSnapshotLock);
if (mSnapshot->hasOneRef()) {
// Just destroy it, since no-one else knows about it.
mSnapshot = nullptr;

View File

@ -280,6 +280,7 @@ private:
// The latest snapshot of this surface. This needs to be told when this
// target is modified. We keep it alive as a cache.
RefPtr<SourceSurfaceD2D1> mSnapshot;
std::shared_ptr<Mutex> mSnapshotLock;
// A list of targets we need to flush when we're modified.
TargetSet mDependentTargets;
// A list of targets which have this object in their mDependentTargets set

View File

@ -23,6 +23,9 @@ SourceSurfaceD2D1::SourceSurfaceD2D1(ID2D1Image *aImage, ID2D1DeviceContext *aDC
mFormat = aFormat;
mSize = aSize;
if (aDT) {
mSnapshotLock = aDT->mSnapshotLock;
}
}
SourceSurfaceD2D1::~SourceSurfaceD2D1()
@ -109,6 +112,9 @@ SourceSurfaceD2D1::EnsureRealizedBitmap()
void
SourceSurfaceD2D1::DrawTargetWillChange()
{
MOZ_ASSERT(mSnapshotLock);
mSnapshotLock->AssertCurrentThreadOwns();
// At this point in time this should always be true here.
MOZ_ASSERT(mRealizedBitmap);

View File

@ -62,6 +62,7 @@ private:
SurfaceFormat mFormat;
IntSize mSize;
DrawTargetD2D1* mDrawTarget;
std::shared_ptr<Mutex> mSnapshotLock;
};
class DataSourceSurfaceD2D1 : public DataSourceSurface