Commit 264ab56f by Corentin Wallez

Make the default framebuffer owned by Surface

Reland with a fix for SurfaceTest in angle_unittests and fixes for signed-unsigned warnings In CGL there is no notion of default Framebuffer and MakeCurrent only makes a context current but not a drawable. Instead, everything is done via render to texture. For that reason, different surfaces will have different FBOs as default framebuffers, which causes that change. BUG=angleproject:891 Change-Id: I0664896bc335b1a757226aaa212536b8f9d0f08f Reviewed-on: https://chromium-review.googlesource.com/293752Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent ccdf74b8
......@@ -94,15 +94,10 @@ Context::Context(const egl::Config *config,
mState.initializeZeroTextures(mZeroTextures);
// Allocate default FBO
mFramebufferMap[0] = new Framebuffer(mCaps, mRenderer, 0);
bindVertexArray(0);
bindArrayBuffer(0);
bindElementArrayBuffer(0);
bindReadFramebuffer(0);
bindDrawFramebuffer(0);
bindRenderbuffer(0);
bindGenericUniformBuffer(0);
......@@ -136,10 +131,13 @@ Context::~Context()
{
mState.reset();
while (!mFramebufferMap.empty())
for (auto framebuffer : mFramebufferMap)
{
// Delete the framebuffer in reverse order to destroy the framebuffer zero last.
deleteFramebuffer(mFramebufferMap.rbegin()->first);
// Default framebuffer are owned by their respective Surface
if (framebuffer.second->id() != 0)
{
SafeDelete(framebuffer.second);
}
}
while (!mFenceNVMap.empty())
......@@ -204,60 +202,43 @@ void Context::makeCurrent(egl::Surface *surface)
{
releaseSurface();
}
ASSERT(mCurrentSurface == nullptr);
mCurrentSurface = surface;
surface->setIsCurrent(true);
mCurrentSurface = surface;
// Update default framebuffer
Framebuffer *defaultFBO = mFramebufferMap[0];
GLenum drawBufferState = GL_BACK;
defaultFBO->setDrawBuffers(1, &drawBufferState);
defaultFBO->setReadBuffer(GL_BACK);
const FramebufferAttachment *backAttachment = defaultFBO->getAttachment(GL_BACK);
if (backAttachment && backAttachment->getSurface() == surface)
{
// FBO already initialized to the surface.
return;
}
const egl::Config *config = surface->getConfig();
defaultFBO->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::MakeInvalid(), surface);
if (config->depthSize > 0)
{
defaultFBO->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, ImageIndex::MakeInvalid(), surface);
}
else
{
defaultFBO->resetAttachment(GL_DEPTH);
}
if (config->stencilSize > 0)
// Update default framebuffer, the binding of the previous default
// framebuffer (or lack of) will have a nullptr.
{
defaultFBO->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, ImageIndex::MakeInvalid(), surface);
}
else
{
defaultFBO->resetAttachment(GL_STENCIL);
Framebuffer *newDefault = surface->getDefaultFramebuffer();
if (mState.getReadFramebuffer() == nullptr)
{
mState.setReadFramebufferBinding(newDefault);
}
if (mState.getDrawFramebuffer() == nullptr)
{
mState.setDrawFramebufferBinding(newDefault);
}
mFramebufferMap[0] = newDefault;
}
}
void Context::releaseSurface()
{
Framebuffer *defaultFBO = mFramebufferMap[0];
if (defaultFBO)
ASSERT(mCurrentSurface != nullptr);
// Remove the default framebuffer
{
defaultFBO->resetAttachment(GL_BACK);
defaultFBO->resetAttachment(GL_DEPTH);
defaultFBO->resetAttachment(GL_STENCIL);
Framebuffer *currentDefault = mCurrentSurface->getDefaultFramebuffer();
if (mState.getReadFramebuffer() == currentDefault)
{
mState.setReadFramebufferBinding(nullptr);
}
if (mState.getDrawFramebuffer() == currentDefault)
{
mState.setDrawFramebufferBinding(nullptr);
}
mFramebufferMap.erase(0);
}
ASSERT(mCurrentSurface != nullptr);
mCurrentSurface->setIsCurrent(false);
mCurrentSurface = nullptr;
}
......@@ -1402,10 +1383,19 @@ EGLenum Context::getClientType() const
EGLenum Context::getRenderBuffer() const
{
ASSERT(mFramebufferMap.count(0) > 0);
const Framebuffer *framebuffer = mFramebufferMap.find(0)->second;
const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
return backAttachment ? backAttachment->getSurface()->getRenderBuffer() : EGL_NONE;
auto framebufferIt = mFramebufferMap.find(0);
if (framebufferIt != mFramebufferMap.end())
{
const Framebuffer *framebuffer = framebufferIt->second;
const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
ASSERT(backAttachment != nullptr);
return backAttachment->getSurface()->getRenderBuffer();
}
else
{
return EGL_NONE;
}
}
const Caps &Context::getCaps() const
......
......@@ -20,6 +20,7 @@
#include "libANGLE/renderer/FramebufferImpl.h"
#include "libANGLE/renderer/ImplFactory.h"
#include "libANGLE/renderer/RenderbufferImpl.h"
#include "libANGLE/renderer/SurfaceImpl.h"
namespace gl
{
......@@ -37,6 +38,14 @@ void DetachMatchingAttachment(FramebufferAttachment *attachment, GLenum matchTyp
}
}
Framebuffer::Data::Data()
: mColorAttachments(1),
mDrawBufferStates(1, GL_NONE),
mReadBufferState(GL_COLOR_ATTACHMENT0_EXT)
{
mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT;
}
Framebuffer::Data::Data(const Caps &caps)
: mColorAttachments(caps.maxColorAttachments),
mDrawBufferStates(caps.maxDrawBuffers, GL_NONE),
......@@ -83,7 +92,7 @@ const FramebufferAttachment *Framebuffer::Data::getDepthOrStencilAttachment() co
return nullptr;
}
const FramebufferAttachment *Framebuffer::Data::getColorAttachment(unsigned int colorAttachment) const
const FramebufferAttachment *Framebuffer::Data::getColorAttachment(size_t colorAttachment) const
{
ASSERT(colorAttachment < mColorAttachments.size());
return mColorAttachments[colorAttachment].isAttached() ?
......@@ -116,18 +125,15 @@ const FramebufferAttachment *Framebuffer::Data::getDepthStencilAttachment() cons
}
Framebuffer::Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id)
: mData(caps),
mImpl(nullptr),
mId(id)
: mData(caps), mImpl(factory->createFramebuffer(mData)), mId(id)
{
ASSERT(mId != 0);
ASSERT(mImpl != nullptr);
}
Framebuffer::Framebuffer(rx::SurfaceImpl *surface)
: mData(), mImpl(surface->createDefaultFramebuffer(mData)), mId(0)
{
if (mId == 0)
{
mImpl = factory->createDefaultFramebuffer(mData);
}
else
{
mImpl = factory->createFramebuffer(mData);
}
ASSERT(mImpl != nullptr);
}
......@@ -157,7 +163,7 @@ void Framebuffer::detachResourceById(GLenum resourceType, GLuint resourceId)
DetachMatchingAttachment(&mData.mStencilAttachment, resourceType, resourceId);
}
const FramebufferAttachment *Framebuffer::getColorbuffer(unsigned int colorAttachment) const
const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const
{
return mData.getColorAttachment(colorAttachment);
}
......@@ -257,7 +263,7 @@ void Framebuffer::setReadBuffer(GLenum buffer)
mImpl->setReadBuffer(buffer);
}
bool Framebuffer::isEnabledColorAttachment(unsigned int colorAttachment) const
bool Framebuffer::isEnabledColorAttachment(size_t colorAttachment) const
{
ASSERT(colorAttachment < mData.mColorAttachments.size());
return (mData.mColorAttachments[colorAttachment].isAttached() &&
......@@ -277,6 +283,11 @@ bool Framebuffer::hasEnabledColorAttachment() const
return false;
}
size_t Framebuffer::getNumColorBuffers() const
{
return mData.mColorAttachments.size();
}
bool Framebuffer::hasStencil() const
{
return (mData.mStencilAttachment.isAttached() && mData.mStencilAttachment.getStencilSize() > 0);
......
......@@ -23,6 +23,7 @@ namespace rx
class ImplFactory;
class FramebufferImpl;
class RenderbufferImpl;
class SurfaceImpl;
}
namespace egl
......@@ -50,13 +51,14 @@ class Framebuffer
class Data final : angle::NonCopyable
{
public:
explicit Data();
explicit Data(const Caps &caps);
~Data();
const FramebufferAttachment *getReadAttachment() const;
const FramebufferAttachment *getFirstColorAttachment() const;
const FramebufferAttachment *getDepthOrStencilAttachment() const;
const FramebufferAttachment *getColorAttachment(unsigned int colorAttachment) const;
const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
const FramebufferAttachment *getDepthAttachment() const;
const FramebufferAttachment *getStencilAttachment() const;
const FramebufferAttachment *getDepthStencilAttachment() const;
......@@ -76,6 +78,7 @@ class Framebuffer
};
Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id);
Framebuffer(rx::SurfaceImpl *surface);
virtual ~Framebuffer();
const rx::FramebufferImpl *getImplementation() const { return mImpl; }
......@@ -92,7 +95,7 @@ class Framebuffer
void detachTexture(GLuint texture);
void detachRenderbuffer(GLuint renderbuffer);
const FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
const FramebufferAttachment *getDepthbuffer() const;
const FramebufferAttachment *getStencilbuffer() const;
const FramebufferAttachment *getDepthStencilBuffer() const;
......@@ -109,8 +112,9 @@ class Framebuffer
GLenum getReadBufferState() const;
void setReadBuffer(GLenum buffer);
bool isEnabledColorAttachment(unsigned int colorAttachment) const;
bool isEnabledColorAttachment(size_t colorAttachment) const;
bool hasEnabledColorAttachment() const;
size_t getNumColorBuffers() const;
bool hasStencil() const;
int getSamples(const gl::Data &data) const;
bool usingExtendedDrawBuffers() const;
......
......@@ -11,6 +11,7 @@
#include "libANGLE/Surface.h"
#include "libANGLE/Config.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/Texture.h"
#include <EGL/eglext.h>
......@@ -26,6 +27,7 @@ Surface::Surface(rx::SurfaceImpl *impl,
const AttributeMap &attributes)
: FramebufferAttachmentObject(),
mImplementation(impl),
mDefaultFramebuffer(nullptr),
mCurrentCount(0),
mDestroyed(false),
mType(surfaceType),
......@@ -55,6 +57,9 @@ Surface::Surface(rx::SurfaceImpl *impl,
mTextureFormat = attributes.get(EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE);
mTextureTarget = attributes.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE);
}
mDefaultFramebuffer = createDefaultFramebuffer();
ASSERT(mDefaultFramebuffer != nullptr);
}
Surface::~Surface()
......@@ -213,4 +218,30 @@ GLuint Surface::getId() const
UNREACHABLE();
return 0;
}
gl::Framebuffer *Surface::createDefaultFramebuffer()
{
gl::Framebuffer *framebuffer = new gl::Framebuffer(mImplementation);
GLenum drawBufferState = GL_BACK;
framebuffer->setDrawBuffers(1, &drawBufferState);
framebuffer->setReadBuffer(GL_BACK);
framebuffer->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, gl::ImageIndex::MakeInvalid(),
this);
if (mConfig->depthSize > 0)
{
framebuffer->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, gl::ImageIndex::MakeInvalid(),
this);
}
if (mConfig->stencilSize > 0)
{
framebuffer->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_STENCIL,
gl::ImageIndex::MakeInvalid(), this);
}
return framebuffer;
}
}
......@@ -21,6 +21,7 @@
namespace gl
{
class Framebuffer;
class Texture;
}
......@@ -64,6 +65,7 @@ class Surface final : public gl::FramebufferAttachmentObject
EGLenum getTextureTarget() const;
gl::Texture *getBoundTexture() const { return mTexture.get(); }
gl::Framebuffer *getDefaultFramebuffer() { return mDefaultFramebuffer; }
EGLint isFixedSize() const;
......@@ -81,11 +83,14 @@ class Surface final : public gl::FramebufferAttachmentObject
virtual ~Surface();
rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override { return mImplementation; }
gl::Framebuffer *createDefaultFramebuffer();
// ANGLE-only method, used internally
friend class gl::Texture;
void releaseTexImageFromTexture();
rx::SurfaceImpl *mImplementation;
gl::Framebuffer *mDefaultFramebuffer;
int mCurrentCount;
bool mDestroyed;
......
......@@ -6,9 +6,13 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/AttributeMap.h"
#include "libANGLE/Config.h"
#include "libANGLE/Data.h"
#include "libANGLE/State.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/FramebufferImpl.h"
#include "libANGLE/renderer/SurfaceImpl.h"
namespace
......@@ -20,6 +24,8 @@ class MockSurfaceImpl : public rx::SurfaceImpl
virtual ~MockSurfaceImpl() { destroy(); }
MOCK_METHOD0(initialize, egl::Error());
MOCK_METHOD1(createDefaultFramebuffer,
rx::FramebufferImpl *(const gl::Framebuffer::Data &data));
MOCK_METHOD0(swap, egl::Error());
MOCK_METHOD4(postSubBuffer, egl::Error(EGLint, EGLint, EGLint, EGLint));
MOCK_METHOD2(querySurfacePointerANGLE, egl::Error(EGLint, void**));
......@@ -35,15 +41,71 @@ class MockSurfaceImpl : public rx::SurfaceImpl
MOCK_METHOD0(destroy, void());
};
class MockFramebufferImpl : public rx::FramebufferImpl
{
public:
MockFramebufferImpl() : rx::FramebufferImpl(gl::Framebuffer::Data()) {}
virtual ~MockFramebufferImpl() { destroy(); }
MOCK_METHOD1(onUpdateColorAttachment, void(size_t));
MOCK_METHOD0(onUpdateDepthAttachment, void());
MOCK_METHOD0(onUpdateStencilAttachment, void());
MOCK_METHOD0(onUpdateDepthStencilAttachment, void());
MOCK_METHOD2(setDrawBuffers, void(size_t, const GLenum *));
MOCK_METHOD1(setReadBuffer, void(GLenum));
MOCK_METHOD2(discard, gl::Error(size_t, const GLenum *));
MOCK_METHOD2(invalidate, gl::Error(size_t, const GLenum *));
MOCK_METHOD3(invalidateSub, gl::Error(size_t, const GLenum *, const gl::Rectangle &));
MOCK_METHOD2(clear, gl::Error(const gl::Data &, GLbitfield));
MOCK_METHOD4(clearBufferfv, gl::Error(const gl::State &, GLenum, GLint, const GLfloat *));
MOCK_METHOD4(clearBufferuiv, gl::Error(const gl::State &, GLenum, GLint, const GLuint *));
MOCK_METHOD4(clearBufferiv, gl::Error(const gl::State &, GLenum, GLint, const GLint *));
MOCK_METHOD5(clearBufferfi, gl::Error(const gl::State &, GLenum, GLint, GLfloat, GLint));
MOCK_CONST_METHOD0(getImplementationColorReadFormat, GLenum());
MOCK_CONST_METHOD0(getImplementationColorReadType, GLenum());
MOCK_CONST_METHOD5(
readPixels,
gl::Error(const gl::State &, const gl::Rectangle &, GLenum, GLenum, GLvoid *));
MOCK_METHOD6(blit,
gl::Error(const gl::State &,
const gl::Rectangle &,
const gl::Rectangle &,
GLbitfield,
GLenum,
const gl::Framebuffer *));
MOCK_CONST_METHOD0(checkStatus, GLenum());
MOCK_METHOD0(destroy, void());
};
class SurfaceTest : public testing::Test
{
protected:
virtual void SetUp()
{
mImpl = new MockSurfaceImpl;
EXPECT_CALL(*mImpl, getSwapBehavior());
EXPECT_CALL(*mImpl, destroy());
mSurface = new egl::Surface(mImpl, EGL_WINDOW_BIT, &mConfig, egl::AttributeMap());
MockFramebufferImpl *framebuffer = new MockFramebufferImpl;
mSurfaceImpl = new MockSurfaceImpl;
EXPECT_CALL(*mSurfaceImpl, getSwapBehavior());
EXPECT_CALL(*mSurfaceImpl, createDefaultFramebuffer(testing::_))
.WillOnce(testing::Return(framebuffer));
EXPECT_CALL(*mSurfaceImpl, destroy());
EXPECT_CALL(*framebuffer, setDrawBuffers(1, testing::_));
EXPECT_CALL(*framebuffer, setReadBuffer(GL_BACK));
EXPECT_CALL(*framebuffer, onUpdateColorAttachment(0));
mSurface = new egl::Surface(mSurfaceImpl, EGL_WINDOW_BIT, &mConfig, egl::AttributeMap());
EXPECT_CALL(*framebuffer, destroy());
SafeDelete(framebuffer);
}
virtual void TearDown()
......@@ -51,20 +113,31 @@ class SurfaceTest : public testing::Test
mSurface->onDestroy();
}
MockSurfaceImpl *mImpl;
MockSurfaceImpl *mSurfaceImpl;
egl::Surface *mSurface;
egl::Config mConfig;
};
TEST_F(SurfaceTest, DestructionDeletesImpl)
{
MockFramebufferImpl *framebuffer = new MockFramebufferImpl;
MockSurfaceImpl *impl = new MockSurfaceImpl;
EXPECT_CALL(*impl, getSwapBehavior());
EXPECT_CALL(*impl, createDefaultFramebuffer(testing::_)).WillOnce(testing::Return(framebuffer));
EXPECT_CALL(*framebuffer, setDrawBuffers(1, testing::_));
EXPECT_CALL(*framebuffer, setReadBuffer(GL_BACK));
EXPECT_CALL(*framebuffer, onUpdateColorAttachment(0));
EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation();
egl::Surface *surface = new egl::Surface(impl, EGL_WINDOW_BIT, &mConfig, egl::AttributeMap());
surface->onDestroy();
EXPECT_CALL(*framebuffer, destroy());
SafeDelete(framebuffer);
// Only needed because the mock is leaked if bugs are present,
// which logs an error, but does not cause the test to fail.
// Ordinarily mocks are verified when destroyed.
......
......@@ -29,8 +29,8 @@ DisplayImpl::~DisplayImpl()
void DisplayImpl::destroySurface(egl::Surface *surface)
{
surface->onDestroy();
mSurfaceSet.erase(surface);
surface->onDestroy();
}
const egl::DisplayExtensions &DisplayImpl::getExtensions() const
......
......@@ -41,7 +41,6 @@ class ImplFactory : angle::NonCopyable
virtual ProgramImpl *createProgram(const gl::Program::Data &data) = 0;
// Framebuffer creation
virtual FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) = 0;
virtual FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) = 0;
// Texture creation
......
......@@ -11,6 +11,7 @@
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
namespace egl
......@@ -22,6 +23,8 @@ struct Config;
namespace rx
{
class FramebufferImpl;
class SurfaceImpl : public FramebufferAttachmentObjectImpl
{
public:
......@@ -29,6 +32,7 @@ class SurfaceImpl : public FramebufferAttachmentObjectImpl
virtual ~SurfaceImpl();
virtual egl::Error initialize() = 0;
virtual FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) = 0;
virtual egl::Error swap() = 0;
virtual egl::Error postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) = 0;
virtual egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) = 0;
......
......@@ -519,7 +519,7 @@ size_t RendererD3D::getBoundFramebufferTextures(const gl::Data &data, Framebuffe
size_t textureCount = 0;
const gl::Framebuffer *drawFramebuffer = data.state->getDrawFramebuffer();
for (unsigned int i = 0; i < data.caps->maxColorAttachments; i++)
for (size_t i = 0; i < drawFramebuffer->getNumColorBuffers(); i++)
{
const gl::FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(i);
if (attachment && attachment->type() == GL_TEXTURE)
......
......@@ -80,6 +80,11 @@ egl::Error SurfaceD3D::initialize()
return egl::Error(EGL_SUCCESS);
}
FramebufferImpl *SurfaceD3D::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return mRenderer->createFramebuffer(data);
}
egl::Error SurfaceD3D::bindTexImage(EGLint)
{
return egl::Error(EGL_SUCCESS);
......
......@@ -33,6 +33,7 @@ class SurfaceD3D : public SurfaceImpl
void releaseSwapChain();
egl::Error initialize() override;
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
egl::Error swap() override;
egl::Error postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) override;
......
......@@ -2962,11 +2962,6 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
return gl::Error(GL_NO_ERROR);
}
FramebufferImpl *Renderer11::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return createFramebuffer(data);
}
FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data)
{
return new Framebuffer11(data, this);
......
......@@ -182,7 +182,6 @@ class Renderer11 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT);
// Framebuffer creation
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation
......
......@@ -2652,11 +2652,6 @@ gl::Error Renderer9::createRenderTarget(int width, int height, GLenum format, GL
return gl::Error(GL_NO_ERROR);
}
FramebufferImpl *Renderer9::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return createFramebuffer(data);
}
FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data)
{
return new Framebuffer9(data, this);
......
......@@ -167,7 +167,6 @@ class Renderer9 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT);
// Framebuffer creation
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation
......
......@@ -36,6 +36,7 @@ class DisplayGL : public DisplayImpl
egl::Error makeCurrent(egl::Surface *drawSurface, egl::Surface *readSurface, gl::Context *context) override;
protected:
RendererGL *getRenderer() const { return mRenderer; };
const gl::Version &getMaxSupportedESVersion() const;
private:
......
......@@ -181,11 +181,6 @@ ProgramImpl *RendererGL::createProgram(const gl::Program::Data &data)
return new ProgramGL(data, mFunctions, mStateManager);
}
FramebufferImpl *RendererGL::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return new FramebufferGL(data, mFunctions, mStateManager, true);
}
FramebufferImpl *RendererGL::createFramebuffer(const gl::Framebuffer::Data &data)
{
return new FramebufferGL(data, mFunctions, mStateManager, false);
......
......@@ -39,7 +39,6 @@ class RendererGL : public Renderer
ProgramImpl *createProgram(const gl::Program::Data &data) override;
// Framebuffer creation
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Texture creation
......@@ -80,6 +79,8 @@ class RendererGL : public Renderer
void syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits) override;
const gl::Version &getMaxSupportedESVersion() const;
const FunctionsGL *getFunctions() const { return mFunctions; }
StateManagerGL *getStateManager() const { return mStateManager; }
private:
void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap* outTextureCaps,
......
......@@ -8,11 +8,13 @@
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
namespace rx
{
SurfaceGL::SurfaceGL()
: SurfaceImpl()
SurfaceGL::SurfaceGL(RendererGL *renderer) : SurfaceImpl(), mRenderer(renderer)
{
}
......@@ -20,4 +22,8 @@ SurfaceGL::~SurfaceGL()
{
}
FramebufferImpl *SurfaceGL::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return new FramebufferGL(data, mRenderer->getFunctions(), mRenderer->getStateManager(), true);
}
}
......@@ -14,10 +14,12 @@
namespace rx
{
class RendererGL;
class SurfaceGL : public SurfaceImpl
{
public:
SurfaceGL();
SurfaceGL(RendererGL *renderer);
~SurfaceGL() override;
gl::Error getAttachmentRenderTarget(const gl::FramebufferAttachment::Target &target,
......@@ -26,7 +28,12 @@ class SurfaceGL : public SurfaceImpl
return gl::Error(GL_OUT_OF_MEMORY, "Not supported on OpenGL");
}
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
virtual egl::Error makeCurrent() = 0;
private:
RendererGL *mRenderer;
};
}
......
......@@ -42,7 +42,7 @@ SurfaceImpl *DisplayCGL::createWindowSurface(const egl::Config *configuration,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return new WindowSurfaceCGL();
return new WindowSurfaceCGL(this->getRenderer());
}
SurfaceImpl *DisplayCGL::createPbufferSurface(const egl::Config *configuration,
......
......@@ -17,7 +17,7 @@ namespace rx
class WindowSurfaceCGL : public SurfaceGL
{
public:
WindowSurfaceCGL();
WindowSurfaceCGL(RendererGL *renderer);
~WindowSurfaceCGL() override;
egl::Error initialize() override;
......
......@@ -9,12 +9,12 @@
#include "libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h"
#include "common/debug.h"
#include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
namespace rx
{
WindowSurfaceCGL::WindowSurfaceCGL()
: SurfaceGL()
WindowSurfaceCGL::WindowSurfaceCGL(RendererGL *renderer) : SurfaceGL(renderer)
{
}
......
......@@ -197,7 +197,8 @@ SurfaceImpl *DisplayGLX::createWindowSurface(const egl::Config *configuration,
ASSERT(configIdToGLXConfig.count(configuration->configID) > 0);
glx::FBConfig fbConfig = configIdToGLXConfig[configuration->configID];
return new WindowSurfaceGLX(mGLX, *this, window, mGLX.getDisplay(), mContext, fbConfig);
return new WindowSurfaceGLX(mGLX, this, this->getRenderer(), window, mGLX.getDisplay(),
mContext, fbConfig);
}
SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration,
......@@ -210,7 +211,8 @@ SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration,
EGLint height = attribs.get(EGL_HEIGHT, 0);
bool largest = (attribs.get(EGL_LARGEST_PBUFFER, EGL_FALSE) == EGL_TRUE);
return new PbufferSurfaceGLX(width, height, largest, mGLX, mContext, fbConfig);
return new PbufferSurfaceGLX(this->getRenderer(), width, height, largest, mGLX, mContext,
fbConfig);
}
SurfaceImpl* DisplayGLX::createPbufferFromClientBuffer(const egl::Config *configuration,
......
......@@ -9,14 +9,20 @@
#include "libANGLE/renderer/gl/glx/PbufferSurfaceGLX.h"
#include "common/debug.h"
#include "libANGLE/renderer/gl/glx/DisplayGLX.h"
#include "libANGLE/renderer/gl/glx/FunctionsGLX.h"
namespace rx
{
PbufferSurfaceGLX::PbufferSurfaceGLX(EGLint width, EGLint height, bool largest, const FunctionsGLX &glx,
glx::Context context, glx::FBConfig fbConfig)
: SurfaceGL(),
PbufferSurfaceGLX::PbufferSurfaceGLX(RendererGL *renderer,
EGLint width,
EGLint height,
bool largest,
const FunctionsGLX &glx,
glx::Context context,
glx::FBConfig fbConfig)
: SurfaceGL(renderer),
mWidth(width),
mHeight(height),
mLargest(largest),
......
......@@ -15,13 +15,19 @@
namespace rx
{
class DisplayGLX;
class FunctionsGLX;
class PbufferSurfaceGLX : public SurfaceGL
{
public:
PbufferSurfaceGLX(EGLint width, EGLint height, bool largest, const FunctionsGLX &glx,
glx::Context context, glx::FBConfig fbConfig);
PbufferSurfaceGLX(RendererGL *renderer,
EGLint width,
EGLint height,
bool largest,
const FunctionsGLX &glx,
glx::Context context,
glx::FBConfig fbConfig);
~PbufferSurfaceGLX() override;
egl::Error initialize() override;
......
......@@ -16,14 +16,19 @@
namespace rx
{
WindowSurfaceGLX::WindowSurfaceGLX(const FunctionsGLX &glx, const DisplayGLX &glxDisplay, Window window, Display *display,
glx::Context context, glx::FBConfig fbConfig)
: SurfaceGL(),
WindowSurfaceGLX::WindowSurfaceGLX(const FunctionsGLX &glx,
DisplayGLX *glxDisplay,
RendererGL *renderer,
Window window,
Display *display,
glx::Context context,
glx::FBConfig fbConfig)
: SurfaceGL(renderer),
mParent(window),
mWindow(0),
mDisplay(display),
mGLX(glx),
mGLXDisplay(glxDisplay),
mGLXDisplay(*glxDisplay),
mContext(context),
mFBConfig(fbConfig),
mGLXWindow(0),
......
......@@ -21,8 +21,13 @@ class FunctionsGLX;
class WindowSurfaceGLX : public SurfaceGL
{
public:
WindowSurfaceGLX(const FunctionsGLX &glx, const DisplayGLX &glxDisplay, Window window, Display *display,
glx::Context context, glx::FBConfig fbConfig);
WindowSurfaceGLX(const FunctionsGLX &glx,
DisplayGLX *glxDisplay,
RendererGL *renderer,
Window window,
Display *display,
glx::Context context,
glx::FBConfig fbConfig);
~WindowSurfaceGLX() override;
egl::Error initialize() override;
......
......@@ -321,7 +321,8 @@ SurfaceImpl *DisplayWGL::createWindowSurface(const egl::Config *configuration,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
return new WindowSurfaceWGL(window, mPixelFormat, mWGLContext, mFunctionsWGL);
return new WindowSurfaceWGL(this->getRenderer(), window, mPixelFormat, mWGLContext,
mFunctionsWGL);
}
SurfaceImpl *DisplayWGL::createPbufferSurface(const egl::Config *configuration,
......@@ -333,8 +334,8 @@ SurfaceImpl *DisplayWGL::createPbufferSurface(const egl::Config *configuration,
EGLenum textureFormat = attribs.get(EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE);
EGLenum textureTarget = attribs.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE);
return new PbufferSurfaceWGL(width, height, textureFormat, textureTarget, largest,
mPixelFormat, mDeviceContext, mWGLContext, mFunctionsWGL);
return new PbufferSurfaceWGL(this->getRenderer(), width, height, textureFormat, textureTarget,
largest, mPixelFormat, mDeviceContext, mWGLContext, mFunctionsWGL);
}
SurfaceImpl *DisplayWGL::createPbufferFromClientBuffer(const egl::Config *configuration,
......
......@@ -9,16 +9,24 @@
#include "libANGLE/renderer/gl/wgl/PbufferSurfaceWGL.h"
#include "common/debug.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
#include "libANGLE/renderer/gl/wgl/wgl_utils.h"
namespace rx
{
PbufferSurfaceWGL::PbufferSurfaceWGL(EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget,
bool largest, int pixelFormat, HDC deviceContext, HGLRC wglContext,
PbufferSurfaceWGL::PbufferSurfaceWGL(RendererGL *renderer,
EGLint width,
EGLint height,
EGLenum textureFormat,
EGLenum textureTarget,
bool largest,
int pixelFormat,
HDC deviceContext,
HGLRC wglContext,
const FunctionsWGL *functions)
: SurfaceGL(),
: SurfaceGL(renderer),
mWidth(width),
mHeight(height),
mLargest(largest),
......
......@@ -21,8 +21,15 @@ class FunctionsWGL;
class PbufferSurfaceWGL : public SurfaceGL
{
public:
PbufferSurfaceWGL(EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget,
bool largest, int pixelFormat, HDC deviceContext, HGLRC wglContext,
PbufferSurfaceWGL(RendererGL *renderer,
EGLint width,
EGLint height,
EGLenum textureFormat,
EGLenum textureTarget,
bool largest,
int pixelFormat,
HDC deviceContext,
HGLRC wglContext,
const FunctionsWGL *functions);
~PbufferSurfaceWGL() override;
......
......@@ -9,17 +9,19 @@
#include "libANGLE/renderer/gl/wgl/WindowSurfaceWGL.h"
#include "common/debug.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
#include "libANGLE/renderer/gl/wgl/wgl_utils.h"
namespace rx
{
WindowSurfaceWGL::WindowSurfaceWGL(EGLNativeWindowType window,
WindowSurfaceWGL::WindowSurfaceWGL(RendererGL *renderer,
EGLNativeWindowType window,
int pixelFormat,
HGLRC wglContext,
const FunctionsWGL *functions)
: SurfaceGL(),
: SurfaceGL(renderer),
mPixelFormat(pixelFormat),
mWGLContext(wglContext),
mWindow(window),
......
......@@ -21,7 +21,11 @@ class FunctionsWGL;
class WindowSurfaceWGL : public SurfaceGL
{
public:
WindowSurfaceWGL(EGLNativeWindowType window, int pixelFormat, HGLRC wglContext, const FunctionsWGL *functions);
WindowSurfaceWGL(RendererGL *renderer,
EGLNativeWindowType window,
int pixelFormat,
HGLRC wglContext,
const FunctionsWGL *functions);
~WindowSurfaceWGL() override;
egl::Error initialize() override;
......
......@@ -605,7 +605,7 @@ bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint
GLenum readInternalFormat = readColorBuffer->getInternalFormat();
const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat);
for (GLuint i = 0; i < context->getCaps().maxColorAttachments; i++)
for (size_t i = 0; i < drawFramebuffer->getNumColorBuffers(); i++)
{
if (drawFramebuffer->isEnabledColorAttachment(i))
{
......@@ -661,7 +661,8 @@ bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint
return false;
}
for (GLuint colorAttachment = 0; colorAttachment < context->getCaps().maxColorAttachments; ++colorAttachment)
for (size_t colorAttachment = 0;
colorAttachment < drawFramebuffer->getNumColorBuffers(); ++colorAttachment)
{
if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
{
......
......@@ -26,7 +26,6 @@ class NullFactory : public ImplFactory
ProgramImpl *createProgram(const gl::Program::Data &data) override { return nullptr; }
// Framebuffer creation
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override { return nullptr; }
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override { return nullptr; }
// Texture creation
......
......@@ -55,7 +55,7 @@ class D3D11EmulatedIndexedBufferTest : public ANGLETest
void TearDown() override
{
SafeDelete(mSourceBuffer);
ANGLETest::TearDown();
ANGLETest::TearDown();
}
void createMappableCompareBufferFromEmulatedBuffer(ID3D11Buffer *sourceBuffer, GLuint size, ID3D11Buffer **mappableBuffer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment