summaryrefslogtreecommitdiffstats
path: root/content/common/gpu
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 04:22:04 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 04:22:04 +0000
commit9db65ffe5a9f00744350653c904ad9f8990887b3 (patch)
tree2865e3e57a416d1f5053c5ea7bed00dee3713537 /content/common/gpu
parentae0f0d38552900c3e43578d040f5233c083b88b1 (diff)
downloadchromium_src-9db65ffe5a9f00744350653c904ad9f8990887b3.zip
chromium_src-9db65ffe5a9f00744350653c904ad9f8990887b3.tar.gz
chromium_src-9db65ffe5a9f00744350653c904ad9f8990887b3.tar.bz2
Clean up memory manager's context tracking structures.
This change should not change any behavior. Use GetMemoryTracker and comparisons instead of IsInSameContextShareGroup to determine if two stubs should be counted as being in the same group. Simplify the logic in GpuMemoryManager::Manage() use an O(log n) lookup based on memory tracker instead of an O(n) lookup based on stub context group to determine if two stubs are in the same context group. Fix a number of places in the memory manager unit test where "is in the same context group as" was assumed not to be an equivalence relation (now that the lookup is based on memory tracker, it is an equivalence relation). Add memory tracking to the memory manager unit test (so that we can simulate unmanaged memory, e.g, WebGL, entering the mix). Clean up the memory manager unit test to use a common base class for the two stub classes. BUG=134750 Review URL: https://chromiumcodereview.appspot.com/11361050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165617 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common/gpu')
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.cc7
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.h8
-rw-r--r--content/common/gpu/gpu_memory_manager.cc155
-rw-r--r--content/common/gpu/gpu_memory_manager.h3
-rw-r--r--content/common/gpu/gpu_memory_manager_unittest.cc137
-rw-r--r--content/common/gpu/gpu_memory_tracking.h10
6 files changed, 157 insertions, 163 deletions
diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc
index 6b79553..8bb6476 100644
--- a/content/common/gpu/gpu_command_buffer_stub.cc
+++ b/content/common/gpu/gpu_command_buffer_stub.cc
@@ -47,6 +47,7 @@ class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker {
GpuCommandBufferMemoryTracker(GpuChannel* channel) {
gpu_memory_manager_tracking_group_ = new GpuMemoryTrackingGroup(
channel->renderer_pid(),
+ this,
channel->gpu_channel_manager()->gpu_memory_manager());
}
@@ -834,10 +835,8 @@ gfx::Size GpuCommandBufferStub::GetSurfaceSize() const {
return surface_->GetSize();
}
-bool GpuCommandBufferStub::IsInSameContextShareGroup(
- const GpuCommandBufferStubBase& other) const {
- return context_group_ ==
- static_cast<const GpuCommandBufferStub&>(other).context_group_;
+gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const {
+ return context_group_->memory_tracker();
}
const GpuCommandBufferStubBase::MemoryManagerState&
diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h
index 4793ebd..e2253fc 100644
--- a/content/common/gpu/gpu_command_buffer_stub.h
+++ b/content/common/gpu/gpu_command_buffer_stub.h
@@ -74,8 +74,7 @@ class CONTENT_EXPORT GpuCommandBufferStubBase {
virtual gfx::Size GetSurfaceSize() const = 0;
- virtual bool IsInSameContextShareGroup(
- const GpuCommandBufferStubBase& other) const = 0;
+ virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const = 0;
virtual void SetMemoryAllocation(
const GpuMemoryAllocation& allocation) = 0;
@@ -130,9 +129,8 @@ class GpuCommandBufferStub
// Returns surface size.
virtual gfx::Size GetSurfaceSize() const OVERRIDE;
- // Returns true iff |other| is in the same context share group as this stub.
- virtual bool IsInSameContextShareGroup(
- const GpuCommandBufferStubBase& other) const OVERRIDE;
+ // Returns the memory tracker for this stub.
+ virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const OVERRIDE;
// Sets buffer usage depending on Memory Allocation
virtual void SetMemoryAllocation(
diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc
index 877d29a..2ff735d 100644
--- a/content/common/gpu/gpu_memory_manager.cc
+++ b/content/common/gpu/gpu_memory_manager.cc
@@ -25,22 +25,10 @@ namespace {
const int kDelayedScheduleManageTimeoutMs = 67;
-bool IsInSameContextShareGroupAsAnyOf(
- const GpuCommandBufferStubBase* stub,
- const std::vector<GpuCommandBufferStubBase*>& stubs) {
- for (std::vector<GpuCommandBufferStubBase*>::const_iterator it =
- stubs.begin(); it != stubs.end(); ++it) {
- if (stub->IsInSameContextShareGroup(**it))
- return true;
- }
- return false;
-}
-
void AssignMemoryAllocations(
- const std::vector<GpuCommandBufferStubBase*>& stubs,
+ const GpuMemoryManager::StubVector& stubs,
const GpuMemoryAllocation& allocation) {
- for (std::vector<GpuCommandBufferStubBase*>::const_iterator it =
- stubs.begin();
+ for (GpuMemoryManager::StubVector::const_iterator it = stubs.begin();
it != stubs.end();
++it) {
(*it)->SetMemoryAllocation(allocation);
@@ -104,7 +92,7 @@ size_t GpuMemoryManager::CalcAvailableFromGpuTotal(size_t total_gpu_memory) {
}
void GpuMemoryManager::UpdateAvailableGpuMemory(
- std::vector<GpuCommandBufferStubBase*>& stubs) {
+ const StubVector& stubs) {
// If the amount of video memory to use was specified at the command
// line, never change it.
if (bytes_available_gpu_memory_overridden_)
@@ -114,39 +102,50 @@ void GpuMemoryManager::UpdateAvailableGpuMemory(
// On Android we use the surface size, so this finds the largest visible
// surface size instead of lowest gpu's limit.
int max_surface_area = 0;
- for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin();
- it != stubs.end(); ++it) {
- GpuCommandBufferStubBase* stub = *it;
- gfx::Size surface_size = stub->GetSurfaceSize();
- max_surface_area = std::max(max_surface_area, surface_size.width() *
- surface_size.height());
- }
- bytes_available_gpu_memory_ = CalcAvailableFromViewportArea(max_surface_area);
#else
+ // On non-Android, we use an operating system query when possible.
// We do not have a reliable concept of multiple GPUs existing in
// a system, so just be safe and go with the minimum encountered.
size_t bytes_min = 0;
- for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin();
+#endif
+
+ // Only use the stubs that are visible, because otherwise the set of stubs
+ // we are querying could become extremely large.
+ for (StubVector::const_iterator it = stubs.begin();
it != stubs.end(); ++it) {
GpuCommandBufferStubBase* stub = *it;
+ if (!stub->memory_manager_state().has_surface)
+ continue;
+ if (!stub->memory_manager_state().visible)
+ continue;
+
+#if defined(OS_ANDROID)
+ gfx::Size surface_size = stub->GetSurfaceSize();
+ max_surface_area = std::max(max_surface_area, surface_size.width() *
+ surface_size.height());
+#else
size_t bytes = 0;
if (stub->GetTotalGpuMemory(&bytes)) {
if (!bytes_min || bytes < bytes_min)
bytes_min = bytes;
}
+#endif
}
+
+#if defined(OS_ANDROID)
+ bytes_available_gpu_memory_ = CalcAvailableFromViewportArea(max_surface_area);
+#else
if (!bytes_min)
return;
bytes_available_gpu_memory_ = CalcAvailableFromGpuTotal(bytes_min);
-
#endif
- // And never go below the default allocation
+ // Never go below the default allocation
bytes_available_gpu_memory_ = std::max(bytes_available_gpu_memory_,
GetDefaultAvailableGpuMemory());
- // And never go above the maximum.
+ // Never go above the maximum.
bytes_available_gpu_memory_ = std::min(bytes_available_gpu_memory_,
GetMaximumTotalGpuMemory());
}
@@ -281,14 +280,13 @@ void GpuMemoryManager::Manage() {
delayed_manage_callback_.Cancel();
// Create stub lists by separating out the two types received from client
- std::vector<GpuCommandBufferStubBase*> stubs_with_surface;
- std::vector<GpuCommandBufferStubBase*> stubs_without_surface;
+ StubVector stubs_with_surface;
+ StubVector stubs_without_surface;
{
- std::vector<GpuCommandBufferStubBase*> stubs;
+ StubVector stubs;
client_->AppendAllCommandBufferStubs(stubs);
- for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin();
- it != stubs.end(); ++it) {
+ for (StubVector::iterator it = stubs.begin(); it != stubs.end(); ++it) {
GpuCommandBufferStubBase* stub = *it;
if (!stub->memory_manager_state().
client_has_memory_allocation_changed_callback)
@@ -308,95 +306,86 @@ void GpuMemoryManager::Manage() {
DCHECK(std::unique(stubs_with_surface.begin(), stubs_with_surface.end()) ==
stubs_with_surface.end());
- // Separate stubs into memory allocation sets.
- std::vector<GpuCommandBufferStubBase*> stubs_with_surface_foreground,
- stubs_with_surface_background,
- stubs_with_surface_hibernated,
- stubs_without_surface_foreground,
- stubs_without_surface_background,
- stubs_without_surface_hibernated;
+ std::set<gpu::gles2::MemoryTracker*> memory_trackers_not_hibernated;
+ // Separate the stubs with surfaces into the ones that will get a
+ // frontbuffer (the ones that are visible, and then the most recently
+ // used, up to a limit) and those that do not get a frontbuffer.
+ size_t stubs_with_surface_visible_count = 0;
+ StubVector stubs_with_surface_not_hibernated;
+ StubVector stubs_with_surface_hibernated;
for (size_t i = 0; i < stubs_with_surface.size(); ++i) {
GpuCommandBufferStubBase* stub = stubs_with_surface[i];
DCHECK(stub->memory_manager_state().has_surface);
+
if (stub->memory_manager_state().visible)
- stubs_with_surface_foreground.push_back(stub);
- else if (i < max_surfaces_with_frontbuffer_soft_limit_)
- stubs_with_surface_background.push_back(stub);
- else
+ stubs_with_surface_visible_count++;
+
+ if (stub->memory_manager_state().visible ||
+ i < max_surfaces_with_frontbuffer_soft_limit_) {
+ memory_trackers_not_hibernated.insert(stub->GetMemoryTracker());
+ stubs_with_surface_not_hibernated.push_back(stub);
+ } else {
stubs_with_surface_hibernated.push_back(stub);
+ }
}
- for (std::vector<GpuCommandBufferStubBase*>::const_iterator it =
+
+ // Separate the stubs without surfaces into the ones that will be given a
+ // memory allocation (the ones that are in a share group with a stub with
+ // a surface that has a frontbuffer) and those that won't.
+ StubVector stubs_without_surface_not_hibernated;
+ StubVector stubs_without_surface_hibernated;
+ for (StubVector::const_iterator it =
stubs_without_surface.begin(); it != stubs_without_surface.end(); ++it) {
GpuCommandBufferStubBase* stub = *it;
DCHECK(!stub->memory_manager_state().has_surface);
-
- // Stubs without surfaces have deduced allocation state using the state
- // of surface stubs which are in the same context share group.
- if (IsInSameContextShareGroupAsAnyOf(stub, stubs_with_surface_foreground))
- stubs_without_surface_foreground.push_back(stub);
- else if (IsInSameContextShareGroupAsAnyOf(
- stub, stubs_with_surface_background))
- stubs_without_surface_background.push_back(stub);
+ if (memory_trackers_not_hibernated.count(stub->GetMemoryTracker()))
+ stubs_without_surface_not_hibernated.push_back(stub);
else
stubs_without_surface_hibernated.push_back(stub);
}
- // Update the amount of GPU memory available on the system. Only use the
- // stubs that are visible, because otherwise the set of stubs we are
- // querying could become extremely large (resulting in hundreds of calls
- // to the driver).
- UpdateAvailableGpuMemory(stubs_with_surface_foreground);
+ // Update the amount of GPU memory available on the system.
+ UpdateAvailableGpuMemory(stubs_with_surface);
- size_t bonus_allocation = 0;
// Calculate bonus allocation by splitting remainder of global limit equally
// after giving out the minimum to those that need it.
- size_t num_stubs_need_mem = stubs_with_surface_foreground.size() +
- stubs_without_surface_foreground.size() +
- stubs_without_surface_background.size();
+ size_t num_stubs_need_mem = stubs_with_surface_visible_count +
+ stubs_without_surface_not_hibernated.size();
size_t base_allocation_size = GetMinimumTabAllocation() * num_stubs_need_mem;
+ size_t bonus_allocation = 0;
if (base_allocation_size < GetAvailableGpuMemory() &&
- !stubs_with_surface_foreground.empty())
+ stubs_with_surface_visible_count)
bonus_allocation = (GetAvailableGpuMemory() - base_allocation_size) /
- stubs_with_surface_foreground.size();
- size_t stubs_with_surface_foreground_allocation = GetMinimumTabAllocation() +
- bonus_allocation;
+ stubs_with_surface_visible_count;
+ size_t stubs_allocation_when_visible = GetMinimumTabAllocation() +
+ bonus_allocation;
// If we have received a window count message, then override the stub-based
// scheme with a per-window scheme
if (window_count_has_been_received_) {
- stubs_with_surface_foreground_allocation = std::max(
- stubs_with_surface_foreground_allocation,
+ stubs_allocation_when_visible = std::max(
+ stubs_allocation_when_visible,
GetAvailableGpuMemory()/std::max(window_count_, 1u));
}
// Limit the memory per stub to its maximum allowed level.
- if (stubs_with_surface_foreground_allocation >= GetMaximumTabAllocation())
- stubs_with_surface_foreground_allocation = GetMaximumTabAllocation();
+ if (stubs_allocation_when_visible >= GetMaximumTabAllocation())
+ stubs_allocation_when_visible = GetMaximumTabAllocation();
// Now give out allocations to everyone.
AssignMemoryAllocations(
- stubs_with_surface_foreground,
- GpuMemoryAllocation(stubs_with_surface_foreground_allocation,
- GpuMemoryAllocation::kHasFrontbuffer));
-
- AssignMemoryAllocations(
- stubs_with_surface_background,
- GpuMemoryAllocation(stubs_with_surface_foreground_allocation,
+ stubs_with_surface_not_hibernated,
+ GpuMemoryAllocation(stubs_allocation_when_visible,
GpuMemoryAllocation::kHasFrontbuffer));
AssignMemoryAllocations(
stubs_with_surface_hibernated,
- GpuMemoryAllocation(stubs_with_surface_foreground_allocation,
- GpuMemoryAllocation::kHasNoFrontbuffer));
-
- AssignMemoryAllocations(
- stubs_without_surface_foreground,
- GpuMemoryAllocation(GetMinimumTabAllocation(),
+ GpuMemoryAllocation(stubs_allocation_when_visible,
GpuMemoryAllocation::kHasNoFrontbuffer));
AssignMemoryAllocations(
- stubs_without_surface_background,
+ stubs_without_surface_not_hibernated,
GpuMemoryAllocation(GetMinimumTabAllocation(),
GpuMemoryAllocation::kHasNoFrontbuffer));
diff --git a/content/common/gpu/gpu_memory_manager.h b/content/common/gpu/gpu_memory_manager.h
index 1aadfdd..5870bae 100644
--- a/content/common/gpu/gpu_memory_manager.h
+++ b/content/common/gpu/gpu_memory_manager.h
@@ -49,6 +49,7 @@ class CONTENT_EXPORT GpuMemoryManager :
public base::SupportsWeakPtr<GpuMemoryManager> {
public:
enum { kDefaultMaxSurfacesWithFrontbufferSoftLimit = 8 };
+ typedef std::vector<GpuCommandBufferStubBase*> StubVector;
GpuMemoryManager(GpuMemoryManagerClient* client,
size_t max_surfaces_with_frontbuffer_soft_limit);
@@ -83,7 +84,7 @@ class CONTENT_EXPORT GpuMemoryManager :
// Update the amount of GPU memory we think we have in the system, based
// on what the stubs' contexts report.
- void UpdateAvailableGpuMemory(std::vector<GpuCommandBufferStubBase*>& stubs);
+ void UpdateAvailableGpuMemory(const StubVector& stubs);
// The amount of video memory which is available for allocation
size_t GetAvailableGpuMemory() const {
diff --git a/content/common/gpu/gpu_memory_manager_unittest.cc b/content/common/gpu/gpu_memory_manager_unittest.cc
index 8ac5fcb..5d219e1 100644
--- a/content/common/gpu/gpu_memory_manager_unittest.cc
+++ b/content/common/gpu/gpu_memory_manager_unittest.cc
@@ -5,10 +5,20 @@
#include "content/common/gpu/gpu_command_buffer_stub.h"
#include "content/common/gpu/gpu_memory_allocation.h"
#include "content/common/gpu/gpu_memory_manager.h"
+#include "content/common/gpu/gpu_memory_tracking.h"
#include "ui/gfx/size_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
+class FakeMemoryTracker : public gpu::gles2::MemoryTracker {
+ public:
+ void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) {
+ }
+ private:
+ ~FakeMemoryTracker() {
+ }
+};
+
namespace content {
// This class is used to collect all stub assignments during a
@@ -40,42 +50,30 @@ class StubAssignmentCollector {
StubAssignmentCollector::StubMemoryStatMap
StubAssignmentCollector::stub_memory_stats_for_last_manage_;
-class FakeCommandBufferStub : public GpuCommandBufferStubBase {
+class FakeCommandBufferStubBase : public GpuCommandBufferStubBase {
public:
MemoryManagerState memory_manager_state_;
GpuMemoryAllocation allocation_;
- gfx::Size surface_size_;
size_t total_gpu_memory_;
+ scoped_refptr<gpu::gles2::MemoryTracker> memory_tracker_;
+ gpu::gles2::MemoryTracker* overridden_memory_tracker_;
- FakeCommandBufferStub()
+ FakeCommandBufferStubBase()
: memory_manager_state_(0, false, base::TimeTicks())
- , total_gpu_memory_(0) {
- memory_manager_state_.client_has_memory_allocation_changed_callback = true;
- }
-
- FakeCommandBufferStub(int32 surface_id,
- bool visible,
- base::TimeTicks last_used_time)
- : memory_manager_state_(surface_id != 0, visible, last_used_time)
- , total_gpu_memory_(0) {
+ , total_gpu_memory_(0)
+ , memory_tracker_(new FakeMemoryTracker())
+ , overridden_memory_tracker_(0) {
memory_manager_state_.client_has_memory_allocation_changed_callback = true;
}
virtual const MemoryManagerState& memory_manager_state() const {
return memory_manager_state_;
}
-
- virtual gfx::Size GetSurfaceSize() const {
- return surface_size_;
- }
- virtual bool IsInSameContextShareGroup(
- const GpuCommandBufferStubBase& stub) const {
- return false;
- }
virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) {
allocation_ = alloc;
StubAssignmentCollector::AddStubStat(this, alloc);
}
+
virtual bool GetTotalGpuMemory(size_t* bytes) {
if (total_gpu_memory_) {
*bytes = total_gpu_memory_;
@@ -83,41 +81,49 @@ class FakeCommandBufferStub : public GpuCommandBufferStubBase {
}
return false;
}
-
void SetTotalGpuMemory(size_t bytes) { total_gpu_memory_ = bytes; }
- void SetSurfaceSize(gfx::Size size) { surface_size_ = size; }
+
+ virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const OVERRIDE {
+ if (overridden_memory_tracker_)
+ return overridden_memory_tracker_;
+ return memory_tracker_.get();
+ }
+
+ void SetInSameShareGroup(GpuCommandBufferStubBase* stub) {
+ overridden_memory_tracker_ = stub->GetMemoryTracker();
+ }
};
-class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase {
+class FakeCommandBufferStub : public FakeCommandBufferStubBase {
public:
- MemoryManagerState memory_manager_state_;
- GpuMemoryAllocation allocation_;
- std::vector<GpuCommandBufferStubBase*> share_group_;
+ gfx::Size surface_size_;
- FakeCommandBufferStubWithoutSurface()
- : memory_manager_state_(false, true, base::TimeTicks()) {
- memory_manager_state_.client_has_memory_allocation_changed_callback = true;
+ FakeCommandBufferStub() {
}
- virtual const MemoryManagerState& memory_manager_state() const {
- return memory_manager_state_;
+ FakeCommandBufferStub(int32 surface_id,
+ bool visible,
+ base::TimeTicks last_used_time) {
+ memory_manager_state_.has_surface = (surface_id != 0);
+ memory_manager_state_.visible = visible;
+ memory_manager_state_.last_used_time = last_used_time;
}
virtual gfx::Size GetSurfaceSize() const {
- return gfx::Size();
- }
- virtual bool IsInSameContextShareGroup(
- const GpuCommandBufferStubBase& stub) const {
- return std::find(share_group_.begin(),
- share_group_.end(),
- &stub) != share_group_.end();
+ return surface_size_;
}
- virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) {
- allocation_ = alloc;
- StubAssignmentCollector::AddStubStat(this, alloc);
+ void SetSurfaceSize(gfx::Size size) { surface_size_ = size; }
+};
+
+class FakeCommandBufferStubWithoutSurface : public FakeCommandBufferStubBase {
+ public:
+ FakeCommandBufferStubWithoutSurface() {
+ memory_manager_state_.has_surface = false;
+ memory_manager_state_.visible = true;
}
- virtual bool GetTotalGpuMemory(size_t* bytes) {
- return false;
+
+ virtual gfx::Size GetSurfaceSize() const {
+ return gfx::Size();
}
};
@@ -307,8 +313,8 @@ TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) {
// Test stubs without surface, with share group of 1 stub.
FakeCommandBufferStubWithoutSurface stub3, stub4;
- stub3.share_group_.push_back(&stub1);
- stub4.share_group_.push_back(&stub2);
+ stub3.SetInSameShareGroup(&stub1);
+ stub4.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub3);
client_.stubs_.push_back(&stub4);
@@ -320,8 +326,7 @@ TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) {
// Test stub without surface, with share group of multiple stubs.
FakeCommandBufferStubWithoutSurface stub5;
- stub5.share_group_.push_back(&stub1);
- stub5.share_group_.push_back(&stub2);
+ stub5.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub5);
Manage();
@@ -340,14 +345,13 @@ TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) {
client_.stubs_.push_back(&stub2);
FakeCommandBufferStubWithoutSurface stub3, stub4;
- stub3.share_group_.push_back(&stub1);
- stub4.share_group_.push_back(&stub2);
+ stub3.SetInSameShareGroup(&stub1);
+ stub4.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub3);
client_.stubs_.push_back(&stub4);
FakeCommandBufferStubWithoutSurface stub5;
- stub5.share_group_.push_back(&stub1);
- stub5.share_group_.push_back(&stub2);
+ stub5.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub5);
Manage();
@@ -382,14 +386,13 @@ TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) {
client_.stubs_.push_back(&stub4);
FakeCommandBufferStubWithoutSurface stub5, stub6;
- stub5.share_group_.push_back(&stub1);
- stub6.share_group_.push_back(&stub2);
+ stub5.SetInSameShareGroup(&stub1);
+ stub6.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub5);
client_.stubs_.push_back(&stub6);
FakeCommandBufferStubWithoutSurface stub7;
- stub7.share_group_.push_back(&stub1);
- stub7.share_group_.push_back(&stub2);
+ stub7.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub7);
Manage();
@@ -416,14 +419,13 @@ TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) {
client_.stubs_.push_back(&stub4);
FakeCommandBufferStubWithoutSurface stub5, stub6;
- stub5.share_group_.push_back(&stub1);
- stub6.share_group_.push_back(&stub4);
+ stub5.SetInSameShareGroup(&stub1);
+ stub6.SetInSameShareGroup(&stub4);
client_.stubs_.push_back(&stub5);
client_.stubs_.push_back(&stub6);
FakeCommandBufferStubWithoutSurface stub7;
- stub7.share_group_.push_back(&stub1);
- stub7.share_group_.push_back(&stub4);
+ stub7.SetInSameShareGroup(&stub1);
client_.stubs_.push_back(&stub7);
Manage();
@@ -450,14 +452,13 @@ TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) {
client_.stubs_.push_back(&stub4);
FakeCommandBufferStubWithoutSurface stub5, stub6;
- stub5.share_group_.push_back(&stub3);
- stub6.share_group_.push_back(&stub4);
+ stub5.SetInSameShareGroup(&stub3);
+ stub6.SetInSameShareGroup(&stub4);
client_.stubs_.push_back(&stub5);
client_.stubs_.push_back(&stub6);
FakeCommandBufferStubWithoutSurface stub7;
- stub7.share_group_.push_back(&stub3);
- stub7.share_group_.push_back(&stub4);
+ stub7.SetInSameShareGroup(&stub3);
client_.stubs_.push_back(&stub7);
Manage();
@@ -479,7 +480,7 @@ TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) {
EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_));
EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_));
EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
+ EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub7.allocation_));
}
// Test GpuMemoryManager::Manage functionality: Test changing importance of
@@ -499,10 +500,8 @@ TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) {
client_.stubs_.push_back(&stub2);
FakeCommandBufferStubWithoutSurface stub3, stub4;
- stub3.share_group_.push_back(&stub1);
- stub3.share_group_.push_back(&stub2);
- stub4.share_group_.push_back(&stub1);
- stub4.share_group_.push_back(&stub2);
+ stub3.SetInSameShareGroup(&stub2);
+ stub4.SetInSameShareGroup(&stub2);
client_.stubs_.push_back(&stub3);
client_.stubs_.push_back(&stub4);
@@ -681,7 +680,7 @@ TEST_F(GpuMemoryManagerTest, StubMemoryStatsForLastManageTests) {
FakeCommandBufferStubWithoutSurface stub2;
client_.stubs_.push_back(&stub2);
- stub2.share_group_.push_back(&stub1);
+ stub2.SetInSameShareGroup(&stub1);
Manage();
stats = StubAssignmentCollector::GetStubStatsForLastManage();
EXPECT_EQ(stats.count(&stub1), 1ul);
diff --git a/content/common/gpu/gpu_memory_tracking.h b/content/common/gpu/gpu_memory_tracking.h
index c8c7148..79bea78 100644
--- a/content/common/gpu/gpu_memory_tracking.h
+++ b/content/common/gpu/gpu_memory_tracking.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "content/common/gpu/gpu_memory_manager.h"
+#include "gpu/command_buffer/service/memory_tracking.h"
namespace content {
@@ -16,9 +17,12 @@ namespace content {
// which tracks GPU resource consumption for the entire context group.
class GpuMemoryTrackingGroup {
public:
- GpuMemoryTrackingGroup(base::ProcessId pid, GpuMemoryManager* memory_manager)
+ GpuMemoryTrackingGroup(base::ProcessId pid,
+ gpu::gles2::MemoryTracker* memory_tracker,
+ GpuMemoryManager* memory_manager)
: pid_(pid),
size_(0),
+ memory_tracker_(memory_tracker),
memory_manager_(memory_manager) {
memory_manager_->AddTrackingGroup(this);
}
@@ -43,10 +47,14 @@ class GpuMemoryTrackingGroup {
size_t GetSize() const {
return size_;
}
+ gpu::gles2::MemoryTracker* GetMemoryTracker() const {
+ return memory_tracker_;
+ }
private:
base::ProcessId pid_;
size_t size_;
+ gpu::gles2::MemoryTracker* memory_tracker_;
GpuMemoryManager* memory_manager_;
};