2013-02-13 15:26:24 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef SURFACESTREAM_H_
|
|
|
|
#define SURFACESTREAM_H_
|
|
|
|
|
|
|
|
#include <stack>
|
|
|
|
#include <set>
|
2013-03-22 12:22:20 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
2013-02-13 15:26:24 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-12-10 08:12:18 -08:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2014-03-05 13:49:37 -08:00
|
|
|
#include "mozilla/GenericRefCounted.h"
|
2014-08-15 17:38:08 -07:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-02-13 15:26:24 -08:00
|
|
|
#include "SurfaceTypes.h"
|
2014-08-15 17:38:08 -07:00
|
|
|
#include "SharedSurface.h"
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-09-04 05:14:52 -07:00
|
|
|
|
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
2013-02-13 15:26:24 -08:00
|
|
|
class SharedSurface;
|
|
|
|
class SurfaceFactory;
|
|
|
|
|
|
|
|
// Owned by: ScreenBuffer
|
2014-03-05 13:49:37 -08:00
|
|
|
class SurfaceStream : public GenericAtomicRefCounted
|
2013-02-13 15:26:24 -08:00
|
|
|
{
|
|
|
|
public:
|
2014-03-09 11:40:49 -07:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream)
|
2013-02-13 15:26:24 -08:00
|
|
|
typedef enum {
|
|
|
|
MainThread,
|
|
|
|
OffMainThread
|
|
|
|
} OMTC;
|
|
|
|
|
|
|
|
static SurfaceStreamType ChooseGLStreamType(OMTC omtc,
|
|
|
|
bool preserveBuffer);
|
|
|
|
|
2014-08-15 17:38:07 -07:00
|
|
|
static TemporaryRef<SurfaceStream> CreateForType(SurfaceStreamType type,
|
|
|
|
mozilla::gl::GLContext* glContext,
|
|
|
|
SurfaceStream* prevStream = nullptr);
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-04-07 06:35:21 -07:00
|
|
|
const SurfaceStreamType mType;
|
2013-07-17 10:03:18 -07:00
|
|
|
|
|
|
|
mozilla::gl::GLContext* GLContext() const { return mGLContext; }
|
2014-03-05 13:49:37 -08:00
|
|
|
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
protected:
|
|
|
|
// |mProd| is owned by us, but can be ripped away when
|
|
|
|
// creating a new GLStream from this one.
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface> mProducer;
|
|
|
|
#ifdef DEBUG
|
2013-02-13 15:26:24 -08:00
|
|
|
std::set<SharedSurface*> mSurfaces;
|
2014-08-15 17:38:08 -07:00
|
|
|
#endif
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtrQueue<SharedSurface> mScraps;
|
2014-06-06 21:02:28 -07:00
|
|
|
mutable Monitor mMonitor;
|
|
|
|
bool mIsAlive;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-07-17 10:03:18 -07:00
|
|
|
// Do not use this. It exists solely so we can ref it in CanvasClientWebGL::Update()
|
|
|
|
// before sent up to the compositor. You have been warned (Bug 894405)
|
|
|
|
mozilla::gl::GLContext* mGLContext;
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// |previous| can be null, indicating this is the first one.
|
|
|
|
// Otherwise, we pull in |mProd| from |previous| an our initial surface.
|
2014-08-15 17:38:08 -07:00
|
|
|
SurfaceStream(SurfaceStreamType type, SurfaceStream* prevStream);
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SurfaceStream();
|
|
|
|
|
|
|
|
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.
|
2014-08-15 17:38:08 -07:00
|
|
|
void MoveTo(UniquePtr<SharedSurface>* slotFrom,
|
|
|
|
UniquePtr<SharedSurface>* slotTo);
|
2013-12-10 08:12:18 -08:00
|
|
|
void New(SurfaceFactory* factory, const gfx::IntSize& size,
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface>* surfSlot);
|
|
|
|
void Delete(UniquePtr<SharedSurface>* surfSlot);
|
|
|
|
void Recycle(SurfaceFactory* factory,
|
|
|
|
UniquePtr<SharedSurface>* surfSlot);
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
// Surrender control of a surface, and return it for use elsewhere.
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface> Surrender(UniquePtr<SharedSurface>* surfSlot);
|
2013-02-13 15:26:24 -08:00
|
|
|
// Absorb control of a surface from elsewhere, clears its old location.
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface> Absorb(UniquePtr<SharedSurface>* surfSlot);
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
// 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.
|
2014-08-15 17:38:08 -07:00
|
|
|
void Scrap(UniquePtr<SharedSurface>* surfSlot);
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
// Not thread-safe.
|
|
|
|
void RecycleScraps(SurfaceFactory* factory);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/* Note that ownership of the returned surfaces below
|
|
|
|
* transfers to the caller.
|
|
|
|
* SwapProd returns null on failure. Returning null doesn't mean nothing
|
|
|
|
* happened, but rather that a surface allocation failed. After returning
|
|
|
|
* null, we must be able to call SwapProducer again with better args
|
|
|
|
* and have everything work again.
|
|
|
|
* One common failure is asking for a too-large |size|.
|
|
|
|
*/
|
|
|
|
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
|
2013-12-10 08:12:18 -08:00
|
|
|
const gfx::IntSize& size) = 0;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-12-10 08:12:18 -08:00
|
|
|
virtual SharedSurface* Resize(SurfaceFactory* factory, const gfx::IntSize& size);
|
2013-03-22 12:22:20 -07:00
|
|
|
|
2014-03-05 13:49:37 -08:00
|
|
|
virtual bool CopySurfaceToProducer(SharedSurface* src, SurfaceFactory* factory) { MOZ_ASSERT(0); return false; }
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
protected:
|
|
|
|
// SwapCons will return the same surface more than once,
|
|
|
|
// if nothing new has been published.
|
|
|
|
virtual SharedSurface* SwapConsumer_NoWait() = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual SharedSurface* SwapConsumer();
|
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
|
|
|
|
UniquePtr<SharedSurface>* out_consumer) = 0;
|
2013-02-13 15:26:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Not thread-safe. Don't use cross-threads.
|
|
|
|
class SurfaceStream_SingleBuffer
|
|
|
|
: public SurfaceStream
|
|
|
|
{
|
|
|
|
protected:
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface> mConsumer; // Only present after resize-swap.
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
public:
|
2014-03-09 11:40:49 -07:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_SingleBuffer)
|
2014-08-15 17:38:08 -07:00
|
|
|
|
2014-08-07 18:17:30 -07:00
|
|
|
explicit SurfaceStream_SingleBuffer(SurfaceStream* prevStream);
|
2013-02-13 15:26:24 -08:00
|
|
|
virtual ~SurfaceStream_SingleBuffer();
|
|
|
|
|
|
|
|
/* Since we're non-OMTC, we know the order of execution here:
|
|
|
|
* SwapProd gets called in UpdateSurface, followed by
|
|
|
|
* SwapCons being called in Render.
|
|
|
|
*/
|
|
|
|
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
|
2014-08-15 17:38:08 -07:00
|
|
|
const gfx::IntSize& size) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual SharedSurface* SwapConsumer_NoWait() MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
|
|
|
|
UniquePtr<SharedSurface>* out_consumer) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Our hero for preserveDrawingBuffer=true.
|
|
|
|
class SurfaceStream_TripleBuffer_Copy
|
|
|
|
: public SurfaceStream
|
|
|
|
{
|
|
|
|
protected:
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface> mStaging;
|
|
|
|
UniquePtr<SharedSurface> mConsumer;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
|
|
|
public:
|
2014-03-09 11:40:49 -07:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer_Copy)
|
2014-08-15 17:38:08 -07:00
|
|
|
|
2014-08-07 18:17:30 -07:00
|
|
|
explicit SurfaceStream_TripleBuffer_Copy(SurfaceStream* prevStream);
|
2013-02-13 15:26:24 -08:00
|
|
|
virtual ~SurfaceStream_TripleBuffer_Copy();
|
|
|
|
|
|
|
|
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
|
2014-08-15 17:38:08 -07:00
|
|
|
const gfx::IntSize& size) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual SharedSurface* SwapConsumer_NoWait() MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
|
|
|
|
UniquePtr<SharedSurface>* out_consumer) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SurfaceStream_TripleBuffer
|
|
|
|
: public SurfaceStream
|
|
|
|
{
|
|
|
|
protected:
|
2014-08-15 17:38:08 -07:00
|
|
|
UniquePtr<SharedSurface> mStaging;
|
|
|
|
UniquePtr<SharedSurface> mConsumer;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-04-14 15:37:06 -07:00
|
|
|
// Returns true if we were able to wait, false if not
|
2014-05-13 21:10:00 -07:00
|
|
|
virtual void WaitForCompositor() {}
|
2014-04-14 15:37:06 -07:00
|
|
|
|
2013-04-07 06:35:21 -07:00
|
|
|
// To support subclasses initializing the mType.
|
2014-06-06 21:02:28 -07:00
|
|
|
SurfaceStream_TripleBuffer(SurfaceStreamType type, SurfaceStream* prevStream);
|
2013-04-07 06:35:21 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
public:
|
2014-03-09 11:40:49 -07:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer)
|
2014-08-15 17:38:08 -07:00
|
|
|
|
2014-08-07 18:17:30 -07:00
|
|
|
explicit SurfaceStream_TripleBuffer(SurfaceStream* prevStream);
|
2013-02-13 15:26:24 -08:00
|
|
|
virtual ~SurfaceStream_TripleBuffer();
|
2014-08-15 17:38:08 -07:00
|
|
|
|
|
|
|
virtual bool CopySurfaceToProducer(SharedSurface* src,
|
|
|
|
SurfaceFactory* factory) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-04-07 06:35:21 -07:00
|
|
|
private:
|
|
|
|
// Common constructor code.
|
|
|
|
void Init(SurfaceStream* prevStream);
|
|
|
|
|
|
|
|
public:
|
2013-02-13 15:26:24 -08:00
|
|
|
// Done writing to prod, swap prod and staging
|
|
|
|
virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
|
2014-08-15 17:38:08 -07:00
|
|
|
const gfx::IntSize& size) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual SharedSurface* SwapConsumer_NoWait() MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-08-15 17:38:08 -07:00
|
|
|
virtual void SurrenderSurfaces(UniquePtr<SharedSurface>* out_producer,
|
|
|
|
UniquePtr<SharedSurface>* out_consumer) MOZ_OVERRIDE;
|
2013-02-13 15:26:24 -08:00
|
|
|
};
|
|
|
|
|
2014-04-14 15:37:06 -07:00
|
|
|
class SurfaceStream_TripleBuffer_Async
|
|
|
|
: public SurfaceStream_TripleBuffer
|
|
|
|
{
|
|
|
|
protected:
|
2014-05-13 21:10:00 -07:00
|
|
|
virtual void WaitForCompositor() MOZ_OVERRIDE;
|
2014-04-14 15:37:06 -07:00
|
|
|
|
|
|
|
public:
|
2014-08-15 17:38:08 -07:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer_Async)
|
|
|
|
|
2014-08-07 18:17:30 -07:00
|
|
|
explicit SurfaceStream_TripleBuffer_Async(SurfaceStream* prevStream);
|
2014-04-14 15:37:06 -07:00
|
|
|
virtual ~SurfaceStream_TripleBuffer_Async();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-11 15:10:49 -07:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2014-07-11 15:10:49 -07:00
|
|
|
#endif // SURFACESTREAM_H_
|