#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/viz/service/frame_sinks/video_capture/video_capture_overlay.h"
#include <algorithm>
#include <cmath>
#include <optional>
#include <string>
#include <utility>
#include "base/containers/heap_array.h"
#include "base/functional/bind.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "media/base/limits.h"
#include "media/base/video_frame.h"
#include "media/base/video_types.h"
#include "media/base/video_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
VideoFrame;
VideoPixelFormat;
namespace viz {
VideoCaptureOverlay::FrameSource::~FrameSource() = default;
VideoCaptureOverlay::VideoCaptureOverlay(
FrameSource& frame_source,
mojo::PendingReceiver<mojom::FrameSinkVideoCaptureOverlay> receiver)
: … { … }
VideoCaptureOverlay::~VideoCaptureOverlay() = default;
void VideoCaptureOverlay::SetImageAndBounds(const SkBitmap& image,
const gfx::RectF& bounds) { … }
void VideoCaptureOverlay::SetBounds(const gfx::RectF& bounds) { … }
namespace {
gfx::Rect ToAbsoluteBoundsForI420(const gfx::RectF& relative,
const gfx::Rect& span) { … }
gfx::Rect Transform(const gfx::Rect& source,
const gfx::Rect& from_region,
const gfx::Rect& to_region) { … }
}
std::string VideoCaptureOverlay::CapturedFrameProperties::ToString() const { … }
std::string VideoCaptureOverlay::BlendInformation::ToString() const { … }
std::optional<VideoCaptureOverlay::BlendInformation>
VideoCaptureOverlay::CalculateBlendInformation(
const CapturedFrameProperties& properties) const { … }
VideoCaptureOverlay::OnceRenderer VideoCaptureOverlay::MakeRenderer(
const CapturedFrameProperties& properties) { … }
VideoCaptureOverlay::OnceRenderer VideoCaptureOverlay::MakeCombinedRenderer(
const std::vector<VideoCaptureOverlay*>& overlays,
const CapturedFrameProperties& properties) { … }
gfx::Rect VideoCaptureOverlay::ComputeSourceMutationRect() const { … }
VideoCaptureOverlay::Sprite::Sprite(const SkBitmap& image,
const gfx::Size& size,
const VideoPixelFormat format)
: … { … }
VideoCaptureOverlay::Sprite::~Sprite() { … }
namespace {
template <typename Pointer>
Pointer PositionPointerInPlane(Pointer plane_begin,
int stride,
const gfx::Point& offset) { … }
template <typename Pointer>
Pointer PositionPointerARGB(Pointer pixels_begin,
int stride,
const gfx::Point& offset) { … }
float From255(uint8_t value) { … }
uint32_t ToClamped255(float value) { … }
}
void VideoCaptureOverlay::Sprite::Blend(const gfx::Rect& src_rect,
const gfx::Rect& dst_rect,
VideoFrame* frame) { … }
void VideoCaptureOverlay::Sprite::TransformImage() { … }
}