Chromium Code Reviews

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

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 <limits> 9 #include <limits>
10 10
(...skipping 2840 matching lines...)
2851 kTarget, kLevel, kXOffset, kYOffset, kZOffset, kWidth, kHeight, kDepth, 2851 kTarget, kLevel, kXOffset, kYOffset, kZOffset, kWidth, kHeight, kDepth,
2852 kFormat, kType, pixels.get()); 2852 kFormat, kType, pixels.get());
2853 2853
2854 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 2854 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2855 uint32 offset_to_last = first_size + second_size + third_size; 2855 uint32 offset_to_last = first_size + second_size + third_size;
2856 EXPECT_TRUE(CheckRect( 2856 EXPECT_TRUE(CheckRect(
2857 kWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment, false, 2857 kWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment, false,
2858 reinterpret_cast<uint8*>(pixels.get()) + offset_to_last, mem2_2.ptr)); 2858 reinterpret_cast<uint8*>(pixels.get()) + offset_to_last, mem2_2.ptr));
2859 } 2859 }
2860 2860
2861 // Binds can not be cached with bind_generates_resource = false because
2862 // our id might not be valid. More specifically if you bind on contextA then
2863 // delete on contextB the resource is still bound on contextA but GetInterger
2864 // won't return an id.
2865 TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) {
2866 struct PNameValue {
2867 GLenum pname;
2868 GLint expected;
2869 };
2870 const PNameValue pairs[] = {{GL_TEXTURE_BINDING_2D, 1, },
2871 {GL_TEXTURE_BINDING_CUBE_MAP, 2, },
2872 {GL_TEXTURE_BINDING_EXTERNAL_OES, 3, },
2873 {GL_FRAMEBUFFER_BINDING, 4, },
2874 {GL_RENDERBUFFER_BINDING, 5, },
2875 {GL_ARRAY_BUFFER_BINDING, 6, },
2876 {GL_ELEMENT_ARRAY_BUFFER_BINDING, 7, }, };
2877 size_t num_pairs = sizeof(pairs) / sizeof(pairs[0]);
2878 for (size_t ii = 0; ii < num_pairs; ++ii) {
2879 const PNameValue& pv = pairs[ii];
2880 GLint v = -1;
2881 ExpectedMemoryInfo result1 =
2882 GetExpectedResultMemory(sizeof(cmds::GetIntegerv::Result));
2883 EXPECT_CALL(*command_buffer(), OnFlush())
2884 .WillOnce(SetMemory(result1.ptr,
2885 SizedResultHelper<GLuint>(pv.expected)))
2886 .RetiresOnSaturation();
2887 gl_->GetIntegerv(pv.pname, &v);
2888 EXPECT_EQ(pv.expected, v);
2889 }
2890 }
2891
2892 // glGen* Ids must not be reused until glDelete* commands have been 2861 // glGen* Ids must not be reused until glDelete* commands have been
2893 // flushed by glFlush. 2862 // flushed by glFlush.
2894 TEST_F(GLES2ImplementationStrictSharedTest, FlushGenerationTestBuffers) { 2863 TEST_F(GLES2ImplementationStrictSharedTest, FlushGenerationTestBuffers) {
2895 FlushGenerationTest<GenBuffersAPI>(); 2864 FlushGenerationTest<GenBuffersAPI>();
2896 } 2865 }
2897 TEST_F(GLES2ImplementationStrictSharedTest, FlushGenerationTestFramebuffers) { 2866 TEST_F(GLES2ImplementationStrictSharedTest, FlushGenerationTestFramebuffers) {
2898 FlushGenerationTest<GenFramebuffersAPI>(); 2867 FlushGenerationTest<GenFramebuffersAPI>();
2899 } 2868 }
2900 TEST_F(GLES2ImplementationStrictSharedTest, FlushGenerationTestRenderbuffers) { 2869 TEST_F(GLES2ImplementationStrictSharedTest, FlushGenerationTestRenderbuffers) {
2901 FlushGenerationTest<GenRenderbuffersAPI>(); 2870 FlushGenerationTest<GenRenderbuffersAPI>();
(...skipping 722 matching lines...)
3624 Cmds expected; 3593 Cmds expected;
3625 const GLuint64 kTimeout = GL_TIMEOUT_IGNORED; 3594 const GLuint64 kTimeout = GL_TIMEOUT_IGNORED;
3626 uint32_t v32_0 = 0, v32_1 = 0; 3595 uint32_t v32_0 = 0, v32_1 = 0;
3627 GLES2Util::MapUint64ToTwoUint32(kTimeout, &v32_0, &v32_1); 3596 GLES2Util::MapUint64ToTwoUint32(kTimeout, &v32_0, &v32_1);
3628 expected.cmd.Init(kClientSyncId, 0, v32_0, v32_1); 3597 expected.cmd.Init(kClientSyncId, 0, v32_0, v32_1);
3629 3598
3630 gl_->WaitSync(reinterpret_cast<GLsync>(kClientSyncId), 0, kTimeout); 3599 gl_->WaitSync(reinterpret_cast<GLsync>(kClientSyncId), 0, kTimeout);
3631 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 3600 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
3632 } 3601 }
3633 3602
3603 TEST_F(GLES2ImplementationTest, MapBufferRangeUnmapBufferWrite) {
3604 ExpectedMemoryInfo result =
3605 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3606
3607 EXPECT_CALL(*command_buffer(), OnFlush())
3608 .WillOnce(SetMemory(result.ptr, uint32_t(1)))
3609 .RetiresOnSaturation();
3610
3611 const GLuint kBufferId = 123;
3612 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3613
3614 void* mem = gl_->MapBufferRange(GL_ARRAY_BUFFER, 10, 64, GL_MAP_WRITE_BIT);
3615 EXPECT_TRUE(mem != nullptr);
3616
3617 EXPECT_TRUE(gl_->UnmapBuffer(GL_ARRAY_BUFFER));
3618 }
3619
3620 TEST_F(GLES2ImplementationTest, MapBufferRangeWriteWithInvalidateBit) {
3621 ExpectedMemoryInfo result =
3622 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3623
3624 EXPECT_CALL(*command_buffer(), OnFlush())
3625 .WillOnce(SetMemory(result.ptr, uint32_t(1)))
3626 .RetiresOnSaturation();
3627
3628 const GLuint kBufferId = 123;
3629 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3630
3631 GLsizeiptr kSize = 64;
3632 void* mem = gl_->MapBufferRange(
3633 GL_ARRAY_BUFFER, 10, kSize,
3634 GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT);
3635 EXPECT_TRUE(mem != nullptr);
3636 std::vector<int8_t> zero(kSize);
3637 memset(&zero[0], 0, kSize);
3638 EXPECT_EQ(0, memcmp(mem, &zero[0], kSize));
3639 }
3640
3641 TEST_F(GLES2ImplementationTest, MapBufferRangeWriteWithGLError) {
3642 ExpectedMemoryInfo result =
3643 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3644
3645 // Return a result of 0 to indicate an GL error.
3646 EXPECT_CALL(*command_buffer(), OnFlush())
3647 .WillOnce(SetMemory(result.ptr, uint32_t(0)))
3648 .RetiresOnSaturation();
3649
3650 const GLuint kBufferId = 123;
3651 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3652
3653 void* mem = gl_->MapBufferRange(GL_ARRAY_BUFFER, 10, 64, GL_MAP_WRITE_BIT);
3654 EXPECT_TRUE(mem == nullptr);
3655 }
3656
3657 TEST_F(GLES2ImplementationTest, MapBufferRangeUnmapBufferRead) {
3658 ExpectedMemoryInfo result =
3659 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3660
3661 EXPECT_CALL(*command_buffer(), OnFlush())
3662 .WillOnce(SetMemory(result.ptr, uint32_t(1)))
3663 .RetiresOnSaturation();
3664
3665 const GLuint kBufferId = 123;
3666 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3667
3668 void* mem = gl_->MapBufferRange(GL_ARRAY_BUFFER, 10, 64, GL_MAP_READ_BIT);
3669 EXPECT_TRUE(mem != nullptr);
3670
3671 EXPECT_TRUE(gl_->UnmapBuffer(GL_ARRAY_BUFFER));
3672 }
3673
3674 TEST_F(GLES2ImplementationTest, MapBufferRangeReadWithGLError) {
3675 ExpectedMemoryInfo result =
3676 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3677
3678 // Return a result of 0 to indicate an GL error.
3679 EXPECT_CALL(*command_buffer(), OnFlush())
3680 .WillOnce(SetMemory(result.ptr, uint32_t(0)))
3681 .RetiresOnSaturation();
3682
3683 const GLuint kBufferId = 123;
3684 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3685
3686 void* mem = gl_->MapBufferRange(GL_ARRAY_BUFFER, 10, 64, GL_MAP_READ_BIT);
3687 EXPECT_TRUE(mem == nullptr);
3688 }
3689
3690 TEST_F(GLES2ImplementationTest, UnmapBufferFails) {
3691 // No bound buffer.
3692 EXPECT_FALSE(gl_->UnmapBuffer(GL_ARRAY_BUFFER));
3693 EXPECT_EQ(GL_INVALID_OPERATION, CheckError());
3694
3695 const GLuint kBufferId = 123;
3696 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3697
3698 // Buffer is unmapped.
3699 EXPECT_FALSE(gl_->UnmapBuffer(GL_ARRAY_BUFFER));
3700 EXPECT_EQ(GL_INVALID_OPERATION, CheckError());
3701 }
3702
3703 TEST_F(GLES2ImplementationTest, BufferDataUnmapsDataStore) {
3704 ExpectedMemoryInfo result =
3705 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3706
3707 EXPECT_CALL(*command_buffer(), OnFlush())
3708 .WillOnce(SetMemory(result.ptr, uint32_t(1)))
3709 .RetiresOnSaturation();
3710
3711 const GLuint kBufferId = 123;
3712 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3713
3714 void* mem = gl_->MapBufferRange(GL_ARRAY_BUFFER, 10, 64, GL_MAP_WRITE_BIT);
3715 EXPECT_TRUE(mem != nullptr);
3716
3717 std::vector<uint8_t> data(16);
3718 // BufferData unmaps the data store.
3719 gl_->BufferData(GL_ARRAY_BUFFER, 16, &data[0], GL_STREAM_DRAW);
3720
3721 EXPECT_FALSE(gl_->UnmapBuffer(GL_ARRAY_BUFFER));
3722 EXPECT_EQ(GL_INVALID_OPERATION, CheckError());
3723 }
3724
3725 TEST_F(GLES2ImplementationTest, DeleteBuffersUnmapsDataStore) {
3726 ExpectedMemoryInfo result =
3727 GetExpectedResultMemory(sizeof(cmds::MapBufferRange::Result));
3728
3729 EXPECT_CALL(*command_buffer(), OnFlush())
3730 .WillOnce(SetMemory(result.ptr, uint32_t(1)))
3731 .RetiresOnSaturation();
3732
3733 const GLuint kBufferId = 123;
3734 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
3735
3736 void* mem = gl_->MapBufferRange(GL_ARRAY_BUFFER, 10, 64, GL_MAP_WRITE_BIT);
3737 EXPECT_TRUE(mem != nullptr);
3738
3739 std::vector<uint8_t> data(16);
3740 // DeleteBuffers unmaps the data store.
3741 gl_->DeleteBuffers(1, &kBufferId);
3742
3743 EXPECT_FALSE(gl_->UnmapBuffer(GL_ARRAY_BUFFER));
3744 EXPECT_EQ(GL_INVALID_OPERATION, CheckError());
3745 }
3746
3634 TEST_F(GLES2ImplementationManualInitTest, LoseContextOnOOM) { 3747 TEST_F(GLES2ImplementationManualInitTest, LoseContextOnOOM) {
3635 ContextInitOptions init_options; 3748 ContextInitOptions init_options;
3636 init_options.lose_context_when_out_of_memory = true; 3749 init_options.lose_context_when_out_of_memory = true;
3637 ASSERT_TRUE(Initialize(init_options)); 3750 ASSERT_TRUE(Initialize(init_options));
3638 3751
3639 struct Cmds { 3752 struct Cmds {
3640 cmds::LoseContextCHROMIUM cmd; 3753 cmds::LoseContextCHROMIUM cmd;
3641 }; 3754 };
3642 3755
3643 GLsizei max = std::numeric_limits<GLsizei>::max(); 3756 GLsizei max = std::numeric_limits<GLsizei>::max();
(...skipping 39 matching lines...)
3683 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { 3796 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) {
3684 ContextInitOptions init_options; 3797 ContextInitOptions init_options;
3685 init_options.transfer_buffer_initialize_fail = true; 3798 init_options.transfer_buffer_initialize_fail = true;
3686 EXPECT_FALSE(Initialize(init_options)); 3799 EXPECT_FALSE(Initialize(init_options));
3687 } 3800 }
3688 3801
3689 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 3802 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
3690 3803
3691 } // namespace gles2 3804 } // namespace gles2
3692 } // namespace gpu 3805 } // namespace gpu
OLDNEW

Powered by Google App Engine