Bug 1615751 - Prune unused parts of GLScreenBuffer. r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D62979

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jeff Gilbert 2020-02-15 04:15:21 +00:00
Родитель d5933e1d25
Коммит 739ec46d60
6 изменённых файлов: 14 добавлений и 249 удалений

Просмотреть файл

@ -2120,9 +2120,6 @@ void GLContext::ReportOutstandingNames() {
#endif /* DEBUG */ #endif /* DEBUG */
void GLContext::GuaranteeResolve() { void GLContext::GuaranteeResolve() {
if (mScreen) {
mScreen->AssureBlitted();
}
fFinish(); fFinish();
} }
@ -2335,21 +2332,6 @@ bool GLContext::Readback(SharedSurface* src, gfx::DataSourceSurface* dest) {
return true; return true;
} }
// Do whatever tear-down is necessary after drawing to our offscreen FBO,
// if it's bound.
void GLContext::AfterGLDrawCall() {
if (mScreen) {
mScreen->AfterDrawCall();
}
mHeavyGLCallsSinceLastFlush = true;
}
// Do whatever setup is necessary to read from our offscreen FBO, if it's
// bound.
void GLContext::BeforeGLReadCall() {
if (mScreen) mScreen->BeforeReadCall();
}
void GLContext::fBindFramebuffer(GLenum target, GLuint framebuffer) { void GLContext::fBindFramebuffer(GLenum target, GLuint framebuffer) {
if (!mScreen) { if (!mScreen) {
raw_fBindFramebuffer(target, framebuffer); raw_fBindFramebuffer(target, framebuffer);
@ -2620,10 +2602,6 @@ bool GLContext::InitOffscreen(const gfx::IntSize& size,
return true; return true;
} }
bool GLContext::IsDrawingToDefaultFramebuffer() {
return Screen()->IsDrawFramebufferDefault();
}
GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat,
GLenum aType, const gfx::IntSize& aSize, bool linear) { GLenum aType, const gfx::IntSize& aSize, bool linear) {
GLuint tex = 0; GLuint tex = 0;

Просмотреть файл

@ -726,11 +726,11 @@ class GLContext : public GenericAtomicRefCounted,
// Do whatever tear-down is necessary after drawing to our offscreen FBO, // Do whatever tear-down is necessary after drawing to our offscreen FBO,
// if it's bound. // if it's bound.
void AfterGLDrawCall(); void AfterGLDrawCall() { mHeavyGLCallsSinceLastFlush = true; }
// Do whatever setup is necessary to read from our offscreen FBO, if it's // Do whatever setup is necessary to read from our offscreen FBO, if it's
// bound. // bound.
void BeforeGLReadCall(); void BeforeGLReadCall() {}
// Do whatever tear-down is necessary after reading from our offscreen FBO, // Do whatever tear-down is necessary after reading from our offscreen FBO,
// if it's bound. // if it's bound.
@ -3568,8 +3568,6 @@ class GLContext : public GenericAtomicRefCounted,
bool WorkAroundDriverBugs() const { return mWorkAroundDriverBugs; } bool WorkAroundDriverBugs() const { return mWorkAroundDriverBugs; }
bool IsDrawingToDefaultFramebuffer();
bool IsOffscreenSizeAllowed(const gfx::IntSize& aSize) const; bool IsOffscreenSizeAllowed(const gfx::IntSize& aSize) const;
virtual bool Init(); virtual bool Init();

Просмотреть файл

@ -415,15 +415,6 @@ bool GLContextEGL::ReleaseTexImage() {
} }
void GLContextEGL::SetEGLSurfaceOverride(EGLSurface surf) { void GLContextEGL::SetEGLSurfaceOverride(EGLSurface surf) {
if (Screen()) {
/* Blit `draw` to `read` if we need to, before we potentially juggle
* `read` around. If we don't, we might attach a different `read`,
* and *then* hit AssureBlitted, which will blit a dirty `draw` onto
* the wrong `read`!
*/
Screen()->AssureBlitted();
}
mSurfaceOverride = surf; mSurfaceOverride = surf;
DebugOnly<bool> ok = MakeCurrent(true); DebugOnly<bool> ok = MakeCurrent(true);
MOZ_ASSERT(ok); MOZ_ASSERT(ok);

Просмотреть файл

@ -156,9 +156,6 @@ GLScreenBuffer::GLScreenBuffer(GLContext* gl, const SurfaceCaps& caps,
: mGL(gl), : mGL(gl),
mCaps(caps), mCaps(caps),
mFactory(std::move(factory)), mFactory(std::move(factory)),
mNeedsBlit(true),
mUserReadBufferMode(LOCAL_GL_BACK),
mUserDrawBufferMode(LOCAL_GL_BACK),
mUserDrawFB(0), mUserDrawFB(0),
mUserReadFB(0), mUserReadFB(0),
mInternalDrawFB(0), mInternalDrawFB(0),
@ -181,36 +178,6 @@ GLScreenBuffer::~GLScreenBuffer() {
mBack->Surf()->ProducerRelease(); mBack->Surf()->ProducerRelease();
} }
void GLScreenBuffer::BindAsFramebuffer(GLContext* const gl,
GLenum target) const {
GLuint drawFB = DrawFB();
GLuint readFB = ReadFB();
if (!gl->IsSupported(GLFeature::split_framebuffer)) {
MOZ_ASSERT(drawFB == readFB);
gl->raw_fBindFramebuffer(target, readFB);
return;
}
switch (target) {
case LOCAL_GL_FRAMEBUFFER:
gl->raw_fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER_EXT, drawFB);
gl->raw_fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER_EXT, readFB);
break;
case LOCAL_GL_DRAW_FRAMEBUFFER_EXT:
gl->raw_fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER_EXT, drawFB);
break;
case LOCAL_GL_READ_FRAMEBUFFER_EXT:
gl->raw_fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER_EXT, readFB);
break;
default:
MOZ_CRASH("GFX: Bad `target` for BindFramebuffer.");
}
}
void GLScreenBuffer::BindFB(GLuint fb) { void GLScreenBuffer::BindFB(GLuint fb) {
GLuint drawFB = DrawFB(); GLuint drawFB = DrawFB();
GLuint readFB = ReadFB(); GLuint readFB = ReadFB();
@ -262,28 +229,6 @@ void GLScreenBuffer::BindReadFB(GLuint fb) {
#endif #endif
} }
void GLScreenBuffer::BindFB_Internal(GLuint fb) {
mInternalDrawFB = mUserDrawFB = fb;
mInternalReadFB = mUserReadFB = fb;
mGL->raw_fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mInternalDrawFB);
#ifdef DEBUG
mInInternalMode_DrawFB = true;
mInInternalMode_ReadFB = true;
#endif
}
void GLScreenBuffer::BindDrawFB_Internal(GLuint fb) {
MOZ_ASSERT(mGL->IsSupported(GLFeature::split_framebuffer));
mInternalDrawFB = mUserDrawFB = fb;
mGL->raw_fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER_EXT, mInternalDrawFB);
#ifdef DEBUG
mInInternalMode_DrawFB = true;
#endif
}
void GLScreenBuffer::BindReadFB_Internal(GLuint fb) { void GLScreenBuffer::BindReadFB_Internal(GLuint fb) {
MOZ_ASSERT(mGL->IsSupported(GLFeature::split_framebuffer)); MOZ_ASSERT(mGL->IsSupported(GLFeature::split_framebuffer));
@ -357,18 +302,6 @@ void GLScreenBuffer::DeletingFB(GLuint fb) {
} }
} }
void GLScreenBuffer::AfterDrawCall() {
if (mUserDrawFB != 0) return;
RequireBlit();
}
void GLScreenBuffer::BeforeReadCall() {
if (mUserReadFB != 0) return;
AssureBlitted();
}
bool GLScreenBuffer::CopyTexImage2D(GLenum target, GLint level, bool GLScreenBuffer::CopyTexImage2D(GLenum target, GLint level,
GLenum internalformat, GLint x, GLint y, GLenum internalformat, GLint x, GLint y,
GLsizei width, GLsizei height, GLsizei width, GLsizei height,
@ -407,14 +340,6 @@ bool GLScreenBuffer::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
return false; return false;
} }
void GLScreenBuffer::RequireBlit() { mNeedsBlit = true; }
void GLScreenBuffer::AssureBlitted() {
if (!mNeedsBlit) return;
mNeedsBlit = false;
}
void GLScreenBuffer::Morph(UniquePtr<SurfaceFactory> newFactory) { void GLScreenBuffer::Morph(UniquePtr<SurfaceFactory> newFactory) {
MOZ_RELEASE_ASSERT(newFactory, "newFactory must not be null"); MOZ_RELEASE_ASSERT(newFactory, "newFactory must not be null");
mFactory = std::move(newFactory); mFactory = std::move(newFactory);
@ -450,20 +375,6 @@ bool GLScreenBuffer::Attach(SharedSurface* surf, const gfx::IntSize& size) {
// Check that we're all set up. // Check that we're all set up.
MOZ_ASSERT(SharedSurf() == surf); MOZ_ASSERT(SharedSurf() == surf);
// Update the ReadBuffer mode.
if (mGL->IsSupported(gl::GLFeature::read_buffer)) {
BindFB(0);
mRead->SetReadBuffer(mUserReadBufferMode);
}
// Update the DrawBuffer mode.
if (mGL->IsSupported(gl::GLFeature::draw_buffers)) {
BindFB(0);
SetDrawBuffer(mUserDrawBufferMode);
}
RequireBlit();
return true; return true;
} }
@ -487,7 +398,7 @@ bool GLScreenBuffer::Swap(const gfx::IntSize& size) {
mFront = mBack; mFront = mBack;
mBack = newBack; mBack = newBack;
if (ShouldPreserveBuffer() && mFront && mBack) { if (mCaps.preserve && mFront && mBack) {
auto src = mFront->Surf(); auto src = mFront->Surf();
auto dest = mBack->Surf(); auto dest = mBack->Surf();
@ -524,13 +435,6 @@ bool GLScreenBuffer::Swap(const gfx::IntSize& size) {
return true; return true;
} }
bool GLScreenBuffer::PublishFrame(const gfx::IntSize& size) {
AssureBlitted();
bool good = Swap(size);
return good;
}
bool GLScreenBuffer::Resize(const gfx::IntSize& size) { bool GLScreenBuffer::Resize(const gfx::IntSize& size) {
RefPtr<layers::SharedSurfaceTextureClient> newBack = RefPtr<layers::SharedSurfaceTextureClient> newBack =
mFactory->NewTexClient(size); mFactory->NewTexClient(size);
@ -555,58 +459,6 @@ UniquePtr<ReadBuffer> GLScreenBuffer::CreateRead(SharedSurface* surf) {
return ReadBuffer::Create(gl, caps, formats, surf); return ReadBuffer::Create(gl, caps, formats, surf);
} }
void GLScreenBuffer::SetDrawBuffer(GLenum mode) {
MOZ_ASSERT(mGL->IsSupported(gl::GLFeature::draw_buffers));
MOZ_ASSERT(GetDrawFB() == 0);
if (!mGL->IsSupported(GLFeature::draw_buffers)) return;
mUserDrawBufferMode = mode;
GLuint fb = mRead->mFB;
GLenum internalMode;
switch (mode) {
case LOCAL_GL_BACK:
internalMode = (fb == 0) ? LOCAL_GL_BACK : LOCAL_GL_COLOR_ATTACHMENT0;
break;
case LOCAL_GL_NONE:
internalMode = LOCAL_GL_NONE;
break;
default:
MOZ_CRASH("GFX: Bad value.");
}
mGL->MakeCurrent();
mGL->fDrawBuffers(1, &internalMode);
}
void GLScreenBuffer::SetReadBuffer(GLenum mode) {
MOZ_ASSERT(mGL->IsSupported(gl::GLFeature::read_buffer));
MOZ_ASSERT(GetReadFB() == 0);
mUserReadBufferMode = mode;
mRead->SetReadBuffer(mUserReadBufferMode);
}
bool GLScreenBuffer::IsDrawFramebufferDefault() const {
return IsReadFramebufferDefault();
}
bool GLScreenBuffer::IsReadFramebufferDefault() const {
return SharedSurf()->mAttachType == AttachmentType::Screen;
}
uint32_t GLScreenBuffer::DepthBits() const {
const GLFormats& formats = mFactory->mFormats;
if (formats.depth == LOCAL_GL_DEPTH_COMPONENT16) return 16;
return 24;
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Utils // Utils
@ -758,27 +610,4 @@ void ReadBuffer::Attach(SharedSurface* surf) {
const gfx::IntSize& ReadBuffer::Size() const { return mSurf->mSize; } const gfx::IntSize& ReadBuffer::Size() const { return mSurf->mSize; }
void ReadBuffer::SetReadBuffer(GLenum userMode) const {
if (!mGL->IsSupported(GLFeature::read_buffer)) return;
GLenum internalMode;
switch (userMode) {
case LOCAL_GL_BACK:
case LOCAL_GL_FRONT:
internalMode = (mFB == 0) ? userMode : LOCAL_GL_COLOR_ATTACHMENT0;
break;
case LOCAL_GL_NONE:
internalMode = LOCAL_GL_NONE;
break;
default:
MOZ_CRASH("GFX: Bad value.");
}
mGL->MakeCurrent();
mGL->fReadBuffer(internalMode);
}
} // namespace mozilla::gl } // namespace mozilla::gl

Просмотреть файл

@ -75,11 +75,9 @@ class ReadBuffer {
const gfx::IntSize& Size() const; const gfx::IntSize& Size() const;
SharedSurface* SharedSurf() const { return mSurf; } SharedSurface* SharedSurf() const { return mSurf; }
void SetReadBuffer(GLenum mode) const;
}; };
class GLScreenBuffer { class GLScreenBuffer final {
public: public:
// Infallible. // Infallible.
static UniquePtr<GLScreenBuffer> Create(GLContext* gl, static UniquePtr<GLScreenBuffer> Create(GLContext* gl,
@ -96,12 +94,12 @@ class GLScreenBuffer {
layers::LayersIPCChannel* ipcChannel, layers::LayersBackend backend, layers::LayersIPCChannel* ipcChannel, layers::LayersBackend backend,
bool useANGLE, const layers::TextureFlags& flags); bool useANGLE, const layers::TextureFlags& flags);
protected: private:
GLContext* const mGL; // Owns us. GLContext* const mGL; // Owns us.
public: public:
const SurfaceCaps mCaps; const SurfaceCaps mCaps;
protected: private:
UniquePtr<SurfaceFactory> mFactory; UniquePtr<SurfaceFactory> mFactory;
RefPtr<layers::SharedSurfaceTextureClient> mBack; RefPtr<layers::SharedSurfaceTextureClient> mBack;
@ -109,11 +107,6 @@ class GLScreenBuffer {
UniquePtr<ReadBuffer> mRead; UniquePtr<ReadBuffer> mRead;
bool mNeedsBlit;
GLenum mUserReadBufferMode;
GLenum mUserDrawBufferMode;
// Below are the parts that help us pretend to be framebuffer 0: // Below are the parts that help us pretend to be framebuffer 0:
GLuint mUserDrawFB; GLuint mUserDrawFB;
GLuint mUserReadFB; GLuint mUserReadFB;
@ -131,25 +124,19 @@ class GLScreenBuffer {
public: public:
virtual ~GLScreenBuffer(); virtual ~GLScreenBuffer();
SurfaceFactory* Factory() const { return mFactory.get(); } const auto& Factory() const { return mFactory; }
const auto& Front() const { return mFront; }
const RefPtr<layers::SharedSurfaceTextureClient>& Front() const {
return mFront;
}
SharedSurface* SharedSurf() const { SharedSurface* SharedSurf() const {
MOZ_ASSERT(mRead); MOZ_ASSERT(mRead);
return mRead->SharedSurf(); return mRead->SharedSurf();
} }
bool ShouldPreserveBuffer() const { return mCaps.preserve; } private:
GLuint DrawFB() const { return ReadFB(); } GLuint DrawFB() const { return ReadFB(); }
GLuint ReadFB() const { return mRead->mFB; } GLuint ReadFB() const { return mRead->mFB; }
uint32_t DepthBits() const; public:
void DeletingFB(GLuint fb); void DeletingFB(GLuint fb);
const gfx::IntSize& Size() const { const gfx::IntSize& Size() const {
@ -159,23 +146,10 @@ class GLScreenBuffer {
bool IsReadBufferReady() const { return mRead.get() != nullptr; } bool IsReadBufferReady() const { return mRead.get() != nullptr; }
void BindAsFramebuffer(GLContext* const gl, GLenum target) const;
void RequireBlit();
void AssureBlitted();
void AfterDrawCall();
void BeforeReadCall();
bool CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, bool CopyTexImage2D(GLenum target, GLint level, GLenum internalformat,
GLint x, GLint y, GLsizei width, GLsizei height, GLint x, GLint y, GLsizei width, GLsizei height,
GLint border); GLint border);
void SetReadBuffer(GLenum userMode);
void SetDrawBuffer(GLenum userMode);
GLenum GetReadBufferMode() const { return mUserReadBufferMode; }
GLenum GetDrawBufferMode() const { return mUserDrawBufferMode; }
/** /**
* Attempts to read pixels from the current bound framebuffer, if * Attempts to read pixels from the current bound framebuffer, if
* it is backed by a SharedSurface. * it is backed by a SharedSurface.
@ -189,16 +163,16 @@ class GLScreenBuffer {
// Morph changes the factory used to create surfaces. // Morph changes the factory used to create surfaces.
void Morph(UniquePtr<SurfaceFactory> newFactory); void Morph(UniquePtr<SurfaceFactory> newFactory);
protected: private:
// Returns false on error or inability to resize. // Returns false on error or inability to resize.
bool Swap(const gfx::IntSize& size); bool Swap(const gfx::IntSize& size);
public: public:
bool PublishFrame(const gfx::IntSize& size); bool PublishFrame(const gfx::IntSize& size) { return Swap(size); }
bool Resize(const gfx::IntSize& size); bool Resize(const gfx::IntSize& size);
protected: private:
bool Attach(SharedSurface* surf, const gfx::IntSize& size); bool Attach(SharedSurface* surf, const gfx::IntSize& size);
UniquePtr<ReadBuffer> CreateRead(SharedSurface* surf); UniquePtr<ReadBuffer> CreateRead(SharedSurface* surf);
@ -218,12 +192,7 @@ class GLScreenBuffer {
// Here `fb` is the actual framebuffer you want bound. Binding 0 will // Here `fb` is the actual framebuffer you want bound. Binding 0 will
// bind the (generally useless) default framebuffer. // bind the (generally useless) default framebuffer.
void BindFB_Internal(GLuint fb);
void BindDrawFB_Internal(GLuint fb);
void BindReadFB_Internal(GLuint fb); void BindReadFB_Internal(GLuint fb);
bool IsDrawFramebufferDefault() const;
bool IsReadFramebufferDefault() const;
}; };
} // namespace gl } // namespace gl

Просмотреть файл

@ -416,7 +416,7 @@ void CanvasClientSharedSurface::UpdateRenderer(gfx::IntSize aSize,
mShSurfClient->GetAllocator() != mShSurfClient->GetAllocator() !=
GetForwarder()->GetTextureForwarder()) { GetForwarder()->GetTextureForwarder()) {
mShSurfClient = mShSurfClient =
CloneSurface(mShSurfClient->Surf(), gl->Screen()->Factory()); CloneSurface(mShSurfClient->Surf(), gl->Screen()->Factory().get());
} }
} }