#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "cc/paint/image_transfer_cache_entry.h"
#include <algorithm>
#include <array>
#include <type_traits>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "cc/paint/paint_op_reader.h"
#include "cc/paint/paint_op_writer.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/core/SkYUVAInfo.h"
#include "third_party/skia/include/gpu/GpuTypes.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrYUVABackendTextures.h"
#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
#include "third_party/skia/include/gpu/graphite/Image.h"
#include "third_party/skia/include/gpu/graphite/Recorder.h"
#include "ui/gfx/color_conversion_sk_filter_cache.h"
#include "ui/gfx/hdr_metadata.h"
#include "ui/gfx/mojom/hdr_metadata.mojom.h"
namespace cc {
namespace {
struct Context { … };
void ReleaseContext(SkImages::ReleaseContext context) { … }
bool IsYUVAInfoValid(SkYUVAInfo::PlaneConfig plane_config,
SkYUVAInfo::Subsampling subsampling,
SkYUVColorSpace yuv_color_space) { … }
int NumPixmapsForYUVConfig(SkYUVAInfo::PlaneConfig plane_config) { … }
sk_sp<SkImage> MakeYUVImageFromUploadedPlanes(
GrDirectContext* gr_context,
skgpu::graphite::Recorder* graphite_recorder,
const std::vector<sk_sp<SkImage>>& plane_images,
const SkYUVAInfo& yuva_info,
sk_sp<SkColorSpace> image_color_space) { … }
base::CheckedNumeric<uint32_t> SafeSizeForPixmap(const SkPixmap& pixmap) { … }
base::CheckedNumeric<uint32_t> SafeSizeForImage(
const ClientImageTransferCacheEntry::Image& image) { … }
size_t GetAlignmentForColorType(SkColorType color_type) { … }
bool WritePixmap(PaintOpWriter& writer, const SkPixmap& pixmap) { … }
bool ReadPixmap(PaintOpReader& reader, SkPixmap& pixmap) { … }
bool WriteImage(PaintOpWriter& writer,
const ClientImageTransferCacheEntry::Image& image) { … }
sk_sp<SkImage> ReadImage(
PaintOpReader& reader,
GrDirectContext* gr_context,
skgpu::graphite::Recorder* graphite_recorder,
bool mip_mapped_for_upload,
std::optional<SkYUVAInfo>* out_yuva_info = nullptr,
std::vector<sk_sp<SkImage>>* out_yuva_plane_images = nullptr) { … }
}
size_t NumberOfPlanesForYUVDecodeFormat(YUVDecodeFormat format) { … }
ClientImageTransferCacheEntry::Image::Image() { … }
ClientImageTransferCacheEntry::Image::Image(const Image&) = default;
ClientImageTransferCacheEntry::Image&
ClientImageTransferCacheEntry::Image::operator=(const Image&) = default;
ClientImageTransferCacheEntry::Image::Image(const SkPixmap* pixmap)
: … { … }
ClientImageTransferCacheEntry::Image::Image(const SkPixmap yuva_pixmaps[],
const SkYUVAInfo& yuva_info,
const SkColorSpace* color_space)
: … { … }
ClientImageTransferCacheEntry::ClientImageTransferCacheEntry(
const Image& image,
bool needs_mips,
const std::optional<gfx::HDRMetadata>& hdr_metadata,
sk_sp<SkColorSpace> target_color_space)
: … { … }
ClientImageTransferCacheEntry::ClientImageTransferCacheEntry(
const Image& image,
const Image& gainmap_image,
const SkGainmapInfo& gainmap_info,
bool needs_mips)
: … { … }
ClientImageTransferCacheEntry::~ClientImageTransferCacheEntry() = default;
base::AtomicSequenceNumber ClientImageTransferCacheEntry::s_next_id_;
uint32_t ClientImageTransferCacheEntry::SerializedSize() const { … }
uint32_t ClientImageTransferCacheEntry::Id() const { … }
bool ClientImageTransferCacheEntry::Serialize(base::span<uint8_t> data) const { … }
void ClientImageTransferCacheEntry::ComputeSize() { … }
ServiceImageTransferCacheEntry::ServiceImageTransferCacheEntry() = default;
ServiceImageTransferCacheEntry::~ServiceImageTransferCacheEntry() = default;
ServiceImageTransferCacheEntry::ServiceImageTransferCacheEntry(
ServiceImageTransferCacheEntry&& other) = default;
ServiceImageTransferCacheEntry& ServiceImageTransferCacheEntry::operator=(
ServiceImageTransferCacheEntry&& other) = default;
bool ServiceImageTransferCacheEntry::BuildFromHardwareDecodedImage(
GrDirectContext* gr_context,
std::vector<sk_sp<SkImage>> plane_images,
SkYUVAInfo::PlaneConfig plane_config,
SkYUVAInfo::Subsampling subsampling,
SkYUVColorSpace yuv_color_space,
size_t buffer_byte_size,
bool needs_mips) { … }
size_t ServiceImageTransferCacheEntry::CachedSize() const { … }
sk_sp<SkImage> ServiceImageTransferCacheEntry::GetImageWithToneMapApplied(
float hdr_headroom,
bool needs_mips) const { … }
bool ServiceImageTransferCacheEntry::Deserialize(
GrDirectContext* gr_context,
skgpu::graphite::Recorder* graphite_recorder,
base::span<const uint8_t> data) { … }
const sk_sp<SkImage>& ServiceImageTransferCacheEntry::GetPlaneImage(
size_t index) const { … }
void ServiceImageTransferCacheEntry::EnsureMips() { … }
bool ServiceImageTransferCacheEntry::has_mips() const { … }
bool ServiceImageTransferCacheEntry::fits_on_gpu() const { … }
}