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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc

Issue 7845017: Fix bug in SimulateAttrib0 that did not check for out of memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include "base/atomicops.h" 7 #include "base/atomicops.h"
8 #include "gpu/command_buffer/common/gles2_cmd_format.h" 8 #include "gpu/command_buffer/common/gles2_cmd_format.h"
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 9 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
10 #include "gpu/command_buffer/common/gl_mock.h" 10 #include "gpu/command_buffer/common/gl_mock.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 GLsizei in_read_width, GLsizei in_read_height, 48 GLsizei in_read_width, GLsizei in_read_height,
49 bool init); 49 bool init);
50 }; 50 };
51 51
52 class GLES2DecoderWithShaderTest : public GLES2DecoderWithShaderTestBase { 52 class GLES2DecoderWithShaderTest : public GLES2DecoderWithShaderTestBase {
53 public: 53 public:
54 GLES2DecoderWithShaderTest() 54 GLES2DecoderWithShaderTest()
55 : GLES2DecoderWithShaderTestBase() { 55 : GLES2DecoderWithShaderTestBase() {
56 } 56 }
57 57
58 void AddExpectationsForSimulatedAttrib0( 58
59 GLsizei num_vertices, GLuint buffer_id) { 59 void AddExpectationsForSimulatedAttrib0WithError(
60 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
61 EXPECT_CALL(*gl_, GetError())
62 .WillOnce(Return(GL_NO_ERROR))
63 .WillOnce(Return(error))
64 .RetiresOnSaturation();
60 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) 65 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
61 .Times(1) 66 .Times(1)
62 .RetiresOnSaturation(); 67 .RetiresOnSaturation();
63 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER, 68 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
64 num_vertices * sizeof(GLfloat) * 4, 69 num_vertices * sizeof(GLfloat) * 4,
65 _, GL_DYNAMIC_DRAW)) 70 _, GL_DYNAMIC_DRAW))
66 .Times(1) 71 .Times(1)
67 .RetiresOnSaturation(); 72 .RetiresOnSaturation();
68 EXPECT_CALL(*gl_, BufferSubData( 73 if (error == GL_NO_ERROR) {
69 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _)) 74 EXPECT_CALL(*gl_, BufferSubData(
70 .Times(1) 75 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
71 .RetiresOnSaturation(); 76 .Times(1)
72 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) 77 .RetiresOnSaturation();
73 .Times(1) 78 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
74 .RetiresOnSaturation(); 79 .Times(1)
75 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) 80 .RetiresOnSaturation();
76 .Times(1) 81 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
77 .RetiresOnSaturation(); 82 .Times(1)
78 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) 83 .RetiresOnSaturation();
79 .Times(1) 84 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
80 .RetiresOnSaturation(); 85 .Times(1)
81 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id)) 86 .RetiresOnSaturation();
82 .Times(1) 87 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
83 .RetiresOnSaturation(); 88 .Times(1)
89 .RetiresOnSaturation();
90 }
91 }
92
93 void AddExpectationsForSimulatedAttrib0(
94 GLsizei num_vertices, GLuint buffer_id) {
95 AddExpectationsForSimulatedAttrib0WithError(
96 num_vertices, buffer_id, GL_NO_ERROR);
84 } 97 }
85 }; 98 };
86 99
87 class GLES2DecoderRGBBackbufferTest : public GLES2DecoderWithShaderTest { 100 class GLES2DecoderRGBBackbufferTest : public GLES2DecoderWithShaderTest {
88 public: 101 public:
89 GLES2DecoderRGBBackbufferTest() { } 102 GLES2DecoderRGBBackbufferTest() { }
90 103
91 virtual void SetUp() { 104 virtual void SetUp() {
92 InitDecoder( 105 InitDecoder(
93 "", // extensions 106 "", // extensions
(...skipping 24 matching lines...) Expand all
118 131
119 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) 132 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
120 .Times(1) 133 .Times(1)
121 .RetiresOnSaturation(); 134 .RetiresOnSaturation();
122 DrawArrays cmd; 135 DrawArrays cmd;
123 cmd.Init(GL_TRIANGLES, 0, kNumVertices); 136 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
124 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 137 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
125 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 138 EXPECT_EQ(GL_NO_ERROR, GetGLError());
126 } 139 }
127 140
141 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
142 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OverflowFails) {
143 const GLsizei kLargeCount = 0x40000000;
144 SetupTexture();
145 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
146 .Times(0)
147 .RetiresOnSaturation();
148 DrawArrays cmd;
149 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
150 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
151 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
152 }
153
154 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
155 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0PosToNegFails) {
156 const GLsizei kLargeCount = 0x7FFFFFFF;
157 SetupTexture();
158 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
159 .Times(0)
160 .RetiresOnSaturation();
161 DrawArrays cmd;
162 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
163 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
164 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
165 }
166
167 // Tests when the driver returns an error
168 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OOMFails) {
169 const GLsizei kFakeLargeCount = 0x1234;
170 SetupTexture();
171 AddExpectationsForSimulatedAttrib0WithError(
172 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
173 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
174 .Times(0)
175 .RetiresOnSaturation();
176 DrawArrays cmd;
177 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
179 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
180 }
181
128 TEST_F(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) { 182 TEST_F(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) {
129 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 183 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
130 // This is an NPOT texture. As the default filtering requires mips 184 // This is an NPOT texture. As the default filtering requires mips
131 // this should trigger replacing with black textures before rendering. 185 // this should trigger replacing with black textures before rendering.
132 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 186 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
133 0, 0); 187 0, 0);
134 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); 188 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
135 { 189 {
136 InSequence sequence; 190 InSequence sequence;
137 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) 191 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
(...skipping 4428 matching lines...) Expand 10 before | Expand all | Expand 10 after
4566 // TODO(gman): TexImage2DImmediate 4620 // TODO(gman): TexImage2DImmediate
4567 4621
4568 // TODO(gman): TexSubImage2DImmediate 4622 // TODO(gman): TexSubImage2DImmediate
4569 4623
4570 // TODO(gman): UseProgram 4624 // TODO(gman): UseProgram
4571 4625
4572 // TODO(gman): SwapBuffers 4626 // TODO(gman): SwapBuffers
4573 4627
4574 } // namespace gles2 4628 } // namespace gles2
4575 } // namespace gpu 4629 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698