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

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

Issue 169403005: command_buffer: Implement path rendering functions for CHROMIUM_path_rendering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nv-pr-02-texgen
Patch Set: rebase and cleanup ids Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "gpu/command_buffer/common/gles2_cmd_format.h" 7 #include "gpu/command_buffer/common/gles2_cmd_format.h"
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" 9 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gl/gl_mock.h" 11 #include "ui/gl/gl_mock.h"
12 12
13 using ::gfx::MockGLInterface; 13 using ::gfx::MockGLInterface;
14 using ::testing::_; 14 using ::testing::_;
15 using ::testing::Return;
15 16
16 namespace gpu { 17 namespace gpu {
17 namespace gles2 { 18 namespace gles2 {
18 19
20 // Class to use to test that functions which need feature flags or
21 // extensions always return INVALID_OPERATION if the feature flags is not
22 // enabled or extension is not present.
23 class GLES2DecoderTestDisabledExtensions : public GLES2DecoderTest {
24 public:
25 GLES2DecoderTestDisabledExtensions() {}
26 };
27 INSTANTIATE_TEST_CASE_P(Service,
28 GLES2DecoderTestDisabledExtensions,
29 ::testing::Bool());
30
31 TEST_P(GLES2DecoderTestDisabledExtensions, CHROMIUMPathRenderingDisabled) {
32 const GLuint kClientPathId = 0;
33 {
34 cmds::MatrixLoadfCHROMIUMImmediate& cmd =
35 *GetImmediateAs<cmds::MatrixLoadfCHROMIUMImmediate>();
36 GLfloat temp[16] = {
37 0,
38 };
39 cmd.Init(GL_PATH_MODELVIEW_CHROMIUM, temp);
40 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
41 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
42 }
43 {
44 cmds::MatrixLoadIdentityCHROMIUM cmd;
45 cmd.Init(GL_PATH_PROJECTION_CHROMIUM);
46 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
47 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
48 }
49 {
50 cmds::GenPathsCHROMIUM cmd;
51 cmd.Init(0, 0);
52 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
53 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
54 }
55 {
56 cmds::DeletePathsCHROMIUM cmd;
57 cmd.Init(0, 0);
58 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
59 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
60 }
61 {
62 cmds::IsPathCHROMIUM cmd;
63 cmd.Init(kClientPathId, shared_memory_id_, shared_memory_offset_);
64 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
65 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
66 }
67 {
68 cmds::PathCommandsCHROMIUM cmd;
69 cmd.Init(kClientPathId, 0, 0, 0, 0, 0, 0);
70 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
71 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
72 }
73 {
74 cmds::PathParameterfCHROMIUM cmd;
75 cmd.Init(kClientPathId, GL_PATH_STROKE_WIDTH_CHROMIUM, 1.0f);
76 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
77 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
78 }
79 {
80 cmds::PathParameteriCHROMIUM cmd;
81 cmd.Init(kClientPathId, GL_PATH_STROKE_WIDTH_CHROMIUM, 1);
82 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
83 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
84 }
85 {
86 cmds::PathStencilFuncCHROMIUM cmd;
87 cmd.Init(GL_NEVER, 2, 3);
88 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
89 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
90 }
91 {
92 cmds::StencilFillPathCHROMIUM cmd;
93 cmd.Init(kClientPathId, GL_COUNT_UP_CHROMIUM, 1);
94 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
95 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
96 }
97 {
98 cmds::StencilStrokePathCHROMIUM cmd;
99 cmd.Init(kClientPathId, 1, 2);
100 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
101 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
102 }
103 {
104 cmds::CoverFillPathCHROMIUM cmd;
105 cmd.Init(kClientPathId);
106 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
107 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
108 }
109 {
110 cmds::CoverStrokePathCHROMIUM cmd;
111 cmd.Init(kClientPathId);
112 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
113 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
114 }
115 {
116 cmds::StencilThenCoverFillPathCHROMIUM cmd;
117 cmd.Init(kClientPathId, GL_COUNT_UP_CHROMIUM, 1);
118 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
119 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
120 }
121 {
122 cmds::StencilThenCoverStrokePathCHROMIUM cmd;
123 cmd.Init(kClientPathId, 1, 2);
124 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
125 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
126 }
127 }
128
19 class GLES2DecoderTestWithCHROMIUMPathRendering : public GLES2DecoderTest { 129 class GLES2DecoderTestWithCHROMIUMPathRendering : public GLES2DecoderTest {
20 public: 130 public:
21 GLES2DecoderTestWithCHROMIUMPathRendering() {} 131 GLES2DecoderTestWithCHROMIUMPathRendering() : client_path_id_(125) {}
132
22 virtual void SetUp() OVERRIDE { 133 virtual void SetUp() OVERRIDE {
23 InitState init; 134 InitState init;
24 init.gl_version = "opengl es 3.1"; 135 init.gl_version = "opengl es 3.1";
25 init.has_alpha = true; 136 init.has_alpha = true;
26 init.has_depth = true; 137 init.has_depth = true;
27 init.request_alpha = true; 138 init.request_alpha = true;
28 init.request_depth = true; 139 init.request_depth = true;
29 init.bind_generates_resource = true; 140 init.bind_generates_resource = true;
30 init.extensions = "GL_NV_path_rendering"; 141 init.extensions = "GL_NV_path_rendering";
31 InitDecoder(init); 142 InitDecoder(init);
143
144 EXPECT_CALL(*gl_, GenPathsNV(1))
145 .WillOnce(Return(kServicePathId))
146 .RetiresOnSaturation();
147 cmds::GenPathsCHROMIUM cmd;
148 cmd.Init(client_path_id_, 1);
149 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
32 } 150 }
151
152 protected:
153 GLuint client_path_id_;
154 static const GLuint kServicePathId = 311;
33 }; 155 };
34 156
35 INSTANTIATE_TEST_CASE_P(Service, 157 INSTANTIATE_TEST_CASE_P(Service,
36 GLES2DecoderTestWithCHROMIUMPathRendering, 158 GLES2DecoderTestWithCHROMIUMPathRendering,
37 ::testing::Bool()); 159 ::testing::Bool());
160
161 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, GenDeletePaths) {
162 static GLuint kFirstClientID = client_path_id_ + 88;
163 static GLsizei kPathCount = 58;
164 static GLuint kFirstCreatedServiceID = 8000;
165
166 // GenPaths range 0 causes no calls.
167 cmds::GenPathsCHROMIUM gen_cmd;
168 gen_cmd.Init(kFirstClientID, 0);
169 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
170 EXPECT_EQ(GL_NO_ERROR, GetGLError());
171
172 // DeletePaths range 0 causes no calls.
173 cmds::DeletePathsCHROMIUM delete_cmd;
174 delete_cmd.Init(kFirstClientID, 0);
175 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
176 EXPECT_EQ(GL_NO_ERROR, GetGLError());
177
178 // DeletePaths client 0 causes no calls and no errors.
179 delete_cmd.Init(0, 1);
180 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
181 EXPECT_EQ(GL_NO_ERROR, GetGLError());
182
183 // DeletePaths with a big range should not cause any deletes.
184 delete_cmd.Init(client_path_id_ + 1,
185 std::numeric_limits<GLsizei>::max() - client_path_id_ - 1);
186 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
187 EXPECT_EQ(GL_NO_ERROR, GetGLError());
188
189 delete_cmd.Init(std::numeric_limits<GLsizei>::max() + 1,
190 std::numeric_limits<GLsizei>::max());
191 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
192 EXPECT_EQ(GL_NO_ERROR, GetGLError());
193
194 // Normal Gen and Delete should cause the normal calls.
195 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
196 .WillOnce(Return(kFirstCreatedServiceID))
197 .RetiresOnSaturation();
198
199 gen_cmd.Init(kFirstClientID, kPathCount);
200 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
201 EXPECT_EQ(GL_NO_ERROR, GetGLError());
202
203 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID, kPathCount))
204 .RetiresOnSaturation();
205
206 delete_cmd.Init(kFirstClientID, kPathCount);
207 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
208 EXPECT_EQ(GL_NO_ERROR, GetGLError());
209 }
210
211 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, GenDeleteRanges) {
212 static GLuint kFirstClientID = client_path_id_ + 77;
213 static GLsizei kPathCount = 5800;
214 static GLuint kFirstCreatedServiceID = 8000;
215
216 // Create a range of path names, delete one in middle and then
217 // the rest. Expect 3 DeletePath calls.
218 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
219 .WillOnce(Return(kFirstCreatedServiceID))
220 .RetiresOnSaturation();
221 cmds::GenPathsCHROMIUM gen_cmd;
222 gen_cmd.Init(kFirstClientID, kPathCount);
223 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
224 EXPECT_EQ(GL_NO_ERROR, GetGLError());
225
226 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID + (kPathCount / 2), 1))
227 .RetiresOnSaturation();
228
229 cmds::DeletePathsCHROMIUM delete_cmd;
230 delete_cmd.Init(kFirstClientID + (kPathCount / 2), 1);
231 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
232 EXPECT_EQ(GL_NO_ERROR, GetGLError());
233
234 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID, (kPathCount / 2)))
235 .RetiresOnSaturation();
236 EXPECT_CALL(*gl_,
237 DeletePathsNV(kFirstCreatedServiceID + (kPathCount / 2) + 1,
238 (kPathCount / 2) - 1)).RetiresOnSaturation();
239
240 delete_cmd.Init(kFirstClientID, kPathCount);
241 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
242 EXPECT_EQ(GL_NO_ERROR, GetGLError());
243 }
244
245 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, GenDeleteManyPaths) {
246 static GLuint kFirstClientID = client_path_id_ + 1;
247 static GLsizei kPathCount = std::numeric_limits<GLsizei>::max();
248 static GLuint kFirstCreatedServiceID = 8000;
249
250 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
251 .WillOnce(Return(kFirstCreatedServiceID))
252 .RetiresOnSaturation();
253
254 // GenPaths with big range.
255 cmds::GenPathsCHROMIUM gen_cmd;
256 gen_cmd.Init(kFirstClientID, kPathCount);
257 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
258 EXPECT_EQ(GL_NO_ERROR, GetGLError());
259
260 // Path range wraps, so we get connection error.
261 gen_cmd.Init(kFirstClientID + kPathCount, kPathCount);
262 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(gen_cmd));
263 EXPECT_EQ(GL_NO_ERROR, GetGLError());
264
265 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID, kPathCount))
266 .RetiresOnSaturation();
267
268 cmds::DeletePathsCHROMIUM delete_cmd;
269 delete_cmd.Init(kFirstClientID, kPathCount);
270 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
271 EXPECT_EQ(GL_NO_ERROR, GetGLError());
272
273 // Delete every possible path.
274 // We run into the one created for client_path_id_.
275 EXPECT_CALL(*gl_, DeletePathsNV(kServicePathId, 1)).RetiresOnSaturation();
276
277 delete_cmd.Init(1u, kPathCount);
278 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
279 EXPECT_EQ(GL_NO_ERROR, GetGLError());
280
281 delete_cmd.Init(static_cast<GLuint>(kPathCount) + 1u, kPathCount);
282 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
283 EXPECT_EQ(GL_NO_ERROR, GetGLError());
284
285 // Allocate every possible path, delete few, allocate them back and
286 // expect minimum amount of calls.
287 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
288 .WillOnce(Return(static_cast<GLuint>(1u)))
289 .WillOnce(Return(static_cast<GLuint>(kPathCount) + 1u))
290 .RetiresOnSaturation();
291
292 gen_cmd.Init(1u, kPathCount);
293 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
294 EXPECT_EQ(GL_NO_ERROR, GetGLError());
295
296 gen_cmd.Init(static_cast<GLuint>(kPathCount) + 1u, kPathCount);
297 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
298 EXPECT_EQ(GL_NO_ERROR, GetGLError());
299
300 gen_cmd.Init(static_cast<GLuint>(kPathCount) * 2u + 2u, kPathCount);
301 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(gen_cmd));
302 EXPECT_EQ(GL_NO_ERROR, GetGLError());
303
304 EXPECT_CALL(*gl_, DeletePathsNV(kFirstClientID, 4)).RetiresOnSaturation();
305
306 delete_cmd.Init(kFirstClientID, 4);
307 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
308 EXPECT_EQ(GL_NO_ERROR, GetGLError());
309
310 EXPECT_CALL(*gl_, DeletePathsNV(kFirstClientID * 3, 1)).RetiresOnSaturation();
311
312 delete_cmd.Init(kFirstClientID * 3, 1);
313 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
314 EXPECT_EQ(GL_NO_ERROR, GetGLError());
315
316 EXPECT_CALL(*gl_, GenPathsNV(1))
317 .WillOnce(Return(kFirstClientID))
318 .WillOnce(Return(kFirstClientID + 1))
319 .WillOnce(Return(kFirstClientID + 2))
320 .WillOnce(Return(kFirstClientID + 3))
321 .RetiresOnSaturation();
322
323 for (int i = 0; i < 4; ++i) {
324 gen_cmd.Init(kFirstClientID + i, 1);
325 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
326 EXPECT_EQ(GL_NO_ERROR, GetGLError());
327 }
328
329 EXPECT_CALL(*gl_, GenPathsNV(1))
330 .WillOnce(Return(kFirstClientID * 3))
331 .RetiresOnSaturation();
332 gen_cmd.Init(kFirstClientID * 3, 1);
333 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
334 EXPECT_EQ(GL_NO_ERROR, GetGLError());
335
336 EXPECT_CALL(*gl_, DeletePathsNV(1u, kPathCount)).RetiresOnSaturation();
337 EXPECT_CALL(*gl_,
338 DeletePathsNV(static_cast<GLuint>(kPathCount) + 1u, kPathCount))
339 .RetiresOnSaturation();
340
341 delete_cmd.Init(1u, kPathCount);
342 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
343 EXPECT_EQ(GL_NO_ERROR, GetGLError());
344
345 delete_cmd.Init(static_cast<GLuint>(kPathCount) + 1u, kPathCount);
346 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
347 EXPECT_EQ(GL_NO_ERROR, GetGLError());
348
349 // Cleanup: return the client_path_id_ as a path.
350 EXPECT_CALL(*gl_, GenPathsNV(1))
351 .WillOnce(Return(static_cast<GLuint>(kServicePathId)))
352 .RetiresOnSaturation();
353
354 gen_cmd.Init(client_path_id_, 1);
355 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
356 EXPECT_EQ(GL_NO_ERROR, GetGLError());
357 }
358
359 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
360 GenPathsCHROMIUMInvalidCalls) {
361 static GLuint kFirstClientID = client_path_id_ + 88;
362 static GLsizei kPathCount = 5800;
363 static GLuint kFirstCreatedServiceID = 8000;
364
365 // Range < 0 is causes gl error.
366 cmds::GenPathsCHROMIUM gen_cmd;
367 gen_cmd.Init(kFirstClientID, -1);
368 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
369 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
370
371 // Path 0 is invalid client id, connection error.
372 gen_cmd.Init(0, kPathCount);
373 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(gen_cmd));
374 EXPECT_EQ(GL_NO_ERROR, GetGLError());
375
376 // Too big range causes client id to wrap, connection error.
377 gen_cmd.Init(std::numeric_limits<GLsizei>::max() + 3,
378 std::numeric_limits<GLsizei>::max());
379 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(gen_cmd));
380 EXPECT_EQ(GL_NO_ERROR, GetGLError());
381
382 // Creating duplicate client_ids cause connection error.
383 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
384 .WillOnce(Return(kFirstCreatedServiceID))
385 .RetiresOnSaturation();
386
387 gen_cmd.Init(kFirstClientID, kPathCount);
388 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
389 EXPECT_EQ(GL_NO_ERROR, GetGLError());
390
391 // Create duplicate by executing the same cmd.
392 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(gen_cmd));
393 EXPECT_EQ(GL_NO_ERROR, GetGLError());
394
395 // Create duplicate by creating a range that contains
396 // an already existing client path id.
397 gen_cmd.Init(kFirstClientID - 1, 2);
398 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(gen_cmd));
399 EXPECT_EQ(GL_NO_ERROR, GetGLError());
400
401 // Cleanup.
402 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID, kPathCount))
403 .RetiresOnSaturation();
404 cmds::DeletePathsCHROMIUM delete_cmd;
405 delete_cmd.Init(kFirstClientID, kPathCount);
406 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
407 EXPECT_EQ(GL_NO_ERROR, GetGLError());
408 }
409
410 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
411 DeletePathsCHROMIUMInvalidCalls) {
412 static GLuint kFirstClientID = client_path_id_ + 88;
413
414 // Range < 0 is causes gl error.
415 cmds::DeletePathsCHROMIUM delete_cmd;
416 delete_cmd.Init(kFirstClientID, -1);
417 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
418 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
419
420 // Too big range causes client id to wrap, connection error.
421 delete_cmd.Init(std::numeric_limits<GLsizei>::max() + 3,
422 std::numeric_limits<GLsizei>::max());
423 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(delete_cmd));
424 EXPECT_EQ(GL_NO_ERROR, GetGLError());
425 }
426
427 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
428 PathCommandsCHROMIUMInvalidCalls) {
429 static GLsizei kCorrectCoordCount = 14;
430 static GLsizei kCorrectCommandCount = 5;
431
432 GLfloat* coords = GetSharedMemoryAs<GLfloat*>();
433 unsigned commands_offset = sizeof(GLfloat) * kCorrectCoordCount;
434 GLubyte* commands = GetSharedMemoryAsWithOffset<GLubyte*>(commands_offset);
435 for (int i = 0; i < kCorrectCoordCount; ++i) {
436 coords[i] = 5.0f * i;
437 }
438 commands[0] = GL_MOVE_TO_CHROMIUM;
439 commands[1] = GL_CLOSE_PATH_CHROMIUM;
440 commands[2] = GL_LINE_TO_CHROMIUM;
441 commands[3] = GL_QUADRATIC_CURVE_TO_CHROMIUM;
442 commands[4] = GL_CUBIC_CURVE_TO_CHROMIUM;
443
444 EXPECT_CALL(*gl_,
445 PathCommandsNV(kServicePathId,
446 kCorrectCommandCount,
447 commands,
448 kCorrectCoordCount,
449 GL_FLOAT,
450 coords)).RetiresOnSaturation();
451
452 cmds::PathCommandsCHROMIUM cmd;
453
454 // Reference call -- this succeeds.
455 cmd.Init(client_path_id_,
456 kCorrectCommandCount,
457 shared_memory_id_,
458 shared_memory_offset_ + commands_offset,
459 kCorrectCoordCount,
460 shared_memory_id_,
461 shared_memory_offset_);
462 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
463 EXPECT_EQ(GL_NO_ERROR, GetGLError());
464
465 EXPECT_CALL(*gl_, PathCommandsNV(_, _, _, _, _, _)).Times(0);
466
467 // Invalid client id fails.
468 cmd.Init(client_path_id_ - 1,
469 kCorrectCommandCount,
470 shared_memory_id_,
471 shared_memory_offset_,
472 kCorrectCoordCount,
473 shared_memory_id_,
474 shared_memory_offset_);
475 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
476 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
477
478 // The numCommands < 0.
479 cmd.Init(client_path_id_,
480 -1,
481 shared_memory_id_,
482 shared_memory_offset_,
483 kCorrectCoordCount,
484 shared_memory_id_,
485 shared_memory_offset_);
486 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
487 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
488
489 // The numCoords < 0.
490 cmd.Init(client_path_id_,
491 kCorrectCommandCount,
492 shared_memory_id_,
493 shared_memory_offset_,
494 -1,
495 shared_memory_id_,
496 shared_memory_offset_);
497 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
498 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
499
500 // Big command counts.
501 cmd.Init(client_path_id_,
502 std::numeric_limits<GLsizei>::max(),
503 shared_memory_id_,
504 shared_memory_offset_ + commands_offset,
505 kCorrectCoordCount,
506 shared_memory_id_,
507 shared_memory_offset_);
508 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
509 EXPECT_EQ(GL_NO_ERROR, GetGLError());
510
511 // Invalid SHM cases.
512 cmd.Init(client_path_id_,
513 kCorrectCommandCount,
514 kInvalidSharedMemoryId,
515 shared_memory_offset_ + commands_offset,
516 kCorrectCoordCount,
517 shared_memory_id_,
518 shared_memory_offset_);
519 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
520 EXPECT_EQ(GL_NO_ERROR, GetGLError());
521
522 cmd.Init(client_path_id_,
523 kCorrectCommandCount,
524 shared_memory_id_,
525 kInvalidSharedMemoryOffset,
526 kCorrectCoordCount,
527 shared_memory_id_,
528 shared_memory_offset_);
529 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
530 EXPECT_EQ(GL_NO_ERROR, GetGLError());
531
532 cmd.Init(client_path_id_,
533 kCorrectCommandCount,
534 shared_memory_id_,
535 shared_memory_offset_ + commands_offset,
536 kCorrectCoordCount,
537 kInvalidSharedMemoryId,
538 shared_memory_offset_);
539 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
540 EXPECT_EQ(GL_NO_ERROR, GetGLError());
541
542 cmd.Init(client_path_id_,
543 kCorrectCommandCount,
544 shared_memory_id_,
545 shared_memory_offset_ + commands_offset,
546 kCorrectCoordCount,
547 shared_memory_id_,
548 kInvalidSharedMemoryOffset);
549 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
550 EXPECT_EQ(GL_NO_ERROR, GetGLError());
551
552 // NULL shm command id. Currently causes gl error, though client should not
553 // let this through.
554 cmd.Init(client_path_id_,
555 kCorrectCommandCount,
556 0,
557 0,
558 kCorrectCoordCount,
559 shared_memory_id_,
560 shared_memory_offset_);
561 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
562 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
563
564 // The coordCount not matching what is in commands.
565 // Expects kCorrectCoordCount+2 coords.
566 commands[1] = GL_MOVE_TO_CHROMIUM;
567 cmd.Init(client_path_id_,
568 kCorrectCommandCount,
569 shared_memory_id_,
570 shared_memory_offset_ + commands_offset,
571 kCorrectCoordCount,
572 shared_memory_id_,
573 shared_memory_offset_);
574 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
575 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
576
577 // The coordCount not matching what is in commands.
578 // Expects kCorrectCoordCount-2 coords.
579 commands[0] = GL_CLOSE_PATH_CHROMIUM;
580 commands[1] = GL_CLOSE_PATH_CHROMIUM;
581 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
582 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
583
584 // NULL shm coord ids. Currently causes gl error, though client should not let
585 // this through.
586 cmd.Init(client_path_id_,
587 kCorrectCommandCount,
588 shared_memory_id_,
589 shared_memory_offset_ + commands_offset,
590 kCorrectCoordCount,
591 0,
592 0);
593 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
594 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
595 }
596
597 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
598 PathCommandsCHROMIUMEmptyCommands) {
599 EXPECT_CALL(*gl_, PathCommandsNV(kServicePathId, 0, NULL, 0, GL_FLOAT, NULL))
600 .RetiresOnSaturation();
601 cmds::PathCommandsCHROMIUM cmd;
602 cmd.Init(client_path_id_, 0, 0, 0, 0, 0, 0);
603 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
604 EXPECT_EQ(GL_NO_ERROR, GetGLError());
605 }
606
607 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
608 PathCommandsCHROMIUMInvalidCommands) {
609 EXPECT_CALL(*gl_, PathCommandsNV(_, _, _, _, _, _)).Times(0);
610
611 cmds::PathCommandsCHROMIUM cmd;
612
613 {
614 const GLsizei kCoordCount = 2;
615 const GLsizei kCommandCount = 2;
616 GLfloat* coords = GetSharedMemoryAs<GLfloat*>();
617 unsigned commands_offset = sizeof(GLfloat) * kCoordCount;
618 GLubyte* commands = GetSharedMemoryAsWithOffset<GLubyte*>(commands_offset);
619
620 coords[0] = 5.0f;
621 coords[1] = 5.0f;
622 commands[0] = 0x3; // Token MOVE_TO_RELATIVE in NV_path_rendering.
623 commands[1] = GL_CLOSE_PATH_CHROMIUM;
624
625 cmd.Init(client_path_id_ - 1,
626 kCommandCount,
627 shared_memory_id_,
628 shared_memory_offset_,
629 kCoordCount,
630 shared_memory_id_,
631 shared_memory_offset_);
632 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
633 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
634 }
635 {
636 const GLsizei kCoordCount = 8;
637 const GLsizei kCommandCount = 4;
638 GLfloat* coords = GetSharedMemoryAs<GLfloat*>();
639 unsigned commands_offset = sizeof(GLfloat) * kCoordCount;
640 GLubyte* commands = GetSharedMemoryAsWithOffset<GLubyte*>(commands_offset);
641
642 for (int i = 0; i < kCoordCount; ++i) {
643 coords[i] = 5.0f * i;
644 }
645 commands[0] = GL_MOVE_TO_CHROMIUM;
646 commands[1] = GL_MOVE_TO_CHROMIUM;
647 commands[2] = 'M'; // Synonym to MOVE_TO in NV_path_rendering.
648 commands[3] = GL_MOVE_TO_CHROMIUM;
649
650 cmd.Init(client_path_id_ - 1,
651 kCommandCount,
652 shared_memory_id_,
653 shared_memory_offset_,
654 kCoordCount,
655 shared_memory_id_,
656 shared_memory_offset_);
657 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
658 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
659 }
660 }
661
662 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, PathParameterXCHROMIUM) {
663 static GLuint kFirstClientID = client_path_id_ + 88;
664 static GLsizei kPathCount = 2;
665 static GLuint kFirstCreatedServiceID = 8000;
666
667 // Create a paths so that we do not modify client_path_id_
668 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
669 .WillOnce(Return(kFirstCreatedServiceID))
670 .RetiresOnSaturation();
671 cmds::GenPathsCHROMIUM gen_cmd;
672 gen_cmd.Init(kFirstClientID, kPathCount);
673 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
674 EXPECT_EQ(GL_NO_ERROR, GetGLError());
675
676 cmds::PathParameterfCHROMIUM fcmd;
677 cmds::PathParameteriCHROMIUM icmd;
678 const struct {
679 GLenum pname;
680 GLfloat value;
681 } kTestcases[] = {
682 {GL_PATH_STROKE_WIDTH_CHROMIUM, 1.0f},
683 {GL_PATH_MITER_LIMIT_CHROMIUM, 500.0f},
684 {GL_PATH_INITIAL_END_CAP_CHROMIUM, GL_FLAT_CHROMIUM},
685 {GL_PATH_TERMINAL_END_CAP_CHROMIUM, GL_SQUARE_CHROMIUM},
686 {GL_PATH_JOIN_STYLE_CHROMIUM, GL_MITER_REVERT_CHROMIUM},
687 };
688
689 for (auto& testcase : kTestcases) {
690 EXPECT_CALL(*gl_,
691 PathParameterfNV(
692 kFirstCreatedServiceID, testcase.pname, testcase.value))
693 .Times(1)
694 .RetiresOnSaturation();
695 fcmd.Init(kFirstClientID, testcase.pname, testcase.value);
696 EXPECT_EQ(error::kNoError, ExecuteCmd(fcmd));
697 EXPECT_EQ(GL_NO_ERROR, GetGLError());
698
699 EXPECT_CALL(*gl_,
700 PathParameteriNV(kFirstCreatedServiceID + 1,
701 testcase.pname,
702 static_cast<GLint>(testcase.value)))
703 .Times(1)
704 .RetiresOnSaturation();
705 icmd.Init(
706 kFirstClientID + 1, testcase.pname, static_cast<GLint>(testcase.value));
707 EXPECT_EQ(error::kNoError, ExecuteCmd(icmd));
708 EXPECT_EQ(GL_NO_ERROR, GetGLError());
709 }
710
711 // Cleanup.
712 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID, kPathCount))
713 .RetiresOnSaturation();
714
715 cmds::DeletePathsCHROMIUM delete_cmd;
716 delete_cmd.Init(kFirstClientID, kPathCount);
717 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
718 EXPECT_EQ(GL_NO_ERROR, GetGLError());
719 }
720
721 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
722 PathParameterXCHROMIUMInvalidArgs) {
723 static GLuint kFirstClientID = client_path_id_ + 88;
724 static GLsizei kPathCount = 2;
725 static GLuint kFirstCreatedServiceID = 8000;
726
727 // Create a paths so that we do not modify client_path_id_
728 EXPECT_CALL(*gl_, GenPathsNV(kPathCount))
729 .WillOnce(Return(kFirstCreatedServiceID))
730 .RetiresOnSaturation();
731 cmds::GenPathsCHROMIUM gen_cmd;
732 gen_cmd.Init(kFirstClientID, kPathCount);
733 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
734 EXPECT_EQ(GL_NO_ERROR, GetGLError());
735
736 cmds::PathParameterfCHROMIUM fcmd;
737 cmds::PathParameteriCHROMIUM icmd;
738 const struct {
739 GLenum pname;
740 GLfloat value;
741 bool try_int_version;
742 GLint error;
743 } kTestcases[] = {
744 {GL_PATH_STROKE_WIDTH_CHROMIUM, -1.0f, true, GL_INVALID_VALUE},
745 {GL_PATH_MITER_LIMIT_CHROMIUM,
746 std::numeric_limits<float>::infinity(),
747 false,
748 GL_INVALID_VALUE},
749 {GL_PATH_MITER_LIMIT_CHROMIUM,
750 std::numeric_limits<float>::quiet_NaN(),
751 false,
752 GL_INVALID_VALUE},
753 {GL_PATH_INITIAL_END_CAP_CHROMIUM, 0x4, true, GL_INVALID_VALUE},
754 {GL_PATH_TERMINAL_END_CAP_CHROMIUM,
755 GL_MITER_REVERT_CHROMIUM,
756 true,
757 GL_INVALID_VALUE},
758 {GL_PATH_JOIN_STYLE_CHROMIUM, GL_FLAT_CHROMIUM, true, GL_INVALID_VALUE},
759 {GL_PATH_MODELVIEW_CHROMIUM, GL_FLAT_CHROMIUM, true, GL_INVALID_ENUM},
760 };
761
762 EXPECT_CALL(*gl_, PathParameterfNV(_, _, _)).Times(0);
763 EXPECT_CALL(*gl_, PathParameteriNV(_, _, _)).Times(0);
764
765 for (auto& testcase : kTestcases) {
766 fcmd.Init(kFirstClientID, testcase.pname, testcase.value);
767 EXPECT_EQ(error::kNoError, ExecuteCmd(fcmd));
768 EXPECT_EQ(testcase.error, GetGLError());
769 if (!testcase.try_int_version) {
770 continue;
771 }
772 icmd.Init(
773 kFirstClientID + 1, testcase.pname, static_cast<GLint>(testcase.value));
774 EXPECT_EQ(error::kNoError, ExecuteCmd(icmd));
775 EXPECT_EQ(testcase.error, GetGLError());
776 }
777
778 // Cleanup.
779 EXPECT_CALL(*gl_, DeletePathsNV(kFirstCreatedServiceID, kPathCount))
780 .RetiresOnSaturation();
781
782 cmds::DeletePathsCHROMIUM delete_cmd;
783 delete_cmd.Init(kFirstClientID, kPathCount);
784 EXPECT_EQ(error::kNoError, ExecuteCmd(delete_cmd));
785 EXPECT_EQ(GL_NO_ERROR, GetGLError());
786 }
787
788 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, StencilFillPathCHROMIUM) {
789 SetupExpectationsForApplyingDefaultDirtyState();
790
791 cmds::StencilFillPathCHROMIUM cmd;
792 cmds::StencilThenCoverFillPathCHROMIUM tcmd;
793
794 static const GLenum kFillModes[] = {
795 GL_INVERT, GL_COUNT_UP_CHROMIUM, GL_COUNT_DOWN_CHROMIUM};
796 static const GLuint kMask = 0x7F;
797
798 for (auto& fill_mode : kFillModes) {
799 EXPECT_CALL(*gl_, StencilFillPathNV(kServicePathId, fill_mode, kMask))
800 .RetiresOnSaturation();
801 cmd.Init(client_path_id_, fill_mode, kMask);
802 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
803 EXPECT_EQ(GL_NO_ERROR, GetGLError());
804
805 EXPECT_CALL(*gl_,
806 StencilThenCoverFillPathNV(
807 kServicePathId, fill_mode, kMask, GL_BOUNDING_BOX_NV))
808 .RetiresOnSaturation();
809 tcmd.Init(client_path_id_, fill_mode, kMask);
810 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
811 EXPECT_EQ(GL_NO_ERROR, GetGLError());
812 }
813
814 // Non-existent path: no error, no call.
815 cmd.Init(client_path_id_ - 1, GL_INVERT, 0x80);
816 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
817 EXPECT_EQ(GL_NO_ERROR, GetGLError());
818
819 tcmd.Init(client_path_id_ - 1, GL_INVERT, 0x80);
820 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
821 EXPECT_EQ(GL_NO_ERROR, GetGLError());
822 }
823
824 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering,
825 StencilFillPathCHROMIUMInvalidArgs) {
826 EXPECT_CALL(*gl_, StencilFillPathNV(_, _, _)).Times(0);
827 EXPECT_CALL(*gl_, StencilThenCoverFillPathNV(_, _, _, _)).Times(0);
828
829 cmds::StencilFillPathCHROMIUM cmd;
830 cmds::StencilThenCoverFillPathCHROMIUM tcmd;
831
832 cmd.Init(client_path_id_, GL_INVERT - 1, 0x80);
833 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
834 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
835
836 tcmd.Init(client_path_id_, GL_INVERT - 1, 0x80);
837 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
838 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
839
840 // The /mask/+1 is not power of two -> invalid value.
841 cmd.Init(client_path_id_, GL_COUNT_UP_CHROMIUM, 0x80);
842 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
843 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
844
845 tcmd.Init(client_path_id_, GL_COUNT_UP_CHROMIUM, 0x80);
846 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
847 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
848
849 cmd.Init(client_path_id_, GL_COUNT_DOWN_CHROMIUM, 5);
850 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
851 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
852
853 tcmd.Init(client_path_id_, GL_COUNT_DOWN_CHROMIUM, 5);
854 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
855 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
856 }
857
858 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, StencilStrokePathCHROMIUM) {
859 SetupExpectationsForApplyingDefaultDirtyState();
860
861 EXPECT_CALL(*gl_, StencilStrokePathNV(kServicePathId, 1, 0x80))
862 .RetiresOnSaturation();
863 EXPECT_CALL(
864 *gl_,
865 StencilThenCoverStrokePathNV(kServicePathId, 1, 0x80, GL_BOUNDING_BOX_NV))
866 .RetiresOnSaturation();
867
868 cmds::StencilStrokePathCHROMIUM cmd;
869 cmds::StencilThenCoverStrokePathCHROMIUM tcmd;
870
871 cmd.Init(client_path_id_, 1, 0x80);
872 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
873 EXPECT_EQ(GL_NO_ERROR, GetGLError());
874
875 tcmd.Init(client_path_id_, 1, 0x80);
876 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
877 EXPECT_EQ(GL_NO_ERROR, GetGLError());
878
879 // Non-existent path: no error, no call.
880 cmd.Init(client_path_id_ - 1, 1, 0x80);
881 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
882 EXPECT_EQ(GL_NO_ERROR, GetGLError());
883
884 tcmd.Init(client_path_id_ - 1, 1, 0x80);
885 EXPECT_EQ(error::kNoError, ExecuteCmd(tcmd));
886 EXPECT_EQ(GL_NO_ERROR, GetGLError());
887 }
888
889 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, CoverFillPathCHROMIUM) {
890 SetupExpectationsForApplyingDefaultDirtyState();
891
892 EXPECT_CALL(*gl_, CoverFillPathNV(kServicePathId, GL_BOUNDING_BOX_NV))
893 .RetiresOnSaturation();
894 cmds::CoverFillPathCHROMIUM cmd;
895 cmd.Init(client_path_id_);
896 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
897 EXPECT_EQ(GL_NO_ERROR, GetGLError());
898
899 // Non-existent path: no error, no call.
900 cmd.Init(client_path_id_ - 1);
901 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
902 EXPECT_EQ(GL_NO_ERROR, GetGLError());
903 }
904
905 TEST_P(GLES2DecoderTestWithCHROMIUMPathRendering, CoverStrokePathCHROMIUM) {
906 SetupExpectationsForApplyingDefaultDirtyState();
907 EXPECT_CALL(*gl_, CoverStrokePathNV(kServicePathId, GL_BOUNDING_BOX_NV))
908 .RetiresOnSaturation();
909 cmds::CoverStrokePathCHROMIUM cmd;
910 cmd.Init(client_path_id_);
911 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
912 EXPECT_EQ(GL_NO_ERROR, GetGLError());
913
914 // Non-existent path: no error, no call.
915 cmd.Init(client_path_id_ - 1);
916 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
917 EXPECT_EQ(GL_NO_ERROR, GetGLError());
918 }
919
38 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_extensions_autog en.h" 920 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_extensions_autog en.h"
39 921
40 } // namespace gles2 922 } // namespace gles2
41 } // namespace gpu 923 } // namespace gpu
42 924
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698