#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/viz/service/display/overlay_processor_ozone.h"
#include <algorithm>
#include <memory>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/timer/elapsed_timer.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#include "build/chromeos_buildflags.h"
#include "components/viz/common/buildflags.h"
#include "components/viz/common/features.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "components/viz/service/display/overlay_strategy_fullscreen.h"
#include "components/viz/service/display/overlay_strategy_single_on_top.h"
#include "components/viz/service/display/overlay_strategy_underlay.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"
#include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "gpu/config/gpu_finch_features.h"
#include "ui/gl/gl_switches.h"
#endif
#if BUILDFLAG(ENABLE_CAST_OVERLAY_STRATEGY)
#include "components/viz/service/display/overlay_strategy_underlay_cast.h"
#endif
namespace viz {
namespace {
gfx::ColorSpace GetColorSpaceForOzone(gfx::BufferFormat format,
const gfx::ColorSpace& orig_color_space) { … }
void ConvertToOzoneOverlaySurface(
const OverlayProcessorInterface::OutputSurfaceOverlayPlane& primary_plane,
ui::OverlaySurfaceCandidate* ozone_candidate) { … }
void ConvertToOzoneOverlaySurface(
const OverlayCandidate& overlay_candidate,
ui::OverlaySurfaceCandidate* ozone_candidate) { … }
void ConvertToTiledOzoneOverlaySurface(
const OverlayCandidate& overlay_candidate,
ui::OverlaySurfaceCandidate* ozone_candidate) { … }
uint32_t MailboxToUInt32(const gpu::Mailbox& mailbox) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
bool IsYUVColorSpace(const gfx::ColorSpace& color_space) {
SkYUVColorSpace yuv_color_space;
return color_space.ToSkYUVColorSpace(&yuv_color_space);
}
bool AllowColorSpaceCombination(
SharedImageFormat source_format,
const gfx::ColorSpace& source_color_space,
const gfx::ColorSpace& destination_color_space) {
if (!source_color_space.IsValid())
return true;
bool is_yuv_color_space = features::IsLacrosColorManagementEnabled() ||
IsYUVColorSpace(source_color_space);
if ((source_format == MultiPlaneFormat::kNV12 ||
source_format == MultiPlaneFormat::kYV12 ||
source_format == MultiPlaneFormat::kP010) &&
is_yuv_color_space &&
(source_color_space.GetMatrixID() ==
gfx::ColorSpace::MatrixID::BT2020_NCL ||
source_color_space.GetRangeID() == gfx::ColorSpace::RangeID::FULL)) {
return false;
}
return source_color_space.GetContentColorUsage() ==
gfx::ContentColorUsage::kSRGB ||
source_color_space.GetContentColorUsage() ==
destination_color_space.GetContentColorUsage();
}
#endif
}
OverlayProcessorOzone::OverlayProcessorOzone(
std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates,
std::vector<OverlayStrategy> available_strategies,
gpu::SharedImageInterface* shared_image_interface)
: … { … }
OverlayProcessorOzone::~OverlayProcessorOzone() = default;
bool OverlayProcessorOzone::IsOverlaySupported() const { … }
bool OverlayProcessorOzone::NeedsSurfaceDamageRectList() const { … }
bool OverlayProcessorOzone::SupportsFlipRotateTransform() const { … }
void OverlayProcessorOzone::NotifyOverlayPromotion(
DisplayResourceProvider* display_resource_provider,
const OverlayCandidateList& candidate_list,
const QuadList& quad_list) { … }
void OverlayProcessorOzone::CheckOverlaySupportImpl(
const OverlayProcessorInterface::OutputSurfaceOverlayPlane* primary_plane,
OverlayCandidateList* surfaces) { … }
void OverlayProcessorOzone::MaybeObserveHardwareCapabilities() { … }
void OverlayProcessorOzone::ReceiveHardwareCapabilities(
ui::HardwareCapabilities hardware_capabilities) { … }
gfx::Rect OverlayProcessorOzone::GetOverlayDamageRectForOutputSurface(
const OverlayCandidate& overlay) const { … }
void OverlayProcessorOzone::RegisterOverlayRequirement(bool requires_overlay) { … }
void OverlayProcessorOzone::OnSwapBuffersComplete(gfx::SwapResult swap_result) { … }
bool OverlayProcessorOzone::SetNativePixmapForCandidate(
ui::OverlaySurfaceCandidate* candidate,
const gpu::Mailbox& mailbox,
bool is_primary) { … }
}