#include "gpu/command_buffer/service/shared_image/wrapped_graphite_texture_backing.h"
#include <utility>
#include "base/logging.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/shared_image/copy_image_plane.h"
#include "gpu/command_buffer/service/shared_image/gl_texture_passthrough_fallback_image_representation.h"
#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"
#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkSurfaceProps.h"
#include "third_party/skia/include/gpu/graphite/BackendTexture.h"
#include "third_party/skia/include/gpu/graphite/Context.h"
#include "third_party/skia/include/gpu/graphite/Image.h"
#include "third_party/skia/include/gpu/graphite/Recorder.h"
#include "third_party/skia/include/gpu/graphite/Recording.h"
#include "third_party/skia/include/gpu/graphite/Surface.h"
#include "third_party/skia/include/gpu/graphite/TextureInfo.h"
#include "ui/gfx/geometry/skia_conversions.h"
#if BUILDFLAG(SKIA_USE_DAWN)
#include "gpu/command_buffer/service/dawn_context_provider.h"
#include "gpu/command_buffer/service/shared_image/dawn_fallback_image_representation.h"
#endif
namespace gpu {
namespace {
struct ReadPixelsContext { … };
void OnReadPixelsDone(
void* raw_ctx,
std::unique_ptr<const SkImage::AsyncReadResult> async_result) { … }
}
class WrappedGraphiteTextureBacking::SkiaGraphiteImageRepresentationImpl
: public SkiaGraphiteImageRepresentation { … };
WrappedGraphiteTextureBacking::WrappedGraphiteTextureBacking(
base::PassKey<WrappedSkImageBackingFactory>,
const Mailbox& mailbox,
viz::SharedImageFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
GrSurfaceOrigin surface_origin,
SkAlphaType alpha_type,
gpu::SharedImageUsageSet usage,
std::string debug_label,
scoped_refptr<SharedContextState> context_state,
const bool thread_safe)
: … { … }
WrappedGraphiteTextureBacking::~WrappedGraphiteTextureBacking() { … }
bool WrappedGraphiteTextureBacking::Initialize() { … }
bool WrappedGraphiteTextureBacking::InitializeWithData(
base::span<const uint8_t> pixels) { … }
SharedImageBackingType WrappedGraphiteTextureBacking::GetType() const { … }
void WrappedGraphiteTextureBacking::Update(
std::unique_ptr<gfx::GpuFence> in_fence) { … }
bool WrappedGraphiteTextureBacking::UploadFromMemory(
const std::vector<SkPixmap>& pixmaps) { … }
bool WrappedGraphiteTextureBacking::ReadbackToMemory(
const std::vector<SkPixmap>& pixmaps) { … }
bool WrappedGraphiteTextureBacking::InsertRecordingAndSubmit() { … }
const std::vector<scoped_refptr<WrappedGraphiteTextureHolder>>&
WrappedGraphiteTextureBacking::GetWrappedGraphiteTextureHolders() { … }
std::vector<skgpu::graphite::BackendTexture>
WrappedGraphiteTextureBacking::GetGraphiteBackendTextures() { … }
std::unique_ptr<SkiaGraphiteImageRepresentation>
WrappedGraphiteTextureBacking::ProduceSkiaGraphite(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) { … }
#if BUILDFLAG(SKIA_USE_DAWN)
std::unique_ptr<GLTexturePassthroughImageRepresentation>
WrappedGraphiteTextureBacking::ProduceGLTexturePassthrough(
SharedImageManager* manager,
MemoryTypeTracker* tracker) { … }
std::unique_ptr<DawnImageRepresentation>
WrappedGraphiteTextureBacking::ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
const wgpu::Device& device,
wgpu::BackendType backend_type,
std::vector<wgpu::TextureFormat> view_formats,
scoped_refptr<SharedContextState> context_state) { … }
#endif
}