Bug 1049957 - Use UniquePtr for SharedSurface, SurfaceFactory. - r=kamidphish

This commit is contained in:
Jeff Gilbert 2014-08-15 17:38:08 -07:00
parent 16a3efd798
commit 2cf705f5f5
20 changed files with 401 additions and 310 deletions

View File

@ -37,7 +37,7 @@ GLScreenBuffer::Create(GLContext* gl,
return nullptr;
}
SurfaceFactory* factory = nullptr;
UniquePtr<SurfaceFactory> factory;
#ifdef MOZ_WIDGET_GONK
/* On B2G, we want a Gralloc factory, and we want one right at the start */
@ -45,7 +45,7 @@ GLScreenBuffer::Create(GLContext* gl,
caps.surfaceAllocator &&
XRE_GetProcessType() != GeckoProcessType_Default)
{
factory = new SurfaceFactory_Gralloc(gl, caps);
factory = MakeUnique<SurfaceFactory_Gralloc>(gl, caps);
}
#endif
#ifdef XP_MACOSX
@ -55,8 +55,9 @@ GLScreenBuffer::Create(GLContext* gl,
}
#endif
if (!factory)
factory = new SurfaceFactory_Basic(gl, caps);
if (!factory) {
factory = MakeUnique<SurfaceFactory_Basic>(gl, caps);
}
auto streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread,
caps.preserve);
@ -80,7 +81,7 @@ GLScreenBuffer::~GLScreenBuffer()
// buffers, but that Allocator may be kept alive by the Factory,
// as it currently the case in SurfaceFactory_Gralloc holding a nsRefPtr
// to the Allocator!
delete mFactory;
mFactory = nullptr;
}
@ -374,13 +375,13 @@ GLScreenBuffer::AssureBlitted()
}
void
GLScreenBuffer::Morph(SurfaceFactory* newFactory, SurfaceStreamType streamType)
GLScreenBuffer::Morph(UniquePtr<SurfaceFactory> newFactory,
SurfaceStreamType streamType)
{
MOZ_ASSERT(mStream);
if (newFactory) {
delete mFactory;
mFactory = newFactory;
mFactory = Move(newFactory);
}
if (mStream->mType == streamType)
@ -437,7 +438,7 @@ GLScreenBuffer::Attach(SharedSurface* surf, const gfx::IntSize& size)
bool
GLScreenBuffer::Swap(const gfx::IntSize& size)
{
SharedSurface* nextSurf = mStream->SwapProducer(mFactory, size);
SharedSurface* nextSurf = mStream->SwapProducer(mFactory.get(), size);
if (!nextSurf) {
SurfaceFactory_Basic basicFactory(mGL, mFactory->mCaps);
nextSurf = mStream->SwapProducer(&basicFactory, size);
@ -463,11 +464,11 @@ GLScreenBuffer::PublishFrame(const gfx::IntSize& size)
bool
GLScreenBuffer::Resize(const gfx::IntSize& size)
{
SharedSurface* surface = mStream->Resize(mFactory, size);
if (!surface)
SharedSurface* surf = mStream->Resize(mFactory.get(), size);
if (!surf)
return false;
return Attach(surface, size);
return Attach(surf, size);
}
bool

View File

@ -127,11 +127,11 @@ protected:
public:
const SurfaceCaps mCaps;
protected:
SurfaceFactory* mFactory; // Owned by us.
UniquePtr<SurfaceFactory> mFactory;
RefPtr<SurfaceStream> mStream;
UniquePtr<DrawBuffer> mDraw; // Owned by us.
UniquePtr<ReadBuffer> mRead; // Owned by us.
UniquePtr<DrawBuffer> mDraw;
UniquePtr<ReadBuffer> mRead;
bool mNeedsBlit;
@ -148,11 +148,11 @@ protected:
GLScreenBuffer(GLContext* gl,
const SurfaceCaps& caps,
SurfaceFactory* factory,
UniquePtr<SurfaceFactory> factory,
const RefPtr<SurfaceStream>& stream)
: mGL(gl)
, mCaps(caps)
, mFactory(factory)
, mFactory(Move(factory))
, mStream(stream)
, mDraw(nullptr)
, mRead(nullptr)
@ -175,7 +175,7 @@ public:
}
SurfaceFactory* Factory() const {
return mFactory;
return mFactory.get();
}
SharedSurface* SharedSurf() const {
@ -235,7 +235,8 @@ public:
* Once you pass newFactory into Morph, newFactory will be owned by
* GLScreenBuffer, so `forget` any references to it that still exist.
*/
void Morph(SurfaceFactory* newFactory, SurfaceStreamType streamType);
void Morph(UniquePtr<SurfaceFactory> newFactory,
SurfaceStreamType streamType);
protected:
// Returns false on error or inability to resize.

View File

@ -29,15 +29,15 @@ SharedSurface::ProdCopy(SharedSurface* src, SharedSurface* dest,
dest->mAttachType == AttachmentType::Screen)
{
// Here, we actually need to blit through a temp surface, so let's make one.
nsAutoPtr<SharedSurface_GLTexture> tempSurf;
UniquePtr<SharedSurface_GLTexture> tempSurf;
tempSurf = SharedSurface_GLTexture::Create(gl,
gl,
factory->mFormats,
src->mSize,
factory->mCaps.alpha);
ProdCopy(src, tempSurf, factory);
ProdCopy(tempSurf, dest, factory);
ProdCopy(src, tempSurf.get(), factory);
ProdCopy(tempSurf.get(), dest, factory);
return;
}
@ -269,46 +269,38 @@ SurfaceFactory::SurfaceFactory(GLContext* gl,
SurfaceFactory::~SurfaceFactory()
{
while (!mScraps.empty()) {
SharedSurface* cur = mScraps.front();
UniquePtr<SharedSurface> cur = Move(mScraps.front());
mScraps.pop();
delete cur;
}
}
SharedSurface*
UniquePtr<SharedSurface>
SurfaceFactory::NewSharedSurface(const gfx::IntSize& size)
{
// Attempt to reuse an old surface.
while (!mScraps.empty()) {
SharedSurface* cur = mScraps.front();
UniquePtr<SharedSurface> cur = Move(mScraps.front());
mScraps.pop();
if (cur->mSize == size)
return cur;
// Destroy old surfaces of the wrong size.
delete cur;
if (cur->mSize == size)
return Move(cur);
// Let `cur` be destroyed as it falls out of scope, if it wasn't
// moved.
}
SharedSurface* ret = CreateShared(size);
return ret;
return CreateShared(size);
}
// Auto-deletes surfs of the wrong type.
void
SurfaceFactory::Recycle(SharedSurface*& surf)
SurfaceFactory::Recycle(UniquePtr<SharedSurface> surf)
{
if (!surf)
return;
MOZ_ASSERT(surf);
if (surf->mType == mType) {
mScraps.push(surf);
} else {
delete surf;
mScraps.push(Move(surf));
}
surf = nullptr;
}
} /* namespace gfx */

View File

@ -22,6 +22,7 @@
#include "GLDefs.h"
#include "mozilla/Attributes.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/WeakPtr.h"
#include "SurfaceTypes.h"
namespace mozilla {
@ -140,15 +141,15 @@ public:
}
protected:
virtual SharedSurface* CreateShared(const gfx::IntSize& size) = 0;
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) = 0;
std::queue<SharedSurface*> mScraps;
std::queue< UniquePtr<SharedSurface> > mScraps;
public:
SharedSurface* NewSharedSurface(const gfx::IntSize& size);
UniquePtr<SharedSurface> NewSharedSurface(const gfx::IntSize& size);
// Auto-deletes surfs of the wrong type.
void Recycle(SharedSurface*& surf);
void Recycle(UniquePtr<SharedSurface> surf);
};
} // namespace gl

View File

@ -11,23 +11,6 @@
namespace mozilla {
namespace gl {
SurfaceFactory_ANGLEShareHandle*
SurfaceFactory_ANGLEShareHandle::Create(GLContext* gl,
const SurfaceCaps& caps)
{
GLLibraryEGL* egl = &sEGLLibrary;
if (!egl)
return nullptr;
if (!egl->IsExtensionSupported(
GLLibraryEGL::ANGLE_surface_d3d_texture_2d_share_handle))
{
return nullptr;
}
return new SurfaceFactory_ANGLEShareHandle(gl, egl, caps);
}
EGLDisplay
SharedSurface_ANGLEShareHandle::Display()
{
@ -179,7 +162,7 @@ CreatePBufferSurface(GLLibraryEGL* egl,
return surface;
}
SharedSurface_ANGLEShareHandle*
/*static*/ UniquePtr<SharedSurface_ANGLEShareHandle>
SharedSurface_ANGLEShareHandle::Create(GLContext* gl,
EGLContext context, EGLConfig config,
const gfx::IntSize& size, bool hasAlpha)
@ -208,12 +191,28 @@ SharedSurface_ANGLEShareHandle::Create(GLContext* gl,
return nullptr;
}
return new SharedSurface_ANGLEShareHandle(gl, egl,
size, hasAlpha,
context, pbuffer,
shareHandle);
typedef SharedSurface_ANGLEShareHandle ptrT;
return UniquePtr<ptrT>( new ptrT(gl, egl, size, hasAlpha, context,
pbuffer, shareHandle) );
}
/*static*/ UniquePtr<SurfaceFactory_ANGLEShareHandle>
SurfaceFactory_ANGLEShareHandle::Create(GLContext* gl,
const SurfaceCaps& caps)
{
GLLibraryEGL* egl = &sEGLLibrary;
if (!egl)
return nullptr;
if (!egl->IsExtensionSupported(
GLLibraryEGL::ANGLE_surface_d3d_texture_2d_share_handle))
{
return nullptr;
}
typedef SurfaceFactory_ANGLEShareHandle ptrT;
return UniquePtr<ptrT>( new ptrT(gl, egl, caps) );
}
SurfaceFactory_ANGLEShareHandle::SurfaceFactory_ANGLEShareHandle(GLContext* gl,
GLLibraryEGL* egl,

View File

@ -20,10 +20,11 @@ class SharedSurface_ANGLEShareHandle
: public SharedSurface
{
public:
static SharedSurface_ANGLEShareHandle* Create(GLContext* gl,
EGLContext context, EGLConfig config,
const gfx::IntSize& size,
bool hasAlpha);
static UniquePtr<SharedSurface_ANGLEShareHandle> Create(GLContext* gl,
EGLContext context,
EGLConfig config,
const gfx::IntSize& size,
bool hasAlpha);
static SharedSurface_ANGLEShareHandle* Cast(SharedSurface* surf) {
MOZ_ASSERT(surf->mType == SharedSurfaceType::EGLSurfaceANGLE);
@ -85,15 +86,15 @@ protected:
EGLConfig mConfig;
public:
static SurfaceFactory_ANGLEShareHandle* Create(GLContext* gl,
const SurfaceCaps& caps);
static UniquePtr<SurfaceFactory_ANGLEShareHandle> Create(GLContext* gl,
const SurfaceCaps& caps);
protected:
SurfaceFactory_ANGLEShareHandle(GLContext* gl,
GLLibraryEGL* egl,
const SurfaceCaps& caps);
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
bool hasAlpha = mReadCaps.alpha;
return SharedSurface_ANGLEShareHandle::Create(mProdGL,
mContext, mConfig,

View File

@ -16,7 +16,7 @@
namespace mozilla {
namespace gl {
SharedSurface_EGLImage*
/*static*/ UniquePtr<SharedSurface_EGLImage>
SharedSurface_EGLImage::Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
@ -46,12 +46,11 @@ SharedSurface_EGLImage::Create(GLContext* prodGL,
return nullptr;
}
return new SharedSurface_EGLImage(prodGL, egl,
size, hasAlpha,
formats, prodTex, image);
typedef SharedSurface_EGLImage ptrT;
return UniquePtr<ptrT>( new ptrT(prodGL, egl, size, hasAlpha,
formats, prodTex, image) );
}
bool
SharedSurface_EGLImage::HasExtensions(GLLibraryEGL* egl, GLContext* gl)
{
@ -216,9 +215,9 @@ SharedSurface_EGLImage::AcquireConsumerTexture(GLContext* consGL, GLuint* out_te
}
SurfaceFactory_EGLImage*
/*static*/ UniquePtr<SurfaceFactory_EGLImage>
SurfaceFactory_EGLImage::Create(GLContext* prodGL,
const SurfaceCaps& caps)
const SurfaceCaps& caps)
{
EGLContext context = GLContextEGL::Cast(prodGL)->GetEGLContext();
@ -227,7 +226,8 @@ SurfaceFactory_EGLImage::Create(GLContext* prodGL,
return nullptr;
}
return new SurfaceFactory_EGLImage(prodGL, context, caps);
typedef SurfaceFactory_EGLImage ptrT;
return UniquePtr<ptrT>( new ptrT(prodGL, context, caps) );
}
} /* namespace gfx */

View File

@ -22,11 +22,11 @@ class SharedSurface_EGLImage
: public SharedSurface
{
public:
static SharedSurface_EGLImage* Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
EGLContext context);
static UniquePtr<SharedSurface_EGLImage> Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
EGLContext context);
static SharedSurface_EGLImage* Cast(SharedSurface* surf) {
MOZ_ASSERT(surf->mType == SharedSurfaceType::EGLImageShare);
@ -84,8 +84,8 @@ class SurfaceFactory_EGLImage
{
public:
// Fallible:
static SurfaceFactory_EGLImage* Create(GLContext* prodGL,
const SurfaceCaps& caps);
static UniquePtr<SurfaceFactory_EGLImage> Create(GLContext* prodGL,
const SurfaceCaps& caps);
protected:
const EGLContext mContext;
@ -98,7 +98,7 @@ protected:
{}
public:
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
bool hasAlpha = mReadCaps.alpha;
return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
}

View File

@ -17,7 +17,7 @@ namespace gl {
using gfx::IntSize;
using gfx::SurfaceFormat;
SharedSurface_Basic*
/*static*/ UniquePtr<SharedSurface_Basic>
SharedSurface_Basic::Create(GLContext* gl,
const GLFormats& formats,
const IntSize& size,
@ -45,7 +45,9 @@ SharedSurface_Basic::Create(GLContext* gl,
default:
MOZ_CRASH("Unhandled Tex format.");
}
return new SharedSurface_Basic(gl, size, hasAlpha, format, tex);
typedef SharedSurface_Basic ptrT;
return UniquePtr<ptrT>( new ptrT(gl, size, hasAlpha, format, tex) );
}
SharedSurface_Basic::SharedSurface_Basic(GLContext* gl,
@ -100,9 +102,10 @@ SharedSurface_Basic::Fence()
ReadPixelsIntoDataSurface(mGL, mData);
}
////////////////////////////////////////////////////////////////////////
// SharedSurface_GLTexture
SharedSurface_GLTexture*
/*static*/ UniquePtr<SharedSurface_GLTexture>
SharedSurface_GLTexture::Create(GLContext* prodGL,
GLContext* consGL,
const GLFormats& formats,
@ -124,7 +127,9 @@ SharedSurface_GLTexture::Create(GLContext* prodGL,
ownsTex = true;
}
return new SharedSurface_GLTexture(prodGL, consGL, size, hasAlpha, tex, ownsTex);
typedef SharedSurface_GLTexture ptrT;
return UniquePtr<ptrT>( new ptrT(prodGL, consGL, size, hasAlpha,
tex, ownsTex) );
}
SharedSurface_GLTexture::~SharedSurface_GLTexture()

View File

@ -34,10 +34,10 @@ class SharedSurface_Basic
: public SharedSurface
{
public:
static SharedSurface_Basic* Create(GLContext* gl,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha);
static UniquePtr<SharedSurface_Basic> Create(GLContext* gl,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha);
static SharedSurface_Basic* Cast(SharedSurface* surf) {
MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic);
@ -90,7 +90,7 @@ public:
: SurfaceFactory(gl, SharedSurfaceType::Basic, caps)
{}
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
bool hasAlpha = mReadCaps.alpha;
return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
}
@ -102,12 +102,12 @@ class SharedSurface_GLTexture
: public SharedSurface
{
public:
static SharedSurface_GLTexture* Create(GLContext* prodGL,
GLContext* consGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
GLuint texture = 0);
static UniquePtr<SharedSurface_GLTexture> Create(GLContext* prodGL,
GLContext* consGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
GLuint texture = 0);
static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
MOZ_ASSERT(surf->mType == SharedSurfaceType::GLTextureShare);
@ -183,7 +183,7 @@ public:
MOZ_ASSERT(consGL != prodGL);
}
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
bool hasAlpha = mReadCaps.alpha;
return SharedSurface_GLTexture::Create(mGL, mConsGL, mFormats, size, hasAlpha);
}

View File

@ -49,7 +49,7 @@ SurfaceFactory_Gralloc::SurfaceFactory_Gralloc(GLContext* prodGL,
mAllocator = allocator;
}
SharedSurface_Gralloc*
/*static*/ UniquePtr<SharedSurface_Gralloc>
SharedSurface_Gralloc::Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
@ -110,11 +110,14 @@ SharedSurface_Gralloc::Create(GLContext* prodGL,
egl->fDestroyImage(display, image);
SharedSurface_Gralloc *surf = new SharedSurface_Gralloc(prodGL, size, hasAlpha, egl, allocator, grallocTC, prodTex);
typedef SharedSurface_Gralloc ptrT;
UniquePtr<ptrT> surf( new ptrT(prodGL, size, hasAlpha, egl,
allocator, grallocTC, prodTex) );
DEBUG_PRINT("SharedSurface_Gralloc::Create: success -- surface %p, GraphicBuffer %p.\n", surf, buffer.get());
return surf;
return Move(surf);
}

View File

@ -23,11 +23,11 @@ class SharedSurface_Gralloc
: public SharedSurface
{
public:
static SharedSurface_Gralloc* Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
layers::ISurfaceAllocator* allocator);
static UniquePtr<SharedSurface_Gralloc> Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
layers::ISurfaceAllocator* allocator);
static SharedSurface_Gralloc* Cast(SharedSurface* surf) {
MOZ_ASSERT(surf->mType == SharedSurfaceType::Gralloc);
@ -84,7 +84,7 @@ public:
const SurfaceCaps& caps,
layers::ISurfaceAllocator* allocator = nullptr);
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
bool hasAlpha = mReadCaps.alpha;
if (!mAllocator) {
return nullptr;

View File

@ -13,14 +13,18 @@
namespace mozilla {
namespace gl {
/* static */ SharedSurface_IOSurface*
SharedSurface_IOSurface::Create(MacIOSurface* surface, GLContext* gl, bool hasAlpha)
/*static*/ UniquePtr<SharedSurface_IOSurface>
SharedSurface_IOSurface::Create(const RefPtr<MacIOSurface>& ioSurf,
GLContext* gl,
bool hasAlpha)
{
MOZ_ASSERT(surface);
MOZ_ASSERT(gl);
gfx::IntSize size(surface->GetWidth(), surface->GetHeight());
return new SharedSurface_IOSurface(surface, gl, size, hasAlpha);
typedef SharedSurface_IOSurface ptrT;
return UniquePtr<ptrT>( new ptrT(ioSurf, gl, size, hasAlpha) );
}
void
@ -87,7 +91,7 @@ BackTextureWithIOSurf(GLContext* gl, GLuint tex, MacIOSurface* ioSurf)
ioSurf->CGLTexImageIOSurface2D(cgl);
}
SharedSurface_IOSurface::SharedSurface_IOSurface(MacIOSurface* surface,
SharedSurface_IOSurface::SharedSurface_IOSurface(const RefPtr<MacIOSurface>& ioSurf,
GLContext* gl,
const gfx::IntSize& size,
bool hasAlpha)
@ -96,7 +100,7 @@ SharedSurface_IOSurface::SharedSurface_IOSurface(MacIOSurface* surface,
gl,
size,
hasAlpha)
, mSurface(surface)
, mIOSurf(ioSurf)
, mCurConsGL(nullptr)
, mConsTex(0)
{
@ -118,7 +122,7 @@ SharedSurface_IOSurface::ConsTexture(GLContext* consGL)
consGL->MakeCurrent();
mConsTex = 0;
consGL->fGenTextures(1, &mConsTex);
BackTextureWithIOSurf(consGL, mConsTex, mSurface);
BackTextureWithIOSurf(consGL, mConsTex, mIOSurf);
}
return mConsTex;
@ -134,17 +138,21 @@ SharedSurface_IOSurface::~SharedSurface_IOSurface()
}
}
////////////////////////////////////////////////////////////////////////
// SurfaceFactory_IOSurface
/*static*/ SurfaceFactory_IOSurface*
/*static*/ UniquePtr<SurfaceFactory_IOSurface>
SurfaceFactory_IOSurface::Create(GLContext* gl,
const SurfaceCaps& caps)
{
gfx::IntSize maxDims(MacIOSurface::GetMaxWidth(),
MacIOSurface::GetMaxHeight());
return new SurfaceFactory_IOSurface(gl, caps, maxDims);
typedef SurfaceFactory_IOSurface ptrT;
return UniquePtr<ptrT>( new ptrT(gl, caps, maxDims) );
}
SharedSurface*
UniquePtr<SharedSurface>
SurfaceFactory_IOSurface::CreateShared(const gfx::IntSize& size)
{
if (size.width > mMaxDims.width ||
@ -154,15 +162,16 @@ SurfaceFactory_IOSurface::CreateShared(const gfx::IntSize& size)
}
bool hasAlpha = mReadCaps.alpha;
RefPtr<MacIOSurface> surf =
MacIOSurface::CreateIOSurface(size.width, size.height, 1.0, hasAlpha);
RefPtr<MacIOSurface> ioSurf;
ioSurf = MacIOSurface::CreateIOSurface(size.width, size.height, 1.0,
hasAlpha);
if (!surf) {
NS_WARNING("Failed to create MacIOSurface.");
return nullptr;
}
return SharedSurface_IOSurface::Create(surf, mGL, hasAlpha);
return SharedSurface_IOSurface::Create(ioSurf, mGL, hasAlpha);
}
}

View File

@ -17,7 +17,9 @@ namespace gl {
class SharedSurface_IOSurface : public SharedSurface
{
public:
static SharedSurface_IOSurface* Create(MacIOSurface* surface, GLContext* gl, bool hasAlpha);
static UniquePtr<SharedSurface_IOSurface> Create(MacIOSurface* surface,
GLContext* gl,
bool hasAlpha);
~SharedSurface_IOSurface();
@ -55,9 +57,10 @@ public:
}
private:
SharedSurface_IOSurface(MacIOSurface* surface, GLContext* gl, const gfx::IntSize& size, bool hasAlpha);
SharedSurface_IOSurface(MacIOSurface* ioSurf, GLContext* gl,
const gfx::IntSize& size, bool hasAlpha);
RefPtr<MacIOSurface> mSurface;
RefPtr<MacIOSurface> mIOSurf;
GLuint mProdTex;
const GLContext* mCurConsGL;
GLuint mConsTex;
@ -67,8 +70,8 @@ class SurfaceFactory_IOSurface : public SurfaceFactory
{
public:
// Infallible.
static SurfaceFactory_IOSurface* Create(GLContext* gl,
const SurfaceCaps& caps);
static UniquePtr<SurfaceFactory_IOSurface> Create(GLContext* gl,
const SurfaceCaps& caps);
protected:
const gfx::IntSize mMaxDims;
@ -80,7 +83,7 @@ protected:
{
}
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE;
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE;
};
} /* namespace gfx */

View File

@ -9,6 +9,7 @@
#include "SharedSurface.h"
#include "SharedSurfaceGL.h"
#include "GeckoProfiler.h"
#include "mozilla/Move.h"
namespace mozilla {
namespace gl {
@ -61,7 +62,7 @@ bool
SurfaceStream_TripleBuffer::CopySurfaceToProducer(SharedSurface* src, SurfaceFactory* factory)
{
if (!mProducer) {
New(factory, src->mSize, mProducer);
New(factory, src->mSize, &mProducer);
if (!mProducer) {
return false;
}
@ -69,14 +70,17 @@ SurfaceStream_TripleBuffer::CopySurfaceToProducer(SharedSurface* src, SurfaceFac
MOZ_ASSERT(src->mSize == mProducer->mSize, "Size mismatch");
SharedSurface::ProdCopy(src, mProducer, factory);
SharedSurface::ProdCopy(src, mProducer.get(), factory);
return true;
}
void
SurfaceStream::New(SurfaceFactory* factory, const gfx::IntSize& size,
SharedSurface*& surf)
UniquePtr<SharedSurface>* surfSlot)
{
MOZ_ASSERT(surfSlot);
UniquePtr<SharedSurface>& surf = *surfSlot;
MOZ_ASSERT(!surf);
surf = factory->NewSharedSurface(size);
@ -84,91 +88,145 @@ SurfaceStream::New(SurfaceFactory* factory, const gfx::IntSize& size,
// Before next use, wait until SharedSurface's buffer
// is no longer being used.
surf->WaitForBufferOwnership();
mSurfaces.insert(surf);
#ifdef DEBUG
mSurfaces.insert(surf.get());
#endif
}
}
void
SurfaceStream::Recycle(SurfaceFactory* factory, SharedSurface*& surf)
SurfaceStream::MoveTo(UniquePtr<SharedSurface>* slotFrom,
UniquePtr<SharedSurface>* slotTo)
{
if (surf) {
mSurfaces.erase(surf);
factory->Recycle(surf);
}
MOZ_ASSERT(!surf);
MOZ_ASSERT(slotFrom);
UniquePtr<SharedSurface>& from = *slotFrom;
MOZ_ASSERT(slotTo);
UniquePtr<SharedSurface>& to = *slotTo;
MOZ_ASSERT(!to);
to = Move(from);
from = nullptr;
}
void
SurfaceStream::Delete(SharedSurface*& surf)
SurfaceStream::Recycle(SurfaceFactory* factory, UniquePtr<SharedSurface>* surfSlot)
{
MOZ_ASSERT(surfSlot);
UniquePtr<SharedSurface>& surf = *surfSlot;
if (surf) {
mSurfaces.erase(surf);
delete surf;
#ifdef DEBUG
mSurfaces.erase(surf.get());
#endif
factory->Recycle(Move(surf));
surf = nullptr;
}
MOZ_ASSERT(!surf);
}
SharedSurface*
SurfaceStream::Surrender(SharedSurface*& surf)
void
SurfaceStream::Delete(UniquePtr<SharedSurface>* surfSlot)
{
SharedSurface* ret = surf;
MOZ_ASSERT(surfSlot);
UniquePtr<SharedSurface>& surf = *surfSlot;
if (surf) {
mSurfaces.erase(surf);
#ifdef DEBUG
mSurfaces.erase(surf.get());
#endif
surf = nullptr;
}
MOZ_ASSERT(!surf);
return ret;
}
SharedSurface*
SurfaceStream::Absorb(SharedSurface*& surf)
UniquePtr<SharedSurface>
SurfaceStream::Surrender(UniquePtr<SharedSurface>* surfSlot)
{
SharedSurface* ret = surf;
MOZ_ASSERT(surfSlot);
UniquePtr<SharedSurface>& surf = *surfSlot;
#ifdef DEBUG
if (surf) {
mSurfaces.insert(surf);
surf = nullptr;
mSurfaces.erase(surf.get());
}
MOZ_ASSERT(!surf);
#endif
return ret;
UniquePtr<SharedSurface> ret = Move(surf);
surf = nullptr;
return Move(ret);
}
// Move `surfSlot` to `return`, but record that the surf is now part of
// this stream.
UniquePtr<SharedSurface>
SurfaceStream::Absorb(UniquePtr<SharedSurface>* surfSlot)
{
MOZ_ASSERT(surfSlot);
UniquePtr<SharedSurface>& surf = *surfSlot;
#ifdef DEBUG
if (surf) {
mSurfaces.insert(surf.get());
}
#endif
UniquePtr<SharedSurface> ret = Move(surf);
surf = nullptr;
return Move(ret);
}
void
SurfaceStream::Scrap(SharedSurface*& scrap)
SurfaceStream::Scrap(UniquePtr<SharedSurface>* surfSlot)
{
if (scrap) {
mScraps.push(scrap);
scrap = nullptr;
MOZ_ASSERT(surfSlot);
UniquePtr<SharedSurface>& surf = *surfSlot;
if (surf) {
mScraps.push(Move(surf));
surf = nullptr;
}
MOZ_ASSERT(!scrap);
MOZ_ASSERT(!surf);
}
void
SurfaceStream::RecycleScraps(SurfaceFactory* factory)
{
while (!mScraps.empty()) {
SharedSurface* cur = mScraps.top();
UniquePtr<SharedSurface> cur = Move(mScraps.top());
mScraps.pop();
Recycle(factory, cur);
Recycle(factory, &cur);
}
}
////////////////////////////////////////////////////////////////////////
// SurfaceStream
SurfaceStream::SurfaceStream(SurfaceStreamType type,
SurfaceStream* prevStream)
: mType(type)
, mProducer(nullptr)
, mMonitor("SurfaceStream monitor")
, mIsAlive(true)
{
MOZ_ASSERT(!prevStream || mType != prevStream->mType,
"We should not need to create a SurfaceStream from another "
"of the same type.");
}
SurfaceStream::~SurfaceStream()
{
Delete(mProducer);
Delete(&mProducer);
while (!mScraps.empty()) {
SharedSurface* cur = mScraps.top();
UniquePtr<SharedSurface> cur = Move(mScraps.top());
mScraps.pop();
Delete(cur);
Delete(&cur);
}
MOZ_ASSERT(mSurfaces.empty());
@ -196,13 +254,16 @@ SurfaceStream::Resize(SurfaceFactory* factory, const gfx::IntSize& size)
MonitorAutoLock lock(mMonitor);
if (mProducer) {
Scrap(mProducer);
Scrap(&mProducer);
}
New(factory, size, mProducer);
return mProducer;
New(factory, size, &mProducer);
return mProducer.get();
}
////////////////////////////////////////////////////////////////////////
// SurfaceStream_SingleBuffer
SurfaceStream_SingleBuffer::SurfaceStream_SingleBuffer(SurfaceStream* prevStream)
: SurfaceStream(SurfaceStreamType::SingleBuffer, prevStream)
, mConsumer(nullptr)
@ -210,33 +271,30 @@ SurfaceStream_SingleBuffer::SurfaceStream_SingleBuffer(SurfaceStream* prevStream
if (!prevStream)
return;
SharedSurface* prevProducer = nullptr;
SharedSurface* prevConsumer = nullptr;
prevStream->SurrenderSurfaces(prevProducer, prevConsumer);
UniquePtr<SharedSurface> prevProducer;
UniquePtr<SharedSurface> prevConsumer;
prevStream->SurrenderSurfaces(&prevProducer, &prevConsumer);
if (prevConsumer == prevProducer)
prevConsumer = nullptr;
mProducer = Absorb(prevProducer);
mConsumer = Absorb(prevConsumer);
mProducer = Absorb(&prevProducer);
mConsumer = Absorb(&prevConsumer);
}
SurfaceStream_SingleBuffer::~SurfaceStream_SingleBuffer()
{
Delete(mConsumer);
Delete(&mConsumer);
}
void
SurfaceStream_SingleBuffer::SurrenderSurfaces(SharedSurface*& producer,
SharedSurface*& consumer)
SurfaceStream_SingleBuffer::SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer)
{
MOZ_ASSERT(out_producer);
MOZ_ASSERT(out_consumer);
mIsAlive = false;
producer = Surrender(mProducer);
consumer = Surrender(mConsumer);
if (!consumer)
consumer = producer;
*out_producer = Surrender(&mProducer);
*out_consumer = Surrender(&mConsumer);
}
SharedSurface*
@ -245,7 +303,7 @@ SurfaceStream_SingleBuffer::SwapProducer(SurfaceFactory* factory,
{
MonitorAutoLock lock(mMonitor);
if (mConsumer) {
Recycle(factory, mConsumer);
Recycle(factory, &mConsumer);
}
if (mProducer) {
@ -265,17 +323,17 @@ SurfaceStream_SingleBuffer::SwapProducer(SurfaceFactory* factory,
}
if (needsNewBuffer) {
Move(mProducer, mConsumer);
MoveTo(&mProducer, &mConsumer);
}
}
// The old Prod (if there every was one) was invalid,
// so we need a new one.
if (!mProducer) {
New(factory, size, mProducer);
New(factory, size, &mProducer);
}
return mProducer;
return mProducer.get();
}
SharedSurface*
@ -285,14 +343,15 @@ SurfaceStream_SingleBuffer::SwapConsumer_NoWait()
// Use Cons, if present.
// Otherwise, just use Prod directly.
SharedSurface* toConsume = mConsumer;
SharedSurface* toConsume = mConsumer.get();
if (!toConsume)
toConsume = mProducer;
toConsume = mProducer.get();
return toConsume;
}
////////////////////////////////////////////////////////////////////////
// SurfaceStream_TripleBuffer_Copy
SurfaceStream_TripleBuffer_Copy::SurfaceStream_TripleBuffer_Copy(SurfaceStream* prevStream)
: SurfaceStream(SurfaceStreamType::TripleBuffer_Copy, prevStream)
@ -302,34 +361,34 @@ SurfaceStream_TripleBuffer_Copy::SurfaceStream_TripleBuffer_Copy(SurfaceStream*
if (!prevStream)
return;
SharedSurface* prevProducer = nullptr;
SharedSurface* prevConsumer = nullptr;
prevStream->SurrenderSurfaces(prevProducer, prevConsumer);
UniquePtr<SharedSurface> prevProducer;
UniquePtr<SharedSurface> prevConsumer;
prevStream->SurrenderSurfaces(&prevProducer, &prevConsumer);
if (prevConsumer == prevProducer)
prevConsumer = nullptr;
mProducer = Absorb(prevProducer);
mConsumer = Absorb(prevConsumer);
mProducer = Absorb(&prevProducer);
mConsumer = Absorb(&prevConsumer);
}
SurfaceStream_TripleBuffer_Copy::~SurfaceStream_TripleBuffer_Copy()
{
Delete(mStaging);
Delete(mConsumer);
Delete(&mStaging);
Delete(&mConsumer);
}
void
SurfaceStream_TripleBuffer_Copy::SurrenderSurfaces(SharedSurface*& producer,
SharedSurface*& consumer)
SurfaceStream_TripleBuffer_Copy::SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer)
{
MOZ_ASSERT(out_producer);
MOZ_ASSERT(out_consumer);
mIsAlive = false;
producer = Surrender(mProducer);
consumer = Surrender(mConsumer);
*out_producer = Surrender(&mProducer);
*out_consumer = Surrender(&mConsumer);
if (!consumer)
consumer = Surrender(mStaging);
if (!*out_consumer)
*out_consumer = Surrender(&mStaging);
}
SharedSurface*
@ -343,55 +402,57 @@ SurfaceStream_TripleBuffer_Copy::SwapProducer(SurfaceFactory* factory,
if (mStaging) {
// We'll re-use this for a new mProducer later on if
// the size remains the same
Recycle(factory, mStaging);
Recycle(factory, &mStaging);
}
Move(mProducer, mStaging);
MoveTo(&mProducer, &mStaging);
mStaging->Fence();
New(factory, size, mProducer);
New(factory, size, &mProducer);
if (mProducer && mStaging->mSize == mProducer->mSize)
SharedSurface::ProdCopy(mStaging, mProducer, factory);
if (mProducer &&
mStaging->mSize == mProducer->mSize)
{
SharedSurface::ProdCopy(mStaging.get(), mProducer.get(), factory);
}
} else {
New(factory, size, mProducer);
New(factory, size, &mProducer);
}
return mProducer;
return mProducer.get();
}
SharedSurface*
SurfaceStream_TripleBuffer_Copy::SwapConsumer_NoWait()
{
MonitorAutoLock lock(mMonitor);
if (mStaging) {
Scrap(mConsumer);
Move(mStaging, mConsumer);
Scrap(&mConsumer);
MoveTo(&mStaging, &mConsumer);
}
return mConsumer;
return mConsumer.get();
}
////////////////////////////////////////////////////////////////////////
// SurfaceStream_TripleBuffer
void SurfaceStream_TripleBuffer::Init(SurfaceStream* prevStream)
{
if (!prevStream)
return;
SharedSurface* prevProducer = nullptr;
SharedSurface* prevConsumer = nullptr;
prevStream->SurrenderSurfaces(prevProducer, prevConsumer);
UniquePtr<SharedSurface> prevProducer;
UniquePtr<SharedSurface> prevConsumer;
prevStream->SurrenderSurfaces(&prevProducer, &prevConsumer);
if (prevConsumer == prevProducer)
prevConsumer = nullptr;
mProducer = Absorb(prevProducer);
mConsumer = Absorb(prevConsumer);
mProducer = Absorb(&prevProducer);
mConsumer = Absorb(&prevConsumer);
}
SurfaceStream_TripleBuffer::SurfaceStream_TripleBuffer(SurfaceStreamType type, SurfaceStream* prevStream)
SurfaceStream_TripleBuffer::SurfaceStream_TripleBuffer(SurfaceStreamType type,
SurfaceStream* prevStream)
: SurfaceStream(type, prevStream)
, mStaging(nullptr)
, mConsumer(nullptr)
@ -409,21 +470,24 @@ SurfaceStream_TripleBuffer::SurfaceStream_TripleBuffer(SurfaceStream* prevStream
SurfaceStream_TripleBuffer::~SurfaceStream_TripleBuffer()
{
Delete(mStaging);
Delete(mConsumer);
Delete(&mStaging);
Delete(&mConsumer);
}
void
SurfaceStream_TripleBuffer::SurrenderSurfaces(SharedSurface*& producer,
SharedSurface*& consumer)
SurfaceStream_TripleBuffer::SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer)
{
MOZ_ASSERT(out_producer);
MOZ_ASSERT(out_consumer);
mIsAlive = false;
producer = Surrender(mProducer);
consumer = Surrender(mConsumer);
*out_producer = Surrender(&mProducer);
*out_consumer = Surrender(&mConsumer);
if (!consumer)
consumer = Surrender(mStaging);
if (!*out_consumer)
*out_consumer = Surrender(&mStaging);
}
SharedSurface*
@ -431,7 +495,7 @@ SurfaceStream_TripleBuffer::SwapProducer(SurfaceFactory* factory,
const gfx::IntSize& size)
{
PROFILER_LABEL("SurfaceStream_TripleBuffer", "SwapProducer",
js::ProfileEntry::Category::GRAPHICS);
js::ProfileEntry::Category::GRAPHICS);
MonitorAutoLock lock(mMonitor);
if (mProducer) {
@ -443,17 +507,17 @@ SurfaceStream_TripleBuffer::SwapProducer(SurfaceFactory* factory,
WaitForCompositor();
}
if (mStaging) {
Scrap(mStaging);
Scrap(&mStaging);
}
Move(mProducer, mStaging);
MoveTo(&mProducer, &mStaging);
mStaging->Fence();
}
MOZ_ASSERT(!mProducer);
New(factory, size, mProducer);
New(factory, size, &mProducer);
return mProducer;
return mProducer.get();
}
SharedSurface*
@ -461,16 +525,20 @@ SurfaceStream_TripleBuffer::SwapConsumer_NoWait()
{
MonitorAutoLock lock(mMonitor);
if (mStaging) {
Scrap(mConsumer);
Move(mStaging, mConsumer);
Scrap(&mConsumer);
MoveTo(&mStaging, &mConsumer);
mMonitor.NotifyAll();
}
return mConsumer;
return mConsumer.get();
}
////////////////////////////////////////////////////////////////////////
// SurfaceStream_TripleBuffer_Async
SurfaceStream_TripleBuffer_Async::SurfaceStream_TripleBuffer_Async(SurfaceStream* prevStream)
: SurfaceStream_TripleBuffer(SurfaceStreamType::TripleBuffer_Async, prevStream)
: SurfaceStream_TripleBuffer(SurfaceStreamType::TripleBuffer_Async,
prevStream)
{
}
@ -481,8 +549,9 @@ SurfaceStream_TripleBuffer_Async::~SurfaceStream_TripleBuffer_Async()
void
SurfaceStream_TripleBuffer_Async::WaitForCompositor()
{
PROFILER_LABEL("SurfaceStream_TripleBuffer_Async", "WaitForCompositor",
js::ProfileEntry::Category::GRAPHICS);
PROFILER_LABEL("SurfaceStream_TripleBuffer_Async",
"WaitForCompositor",
js::ProfileEntry::Category::GRAPHICS);
// If we haven't be notified within 100ms, then
// something must have happened and it will never arrive.

View File

@ -13,6 +13,7 @@
#include "mozilla/gfx/Point.h"
#include "mozilla/GenericRefCounted.h"
#include "SurfaceTypes.h"
#include "SharedSurface.h"
namespace mozilla {
@ -46,9 +47,11 @@ public:
protected:
// |mProd| is owned by us, but can be ripped away when
// creating a new GLStream from this one.
SharedSurface* mProducer;
UniquePtr<SharedSurface> mProducer;
#ifdef DEBUG
std::set<SharedSurface*> mSurfaces;
std::stack<SharedSurface*> mScraps;
#endif
std::stack< UniquePtr<SharedSurface> > mScraps;
mutable Monitor mMonitor;
bool mIsAlive;
@ -58,16 +61,7 @@ protected:
// |previous| can be null, indicating this is the first one.
// Otherwise, we pull in |mProd| from |previous| an our initial surface.
SurfaceStream(SurfaceStreamType type, SurfaceStream* prevStream)
: mType(type)
, mProducer(nullptr)
, mMonitor("SurfaceStream monitor")
, mIsAlive(true)
{
MOZ_ASSERT(!prevStream || mType != prevStream->mType,
"We should not need to create a SurfaceStream from another "
"of the same type.");
}
SurfaceStream(SurfaceStreamType type, SurfaceStream* prevStream);
public:
virtual ~SurfaceStream();
@ -76,26 +70,23 @@ protected:
// These functions below are helpers to make trading buffers around easier.
// For instance, using Move(a,b) instead of normal assignment assures that
// we are never leaving anything hanging around, keeping things very safe.
static void Move(SharedSurface*& from, SharedSurface*& to) {
MOZ_ASSERT(!to);
to = from;
from = nullptr;
}
void MoveTo(UniquePtr<SharedSurface>* slotFrom,
UniquePtr<SharedSurface>* slotTo);
void New(SurfaceFactory* factory, const gfx::IntSize& size,
SharedSurface*& surf);
void Delete(SharedSurface*& surf);
void Recycle(SurfaceFactory* factory, SharedSurface*& surf);
UniquePtr<SharedSurface>* surfSlot);
void Delete(UniquePtr<SharedSurface>* surfSlot);
void Recycle(SurfaceFactory* factory,
UniquePtr<SharedSurface>* surfSlot);
// Surrender control of a surface, and return it for use elsewhere.
SharedSurface* Surrender(SharedSurface*& surf);
UniquePtr<SharedSurface> Surrender(UniquePtr<SharedSurface>* surfSlot);
// Absorb control of a surface from elsewhere, clears its old location.
SharedSurface* Absorb(SharedSurface*& surf);
UniquePtr<SharedSurface> Absorb(UniquePtr<SharedSurface>* surfSlot);
// For holding on to surfaces we don't need until we can return them to the
// Producer's factory via SurfaceFactory::Recycle.
// Not thread-safe.
void Scrap(SharedSurface*& scrap);
void Scrap(UniquePtr<SharedSurface>* surfSlot);
// Not thread-safe.
void RecycleScraps(SurfaceFactory* factory);
@ -124,7 +115,8 @@ protected:
public:
virtual SharedSurface* SwapConsumer();
virtual void SurrenderSurfaces(SharedSurface*& producer, SharedSurface*& consumer) = 0;
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer) = 0;
};
// Not thread-safe. Don't use cross-threads.
@ -132,10 +124,11 @@ class SurfaceStream_SingleBuffer
: public SurfaceStream
{
protected:
SharedSurface* mConsumer; // Only present after resize-swap.
UniquePtr<SharedSurface> mConsumer; // Only present after resize-swap.
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_SingleBuffer)
explicit SurfaceStream_SingleBuffer(SurfaceStream* prevStream);
virtual ~SurfaceStream_SingleBuffer();
@ -144,11 +137,12 @@ public:
* SwapCons being called in Render.
*/
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
const gfx::IntSize& size);
const gfx::IntSize& size) MOZ_OVERRIDE;
virtual SharedSurface* SwapConsumer_NoWait();
virtual SharedSurface* SwapConsumer_NoWait() MOZ_OVERRIDE;
virtual void SurrenderSurfaces(SharedSurface*& producer, SharedSurface*& consumer);
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer) MOZ_OVERRIDE;
};
// Our hero for preserveDrawingBuffer=true.
@ -156,20 +150,22 @@ class SurfaceStream_TripleBuffer_Copy
: public SurfaceStream
{
protected:
SharedSurface* mStaging;
SharedSurface* mConsumer;
UniquePtr<SharedSurface> mStaging;
UniquePtr<SharedSurface> mConsumer;
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer_Copy)
explicit SurfaceStream_TripleBuffer_Copy(SurfaceStream* prevStream);
virtual ~SurfaceStream_TripleBuffer_Copy();
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
const gfx::IntSize& size);
const gfx::IntSize& size) MOZ_OVERRIDE;
virtual SharedSurface* SwapConsumer_NoWait();
virtual SharedSurface* SwapConsumer_NoWait() MOZ_OVERRIDE;
virtual void SurrenderSurfaces(SharedSurface*& producer, SharedSurface*& consumer);
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer) MOZ_OVERRIDE;
};
@ -177,8 +173,8 @@ class SurfaceStream_TripleBuffer
: public SurfaceStream
{
protected:
SharedSurface* mStaging;
SharedSurface* mConsumer;
UniquePtr<SharedSurface> mStaging;
UniquePtr<SharedSurface> mConsumer;
// Returns true if we were able to wait, false if not
virtual void WaitForCompositor() {}
@ -188,9 +184,12 @@ protected:
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer)
explicit SurfaceStream_TripleBuffer(SurfaceStream* prevStream);
virtual ~SurfaceStream_TripleBuffer();
virtual bool CopySurfaceToProducer(SharedSurface* src, SurfaceFactory* factory);
virtual bool CopySurfaceToProducer(SharedSurface* src,
SurfaceFactory* factory) MOZ_OVERRIDE;
private:
// Common constructor code.
@ -199,11 +198,12 @@ private:
public:
// Done writing to prod, swap prod and staging
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
const gfx::IntSize& size);
const gfx::IntSize& size) MOZ_OVERRIDE;
virtual SharedSurface* SwapConsumer_NoWait();
virtual SharedSurface* SwapConsumer_NoWait() MOZ_OVERRIDE;
virtual void SurrenderSurfaces(SharedSurface*& producer, SharedSurface*& consumer);
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
UniquePtr<SharedSurface>* out_consumer) MOZ_OVERRIDE;
};
class SurfaceStream_TripleBuffer_Async
@ -213,6 +213,8 @@ protected:
virtual void WaitForCompositor() MOZ_OVERRIDE;
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer_Async)
explicit SurfaceStream_TripleBuffer_Async(SurfaceStream* prevStream);
virtual ~SurfaceStream_TripleBuffer_Async();
};

View File

@ -157,8 +157,10 @@ CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
// Copy our current surface to the current producer surface in our stream, then
// call SwapProducer to make a new buffer ready.
stream->CopySurfaceToProducer(aLayer->mTextureSurface, aLayer->mFactory);
stream->SwapProducer(aLayer->mFactory, gfx::IntSize(aSize.width, aSize.height));
stream->CopySurfaceToProducer(aLayer->mTextureSurface.get(),
aLayer->mFactory.get());
stream->SwapProducer(aLayer->mFactory.get(),
gfx::IntSize(aSize.width, aSize.height));
} else {
stream = screen->Stream();
}

View File

@ -47,7 +47,7 @@ ClientCanvasLayer::~ClientCanvasLayer()
mCanvasClient = nullptr;
}
if (mTextureSurface) {
delete mTextureSurface;
mTextureSurface = nullptr;
}
}
@ -73,13 +73,16 @@ ClientCanvasLayer::Initialize(const Data& aData)
SurfaceStreamType streamType =
SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread,
screen->PreserveBuffer());
SurfaceFactory* factory = nullptr;
UniquePtr<SurfaceFactory> factory = nullptr;
if (!gfxPrefs::WebGLForceLayersReadback()) {
switch (ClientManager()->AsShadowForwarder()->GetCompositorBackendType()) {
case mozilla::layers::LayersBackend::LAYERS_OPENGL: {
if (mGLContext->GetContextType() == GLContextType::EGL) {
#ifdef MOZ_WIDGET_GONK
factory = new SurfaceFactory_Gralloc(mGLContext, caps, ClientManager()->AsShadowForwarder());
factory = MakeUnique<SurfaceFactory_Gralloc>(mGLContext,
caps,
ClientManager()->AsShadowForwarder());
#else
bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
if (!isCrossProcess) {
@ -96,7 +99,8 @@ ClientCanvasLayer::Initialize(const Data& aData)
#ifdef XP_MACOSX
factory = SurfaceFactory_IOSurface::Create(mGLContext, caps);
#else
factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps);
GLContext* nullConsGL = nullptr; // Bug 1050044.
factory = MakeUnique<SurfaceFactory_GLTexture>(mGLContext, nullConsGL, caps);
#endif
}
break;
@ -117,26 +121,25 @@ ClientCanvasLayer::Initialize(const Data& aData)
if (mStream) {
// We're using a stream other than the one in the default screen
mFactory = factory;
mFactory = Move(factory);
if (!mFactory) {
// Absolutely must have a factory here, so create a basic one
mFactory = new SurfaceFactory_Basic(mGLContext, caps);
mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps);
}
gfx::IntSize size = gfx::IntSize(aData.mSize.width, aData.mSize.height);
mTextureSurface = SharedSurface_GLTexture::Create(mGLContext, mGLContext,
mGLContext->GetGLFormats(),
size, caps.alpha, aData.mTexID);
SharedSurface* producer = mStream->SwapProducer(mFactory, size);
SharedSurface* producer = mStream->SwapProducer(mFactory.get(), size);
if (!producer) {
// Fallback to basic factory
delete mFactory;
mFactory = new SurfaceFactory_Basic(mGLContext, caps);
producer = mStream->SwapProducer(mFactory, size);
mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps);
producer = mStream->SwapProducer(mFactory.get(), size);
MOZ_ASSERT(producer, "Failed to create initial canvas surface with basic factory");
}
} else if (factory) {
screen->Morph(factory, streamType);
screen->Morph(Move(factory), streamType);
}
}
}

View File

@ -101,8 +101,8 @@ protected:
RefPtr<CanvasClient> mCanvasClient;
gl::SharedSurface* mTextureSurface;
gl::SurfaceFactory* mFactory;
UniquePtr<gl::SharedSurface> mTextureSurface;
UniquePtr<gl::SurfaceFactory> mFactory;
friend class DeprecatedCanvasClient2D;
friend class CanvasClient2D;

View File

@ -51,7 +51,7 @@ CanvasLayerD3D10::Initialize(const Data& aData)
SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread,
screen->PreserveBuffer());
SurfaceFactory* factory = nullptr;
UniquePtr<SurfaceFactory> factory = nullptr;
if (!gfxPrefs::WebGLForceLayersReadback()) {
if (mGLContext->IsANGLE()) {
factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext,
@ -60,7 +60,7 @@ CanvasLayerD3D10::Initialize(const Data& aData)
}
if (factory) {
screen->Morph(factory, streamType);
screen->Morph(Move(factory), streamType);
}
} else if (aData.mDrawTarget) {
mDrawTarget = aData.mDrawTarget;