gecko-dev/gfx/gl/GLScreenBuffer.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

202 строки
5.6 KiB
C
Исходник Обычный вид История

/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
/* 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"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/UniquePtr.h"
#include "SharedSurface.h"
#include "SurfaceTypes.h"
namespace mozilla {
namespace layers {
class KnowsCompositor;
class LayersIPCChannel;
class SharedSurfaceTextureClient;
enum class LayersBackend : int8_t;
} // namespace layers
namespace gl {
class GLContext;
class SharedSurface;
class ShSurfHandle;
class SurfaceFactory;
class ReadBuffer {
public:
// Infallible, always non-null.
static UniquePtr<ReadBuffer> Create(GLContext* gl, const SurfaceCaps& caps,
const GLFormats& formats,
SharedSurface* surf);
protected:
GLContext* const mGL;
public:
const GLuint mFB;
protected:
// mFB has the following attachments:
const GLuint mDepthRB;
const GLuint mStencilRB;
// note no mColorRB here: this is provided by mSurf.
SharedSurface* mSurf;
ReadBuffer(GLContext* gl, GLuint fb, GLuint depthRB, GLuint stencilRB,
SharedSurface* surf)
: 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.
void Attach(SharedSurface* surf);
const gfx::IntSize& Size() const;
SharedSurface* SharedSurf() const { return mSurf; }
};
class GLScreenBuffer final {
public:
// Infallible.
static UniquePtr<GLScreenBuffer> Create(GLContext* gl,
const gfx::IntSize& size,
const SurfaceCaps& caps);
static UniquePtr<SurfaceFactory> CreateFactory(
GLContext* gl, const SurfaceCaps& caps,
layers::KnowsCompositor* compositorConnection,
const layers::TextureFlags& flags);
static UniquePtr<SurfaceFactory> CreateFactory(
GLContext* gl, const SurfaceCaps& caps,
layers::LayersIPCChannel* ipcChannel, layers::LayersBackend backend,
bool useANGLE, const layers::TextureFlags& flags);
private:
GLContext* const mGL; // Owns us.
public:
const SurfaceCaps mCaps;
private:
UniquePtr<SurfaceFactory> mFactory;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<layers::SharedSurfaceTextureClient> mBack;
RefPtr<layers::SharedSurfaceTextureClient> mFront;
UniquePtr<ReadBuffer> mRead;
// 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,
UniquePtr<SurfaceFactory> factory);
public:
virtual ~GLScreenBuffer();
const auto& Factory() const { return mFactory; }
const auto& Front() const { return mFront; }
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
SharedSurface* SharedSurf() const {
MOZ_ASSERT(mRead);
return mRead->SharedSurf();
}
private:
GLuint DrawFB() const { return ReadFB(); }
GLuint ReadFB() const { return mRead->mFB; }
public:
void DeletingFB(GLuint fb);
const gfx::IntSize& Size() const {
MOZ_ASSERT(mRead);
return mRead->Size();
}
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);
/**
* Attempts to read pixels from the current bound framebuffer, if
* it is backed by a SharedSurface.
*
* 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);
// Morph changes the factory used to create surfaces.
void Morph(UniquePtr<SurfaceFactory> newFactory);
private:
// Returns false on error or inability to resize.
bool Swap(const gfx::IntSize& size);
public:
bool PublishFrame(const gfx::IntSize& size) { return Swap(size); }
bool Resize(const gfx::IntSize& size);
private:
bool Attach(SharedSurface* surf, const gfx::IntSize& size);
UniquePtr<ReadBuffer> CreateRead(SharedSurface* surf);
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.
void BindReadFB_Internal(GLuint fb);
};
} // namespace gl
} // namespace mozilla
#endif // SCREEN_BUFFER_H_