зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1074842 - Let SourceSurfaceCGBitmapContext take ownership of the data when DrawTargetCG is destroyed. r=jrmuizel
This commit is contained in:
Родитель
1874a2749b
Коммит
9d0fbfa02c
|
@ -149,7 +149,13 @@ DrawTargetCG::DrawTargetCG()
|
|||
|
||||
DrawTargetCG::~DrawTargetCG()
|
||||
{
|
||||
MarkChanged();
|
||||
if (mSnapshot) {
|
||||
if (mSnapshot->refCount() > 1) {
|
||||
// We only need to worry about snapshots that someone else knows about
|
||||
mSnapshot->DrawTargetWillGoAway();
|
||||
}
|
||||
mSnapshot = nullptr;
|
||||
}
|
||||
|
||||
// Both of these are OK with nullptr arguments, so we do not
|
||||
// need to check (these could be nullptr if Init fails)
|
||||
|
|
|
@ -97,6 +97,7 @@ class DrawTargetCG : public DrawTarget
|
|||
public:
|
||||
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetCG)
|
||||
friend class BorrowedCGContext;
|
||||
friend class SourceSurfaceCGBitmapContext;
|
||||
DrawTargetCG();
|
||||
virtual ~DrawTargetCG();
|
||||
|
||||
|
|
|
@ -360,6 +360,24 @@ SourceSurfaceCGBitmapContext::DrawTargetWillChange()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SourceSurfaceCGBitmapContext::DrawTargetWillGoAway()
|
||||
{
|
||||
if (mDrawTarget) {
|
||||
if (mDrawTarget->mData != CGBitmapContextGetData(mCg)) {
|
||||
DrawTargetWillChange();
|
||||
return;
|
||||
}
|
||||
|
||||
// Instead of copying the data over, we can just swap it.
|
||||
mDataHolder.Swap(mDrawTarget->mData);
|
||||
mData = mDataHolder;
|
||||
mCg = nullptr;
|
||||
mDrawTarget = nullptr;
|
||||
// mImage is still valid because it still points to the same data.
|
||||
}
|
||||
}
|
||||
|
||||
SourceSurfaceCGBitmapContext::~SourceSurfaceCGBitmapContext()
|
||||
{
|
||||
if (mImage)
|
||||
|
|
|
@ -101,6 +101,7 @@ class SourceSurfaceCGContext : public DataSourceSurface
|
|||
public:
|
||||
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceCGContext)
|
||||
virtual void DrawTargetWillChange() = 0;
|
||||
virtual void DrawTargetWillGoAway() = 0;
|
||||
virtual CGImageRef GetImage() = 0;
|
||||
};
|
||||
|
||||
|
@ -139,6 +140,7 @@ private:
|
|||
//XXX: do the other backends friend their DrawTarget?
|
||||
friend class DrawTargetCG;
|
||||
virtual void DrawTargetWillChange();
|
||||
virtual void DrawTargetWillGoAway();
|
||||
void EnsureImage() const;
|
||||
|
||||
// We hold a weak reference to these two objects.
|
||||
|
@ -181,6 +183,7 @@ private:
|
|||
//XXX: do the other backends friend their DrawTarget?
|
||||
friend class DrawTargetCG;
|
||||
virtual void DrawTargetWillChange();
|
||||
virtual void DrawTargetWillGoAway() { DrawTargetWillChange(); }
|
||||
void EnsureImage() const;
|
||||
|
||||
SurfaceFormat mFormat;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define MOZILLA_GFX_TOOLS_H_
|
||||
|
||||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
#include "Types.h"
|
||||
#include "Point.h"
|
||||
|
@ -178,6 +179,13 @@ struct AlignedArray
|
|||
mCount = aCount;
|
||||
}
|
||||
|
||||
void Swap(AlignedArray<T, alignment>& aOther)
|
||||
{
|
||||
mozilla::Swap(mPtr, aOther.mPtr);
|
||||
mozilla::Swap(mStorage, aOther.mStorage);
|
||||
mozilla::Swap(mCount, aOther.mCount);
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE operator T*()
|
||||
{
|
||||
return mPtr;
|
||||
|
|
Загрузка…
Ссылка в новой задаче