#include "third_party/blink/renderer/platform/graphics/canvas_resource.h"
#include <string>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/viz/common/resources/bitmap_allocation.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/client/webgpu_interface.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_dispatcher.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_gpu.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/skia/include/core/SkAlphaType.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/gpu/GpuTypes.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
#include "third_party/skia/include/gpu/gl/GrGLTypes.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/color_space.h"
namespace blink {
CanvasResource::CanvasResource(base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality,
const SkColorInfo& info)
: … { … }
CanvasResource::~CanvasResource() { … }
void CanvasResource::Release() { … }
gpu::InterfaceBase* CanvasResource::InterfaceBase() const { … }
gpu::gles2::GLES2Interface* CanvasResource::ContextGL() const { … }
gpu::raster::RasterInterface* CanvasResource::RasterInterface() const { … }
gpu::webgpu::WebGPUInterface* CanvasResource::WebGPUInterface() const { … }
void CanvasResource::WaitSyncToken(const gpu::SyncToken& sync_token) { … }
static void ReleaseFrameResources(
base::WeakPtr<CanvasResourceProvider> resource_provider,
viz::ReleaseCallback&& viz_release_callback,
scoped_refptr<CanvasResource>&& resource,
const gpu::SyncToken& sync_token,
bool lost_resource) { … }
bool CanvasResource::PrepareTransferableResource(
viz::TransferableResource* out_resource,
CanvasResource::ReleaseCallback* out_callback,
bool needs_verified_synctoken) { … }
bool CanvasResource::PrepareAcceleratedTransferableResourceFromClientSI(
viz::TransferableResource* out_resource,
bool needs_verified_synctoken) { … }
SkImageInfo CanvasResource::CreateSkImageInfo() const { … }
viz::SharedImageFormat CanvasResource::GetSharedImageFormat() const { … }
gfx::ColorSpace CanvasResource::GetColorSpace() const { … }
CanvasResourceSharedBitmap::CanvasResourceSharedBitmap(
const SkImageInfo& info,
base::WeakPtr<CanvasResourceProvider> provider,
base::WeakPtr<WebGraphicsSharedImageInterfaceProvider>
shared_image_interface_provider,
cc::PaintFlags::FilterQuality filter_quality)
: … { … }
CanvasResourceSharedBitmap::~CanvasResourceSharedBitmap() { … }
bool CanvasResourceSharedBitmap::IsValid() const { … }
gfx::Size CanvasResourceSharedBitmap::Size() const { … }
scoped_refptr<StaticBitmapImage> CanvasResourceSharedBitmap::Bitmap() { … }
scoped_refptr<CanvasResourceSharedBitmap> CanvasResourceSharedBitmap::Create(
const SkImageInfo& info,
base::WeakPtr<CanvasResourceProvider> provider,
base::WeakPtr<WebGraphicsSharedImageInterfaceProvider>
shared_image_interface_provider,
cc::PaintFlags::FilterQuality filter_quality) { … }
bool CanvasResourceSharedBitmap::PrepareUnacceleratedTransferableResource(
viz::TransferableResource* out_resource) { … }
void CanvasResourceSharedBitmap::NotifyResourceLost() { … }
void CanvasResourceSharedBitmap::TakeSkImage(sk_sp<SkImage> image) { … }
CanvasResourceSharedImage::CanvasResourceSharedImage(
const SkImageInfo& info,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality,
bool is_origin_top_left,
bool is_accelerated,
uint32_t shared_image_usage_flags)
: … { … }
scoped_refptr<CanvasResourceSharedImage> CanvasResourceSharedImage::Create(
const SkImageInfo& info,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality,
bool is_origin_top_left,
bool is_accelerated,
uint32_t shared_image_usage_flags) { … }
bool CanvasResourceSharedImage::IsValid() const { … }
void CanvasResourceSharedImage::BeginReadAccess() { … }
void CanvasResourceSharedImage::EndReadAccess() { … }
void CanvasResourceSharedImage::BeginWriteAccess() { … }
void CanvasResourceSharedImage::EndWriteAccess() { … }
GrBackendTexture CanvasResourceSharedImage::CreateGrTexture() const { … }
CanvasResourceSharedImage::~CanvasResourceSharedImage() { … }
void CanvasResourceSharedImage::WillDraw() { … }
void CanvasResourceSharedImage::OnBitmapImageDestroyed(
scoped_refptr<CanvasResourceSharedImage> resource,
bool has_read_ref_on_texture,
const gpu::SyncToken& sync_token,
bool is_lost) { … }
void CanvasResourceSharedImage::Transfer() { … }
scoped_refptr<StaticBitmapImage> CanvasResourceSharedImage::Bitmap() { … }
void CanvasResourceSharedImage::CopyRenderingResultsToGpuMemoryBuffer(
const sk_sp<SkImage>& image) { … }
scoped_refptr<gpu::ClientSharedImage>
CanvasResourceSharedImage::GetClientSharedImage() { … }
const scoped_refptr<gpu::ClientSharedImage>&
CanvasResourceSharedImage::GetClientSharedImage() const { … }
const gpu::SyncToken
CanvasResourceSharedImage::GetSyncTokenWithOptionalVerification(
bool needs_verified_token) { … }
void CanvasResourceSharedImage::NotifyResourceLost() { … }
base::WeakPtr<WebGraphicsContext3DProviderWrapper>
CanvasResourceSharedImage::ContextProviderWrapper() const { … }
void CanvasResourceSharedImage::OnMemoryDump(
base::trace_event::ProcessMemoryDump* pmd,
const std::string& parent_path,
size_t bytes_per_pixel) const { … }
scoped_refptr<ExternalCanvasResource> ExternalCanvasResource::Create(
scoped_refptr<gpu::ClientSharedImage> client_si,
const viz::TransferableResource& transferable_resource,
viz::ReleaseCallback release_callback,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality,
bool is_origin_top_left) { … }
ExternalCanvasResource::~ExternalCanvasResource() { … }
bool ExternalCanvasResource::IsValid() const { … }
void ExternalCanvasResource::TakeSkImage(sk_sp<SkImage> image) { … }
scoped_refptr<StaticBitmapImage> ExternalCanvasResource::Bitmap() { … }
const gpu::SyncToken
ExternalCanvasResource::GetSyncTokenWithOptionalVerification(
bool needs_verified_token) { … }
void ExternalCanvasResource::GenOrFlushSyncToken() { … }
base::WeakPtr<WebGraphicsContext3DProviderWrapper>
ExternalCanvasResource::ContextProviderWrapper() const { … }
bool ExternalCanvasResource::
PrepareAcceleratedTransferableResourceWithoutClientSI(
viz::TransferableResource* out_resource) { … }
ExternalCanvasResource::ExternalCanvasResource(
scoped_refptr<gpu::ClientSharedImage> client_si,
const viz::TransferableResource& transferable_resource,
viz::ReleaseCallback out_callback,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality,
bool is_origin_top_left)
: … { … }
scoped_refptr<CanvasResourceSwapChain> CanvasResourceSwapChain::Create(
const SkImageInfo& info,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality) { … }
CanvasResourceSwapChain::~CanvasResourceSwapChain() { … }
bool CanvasResourceSwapChain::IsValid() const { … }
void CanvasResourceSwapChain::TakeSkImage(sk_sp<SkImage> image) { … }
scoped_refptr<StaticBitmapImage> CanvasResourceSwapChain::Bitmap() { … }
scoped_refptr<gpu::ClientSharedImage>
CanvasResourceSwapChain::GetClientSharedImage() { … }
const gpu::SyncToken
CanvasResourceSwapChain::GetSyncTokenWithOptionalVerification(
bool needs_verified_token) { … }
void CanvasResourceSwapChain::PresentSwapChain() { … }
base::WeakPtr<WebGraphicsContext3DProviderWrapper>
CanvasResourceSwapChain::ContextProviderWrapper() const { … }
CanvasResourceSwapChain::CanvasResourceSwapChain(
const SkImageInfo& info,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper,
base::WeakPtr<CanvasResourceProvider> provider,
cc::PaintFlags::FilterQuality filter_quality)
: … { … }
}