#include "components/paint_preview/player/player_compositor_delegate.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/files/file_path.h"
#include "base/memory/memory_pressure_monitor.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "base/unguessable_token.h"
#include "base/version.h"
#include "components/paint_preview/browser/paint_preview_base_service.h"
#include "components/paint_preview/browser/warm_compositor.h"
#include "components/paint_preview/common/proto/paint_preview.pb.h"
#include "components/paint_preview/common/recording_map.h"
#include "components/paint_preview/common/serialized_recording.h"
#include "components/paint_preview/common/version.h"
#include "components/paint_preview/public/paint_preview_compositor_client.h"
#include "components/paint_preview/public/paint_preview_compositor_service.h"
#include "components/services/paint_preview_compositor/public/mojom/paint_preview_compositor.mojom.h"
#include "components/version_info/version_info.h"
#include "mojo/public/cpp/base/proto_wrapper.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/rect.h"
namespace paint_preview {
namespace {
std::pair<base::UnguessableToken, std::unique_ptr<HitTester>> BuildHitTester(
const PaintPreviewFrameProto& proto) { … }
std::unique_ptr<
base::flat_map<base::UnguessableToken, std::unique_ptr<HitTester>>>
BuildHitTesters(std::unique_ptr<PaintPreviewProto> proto) { … }
paint_preview::mojom::PaintPreviewBeginCompositeRequestPtr
PrepareCompositeRequest(std::unique_ptr<CaptureResult> capture_result) { … }
}
PlayerCompositorDelegate::PlayerCompositorDelegate()
: … { … }
PlayerCompositorDelegate::~PlayerCompositorDelegate() { … }
void PlayerCompositorDelegate::Initialize(
PaintPreviewBaseService* paint_preview_service,
const GURL& expected_url,
const DirectoryKey& key,
bool main_frame_mode,
CompositorErrorCallback compositor_error,
base::TimeDelta timeout_duration,
std::array<size_t, PressureLevelCount::kLevels> max_requests_map) { … }
void PlayerCompositorDelegate::SetCaptureResult(
std::unique_ptr<CaptureResult> capture_result) { … }
void PlayerCompositorDelegate::InitializeWithFakeServiceForTest(
PaintPreviewBaseService* paint_preview_service,
const GURL& expected_url,
const DirectoryKey& key,
bool main_frame_mode,
CompositorErrorCallback compositor_error,
base::TimeDelta timeout_duration,
std::array<size_t, PressureLevelCount::kLevels> max_requests_map,
std::unique_ptr<PaintPreviewCompositorService, base::OnTaskRunnerDeleter>
fake_compositor_service) { … }
void PlayerCompositorDelegate::InitializeInternal(
PaintPreviewBaseService* paint_preview_service,
const GURL& expected_url,
const DirectoryKey& key,
bool main_frame_mode,
CompositorErrorCallback compositor_error,
base::TimeDelta timeout_duration,
std::array<size_t, PressureLevelCount::kLevels> max_requests_map) { … }
int32_t PlayerCompositorDelegate::RequestBitmap(
const std::optional<base::UnguessableToken>& frame_guid,
const gfx::Rect& clip_rect,
float scale_factor,
base::OnceCallback<void(mojom::PaintPreviewCompositor::BitmapStatus,
const SkBitmap&)> callback,
bool run_callback_on_default_task_runner) { … }
bool PlayerCompositorDelegate::CancelBitmapRequest(int32_t request_id) { … }
void PlayerCompositorDelegate::CancelAllBitmapRequests() { … }
std::vector<const GURL*> PlayerCompositorDelegate::OnClick(
const base::UnguessableToken& frame_guid,
const gfx::Rect& rect) { … }
void PlayerCompositorDelegate::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { … }
base::MemoryPressureMonitor*
PlayerCompositorDelegate::memory_pressure_monitor() { … }
void PlayerCompositorDelegate::OnCompositorReadyStatusAdapter(
mojom::PaintPreviewCompositor::BeginCompositeStatus status,
mojom::PaintPreviewBeginCompositeResponsePtr composite_response) { … }
void PlayerCompositorDelegate::OnCompositorServiceDisconnected() { … }
void PlayerCompositorDelegate::OnCompositorClientCreated(
const GURL& expected_url,
const DirectoryKey& key) { … }
void PlayerCompositorDelegate::OnProtoAvailable(
const GURL& expected_url,
PaintPreviewFileMixin::ProtoReadStatus proto_status,
std::unique_ptr<PaintPreviewProto> proto) { … }
void PlayerCompositorDelegate::ValidateProtoAndLoadAXTree(
const GURL& expected_url) { … }
void PlayerCompositorDelegate::OnAXTreeUpdateAvailable(
std::unique_ptr<ui::AXTreeUpdate> update) { … }
void PlayerCompositorDelegate::SendCompositeRequest(
mojom::PaintPreviewBeginCompositeRequestPtr begin_composite_request) { … }
void PlayerCompositorDelegate::OnHitTestersBuilt(
std::unique_ptr<base::flat_map<base::UnguessableToken,
std::unique_ptr<HitTester>>> hit_testers) { … }
void PlayerCompositorDelegate::OnCompositorClientDisconnected() { … }
void PlayerCompositorDelegate::OnCompositorTimeout() { … }
void PlayerCompositorDelegate::ProcessBitmapRequestsFromQueue() { … }
void PlayerCompositorDelegate::AfterBitmapRequestCallback() { … }
}