Commit 82c47ad0 by Olli Etuaho Committed by Commit Bot

Pass ImplFactory to Texture constructor

This improves encapsulation inside the Texture class, and removes duplication of createTexture calls. This is a necessary step towards adding a shared "Data" structure to the Texture classes, following a similar pattern as for example the Framebuffer class. This patch also shares the same MockFactory class among different unit tests. BUG=angleproject:596 TEST=angle_unittests Change-Id: Ie8d3a9aa4ec35565d7ecbabb8c40e7b1ba068721 Reviewed-on: https://chromium-review.googlesource.com/340200Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent e4857c7d
...@@ -172,19 +172,19 @@ Context::Context(const egl::Config *config, ...@@ -172,19 +172,19 @@ Context::Context(const egl::Config *config,
// In order that access to these initial textures not be lost, they are treated as texture // In order that access to these initial textures not be lost, they are treated as texture
// objects all of whose names are 0. // objects all of whose names are 0.
Texture *zeroTexture2D = new Texture(mRenderer->createTexture(GL_TEXTURE_2D), 0, GL_TEXTURE_2D); Texture *zeroTexture2D = new Texture(mRenderer, 0, GL_TEXTURE_2D);
mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D); mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D);
Texture *zeroTextureCube = new Texture(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), 0, GL_TEXTURE_CUBE_MAP); Texture *zeroTextureCube = new Texture(mRenderer, 0, GL_TEXTURE_CUBE_MAP);
mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube); mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube);
if (mClientVersion >= 3) if (mClientVersion >= 3)
{ {
// TODO: These could also be enabled via extension // TODO: These could also be enabled via extension
Texture *zeroTexture3D = new Texture(mRenderer->createTexture(GL_TEXTURE_3D), 0, GL_TEXTURE_3D); Texture *zeroTexture3D = new Texture(mRenderer, 0, GL_TEXTURE_3D);
mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D); mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D);
Texture *zeroTexture2DArray = new Texture(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), 0, GL_TEXTURE_2D_ARRAY); Texture *zeroTexture2DArray = new Texture(mRenderer, 0, GL_TEXTURE_2D_ARRAY);
mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray); mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray);
} }
......
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
#include "libANGLE/renderer/ImageImpl_mock.h" #include "libANGLE/renderer/ImageImpl_mock.h"
#include "libANGLE/renderer/TextureImpl_mock.h" #include "libANGLE/renderer/TextureImpl_mock.h"
#include "libANGLE/renderer/RenderbufferImpl_mock.h" #include "libANGLE/renderer/RenderbufferImpl_mock.h"
#include "tests/angle_unittests_utils.h"
using ::testing::_; using ::testing::_;
using ::testing::NiceMock;
using ::testing::Return; using ::testing::Return;
namespace angle namespace angle
...@@ -23,9 +25,11 @@ namespace angle ...@@ -23,9 +25,11 @@ namespace angle
// Verify ref counts are maintained between images and their siblings when objects are deleted // Verify ref counts are maintained between images and their siblings when objects are deleted
TEST(ImageTest, RefCounting) TEST(ImageTest, RefCounting)
{ {
NiceMock<rx::MockFactory> mockFactory;
// Create a texture and an EGL image that uses the texture as its source // Create a texture and an EGL image that uses the texture as its source
rx::MockTextureImpl *textureImpl = new rx::MockTextureImpl(); rx::MockTextureImpl *textureImpl = new rx::MockTextureImpl();
gl::Texture *texture = new gl::Texture(textureImpl, 1, GL_TEXTURE_2D); EXPECT_CALL(mockFactory, createTexture(_)).WillOnce(Return(textureImpl));
gl::Texture *texture = new gl::Texture(&mockFactory, 1, GL_TEXTURE_2D);
texture->addRef(); texture->addRef();
rx::MockImageImpl *imageImpl = new rx::MockImageImpl(); rx::MockImageImpl *imageImpl = new rx::MockImageImpl();
...@@ -82,9 +86,11 @@ TEST(ImageTest, RefCounting) ...@@ -82,9 +86,11 @@ TEST(ImageTest, RefCounting)
// Verify that respecifiying textures releases references to the Image. // Verify that respecifiying textures releases references to the Image.
TEST(ImageTest, RespecificationReleasesReferences) TEST(ImageTest, RespecificationReleasesReferences)
{ {
NiceMock<rx::MockFactory> mockFactory;
// Create a texture and an EGL image that uses the texture as its source // Create a texture and an EGL image that uses the texture as its source
rx::MockTextureImpl *textureImpl = new rx::MockTextureImpl(); rx::MockTextureImpl *textureImpl = new rx::MockTextureImpl();
gl::Texture *texture = new gl::Texture(textureImpl, 1, GL_TEXTURE_2D); EXPECT_CALL(mockFactory, createTexture(_)).WillOnce(Return(textureImpl));
gl::Texture *texture = new gl::Texture(&mockFactory, 1, GL_TEXTURE_2D);
texture->addRef(); texture->addRef();
gl::PixelUnpackState defaultUnpackState; gl::PixelUnpackState defaultUnpackState;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "tests/angle_unittests_utils.h"
#include "libANGLE/Program.h" #include "libANGLE/Program.h"
using namespace gl; using namespace gl;
......
...@@ -403,7 +403,7 @@ Texture *ResourceManager::checkTextureAllocation(GLuint handle, GLenum type) ...@@ -403,7 +403,7 @@ Texture *ResourceManager::checkTextureAllocation(GLuint handle, GLenum type)
return textureMapIt->second; return textureMapIt->second;
} }
Texture *texture = new Texture(mFactory->createTexture(type), handle, type); Texture *texture = new Texture(mFactory, handle, type);
texture->addRef(); texture->addRef();
if (handleAllocated) if (handleAllocated)
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "tests/angle_unittests_utils.h"
#include "libANGLE/ResourceManager.h" #include "libANGLE/ResourceManager.h"
#include "tests/angle_unittests_utils.h"
using namespace rx; using namespace rx;
using namespace gl; using namespace gl;
...@@ -18,14 +18,6 @@ using namespace gl; ...@@ -18,14 +18,6 @@ using namespace gl;
namespace namespace
{ {
class MockFactory : public NullFactory
{
public:
MOCK_METHOD0(createBuffer, BufferImpl*());
MOCK_METHOD1(createTexture, TextureImpl*(GLenum));
MOCK_METHOD0(createRenderbuffer, RenderbufferImpl*());
};
class ResourceManagerTest : public testing::Test class ResourceManagerTest : public testing::Test
{ {
protected: protected:
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "libANGLE/Image.h" #include "libANGLE/Image.h"
#include "libANGLE/Surface.h" #include "libANGLE/Surface.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/ImplFactory.h"
#include "libANGLE/renderer/TextureImpl.h"
namespace gl namespace gl
{ {
...@@ -47,9 +49,9 @@ static size_t GetImageDescIndex(GLenum target, size_t level) ...@@ -47,9 +49,9 @@ static size_t GetImageDescIndex(GLenum target, size_t level)
return IsCubeMapTextureTarget(target) ? ((level * 6) + CubeMapTextureTargetToLayerIndex(target)) : level; return IsCubeMapTextureTarget(target) ? ((level * 6) + CubeMapTextureTargetToLayerIndex(target)) : level;
} }
Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target) Texture::Texture(rx::ImplFactory *factory, GLuint id, GLenum target)
: egl::ImageSibling(id), : egl::ImageSibling(id),
mTexture(impl), mTexture(factory->createTexture(target)),
mLabel(), mLabel(),
mTextureState(), mTextureState(),
mTarget(target), mTarget(target),
...@@ -863,4 +865,9 @@ GLuint Texture::getId() const ...@@ -863,4 +865,9 @@ GLuint Texture::getId() const
{ {
return id(); return id();
} }
rx::FramebufferAttachmentObjectImpl *Texture::getAttachmentImpl() const
{
return mTexture;
}
} }
...@@ -21,13 +21,18 @@ ...@@ -21,13 +21,18 @@
#include "libANGLE/FramebufferAttachment.h" #include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Image.h" #include "libANGLE/Image.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/renderer/TextureImpl.h"
namespace egl namespace egl
{ {
class Surface; class Surface;
} }
namespace rx
{
class ImplFactory;
class TextureImpl;
}
namespace gl namespace gl
{ {
class Framebuffer; class Framebuffer;
...@@ -40,7 +45,7 @@ class Texture final : public egl::ImageSibling, ...@@ -40,7 +45,7 @@ class Texture final : public egl::ImageSibling,
public LabeledObject public LabeledObject
{ {
public: public:
Texture(rx::TextureImpl *impl, GLuint id, GLenum target); Texture(rx::ImplFactory *factory, GLuint id, GLenum target);
~Texture() override; ~Texture() override;
void setLabel(const std::string &label) override; void setLabel(const std::string &label) override;
...@@ -180,7 +185,7 @@ class Texture final : public egl::ImageSibling, ...@@ -180,7 +185,7 @@ class Texture final : public egl::ImageSibling,
GLuint getId() const override; GLuint getId() const override;
private: private:
rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override { return mTexture; } rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override;
// ANGLE-only method, used internally // ANGLE-only method, used internally
friend class egl::Surface; friend class egl::Surface;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "libANGLE/Buffer.h" #include "libANGLE/Buffer.h"
#include "libANGLE/Caps.h" #include "libANGLE/Caps.h"
#include "libANGLE/Data.h"
#include "libANGLE/Program.h" #include "libANGLE/Program.h"
#include "libANGLE/renderer/ImplFactory.h" #include "libANGLE/renderer/ImplFactory.h"
#include "libANGLE/renderer/TransformFeedbackImpl.h" #include "libANGLE/renderer/TransformFeedbackImpl.h"
......
...@@ -20,12 +20,6 @@ using ::testing::SetArgumentPointee; ...@@ -20,12 +20,6 @@ using ::testing::SetArgumentPointee;
namespace namespace
{ {
class MockFactory : public rx::NullFactory
{
public:
MOCK_METHOD0(createTransformFeedback, rx::TransformFeedbackImpl *());
};
class TransformFeedbackTest : public testing::Test class TransformFeedbackTest : public testing::Test
{ {
protected: protected:
...@@ -59,7 +53,7 @@ class TransformFeedbackTest : public testing::Test ...@@ -59,7 +53,7 @@ class TransformFeedbackTest : public testing::Test
testing::Mock::VerifyAndClear(mImpl); testing::Mock::VerifyAndClear(mImpl);
} }
MockFactory mMockFactory; rx::MockFactory mMockFactory;
rx::MockTransformFeedbackImpl* mImpl; rx::MockTransformFeedbackImpl* mImpl;
gl::TransformFeedback* mFeedback; gl::TransformFeedback* mFeedback;
gl::Caps mCaps; gl::Caps mCaps;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/Framebuffer.h" #include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h" #include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/renderer/TextureImpl.h"
#include "libANGLE/renderer/d3d/BufferD3D.h" #include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h" #include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/DisplayD3D.h" #include "libANGLE/renderer/d3d/DisplayD3D.h"
...@@ -440,8 +441,7 @@ gl::Texture *RendererD3D::getIncompleteTexture(GLenum type) ...@@ -440,8 +441,7 @@ gl::Texture *RendererD3D::getIncompleteTexture(GLenum type)
const gl::Box area(0, 0, 0, 1, 1, 1); const gl::Box area(0, 0, 0, 1, 1, 1);
// Skip the API layer to avoid needing to pass the Context and mess with dirty bits. // Skip the API layer to avoid needing to pass the Context and mess with dirty bits.
gl::Texture *t = gl::Texture *t = new gl::Texture(this, std::numeric_limits<GLuint>::max(), type);
new gl::Texture(createTexture(type), std::numeric_limits<GLuint>::max(), type);
t->setStorage(type, 1, GL_RGBA8, colorSize); t->setStorage(type, 1, GL_RGBA8, colorSize);
if (type == GL_TEXTURE_CUBE_MAP) if (type == GL_TEXTURE_CUBE_MAP)
......
...@@ -26,14 +26,6 @@ using testing::Return; ...@@ -26,14 +26,6 @@ using testing::Return;
namespace namespace
{ {
class MockFactory : public NullFactory
{
public:
MOCK_METHOD1(createFramebuffer, FramebufferImpl *(const gl::Framebuffer::Data &));
MOCK_METHOD1(createProgram, ProgramImpl *(const gl::Program::Data &));
MOCK_METHOD1(createVertexArray, VertexArrayImpl *(const gl::VertexArray::Data &));
};
class MockValidationContext : public ValidationContext class MockValidationContext : public ValidationContext
{ {
public: public:
...@@ -95,10 +87,11 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError) ...@@ -95,10 +87,11 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
state.initialize(caps, extensions, 3, false); state.initialize(caps, extensions, 3, false);
NiceMock<MockTextureImpl> *textureImpl = new NiceMock<MockTextureImpl>(); NiceMock<MockTextureImpl> *textureImpl = new NiceMock<MockTextureImpl>();
EXPECT_CALL(mockFactory, createTexture(_)).WillOnce(Return(textureImpl));
EXPECT_CALL(*textureImpl, setStorage(_, _, _, _)).WillOnce(Return(Error(GL_NO_ERROR))); EXPECT_CALL(*textureImpl, setStorage(_, _, _, _)).WillOnce(Return(Error(GL_NO_ERROR)));
EXPECT_CALL(*textureImpl, destructor()).Times(1).RetiresOnSaturation(); EXPECT_CALL(*textureImpl, destructor()).Times(1).RetiresOnSaturation();
Texture *texture = new Texture(textureImpl, 0, GL_TEXTURE_2D); Texture *texture = new Texture(&mockFactory, 0, GL_TEXTURE_2D);
texture->addRef(); texture->addRef();
texture->setStorage(GL_TEXTURE_2D, 1, GL_RGBA8, Extents(1, 1, 0)); texture->setStorage(GL_TEXTURE_2D, 1, GL_RGBA8, Extents(1, 1, 0));
......
...@@ -52,6 +52,24 @@ class NullFactory : public ImplFactory ...@@ -52,6 +52,24 @@ class NullFactory : public ImplFactory
SamplerImpl *createSampler() override { return nullptr; } SamplerImpl *createSampler() override { return nullptr; }
}; };
// A class with all the factory methods mocked.
class MockFactory : public ImplFactory
{
public:
MOCK_METHOD0(createCompiler, CompilerImpl *());
MOCK_METHOD1(createShader, ShaderImpl *(const gl::Shader::Data &));
MOCK_METHOD1(createProgram, ProgramImpl *(const gl::Program::Data &));
MOCK_METHOD1(createFramebuffer, FramebufferImpl *(const gl::Framebuffer::Data &));
MOCK_METHOD1(createTexture, TextureImpl *(GLenum target));
MOCK_METHOD0(createRenderbuffer, RenderbufferImpl *());
MOCK_METHOD0(createBuffer, BufferImpl *());
MOCK_METHOD1(createVertexArray, VertexArrayImpl *(const gl::VertexArray::Data &));
MOCK_METHOD1(createQuery, QueryImpl *(GLenum type));
MOCK_METHOD0(createFenceNV, FenceNVImpl *());
MOCK_METHOD0(createFenceSync, FenceSyncImpl *());
MOCK_METHOD0(createTransformFeedback, TransformFeedbackImpl *());
MOCK_METHOD0(createSampler, SamplerImpl *());
};
} }
#endif // TESTS_ANGLE_UNITTESTS_UTILS_H_ #endif // TESTS_ANGLE_UNITTESTS_UTILS_H_
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