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

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: make more consistent 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] = {
51 0.5f, -0.5f, -0.1f, -0.8f, 4.4f, 5.5f, 6.6f, 7.7f, 197 0.5f, -0.5f, -0.1f, -0.8f, 4.4f, 5.5f, 6.6f, 7.7f,
52 8.8f, 9.9f, 10.11f, 11.22f, 12.33f, 13.44f, 14.55f, 15.66f}; 198 8.8f, 9.9f, 10.11f, 11.22f, 12.33f, 13.44f, 14.55f, 15.66f};
53 static const GLenum kMatrixModes[] = {GL_PATH_MODELVIEW_CHROMIUM, 199 static const GLenum kMatrixModes[] = {GL_PATH_MODELVIEW_CHROMIUM,
54 GL_PATH_PROJECTION_CHROMIUM}; 200 GL_PATH_PROJECTION_CHROMIUM};
55 static const GLenum kGetMatrixModes[] = {GL_PATH_MODELVIEW_MATRIX_CHROMIUM, 201 static const GLenum kGetMatrixModes[] = {GL_PATH_MODELVIEW_MATRIX_CHROMIUM,
56 GL_PATH_PROJECTION_MATRIX_CHROMIUM}; 202 GL_PATH_PROJECTION_MATRIX_CHROMIUM};
(...skipping 22 matching lines...) Expand all
79 glGetFloatv(kGetMatrixModes[i], mf); 225 glGetFloatv(kGetMatrixModes[i], mf);
80 glGetIntegerv(kGetMatrixModes[i], mi); 226 glGetIntegerv(kGetMatrixModes[i], mi);
81 ExpectEqualMatrix(kIdentityMatrix, mf); 227 ExpectEqualMatrix(kIdentityMatrix, mf);
82 ExpectEqualMatrix(kIdentityMatrix, mi); 228 ExpectEqualMatrix(kIdentityMatrix, mi);
83 229
84 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 230 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
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 // This is unspecified in NV_path_rendering.
261 EXPECT_EQ(0u, glGenPathsCHROMIUM(0));
262
263 GLuint path = glGenPathsCHROMIUM(1);
264 EXPECT_NE(path, 0u);
265 glDeletePathsCHROMIUM(path, 1);
266 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
267
268 GLuint first_path = glGenPathsCHROMIUM(5);
269 EXPECT_NE(first_path, 0u);
270 glDeletePathsCHROMIUM(first_path, 5);
271 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
272
273 // Test deleting paths that are not actually allocated:
274 // "unused names in /paths/ are silently ignored".
275 first_path = glGenPathsCHROMIUM(5);
276 EXPECT_NE(first_path, 0u);
277 glDeletePathsCHROMIUM(first_path, 6);
278 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
279
280 GLsizei big_range = 0xffff;
281 // Setting big_range = std::numeric_limits<GLsizei>::max() should go through
282 // too, as far as NV_path_rendering is concerned. Current chromium side id
283 // allocator will use too much memory.
284 first_path = glGenPathsCHROMIUM(big_range);
285 EXPECT_NE(first_path, 0u);
286 glDeletePathsCHROMIUM(first_path, big_range);
287 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
288
289 // Test glIsPathCHROMIUM().
290 path = glGenPathsCHROMIUM(1);
291 EXPECT_FALSE(glIsPathCHROMIUM(path));
292 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
293 GLfloat coords[] = {50.0f, 50.0f};
294 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords),
295 GL_FLOAT, coords);
296 EXPECT_TRUE(glIsPathCHROMIUM(path));
297 glDeletePathsCHROMIUM(path, 1);
298 EXPECT_FALSE(glIsPathCHROMIUM(path));
299 }
300
301 TEST_F(CHROMIUMPathRenderingTest, TestGenDeleteErrors) {
302 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
303 return;
304
305 // GenPaths / DeletePaths tests.
306 // std::numeric_limits<GLuint>::max() is wrong for GLsizei.
307 GLuint first_path = glGenPathsCHROMIUM(std::numeric_limits<GLuint>::max());
308 EXPECT_EQ(first_path, 0u);
309 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
310
311 first_path = glGenPathsCHROMIUM(-1);
312 EXPECT_EQ(first_path, 0u);
313 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
314
315 glDeletePathsCHROMIUM(1, -5);
316 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
317
318 first_path = glGenPathsCHROMIUM(-1);
319 EXPECT_EQ(first_path, 0u);
320 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
321
322 // Test that delete with first_id and range such that first_id + range
323 // overflows the GLuint. Example:
324 // Range is 0x7fffffff. First id is X. Last id will be X + 0x7ffffffe.
325 // X = 0x80000001 would succeed, where as X = 0x80000002 would fail.
326 // To get 0x80000002, we need to allocate first 0x7fffffff and then
327 // 3 (0x80000000, 0x80000001 and 0x80000002).
328 // While not guaranteed by the API, we expect the implementation
329 // hands us deterministic ids.
330 first_path = glGenPathsCHROMIUM(std::numeric_limits<GLsizei>::max());
331 EXPECT_EQ(first_path, 1u);
332 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
333
334 GLuint additional_paths = glGenPathsCHROMIUM(3);
335 EXPECT_EQ(additional_paths,
336 static_cast<GLuint>(std::numeric_limits<GLsizei>::max()) + 1u);
337 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
338
339 // Test that passing a range so big that it would overflow client_id + range -
340 // 1 check
341 // causes an error.
342 glDeletePathsCHROMIUM(additional_paths + 2u,
343 std::numeric_limits<GLsizei>::max());
344 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
345
346 // Cleanup the above allocations. Also test that passing max value still
347 // works.
348 glDeletePathsCHROMIUM(1, std::numeric_limits<GLsizei>::max());
349 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
350 glDeletePathsCHROMIUM(std::numeric_limits<GLsizei>::max(),
351 std::numeric_limits<GLsizei>::max());
352 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
353 }
354
355 TEST_F(CHROMIUMPathRenderingTest, TestPathParameterErrors) {
356 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
357 return;
358
359 GLuint path = glGenPathsCHROMIUM(1);
360 // PathParameter*: Wrong value for the pname should fail.
361 glPathParameteriCHROMIUM(path, GL_PATH_JOIN_STYLE_CHROMIUM, GL_FLAT_CHROMIUM);
362 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
363 glPathParameterfCHROMIUM(path, GL_PATH_END_CAPS_CHROMIUM,
364 GL_MITER_REVERT_CHROMIUM);
365 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
366
367 // PathParameter*: Wrong floating-point value should fail.
368 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM, -0.1);
369 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
370 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM,
371 std::numeric_limits<float>::quiet_NaN());
372 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
373 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM,
374 std::numeric_limits<float>::infinity());
375 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
376
377 // PathParameter*: Wrong pname should fail.
378 glPathParameteriCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM - 1, 5);
379 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
380 glDeletePathsCHROMIUM(path, 1);
381 }
382
383 TEST_F(CHROMIUMPathRenderingTest, TestPathObjectState) {
384 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
385 return;
386
387 glViewport(0, 0, kResolution, kResolution);
388 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
389 glStencilMask(0xffffffff);
390 glClearStencil(0);
391 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
392 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
393 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
394
395 // Test that trying to draw non-existing paths does not produce errors or
396 // results.
397 GLuint non_existing_paths[] = {0, 55, 74744};
398 for (auto& p : non_existing_paths) {
399 EXPECT_FALSE(glIsPathCHROMIUM(p));
400 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
401 TryAllDrawFunctions(p, GL_NO_ERROR);
402 }
403
404 // Path name marked as used but without path object state causes
405 // a GL error upon any draw command.
406 GLuint path = glGenPathsCHROMIUM(1);
407 EXPECT_FALSE(glIsPathCHROMIUM(path));
408 TryAllDrawFunctions(path, GL_INVALID_OPERATION);
409 glDeletePathsCHROMIUM(path, 1);
410
411 // Document a bit of an inconsistency: path name marked as used but without
412 // path object state causes a GL error upon any draw command (tested above).
413 // Path name that had path object state, but then was "cleared", still has a
414 // path object state, even though the state is empty.
415 path = glGenPathsCHROMIUM(1);
416 EXPECT_FALSE(glIsPathCHROMIUM(path));
417 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
418 GLfloat coords[] = {50.0f, 50.0f};
419 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords),
420 GL_FLOAT, coords);
421 EXPECT_TRUE(glIsPathCHROMIUM(path));
422 glPathCommandsCHROMIUM(path, 0, NULL, 0, GL_FLOAT, NULL);
423 EXPECT_TRUE(glIsPathCHROMIUM(path)); // The surprise.
424 TryAllDrawFunctions(path, GL_NO_ERROR);
425 glDeletePathsCHROMIUM(path, 1);
426
427 // Document a bit of an inconsistency: "clearing" a used path name causes
428 // path to acquire state.
429 path = glGenPathsCHROMIUM(1);
430 EXPECT_FALSE(glIsPathCHROMIUM(path));
431 glPathCommandsCHROMIUM(path, 0, NULL, 0, GL_FLOAT, NULL);
432 EXPECT_TRUE(glIsPathCHROMIUM(path)); // The surprise.
433 glDeletePathsCHROMIUM(path, 1);
434
435 // Make sure nothing got drawn by the drawing commands that should not produce
436 // anything.
437 const uint8 black[] = {0, 0, 0, 0};
438 EXPECT_TRUE(
439 GLTestHelper::CheckPixels(0, 0, kResolution, kResolution, 0, black));
440 }
441
442 TEST_F(CHROMIUMPathRenderingTest, TestUnnamedPathsErrors) {
443 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
444 return;
445
446 // Unnamed paths: Trying to create a path object with non-existing path name
447 // produces error. (Not a error in real NV_path_rendering).
448 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
449 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
450 GLfloat coords[] = {50.0f, 50.0f};
451 glPathCommandsCHROMIUM(555, arraysize(commands), commands, arraysize(coords),
452 GL_FLOAT, coords);
453 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
454
455 // PathParameter*: Using non-existing path object produces error.
456 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
457 glPathParameterfCHROMIUM(555, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f);
458 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
459
460 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
461 glPathParameteriCHROMIUM(555, GL_PATH_JOIN_STYLE_CHROMIUM, GL_ROUND_CHROMIUM);
462 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
463 }
464
465 TEST_F(CHROMIUMPathRenderingTest, TestPathCommandsErrors) {
466 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
467 return;
468
469 static const GLenum kInvalidCoordType = GL_NONE;
470
471 GLuint path = glGenPathsCHROMIUM(1);
472 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM};
473 GLfloat coords[] = {50.0f, 50.0f};
474
475 glPathCommandsCHROMIUM(path, arraysize(commands), commands, -4, GL_FLOAT,
476 coords);
477 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
478
479 glPathCommandsCHROMIUM(path, -1, commands, arraysize(coords), GL_FLOAT,
480 coords);
481 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
482
483 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords),
484 kInvalidCoordType, coords);
485 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
486
487 // These can not distinquish between the check that should fail them.
488 // This should fail due to coord count * float size overflow.
489 glPathCommandsCHROMIUM(path, arraysize(commands), commands,
490 std::numeric_limits<GLsizei>::max(), GL_FLOAT, coords);
491 // This should fail due to cmd count + coord count * short size.
492 glPathCommandsCHROMIUM(path, arraysize(commands), commands,
493 std::numeric_limits<GLsizei>::max(), GL_SHORT, coords);
494 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
495
496 glDeletePathsCHROMIUM(path, 1);
497 }
498
499 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingInvalidArgs) {
500 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
501 return;
502
503 GLuint path = glGenPathsCHROMIUM(1);
504 glPathCommandsCHROMIUM(path, 0, NULL, 0, GL_FLOAT, NULL);
505
506 // Verify that normal calls work.
507 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F);
508 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
509 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
510 GL_BOUNDING_BOX_CHROMIUM);
511 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
512
513 // Using invalid fill mode causes INVALID_ENUM.
514 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM - 1, 0x7F);
515 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
516 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM - 1, 0x7F,
517 GL_BOUNDING_BOX_CHROMIUM);
518 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
519
520 // Using invalid cover mode causes INVALID_ENUM.
521 glCoverFillPathCHROMIUM(path, GL_CONVEX_HULL_CHROMIUM - 1);
522 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
523 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
524 GL_BOUNDING_BOX_CHROMIUM + 1);
525 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
526
527 // Using mask+1 not being power of two causes INVALID_VALUE with up/down fill
528 // mode.
529 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x40);
530 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
531 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_DOWN_CHROMIUM, 12,
532 GL_BOUNDING_BOX_CHROMIUM);
533 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
534
535 glDeletePathsCHROMIUM(path, 1);
536 }
537
538 // Tests that drawing with CHROMIUM_path_rendering functions work.
539 TEST_F(CHROMIUMPathRenderingTest, TestPathRendering) {
540 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
541 return;
542
543 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
544 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
545
546 SetupStateForTestPattern();
547
548 GLuint path = glGenPathsCHROMIUM(1);
549 SetupPathStateForTestPattern(path);
550
551 // Do the stencil fill, cover fill, stencil stroke, cover stroke
552 // in unconventional order:
553 // 1) stencil the stroke in stencil high bit
554 // 2) stencil the fill in low bits
555 // 3) cover the fill
556 // 4) cover the stroke
557 // This is done to check that glPathStencilFunc works, eg the mask
558 // goes through. Stencil func is not tested ATM, for simplicity.
559
560 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
561 glStencilStrokePathCHROMIUM(path, 0x80, 0x80);
562
563 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F);
564 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F);
565
566 glStencilFunc(GL_LESS, 0, 0x7F);
567 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
568 glUniform4fv(color_loc_, 1, kBlue);
569 glCoverFillPathCHROMIUM(path, GL_BOUNDING_BOX_CHROMIUM);
570
571 glStencilFunc(GL_EQUAL, 0x80, 0x80);
572 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
573 glUniform4fv(color_loc_, 1, kGreen);
574 glCoverStrokePathCHROMIUM(path, GL_CONVEX_HULL_CHROMIUM);
575
576 glDeletePathsCHROMIUM(path, 1);
577
578 // Verify the image.
579 VerifyTestPatternFill(0.0f, 0.0f);
580 VerifyTestPatternBg(0.0f, 0.0f);
581 VerifyTestPatternStroke(0.0f, 0.0f);
582 }
583
584 // Tests that drawing with CHROMIUM_path_rendering
585 // StencilThenCover{Stroke,Fill}Path functions work.
586 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingThenFunctions) {
587 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
588 return;
589
590 static float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
591 static float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
592
593 SetupStateForTestPattern();
594
595 GLuint path = glGenPathsCHROMIUM(1);
596 SetupPathStateForTestPattern(path);
597
598 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
599 glStencilFunc(GL_EQUAL, 0x80, 0x80);
600 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
601 glUniform4fv(color_loc_, 1, kGreen);
602 glStencilThenCoverStrokePathCHROMIUM(path, 0x80, 0x80,
603 GL_BOUNDING_BOX_CHROMIUM);
604
605 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F);
606 glStencilFunc(GL_LESS, 0, 0x7F);
607 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
608 glUniform4fv(color_loc_, 1, kBlue);
609 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
610 GL_CONVEX_HULL_CHROMIUM);
611
612 glDeletePathsCHROMIUM(path, 1);
613
614 // Verify the image.
615 VerifyTestPatternFill(0.0f, 0.0f);
616 VerifyTestPatternBg(0.0f, 0.0f);
617 VerifyTestPatternStroke(0.0f, 0.0f);
108 } 618 }
109 619
110 } // namespace gpu 620 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698