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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation_unittest.cc

Issue 1785483002: Handle UNPACK_SKIP_* and PACK_SKIP_* parameters on the client side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 // Tests for GLES2Implementation. 5 // Tests for GLES2Implementation.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 2484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 2495
2496 gl_->TexImage2D( 2496 gl_->TexImage2D(
2497 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType, 2497 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType,
2498 pixels.get()); 2498 pixels.get());
2499 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 2499 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2500 EXPECT_TRUE(CheckRect( 2500 EXPECT_TRUE(CheckRect(
2501 kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment, 2501 kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment,
2502 pixels.get() + kHeight / 2 * padded_row_size, mem2.ptr)); 2502 pixels.get() + kHeight / 2 * padded_row_size, mem2.ptr));
2503 } 2503 }
2504 2504
2505 TEST_F(GLES2ImplementationTest, SubImageUnpack) { 2505 TEST_F(GLES2ImplementationTest, SubImage2DUnpack) {
2506 static const GLint unpack_alignments[] = { 1, 2, 4, 8 }; 2506 static const GLint unpack_alignments[] = { 1, 2, 4, 8 };
2507 2507
2508 static const GLenum kFormat = GL_RGB; 2508 static const GLenum kFormat = GL_RGB;
2509 static const GLenum kType = GL_UNSIGNED_BYTE; 2509 static const GLenum kType = GL_UNSIGNED_BYTE;
2510 static const GLint kLevel = 0; 2510 static const GLint kLevel = 0;
2511 static const GLint kBorder = 0; 2511 static const GLint kBorder = 0;
2512 // We're testing using the unpack params to pull a subimage out of a larger 2512 // We're testing using the unpack params to pull a subimage out of a larger
2513 // source of pixels. Here we specify the subimage by its border rows / 2513 // source of pixels. Here we specify the subimage by its border rows /
2514 // columns. 2514 // columns.
2515 static const GLint kSrcWidth = 33; 2515 static const GLint kSrcWidth = 33;
2516 static const GLint kSrcSubImageX0 = 11; 2516 static const GLint kSrcSubImageX0 = 11;
2517 static const GLint kSrcSubImageX1 = 20; 2517 static const GLint kSrcSubImageX1 = 20;
2518 static const GLint kSrcSubImageY0 = 18; 2518 static const GLint kSrcSubImageY0 = 18;
2519 static const GLint kSrcSubImageY1 = 23; 2519 static const GLint kSrcSubImageY1 = 23;
2520 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0; 2520 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0;
2521 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0; 2521 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0;
2522 2522
2523 // these are only used in the texsubimage tests 2523 // these are only used in the texsubimage tests
2524 static const GLint kTexWidth = 1023; 2524 static const GLint kTexWidth = 1023;
2525 static const GLint kTexHeight = 511; 2525 static const GLint kTexHeight = 511;
2526 static const GLint kTexSubXOffset = 419; 2526 static const GLint kTexSubXOffset = 419;
2527 static const GLint kTexSubYOffset = 103; 2527 static const GLint kTexSubYOffset = 103;
2528 2528
2529 struct { 2529 struct {
2530 cmds::PixelStorei pixel_store_i[4]; 2530 cmds::PixelStorei pixel_store_i;
2531 cmds::TexImage2D tex_image_2d; 2531 cmds::TexImage2D tex_image_2d;
2532 } texImageExpected; 2532 } texImageExpected;
2533 2533
2534 struct { 2534 struct {
2535 cmds::PixelStorei pixel_store_i[4]; 2535 cmds::PixelStorei pixel_store_i;
2536 cmds::TexImage2D tex_image_2d; 2536 cmds::TexImage2D tex_image_2d;
2537 cmds::TexSubImage2D tex_sub_image_2d; 2537 cmds::TexSubImage2D tex_sub_image_2d;
2538 } texSubImageExpected; 2538 } texSubImageExpected;
2539 2539
2540 uint32_t src_size; 2540 uint32_t pixel_size;
2541 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes( 2541 PixelStoreParams pixel_params;
2542 kSrcWidth, kSrcSubImageY1, 1, kFormat, kType, 8, &src_size, NULL, NULL)); 2542 // Makes sure the pixels size is large enough for all tests.
2543 pixel_params.alignment = 8;
2544 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3(
2545 kSrcWidth, kSrcSubImageY1, 1, kFormat, kType,
2546 pixel_params, &pixel_size, nullptr, nullptr, nullptr, nullptr));
2543 scoped_ptr<uint8_t[]> src_pixels; 2547 scoped_ptr<uint8_t[]> src_pixels;
2544 src_pixels.reset(new uint8_t[src_size]); 2548 src_pixels.reset(new uint8_t[pixel_size]);
2545 for (size_t i = 0; i < src_size; ++i) { 2549 for (size_t i = 0; i < pixel_size; ++i) {
2546 src_pixels[i] = static_cast<int8_t>(i); 2550 src_pixels[i] = static_cast<uint8_t>(i % 255);
2547 } 2551 }
2548 2552
2549 for (int sub = 0; sub < 2; ++sub) { 2553 for (int sub = 0; sub < 2; ++sub) {
2550 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) { 2554 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) {
2555 const void* commands = GetPut();
2556
2551 GLint alignment = unpack_alignments[a]; 2557 GLint alignment = unpack_alignments[a];
2552 uint32_t size; 2558 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment);
2553 uint32_t unpadded_row_size; 2559 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH, kSrcWidth);
2554 uint32_t padded_row_size; 2560 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS, kSrcSubImageX0);
2555 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes( 2561 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS, kSrcSubImageY0);
2556 kSrcSubImageWidth, kSrcSubImageHeight, 1, kFormat, kType, alignment,
2557 &size, &unpadded_row_size, &padded_row_size));
2558 ASSERT_TRUE(size <= MaxTransferBufferSize());
2559 ExpectedMemoryInfo mem = GetExpectedMemory(size);
2560 2562
2561 const void* commands = GetPut(); 2563 uint32_t client_size;
2562 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment); 2564 uint32_t client_unpadded_row_size;
2563 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH_EXT, kSrcWidth); 2565 uint32_t client_padded_row_size;
2564 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, kSrcSubImageX0); 2566 uint32_t client_skip_size;
2565 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS_EXT, kSrcSubImageY0); 2567 {
2568 PixelStoreParams params;
2569 params.alignment = alignment;
2570 params.row_length = kSrcWidth;
2571 params.skip_pixels = kSrcSubImageX0;
2572 params.skip_rows = kSrcSubImageY0;
2573 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3(
2574 kSrcSubImageWidth, kSrcSubImageHeight, 1, kFormat, kType, params,
2575 &client_size, &client_unpadded_row_size, &client_padded_row_size,
2576 &client_skip_size, nullptr));
2577 ASSERT_TRUE(client_size + client_skip_size <= pixel_size);
2578 }
2579
2580 uint32_t service_size;
2581 uint32_t service_unpadded_row_size;
2582 uint32_t service_padded_row_size;
2583 uint32_t service_skip_size;
2584 {
2585 PixelStoreParams params;
2586 // For pixels we send to service side, we already applied all unpack
2587 // parameters except for UNPACK_ALIGNMENT.
2588 params.alignment = alignment;
2589 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3(
2590 kSrcSubImageWidth, kSrcSubImageHeight, 1, kFormat, kType, params,
2591 &service_size, &service_unpadded_row_size, &service_padded_row_size,
2592 &service_skip_size, nullptr));
2593 ASSERT_TRUE(service_size <= MaxTransferBufferSize());
2594 ASSERT_TRUE(service_skip_size == 0);
2595 ASSERT_TRUE(client_unpadded_row_size == service_unpadded_row_size);
2596 }
2597
2598 ExpectedMemoryInfo mem = GetExpectedMemory(service_size);
2566 if (sub) { 2599 if (sub) {
2567 gl_->TexImage2D( 2600 gl_->TexImage2D(
2568 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder, 2601 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder,
2569 kFormat, kType, NULL); 2602 kFormat, kType, nullptr);
2570 gl_->TexSubImage2D( 2603 gl_->TexSubImage2D(
2571 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset, 2604 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset,
2572 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, 2605 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType,
2573 src_pixels.get()); 2606 src_pixels.get());
2574 texSubImageExpected.pixel_store_i[0].Init( 2607 texSubImageExpected.pixel_store_i.Init(GL_UNPACK_ALIGNMENT, alignment);
2575 GL_UNPACK_ALIGNMENT, alignment);
2576 texSubImageExpected.pixel_store_i[1].Init(
2577 GL_UNPACK_ROW_LENGTH_EXT, kSrcWidth);
2578 texSubImageExpected.pixel_store_i[2].Init(
2579 GL_UNPACK_SKIP_PIXELS_EXT, kSrcSubImageX0);
2580 texSubImageExpected.pixel_store_i[3].Init(
2581 GL_UNPACK_SKIP_ROWS_EXT, kSrcSubImageY0);
2582 texSubImageExpected.tex_image_2d.Init( 2608 texSubImageExpected.tex_image_2d.Init(
2583 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, 2609 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight,
2584 kFormat, kType, 0, 0); 2610 kFormat, kType, 0, 0);
2585 texSubImageExpected.tex_sub_image_2d.Init( 2611 texSubImageExpected.tex_sub_image_2d.Init(
2586 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset, 2612 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset,
2587 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, mem.id, 2613 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, mem.id,
2588 mem.offset, GL_FALSE); 2614 mem.offset, GL_FALSE);
2589 EXPECT_EQ(0, memcmp( 2615 EXPECT_EQ(0, memcmp(&texSubImageExpected, commands,
2590 &texSubImageExpected, commands, sizeof(texSubImageExpected))); 2616 sizeof(texSubImageExpected)));
2591 } else { 2617 } else {
2592 gl_->TexImage2D( 2618 gl_->TexImage2D(
2593 GL_TEXTURE_2D, kLevel, kFormat, 2619 GL_TEXTURE_2D, kLevel, kFormat,
2594 kSrcSubImageWidth, kSrcSubImageHeight, kBorder, kFormat, kType, 2620 kSrcSubImageWidth, kSrcSubImageHeight, kBorder, kFormat, kType,
2595 src_pixels.get()); 2621 src_pixels.get());
2596 texImageExpected.pixel_store_i[0].Init(GL_UNPACK_ALIGNMENT, alignment); 2622 texImageExpected.pixel_store_i.Init(GL_UNPACK_ALIGNMENT, alignment);
2597 texImageExpected.pixel_store_i[1].Init(
2598 GL_UNPACK_ROW_LENGTH_EXT, kSrcWidth);
2599 texImageExpected.pixel_store_i[2].Init(
2600 GL_UNPACK_SKIP_PIXELS_EXT, kSrcSubImageX0);
2601 texImageExpected.pixel_store_i[3].Init(
2602 GL_UNPACK_SKIP_ROWS_EXT, kSrcSubImageY0);
2603 texImageExpected.tex_image_2d.Init( 2623 texImageExpected.tex_image_2d.Init(
2604 GL_TEXTURE_2D, kLevel, kFormat, kSrcSubImageWidth, 2624 GL_TEXTURE_2D, kLevel, kFormat, kSrcSubImageWidth,
2605 kSrcSubImageHeight, kFormat, kType, mem.id, mem.offset); 2625 kSrcSubImageHeight, kFormat, kType, mem.id, mem.offset);
2606 EXPECT_EQ(0, memcmp( 2626 EXPECT_EQ(0, memcmp(&texImageExpected, commands,
2607 &texImageExpected, commands, sizeof(texImageExpected))); 2627 sizeof(texImageExpected)));
2608 } 2628 }
2609 uint32_t src_padded_row_size;
2610 ASSERT_TRUE(GLES2Util::ComputeImagePaddedRowSize(
2611 kSrcWidth, kFormat, kType, alignment, &src_padded_row_size));
2612 uint32_t bytes_per_group =
2613 GLES2Util::ComputeImageGroupSize(kFormat, kType);
2614 for (int y = 0; y < kSrcSubImageHeight; ++y) { 2629 for (int y = 0; y < kSrcSubImageHeight; ++y) {
2615 const uint8_t* src_row = src_pixels.get() + 2630 const uint8_t* src_row =
2616 (kSrcSubImageY0 + y) * src_padded_row_size + 2631 src_pixels.get() + client_skip_size + y * client_padded_row_size;
2617 bytes_per_group * kSrcSubImageX0; 2632 const uint8_t* dst_row = mem.ptr + y * service_padded_row_size;
2618 const uint8_t* dst_row = mem.ptr + y * padded_row_size; 2633 EXPECT_EQ(0, memcmp(src_row, dst_row, service_unpadded_row_size));
2619 EXPECT_EQ(0, memcmp(src_row, dst_row, unpadded_row_size));
2620 } 2634 }
2621 ClearCommands(); 2635 ClearCommands();
2622 } 2636 }
2623 } 2637 }
2624 } 2638 }
2625 2639
2626 // Test texture related calls with invalid arguments. 2640 // Test texture related calls with invalid arguments.
2627 TEST_F(GLES2ImplementationTest, TextureInvalidArguments) { 2641 TEST_F(GLES2ImplementationTest, TextureInvalidArguments) {
2628 struct Cmds { 2642 struct Cmds {
2629 cmds::TexImage2D tex_image_2d; 2643 cmds::TexImage2D tex_image_2d;
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
4301 ContextInitOptions init_options; 4315 ContextInitOptions init_options;
4302 init_options.transfer_buffer_initialize_fail = true; 4316 init_options.transfer_buffer_initialize_fail = true;
4303 EXPECT_FALSE(Initialize(init_options)); 4317 EXPECT_FALSE(Initialize(init_options));
4304 } 4318 }
4305 4319
4306 #include "base/macros.h" 4320 #include "base/macros.h"
4307 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 4321 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
4308 4322
4309 } // namespace gles2 4323 } // namespace gles2
4310 } // namespace gpu 4324 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/service/context_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698