Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Unified Diff: gpu/command_buffer/client/gles2_implementation_unittest.cc

Issue 7792008: Manually merging trunk revs 95836 and 96904 to 835 branch (third attempt, nacl should be fixed) (Closed) Base URL: svn://svn.chromium.org/chrome/branches/835/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/client/gles2_implementation_unittest.cc
===================================================================
--- gpu/command_buffer/client/gles2_implementation_unittest.cc (revision 98673)
+++ gpu/command_buffer/client/gles2_implementation_unittest.cc (working copy)
@@ -131,13 +131,14 @@
namespace gles2 {
-using testing::Return;
+using testing::_;
+using testing::DoAll;
+using testing::InSequence;
+using testing::Invoke;
using testing::Mock;
+using testing::Sequence;
using testing::Truly;
-using testing::Sequence;
-using testing::DoAll;
-using testing::Invoke;
-using testing::_;
+using testing::Return;
ACTION_P(SetMemory, obj) {
memcpy(arg0, &obj, sizeof(obj));
@@ -209,6 +210,7 @@
static const GLint kMaxVertexUniformVectors = 128;
static const GLint kNumCompressedTextureFormats = 0;
static const GLint kNumShaderBinaryFormats = 0;
+ static const GLuint kStartId = 1024;
GLES2ImplementationTest()
: commands_(NULL),
@@ -217,6 +219,13 @@
}
virtual void SetUp() {
+ Initialize(false, true);
+ }
+
+ virtual void TearDown() {
+ }
+
+ void Initialize(bool shared_resources, bool bind_generates_resource) {
offset_ = GLES2Implementation::kStartingOffset;
command_buffer_.reset(new MockGLES2CommandBuffer());
@@ -250,18 +259,49 @@
AllocateTransferBuffer(sizeof(state)); // in
uint32 offset = AllocateTransferBuffer(sizeof(state)); // out
- EXPECT_CALL(*command_buffer_, OnFlush(_))
- .WillOnce(SetMemoryAtOffset(offset, state))
- .RetiresOnSaturation();
- GetNextToken(); // eat the token that starting up will use.
+ {
+ InSequence sequence;
- gl_.reset(new GLES2Implementation(
- helper_.get(),
- kTransferBufferSize,
- transfer_buffer_.ptr,
- kTransferBufferId,
- false));
+ EXPECT_CALL(*command_buffer_, OnFlush(_))
+ .WillOnce(SetMemoryAtOffset(offset, state))
+ .RetiresOnSaturation();
+ GetNextToken(); // eat the token that starting up will use.
+ // Must match StrictSharedIdHandler::kNumIdsToGet.
+ GLuint num_ids = 2048;
+ scoped_array<GLuint> all_ids(new GLuint[num_ids]);
+ if (shared_resources) {
+ if (!bind_generates_resource) {
+ GLuint start = kStartId;
+ GLuint max_num_per = MaxTransferBufferSize() / sizeof(GLuint);
+ GLuint* ids = all_ids.get();
+ for (GLuint ii = 0; ii < num_ids; ++ii) {
+ ids[ii] = start + ii;
+ }
+ while (num_ids) {
+ GLuint num = std::min(num_ids, max_num_per);
+ size_t size = num * sizeof(ids[0]);
+ uint32 offset = AllocateTransferBuffer(size);
+ EXPECT_CALL(*command_buffer_, OnFlush(_))
+ .WillOnce(SetMemoryAtOffsetFromArray(offset, ids, size))
+ .RetiresOnSaturation();
+ GetNextToken();
+ start += num;
+ ids += num;
+ num_ids -= num;
+ }
+ }
+ }
+
+ gl_.reset(new GLES2Implementation(
+ helper_.get(),
+ kTransferBufferSize,
+ transfer_buffer_.ptr,
+ kTransferBufferId,
+ shared_resources,
+ bind_generates_resource));
+ }
+
EXPECT_CALL(*command_buffer_, OnFlush(_))
.Times(1)
.RetiresOnSaturation();
@@ -272,9 +312,6 @@
ClearCommands();
}
- virtual void TearDown() {
- }
-
const void* GetPut() {
return helper_->GetSpace(0);
}
@@ -335,6 +372,13 @@
uint32 offset_;
};
+class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest {
+ protected:
+ virtual void SetUp() {
+ Initialize(true, false);
+ }
+};
+
// GCC requires these declarations, but MSVC requires they not be present
#ifndef _MSC_VER
const int32 GLES2ImplementationTest::kTransferBufferId;
@@ -1687,6 +1731,78 @@
GetTransferAddressFromOffsetAs<uint8>(offset4, part_size)));
}
+// Test that GenBuffer does not call GenSharedIds.
+// This is because with client side arrays on we know the StrictSharedIdHandler
+// for buffers has already gotten a set of ids
+TEST_F(GLES2ImplementationStrictSharedTest, GenBuffer) {
+ // Starts at + 2 because client side arrays take first 2 ids.
+ GLuint ids[3] = { kStartId + 2, kStartId + 3, kStartId + 4 };
+ struct Cmds {
+ GenBuffersImmediate gen;
+ GLuint data[3];
+ };
+ Cmds expected;
+ expected.gen.Init(arraysize(ids), &ids[0]);
+ gl_->GenBuffers(arraysize(ids), &ids[0]);
+ EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
+ EXPECT_NE(0u, ids[0]);
+ EXPECT_NE(0u, ids[1]);
+ EXPECT_NE(0u, ids[2]);
+}
+
+// Binds can not be cached with bind_generates_resource = false because
+// our id might not be valid.
+TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) {
+ struct PNameValue {
+ GLenum pname;
+ GLint expected;
+ };
+ const PNameValue pairs[] = {
+ { GL_TEXTURE_BINDING_2D, 1, },
+ { GL_TEXTURE_BINDING_CUBE_MAP, 2, },
+ { GL_FRAMEBUFFER_BINDING, 3, },
+ { GL_RENDERBUFFER_BINDING, 4, },
+ { GL_ARRAY_BUFFER_BINDING, 5, },
+ { GL_ELEMENT_ARRAY_BUFFER_BINDING, 6, },
+ };
+ size_t num_pairs = sizeof(pairs) / sizeof(pairs[0]);
+ for (size_t ii = 0; ii < num_pairs; ++ii) {
+ const PNameValue& pv = pairs[ii];
+ GLint v = -1;
+ EXPECT_CALL(*command_buffer_, OnFlush(_))
+ .WillOnce(SetMemory(SizedResultHelper<GLuint>(pv.expected)))
+ .RetiresOnSaturation();
+ gl_->GetIntegerv(pv.pname, &v);
+ EXPECT_EQ(pv.expected, v);
+ }
+}
+
+TEST_F(GLES2ImplementationStrictSharedTest, CanNotDeleteIdsWeDidNotCreate) {
+ GLuint id = 0x12345678;
+
+ EXPECT_CALL(*command_buffer_, OnFlush(_))
+ .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
+ .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
+ .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
+ .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
+ .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
+ .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
+ .RetiresOnSaturation();
+
+ gl_->DeleteBuffers(1, &id);
+ EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
+ gl_->DeleteFramebuffers(1, &id);
+ EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
+ gl_->DeleteRenderbuffers(1, &id);
+ EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
+ gl_->DeleteTextures(1, &id);
+ EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
+ gl_->DeleteProgram(id);
+ EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
+ gl_->DeleteShader(id);
+ EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
+}
+
} // namespace gles2
} // namespace gpu
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation_autogen.h ('k') | gpu/command_buffer/client/program_info_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698