OLD | NEW |
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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/command_line.h" | 10 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
11 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
12 #include "gpu/command_buffer/service/context_group.h" | 15 #include "gpu/command_buffer/service/context_group.h" |
13 #include "gpu/command_buffer/service/context_state.h" | 16 #include "gpu/command_buffer/service/context_state.h" |
14 #include "gpu/command_buffer/service/gl_surface_mock.h" | 17 #include "gpu/command_buffer/service/gl_surface_mock.h" |
15 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" | 18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" |
16 | 19 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 ReadPixelsEmulator(GLsizei width, | 400 ReadPixelsEmulator(GLsizei width, |
398 GLsizei height, | 401 GLsizei height, |
399 GLint bytes_per_pixel, | 402 GLint bytes_per_pixel, |
400 const void* src_pixels, | 403 const void* src_pixels, |
401 const void* expected_pixels, | 404 const void* expected_pixels, |
402 GLint pack_alignment) | 405 GLint pack_alignment) |
403 : width_(width), | 406 : width_(width), |
404 height_(height), | 407 height_(height), |
405 pack_alignment_(pack_alignment), | 408 pack_alignment_(pack_alignment), |
406 bytes_per_pixel_(bytes_per_pixel), | 409 bytes_per_pixel_(bytes_per_pixel), |
407 src_pixels_(reinterpret_cast<const int8*>(src_pixels)), | 410 src_pixels_(reinterpret_cast<const int8_t*>(src_pixels)), |
408 expected_pixels_(reinterpret_cast<const int8*>(expected_pixels)) {} | 411 expected_pixels_(reinterpret_cast<const int8_t*>(expected_pixels)) {} |
409 | 412 |
410 void ReadPixels(GLint x, | 413 void ReadPixels(GLint x, |
411 GLint y, | 414 GLint y, |
412 GLsizei width, | 415 GLsizei width, |
413 GLsizei height, | 416 GLsizei height, |
414 GLenum format, | 417 GLenum format, |
415 GLenum type, | 418 GLenum type, |
416 void* pixels) const { | 419 void* pixels) const { |
417 DCHECK_GE(x, 0); | 420 DCHECK_GE(x, 0); |
418 DCHECK_GE(y, 0); | 421 DCHECK_GE(y, 0); |
419 DCHECK_LE(x + width, width_); | 422 DCHECK_LE(x + width, width_); |
420 DCHECK_LE(y + height, height_); | 423 DCHECK_LE(y + height, height_); |
421 for (GLint yy = 0; yy < height; ++yy) { | 424 for (GLint yy = 0; yy < height; ++yy) { |
422 const int8* src = GetPixelAddress(src_pixels_, x, y + yy); | 425 const int8_t* src = GetPixelAddress(src_pixels_, x, y + yy); |
423 const void* dst = ComputePackAlignmentAddress(0, yy, width, pixels); | 426 const void* dst = ComputePackAlignmentAddress(0, yy, width, pixels); |
424 memcpy(const_cast<void*>(dst), src, width * bytes_per_pixel_); | 427 memcpy(const_cast<void*>(dst), src, width * bytes_per_pixel_); |
425 } | 428 } |
426 } | 429 } |
427 | 430 |
428 bool CompareRowSegment(GLint x, | 431 bool CompareRowSegment(GLint x, |
429 GLint y, | 432 GLint y, |
430 GLsizei width, | 433 GLsizei width, |
431 const void* data) const { | 434 const void* data) const { |
432 DCHECK(x + width <= width_ || width == 0); | 435 DCHECK(x + width <= width_ || width == 0); |
433 return memcmp(data, | 436 return memcmp(data, |
434 GetPixelAddress(expected_pixels_, x, y), | 437 GetPixelAddress(expected_pixels_, x, y), |
435 width * bytes_per_pixel_) == 0; | 438 width * bytes_per_pixel_) == 0; |
436 } | 439 } |
437 | 440 |
438 // Helper to compute address of pixel in pack aligned data. | 441 // Helper to compute address of pixel in pack aligned data. |
439 const void* ComputePackAlignmentAddress(GLint x, | 442 const void* ComputePackAlignmentAddress(GLint x, |
440 GLint y, | 443 GLint y, |
441 GLsizei width, | 444 GLsizei width, |
442 const void* address) const { | 445 const void* address) const { |
443 GLint unpadded_row_size = ComputeImageDataSize(width, 1); | 446 GLint unpadded_row_size = ComputeImageDataSize(width, 1); |
444 GLint two_rows_size = ComputeImageDataSize(width, 2); | 447 GLint two_rows_size = ComputeImageDataSize(width, 2); |
445 GLsizei padded_row_size = two_rows_size - unpadded_row_size; | 448 GLsizei padded_row_size = two_rows_size - unpadded_row_size; |
446 GLint offset = y * padded_row_size + x * bytes_per_pixel_; | 449 GLint offset = y * padded_row_size + x * bytes_per_pixel_; |
447 return static_cast<const int8*>(address) + offset; | 450 return static_cast<const int8_t*>(address) + offset; |
448 } | 451 } |
449 | 452 |
450 GLint ComputeImageDataSize(GLint width, GLint height) const { | 453 GLint ComputeImageDataSize(GLint width, GLint height) const { |
451 GLint row_size = width * bytes_per_pixel_; | 454 GLint row_size = width * bytes_per_pixel_; |
452 if (height > 1) { | 455 if (height > 1) { |
453 GLint temp = row_size + pack_alignment_ - 1; | 456 GLint temp = row_size + pack_alignment_ - 1; |
454 GLint padded_row_size = (temp / pack_alignment_) * pack_alignment_; | 457 GLint padded_row_size = (temp / pack_alignment_) * pack_alignment_; |
455 GLint size_of_all_but_last_row = (height - 1) * padded_row_size; | 458 GLint size_of_all_but_last_row = (height - 1) * padded_row_size; |
456 return size_of_all_but_last_row + row_size; | 459 return size_of_all_but_last_row + row_size; |
457 } else { | 460 } else { |
458 return height * row_size; | 461 return height * row_size; |
459 } | 462 } |
460 } | 463 } |
461 | 464 |
462 private: | 465 private: |
463 const int8* GetPixelAddress(const int8* base, GLint x, GLint y) const { | 466 const int8_t* GetPixelAddress(const int8_t* base, GLint x, GLint y) const { |
464 return base + (width_ * y + x) * bytes_per_pixel_; | 467 return base + (width_ * y + x) * bytes_per_pixel_; |
465 } | 468 } |
466 | 469 |
467 GLsizei width_; | 470 GLsizei width_; |
468 GLsizei height_; | 471 GLsizei height_; |
469 GLint pack_alignment_; | 472 GLint pack_alignment_; |
470 GLint bytes_per_pixel_; | 473 GLint bytes_per_pixel_; |
471 const int8* src_pixels_; | 474 const int8_t* src_pixels_; |
472 const int8* expected_pixels_; | 475 const int8_t* expected_pixels_; |
473 }; | 476 }; |
474 | 477 |
475 } // anonymous namespace | 478 } // anonymous namespace |
476 | 479 |
477 void GLES2DecoderTest::CheckReadPixelsOutOfRange(GLint in_read_x, | 480 void GLES2DecoderTest::CheckReadPixelsOutOfRange(GLint in_read_x, |
478 GLint in_read_y, | 481 GLint in_read_y, |
479 GLsizei in_read_width, | 482 GLsizei in_read_width, |
480 GLsizei in_read_height, | 483 GLsizei in_read_height, |
481 bool init) { | 484 bool init) { |
482 const GLsizei kWidth = 5; | 485 const GLsizei kWidth = 5; |
483 const GLsizei kHeight = 3; | 486 const GLsizei kHeight = 3; |
484 const GLint kBytesPerPixel = 4; | 487 const GLint kBytesPerPixel = 4; |
485 const GLint kPackAlignment = 4; | 488 const GLint kPackAlignment = 4; |
486 const GLenum kFormat = GL_RGBA; | 489 const GLenum kFormat = GL_RGBA; |
487 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = { | 490 static const uint8_t kSrcPixels[kWidth * kHeight * kBytesPerPixel] = { |
488 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255, | 491 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255, |
489 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255, | 492 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255, |
490 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255, | 493 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255, |
491 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255 | 494 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255}; |
492 }; | |
493 | 495 |
494 ClearSharedMemory(); | 496 ClearSharedMemory(); |
495 | 497 |
496 // We need to setup an FBO so we can know the max size that ReadPixels will | 498 // We need to setup an FBO so we can know the max size that ReadPixels will |
497 // access | 499 // access |
498 if (init) { | 500 if (init) { |
499 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); | 501 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
500 DoTexImage2D(GL_TEXTURE_2D, | 502 DoTexImage2D(GL_TEXTURE_2D, |
501 0, | 503 0, |
502 kFormat, | 504 kFormat, |
(...skipping 15 matching lines...) Expand all Loading... |
518 GL_NO_ERROR); | 520 GL_NO_ERROR); |
519 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) | 521 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) |
520 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) | 522 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) |
521 .RetiresOnSaturation(); | 523 .RetiresOnSaturation(); |
522 } | 524 } |
523 | 525 |
524 ReadPixelsEmulator emu( | 526 ReadPixelsEmulator emu( |
525 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment); | 527 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment); |
526 typedef ReadPixels::Result Result; | 528 typedef ReadPixels::Result Result; |
527 Result* result = GetSharedMemoryAs<Result*>(); | 529 Result* result = GetSharedMemoryAs<Result*>(); |
528 uint32 result_shm_id = kSharedMemoryId; | 530 uint32_t result_shm_id = kSharedMemoryId; |
529 uint32 result_shm_offset = kSharedMemoryOffset; | 531 uint32_t result_shm_offset = kSharedMemoryOffset; |
530 uint32 pixels_shm_id = kSharedMemoryId; | 532 uint32_t pixels_shm_id = kSharedMemoryId; |
531 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); | 533 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); |
532 void* dest = &result[1]; | 534 void* dest = &result[1]; |
533 EXPECT_CALL(*gl_, GetError()) | 535 EXPECT_CALL(*gl_, GetError()) |
534 .WillOnce(Return(GL_NO_ERROR)) | 536 .WillOnce(Return(GL_NO_ERROR)) |
535 .WillOnce(Return(GL_NO_ERROR)) | 537 .WillOnce(Return(GL_NO_ERROR)) |
536 .RetiresOnSaturation(); | 538 .RetiresOnSaturation(); |
537 // ReadPixels will be called for valid size only even though the command | 539 // ReadPixels will be called for valid size only even though the command |
538 // is requesting a larger size. | 540 // is requesting a larger size. |
539 GLint read_x = std::max(0, in_read_x); | 541 GLint read_x = std::max(0, in_read_x); |
540 GLint read_y = std::max(0, in_read_y); | 542 GLint read_y = std::max(0, in_read_y); |
541 GLint read_end_x = std::max(0, std::min(kWidth, in_read_x + in_read_width)); | 543 GLint read_end_x = std::max(0, std::min(kWidth, in_read_x + in_read_width)); |
(...skipping 17 matching lines...) Expand all Loading... |
559 kFormat, | 561 kFormat, |
560 GL_UNSIGNED_BYTE, | 562 GL_UNSIGNED_BYTE, |
561 pixels_shm_id, | 563 pixels_shm_id, |
562 pixels_shm_offset, | 564 pixels_shm_offset, |
563 result_shm_id, | 565 result_shm_id, |
564 result_shm_offset, | 566 result_shm_offset, |
565 false); | 567 false); |
566 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 568 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
567 | 569 |
568 GLint unpadded_row_size = emu.ComputeImageDataSize(in_read_width, 1); | 570 GLint unpadded_row_size = emu.ComputeImageDataSize(in_read_width, 1); |
569 scoped_ptr<int8[]> zero(new int8[unpadded_row_size]); | 571 scoped_ptr<int8_t[]> zero(new int8_t[unpadded_row_size]); |
570 scoped_ptr<int8[]> pack(new int8[kPackAlignment]); | 572 scoped_ptr<int8_t[]> pack(new int8_t[kPackAlignment]); |
571 memset(zero.get(), 0, unpadded_row_size); | 573 memset(zero.get(), 0, unpadded_row_size); |
572 memset(pack.get(), kInitialMemoryValue, kPackAlignment); | 574 memset(pack.get(), kInitialMemoryValue, kPackAlignment); |
573 for (GLint yy = 0; yy < in_read_height; ++yy) { | 575 for (GLint yy = 0; yy < in_read_height; ++yy) { |
574 const int8* row = static_cast<const int8*>( | 576 const int8_t* row = static_cast<const int8_t*>( |
575 emu.ComputePackAlignmentAddress(0, yy, in_read_width, dest)); | 577 emu.ComputePackAlignmentAddress(0, yy, in_read_width, dest)); |
576 GLint y = in_read_y + yy; | 578 GLint y = in_read_y + yy; |
577 if (y < 0 || y >= kHeight) { | 579 if (y < 0 || y >= kHeight) { |
578 EXPECT_EQ(0, memcmp(zero.get(), row, unpadded_row_size)); | 580 EXPECT_EQ(0, memcmp(zero.get(), row, unpadded_row_size)); |
579 } else { | 581 } else { |
580 // check off left. | 582 // check off left. |
581 GLint num_left_pixels = std::max(-in_read_x, 0); | 583 GLint num_left_pixels = std::max(-in_read_x, 0); |
582 GLint num_left_bytes = num_left_pixels * kBytesPerPixel; | 584 GLint num_left_bytes = num_left_pixels * kBytesPerPixel; |
583 EXPECT_EQ(0, memcmp(zero.get(), row, num_left_bytes)); | 585 EXPECT_EQ(0, memcmp(zero.get(), row, num_left_bytes)); |
584 | 586 |
(...skipping 24 matching lines...) Expand all Loading... |
609 } | 611 } |
610 } | 612 } |
611 } | 613 } |
612 } | 614 } |
613 | 615 |
614 TEST_P(GLES2DecoderTest, ReadPixels) { | 616 TEST_P(GLES2DecoderTest, ReadPixels) { |
615 const GLsizei kWidth = 5; | 617 const GLsizei kWidth = 5; |
616 const GLsizei kHeight = 3; | 618 const GLsizei kHeight = 3; |
617 const GLint kBytesPerPixel = 4; | 619 const GLint kBytesPerPixel = 4; |
618 const GLint kPackAlignment = 4; | 620 const GLint kPackAlignment = 4; |
619 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = { | 621 static const uint8_t kSrcPixels[kWidth * kHeight * kBytesPerPixel] = { |
620 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255, | 622 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255, |
621 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255, | 623 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255, |
622 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255, | 624 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255, |
623 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255 | 625 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255}; |
624 }; | |
625 | 626 |
626 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX)); | 627 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX)); |
627 | 628 |
628 ReadPixelsEmulator emu( | 629 ReadPixelsEmulator emu( |
629 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment); | 630 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment); |
630 typedef ReadPixels::Result Result; | 631 typedef ReadPixels::Result Result; |
631 Result* result = GetSharedMemoryAs<Result*>(); | 632 Result* result = GetSharedMemoryAs<Result*>(); |
632 uint32 result_shm_id = kSharedMemoryId; | 633 uint32_t result_shm_id = kSharedMemoryId; |
633 uint32 result_shm_offset = kSharedMemoryOffset; | 634 uint32_t result_shm_offset = kSharedMemoryOffset; |
634 uint32 pixels_shm_id = kSharedMemoryId; | 635 uint32_t pixels_shm_id = kSharedMemoryId; |
635 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); | 636 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); |
636 void* dest = &result[1]; | 637 void* dest = &result[1]; |
637 EXPECT_CALL(*gl_, GetError()) | 638 EXPECT_CALL(*gl_, GetError()) |
638 .WillOnce(Return(GL_NO_ERROR)) | 639 .WillOnce(Return(GL_NO_ERROR)) |
639 .WillOnce(Return(GL_NO_ERROR)) | 640 .WillOnce(Return(GL_NO_ERROR)) |
640 .RetiresOnSaturation(); | 641 .RetiresOnSaturation(); |
641 EXPECT_CALL(*gl_, | 642 EXPECT_CALL(*gl_, |
642 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _)) | 643 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _)) |
643 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels)); | 644 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels)); |
644 ReadPixels cmd; | 645 ReadPixels cmd; |
645 cmd.Init(0, | 646 cmd.Init(0, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd)); | 681 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd)); |
681 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 682 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
682 } | 683 } |
683 | 684 |
684 TEST_P(GLES3DecoderTest, ReadPixelsBufferBound) { | 685 TEST_P(GLES3DecoderTest, ReadPixelsBufferBound) { |
685 const GLsizei kWidth = 5; | 686 const GLsizei kWidth = 5; |
686 const GLsizei kHeight = 3; | 687 const GLsizei kHeight = 3; |
687 const GLint kBytesPerPixel = 4; | 688 const GLint kBytesPerPixel = 4; |
688 GLint size = kWidth * kHeight * kBytesPerPixel; | 689 GLint size = kWidth * kHeight * kBytesPerPixel; |
689 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); | 690 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
690 uint32 result_shm_id = kSharedMemoryId; | 691 uint32_t result_shm_id = kSharedMemoryId; |
691 uint32 result_shm_offset = kSharedMemoryOffset; | 692 uint32_t result_shm_offset = kSharedMemoryOffset; |
692 uint32 pixels_shm_id = kSharedMemoryId; | 693 uint32_t pixels_shm_id = kSharedMemoryId; |
693 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(ReadPixels::Result); | 694 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(ReadPixels::Result); |
694 | 695 |
695 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); | 696 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
696 DoBufferData(GL_PIXEL_PACK_BUFFER, size); | 697 DoBufferData(GL_PIXEL_PACK_BUFFER, size); |
697 | 698 |
698 ReadPixels cmd; | 699 ReadPixels cmd; |
699 cmd.Init(0, | 700 cmd.Init(0, |
700 0, | 701 0, |
701 kWidth, | 702 kWidth, |
702 kHeight, | 703 kHeight, |
703 GL_RGBA, | 704 GL_RGBA, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 false); | 807 false); |
807 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 808 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
808 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); | 809 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
809 } | 810 } |
810 | 811 |
811 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { | 812 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { |
812 const GLsizei kWidth = 3; | 813 const GLsizei kWidth = 3; |
813 const GLsizei kHeight = 3; | 814 const GLsizei kHeight = 3; |
814 const GLint kBytesPerPixel = 4; | 815 const GLint kBytesPerPixel = 4; |
815 const GLint kPackAlignment = 4; | 816 const GLint kPackAlignment = 4; |
816 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = { | 817 static const uint8_t kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = { |
817 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255, | 818 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255, |
818 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255, | 819 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255, |
819 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255, | 820 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255, |
820 }; | 821 }; |
821 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = { | 822 static const uint8_t kSrcPixels[kWidth * kHeight * kBytesPerPixel] = { |
822 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 29, 28, 23, 22, 21, 22, | 823 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 29, 28, 23, 22, 21, 22, |
823 21, 29, 28, 23, 22, 21, 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, | 824 21, 29, 28, 23, 22, 21, 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, |
824 }; | 825 }; |
825 | 826 |
826 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX)); | 827 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX)); |
827 | 828 |
828 ReadPixelsEmulator emu(kWidth, | 829 ReadPixelsEmulator emu(kWidth, |
829 kHeight, | 830 kHeight, |
830 kBytesPerPixel, | 831 kBytesPerPixel, |
831 kSrcPixels, | 832 kSrcPixels, |
832 kExpectedPixels, | 833 kExpectedPixels, |
833 kPackAlignment); | 834 kPackAlignment); |
834 typedef ReadPixels::Result Result; | 835 typedef ReadPixels::Result Result; |
835 Result* result = GetSharedMemoryAs<Result*>(); | 836 Result* result = GetSharedMemoryAs<Result*>(); |
836 uint32 result_shm_id = kSharedMemoryId; | 837 uint32_t result_shm_id = kSharedMemoryId; |
837 uint32 result_shm_offset = kSharedMemoryOffset; | 838 uint32_t result_shm_offset = kSharedMemoryOffset; |
838 uint32 pixels_shm_id = kSharedMemoryId; | 839 uint32_t pixels_shm_id = kSharedMemoryId; |
839 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); | 840 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); |
840 void* dest = &result[1]; | 841 void* dest = &result[1]; |
841 EXPECT_CALL(*gl_, GetError()) | 842 EXPECT_CALL(*gl_, GetError()) |
842 .WillOnce(Return(GL_NO_ERROR)) | 843 .WillOnce(Return(GL_NO_ERROR)) |
843 .WillOnce(Return(GL_NO_ERROR)) | 844 .WillOnce(Return(GL_NO_ERROR)) |
844 .RetiresOnSaturation(); | 845 .RetiresOnSaturation(); |
845 EXPECT_CALL(*gl_, | 846 EXPECT_CALL(*gl_, |
846 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _)) | 847 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _)) |
847 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels)); | 848 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels)); |
848 ReadPixels cmd; | 849 ReadPixels cmd; |
849 cmd.Init(0, | 850 cmd.Init(0, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 }; | 891 }; |
891 | 892 |
892 for (size_t tt = 0; tt < arraysize(tests); ++tt) { | 893 for (size_t tt = 0; tt < arraysize(tests); ++tt) { |
893 CheckReadPixelsOutOfRange( | 894 CheckReadPixelsOutOfRange( |
894 tests[tt][0], tests[tt][1], tests[tt][2], tests[tt][3], tt == 0); | 895 tests[tt][0], tests[tt][1], tests[tt][2], tests[tt][3], tt == 0); |
895 } | 896 } |
896 } | 897 } |
897 | 898 |
898 TEST_P(GLES2DecoderTest, ReadPixelsInvalidArgs) { | 899 TEST_P(GLES2DecoderTest, ReadPixelsInvalidArgs) { |
899 typedef ReadPixels::Result Result; | 900 typedef ReadPixels::Result Result; |
900 uint32 result_shm_id = kSharedMemoryId; | 901 uint32_t result_shm_id = kSharedMemoryId; |
901 uint32 result_shm_offset = kSharedMemoryOffset; | 902 uint32_t result_shm_offset = kSharedMemoryOffset; |
902 uint32 pixels_shm_id = kSharedMemoryId; | 903 uint32_t pixels_shm_id = kSharedMemoryId; |
903 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); | 904 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); |
904 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); | 905 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
905 ReadPixels cmd; | 906 ReadPixels cmd; |
906 cmd.Init(0, | 907 cmd.Init(0, |
907 0, | 908 0, |
908 -1, | 909 -1, |
909 1, | 910 1, |
910 GL_RGB, | 911 GL_RGB, |
911 GL_UNSIGNED_BYTE, | 912 GL_UNSIGNED_BYTE, |
912 pixels_shm_id, | 913 pixels_shm_id, |
913 pixels_shm_offset, | 914 pixels_shm_offset, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 init.gl_version = "opengl es 3.0"; | 999 init.gl_version = "opengl es 3.0"; |
999 init.has_alpha = true; | 1000 init.has_alpha = true; |
1000 init.request_alpha = true; | 1001 init.request_alpha = true; |
1001 init.bind_generates_resource = true; | 1002 init.bind_generates_resource = true; |
1002 InitDecoder(init); | 1003 InitDecoder(init); |
1003 | 1004 |
1004 typedef ReadPixels::Result Result; | 1005 typedef ReadPixels::Result Result; |
1005 | 1006 |
1006 const GLsizei kWidth = 4; | 1007 const GLsizei kWidth = 4; |
1007 const GLsizei kHeight = 4; | 1008 const GLsizei kHeight = 4; |
1008 uint32 result_shm_id = kSharedMemoryId; | 1009 uint32_t result_shm_id = kSharedMemoryId; |
1009 uint32 result_shm_offset = kSharedMemoryOffset; | 1010 uint32_t result_shm_offset = kSharedMemoryOffset; |
1010 uint32 pixels_shm_id = kSharedMemoryId; | 1011 uint32_t pixels_shm_id = kSharedMemoryId; |
1011 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); | 1012 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); |
1012 | 1013 |
1013 EXPECT_CALL(*gl_, GetError()) | 1014 EXPECT_CALL(*gl_, GetError()) |
1014 // first error check must pass to get to the test | 1015 // first error check must pass to get to the test |
1015 .WillOnce(Return(GL_NO_ERROR)) | 1016 .WillOnce(Return(GL_NO_ERROR)) |
1016 // second check is after BufferData, simulate fail here | 1017 // second check is after BufferData, simulate fail here |
1017 .WillOnce(Return(GL_INVALID_OPERATION)) | 1018 .WillOnce(Return(GL_INVALID_OPERATION)) |
1018 // third error check is fall-through call to sync ReadPixels | 1019 // third error check is fall-through call to sync ReadPixels |
1019 .WillOnce(Return(GL_NO_ERROR)) | 1020 .WillOnce(Return(GL_NO_ERROR)) |
1020 .RetiresOnSaturation(); | 1021 .RetiresOnSaturation(); |
1021 | 1022 |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 true); | 1986 true); |
1986 } | 1987 } |
1987 | 1988 |
1988 TEST_P(GLES2DecoderTest, ReadPixelsGLError) { | 1989 TEST_P(GLES2DecoderTest, ReadPixelsGLError) { |
1989 GLenum kFormat = GL_RGBA; | 1990 GLenum kFormat = GL_RGBA; |
1990 GLint x = 0; | 1991 GLint x = 0; |
1991 GLint y = 0; | 1992 GLint y = 0; |
1992 GLsizei width = 2; | 1993 GLsizei width = 2; |
1993 GLsizei height = 4; | 1994 GLsizei height = 4; |
1994 typedef ReadPixels::Result Result; | 1995 typedef ReadPixels::Result Result; |
1995 uint32 result_shm_id = kSharedMemoryId; | 1996 uint32_t result_shm_id = kSharedMemoryId; |
1996 uint32 result_shm_offset = kSharedMemoryOffset; | 1997 uint32_t result_shm_offset = kSharedMemoryOffset; |
1997 uint32 pixels_shm_id = kSharedMemoryId; | 1998 uint32_t pixels_shm_id = kSharedMemoryId; |
1998 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); | 1999 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); |
1999 EXPECT_CALL(*gl_, GetError()) | 2000 EXPECT_CALL(*gl_, GetError()) |
2000 .WillOnce(Return(GL_NO_ERROR)) | 2001 .WillOnce(Return(GL_NO_ERROR)) |
2001 .WillOnce(Return(GL_OUT_OF_MEMORY)) | 2002 .WillOnce(Return(GL_OUT_OF_MEMORY)) |
2002 .RetiresOnSaturation(); | 2003 .RetiresOnSaturation(); |
2003 EXPECT_CALL(*gl_, | 2004 EXPECT_CALL(*gl_, |
2004 ReadPixels(x, y, width, height, kFormat, GL_UNSIGNED_BYTE, _)) | 2005 ReadPixels(x, y, width, height, kFormat, GL_UNSIGNED_BYTE, _)) |
2005 .Times(1) | 2006 .Times(1) |
2006 .RetiresOnSaturation(); | 2007 .RetiresOnSaturation(); |
2007 ReadPixels cmd; | 2008 ReadPixels cmd; |
2008 cmd.Init(x, | 2009 cmd.Init(x, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 0, 0, 1, 1); | 2117 0, 0, 1, 1); |
2117 | 2118 |
2118 EXPECT_CALL(*gl_, GetError()) | 2119 EXPECT_CALL(*gl_, GetError()) |
2119 .WillOnce(Return(GL_NO_ERROR)) | 2120 .WillOnce(Return(GL_NO_ERROR)) |
2120 .WillOnce(Return(GL_NO_ERROR)) | 2121 .WillOnce(Return(GL_NO_ERROR)) |
2121 .RetiresOnSaturation(); | 2122 .RetiresOnSaturation(); |
2122 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _)) | 2123 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _)) |
2123 .Times(1) | 2124 .Times(1) |
2124 .RetiresOnSaturation(); | 2125 .RetiresOnSaturation(); |
2125 typedef ReadPixels::Result Result; | 2126 typedef ReadPixels::Result Result; |
2126 uint32 result_shm_id = kSharedMemoryId; | 2127 uint32_t result_shm_id = kSharedMemoryId; |
2127 uint32 result_shm_offset = kSharedMemoryOffset; | 2128 uint32_t result_shm_offset = kSharedMemoryOffset; |
2128 uint32 pixels_shm_id = kSharedMemoryId; | 2129 uint32_t pixels_shm_id = kSharedMemoryId; |
2129 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); | 2130 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); |
2130 ReadPixels cmd; | 2131 ReadPixels cmd; |
2131 cmd.Init(0, | 2132 cmd.Init(0, |
2132 0, | 2133 0, |
2133 1, | 2134 1, |
2134 1, | 2135 1, |
2135 GL_RGBA, | 2136 GL_RGBA, |
2136 GL_UNSIGNED_BYTE, | 2137 GL_UNSIGNED_BYTE, |
2137 pixels_shm_id, | 2138 pixels_shm_id, |
2138 pixels_shm_offset, | 2139 pixels_shm_offset, |
2139 result_shm_id, | 2140 result_shm_id, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2445 0, 0, 32, 32); | 2446 0, 0, 32, 32); |
2446 | 2447 |
2447 EXPECT_CALL(*gl_, GetError()) | 2448 EXPECT_CALL(*gl_, GetError()) |
2448 .WillOnce(Return(GL_NO_ERROR)) | 2449 .WillOnce(Return(GL_NO_ERROR)) |
2449 .WillOnce(Return(GL_NO_ERROR)) | 2450 .WillOnce(Return(GL_NO_ERROR)) |
2450 .RetiresOnSaturation(); | 2451 .RetiresOnSaturation(); |
2451 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _)) | 2452 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _)) |
2452 .Times(1) | 2453 .Times(1) |
2453 .RetiresOnSaturation(); | 2454 .RetiresOnSaturation(); |
2454 typedef ReadPixels::Result Result; | 2455 typedef ReadPixels::Result Result; |
2455 uint32 result_shm_id = kSharedMemoryId; | 2456 uint32_t result_shm_id = kSharedMemoryId; |
2456 uint32 result_shm_offset = kSharedMemoryOffset; | 2457 uint32_t result_shm_offset = kSharedMemoryOffset; |
2457 uint32 pixels_shm_id = kSharedMemoryId; | 2458 uint32_t pixels_shm_id = kSharedMemoryId; |
2458 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); | 2459 uint32_t pixels_shm_offset = kSharedMemoryOffset + sizeof(Result); |
2459 ReadPixels cmd; | 2460 ReadPixels cmd; |
2460 cmd.Init(0, | 2461 cmd.Init(0, |
2461 0, | 2462 0, |
2462 1, | 2463 1, |
2463 1, | 2464 1, |
2464 GL_RGBA, | 2465 GL_RGBA, |
2465 GL_UNSIGNED_BYTE, | 2466 GL_UNSIGNED_BYTE, |
2466 pixels_shm_id, | 2467 pixels_shm_id, |
2467 pixels_shm_offset, | 2468 pixels_shm_offset, |
2468 result_shm_id, | 2469 result_shm_id, |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3065 EXPECT_EQ(1, result->GetNumResults()); | 3066 EXPECT_EQ(1, result->GetNumResults()); |
3066 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3067 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
3067 } | 3068 } |
3068 | 3069 |
3069 // TODO(gman): PixelStorei | 3070 // TODO(gman): PixelStorei |
3070 | 3071 |
3071 // TODO(gman): SwapBuffers | 3072 // TODO(gman): SwapBuffers |
3072 | 3073 |
3073 } // namespace gles2 | 3074 } // namespace gles2 |
3074 } // namespace gpu | 3075 } // namespace gpu |
OLD | NEW |