OLD | NEW |
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 Loading... |
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 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 62 return; |
| 63 } |
| 64 |
| 65 EXPECT_CALL(*gl_, GetError()) |
| 66 .WillOnce(Return(GL_NO_ERROR)) |
| 67 .WillOnce(Return(error)) |
| 68 .RetiresOnSaturation(); |
60 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) | 69 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) |
61 .Times(1) | 70 .Times(1) |
62 .RetiresOnSaturation(); | 71 .RetiresOnSaturation(); |
63 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER, | 72 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER, |
64 num_vertices * sizeof(GLfloat) * 4, | 73 num_vertices * sizeof(GLfloat) * 4, |
65 _, GL_DYNAMIC_DRAW)) | 74 _, GL_DYNAMIC_DRAW)) |
66 .Times(1) | 75 .Times(1) |
67 .RetiresOnSaturation(); | 76 .RetiresOnSaturation(); |
68 EXPECT_CALL(*gl_, BufferSubData( | 77 if (error == GL_NO_ERROR) { |
69 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _)) | 78 EXPECT_CALL(*gl_, BufferSubData( |
70 .Times(1) | 79 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _)) |
71 .RetiresOnSaturation(); | 80 .Times(1) |
72 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) | 81 .RetiresOnSaturation(); |
73 .Times(1) | 82 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) |
74 .RetiresOnSaturation(); | 83 .Times(1) |
75 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) | 84 .RetiresOnSaturation(); |
76 .Times(1) | 85 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) |
77 .RetiresOnSaturation(); | 86 .Times(1) |
78 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) | 87 .RetiresOnSaturation(); |
79 .Times(1) | 88 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) |
80 .RetiresOnSaturation(); | 89 .Times(1) |
81 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id)) | 90 .RetiresOnSaturation(); |
82 .Times(1) | 91 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id)) |
83 .RetiresOnSaturation(); | 92 .Times(1) |
| 93 .RetiresOnSaturation(); |
| 94 } |
| 95 } |
| 96 |
| 97 void AddExpectationsForSimulatedAttrib0( |
| 98 GLsizei num_vertices, GLuint buffer_id) { |
| 99 AddExpectationsForSimulatedAttrib0WithError( |
| 100 num_vertices, buffer_id, GL_NO_ERROR); |
84 } | 101 } |
85 }; | 102 }; |
86 | 103 |
87 class GLES2DecoderRGBBackbufferTest : public GLES2DecoderWithShaderTest { | 104 class GLES2DecoderRGBBackbufferTest : public GLES2DecoderWithShaderTest { |
88 public: | 105 public: |
89 GLES2DecoderRGBBackbufferTest() { } | 106 GLES2DecoderRGBBackbufferTest() { } |
90 | 107 |
91 virtual void SetUp() { | 108 virtual void SetUp() { |
92 InitDecoder( | 109 InitDecoder( |
93 "", // extensions | 110 "", // extensions |
(...skipping 24 matching lines...) Expand all Loading... |
118 | 135 |
119 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) | 136 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) |
120 .Times(1) | 137 .Times(1) |
121 .RetiresOnSaturation(); | 138 .RetiresOnSaturation(); |
122 DrawArrays cmd; | 139 DrawArrays cmd; |
123 cmd.Init(GL_TRIANGLES, 0, kNumVertices); | 140 cmd.Init(GL_TRIANGLES, 0, kNumVertices); |
124 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 141 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
125 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 142 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
126 } | 143 } |
127 | 144 |
| 145 // Tests when the math overflows (0x40000000 * sizeof GLfloat) |
| 146 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OverflowFails) { |
| 147 const GLsizei kLargeCount = 0x40000000; |
| 148 SetupTexture(); |
| 149 EXPECT_CALL(*gl_, DrawArrays(_, _, _)) |
| 150 .Times(0) |
| 151 .RetiresOnSaturation(); |
| 152 DrawArrays cmd; |
| 153 cmd.Init(GL_TRIANGLES, 0, kLargeCount); |
| 154 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 155 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 156 } |
| 157 |
| 158 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts) |
| 159 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0PosToNegFails) { |
| 160 const GLsizei kLargeCount = 0x7FFFFFFF; |
| 161 SetupTexture(); |
| 162 EXPECT_CALL(*gl_, DrawArrays(_, _, _)) |
| 163 .Times(0) |
| 164 .RetiresOnSaturation(); |
| 165 DrawArrays cmd; |
| 166 cmd.Init(GL_TRIANGLES, 0, kLargeCount); |
| 167 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 168 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 169 } |
| 170 |
| 171 // Tests when the driver returns an error |
| 172 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OOMFails) { |
| 173 const GLsizei kFakeLargeCount = 0x1234; |
| 174 SetupTexture(); |
| 175 AddExpectationsForSimulatedAttrib0WithError( |
| 176 kFakeLargeCount, 0, GL_OUT_OF_MEMORY); |
| 177 EXPECT_CALL(*gl_, DrawArrays(_, _, _)) |
| 178 .Times(0) |
| 179 .RetiresOnSaturation(); |
| 180 DrawArrays cmd; |
| 181 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount); |
| 182 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 183 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 184 } |
| 185 |
128 TEST_F(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) { | 186 TEST_F(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) { |
129 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); | 187 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
130 // This is an NPOT texture. As the default filtering requires mips | 188 // This is an NPOT texture. As the default filtering requires mips |
131 // this should trigger replacing with black textures before rendering. | 189 // 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, | 190 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
133 0, 0); | 191 0, 0); |
134 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); | 192 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); |
135 { | 193 { |
136 InSequence sequence; | 194 InSequence sequence; |
137 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | 195 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
(...skipping 4428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4566 // TODO(gman): TexImage2DImmediate | 4624 // TODO(gman): TexImage2DImmediate |
4567 | 4625 |
4568 // TODO(gman): TexSubImage2DImmediate | 4626 // TODO(gman): TexSubImage2DImmediate |
4569 | 4627 |
4570 // TODO(gman): UseProgram | 4628 // TODO(gman): UseProgram |
4571 | 4629 |
4572 // TODO(gman): SwapBuffers | 4630 // TODO(gman): SwapBuffers |
4573 | 4631 |
4574 } // namespace gles2 | 4632 } // namespace gles2 |
4575 } // namespace gpu | 4633 } // namespace gpu |
OLD | NEW |