Chromium Code Reviews| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "cc/output/compositor_frame.h" | 6 #include "cc/output/compositor_frame.h" |
| 7 #include "cc/quads/texture_draw_quad.h" | 7 #include "cc/quads/texture_draw_quad.h" |
| 8 #include "cc/surfaces/surface.h" | 8 #include "cc/surfaces/surface.h" |
| 9 #include "cc/surfaces/surface_manager.h" | 9 #include "cc/surfaces/surface_manager.h" |
| 10 #include "components/exo/buffer.h" | 10 #include "components/exo/buffer.h" |
| 11 #include "components/exo/surface.h" | 11 #include "components/exo/surface.h" |
| 12 #include "components/exo/test/exo_test_base.h" | 12 #include "components/exo/test/exo_test_base.h" |
| 13 #include "components/exo/test/exo_test_helper.h" | 13 #include "components/exo/test/exo_test_helper.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 16 #include "ui/compositor/layer_tree_owner.h" | 16 #include "ui/compositor/layer_tree_owner.h" |
| 17 #include "ui/gfx/gpu_memory_buffer.h" | 17 #include "ui/gfx/gpu_memory_buffer.h" |
| 18 #include "ui/wm/core/window_util.h" | 18 #include "ui/wm/core/window_util.h" |
| 19 | 19 |
| 20 namespace exo { | 20 namespace exo { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 using SurfaceTest = test::ExoTestBase; | 23 using SurfaceTest = test::ExoTestBase; |
| 24 | 24 |
| 25 void ReleaseBuffer(int* release_buffer_call_count) { | 25 void ReleaseBuffer(int* release_buffer_call_count) { |
| 26 (*release_buffer_call_count)++; | 26 (*release_buffer_call_count)++; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // SurafaceTest.Attach is failing | |
| 29 TEST_F(SurfaceTest, Attach) { | 30 TEST_F(SurfaceTest, Attach) { |
| 30 gfx::Size buffer_size(256, 256); | 31 gfx::Size buffer_size(256, 256); |
| 31 std::unique_ptr<Buffer> buffer( | 32 std::unique_ptr<Buffer> buffer( |
| 32 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); | 33 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| 33 | 34 |
| 34 // Set the release callback that will be run when buffer is no longer in use. | 35 // Set the release callback that will be run when buffer is no longer in use. |
| 35 int release_buffer_call_count = 0; | 36 int release_buffer_call_count = 0; |
| 36 buffer->set_release_callback( | 37 buffer->set_release_callback( |
| 37 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count))); | 38 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count))); |
| 38 | 39 |
| 39 std::unique_ptr<Surface> surface(new Surface); | 40 std::unique_ptr<Surface> surface(new Surface); |
| 40 | 41 |
| 41 // Attach the buffer to surface1. | 42 // Attach the buffer to surface1. |
| 42 surface->Attach(buffer.get()); | 43 surface->Attach(buffer.get()); |
| 43 surface->Commit(); | 44 surface->Commit(); |
| 44 | 45 |
| 45 // Commit without calling Attach() should have no effect. | 46 // Commit without calling Attach() should have no effect. |
| 46 surface->Commit(); | 47 surface->Commit(); |
| 47 EXPECT_EQ(0, release_buffer_call_count); | 48 EXPECT_EQ(0, release_buffer_call_count); |
| 48 | 49 |
| 49 // Attach a null buffer to surface, this should release the previously | 50 // Attach a null buffer to surface, this should release the previously |
| 50 // attached buffer. | 51 // attached buffer. |
| 51 surface->Attach(nullptr); | 52 surface->Attach(nullptr); |
| 52 surface->Commit(); | 53 surface->Commit(); |
| 54 RunAllPendingInMessageLoop(); | |
|
Fady Samuel
2016/11/30 16:41:57
Add a comment about why this is necessary.
Alex Z.
2016/11/30 20:00:30
Done.
| |
| 53 ASSERT_EQ(1, release_buffer_call_count); | 55 ASSERT_EQ(1, release_buffer_call_count); |
| 54 } | 56 } |
| 55 | 57 |
| 56 TEST_F(SurfaceTest, Damage) { | 58 TEST_F(SurfaceTest, Damage) { |
| 57 gfx::Size buffer_size(256, 256); | 59 gfx::Size buffer_size(256, 256); |
| 58 std::unique_ptr<Buffer> buffer( | 60 std::unique_ptr<Buffer> buffer( |
| 59 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); | 61 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| 60 std::unique_ptr<Surface> surface(new Surface); | 62 std::unique_ptr<Surface> surface(new Surface); |
| 61 | 63 |
| 62 // Attach the buffer to the surface. This will update the pending bounds of | 64 // Attach the buffer to the surface. This will update the pending bounds of |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); | 242 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| 241 std::unique_ptr<Surface> surface(new Surface); | 243 std::unique_ptr<Surface> surface(new Surface); |
| 242 | 244 |
| 243 surface->Attach(buffer.get()); | 245 surface->Attach(buffer.get()); |
| 244 surface->SetAlpha(0.5f); | 246 surface->SetAlpha(0.5f); |
| 245 surface->Commit(); | 247 surface->Commit(); |
| 246 } | 248 } |
| 247 | 249 |
| 248 TEST_F(SurfaceTest, Commit) { | 250 TEST_F(SurfaceTest, Commit) { |
| 249 std::unique_ptr<Surface> surface(new Surface); | 251 std::unique_ptr<Surface> surface(new Surface); |
| 250 | |
| 251 // Calling commit without a buffer should succeed. | 252 // Calling commit without a buffer should succeed. |
| 252 surface->Commit(); | 253 surface->Commit(); |
| 253 } | 254 } |
| 254 | 255 |
| 255 } // namespace | 256 } // namespace |
| 256 } // namespace exo | 257 } // namespace exo |
| OLD | NEW |