| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <unordered_map> | 7 #include <unordered_map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "cc/surfaces/compositor_frame_sink_support.h" | 11 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 12 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_id.h" | 13 #include "cc/surfaces/surface_id.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 15 #include "cc/test/compositor_frame_helpers.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using testing::ElementsAre; | 19 using testing::ElementsAre; |
| 19 using testing::IsEmpty; | 20 using testing::IsEmpty; |
| 20 using testing::SizeIs; | 21 using testing::SizeIs; |
| 21 using testing::UnorderedElementsAre; | 22 using testing::UnorderedElementsAre; |
| 22 | 23 |
| 23 namespace cc { | 24 namespace cc { |
| 24 | |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 constexpr FrameSinkId kFrameSink1(1, 0); | 27 constexpr FrameSinkId kFrameSink1(1, 0); |
| 28 constexpr FrameSinkId kFrameSink2(2, 0); | 28 constexpr FrameSinkId kFrameSink2(2, 0); |
| 29 constexpr FrameSinkId kFrameSink3(3, 0); | 29 constexpr FrameSinkId kFrameSink3(3, 0); |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 // Tests for reference tracking in SurfaceManager. | 33 // Tests for reference tracking in SurfaceManager. |
| 34 class SurfaceManagerRefTest : public testing::Test { | 34 class SurfaceManagerRefTest : public testing::Test { |
| 35 public: | 35 public: |
| 36 SurfaceManager& manager() { return *manager_; } | 36 SurfaceManager& manager() { return *manager_; } |
| 37 | 37 |
| 38 // Creates a new Surface with the provided |frame_sink_id| and |local_id|. | 38 // Creates a new Surface with the provided |frame_sink_id| and |local_id|. |
| 39 // Will first create a Surfacesupport for |frame_sink_id| if necessary. | 39 // Will first create a Surfacesupport for |frame_sink_id| if necessary. |
| 40 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, uint32_t local_id) { | 40 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, uint32_t local_id) { |
| 41 LocalSurfaceId local_surface_id(local_id, | 41 LocalSurfaceId local_surface_id(local_id, |
| 42 base::UnguessableToken::Deserialize(0, 1u)); | 42 base::UnguessableToken::Deserialize(0, 1u)); |
| 43 GetCompositorFrameSinkSupport(frame_sink_id) | 43 GetCompositorFrameSinkSupport(frame_sink_id) |
| 44 .SubmitCompositorFrame(local_surface_id, CompositorFrame()); | 44 .SubmitCompositorFrame(local_surface_id, test::MakeCompositorFrame()); |
| 45 return SurfaceId(frame_sink_id, local_surface_id); | 45 return SurfaceId(frame_sink_id, local_surface_id); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Destroy Surface with |surface_id|. | 48 // Destroy Surface with |surface_id|. |
| 49 void DestroySurface(const SurfaceId& surface_id) { | 49 void DestroySurface(const SurfaceId& surface_id) { |
| 50 GetCompositorFrameSinkSupport(surface_id.frame_sink_id()).EvictFrame(); | 50 GetCompositorFrameSinkSupport(surface_id.frame_sink_id()).EvictFrame(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 CompositorFrameSinkSupport& GetCompositorFrameSinkSupport( | 53 CompositorFrameSinkSupport& GetCompositorFrameSinkSupport( |
| 54 const FrameSinkId& frame_sink_id) { | 54 const FrameSinkId& frame_sink_id) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1b)); | 506 ASSERT_THAT(GetAllTempReferences(), UnorderedElementsAre(id1b)); |
| 507 | 507 |
| 508 // If the parent has crashed then the window server will have already removed | 508 // If the parent has crashed then the window server will have already removed |
| 509 // it from the ServerWindow hierarchy and won't have an owner for |id2b|. The | 509 // it from the ServerWindow hierarchy and won't have an owner for |id2b|. The |
| 510 // window server will ask to drop the reference instead. | 510 // window server will ask to drop the reference instead. |
| 511 manager().DropTemporaryReference(id1b); | 511 manager().DropTemporaryReference(id1b); |
| 512 ASSERT_THAT(GetAllTempReferences(), IsEmpty()); | 512 ASSERT_THAT(GetAllTempReferences(), IsEmpty()); |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namespace cc | 515 } // namespace cc |
| OLD | NEW |