2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
|
2013-02-13 23:26:24 +00: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 15:07:46 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-12-10 16:12:18 +00:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2014-08-16 00:38:08 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-10-08 04:15:39 +00:00
|
|
|
#include "SharedSurface.h"
|
|
|
|
#include "SurfaceTypes.h"
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-06-05 00:15:38 +00:00
|
|
|
namespace layers {
|
2016-09-27 03:22:20 +00:00
|
|
|
class KnowsCompositor;
|
|
|
|
class LayersIPCChannel;
|
2015-06-05 00:15:38 +00:00
|
|
|
class SharedSurfaceTextureClient;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace layers
|
2015-06-05 00:15:38 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
namespace gl {
|
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
class GLContext;
|
|
|
|
class SharedSurface;
|
2014-10-08 04:01:51 +00:00
|
|
|
class ShSurfHandle;
|
|
|
|
class SurfaceFactory;
|
2014-07-11 22:10:49 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
class ReadBuffer {
|
|
|
|
public:
|
|
|
|
// Infallible, always non-null.
|
2014-08-16 00:38:07 +00:00
|
|
|
static UniquePtr<ReadBuffer> Create(GLContext* gl, const SurfaceCaps& caps,
|
|
|
|
const GLFormats& formats,
|
|
|
|
SharedSurface* surf);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
protected:
|
|
|
|
GLContext* const mGL;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
public:
|
2013-02-13 23:26:24 +00:00
|
|
|
const GLuint mFB;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
protected:
|
2013-02-13 23:26:24 +00:00
|
|
|
// mFB has the following attachments:
|
|
|
|
const GLuint mDepthRB;
|
|
|
|
const GLuint mStencilRB;
|
|
|
|
// note no mColorRB here: this is provided by mSurf.
|
2014-10-08 04:15:39 +00:00
|
|
|
SharedSurface* mSurf;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
ReadBuffer(GLContext* gl, GLuint fb, GLuint depthRB, GLuint stencilRB,
|
2014-07-11 22:10:49 +00:00
|
|
|
SharedSurface* surf)
|
2013-02-13 23:26:24 +00:00
|
|
|
: mGL(gl),
|
|
|
|
mFB(fb),
|
|
|
|
mDepthRB(depthRB),
|
|
|
|
mStencilRB(stencilRB),
|
|
|
|
mSurf(surf) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
public:
|
|
|
|
virtual ~ReadBuffer();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
// Cannot attach a surf of a different AttachType or Size than before.
|
2014-07-11 22:10:49 +00:00
|
|
|
void Attach(SharedSurface* surf);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-12-10 16:11:58 +00:00
|
|
|
const gfx::IntSize& Size() const;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
SharedSurface* SharedSurf() const { return mSurf; }
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-02-19 00:57:05 +00:00
|
|
|
void SetReadBuffer(GLenum mode) const;
|
2013-02-13 23:26:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GLScreenBuffer {
|
2018-11-30 10:46:48 +00:00
|
|
|
public:
|
2013-02-13 23:26:24 +00:00
|
|
|
// Infallible.
|
2014-08-16 00:38:07 +00:00
|
|
|
static UniquePtr<GLScreenBuffer> Create(GLContext* gl,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
const SurfaceCaps& caps);
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2014-08-16 00:38:07 +00:00
|
|
|
static UniquePtr<SurfaceFactory> CreateFactory(
|
|
|
|
GLContext* gl, const SurfaceCaps& caps,
|
2016-09-27 03:22:20 +00:00
|
|
|
layers::KnowsCompositor* compositorConnection,
|
2014-08-16 00:38:07 +00:00
|
|
|
const layers::TextureFlags& flags);
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2015-10-12 03:21:02 +00:00
|
|
|
protected:
|
|
|
|
GLContext* const mGL; // Owns us.
|
2018-11-30 10:46:48 +00:00
|
|
|
public:
|
2015-10-12 03:21:02 +00:00
|
|
|
const SurfaceCaps mCaps;
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
protected:
|
2014-08-16 00:38:08 +00:00
|
|
|
UniquePtr<SurfaceFactory> mFactory;
|
2014-10-08 04:01:07 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<layers::SharedSurfaceTextureClient> mBack;
|
|
|
|
RefPtr<layers::SharedSurfaceTextureClient> mFront;
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2014-08-16 00:38:08 +00:00
|
|
|
UniquePtr<ReadBuffer> mRead;
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
bool mNeedsBlit;
|
|
|
|
|
2015-02-19 00:57:05 +00:00
|
|
|
GLenum mUserReadBufferMode;
|
2015-07-31 19:56:32 +00:00
|
|
|
GLenum mUserDrawBufferMode;
|
2015-02-19 00:57:05 +00:00
|
|
|
|
2013-02-13 23:26:24 +00: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 00:15:38 +00:00
|
|
|
UniquePtr<SurfaceFactory> factory);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
|
|
|
public:
|
2013-02-13 23:26:24 +00:00
|
|
|
virtual ~GLScreenBuffer();
|
|
|
|
|
|
|
|
SurfaceFactory* Factory() const { return mFactory.get(); }
|
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
const RefPtr<layers::SharedSurfaceTextureClient>& Front() const {
|
2014-08-16 00:38:08 +00:00
|
|
|
return mFront;
|
2013-02-13 23:26:24 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
SharedSurface* SharedSurf() const {
|
|
|
|
MOZ_ASSERT(mRead);
|
2014-10-08 04:01:51 +00:00
|
|
|
return mRead->SharedSurf();
|
2014-10-08 04:01:07 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
bool ShouldPreserveBuffer() const { return mCaps.preserve; }
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2019-06-14 19:09:54 +00:00
|
|
|
GLuint DrawFB() const { return ReadFB(); }
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2014-07-11 22:10:49 +00:00
|
|
|
GLuint ReadFB() const { return mRead->mFB; }
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2015-01-12 23:05:21 +00:00
|
|
|
uint32_t DepthBits() const;
|
|
|
|
|
2016-04-25 20:17:25 +00:00
|
|
|
void DeletingFB(GLuint fb);
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
const gfx::IntSize& Size() const {
|
|
|
|
MOZ_ASSERT(mRead);
|
|
|
|
return mRead->Size();
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
bool IsReadBufferReady() const { return mRead.get() != nullptr; }
|
|
|
|
|
2018-08-24 15:32:12 +00:00
|
|
|
void BindAsFramebuffer(GLContext* const gl, GLenum target) const;
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
void RequireBlit();
|
|
|
|
void AssureBlitted();
|
|
|
|
void AfterDrawCall();
|
|
|
|
void BeforeReadCall();
|
|
|
|
|
|
|
|
bool CopyTexImage2D(GLenum target, GLint level, GLenum internalformat,
|
|
|
|
GLint x, GLint y, GLsizei width, GLsizei height,
|
|
|
|
GLint border);
|
|
|
|
|
2015-03-23 03:55:26 +00:00
|
|
|
void SetReadBuffer(GLenum userMode);
|
|
|
|
void SetDrawBuffer(GLenum userMode);
|
|
|
|
|
2015-02-19 00:57:05 +00:00
|
|
|
GLenum GetReadBufferMode() const { return mUserReadBufferMode; }
|
2015-07-31 19:56:32 +00:00
|
|
|
GLenum GetDrawBufferMode() const { return mUserDrawBufferMode; }
|
2015-02-19 00:57:05 +00:00
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
/**
|
2016-12-22 22:24:31 +00:00
|
|
|
* Attempts to read pixels from the current bound framebuffer, if
|
2014-07-11 22:10:49 +00:00
|
|
|
* it is backed by a SharedSurface.
|
2018-11-30 10:46:48 +00:00
|
|
|
*
|
2016-12-22 22:24:31 +00:00
|
|
|
* Returns true if the pixel data has been read back, false
|
|
|
|
* otherwise.
|
2018-11-30 10:46:48 +00:00
|
|
|
*/
|
2016-12-22 22:24:31 +00:00
|
|
|
bool ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type, GLvoid* pixels);
|
2016-04-01 06:06:33 +00:00
|
|
|
|
2013-07-18 03:24:15 +00:00
|
|
|
// Morph changes the factory used to create surfaces.
|
2016-06-11 01:37:07 +00:00
|
|
|
void Morph(UniquePtr<SurfaceFactory> newFactory);
|
2013-07-18 03:24:15 +00:00
|
|
|
|
2014-10-08 04:01:07 +00:00
|
|
|
protected:
|
|
|
|
// Returns false on error or inability to resize.
|
|
|
|
bool Swap(const gfx::IntSize& size);
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
public:
|
2013-12-10 16:12:18 +00:00
|
|
|
bool PublishFrame(const gfx::IntSize& size);
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2013-12-10 16:12:18 +00:00
|
|
|
bool Resize(const gfx::IntSize& size);
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
protected:
|
2013-12-10 16:12:18 +00:00
|
|
|
bool Attach(SharedSurface* surf, const gfx::IntSize& size);
|
2013-03-22 19:22:20 +00:00
|
|
|
|
2014-08-16 00:38:07 +00:00
|
|
|
UniquePtr<ReadBuffer> CreateRead(SharedSurface* surf);
|
2013-03-22 19:22:20 +00:00
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
public:
|
2014-08-16 00:38:07 +00: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 10:46:48 +00:00
|
|
|
*/
|
2013-02-13 23:26:24 +00:00
|
|
|
void BindFB(GLuint fb);
|
|
|
|
void BindDrawFB(GLuint fb);
|
2014-08-16 00:38:07 +00:00
|
|
|
void BindReadFB(GLuint fb);
|
2013-02-13 23:26:24 +00:00
|
|
|
GLuint GetFB() const;
|
|
|
|
GLuint GetDrawFB() const;
|
2014-08-16 00:38:07 +00:00
|
|
|
GLuint GetReadFB() const;
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
// Here `fb` is the actual framebuffer you want bound. Binding 0 will
|
|
|
|
// bind the (generally useless) default framebuffer.
|
2014-08-08 02:03:25 +00:00
|
|
|
void BindFB_Internal(GLuint fb);
|
2013-02-13 23:26:24 +00:00
|
|
|
void BindDrawFB_Internal(GLuint fb);
|
|
|
|
void BindReadFB_Internal(GLuint fb);
|
2014-10-14 21:49:49 +00:00
|
|
|
|
|
|
|
bool IsDrawFramebufferDefault() const;
|
|
|
|
bool IsReadFramebufferDefault() const;
|
2013-02-13 23:26:24 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
#endif // SCREEN_BUFFER_H_
|