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

Side by Side Diff: gpu/command_buffer/tests/gl_chromium_path_rendering_unittest.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 Created 5 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <GLES2/gl2.h> 5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h> 6 #include <GLES2/gl2ext.h>
7 #include <GLES2/gl2extchromium.h> 7 #include <GLES2/gl2extchromium.h>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/strings/stringprintf.h"
10 #include "gpu/command_buffer/tests/gl_manager.h" 11 #include "gpu/command_buffer/tests/gl_manager.h"
11 #include "gpu/command_buffer/tests/gl_test_utils.h" 12 #include "gpu/command_buffer/tests/gl_test_utils.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
16 #define SHADER(Src) #Src
17
15 namespace gpu { 18 namespace gpu {
16 19
17 class CHROMIUMPathRenderingTest : public testing::Test { 20 class CHROMIUMPathRenderingTest : public testing::Test {
18 public: 21 public:
19 static const GLsizei kResolution = 100; 22 static const GLsizei kResolution = 100;
20 23
21 protected: 24 protected:
22 void SetUp() override { 25 void SetUp() override {
23 GLManager::Options options; 26 GLManager::Options options;
24 options.size = gfx::Size(kResolution, kResolution); 27 options.size = gfx::Size(kResolution, kResolution);
25 gl_.Initialize(options); 28 gl_.Initialize(options);
26 } 29 }
27 30
28 void TearDown() override { gl_.Destroy(); } 31 void TearDown() override { gl_.Destroy(); }
29 32
30 void ExpectEqualMatrix(const GLfloat* expected, const GLfloat* actual) { 33 void ExpectEqualMatrix(const GLfloat* expected, const GLfloat* actual) {
31 for (size_t i = 0; i < 16; ++i) { 34 for (size_t i = 0; i < 16; ++i) {
32 EXPECT_EQ(expected[i], actual[i]); 35 EXPECT_EQ(expected[i], actual[i]);
33 } 36 }
34 } 37 }
35 void ExpectEqualMatrix(const GLfloat* expected, const GLint* actual) { 38 void ExpectEqualMatrix(const GLfloat* expected, const GLint* actual) {
36 for (size_t i = 0; i < 16; ++i) { 39 for (size_t i = 0; i < 16; ++i) {
37 EXPECT_EQ(static_cast<GLint>(round(expected[i])), actual[i]); 40 EXPECT_EQ(static_cast<GLint>(round(expected[i])), actual[i]);
38 } 41 }
39 } 42 }
43
44 void SetupStateForTestPattern() {
45 glViewport(0, 0, kResolution, kResolution);
46 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
47 glStencilMask(0xffffffff);
48 glClearStencil(0);
49 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
50
51 static const char* kVertexShaderSource =
52 SHADER(void main() { gl_Position = vec4(1); });
53 static const char* kFragmentShaderSource =
54 SHADER(precision mediump float; uniform vec4 color;
55 void main() { gl_FragColor = color; });
56
57 GLuint program =
58 GLTestHelper::LoadProgram(kVertexShaderSource, kFragmentShaderSource);
59 glUseProgram(program);
60 color_loc_ = glGetUniformLocation(program, "color");
61 glDeleteProgram(program);
62
63 // Set up orthogonal projection with near/far plane distance of 2.
64 static GLfloat matrix[16] = {2.0f / (kResolution - 1),
65 0.0f,
66 0.0f,
67 0.0f,
68 0.0f,
69 2.0f / (kResolution - 1),
70 0.0f,
71 0.0f,
72 0.0f,
73 0.0f,
74 -1.0f,
75 0.0f,
76 -1.0f,
77 -1.0f,
78 0.0f,
79 1.0f};
80 glMatrixLoadfCHROMIUM(GL_PATH_PROJECTION_CHROMIUM, matrix);
81 glMatrixLoadIdentityCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM);
82
83 glEnable(GL_STENCIL_TEST);
84
85 GLTestHelper::CheckGLError("no errors at state setup", __LINE__);
86 }
87
88 void SetupPathStateForTestPattern(GLuint path) {
89 static const GLubyte kCommands[] = {GL_MOVE_TO_CHROMIUM,
90 GL_LINE_TO_CHROMIUM,
91 GL_QUADRATIC_CURVE_TO_CHROMIUM,
92 GL_CUBIC_CURVE_TO_CHROMIUM,
93 GL_CLOSE_PATH_CHROMIUM};
94
95 static const GLfloat kCoords[] = {50.0f,
96 50.0f,
97 75.0f,
98 75.0f,
99 100.0f,
100 62.5f,
101 50.0f,
102 25.5f,
103 0.0f,
104 62.5f,
105 50.0f,
106 50.0f,
107 25.0f,
108 75.0f};
109
110 glPathCommandsCHROMIUM(path, arraysize(kCommands), kCommands,
111 arraysize(kCoords), GL_FLOAT, kCoords);
112
113 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f);
114 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM, 1.0f);
115 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_BOUND_CHROMIUM, .02f);
116 glPathParameteriCHROMIUM(path, GL_PATH_JOIN_STYLE_CHROMIUM,
117 GL_ROUND_CHROMIUM);
118 glPathParameteriCHROMIUM(path, GL_PATH_END_CAPS_CHROMIUM,
119 GL_SQUARE_CHROMIUM);
120 }
121
122 void VerifyTestPatternFill(float x, float y) {
123 static const float kFillCoords[] = {
124 55.0f, 55.0f, 50.0f, 28.0f, 66.0f, 63.0f};
125 static const uint8 kBlue[] = {0, 0, 255, 255};
126
127 for (size_t i = 0; i < arraysize(kFillCoords); i += 2) {
128 float fx = kFillCoords[i];
129 float fy = kFillCoords[i + 1];
130
131 EXPECT_TRUE(GLTestHelper::CheckPixels(x + fx, y + fy, 1, 1, 0, kBlue));
132 }
133 }
134
135 void VerifyTestPatternBg(float x, float y) {
136 const float kBackgroundCoords[] = {80.0f, 80.0f, 20.0f, 20.0f, 90.0f, 1.0f};
137 const uint8 kExpectedColor[] = {0, 0, 0, 0};
138
139 for (size_t i = 0; i < arraysize(kBackgroundCoords); i += 2) {
140 float bx = kBackgroundCoords[i];
141 float by = kBackgroundCoords[i + 1];
142
143 EXPECT_TRUE(
144 GLTestHelper::CheckPixels(x + bx, y + by, 1, 1, 0, kExpectedColor));
145 }
146 }
147
148 void VerifyTestPatternStroke(float x, float y) {
149 // Inside the stroke we should have green.
150 const uint8 kGreen[] = {0, 255, 0, 255};
151 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 50, y + 53, 1, 1, 0, kGreen));
152 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 26, y + 76, 1, 1, 0, kGreen));
153
154 // Outside the path we should have black.
155 const uint8 black[] = {0, 0, 0, 0};
156 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 10, y + 10, 1, 1, 0, black));
157 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 80, y + 80, 1, 1, 0, black));
158 }
159
160 void TryAllDrawFunctions(GLuint path, GLenum expected_error) {
161 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F);
162 EXPECT_EQ(expected_error, glGetError());
163
164 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F);
165 EXPECT_EQ(expected_error, glGetError());
166
167 glStencilStrokePathCHROMIUM(path, 0x80, 0x80);
168 EXPECT_EQ(expected_error, glGetError());
169
170 glCoverFillPathCHROMIUM(path, GL_BOUNDING_BOX_CHROMIUM);
171 EXPECT_EQ(expected_error, glGetError());
172
173 glCoverStrokePathCHROMIUM(path, GL_BOUNDING_BOX_CHROMIUM);
174 EXPECT_EQ(expected_error, glGetError());
175
176 glStencilThenCoverStrokePathCHROMIUM(path, 0x80, 0x80,
177 GL_BOUNDING_BOX_CHROMIUM);
178 EXPECT_EQ(expected_error, glGetError());
179
180 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
181 GL_BOUNDING_BOX_CHROMIUM);
182 EXPECT_EQ(expected_error, glGetError());
183 }
184
40 GLManager gl_; 185 GLManager gl_;
186 GLint color_loc_;
41 }; 187 };
42 188
43 TEST_F(CHROMIUMPathRenderingTest, TestMatrix) { 189 TEST_F(CHROMIUMPathRenderingTest, TestMatrix) {
44 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { 190 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
45 return; 191 return;
46 } 192 }
47 static const GLfloat kIdentityMatrix[16] = { 193 static const GLfloat kIdentityMatrix[16] = {
48 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 194 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
49 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; 195 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
50 static const GLfloat kSeqMatrix[16] = { 196 static const GLfloat kSeqMatrix[16] = {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 231 }
86 } 232 }
87 233
88 TEST_F(CHROMIUMPathRenderingTest, TestMatrixErrors) { 234 TEST_F(CHROMIUMPathRenderingTest, TestMatrixErrors) {
89 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { 235 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
90 return; 236 return;
91 } 237 }
92 GLfloat mf[16]; 238 GLfloat mf[16];
93 memset(mf, 0, sizeof(mf)); 239 memset(mf, 0, sizeof(mf));
94 240
95 // This should fail. 241 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM, mf);
242 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
243
244 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM);
245 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
246
247 // Test that invalid matrix targets fail.
96 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM - 1, mf); 248 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM - 1, mf);
97 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); 249 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
98 250
99 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM, mf); 251 // Test that invalid matrix targets fail.
100 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
101
102 // This should fail.
103 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM + 1); 252 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM + 1);
104 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); 253 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
105 254 }
106 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM); 255
107 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 256 TEST_F(CHROMIUMPathRenderingTest, TestSimpleCalls) {
257 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
258 return;
259 }
260
261 // This is unspecified in NV_path_rendering.
262 EXPECT_EQ(0u, glGenPathsCHROMIUM(0));
263
264 GLuint path = glGenPathsCHROMIUM(1);
265 EXPECT_TRUE(path != 0);
266 glDeletePathsCHROMIUM(path, 1);
267 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
268
269 GLuint first_path = glGenPathsCHROMIUM(5);
270 EXPECT_TRUE(first_path != 0);
271 glDeletePathsCHROMIUM(first_path, 5);
272 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
273
274 // Test deleting paths that are not actually allocated:
275 // "unused names in /paths/ are silently ignored".
276 first_path = glGenPathsCHROMIUM(5);
277 EXPECT_TRUE(first_path != 0);
278 glDeletePathsCHROMIUM(first_path, 6);
279 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
280
281 GLsizei big_range = 0xffff;
282 // Setting big_range = std::numeric_limits<GLsizei>::max() should go through
283 // too, as far as NV_path_rendering is concerned. Current chromium side id
284 // allocator will use too much memory.
285 first_path = glGenPathsCHROMIUM(big_range);
286 EXPECT_TRUE(first_path != 0);
287 glDeletePathsCHROMIUM(first_path, big_range);
288 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
289
290 // Test glIsPathCHROMIUM().
291 path = glGenPathsCHROMIUM(1);
292 EXPECT_FALSE(glIsPathCHROMIUM(path));
293 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
294 GLfloat coords[] = {50.0f, 50.0f};
295 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords),
296 GL_FLOAT, coords);
297 EXPECT_TRUE(glIsPathCHROMIUM(path));
298 glDeletePathsCHROMIUM(path, 1);
299 EXPECT_FALSE(glIsPathCHROMIUM(path));
300 }
301
302 TEST_F(CHROMIUMPathRenderingTest, TestGenDeleteErrors) {
303 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
304 return;
305 }
306 // GenPaths / DeletePaths tests.
307 // std::numeric_limits<GLuint>::max() is wrong for GLsizei.
308 GLuint first_path = glGenPathsCHROMIUM(std::numeric_limits<GLuint>::max());
309 EXPECT_TRUE(first_path == 0);
310 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
311
312 first_path = glGenPathsCHROMIUM(-1);
313 EXPECT_TRUE(first_path == 0);
314 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
315
316 glDeletePathsCHROMIUM(1, -5);
317 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
318 }
319
320 TEST_F(CHROMIUMPathRenderingTest, TestPathParameterErrors) {
321 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
322 return;
323 }
324
325 GLuint path = glGenPathsCHROMIUM(1);
326 // PathParameter*: Wrong value for the pname should fail.
327 glPathParameteriCHROMIUM(path, GL_PATH_JOIN_STYLE_CHROMIUM, GL_FLAT_CHROMIUM);
328 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
329 glPathParameterfCHROMIUM(path, GL_PATH_END_CAPS_CHROMIUM,
330 GL_MITER_REVERT_CHROMIUM);
331 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
332
333 // PathParameter*: Wrong floating-point value should fail.
334 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM, -0.1);
335 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
336 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM,
337 std::numeric_limits<float>::quiet_NaN());
338 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
339 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM,
340 std::numeric_limits<float>::infinity());
341 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
342
343 // PathParameter*: Wrong pname should fail.
344 glPathParameteriCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM - 1, 5);
345 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
346 glDeletePathsCHROMIUM(path, 1);
347 }
348
349 TEST_F(CHROMIUMPathRenderingTest, TestPathObjectState) {
350 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
351 return;
352 }
353 glViewport(0, 0, kResolution, kResolution);
354 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
355 glStencilMask(0xffffffff);
356 glClearStencil(0);
357 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
358 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
359 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
360
361 // Test that trying to draw non-existing paths does not produce errors or
362 // results.
363 GLuint non_existing_paths[] = {0, 55, 74744};
364 for (auto& p : non_existing_paths) {
365 EXPECT_FALSE(glIsPathCHROMIUM(p));
366 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
367 TryAllDrawFunctions(p, GL_NO_ERROR);
368 }
369
370 // Path name marked as used but without path object state causes
371 // a GL error upon any draw command.
372 GLuint path = glGenPathsCHROMIUM(1);
373 EXPECT_FALSE(glIsPathCHROMIUM(path));
374 TryAllDrawFunctions(path, GL_INVALID_OPERATION);
375 glDeletePathsCHROMIUM(path, 1);
376
377 // Document a bit of an inconsistency: path name marked as used but without
378 // path object state causes a GL error upon any draw command (tested above).
379 // Path name that had path object state, but then was "cleared", still has a
380 // path object state, even though the state is empty.
381 path = glGenPathsCHROMIUM(1);
382 EXPECT_FALSE(glIsPathCHROMIUM(path));
383 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
384 GLfloat coords[] = {50.0f, 50.0f};
385 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords),
386 GL_FLOAT, coords);
387 EXPECT_TRUE(glIsPathCHROMIUM(path));
388 glPathCommandsCHROMIUM(path, 0, NULL, 0, GL_FLOAT, NULL);
389 EXPECT_TRUE(glIsPathCHROMIUM(path)); // The surprise.
390 TryAllDrawFunctions(path, GL_NO_ERROR);
391 glDeletePathsCHROMIUM(path, 1);
392
393 // Document a bit of an inconsistency: "clearing" a used path name causes
394 // path to acquire state.
395 path = glGenPathsCHROMIUM(1);
396 EXPECT_FALSE(glIsPathCHROMIUM(path));
397 glPathCommandsCHROMIUM(path, 0, NULL, 0, GL_FLOAT, NULL);
398 EXPECT_TRUE(glIsPathCHROMIUM(path)); // The surprise.
399 glDeletePathsCHROMIUM(path, 1);
400
401 // Make sure nothing got drawn by the drawing commands that should not produce
402 // anything.
403 const uint8 black[] = {0, 0, 0, 0};
404 EXPECT_TRUE(
405 GLTestHelper::CheckPixels(0, 0, kResolution, kResolution, 0, black));
406 }
407
408 TEST_F(CHROMIUMPathRenderingTest, TestUnnamedPathsErrors) {
409 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
410 return;
411 }
412
413 // Unnamed paths: Trying to create a path object with non-existing path name
414 // produces error. (Not a error in real NV_path_rendering).
415 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
416 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
417 GLfloat coords[] = {50.0f, 50.0f};
418 glPathCommandsCHROMIUM(555, arraysize(commands), commands, arraysize(coords),
419 GL_FLOAT, coords);
420 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
421
422 // PathParameter*: Using non-existing path object produces error.
423 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
424 glPathParameterfCHROMIUM(555, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f);
425 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
426
427 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
428 glPathParameteriCHROMIUM(555, GL_PATH_JOIN_STYLE_CHROMIUM, GL_ROUND_CHROMIUM);
429 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
430 }
431
432 TEST_F(CHROMIUMPathRenderingTest, TestPathCommandsErrors) {
433 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
434 return;
435 }
436 static const GLenum kInvalidCoordType = GL_NONE;
437
438 GLuint path = glGenPathsCHROMIUM(1);
439 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
440 GLfloat coords[] = {50.0f, 50.0f};
441
442 glPathCommandsCHROMIUM(path, arraysize(commands), commands, -4, GL_FLOAT,
443 coords);
444 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
445
446 glPathCommandsCHROMIUM(path, -1, commands, arraysize(coords), GL_FLOAT,
447 coords);
448 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
449
450 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords),
451 kInvalidCoordType, coords);
452 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
453
454 glDeletePathsCHROMIUM(path, 1);
455 }
456
457 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingInvalidArgs) {
458 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
459 return;
460 }
461 GLuint path = glGenPathsCHROMIUM(1);
462 glPathCommandsCHROMIUM(path, 0, NULL, 0, GL_FLOAT, NULL);
463
464 // Verify that normal calls work.
465 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F);
466 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
467 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
468 GL_BOUNDING_BOX_CHROMIUM);
469 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
470
471 // Using invalid fill mode causes INVALID_ENUM.
472 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM - 1, 0x7F);
473 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
474 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM - 1, 0x7F,
475 GL_BOUNDING_BOX_CHROMIUM);
476 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
477
478 // Using invalid cover mode causes INVALID_ENUM.
479 glCoverFillPathCHROMIUM(path, GL_CONVEX_HULL_CHROMIUM - 1);
480 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
481 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
482 GL_BOUNDING_BOX_CHROMIUM + 1);
483 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
484
485 // Using mask+1 not being power of two causes INVALID_VALUE with up/down fill
486 // mode.
487 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x40);
488 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
489 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_DOWN_CHROMIUM, 12,
490 GL_BOUNDING_BOX_CHROMIUM);
491 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
492
493 glDeletePathsCHROMIUM(path, 1);
494 }
495
496 // Tests that drawing with CHROMIUM_path_rendering functions work.
497 TEST_F(CHROMIUMPathRenderingTest, TestPathRendering) {
498 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
499 return;
500 }
501 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
502 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
503
504 SetupStateForTestPattern();
505
506 GLuint path = glGenPathsCHROMIUM(1);
507 SetupPathStateForTestPattern(path);
508
509 // Do the stencil fill, cover fill, stencil stroke, cover stroke
510 // in unconventional order:
511 // 1) stencil the stroke in stencil high bit
512 // 2) stencil the fill in low bits
513 // 3) cover the fill
514 // 4) cover the stroke
515 // This is done to check that glPathStencilFunc works, eg the mask
516 // goes through. Stencil func is not tested ATM, for simplicity.
517
518 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
519 glStencilStrokePathCHROMIUM(path, 0x80, 0x80);
520
521 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F);
522 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F);
523
524 glStencilFunc(GL_LESS, 0, 0x7F);
525 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
526 glUniform4fv(color_loc_, 1, kBlue);
527 glCoverFillPathCHROMIUM(path, GL_BOUNDING_BOX_CHROMIUM);
528
529 glStencilFunc(GL_EQUAL, 0x80, 0x80);
530 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
531 glUniform4fv(color_loc_, 1, kGreen);
532 glCoverStrokePathCHROMIUM(path, GL_CONVEX_HULL_CHROMIUM);
533
534 glDeletePathsCHROMIUM(path, 1);
535
536 // Verify the image.
537 VerifyTestPatternFill(0.0f, 0.0f);
538 VerifyTestPatternBg(0.0f, 0.0f);
539 VerifyTestPatternStroke(0.0f, 0.0f);
540 }
541
542 // Tests that drawing with CHROMIUM_path_rendering
543 // StencilThenCover{Stroke,Fill}Path functions work.
544 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingThenFunctions) {
545 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
546 return;
547 }
548 static float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
549 static float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
550
551 SetupStateForTestPattern();
552
553 GLuint path = glGenPathsCHROMIUM(1);
554 SetupPathStateForTestPattern(path);
555
556 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
557 glStencilFunc(GL_EQUAL, 0x80, 0x80);
558 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
559 glUniform4fv(color_loc_, 1, kGreen);
560 glStencilThenCoverStrokePathCHROMIUM(path, 0x80, 0x80,
561 GL_BOUNDING_BOX_CHROMIUM);
562
563 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F);
564 glStencilFunc(GL_LESS, 0, 0x7F);
565 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
566 glUniform4fv(color_loc_, 1, kBlue);
567 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
568 GL_CONVEX_HULL_CHROMIUM);
569
570 glDeletePathsCHROMIUM(path, 1);
571
572 // Verify the image.
573 VerifyTestPatternFill(0.0f, 0.0f);
574 VerifyTestPatternBg(0.0f, 0.0f);
575 VerifyTestPatternStroke(0.0f, 0.0f);
108 } 576 }
109 577
110 } // namespace gpu 578 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698