зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1404656: Protect access to mDrawTarget and mImage after a SourceSurfaceSkia has been initialized. r=dvander
MozReview-Commit-ID: 6HGM22V8FbJ
This commit is contained in:
Родитель
424bc1c8e1
Коммит
9218253d7e
|
@ -519,6 +519,9 @@ public:
|
|||
/** @deprecated
|
||||
* Get the raw bitmap data of the surface.
|
||||
* Can return null if there was OOM allocating surface data.
|
||||
*
|
||||
* Deprecated means you shouldn't be using this!! Use Map instead.
|
||||
* Please deny any reviews which add calls to this!
|
||||
*/
|
||||
virtual uint8_t *GetData() = 0;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace gfx {
|
|||
|
||||
SourceSurfaceSkia::SourceSurfaceSkia()
|
||||
: mDrawTarget(nullptr)
|
||||
, mChangeMutex("SourceSurfaceSkia::mChangeMutex")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -40,6 +41,14 @@ SourceSurfaceSkia::GetFormat() const
|
|||
return mFormat;
|
||||
}
|
||||
|
||||
sk_sp<SkImage>
|
||||
SourceSurfaceSkia::GetImage()
|
||||
{
|
||||
MutexAutoLock lock(mChangeMutex);
|
||||
sk_sp<SkImage> image = mImage;
|
||||
return image;
|
||||
}
|
||||
|
||||
static sk_sp<SkData>
|
||||
MakeSkData(void* aData, int32_t aHeight, size_t aStride)
|
||||
{
|
||||
|
@ -155,9 +164,28 @@ SourceSurfaceSkia::GetData()
|
|||
return reinterpret_cast<uint8_t*>(pixmap.writable_addr());
|
||||
}
|
||||
|
||||
bool
|
||||
SourceSurfaceSkia::Map(MapType, MappedSurface *aMappedSurface)
|
||||
{
|
||||
mChangeMutex.Lock();
|
||||
aMappedSurface->mData = GetData();
|
||||
aMappedSurface->mStride = Stride();
|
||||
mIsMapped = !!aMappedSurface->mData;
|
||||
return mIsMapped;
|
||||
}
|
||||
|
||||
void
|
||||
SourceSurfaceSkia::Unmap()
|
||||
{
|
||||
mChangeMutex.Unlock();
|
||||
MOZ_ASSERT(mIsMapped);
|
||||
mIsMapped = false;
|
||||
}
|
||||
|
||||
void
|
||||
SourceSurfaceSkia::DrawTargetWillChange()
|
||||
{
|
||||
MutexAutoLock lock(mChangeMutex);
|
||||
if (mDrawTarget) {
|
||||
// Raster snapshots do not use Skia's internal copy-on-write mechanism,
|
||||
// so we need to do an explicit copy here.
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "2D.h"
|
||||
#include <vector>
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "skia/include/core/SkCanvas.h"
|
||||
#include "skia/include/core/SkImage.h"
|
||||
|
||||
|
@ -28,7 +29,7 @@ public:
|
|||
virtual IntSize GetSize() const;
|
||||
virtual SurfaceFormat GetFormat() const;
|
||||
|
||||
sk_sp<SkImage>& GetImage() { return mImage; }
|
||||
sk_sp<SkImage> GetImage();
|
||||
|
||||
bool InitFromData(unsigned char* aData,
|
||||
const IntSize &aSize,
|
||||
|
@ -41,6 +42,13 @@ public:
|
|||
|
||||
virtual uint8_t* GetData();
|
||||
|
||||
/**
|
||||
* The caller is responsible for ensuring aMappedSurface is not null.
|
||||
*/
|
||||
virtual bool Map(MapType, MappedSurface *aMappedSurface);
|
||||
|
||||
virtual void Unmap();
|
||||
|
||||
virtual int32_t Stride() { return mStride; }
|
||||
|
||||
private:
|
||||
|
@ -53,6 +61,7 @@ private:
|
|||
IntSize mSize;
|
||||
int32_t mStride;
|
||||
RefPtr<DrawTargetSkia> mDrawTarget;
|
||||
Mutex mChangeMutex;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
|
Загрузка…
Ссылка в новой задаче