ImageRotationSessionVT.h [plain text]
#pragma once
#include "AffineTransform.h"
#include "FloatSize.h"
typedef struct OpaqueVTImageRotationSession* VTImageRotationSessionRef;
typedef struct __CVBuffer *CVPixelBufferRef;
typedef struct __CVPixelBufferPool* CVPixelBufferPoolRef;
namespace WebCore {
class MediaSample;
class ImageRotationSessionVT final {
WTF_MAKE_FAST_ALLOCATED;
public:
struct RotationProperties {
bool flipX { false };
bool flipY { false };
unsigned angle { 0 };
bool isIdentity() const { return !flipX && !flipY && !angle; }
};
enum class IsCGImageCompatible {
No,
Yes,
};
ImageRotationSessionVT(AffineTransform&&, FloatSize, OSType, IsCGImageCompatible);
ImageRotationSessionVT(const RotationProperties&, FloatSize, OSType, IsCGImageCompatible);
ImageRotationSessionVT() = default;
const Optional<AffineTransform>& transform() const { return m_transform; }
const RotationProperties& rotationProperties() const { return m_rotationProperties; }
const FloatSize& size() { return m_size; }
const FloatSize& rotatedSize() { return m_rotatedSize; }
RetainPtr<CVPixelBufferRef> rotate(CVPixelBufferRef);
WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> rotate(MediaSample&, const RotationProperties&, IsCGImageCompatible);
bool isMatching(MediaSample&, const RotationProperties&);
private:
void initialize(const RotationProperties&, FloatSize, OSType pixelFormat, IsCGImageCompatible);
Optional<AffineTransform> m_transform;
RotationProperties m_rotationProperties;
FloatSize m_size;
FloatSize m_rotatedSize;
RetainPtr<VTImageRotationSessionRef> m_rotationSession;
RetainPtr<CVPixelBufferPoolRef> m_rotationPool;
};
inline bool operator==(const ImageRotationSessionVT::RotationProperties& rotation1, const ImageRotationSessionVT::RotationProperties& rotation2)
{
return rotation1.flipX == rotation2.flipX && rotation1.flipY == rotation2.flipY && rotation1.angle == rotation2.angle;
}
inline bool operator!=(const ImageRotationSessionVT::RotationProperties& rotation1, const ImageRotationSessionVT::RotationProperties& rotation2)
{
return !(rotation1 == rotation2);
}
}