summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.cc24
-rw-r--r--content/common/gpu/gpu_memory_manager.cc30
-rw-r--r--content/common/gpu/gpu_memory_manager.h13
3 files changed, 56 insertions, 11 deletions
diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc
index e83be95..15302bf 100644
--- a/content/common/gpu/gpu_command_buffer_stub.cc
+++ b/content/common/gpu/gpu_command_buffer_stub.cc
@@ -23,6 +23,7 @@
#include "content/public/common/content_client.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
+#include "gpu/command_buffer/service/memory_tracking.h"
#include "net/disk_cache/hash.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_switches.h"
@@ -33,6 +34,23 @@
namespace {
+// The GpuCommandBufferMemoryTracker class provides a bridge between the
+// ContextGroup's memory type managers and the GpuMemoryManager class.
+class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker {
+ public:
+ GpuCommandBufferMemoryTracker(GpuMemoryManager* gpu_memory_manager)
+ : gpu_memory_manager_(gpu_memory_manager) {}
+ void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) {
+ gpu_memory_manager_->TrackMemoryAllocatedChange(old_size, new_size);
+ }
+
+ private:
+ ~GpuCommandBufferMemoryTracker() {}
+ GpuMemoryManager* gpu_memory_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker);
+};
+
// FastSetActiveURL will shortcut the expensive call to SetActiveURL when the
// url_hash matches.
void FastSetActiveURL(const GURL& url, size_t url_hash) {
@@ -103,7 +121,11 @@ GpuCommandBufferStub::GpuCommandBufferStub(
if (share_group) {
context_group_ = share_group->context_group_;
} else {
- context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true);
+ context_group_ = new gpu::gles2::ContextGroup(
+ mailbox_manager,
+ new GpuCommandBufferMemoryTracker(
+ channel->gpu_channel_manager()->gpu_memory_manager()),
+ true);
}
if (surface_id != 0)
surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState(
diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc
index 39b8e48..1088328 100644
--- a/content/common/gpu/gpu_memory_manager.cc
+++ b/content/common/gpu/gpu_memory_manager.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include "base/bind.h"
+#include "base/debug/trace_event.h"
#include "base/message_loop.h"
#include "content/common/gpu/gpu_command_buffer_stub.h"
#include "content/common/gpu/gpu_memory_allocation.h"
@@ -70,7 +71,8 @@ GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client,
manage_immediate_scheduled_(false),
max_surfaces_with_frontbuffer_soft_limit_(
max_surfaces_with_frontbuffer_soft_limit),
- peak_assigned_allocation_sum_(0) {
+ bytes_allocated_current_(0),
+ bytes_allocated_historical_max_(0) {
}
GpuMemoryManager::~GpuMemoryManager() {
@@ -115,6 +117,29 @@ size_t GpuMemoryManager::GetAvailableGpuMemory() const {
return kMaximumAllocationForTabs;
}
+void GpuMemoryManager::TrackMemoryAllocatedChange(size_t old_size,
+ size_t new_size)
+{
+ if (new_size < old_size) {
+ size_t delta = old_size - new_size;
+ DCHECK(bytes_allocated_current_ >= delta);
+ bytes_allocated_current_ -= delta;
+ }
+ else {
+ size_t delta = new_size - old_size;
+ bytes_allocated_current_ += delta;
+ if (bytes_allocated_current_ > bytes_allocated_historical_max_) {
+ bytes_allocated_historical_max_ = bytes_allocated_current_;
+ }
+ }
+ if (new_size != old_size) {
+ TRACE_COUNTER_ID1("GpuMemoryManager",
+ "GpuMemoryUsage",
+ this,
+ bytes_allocated_current_);
+ }
+}
+
// The current Manage algorithm simply classifies contexts (stubs) into
// "foreground", "background", or "hibernated" categories.
// For each of these three categories, there are predefined memory allocation
@@ -278,9 +303,6 @@ void GpuMemoryManager::Manage() {
++it) {
assigned_allocation_sum += it->second.allocation.gpu_resource_size_in_bytes;
}
-
- if (assigned_allocation_sum > peak_assigned_allocation_sum_)
- peak_assigned_allocation_sum_ = assigned_allocation_sum;
}
#endif
diff --git a/content/common/gpu/gpu_memory_manager.h b/content/common/gpu/gpu_memory_manager.h
index 21a96de..d3268ca 100644
--- a/content/common/gpu/gpu_memory_manager.h
+++ b/content/common/gpu/gpu_memory_manager.h
@@ -93,11 +93,9 @@ class CONTENT_EXPORT GpuMemoryManager :
// other internal but non GpuMemoryManager managed sources, etc.
size_t GetAvailableGpuMemory() const;
- // GetPeakAssignedAllocationSum() will return the historical max value for the
- // sum of all assigned client allocations (ie, peak system memory allocation).
- size_t peak_assigned_allocation_sum() const {
- return peak_assigned_allocation_sum_;
- }
+ // Track a change in memory allocated by any context
+ void TrackMemoryAllocatedChange(size_t old_size, size_t new_size);
+
private:
friend class GpuMemoryManagerTest;
@@ -117,7 +115,10 @@ class CONTENT_EXPORT GpuMemoryManager :
size_t max_surfaces_with_frontbuffer_soft_limit_;
StubMemoryStatMap stub_memory_stats_for_last_manage_;
- size_t peak_assigned_allocation_sum_;
+
+ // The current total memory usage, and historical maximum memory usage
+ size_t bytes_allocated_current_;
+ size_t bytes_allocated_historical_max_;
DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
};