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/. */
|
|
|
|
|
|
|
|
/* GLScreenBuffer is the abstraction for the "default framebuffer" used
|
|
|
|
* by an offscreen GLContext. Since it's only for offscreen GLContext's,
|
|
|
|
* it's only useful for things like WebGL, and is NOT used by the
|
|
|
|
* compositor's GLContext. Remember that GLContext provides an abstraction
|
|
|
|
* so that even if you want to draw to the 'screen', even if that's not
|
|
|
|
* actually the screen, just draw to 0. This GLScreenBuffer class takes the
|
|
|
|
* logic handling out of GLContext.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCREEN_BUFFER_H_
|
|
|
|
#define SCREEN_BUFFER_H_
|
|
|
|
|
|
|
|
#include "GLContextTypes.h"
|
|
|
|
#include "GLDefs.h"
|
2014-02-12 19:07:46 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-12-10 20:12:18 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2014-08-16 04:38:08 +04:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-10-08 08:15:39 +04:00
|
|
|
#include "SharedSurface.h"
|
|
|
|
#include "SurfaceTypes.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-06-05 03:15:38 +03:00
|
|
|
namespace layers {
|
2016-09-27 06:22:20 +03:00
|
|
|
class KnowsCompositor;
|
|
|
|
class LayersIPCChannel;
|
2015-06-05 03:15:38 +03:00
|
|
|
class SharedSurfaceTextureClient;
|
2020-01-09 01:19:16 +03:00
|
|
|
enum class LayersBackend : int8_t;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2015-06-05 03:15:38 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
namespace gl {
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
class GLContext;
|
|
|
|
class SharedSurface;
|
2014-10-08 08:01:51 +04:00
|
|
|
class ShSurfHandle;
|
|
|
|
class SurfaceFactory;
|
2014-07-12 02:10:49 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
class ReadBuffer {
|
|
|
|
public:
|
|
|
|
// Infallible, always non-null.
|
2014-08-16 04:38:07 +04:00
|
|
|
static UniquePtr<ReadBuffer> Create(GLContext* gl, const SurfaceCaps& caps,
|
|
|
|
const GLFormats& formats,
|
|
|
|
SharedSurface* surf);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
protected:
|
|
|
|
GLContext* const mGL;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
public:
|
2013-02-14 03:26:24 +04:00
|
|
|
const GLuint mFB;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
protected:
|
2013-02-14 03:26:24 +04:00
|
|
|
// mFB has the following attachments:
|
|
|
|
const GLuint mDepthRB;
|
|
|
|
const GLuint mStencilRB;
|
|
|
|
// note no mColorRB here: this is provided by mSurf.
|
2014-10-08 08:15:39 +04:00
|
|
|
SharedSurface* mSurf;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
ReadBuffer(GLContext* gl, GLuint fb, GLuint depthRB, GLuint stencilRB,
|
2014-07-12 02:10:49 +04:00
|
|
|
SharedSurface* surf)
|
2013-02-14 03:26:24 +04:00
|
|
|
: mGL(gl),
|
|
|
|
mFB(fb),
|
|
|
|
mDepthRB(depthRB),
|
|
|
|
mStencilRB(stencilRB),
|
|
|
|
mSurf(surf) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
public:
|
|
|
|
virtual ~ReadBuffer();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
// Cannot attach a surf of a different AttachType or Size than before.
|
2014-07-12 02:10:49 +04:00
|
|
|
void Attach(SharedSurface* surf);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& Size() const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
SharedSurface* SharedSurf() const { return mSurf; }
|
2013-02-14 03:26:24 +04:00
|
|
|
};
|
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
class GLScreenBuffer final {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2013-02-14 03:26:24 +04:00
|
|
|
// Infallible.
|
2014-08-16 04:38:07 +04:00
|
|
|
static UniquePtr<GLScreenBuffer> Create(GLContext* gl,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
const SurfaceCaps& caps);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-08-16 04:38:07 +04:00
|
|
|
static UniquePtr<SurfaceFactory> CreateFactory(
|
|
|
|
GLContext* gl, const SurfaceCaps& caps,
|
2016-09-27 06:22:20 +03:00
|
|
|
layers::KnowsCompositor* compositorConnection,
|
2014-08-16 04:38:07 +04:00
|
|
|
const layers::TextureFlags& flags);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2020-01-09 01:19:14 +03:00
|
|
|
static UniquePtr<SurfaceFactory> CreateFactory(
|
|
|
|
GLContext* gl, const SurfaceCaps& caps,
|
|
|
|
layers::LayersIPCChannel* ipcChannel, layers::LayersBackend backend,
|
|
|
|
bool useANGLE, const layers::TextureFlags& flags);
|
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
private:
|
2015-10-12 06:21:02 +03:00
|
|
|
GLContext* const mGL; // Owns us.
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2015-10-12 06:21:02 +03:00
|
|
|
const SurfaceCaps mCaps;
|
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
private:
|
2014-08-16 04:38:08 +04:00
|
|
|
UniquePtr<SurfaceFactory> mFactory;
|
2014-10-08 08:01:07 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<layers::SharedSurfaceTextureClient> mBack;
|
|
|
|
RefPtr<layers::SharedSurfaceTextureClient> mFront;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-08-16 04:38:08 +04:00
|
|
|
UniquePtr<ReadBuffer> mRead;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
// Below are the parts that help us pretend to be framebuffer 0:
|
|
|
|
GLuint mUserDrawFB;
|
|
|
|
GLuint mUserReadFB;
|
|
|
|
GLuint mInternalDrawFB;
|
|
|
|
GLuint mInternalReadFB;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mInInternalMode_DrawFB;
|
|
|
|
bool mInInternalMode_ReadFB;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GLScreenBuffer(GLContext* gl, const SurfaceCaps& caps,
|
2015-06-05 03:15:38 +03:00
|
|
|
UniquePtr<SurfaceFactory> factory);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
public:
|
2013-02-14 03:26:24 +04:00
|
|
|
virtual ~GLScreenBuffer();
|
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
const auto& Factory() const { return mFactory; }
|
|
|
|
const auto& Front() const { return mFront; }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
SharedSurface* SharedSurf() const {
|
|
|
|
MOZ_ASSERT(mRead);
|
2014-10-08 08:01:51 +04:00
|
|
|
return mRead->SharedSurf();
|
2014-10-08 08:01:07 +04:00
|
|
|
}
|
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
private:
|
2019-06-14 22:09:54 +03:00
|
|
|
GLuint DrawFB() const { return ReadFB(); }
|
2014-07-12 02:10:49 +04:00
|
|
|
GLuint ReadFB() const { return mRead->mFB; }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
public:
|
2016-04-25 23:17:25 +03:00
|
|
|
void DeletingFB(GLuint fb);
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
const gfx::IntSize& Size() const {
|
|
|
|
MOZ_ASSERT(mRead);
|
|
|
|
return mRead->Size();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
bool IsReadBufferReady() const { return mRead.get() != nullptr; }
|
|
|
|
|
|
|
|
bool CopyTexImage2D(GLenum target, GLint level, GLenum internalformat,
|
|
|
|
GLint x, GLint y, GLsizei width, GLsizei height,
|
|
|
|
GLint border);
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2016-12-23 01:24:31 +03:00
|
|
|
* Attempts to read pixels from the current bound framebuffer, if
|
2014-07-12 02:10:49 +04:00
|
|
|
* it is backed by a SharedSurface.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2016-12-23 01:24:31 +03:00
|
|
|
* Returns true if the pixel data has been read back, false
|
|
|
|
* otherwise.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2016-12-23 01:24:31 +03:00
|
|
|
bool ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type, GLvoid* pixels);
|
2016-04-01 09:06:33 +03:00
|
|
|
|
2013-07-18 07:24:15 +04:00
|
|
|
// Morph changes the factory used to create surfaces.
|
2016-06-11 04:37:07 +03:00
|
|
|
void Morph(UniquePtr<SurfaceFactory> newFactory);
|
2013-07-18 07:24:15 +04:00
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
private:
|
2014-10-08 08:01:07 +04:00
|
|
|
// Returns false on error or inability to resize.
|
|
|
|
bool Swap(const gfx::IntSize& size);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
2020-02-16 01:48:36 +03:00
|
|
|
bool PublishFrame(const gfx::IntSize& size) { return Swap(size); }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2013-12-10 20:12:18 +04:00
|
|
|
bool Resize(const gfx::IntSize& size);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2020-02-16 01:48:36 +03:00
|
|
|
private:
|
2013-12-10 20:12:18 +04:00
|
|
|
bool Attach(SharedSurface* surf, const gfx::IntSize& size);
|
2013-03-22 23:22:20 +04:00
|
|
|
|
2014-08-16 04:38:07 +04:00
|
|
|
UniquePtr<ReadBuffer> CreateRead(SharedSurface* surf);
|
2013-03-22 23:22:20 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-08-16 04:38:07 +04:00
|
|
|
/* `fb` in these functions is the framebuffer the GLContext is hoping to
|
|
|
|
* bind. When this is 0, we intercept the call and bind our own
|
|
|
|
* framebuffers. As a client of these functions, just bind 0 when you want
|
|
|
|
* to draw to the default framebuffer/'screen'.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2013-02-14 03:26:24 +04:00
|
|
|
void BindFB(GLuint fb);
|
|
|
|
void BindDrawFB(GLuint fb);
|
2014-08-16 04:38:07 +04:00
|
|
|
void BindReadFB(GLuint fb);
|
2013-02-14 03:26:24 +04:00
|
|
|
GLuint GetFB() const;
|
|
|
|
GLuint GetDrawFB() const;
|
2014-08-16 04:38:07 +04:00
|
|
|
GLuint GetReadFB() const;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
// Here `fb` is the actual framebuffer you want bound. Binding 0 will
|
|
|
|
// bind the (generally useless) default framebuffer.
|
|
|
|
void BindReadFB_Internal(GLuint fb);
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
#endif // SCREEN_BUFFER_H_
|