OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "cc/resources/single_release_callback.h" |
| 7 #include "components/exo/buffer.h" |
| 8 #include "components/exo/surface.h" |
| 9 #include "components/exo/test/exo_test_base.h" |
| 10 #include "components/exo/test/exo_test_helper.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/khronos/GLES2/gl2.h" |
| 13 #include "ui/gfx/gpu_memory_buffer.h" |
| 14 |
| 15 namespace exo { |
| 16 namespace { |
| 17 |
| 18 using BufferTest = test::ExoTestBase; |
| 19 |
| 20 void Release(int* release_call_count) { |
| 21 (*release_call_count)++; |
| 22 } |
| 23 |
| 24 TEST_F(BufferTest, ReleaseCallback) { |
| 25 gfx::Size buffer_size(256, 256); |
| 26 scoped_ptr<Buffer> buffer( |
| 27 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(), |
| 28 GL_TEXTURE_2D)); |
| 29 |
| 30 // Set the release callback. |
| 31 int release_call_count = 0; |
| 32 buffer->set_release_callback( |
| 33 base::Bind(&Release, base::Unretained(&release_call_count))); |
| 34 |
| 35 // Acquire a texture mailbox for the contents of the buffer. |
| 36 cc::TextureMailbox texture_mailbox; |
| 37 scoped_ptr<cc::SingleReleaseCallback> buffer_release_callback = |
| 38 buffer->AcquireTextureMailbox(&texture_mailbox); |
| 39 ASSERT_TRUE(buffer_release_callback); |
| 40 |
| 41 // Trying to acquire an already in-use buffer should fail. |
| 42 EXPECT_FALSE(buffer->AcquireTextureMailbox(&texture_mailbox)); |
| 43 |
| 44 // Release buffer. |
| 45 buffer_release_callback->Run(gpu::SyncToken(), false); |
| 46 |
| 47 // Release() should have been called exactly once. |
| 48 ASSERT_EQ(release_call_count, 1); |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 } // namespace exo |
OLD | NEW |