2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
|
2013-02-14 03:26:24 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* SharedSurface abstracts an actual surface (can be a GL texture, but
|
|
|
|
* not necessarily) that handles sharing.
|
|
|
|
* Its specializations are:
|
|
|
|
* SharedSurface_Basic (client-side bitmap, does readback)
|
|
|
|
* SharedSurface_GLTexture
|
|
|
|
* SharedSurface_EGLImage
|
|
|
|
* SharedSurface_ANGLEShareHandle
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHARED_SURFACE_H_
|
|
|
|
#define SHARED_SURFACE_H_
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
#include <queue>
|
2015-06-05 03:15:38 +03:00
|
|
|
#include <set>
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2014-07-12 02:10:49 +04:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
#include "GLContext.h" // Bug 1635644
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "GLContextTypes.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
#include "GLDefs.h"
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-09-03 02:15:41 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2013-12-10 20:11:58 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2015-10-12 06:21:02 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2014-08-16 04:38:08 +04:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-08-16 04:38:08 +04:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
#include "SurfaceTypes.h"
|
|
|
|
|
2014-09-03 02:15:41 +04:00
|
|
|
class nsIThread;
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
namespace mozilla {
|
2014-10-11 01:36:17 +04:00
|
|
|
namespace gfx {
|
2015-10-12 06:21:03 +03:00
|
|
|
class DataSourceSurface;
|
2014-10-11 01:36:17 +04:00
|
|
|
class DrawTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2015-06-05 03:15:38 +03:00
|
|
|
|
|
|
|
namespace layers {
|
2020-06-15 21:25:55 +03:00
|
|
|
class KnowsCompositor;
|
|
|
|
enum class LayersBackend : int8_t;
|
2016-09-27 06:22:20 +03:00
|
|
|
class LayersIPCChannel;
|
2015-06-05 03:15:38 +03:00
|
|
|
class SharedSurfaceTextureClient;
|
|
|
|
class SurfaceDescriptor;
|
|
|
|
class TextureClient;
|
2020-06-15 21:25:55 +03:00
|
|
|
enum class TextureFlags : uint32_t;
|
|
|
|
enum class TextureType : int8_t;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2015-06-05 03:15:38 +03:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
namespace gl {
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
class MozFramebuffer;
|
|
|
|
struct ScopedBindFramebuffer;
|
2013-02-14 03:26:24 +04:00
|
|
|
class SurfaceFactory;
|
2020-06-15 21:25:55 +03:00
|
|
|
|
|
|
|
struct PartialSharedSurfaceDesc {
|
|
|
|
const WeakPtr<GLContext> gl;
|
|
|
|
const SharedSurfaceType type;
|
|
|
|
const layers::TextureType consumerType;
|
|
|
|
const bool canRecycle;
|
|
|
|
};
|
|
|
|
struct SharedSurfaceDesc : public PartialSharedSurfaceDesc {
|
|
|
|
gfx::IntSize size = {};
|
|
|
|
};
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
class SharedSurface {
|
2014-07-12 02:10:49 +04:00
|
|
|
public:
|
2020-06-15 21:25:55 +03:00
|
|
|
const SharedSurfaceDesc mDesc;
|
|
|
|
const UniquePtr<MozFramebuffer> mFb; // null if we should use fb=0.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
protected:
|
2020-06-15 21:25:55 +03:00
|
|
|
bool mIsLocked = false;
|
|
|
|
bool mIsProducerAcquired = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
SharedSurface(const SharedSurfaceDesc&, UniquePtr<MozFramebuffer>);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
public:
|
2014-08-16 04:38:08 +04:00
|
|
|
virtual ~SharedSurface();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-09 03:44:17 +03:00
|
|
|
bool IsLocked() const { return mIsLocked; }
|
2015-10-19 19:26:26 +03:00
|
|
|
bool IsProducerAcquired() const { return mIsProducerAcquired; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-19 19:26:26 +03:00
|
|
|
// This locks the SharedSurface as the production buffer for the context.
|
|
|
|
// This is needed by backends which use PBuffers and/or EGLSurfaces.
|
2014-07-12 02:10:49 +04:00
|
|
|
void LockProd();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-19 19:26:26 +03:00
|
|
|
// Unlocking is harmless if we're already unlocked.
|
2013-02-14 03:26:24 +04:00
|
|
|
void UnlockProd();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-19 19:26:26 +03:00
|
|
|
// This surface has been moved to the front buffer and will not be locked
|
|
|
|
// again until it is recycled. Do any finalization steps here.
|
|
|
|
virtual void Commit() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-19 19:26:26 +03:00
|
|
|
protected:
|
2020-06-15 21:25:55 +03:00
|
|
|
virtual void LockProdImpl(){};
|
|
|
|
virtual void UnlockProdImpl(){};
|
|
|
|
|
|
|
|
virtual void ProducerAcquireImpl(){};
|
|
|
|
virtual void ProducerReleaseImpl(){};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-09 03:44:17 +03:00
|
|
|
virtual void ProducerReadAcquireImpl() { ProducerAcquireImpl(); }
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual void ProducerReadReleaseImpl() { ProducerReleaseImpl(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
public:
|
2016-01-06 02:57:44 +03:00
|
|
|
void ProducerAcquire() {
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(!mIsProducerAcquired);
|
|
|
|
ProducerAcquireImpl();
|
|
|
|
mIsProducerAcquired = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-06-05 03:15:38 +03:00
|
|
|
void ProducerRelease() {
|
2014-10-10 00:33:22 +04:00
|
|
|
MOZ_ASSERT(mIsProducerAcquired);
|
2015-06-05 03:15:38 +03:00
|
|
|
ProducerReleaseImpl();
|
2013-02-14 03:26:24 +04:00
|
|
|
mIsProducerAcquired = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-07-12 02:10:49 +04:00
|
|
|
void ProducerReadAcquire() {
|
2015-06-05 03:15:38 +03:00
|
|
|
MOZ_ASSERT(!mIsProducerAcquired);
|
2014-07-12 02:10:49 +04:00
|
|
|
ProducerReadAcquireImpl();
|
2017-03-04 00:14:27 +03:00
|
|
|
mIsProducerAcquired = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-04 00:14:27 +03:00
|
|
|
void ProducerReadRelease() {
|
|
|
|
MOZ_ASSERT(mIsProducerAcquired);
|
2015-06-05 03:15:38 +03:00
|
|
|
ProducerReadReleaseImpl();
|
2017-03-04 00:14:27 +03:00
|
|
|
mIsProducerAcquired = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-03-04 00:14:27 +03:00
|
|
|
// This function waits until the buffer is no longer being used.
|
|
|
|
// To optimize the performance, some implementaions recycle SharedSurfaces
|
|
|
|
// even when its buffer is still being used.
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual void WaitForBufferOwnership() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-06 02:57:44 +03:00
|
|
|
// Returns true if the buffer is available.
|
2018-07-28 13:33:55 +03:00
|
|
|
// You can call WaitForBufferOwnership to wait for availability.
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual bool IsBufferAvailable() const { return true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-10 00:33:22 +04:00
|
|
|
virtual bool NeedsIndirectReads() const { return false; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
virtual Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-03 02:15:41 +04:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
// -
|
2020-06-11 02:43:35 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
class SurfaceFactory {
|
2020-06-11 02:43:35 +03:00
|
|
|
public:
|
2020-06-15 21:25:55 +03:00
|
|
|
const PartialSharedSurfaceDesc mDesc;
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
protected:
|
|
|
|
Mutex mMutex;
|
2020-06-11 19:44:20 +03:00
|
|
|
|
|
|
|
public:
|
2020-06-15 21:25:55 +03:00
|
|
|
static UniquePtr<SurfaceFactory> Create(GLContext*, layers::TextureType);
|
2014-08-16 04:38:08 +04:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
protected:
|
2020-06-15 21:25:55 +03:00
|
|
|
explicit SurfaceFactory(const PartialSharedSurfaceDesc&);
|
2014-08-16 04:38:08 +04:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
public:
|
|
|
|
virtual ~SurfaceFactory();
|
2014-08-16 04:38:08 +04:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
protected:
|
2020-06-15 21:25:55 +03:00
|
|
|
virtual UniquePtr<SharedSurface> CreateSharedImpl(
|
|
|
|
const SharedSurfaceDesc&) = 0;
|
2014-07-12 02:10:49 +04:00
|
|
|
|
|
|
|
public:
|
2020-06-15 21:25:55 +03:00
|
|
|
UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) {
|
|
|
|
return CreateSharedImpl({mDesc, size});
|
|
|
|
}
|
2020-06-11 19:44:20 +03:00
|
|
|
};
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
template <typename T>
|
|
|
|
inline UniquePtr<T> AsUnique(T* const p) {
|
|
|
|
return UniquePtr<T>(p);
|
|
|
|
}
|
2014-10-11 01:36:17 +04:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
#endif // SHARED_SURFACE_H_
|