#include "cc/resources/resource_pool.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include "base/atomic_sequence_num.h"
#include "base/containers/contains.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "cc/base/container_util.h"
#include "components/viz/client/client_resource_provider.h"
#include "components/viz/common/gpu/raster_context_provider.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/mailbox.h"
MemoryAllocatorDump;
MemoryDumpLevelOfDetail;
namespace cc {
ResourcePool::GpuBacking::GpuBacking() = default;
ResourcePool::GpuBacking::~GpuBacking() = default;
ResourcePool::SoftwareBacking::SoftwareBacking() = default;
ResourcePool::SoftwareBacking::~SoftwareBacking() = default;
namespace {
base::AtomicSequenceNumber g_next_tracing_id;
bool ResourceMeetsSizeRequirements(const gfx::Size& requested_size,
const gfx::Size& actual_size,
bool disallow_non_exact_reuse) { … }
}
constexpr base::TimeDelta ResourcePool::kDefaultExpirationDelay;
constexpr base::TimeDelta ResourcePool::kDefaultMaxFlushDelay;
ResourcePool::ResourcePool(
viz::ClientResourceProvider* resource_provider,
viz::RasterContextProvider* context_provider,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const base::TimeDelta& expiration_delay,
bool disallow_non_exact_reuse)
: … { … }
ResourcePool::~ResourcePool() { … }
ResourcePool::PoolResource* ResourcePool::ReuseResource(
const gfx::Size& size,
viz::SharedImageFormat format,
const gfx::ColorSpace& color_space) { … }
ResourcePool::PoolResource* ResourcePool::CreateResource(
const gfx::Size& size,
viz::SharedImageFormat format,
const gfx::ColorSpace& color_space) { … }
ResourcePool::InUsePoolResource ResourcePool::AcquireResource(
const gfx::Size& size,
viz::SharedImageFormat format,
const gfx::ColorSpace& color_space,
const std::string& debug_name) { … }
ResourcePool::InUsePoolResource
ResourcePool::TryAcquireResourceForPartialRaster(
uint64_t new_content_id,
const gfx::Rect& new_invalidated_rect,
uint64_t previous_content_id,
gfx::Rect* total_invalidated_rect,
const gfx::ColorSpace& raster_color_space,
const std::string& debug_name) { … }
void ResourcePool::OnBackingAllocated(PoolResource* resource) { … }
void ResourcePool::OnResourceReleased(size_t unique_id,
const gpu::SyncToken& sync_token,
bool lost) { … }
bool ResourcePool::PrepareForExport(
const InUsePoolResource& in_use_resource,
viz::TransferableResource::ResourceSource resource_source) { … }
void ResourcePool::InvalidateResources() { … }
void ResourcePool::ReleaseResource(InUsePoolResource in_use_resource) { … }
void ResourcePool::OnContentReplaced(const InUsePoolResource& in_use_resource,
uint64_t content_id) { … }
void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
size_t max_resource_count) { … }
void ResourcePool::ReduceResourceUsage() { … }
bool ResourcePool::ResourceUsageTooHigh() { … }
void ResourcePool::DeleteResource(std::unique_ptr<PoolResource> resource) { … }
void ResourcePool::UpdateResourceContentIdAndInvalidation(
PoolResource* resource,
uint64_t new_content_id,
const gfx::Rect& new_invalidated_rect) { … }
void ResourcePool::DidFinishUsingResource(
std::unique_ptr<PoolResource> resource) { … }
void ResourcePool::ScheduleEvictExpiredResourcesIn(
base::TimeDelta time_from_now) { … }
void ResourcePool::EvictExpiredResources() { … }
void ResourcePool::EvictResourcesNotUsedSince(base::TimeTicks time_limit) { … }
base::TimeTicks ResourcePool::GetUsageTimeForLRUResource() const { … }
void ResourcePool::FlushEvictedResources() { … }
bool ResourcePool::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) { … }
void ResourcePool::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) { … }
ResourcePool::PoolResource::PoolResource(ResourcePool* resource_pool,
size_t unique_id,
const gfx::Size& size,
viz::SharedImageFormat format,
const gfx::ColorSpace& color_space)
: … { … }
ResourcePool::PoolResource::~PoolResource() = default;
void ResourcePool::PoolResource::OnMemoryDump(
base::trace_event::ProcessMemoryDump* pmd,
int tracing_id,
const viz::ClientResourceProvider* resource_provider,
bool is_free,
bool is_busy) const { … }
}