Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 "content/common/gpu/gpu_memory_manager.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
|
nduca
2012/01/31 06:53:47
i think we put a space between the "class header f
mmocny
2012/01/31 18:54:57
Done.
| |
| 7 | |
| 8 //////////////////////////////////////////////////////////////////////////////// | |
|
nduca
2012/01/31 06:53:47
I dont see the /// pattern being used in the gpu c
mmocny
2012/01/31 18:54:57
I saw usage all over content/common..
I didn't rea
| |
| 9 // Fake Overrides for testing | |
|
nduca
2012/01/31 06:53:47
not sure this comment adds value
mmocny
2012/01/31 18:54:57
Done.
| |
| 10 | |
| 11 struct FakeCommandBufferStub : GpuMemoryManageableCommandBufferStub { | |
|
nduca
2012/01/31 06:53:47
why struct?
mmocny
2012/01/31 18:54:57
Done.
| |
| 12 virtual const GpuSurfaceState& surface_state() { | |
| 13 return surface_state_; | |
| 14 } | |
| 15 virtual const std::vector<int32>& affected_surface_ids() { | |
| 16 return affected_surface_ids_; | |
| 17 } | |
| 18 virtual void SendMemoryAllocation(const GpuMemoryAllocation& alloc) { | |
| 19 allocation_ = alloc; | |
| 20 } | |
| 21 | |
| 22 GpuSurfaceState surface_state_; | |
| 23 std::vector<int32> affected_surface_ids_; | |
| 24 GpuMemoryAllocation allocation_; | |
| 25 }; | |
| 26 | |
| 27 struct FakeClient : GpuMemoryManagerClient { | |
|
nduca
2012/01/31 06:53:47
class
mmocny
2012/01/31 18:54:57
Done.
| |
| 28 virtual void AppendAllCommandBufferStubs( | |
| 29 std::vector<GpuMemoryManageableCommandBufferStub*>& stubs_with_surface, | |
| 30 std::vector<GpuMemoryManageableCommandBufferStub*>& stubs_without_surface) | |
| 31 { | |
| 32 stubs_with_surface.insert(stubs_with_surface.end(), | |
| 33 stubs_with_surface_.begin(), | |
| 34 stubs_with_surface_.end()); | |
| 35 stubs_with_surface.insert(stubs_without_surface.end(), | |
| 36 stubs_without_surface_.begin(), | |
| 37 stubs_without_surface_.end()); | |
| 38 } | |
| 39 | |
| 40 std::vector<GpuMemoryManageableCommandBufferStub*> stubs_with_surface_; | |
| 41 std::vector<GpuMemoryManageableCommandBufferStub*> stubs_without_surface_; | |
| 42 }; | |
| 43 | |
| 44 //////////////////////////////////////////////////////////////////////////////// | |
| 45 // Helpers | |
| 46 | |
| 47 FakeCommandBufferStub CreateFakeCommandBufferStubWithSurface() { | |
| 48 static int32 surface_id_ = 1; | |
| 49 FakeCommandBufferStub ret; | |
|
nduca
2012/01/31 06:53:47
ret -> stub
mmocny
2012/01/31 18:54:57
Done.
| |
| 50 ret.surface_state_.surface_id = surface_id_++; | |
| 51 ret.surface_state_.visible = true; | |
| 52 ret.surface_state_.last_used_time = base::TimeTicks::Now(); | |
| 53 return ret; | |
| 54 } | |
| 55 | |
| 56 FakeCommandBufferStub CreateFakeCommandBufferStubWithoutSurface() { | |
|
nduca
2012/01/31 06:53:47
you know, I'm thinking you might be better served
mmocny
2012/01/31 18:54:57
Done.
| |
| 57 FakeCommandBufferStub ret; | |
| 58 ret.surface_state_.surface_id = 0; | |
| 59 ret.surface_state_.visible = true; | |
| 60 ret.surface_state_.last_used_time = base::TimeTicks::Now(); | |
| 61 return ret; | |
| 62 } | |
| 63 | |
| 64 //////////////////////////////////////////////////////////////////////////////// | |
| 65 | |
| 66 TEST(GpuMemoryManagerTest, BasicFunctionality) { | |
| 67 FakeClient fake_client; | |
| 68 | |
| 69 FakeCommandBufferStub fake_stub_with_surface1 = | |
|
nduca
2012/01/31 06:53:47
i think you're killing yourself with these names.
mmocny
2012/01/31 18:54:57
Working on it :)
On 2012/01/31 06:53:47, nduca wro
| |
| 70 CreateFakeCommandBufferStubWithSurface(); | |
| 71 FakeCommandBufferStub fake_stub_with_surface2 = | |
| 72 CreateFakeCommandBufferStubWithSurface(); | |
| 73 fake_stub_with_surface1.surface_state_.visible = true; | |
| 74 fake_stub_with_surface2.surface_state_.visible = false; | |
| 75 fake_stub_with_surface2.surface_state_.last_used_time += | |
| 76 base::TimeDelta::FromSeconds(1); | |
| 77 | |
| 78 FakeCommandBufferStub fake_stub_without_surface1 = | |
| 79 CreateFakeCommandBufferStubWithoutSurface(); | |
| 80 FakeCommandBufferStub fake_stub_without_surface2 = | |
| 81 CreateFakeCommandBufferStubWithoutSurface(); | |
| 82 fake_stub_without_surface1.surface_state_.visible = false; | |
| 83 fake_stub_without_surface2.surface_state_.visible = false; | |
| 84 fake_stub_without_surface2.surface_state_.last_used_time -= | |
| 85 base::TimeDelta::FromSeconds(1); | |
| 86 fake_stub_without_surface1.affected_surface_ids_.push_back( | |
| 87 fake_stub_with_surface1.surface_state_.surface_id); | |
| 88 fake_stub_without_surface2.affected_surface_ids_.push_back( | |
| 89 fake_stub_with_surface1.surface_state_.surface_id); | |
| 90 fake_stub_without_surface2.affected_surface_ids_.push_back( | |
| 91 fake_stub_with_surface2.surface_state_.surface_id); | |
| 92 | |
| 93 EXPECT_EQ(IsMoreImportant(&fake_stub_with_surface1, | |
| 94 &fake_stub_with_surface2), true); | |
| 95 EXPECT_EQ(IsMoreImportant(&fake_stub_without_surface1, | |
| 96 &fake_stub_without_surface2), true); | |
| 97 | |
| 98 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 99 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface2); | |
| 100 fake_client.stubs_without_surface_.push_back(&fake_stub_without_surface1); | |
| 101 fake_client.stubs_without_surface_.push_back(&fake_stub_without_surface2); | |
| 102 | |
| 103 #if 0 | |
| 104 GpuMemoryManager memory_manager(&fake_client); | |
| 105 memory_manager.Manage(); | |
| 106 | |
| 107 EXPECT_EQ(fake_stub_with_surface1.allocation_.hasFrontbuffer, true); | |
| 108 EXPECT_EQ(fake_stub_with_surface1.allocation_.hasBackbuffer, true); | |
| 109 EXPECT_EQ(fake_stub_with_surface2.allocation_.hasFrontbuffer, true); | |
| 110 EXPECT_EQ(fake_stub_with_surface2.allocation_.hasBackbuffer, false); | |
| 111 EXPECT_EQ(fake_stub_without_surface1.allocation_.hasFrontbuffer, true); | |
| 112 EXPECT_EQ(fake_stub_without_surface1.allocation_.hasBackbuffer, false); | |
| 113 EXPECT_EQ(fake_stub_without_surface2.allocation_.hasFrontbuffer, true); | |
| 114 EXPECT_EQ(fake_stub_without_surface2.allocation_.hasBackbuffer, true); | |
| 115 | |
| 116 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 117 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 118 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 119 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 120 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 121 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 122 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 123 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 124 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 125 fake_client.stubs_with_surface_.push_back(&fake_stub_with_surface1); | |
| 126 | |
| 127 memory_manager.Manage(); | |
| 128 EXPECT_EQ(fake_stub_with_surface1.allocation_.hasFrontbuffer, true); | |
| 129 EXPECT_EQ(fake_stub_with_surface1.allocation_.hasBackbuffer, true); | |
| 130 EXPECT_EQ(fake_stub_with_surface2.allocation_.hasFrontbuffer, false); | |
| 131 EXPECT_EQ(fake_stub_with_surface2.allocation_.hasBackbuffer, false); | |
| 132 EXPECT_EQ(fake_stub_without_surface1.allocation_.hasFrontbuffer, false); | |
| 133 EXPECT_EQ(fake_stub_without_surface1.allocation_.hasBackbuffer, false); | |
| 134 EXPECT_EQ(fake_stub_without_surface2.allocation_.hasFrontbuffer, true); | |
| 135 EXPECT_EQ(fake_stub_without_surface2.allocation_.hasBackbuffer, true); | |
| 136 #endif | |
| 137 } | |
| OLD | NEW |