#include "components/viz/service/display_embedder/skia_output_device.h"
#include <algorithm>
#include <utility>
#include "base/check_op.h"
#include "base/notreached.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/skia_utils.h"
#include "services/tracing/public/cpp/perfetto/flow_event_utils.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/skia/include/gpu/graphite/Context.h"
#include "third_party/skia/include/gpu/graphite/Recording.h"
#include "third_party/skia/include/private/chromium/GrDeferredDisplayList.h"
#include "ui/gfx/gpu_fence.h"
#include "ui/gfx/presentation_feedback.h"
#if BUILDFLAG(IS_WIN)
#include "components/viz/service/display/dc_layer_overlay.h"
#endif
namespace viz {
namespace {
void ReportLatency(const gfx::SwapTimings& timings,
std::vector<ui::LatencyInfo> latency_info) { … }
}
SkiaOutputDevice::ScopedPaint::ScopedPaint(
std::vector<GrBackendSemaphore> end_semaphores,
SkiaOutputDevice* device,
SkSurface* sk_surface)
: … { … }
SkiaOutputDevice::ScopedPaint::~ScopedPaint() { … }
SkCanvas* SkiaOutputDevice::ScopedPaint::GetCanvas() { … }
GrSemaphoresSubmitted SkiaOutputDevice::ScopedPaint::Flush(
VulkanContextProvider* vulkan_context_provider,
std::vector<GrBackendSemaphore> end_semaphores,
base::OnceClosure on_finished) { … }
bool SkiaOutputDevice::ScopedPaint::Wait(
int num_semaphores,
const GrBackendSemaphore wait_semaphores[],
bool delete_semaphores_after_wait) { … }
bool SkiaOutputDevice::ScopedPaint::Draw(
sk_sp<const GrDeferredDisplayList> ddl) { … }
bool SkiaOutputDevice::ScopedPaint::Draw(
std::unique_ptr<skgpu::graphite::Recording> graphite_recording,
base::OnceClosure on_finished) { … }
SkiaOutputDevice::SkiaOutputDevice(
GrDirectContext* gr_context,
skgpu::graphite::Context* graphite_context,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback,
ReleaseOverlaysCallback release_overlays_callback)
: … { … }
SkiaOutputDevice::~SkiaOutputDevice() = default;
std::unique_ptr<SkiaOutputDevice::ScopedPaint>
SkiaOutputDevice::BeginScopedPaint() { … }
void SkiaOutputDevice::SetViewportSize(const gfx::Size& viewport_size) { … }
void SkiaOutputDevice::Submit(bool sync_cpu, base::OnceClosure callback) { … }
void SkiaOutputDevice::ScheduleOverlays(
SkiaOutputSurface::OverlayList overlays) { … }
void SkiaOutputDevice::EnsureBackbuffer() { … }
void SkiaOutputDevice::DiscardBackbuffer() { … }
void SkiaOutputDevice::SetDrawTimings(base::TimeTicks submitted,
base::TimeTicks started) { … }
void SkiaOutputDevice::SetDependencyTimings(base::TimeTicks task_ready) { … }
void SkiaOutputDevice::StartSwapBuffers(BufferPresentedCallback feedback) { … }
void SkiaOutputDevice::FinishSwapBuffers(
gfx::SwapCompletionResult result,
const gfx::Size& size,
OutputSurfaceFrame frame,
const std::optional<gfx::Rect>& damage_area,
std::vector<gpu::Mailbox> released_overlays) { … }
void SkiaOutputDevice::SwapBuffersSkipped(BufferPresentedCallback feedback,
OutputSurfaceFrame frame) { … }
SkiaOutputDevice::SwapInfo::SwapInfo(
uint64_t swap_id,
SkiaOutputDevice::BufferPresentedCallback feedback,
base::TimeTicks viz_scheduled_draw,
base::TimeTicks gpu_started_draw,
base::TimeTicks gpu_task_ready)
: … { … }
SkiaOutputDevice::SwapInfo::SwapInfo(SwapInfo&& other) = default;
SkiaOutputDevice::SwapInfo::~SwapInfo() = default;
uint64_t SkiaOutputDevice::SwapInfo::SwapId() { … }
const gpu::SwapBuffersCompleteParams& SkiaOutputDevice::SwapInfo::Complete(
gfx::SwapCompletionResult result,
const std::optional<gfx::Rect>& damage_rect,
std::vector<gpu::Mailbox> released_overlays,
int64_t swap_trace_id) { … }
void SkiaOutputDevice::SwapInfo::CallFeedback() { … }
SkCanvas* SkiaOutputDevice::GetCanvas(SkSurface* sk_surface) { … }
GrSemaphoresSubmitted SkiaOutputDevice::Flush(
SkSurface* sk_surface,
VulkanContextProvider* vulkan_context_provider,
std::vector<GrBackendSemaphore> end_semaphores,
base::OnceClosure on_finished) { … }
bool SkiaOutputDevice::Wait(SkSurface* sk_surface,
int num_semaphores,
const GrBackendSemaphore wait_semaphores[],
bool delete_semaphores_after_wait) { … }
bool SkiaOutputDevice::Draw(SkSurface* sk_surface,
sk_sp<const GrDeferredDisplayList> ddl) { … }
bool SkiaOutputDevice::Draw(
SkSurface* sk_surface,
std::unique_ptr<skgpu::graphite::Recording> graphite_recording,
base::OnceClosure on_finished) { … }
}