| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/gl2chromium.h> | 6 #include <GLES2/gl2chromium.h> |
| 7 #include <GLES2/gl2ext.h> | 7 #include <GLES2/gl2ext.h> |
| 8 #include <GLES2/gl2extchromium.h> | 8 #include <GLES2/gl2extchromium.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 15 #include "gpu/command_buffer/client/gles2_implementation.h" | 15 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 16 #include "gpu/command_buffer/service/command_buffer_service.h" | 16 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 17 #include "gpu/command_buffer/service/fence_manager.h" | 17 #include "gpu/command_buffer/service/fence_manager.h" |
| 18 #include "gpu/command_buffer/tests/gl_manager.h" | 18 #include "gpu/command_buffer/tests/gl_manager.h" |
| 19 #include "gpu/command_buffer/tests/gl_test_utils.h" | 19 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "ui/gfx/gpu_fence.h" | 22 #include "ui/gfx/gpu_fence.h" |
| 23 #include "ui/gfx/gpu_memory_buffer.h" |
| 23 #include "ui/gl/gl_fence.h" | 24 #include "ui/gl/gl_fence.h" |
| 25 #include "ui/gl/gl_image.h" |
| 24 | 26 |
| 25 using testing::_; | 27 using testing::_; |
| 26 using testing::IgnoreResult; | 28 using testing::IgnoreResult; |
| 27 using testing::InvokeWithoutArgs; | 29 using testing::InvokeWithoutArgs; |
| 28 using testing::Invoke; | 30 using testing::Invoke; |
| 29 using testing::Return; | 31 using testing::Return; |
| 30 using testing::SetArgPointee; | 32 using testing::SetArgPointee; |
| 31 using testing::StrictMock; | 33 using testing::StrictMock; |
| 32 | 34 |
| 33 namespace gpu { | 35 namespace gpu { |
| 34 namespace gles2 { | 36 namespace gles2 { |
| 35 | 37 |
| 36 class GpuFenceTest : public testing::Test { | 38 class GpuFenceTest : public testing::Test { |
| 37 protected: | 39 protected: |
| 38 void SetUp() override { gl_.Initialize(GLManager::Options()); } | 40 void SetUp() override { gl_.Initialize(GLManager::Options()); } |
| 39 void TearDown() override { gl_.Destroy(); } | 41 void TearDown() override { gl_.Destroy(); } |
| 40 | 42 |
| 41 GLManager gl_; | 43 GLManager gl_; |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 // An end to end test that tests the whole GpuFence lifecycle. | 46 // An end to end test that tests the whole GpuFence lifecycle. |
| 45 TEST_F(GpuFenceTest, Lifecycle) { | 47 TEST_F(GpuFenceTest, Lifecycle) { |
| 46 // Create the gpu fence. | 48 // Create the gpu fence. |
| 47 std::unique_ptr<gfx::GpuFence> fence(gl_.CreateGpuFence()); | 49 std::unique_ptr<gfx::GpuFence> fence(gl_.CreateGpuFence()); |
| 48 | 50 |
| 49 // Check fence. | |
| 50 bool rv = fence->Wait(base::TimeDelta()); | |
| 51 DCHECK(!rv); | |
| 52 | |
| 53 // Create the GL fence. This should add the fence ID to the FenceManager. | 51 // Create the GL fence. This should add the fence ID to the FenceManager. |
| 54 GLuint fence_id = glCreateFenceCHROMIUM(fence->AsClientFence()); | 52 GLuint fence_id = glCreateFenceCHROMIUM(fence->AsClientFence()); |
| 55 ASSERT_NE(0u, fence_id); | 53 ASSERT_NE(0u, fence_id); |
| 56 ASSERT_TRUE(gl_.decoder()->GetFenceManager()->LookupFence(fence_id) != NULL); | 54 ASSERT_TRUE(gl_.decoder()->GetFenceManager()->LookupFence(fence_id) != NULL); |
| 57 | 55 |
| 58 // Wait for 1us on fence. | 56 // Create a gpu memory buffer. |
| 59 rv = fence->Wait(base::TimeDelta::FromMicroseconds(1)); | 57 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
| 58 gl_.CreateGpuMemoryBuffer(gfx::Size(4, 4), gfx::BufferFormat::RGBA_8888)); |
| 59 |
| 60 // Create an image. |
| 61 GLuint image_id = |
| 62 glCreateImageCHROMIUM(buffer->AsClientBuffer(), 4, 4, GL_RGBA); |
| 63 ASSERT_NE(0u, image_id); |
| 64 |
| 65 // Create a texture. |
| 66 GLuint texture_id = 0; |
| 67 glGenTextures(1, &texture_id); |
| 68 ASSERT_NE(0u, texture_id); |
| 69 glBindTexture(GL_TEXTURE_2D, texture_id); |
| 70 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 71 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 74 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 75 nullptr); |
| 76 |
| 77 // Check fence. |
| 78 bool rv = fence->IsSignaled(); |
| 79 DCHECK(!rv); |
| 80 |
| 81 // Copy image to texture and signal fence when copy has completed. |
| 82 glCopyImageSubDataCHROMIUM(image_id, texture_id, 0, 0, 0, 0, 4, 4, 0, |
| 83 fence_id); |
| 84 |
| 85 // Wait for 1s on fence. |
| 86 rv = fence->Wait(base::TimeDelta::FromSeconds(1)); |
| 60 DCHECK(!rv); | 87 DCHECK(!rv); |
| 61 | 88 |
| 62 // Clean up. | 89 // Clean up. |
| 90 glDeleteTextures(1, &texture_id); |
| 91 glDestroyImageCHROMIUM(image_id); |
| 63 glDestroyFenceCHROMIUM(fence_id); | 92 glDestroyFenceCHROMIUM(fence_id); |
| 64 } | 93 } |
| 65 | 94 |
| 66 } // namespace gles2 | 95 } // namespace gles2 |
| 67 } // namespace gpu | 96 } // namespace gpu |
| OLD | NEW |