#include "gpu/ipc/service/image_decode_accelerator_stub.h"
#include <stddef.h>
#include <algorithm>
#include <new>
#include <optional>
#include <utility>
#include <vector>
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/common/context_result.h"
#include "gpu/command_buffer/common/discardable_handle.h"
#include "gpu/command_buffer/common/scheduling_priority.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/decoder_context.h"
#include "gpu/command_buffer/service/gr_shader_cache.h"
#include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/service_transfer_cache.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/command_buffer/service/shared_image/shared_image_factory.h"
#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/ipc/common/command_buffer_id.h"
#include "gpu/ipc/common/surface_handle.h"
#include "gpu/ipc/service/command_buffer_stub.h"
#include "gpu/ipc/service/gpu_channel.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/shared_image_stub.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/gpu_memory_buffer.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ui/gfx/linux/native_pixmap_dmabuf.h"
#endif
namespace gpu {
class Buffer;
#if BUILDFLAG(IS_CHROMEOS_ASH)
namespace {
struct CleanUpContext {
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
raw_ptr<SharedContextState> shared_context_state_ = nullptr;
std::unique_ptr<SkiaImageRepresentation> skia_representation_;
std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess>
skia_scoped_access_;
size_t num_callbacks_pending_;
CleanUpContext(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
raw_ptr<SharedContextState> shared_context_state,
std::unique_ptr<SkiaImageRepresentation> skia_representation,
std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess>
skia_scoped_access)
: main_task_runner_(main_task_runner),
shared_context_state_(shared_context_state),
skia_representation_(std::move(skia_representation)),
skia_scoped_access_(std::move(skia_scoped_access)),
num_callbacks_pending_(skia_representation_->NumPlanesExpected()) {}
};
void CleanUpResource(SkImages::ReleaseContext context) {
auto* clean_up_context = static_cast<CleanUpContext*>(context);
DCHECK(clean_up_context->main_task_runner_->BelongsToCurrentThread());
DCHECK(
clean_up_context->shared_context_state_->IsCurrent(nullptr));
clean_up_context->skia_scoped_access_->ApplyBackendSurfaceEndState();
CHECK_GT(clean_up_context->num_callbacks_pending_, 0u);
clean_up_context->num_callbacks_pending_--;
if (clean_up_context->num_callbacks_pending_ == 0u) {
delete clean_up_context;
}
}
}
#endif
ImageDecodeAcceleratorStub::ImageDecodeAcceleratorStub(
ImageDecodeAcceleratorWorker* worker,
GpuChannel* channel,
int32_t route_id)
: … { … }
void ImageDecodeAcceleratorStub::Shutdown() { … }
ImageDecodeAcceleratorStub::~ImageDecodeAcceleratorStub() { … }
void ImageDecodeAcceleratorStub::ScheduleImageDecode(
mojom::ScheduleImageDecodeParamsPtr params,
uint64_t release_count) { … }
void ImageDecodeAcceleratorStub::ProcessCompletedDecode(
mojom::ScheduleImageDecodeParamsPtr params_ptr,
uint64_t decode_release_count) { … }
void ImageDecodeAcceleratorStub::FinishCompletedDecode(
uint64_t decode_release_count) { … }
void ImageDecodeAcceleratorStub::OnDecodeCompleted(
gfx::Size expected_output_size,
std::unique_ptr<ImageDecodeAcceleratorWorker::DecodeResult> result) { … }
}