Hash :
7aea7e05
Author :
Date :
2016-05-10T10:39:45
Add EGLImplFactory. Also rename ImplFactory to GLImplFactory. This will allow us to use the same factory design pattern for EGL objects, and to use State helper classes to share data with Impls. BUG=angleproject:1363 BUG=angleproject:1369 Change-Id: I07a8fe40838d5d4ca32b04910c306edeab4d25a7 Reviewed-on: https://chromium-review.googlesource.com/342051 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationES unit tests:
// Unit tests for general ES validation functions.
//
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "libANGLE/ContextState.h"
#include "libANGLE/renderer/FramebufferImpl_mock.h"
#include "libANGLE/renderer/ProgramImpl_mock.h"
#include "libANGLE/renderer/TextureImpl_mock.h"
#include "libANGLE/validationES.h"
#include "tests/angle_unittests_utils.h"
using namespace gl;
using namespace rx;
using testing::_;
using testing::NiceMock;
using testing::Return;
namespace
{
class MockValidationContext : public ValidationContext
{
public:
MockValidationContext(GLint clientVersion,
const State &state,
const Caps &caps,
const TextureCapsMap &textureCaps,
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations,
bool skipValidation);
MOCK_METHOD1(handleError, void(const Error &));
};
MockValidationContext::MockValidationContext(GLint clientVersion,
const State &state,
const Caps &caps,
const TextureCapsMap &textureCaps,
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations,
bool skipValidation)
: ValidationContext(clientVersion,
state,
caps,
textureCaps,
extensions,
resourceManager,
limitations,
skipValidation)
{
}
// Test that ANGLE generates an INVALID_OPERATION when validating index data that uses a value
// larger than MAX_ELEMENT_INDEX. Not specified in the GLES 3 spec, it's undefined behaviour,
// but we want a test to ensure we maintain this behaviour.
TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
{
auto framebufferImpl = MakeFramebufferMock();
auto programImpl = MakeProgramMock();
// TODO(jmadill): Generalize some of this code so we can re-use it for other tests.
NiceMock<MockGLFactory> mockFactory;
EXPECT_CALL(mockFactory, createFramebuffer(_)).WillOnce(Return(framebufferImpl));
EXPECT_CALL(mockFactory, createProgram(_)).WillOnce(Return(programImpl));
EXPECT_CALL(mockFactory, createVertexArray(_)).WillOnce(Return(nullptr));
State state;
Caps caps;
TextureCapsMap textureCaps;
Extensions extensions;
Limitations limitations;
// Set some basic caps.
caps.maxElementIndex = 100;
caps.maxDrawBuffers = 1;
caps.maxColorAttachments = 1;
state.initialize(caps, extensions, 3, false);
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, destructor()).Times(1).RetiresOnSaturation();
Texture *texture = new Texture(&mockFactory, 0, GL_TEXTURE_2D);
texture->addRef();
texture->setStorage(GL_TEXTURE_2D, 1, GL_RGBA8, Extents(1, 1, 0));
VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1);
Framebuffer *framebuffer = new Framebuffer(caps, &mockFactory, 1);
framebuffer->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::Make2D(0), texture);
Program *program = new Program(&mockFactory, nullptr, 1);
state.setVertexArrayBinding(vertexArray);
state.setDrawFramebufferBinding(framebuffer);
state.setProgram(program);
NiceMock<MockValidationContext> testContext(3, state, caps, textureCaps, extensions, nullptr,
limitations, false);
// Set the expectation for the validation error here.
Error expectedError(GL_INVALID_OPERATION, g_ExceedsMaxElementErrorMessage);
EXPECT_CALL(testContext, handleError(expectedError)).Times(1);
// Call once with maximum index, and once with an excessive index.
GLuint indexData[] = {0, 1, static_cast<GLuint>(caps.maxElementIndex - 1),
3, 4, static_cast<GLuint>(caps.maxElementIndex)};
IndexRange indexRange;
EXPECT_TRUE(ValidateDrawElements(&testContext, GL_TRIANGLES, 3, GL_UNSIGNED_INT, indexData, 1,
&indexRange));
EXPECT_FALSE(ValidateDrawElements(&testContext, GL_TRIANGLES, 6, GL_UNSIGNED_INT, indexData, 2,
&indexRange));
texture->release();
state.setVertexArrayBinding(nullptr);
state.setDrawFramebufferBinding(nullptr);
state.setProgram(nullptr);
SafeDelete(vertexArray);
SafeDelete(framebuffer);
SafeDelete(program);
}
} // anonymous namespace