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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_CLIENT_H_ 6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_CLIENT_H_ 7 8 #if defined(ENABLE_GPU) 9 10 #include <list> 11 12 #include "base/basictypes.h" 13 #include "content/common/content_export.h" 14 #include "content/common/gpu/gpu_memory_allocation.h" 15 #include "gpu/command_buffer/service/memory_tracking.h" 16 #include "ui/gfx/size.h" 17 18 namespace content { 19 20 class GpuMemoryManager; 21 class GpuMemoryTrackingGroup; 22 23 // The interface that the GPU memory manager uses to manipulate a client (to 24 // send it allocation information and query its properties). 25 class CONTENT_EXPORT GpuMemoryManagerClient { 26 public: 27 virtual ~GpuMemoryManagerClient() {} 28 29 // Returns surface size. 30 virtual gfx::Size GetSurfaceSize() const = 0; 31 32 // Returns the memory tracker for this stub. 33 virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const = 0; 34 35 // Sets buffer usage depending on Memory Allocation 36 virtual void SetMemoryAllocation( 37 const GpuMemoryAllocation& allocation) = 0; 38 39 // Returns in bytes the total amount of GPU memory for the GPU which this 40 // context is currently rendering on. Returns false if no extension exists 41 // to get the exact amount of GPU memory. 42 virtual bool GetTotalGpuMemory(uint64* bytes) = 0; 43 }; 44 45 // The state associated with a GPU memory manager client. This acts as the 46 // handle through which the client interacts with the GPU memory manager. 47 class CONTENT_EXPORT GpuMemoryManagerClientState { 48 public: 49 ~GpuMemoryManagerClientState(); 50 void SetVisible(bool visible); 51 void SetManagedMemoryStats(const GpuManagedMemoryStats& stats); 52 53 private: 54 friend class GpuMemoryManager; 55 56 GpuMemoryManagerClientState(GpuMemoryManager* memory_manager, 57 GpuMemoryManagerClient* client, 58 GpuMemoryTrackingGroup* tracking_group, 59 bool has_surface, 60 bool visible); 61 62 // The memory manager this client is hanging off of. 63 GpuMemoryManager* memory_manager_; 64 65 // The client to send allocations to. 66 GpuMemoryManagerClient* client_; 67 68 // The tracking group for this client. 69 GpuMemoryTrackingGroup* tracking_group_; 70 71 // Offscreen commandbuffers will not have a surface. 72 const bool has_surface_; 73 74 // Whether or not this client is visible. 75 bool visible_; 76 77 // If the client has a surface, then this is an iterator in the 78 // clients_visible_mru_ if this client is visible and 79 // clients_nonvisible_mru_ if this is non-visible. Otherwise this is an 80 // iterator in clients_nonsurface_. 81 std::list<GpuMemoryManagerClientState*>::iterator list_iterator_; 82 bool list_iterator_valid_; 83 84 // Statistics about memory usage. 85 GpuManagedMemoryStats managed_memory_stats_; 86 bool managed_memory_stats_received_; 87 88 // When managed_memory_stats_.bytes_nicetohave leaves the range 89 // [low_, high_], then re-adjust memory limits. 90 uint64 bytes_nicetohave_limit_low_; 91 uint64 bytes_nicetohave_limit_high_; 92 93 // The allocation for this client, used transiently during memory policy 94 // calculation. 95 uint64 bytes_allocation_when_visible_; 96 uint64 bytes_allocation_when_nonvisible_; 97 98 // The ideal allocation for this client for three performance levels, used 99 // transiently during memory policy calculation. 100 uint64 bytes_allocation_ideal_nicetohave_; 101 uint64 bytes_allocation_ideal_required_; 102 uint64 bytes_allocation_ideal_minimum_; 103 104 // Set to disable allocating a frontbuffer or to disable allocations 105 // for clients that don't have surfaces. 106 bool hibernated_; 107 }; 108 109 } // namespace content 110 111 #endif 112 113 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_CLIENT_H_ 114