Bug 557671: Properly make image layers threadsafe by guarding the active image. r=roc

This commit is contained in:
Bas Schouten 2010-04-08 09:29:55 +02:00
parent 0873100d88
commit 60de353002
2 changed files with 18 additions and 12 deletions

View File

@ -42,6 +42,14 @@
namespace mozilla {
namespace layers {
using mozilla::MutexAutoLock;
ImageContainerOGL::ImageContainerOGL(LayerManagerOGL *aManager)
: ImageContainer(aManager)
, mActiveImageLock("mozilla.layers.ImageContainerOGL.mActiveImageLock")
{
}
already_AddRefed<Image>
ImageContainerOGL::CreateImage(const Image::Format *aFormats,
PRUint32 aNumFormats)
@ -61,12 +69,16 @@ ImageContainerOGL::CreateImage(const Image::Format *aFormats,
void
ImageContainerOGL::SetCurrentImage(Image *aImage)
{
MutexAutoLock lock(mActiveImageLock);
mActiveImage = aImage;
}
already_AddRefed<Image>
ImageContainerOGL::GetCurrentImage()
{
MutexAutoLock lock(mActiveImageLock);
nsRefPtr<Image> retval = mActiveImage;
return retval.forget();
}
@ -191,10 +203,6 @@ PlanarYCbCrImageOGL::~PlanarYCbCrImageOGL()
void
PlanarYCbCrImageOGL::SetData(const PlanarYCbCrImage::Data &aData)
{
/**
* XXX - Should do something more clever here, also introduce thread safety
* there's potential race conditions in this class.
*/
mData = aData;
mData.mCbChannel = new PRUint8[aData.mCbCrStride * aData.mCbCrSize.height];
mData.mCrChannel = new PRUint8[aData.mCbCrStride * aData.mCbCrSize.height];
@ -319,10 +327,6 @@ CairoImageOGL::~CairoImageOGL()
void
CairoImageOGL::SetData(const CairoImage::Data &aData)
{
/**
* XXX - Should make sure this happens on the correct thread. Since this
* is supposed to be threadsafe.
*/
mSize = aData.mSize;
mManager->MakeCurrent();

View File

@ -40,6 +40,7 @@
#include "LayerManagerOGL.h"
#include "ImageLayers.h"
#include "mozilla/Mutex.h"
namespace mozilla {
namespace layers {
@ -47,10 +48,7 @@ namespace layers {
class THEBES_API ImageContainerOGL : public ImageContainer
{
public:
ImageContainerOGL(LayerManagerOGL *aManager)
: ImageContainer(aManager)
{ }
ImageContainerOGL(LayerManagerOGL *aManager);
virtual ~ImageContainerOGL() {}
virtual already_AddRefed<Image> CreateImage(const Image::Format* aFormats,
@ -62,7 +60,11 @@ public:
virtual already_AddRefed<gfxASurface> GetCurrentAsSurface(gfxIntSize* aSize);
private:
typedef mozilla::Mutex Mutex;
nsRefPtr<Image> mActiveImage;
Mutex mActiveImageLock;
};
class THEBES_API ImageLayerOGL : public ImageLayer,