| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/gpu_memory_manager.h" | 5 #include "content/common/gpu/gpu_memory_manager.h" |
| 6 #include "content/common/gpu/gpu_memory_manager_client.h" | 6 #include "content/common/gpu/gpu_memory_manager_client.h" |
| 7 #include "content/common/gpu/gpu_memory_tracking.h" | 7 #include "content/common/gpu/gpu_memory_tracking.h" |
| 8 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 8 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 9 #include "ui/gfx/size_conversions.h" | 9 #include "ui/gfx/size_conversions.h" |
| 10 | 10 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using gpu::MemoryAllocation; | 13 using gpu::MemoryAllocation; |
| 14 | 14 |
| 15 class FakeMemoryTracker : public gpu::gles2::MemoryTracker { | 15 class FakeMemoryTracker : public gpu::gles2::MemoryTracker { |
| 16 public: | 16 public: |
| 17 virtual void TrackMemoryAllocatedChange( | 17 void TrackMemoryAllocatedChange( |
| 18 size_t /* old_size */, | 18 size_t /* old_size */, |
| 19 size_t /* new_size */, | 19 size_t /* new_size */, |
| 20 gpu::gles2::MemoryTracker::Pool /* pool */) override { | 20 gpu::gles2::MemoryTracker::Pool /* pool */) override {} |
| 21 } | 21 bool EnsureGPUMemoryAvailable(size_t /* size_needed */) override { |
| 22 virtual bool EnsureGPUMemoryAvailable(size_t /* size_needed */) override { | |
| 23 return true; | 22 return true; |
| 24 } | 23 } |
| 25 private: | 24 private: |
| 26 virtual ~FakeMemoryTracker() { | 25 ~FakeMemoryTracker() override {} |
| 27 } | |
| 28 }; | 26 }; |
| 29 | 27 |
| 30 namespace content { | 28 namespace content { |
| 31 | 29 |
| 32 // This class is used to collect all stub assignments during a | 30 // This class is used to collect all stub assignments during a |
| 33 // Manage() call. | 31 // Manage() call. |
| 34 class ClientAssignmentCollector { | 32 class ClientAssignmentCollector { |
| 35 public: | 33 public: |
| 36 struct ClientMemoryStat { | 34 struct ClientMemoryStat { |
| 37 MemoryAllocation allocation; | 35 MemoryAllocation allocation; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 total_gpu_memory_(0), | 90 total_gpu_memory_(0), |
| 93 share_group_(NULL), | 91 share_group_(NULL), |
| 94 memory_tracker_(NULL) { | 92 memory_tracker_(NULL) { |
| 95 memory_tracker_ = new FakeMemoryTracker(); | 93 memory_tracker_ = new FakeMemoryTracker(); |
| 96 tracking_group_.reset( | 94 tracking_group_.reset( |
| 97 memmgr_->CreateTrackingGroup(0, memory_tracker_.get())); | 95 memmgr_->CreateTrackingGroup(0, memory_tracker_.get())); |
| 98 client_state_.reset( | 96 client_state_.reset( |
| 99 memmgr_->CreateClientState(this, surface_id != 0, visible)); | 97 memmgr_->CreateClientState(this, surface_id != 0, visible)); |
| 100 } | 98 } |
| 101 | 99 |
| 102 virtual ~FakeClient() { | 100 ~FakeClient() override { |
| 103 client_state_.reset(); | 101 client_state_.reset(); |
| 104 tracking_group_.reset(); | 102 tracking_group_.reset(); |
| 105 memory_tracker_ = NULL; | 103 memory_tracker_ = NULL; |
| 106 } | 104 } |
| 107 | 105 |
| 108 virtual void SetMemoryAllocation(const MemoryAllocation& alloc) override { | 106 void SetMemoryAllocation(const MemoryAllocation& alloc) override { |
| 109 allocation_ = alloc; | 107 allocation_ = alloc; |
| 110 ClientAssignmentCollector::AddClientStat(this, alloc); | 108 ClientAssignmentCollector::AddClientStat(this, alloc); |
| 111 } | 109 } |
| 112 | 110 |
| 113 virtual void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override { | 111 void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override { |
| 114 suggest_have_frontbuffer_ = suggest_have_frontbuffer; | 112 suggest_have_frontbuffer_ = suggest_have_frontbuffer; |
| 115 } | 113 } |
| 116 | 114 |
| 117 virtual bool GetTotalGpuMemory(uint64* bytes) override { | 115 bool GetTotalGpuMemory(uint64* bytes) override { |
| 118 if (total_gpu_memory_) { | 116 if (total_gpu_memory_) { |
| 119 *bytes = total_gpu_memory_; | 117 *bytes = total_gpu_memory_; |
| 120 return true; | 118 return true; |
| 121 } | 119 } |
| 122 return false; | 120 return false; |
| 123 } | 121 } |
| 124 void SetTotalGpuMemory(uint64 bytes) { total_gpu_memory_ = bytes; } | 122 void SetTotalGpuMemory(uint64 bytes) { total_gpu_memory_ = bytes; } |
| 125 | 123 |
| 126 virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const override { | 124 gpu::gles2::MemoryTracker* GetMemoryTracker() const override { |
| 127 if (share_group_) | 125 if (share_group_) |
| 128 return share_group_->GetMemoryTracker(); | 126 return share_group_->GetMemoryTracker(); |
| 129 return memory_tracker_.get(); | 127 return memory_tracker_.get(); |
| 130 } | 128 } |
| 131 | 129 |
| 132 virtual gfx::Size GetSurfaceSize() const override { | 130 gfx::Size GetSurfaceSize() const override { return surface_size_; } |
| 133 return surface_size_; | |
| 134 } | |
| 135 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; } | 131 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; } |
| 136 | 132 |
| 137 void SetVisible(bool visible) { | 133 void SetVisible(bool visible) { |
| 138 client_state_->SetVisible(visible); | 134 client_state_->SetVisible(visible); |
| 139 } | 135 } |
| 140 | 136 |
| 141 uint64 BytesWhenVisible() const { | 137 uint64 BytesWhenVisible() const { |
| 142 return allocation_.bytes_limit_when_visible; | 138 return allocation_.bytes_limit_when_visible; |
| 143 } | 139 } |
| 144 }; | 140 }; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 stub_ignore_c.SetVisible(true); | 395 stub_ignore_c.SetVisible(true); |
| 400 stub_ignore_c.SetVisible(false); | 396 stub_ignore_c.SetVisible(false); |
| 401 Manage(); | 397 Manage(); |
| 402 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | 398 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); |
| 403 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); | 399 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); |
| 404 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); | 400 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); |
| 405 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); | 401 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); |
| 406 } | 402 } |
| 407 | 403 |
| 408 } // namespace content | 404 } // namespace content |
| OLD | NEW |