2013-02-14 03:26:24 +04: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/. */
|
|
|
|
|
|
|
|
/* 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 {
|
|
|
|
class SharedSurfaceTextureClient;
|
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 DrawBuffer
|
|
|
|
{
|
|
|
|
public:
|
2014-04-29 05:11:14 +04:00
|
|
|
// Fallible!
|
|
|
|
// But it may return true with *out_buffer==nullptr if unneeded.
|
|
|
|
static bool Create(GLContext* const gl,
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
const GLFormats& formats,
|
|
|
|
const gfx::IntSize& size,
|
2014-08-16 04:38:07 +04:00
|
|
|
UniquePtr<DrawBuffer>* out_buffer);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
GLContext* const mGL;
|
2014-07-12 02:10:49 +04:00
|
|
|
public:
|
2013-12-10 20:12:18 +04:00
|
|
|
const gfx::IntSize mSize;
|
2015-01-13 02:05:21 +03:00
|
|
|
const GLsizei mSamples;
|
2013-02-14 03:26:24 +04:00
|
|
|
const GLuint mFB;
|
2014-07-12 02:10:49 +04:00
|
|
|
protected:
|
2013-02-14 03:26:24 +04:00
|
|
|
const GLuint mColorMSRB;
|
|
|
|
const GLuint mDepthRB;
|
|
|
|
const GLuint mStencilRB;
|
|
|
|
|
|
|
|
DrawBuffer(GLContext* gl,
|
2013-12-10 20:12:18 +04:00
|
|
|
const gfx::IntSize& size,
|
2015-01-13 02:05:21 +03:00
|
|
|
GLsizei samples,
|
2013-02-14 03:26:24 +04:00
|
|
|
GLuint fb,
|
|
|
|
GLuint colorMSRB,
|
|
|
|
GLuint depthRB,
|
|
|
|
GLuint stencilRB)
|
|
|
|
: mGL(gl)
|
|
|
|
, mSize(size)
|
2015-01-13 02:05:21 +03:00
|
|
|
, mSamples(samples)
|
2013-02-14 03:26:24 +04:00
|
|
|
, mFB(fb)
|
|
|
|
, mColorMSRB(colorMSRB)
|
|
|
|
, mDepthRB(depthRB)
|
|
|
|
, mStencilRB(stencilRB)
|
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~DrawBuffer();
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
GLContext* const mGL;
|
2014-07-12 02:10:49 +04:00
|
|
|
public:
|
2013-02-14 03:26:24 +04:00
|
|
|
const GLuint mFB;
|
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;
|
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)
|
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~ReadBuffer();
|
|
|
|
|
|
|
|
// Cannot attach a surf of a different AttachType or Size than before.
|
2014-07-12 02:10:49 +04:00
|
|
|
void Attach(SharedSurface* surf);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& Size() const;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
SharedSurface* SharedSurf() const {
|
2013-02-14 03:26:24 +04:00
|
|
|
return mSurf;
|
|
|
|
}
|
2015-02-19 03:57:05 +03:00
|
|
|
|
|
|
|
void SetReadBuffer(GLenum mode) const;
|
2013-02-14 03:26:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GLScreenBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// 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
|
|
|
|
|
|
|
protected:
|
2014-08-16 04:38:07 +04:00
|
|
|
GLContext* const mGL; // Owns us.
|
2014-07-12 02:10:49 +04:00
|
|
|
public:
|
|
|
|
const SurfaceCaps mCaps;
|
|
|
|
protected:
|
2014-08-16 04:38:08 +04:00
|
|
|
UniquePtr<SurfaceFactory> mFactory;
|
2014-10-08 08:01:07 +04:00
|
|
|
|
2015-06-05 03:15:38 +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<DrawBuffer> mDraw;
|
|
|
|
UniquePtr<ReadBuffer> mRead;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
bool mNeedsBlit;
|
|
|
|
|
2015-02-19 03:57:05 +03:00
|
|
|
GLenum mUserReadBufferMode;
|
|
|
|
|
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);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~GLScreenBuffer();
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
SurfaceFactory* Factory() const {
|
2014-08-16 04:38:08 +04:00
|
|
|
return mFactory.get();
|
2013-02-14 03:26:24 +04:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
const RefPtr<layers::SharedSurfaceTextureClient>& Front() const {
|
2014-10-08 08:01:51 +04:00
|
|
|
return mFront;
|
2014-10-08 08:01:07 +04:00
|
|
|
}
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
SharedSurface* SharedSurf() const {
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(mRead);
|
|
|
|
return mRead->SharedSurf();
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:01:07 +04:00
|
|
|
bool ShouldPreserveBuffer() const {
|
2013-02-14 03:26:24 +04:00
|
|
|
return mCaps.preserve;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLuint DrawFB() const {
|
|
|
|
if (!mDraw)
|
|
|
|
return ReadFB();
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
return mDraw->mFB;
|
2013-02-14 03:26:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GLuint ReadFB() const {
|
2014-07-12 02:10:49 +04:00
|
|
|
return mRead->mFB;
|
2013-02-14 03:26:24 +04:00
|
|
|
}
|
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
GLsizei Samples() const {
|
|
|
|
if (!mDraw)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return mDraw->mSamples;
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
void DeletingFB(GLuint fb);
|
|
|
|
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& Size() const {
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(mRead);
|
2014-07-12 02:10:49 +04:00
|
|
|
MOZ_ASSERT(!mDraw || mDraw->mSize == mRead->Size());
|
2013-02-14 03:26:24 +04:00
|
|
|
return mRead->Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BindAsFramebuffer(GLContext* const gl, GLenum target) const;
|
|
|
|
|
|
|
|
void RequireBlit();
|
|
|
|
void AssureBlitted();
|
|
|
|
void AfterDrawCall();
|
|
|
|
void BeforeReadCall();
|
|
|
|
|
2015-03-23 06:55:26 +03:00
|
|
|
bool CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x,
|
|
|
|
GLint y, GLsizei width, GLsizei height, GLint border);
|
|
|
|
|
2015-02-19 03:57:05 +03:00
|
|
|
void SetReadBuffer(GLenum userMode);
|
|
|
|
|
2013-07-18 07:24:15 +04: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.
|
2013-07-18 07:24:15 +04:00
|
|
|
*
|
|
|
|
* Returns true if the pixel data has been read back, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
bool ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type, GLvoid *pixels);
|
|
|
|
|
2014-10-08 08:01:07 +04:00
|
|
|
// Morph changes the factory used to create surfaces.
|
|
|
|
void Morph(UniquePtr<SurfaceFactory> newFactory);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Returns false on error or inability to resize.
|
2013-12-10 20:12:18 +04:00
|
|
|
bool Swap(const gfx::IntSize& size);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
2013-12-10 20:12:18 +04:00
|
|
|
bool PublishFrame(const gfx::IntSize& size);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2013-12-10 20:12:18 +04:00
|
|
|
bool Resize(const gfx::IntSize& size);
|
2013-03-22 23:22:20 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
protected:
|
2014-08-16 04:38:07 +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
|
|
|
bool CreateDraw(const gfx::IntSize& size, UniquePtr<DrawBuffer>* out_buffer);
|
|
|
|
UniquePtr<ReadBuffer> CreateRead(SharedSurface* surf);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
/* `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'.
|
|
|
|
*/
|
|
|
|
void BindFB(GLuint fb);
|
|
|
|
void BindDrawFB(GLuint fb);
|
|
|
|
void BindReadFB(GLuint fb);
|
|
|
|
GLuint GetFB() const;
|
|
|
|
GLuint GetDrawFB() const;
|
|
|
|
GLuint GetReadFB() const;
|
|
|
|
|
|
|
|
// Here `fb` is the actual framebuffer you want bound. Binding 0 will
|
|
|
|
// bind the (generally useless) default framebuffer.
|
2014-08-08 06:03:25 +04:00
|
|
|
void BindFB_Internal(GLuint fb);
|
2013-02-14 03:26:24 +04:00
|
|
|
void BindDrawFB_Internal(GLuint fb);
|
|
|
|
void BindReadFB_Internal(GLuint fb);
|
2014-10-15 01:49:49 +04:00
|
|
|
|
|
|
|
bool IsDrawFramebufferDefault() const;
|
|
|
|
bool IsReadFramebufferDefault() const;
|
2013-02-14 03:26:24 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
#endif // SCREEN_BUFFER_H_
|