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> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
14 #include "gpu/command_buffer/common/id_allocator.h" | 14 #include "gpu/command_buffer/common/id_allocator.h" |
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 15 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
16 #include "gpu/command_buffer/service/context_group.h" | 16 #include "gpu/command_buffer/service/context_group.h" |
17 #include "gpu/command_buffer/service/context_state.h" | 17 #include "gpu/command_buffer/service/context_state.h" |
18 #include "gpu/command_buffer/service/gl_surface_mock.h" | 18 #include "gpu/command_buffer/service/gl_surface_mock.h" |
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" | 19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" |
20 #include "gpu/command_buffer/service/image_manager.h" | 20 #include "gpu/command_buffer/service/image_manager.h" |
21 #include "gpu/command_buffer/service/mailbox_manager.h" | 21 #include "gpu/command_buffer/service/mailbox_manager.h" |
22 #include "gpu/command_buffer/service/mocks.h" | 22 #include "gpu/command_buffer/service/mocks.h" |
23 #include "gpu/command_buffer/service/program_manager.h" | 23 #include "gpu/command_buffer/service/program_manager.h" |
| 24 #include "gpu/command_buffer/service/service_discardable_manager.h" |
24 #include "gpu/command_buffer/service/test_helper.h" | 25 #include "gpu/command_buffer/service/test_helper.h" |
25 #include "gpu/config/gpu_switches.h" | 26 #include "gpu/config/gpu_switches.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/gl/gl_image_stub.h" | 28 #include "ui/gl/gl_image_stub.h" |
28 #include "ui/gl/gl_implementation.h" | 29 #include "ui/gl/gl_implementation.h" |
29 #include "ui/gl/gl_mock.h" | 30 #include "ui/gl/gl_mock.h" |
30 #include "ui/gl/gl_surface_stub.h" | 31 #include "ui/gl/gl_surface_stub.h" |
31 | 32 |
32 #if !defined(GL_DEPTH24_STENCIL8) | 33 #if !defined(GL_DEPTH24_STENCIL8) |
33 #define GL_DEPTH24_STENCIL8 0x88F0 | 34 #define GL_DEPTH24_STENCIL8 0x88F0 |
34 #endif | 35 #endif |
35 | 36 |
36 using ::gl::MockGLInterface; | 37 using ::gl::MockGLInterface; |
37 using ::testing::_; | 38 using ::testing::_; |
| 39 using ::testing::AnyNumber; |
38 using ::testing::DoAll; | 40 using ::testing::DoAll; |
39 using ::testing::InSequence; | 41 using ::testing::InSequence; |
40 using ::testing::Invoke; | 42 using ::testing::Invoke; |
41 using ::testing::MatcherCast; | 43 using ::testing::MatcherCast; |
42 using ::testing::Mock; | 44 using ::testing::Mock; |
43 using ::testing::Pointee; | 45 using ::testing::Pointee; |
44 using ::testing::Return; | 46 using ::testing::Return; |
45 using ::testing::SaveArg; | 47 using ::testing::SaveArg; |
46 using ::testing::SetArrayArgument; | 48 using ::testing::SetArrayArgument; |
47 using ::testing::SetArgPointee; | 49 using ::testing::SetArgPointee; |
(...skipping 4804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4852 typedef GetTexParameteriv::Result Result; | 4854 typedef GetTexParameteriv::Result Result; |
4853 Result* result = static_cast<Result*>(shared_memory_address_); | 4855 Result* result = static_cast<Result*>(shared_memory_address_); |
4854 result->size = 0; | 4856 result->size = 0; |
4855 GetTexParameteriv cmd; | 4857 GetTexParameteriv cmd; |
4856 cmd.Init(kTarget, kSwizzleParam, shared_memory_id_, shared_memory_offset_); | 4858 cmd.Init(kTarget, kSwizzleParam, shared_memory_id_, shared_memory_offset_); |
4857 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 4859 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
4858 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); | 4860 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); |
4859 } | 4861 } |
4860 } | 4862 } |
4861 | 4863 |
| 4864 TEST_P(GLES2DecoderTest, TestInitDiscardableTexture) { |
| 4865 EXPECT_EQ(0u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4866 DoInitializeDiscardableTextureCHROMIUM(client_texture_id_); |
| 4867 EXPECT_EQ(1u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4868 } |
| 4869 |
| 4870 TEST_P(GLES2DecoderTest, TestInitInvalidDiscardableTexture) { |
| 4871 EXPECT_EQ(0u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4872 DoInitializeDiscardableTextureCHROMIUM(0); |
| 4873 EXPECT_EQ(0u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4874 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); |
| 4875 } |
| 4876 |
| 4877 TEST_P(GLES2DecoderTest, TestUnlockDiscardableTexture) { |
| 4878 const ContextGroup& context_group = group(); |
| 4879 EXPECT_EQ(0u, |
| 4880 context_group.discardable_manager()->NumCacheEntriesForTesting()); |
| 4881 DoInitializeDiscardableTextureCHROMIUM(client_texture_id_); |
| 4882 EXPECT_TRUE(context_group.discardable_manager()->IsEntryLockedForTesting( |
| 4883 client_texture_id_, context_group.texture_manager())); |
| 4884 DoUnlockDiscardableTextureCHROMIUM(client_texture_id_); |
| 4885 EXPECT_FALSE(context_group.discardable_manager()->IsEntryLockedForTesting( |
| 4886 client_texture_id_, context_group.texture_manager())); |
| 4887 } |
| 4888 |
| 4889 TEST_P(GLES2DecoderTest, TestDeleteDiscardableTexture) { |
| 4890 EXPECT_EQ(0u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4891 DoInitializeDiscardableTextureCHROMIUM(client_texture_id_); |
| 4892 EXPECT_EQ(1u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4893 DoDeleteTexture(client_texture_id_, kServiceTextureId); |
| 4894 EXPECT_EQ(0u, group().discardable_manager()->NumCacheEntriesForTesting()); |
| 4895 } |
| 4896 |
| 4897 TEST_P(GLES2DecoderManualInitTest, |
| 4898 TestDiscardableTextureUnusableWhileUnlocked) { |
| 4899 base::CommandLine command_line(0, NULL); |
| 4900 InitState init; |
| 4901 init.bind_generates_resource = false; |
| 4902 InitDecoderWithCommandLine(init, &command_line); |
| 4903 |
| 4904 DoInitializeDiscardableTextureCHROMIUM(client_texture_id_); |
| 4905 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 4906 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4907 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)).RetiresOnSaturation(); |
| 4908 DoUnlockDiscardableTextureCHROMIUM(client_texture_id_); |
| 4909 { |
| 4910 // Avoid DoBindTexture, as we expect failure. |
| 4911 cmds::BindTexture cmd; |
| 4912 cmd.Init(GL_TEXTURE_2D, client_texture_id_); |
| 4913 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 4914 } |
| 4915 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 4916 DoLockDiscardableTextureCHROMIUM(client_texture_id_); |
| 4917 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 4918 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4919 } |
| 4920 |
| 4921 TEST_P(GLES2DecoderTest, TestDiscardableTextureBindGeneratesUnlocked) { |
| 4922 DoInitializeDiscardableTextureCHROMIUM(client_texture_id_); |
| 4923 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 4924 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4925 // Unlock will unbind the texture. |
| 4926 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)).RetiresOnSaturation(); |
| 4927 DoUnlockDiscardableTextureCHROMIUM(client_texture_id_); |
| 4928 |
| 4929 // At this point, the texture is unlocked and unusable. Bind will generate a |
| 4930 // new resource. |
| 4931 EXPECT_CALL(*gl_, GenTextures(_, _)) |
| 4932 .WillOnce(SetArgPointee<1>(kNewServiceId)) |
| 4933 .RetiresOnSaturation(); |
| 4934 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kNewServiceId); |
| 4935 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4936 |
| 4937 // Re-locking should delete the previous resource (preserving the generated |
| 4938 // one). |
| 4939 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(kServiceTextureId))) |
| 4940 .RetiresOnSaturation(); |
| 4941 DoLockDiscardableTextureCHROMIUM(client_texture_id_); |
| 4942 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kNewServiceId); |
| 4943 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4944 } |
| 4945 |
4862 // TODO(gman): Complete this test. | 4946 // TODO(gman): Complete this test. |
4863 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) { | 4947 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) { |
4864 // } | 4948 // } |
4865 | 4949 |
4866 // TODO(gman): CompressedTexImage2D | 4950 // TODO(gman): CompressedTexImage2D |
4867 | 4951 |
4868 // TODO(gman): CompressedTexImage2DImmediate | 4952 // TODO(gman): CompressedTexImage2DImmediate |
4869 | 4953 |
4870 // TODO(gman): CompressedTexSubImage2DImmediate | 4954 // TODO(gman): CompressedTexSubImage2DImmediate |
4871 | 4955 |
4872 // TODO(gman): TexImage2D | 4956 // TODO(gman): TexImage2D |
4873 | 4957 |
4874 // TODO(gman): TexImage2DImmediate | 4958 // TODO(gman): TexImage2DImmediate |
4875 | 4959 |
4876 // TODO(gman): TexSubImage2DImmediate | 4960 // TODO(gman): TexSubImage2DImmediate |
4877 | 4961 |
4878 } // namespace gles2 | 4962 } // namespace gles2 |
4879 } // namespace gpu | 4963 } // namespace gpu |
OLD | NEW |