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

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

Issue 7633060: Add option to not generate resources on bind in OpenGL ES (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nacl fix 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
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation_autogen.h ('k') | gpu/command_buffer/common/id_allocator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/gles2_implementation_unittest.cc
diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc
index 68ae339a78006f9db2cb554d573abfb4d9a15cc1..324d51fdc010d1a7c5d38130747ca3b570e75dc6 100644
--- a/gpu/command_buffer/client/gles2_implementation_unittest.cc
+++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc
@@ -130,13 +130,14 @@ const int32 GLES2MockCommandBufferHelper::kTransferBufferId;
namespace gles2 {
-using testing::Return;
-using testing::Mock;
-using testing::Truly;
-using testing::Sequence;
+using testing::_;
using testing::DoAll;
+using testing::InSequence;
using testing::Invoke;
-using testing::_;
+using testing::Mock;
+using testing::Sequence;
+using testing::Truly;
+using testing::Return;
ACTION_P(SetMemory, obj) {
memcpy(arg0, &obj, sizeof(obj));
@@ -208,6 +209,7 @@ class GLES2ImplementationTest : public testing::Test {
static const GLint kMaxVertexUniformVectors = 128;
static const GLint kNumCompressedTextureFormats = 0;
static const GLint kNumShaderBinaryFormats = 0;
+ static const GLuint kStartId = 1024;
GLES2ImplementationTest()
: commands_(NULL),
@@ -216,6 +218,13 @@ class GLES2ImplementationTest : public testing::Test {
}
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());
@@ -249,17 +258,48 @@ class GLES2ImplementationTest : public testing::Test {
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.
-
- gl_.reset(new GLES2Implementation(
- helper_.get(),
- kTransferBufferSize,
- transfer_buffer_.ptr,
- kTransferBufferId,
- false));
+ {
+ InSequence sequence;
+
+ 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)
@@ -271,9 +311,6 @@ class GLES2ImplementationTest : public testing::Test {
ClearCommands();
}
- virtual void TearDown() {
- }
-
const void* GetPut() {
return helper_->GetSpace(0);
}
@@ -334,6 +371,13 @@ class GLES2ImplementationTest : public testing::Test {
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;
@@ -1686,6 +1730,78 @@ TEST_F(GLES2ImplementationTest, TexImage2DSubRows) {
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/common/id_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698