#include "components/viz/service/display/display_resource_provider.h"
#include <algorithm>
#include <string>
#include "base/atomic_sequence_num.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/numerics/safe_math.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/viz/common/resources/resource_sizes.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/trace_util.h"
namespace viz {
namespace {
base::AtomicSequenceNumber g_next_display_resource_provider_tracing_id;
}
DisplayResourceProvider::DisplayResourceProvider(Mode mode)
: … { … }
DisplayResourceProvider::~DisplayResourceProvider() { … }
void DisplayResourceProvider::Destroy() { … }
bool DisplayResourceProvider::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) { … }
base::WeakPtr<DisplayResourceProvider> DisplayResourceProvider::GetWeakPtr() { … }
#if BUILDFLAG(IS_ANDROID)
bool DisplayResourceProvider::IsBackedBySurfaceTexture(ResourceId id) const {
const ChildResource* resource = GetResource(id);
return resource->transferable.is_backed_by_surface_texture;
}
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
bool DisplayResourceProvider::DoesResourceWantPromotionHint(
ResourceId id) const {
const ChildResource* resource = TryGetResource(id);
return resource && resource->transferable.wants_promotion_hint;
}
#endif
bool DisplayResourceProvider::IsOverlayCandidate(ResourceId id) const { … }
SurfaceId DisplayResourceProvider::GetSurfaceId(ResourceId id) const { … }
int DisplayResourceProvider::GetChildId(ResourceId id) const { … }
bool DisplayResourceProvider::IsResourceSoftwareBacked(ResourceId id) const { … }
const gfx::Size DisplayResourceProvider::GetResourceBackedSize(
ResourceId id) const { … }
SharedImageFormat DisplayResourceProvider::GetSharedImageFormat(
ResourceId id) const { … }
const gfx::ColorSpace& DisplayResourceProvider::GetColorSpace(
ResourceId id) const { … }
bool DisplayResourceProvider::GetNeedsDetiling(ResourceId id) const { … }
const gfx::HDRMetadata& DisplayResourceProvider::GetHDRMetadata(
ResourceId id) const { … }
int DisplayResourceProvider::CreateChild(ReturnCallback return_callback,
const SurfaceId& surface_id) { … }
void DisplayResourceProvider::DestroyChild(int child_id) { … }
void DisplayResourceProvider::ReceiveFromChild(
int child_id,
const std::vector<TransferableResource>& resources) { … }
void DisplayResourceProvider::DeclareUsedResourcesFromChild(
int child,
const ResourceIdSet& resources_from_child) { … }
gpu::Mailbox DisplayResourceProvider::GetMailbox(ResourceId resource_id) const { … }
const std::unordered_map<ResourceId, ResourceId, ResourceIdHasher>&
DisplayResourceProvider::GetChildToParentMap(int child) const { … }
bool DisplayResourceProvider::InUse(ResourceId id) const { … }
const DisplayResourceProvider::ChildResource*
DisplayResourceProvider::GetResource(ResourceId id) const { … }
DisplayResourceProvider::ChildResource* DisplayResourceProvider::GetResource(
ResourceId id) { … }
const DisplayResourceProvider::ChildResource*
DisplayResourceProvider::TryGetResource(ResourceId id) const { … }
DisplayResourceProvider::ChildResource* DisplayResourceProvider::TryGetResource(
ResourceId id) { … }
void DisplayResourceProvider::OnResourceFencePassed(
ResourceFence* resource_fence,
base::flat_set<ResourceId> resources) { … }
void DisplayResourceProvider::TryReleaseResource(ResourceId id,
ChildResource* resource) { … }
bool DisplayResourceProvider::ResourceFenceHasPassed(
const ChildResource* resource) const { … }
DisplayResourceProvider::CanDeleteNowResult
DisplayResourceProvider::CanDeleteNow(const Child& child_info,
const ChildResource& resource,
DeleteStyle style) const { … }
void DisplayResourceProvider::DeleteAndReturnUnusedResourcesToChild(
ChildMap::iterator child_it,
DeleteStyle style,
const std::vector<ResourceId>& unused) { … }
void DisplayResourceProvider::DestroyChildInternal(ChildMap::iterator it,
DeleteStyle style) { … }
void DisplayResourceProvider::TryFlushBatchedResources() { … }
void DisplayResourceProvider::SetBatchReturnResources(bool batch) { … }
void DisplayResourceProvider::SetAllowAccessToGPUThread(bool allow) { … }
DisplayResourceProvider::ScopedReadLockSharedImage::ScopedReadLockSharedImage(
DisplayResourceProvider* resource_provider,
ResourceId resource_id)
: … { … }
DisplayResourceProvider::ScopedReadLockSharedImage::ScopedReadLockSharedImage(
ScopedReadLockSharedImage&& other) { … }
DisplayResourceProvider::ScopedReadLockSharedImage::
~ScopedReadLockSharedImage() { … }
DisplayResourceProvider::ScopedReadLockSharedImage&
DisplayResourceProvider::ScopedReadLockSharedImage::operator=(
ScopedReadLockSharedImage&& other) { … }
void DisplayResourceProvider::ScopedReadLockSharedImage::SetReleaseFence(
gfx::GpuFenceHandle release_fence) { … }
bool DisplayResourceProvider::ScopedReadLockSharedImage::HasReadLockFence()
const { … }
void DisplayResourceProvider::ScopedReadLockSharedImage::Reset() { … }
DisplayResourceProvider::ScopedBatchReturnResources::ScopedBatchReturnResources(
DisplayResourceProvider* resource_provider,
bool allow_access_to_gpu_thread)
: … { … }
DisplayResourceProvider::ScopedBatchReturnResources::
~ScopedBatchReturnResources() { … }
DisplayResourceProvider::Child::Child() = default;
DisplayResourceProvider::Child::Child(Child&& other) = default;
DisplayResourceProvider::Child& DisplayResourceProvider::Child::operator=(
Child&& other) = default;
DisplayResourceProvider::Child::~Child() = default;
DisplayResourceProvider::ChildResource::ChildResource(
int child_id,
const TransferableResource& transferable)
: … { … }
DisplayResourceProvider::ChildResource::ChildResource(ChildResource&& other) =
default;
DisplayResourceProvider::ChildResource::~ChildResource() = default;
void DisplayResourceProvider::ChildResource::UpdateSyncToken(
const gpu::SyncToken& sync_token) { … }
}