| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/gl2extchromium.h> |
| 6 |
| 5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "cc/output/context_provider.h" |
| 6 #include "cc/resources/single_release_callback.h" | 9 #include "cc/resources/single_release_callback.h" |
| 7 #include "components/exo/buffer.h" | 10 #include "components/exo/buffer.h" |
| 8 #include "components/exo/surface.h" | 11 #include "components/exo/surface.h" |
| 9 #include "components/exo/test/exo_test_base.h" | 12 #include "components/exo/test/exo_test_base.h" |
| 10 #include "components/exo/test/exo_test_helper.h" | 13 #include "components/exo/test/exo_test_helper.h" |
| 14 #include "gpu/command_buffer/client/gles2_interface.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/khronos/GLES2/gl2.h" | 16 #include "third_party/khronos/GLES2/gl2.h" |
| 17 #include "ui/aura/env.h" |
| 18 #include "ui/compositor/compositor.h" |
| 13 #include "ui/gfx/gpu_memory_buffer.h" | 19 #include "ui/gfx/gpu_memory_buffer.h" |
| 14 | 20 |
| 15 namespace exo { | 21 namespace exo { |
| 16 namespace { | 22 namespace { |
| 17 | 23 |
| 18 using BufferTest = test::ExoTestBase; | 24 using BufferTest = test::ExoTestBase; |
| 19 | 25 |
| 20 void Release(int* release_call_count) { | 26 void Release(int* release_call_count) { |
| 21 (*release_call_count)++; | 27 (*release_call_count)++; |
| 22 } | 28 } |
| 23 | 29 |
| 24 TEST_F(BufferTest, ReleaseCallback) { | 30 TEST_F(BufferTest, ReleaseCallback) { |
| 25 gfx::Size buffer_size(256, 256); | 31 gfx::Size buffer_size(256, 256); |
| 26 scoped_ptr<Buffer> buffer( | 32 scoped_ptr<Buffer> buffer( |
| 27 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(), | 33 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(), |
| 28 GL_TEXTURE_2D)); | 34 GL_TEXTURE_2D)); |
| 29 | 35 |
| 30 // Set the release callback. | 36 // Set the release callback. |
| 31 int release_call_count = 0; | 37 int release_call_count = 0; |
| 32 buffer->set_release_callback( | 38 buffer->set_release_callback( |
| 33 base::Bind(&Release, base::Unretained(&release_call_count))); | 39 base::Bind(&Release, base::Unretained(&release_call_count))); |
| 34 | 40 |
| 35 // Acquire a texture mailbox for the contents of the buffer. | 41 // Produce a texture mailbox for the contents of the buffer. |
| 36 cc::TextureMailbox texture_mailbox; | 42 cc::TextureMailbox texture_mailbox; |
| 37 scoped_ptr<cc::SingleReleaseCallback> buffer_release_callback = | 43 scoped_ptr<cc::SingleReleaseCallback> buffer_release_callback = |
| 38 buffer->AcquireTextureMailbox(&texture_mailbox); | 44 buffer->ProduceTextureMailbox(&texture_mailbox); |
| 39 ASSERT_TRUE(buffer_release_callback); | 45 ASSERT_TRUE(buffer_release_callback); |
| 40 | 46 |
| 41 // Trying to acquire an already in-use buffer should fail. | |
| 42 EXPECT_FALSE(buffer->AcquireTextureMailbox(&texture_mailbox)); | |
| 43 | |
| 44 // Release buffer. | 47 // Release buffer. |
| 45 buffer_release_callback->Run(gpu::SyncToken(), false); | 48 buffer_release_callback->Run(gpu::SyncToken(), false); |
| 46 | 49 |
| 47 // Release() should have been called exactly once. | 50 // Release() should have been called exactly once. |
| 48 ASSERT_EQ(release_call_count, 1); | 51 ASSERT_EQ(release_call_count, 1); |
| 49 } | 52 } |
| 50 | 53 |
| 54 TEST_F(BufferTest, IsLost) { |
| 55 gfx::Size buffer_size(256, 256); |
| 56 scoped_ptr<Buffer> buffer( |
| 57 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(), |
| 58 GL_TEXTURE_2D)); |
| 59 |
| 60 // Acquire a texture mailbox for the contents of the buffer. |
| 61 cc::TextureMailbox texture_mailbox; |
| 62 scoped_ptr<cc::SingleReleaseCallback> buffer_release_callback = |
| 63 buffer->ProduceTextureMailbox(&texture_mailbox); |
| 64 ASSERT_TRUE(buffer_release_callback); |
| 65 |
| 66 scoped_refptr<cc::ContextProvider> context_provider = |
| 67 aura::Env::GetInstance() |
| 68 ->context_factory() |
| 69 ->SharedMainThreadContextProvider(); |
| 70 if (context_provider) { |
| 71 gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL(); |
| 72 gles2->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 73 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 74 } |
| 75 |
| 76 // Release buffer. |
| 77 bool is_lost = true; |
| 78 buffer_release_callback->Run(gpu::SyncToken(), is_lost); |
| 79 |
| 80 // Producing a new texture mailbox for the contents of the buffer. |
| 81 buffer_release_callback = buffer->ProduceTextureMailbox(&texture_mailbox); |
| 82 ASSERT_TRUE(buffer_release_callback); |
| 83 |
| 84 // Release buffer. |
| 85 buffer_release_callback->Run(gpu::SyncToken(), false); |
| 86 } |
| 87 |
| 51 } // namespace | 88 } // namespace |
| 52 } // namespace exo | 89 } // namespace exo |
| OLD | NEW |