Commit e60d05b2 by Jamie Madill Committed by Commit Bot

Make Sync constructors take GLImplFactory.

Makes them consistent with the rest of the code. Will allow the Sync class to call methods in GLImplFactory to generate a resource Serial. Also updates the unit test to the new design. Bug: angleproject:4223 Change-Id: Ic5ba69c3a6a51d4b51d876c3b5e7eb7bc44a9ae8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1969060 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent 44722daa
...@@ -737,7 +737,7 @@ void Context::genFencesNV(GLsizei n, FenceNVID *fences) ...@@ -737,7 +737,7 @@ void Context::genFencesNV(GLsizei n, FenceNVID *fences)
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
GLuint handle = mFenceNVHandleAllocator.allocate(); GLuint handle = mFenceNVHandleAllocator.allocate();
mFenceNVMap.assign({handle}, new FenceNV(mImplementation->createFenceNV())); mFenceNVMap.assign({handle}, new FenceNV(mImplementation.get()));
fences[i] = {handle}; fences[i] = {handle};
} }
} }
......
...@@ -12,13 +12,14 @@ ...@@ -12,13 +12,14 @@
#include "common/utilities.h" #include "common/utilities.h"
#include "libANGLE/renderer/FenceNVImpl.h" #include "libANGLE/renderer/FenceNVImpl.h"
#include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/SyncImpl.h" #include "libANGLE/renderer/SyncImpl.h"
namespace gl namespace gl
{ {
FenceNV::FenceNV(rx::FenceNVImpl *impl) FenceNV::FenceNV(rx::GLImplFactory *factory)
: mFence(impl), mIsSet(false), mStatus(GL_FALSE), mCondition(GL_NONE) : mFence(factory->createFenceNV()), mIsSet(false), mStatus(GL_FALSE), mCondition(GL_NONE)
{} {}
FenceNV::~FenceNV() FenceNV::~FenceNV()
...@@ -57,9 +58,9 @@ angle::Result FenceNV::finish(const Context *context) ...@@ -57,9 +58,9 @@ angle::Result FenceNV::finish(const Context *context)
return angle::Result::Continue; return angle::Result::Continue;
} }
Sync::Sync(rx::SyncImpl *impl, GLuint id) Sync::Sync(rx::GLImplFactory *factory, GLuint id)
: RefCountObject(id), : RefCountObject(id),
mFence(impl), mFence(factory->createSync()),
mLabel(), mLabel(),
mCondition(GL_SYNC_GPU_COMMANDS_COMPLETE), mCondition(GL_SYNC_GPU_COMMANDS_COMPLETE),
mFlags(0) mFlags(0)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
namespace rx namespace rx
{ {
class GLImplFactory;
class FenceNVImpl; class FenceNVImpl;
class SyncImpl; class SyncImpl;
} // namespace rx } // namespace rx
...@@ -28,7 +29,7 @@ namespace gl ...@@ -28,7 +29,7 @@ namespace gl
class FenceNV final : angle::NonCopyable class FenceNV final : angle::NonCopyable
{ {
public: public:
explicit FenceNV(rx::FenceNVImpl *impl); explicit FenceNV(rx::GLImplFactory *factory);
virtual ~FenceNV(); virtual ~FenceNV();
angle::Result set(const Context *context, GLenum condition); angle::Result set(const Context *context, GLenum condition);
...@@ -51,7 +52,7 @@ class FenceNV final : angle::NonCopyable ...@@ -51,7 +52,7 @@ class FenceNV final : angle::NonCopyable
class Sync final : public RefCountObject<GLuint>, public LabeledObject class Sync final : public RefCountObject<GLuint>, public LabeledObject
{ {
public: public:
Sync(rx::SyncImpl *impl, GLuint id); Sync(rx::GLImplFactory *factory, GLuint id);
~Sync() override; ~Sync() override;
void onDestroy(const Context *context) override; void onDestroy(const Context *context) override;
...@@ -70,6 +71,8 @@ class Sync final : public RefCountObject<GLuint>, public LabeledObject ...@@ -70,6 +71,8 @@ class Sync final : public RefCountObject<GLuint>, public LabeledObject
GLenum getCondition() const { return mCondition; } GLenum getCondition() const { return mCondition; }
GLbitfield getFlags() const { return mFlags; } GLbitfield getFlags() const { return mFlags; }
rx::SyncImpl *getImplementation() const { return mFence; }
private: private:
rx::SyncImpl *mFence; rx::SyncImpl *mFence;
......
...@@ -10,11 +10,9 @@ ...@@ -10,11 +10,9 @@
#include "libANGLE/Fence.h" #include "libANGLE/Fence.h"
#include "libANGLE/renderer/FenceNVImpl.h" #include "libANGLE/renderer/FenceNVImpl.h"
#include "libANGLE/renderer/SyncImpl.h" #include "libANGLE/renderer/SyncImpl.h"
#include "tests/angle_unittests_utils.h"
using ::testing::_; using namespace testing;
using ::testing::DoAll;
using ::testing::Return;
using ::testing::SetArgumentPointee;
namespace namespace
{ {
...@@ -35,36 +33,25 @@ class MockFenceNVImpl : public rx::FenceNVImpl ...@@ -35,36 +33,25 @@ class MockFenceNVImpl : public rx::FenceNVImpl
MOCK_METHOD0(destroy, void()); MOCK_METHOD0(destroy, void());
}; };
class FenceNVTest : public testing::Test class FenceNVTest : public Test
{ {
protected: protected:
virtual void SetUp() void SetUp() override
{ {
mImpl = new MockFenceNVImpl; mImpl = new MockFenceNVImpl;
EXPECT_CALL(factory, createFenceNV()).WillOnce(Return(mImpl));
EXPECT_CALL(*mImpl, destroy()); EXPECT_CALL(*mImpl, destroy());
mFence = new gl::FenceNV(mImpl); mFence = new gl::FenceNV(&factory);
} }
virtual void TearDown() { delete mFence; } void TearDown() override { delete mFence; }
NiceMock<rx::MockGLFactory> factory;
MockFenceNVImpl *mImpl; MockFenceNVImpl *mImpl;
gl::FenceNV *mFence; gl::FenceNV *mFence;
}; };
TEST_F(FenceNVTest, DestructionDeletesImpl)
{
MockFenceNVImpl *impl = new MockFenceNVImpl;
EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation();
gl::FenceNV *fence = new gl::FenceNV(impl);
delete fence;
// 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.
testing::Mock::VerifyAndClear(impl);
}
TEST_F(FenceNVTest, SetAndTestBehavior) TEST_F(FenceNVTest, SetAndTestBehavior)
{ {
EXPECT_CALL(*mImpl, set(_, _)).WillOnce(Return(angle::Result::Continue)).RetiresOnSaturation(); EXPECT_CALL(*mImpl, set(_, _)).WillOnce(Return(angle::Result::Continue)).RetiresOnSaturation();
...@@ -102,38 +89,26 @@ class MockSyncImpl : public rx::SyncImpl ...@@ -102,38 +89,26 @@ class MockSyncImpl : public rx::SyncImpl
MOCK_METHOD0(destroy, void()); MOCK_METHOD0(destroy, void());
}; };
class FenceSyncTest : public testing::Test class FenceSyncTest : public Test
{ {
protected: protected:
virtual void SetUp() void SetUp() override
{ {
mImpl = new MockSyncImpl; mImpl = new MockSyncImpl;
EXPECT_CALL(factory, createSync()).WillOnce(Return(mImpl));
mFence = new gl::Sync(&factory, 1);
EXPECT_CALL(*mImpl, destroy()); EXPECT_CALL(*mImpl, destroy());
mFence = new gl::Sync(mImpl, 1);
mFence->addRef(); mFence->addRef();
} }
virtual void TearDown() { mFence->release(nullptr); } void TearDown() override { mFence->release(nullptr); }
NiceMock<rx::MockGLFactory> factory;
MockSyncImpl *mImpl; MockSyncImpl *mImpl;
gl::Sync *mFence; gl::Sync *mFence;
}; };
TEST_F(FenceSyncTest, DestructionDeletesImpl)
{
MockSyncImpl *impl = new MockSyncImpl;
EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation();
gl::Sync *fence = new gl::Sync(impl, 1);
fence->addRef();
fence->release(nullptr);
// 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.
testing::Mock::VerifyAndClear(impl);
}
TEST_F(FenceSyncTest, SetAndGetStatusBehavior) TEST_F(FenceSyncTest, SetAndGetStatusBehavior)
{ {
EXPECT_CALL(*mImpl, set(_, _, _)) EXPECT_CALL(*mImpl, set(_, _, _))
......
...@@ -335,7 +335,7 @@ void SyncManager::DeleteObject(const Context *context, Sync *sync) ...@@ -335,7 +335,7 @@ void SyncManager::DeleteObject(const Context *context, Sync *sync)
GLuint SyncManager::createSync(rx::GLImplFactory *factory) GLuint SyncManager::createSync(rx::GLImplFactory *factory)
{ {
GLuint handle = mHandleAllocator.allocate(); GLuint handle = mHandleAllocator.allocate();
Sync *sync = new Sync(factory->createSync(), handle); Sync *sync = new Sync(factory, handle);
sync->addRef(); sync->addRef();
mObjectMap.assign(handle, sync); mObjectMap.assign(handle, sync);
return handle; return handle;
......
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