6#include <QtCore/qdebug.h>
7#include <QtCore/qloggingcategory.h>
9#include <CoreGraphics/CoreGraphics.h>
10#include <IOSurface/IOSurface.h>
26 Q_ASSERT(
width <= IOSurfaceGetPropertyMaximum(kIOSurfaceWidth));
29 static const char bytesPerElement = 4;
31 const size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow,
width * bytesPerElement);
32 const size_t totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize,
height * bytesPerRow);
34 NSDictionary *options = @{
36 (
id)kIOSurfaceHeight: @(
height),
37 (
id)kIOSurfacePixelFormat: @(unsigned(
'BGRA')),
38 (
id)kIOSurfaceBytesPerElement: @(bytesPerElement),
39 (
id)kIOSurfaceBytesPerRow: @(bytesPerRow),
40 (
id)kIOSurfaceAllocSize: @(totalBytes),
43 m_surface = IOSurfaceCreate((CFDictionaryRef)options);
56 static const auto kIOSurfaceColorSpace = CFSTR(
"IOSurfaceColorSpace");
58 qCDebug(lcQpaIOSurface) <<
"Tagging" <<
this <<
"with color space" << colorSpace;
61 IOSurfaceSetValue(m_surface, kIOSurfaceColorSpace,
64 IOSurfaceRemoveValue(m_surface, kIOSurfaceColorSpace);
70 return (
const uchar *)IOSurfaceGetBaseAddress(m_surface);
75 return (
uchar *)IOSurfaceGetBaseAddress(m_surface);
80 return IOSurfaceGetBytesPerRow(m_surface);
90 return IOSurfaceIsInUse(m_surface);
95 IOSurfaceLockOptions lockOptions = 0;
97 lockOptions |= kIOSurfaceLockReadOnly;
106 qCDebug(lcQpaIOSurface) <<
"Locking" <<
this <<
"for" <<
access;
116 lockOptions |= kIOSurfaceLockAvoidSync;
117 kern_return_t
ret = IOSurfaceLock(m_surface, lockOptions,
nullptr);
118 if (
ret == kIOSurfaceSuccess)
121 if (
ret == kIOReturnCannotLock) {
122 qCWarning(lcQpaIOSurface) <<
"Locking of" <<
this <<
"requires read-back";
123 lockOptions ^= kIOSurfaceLockAvoidSync;
124 ret = IOSurfaceLock(m_surface, lockOptions,
nullptr);
127 if (
ret != kIOSurfaceSuccess) {
128 qCWarning(lcQpaIOSurface) <<
"Failed to lock" <<
this <<
ret;
137 qCDebug(lcQpaIOSurface) <<
"Unlocking" <<
this <<
"from" <<
isLocked();
140 bool success = IOSurfaceUnlock(m_surface, lockOptions,
nullptr) == kIOSurfaceSuccess;
141 Q_ASSERT_X(success,
"QIOSurfaceGraphicsBuffer",
"Unlocking surface should succeed");
144#ifndef QT_NO_DEBUG_STREAM
149 debug <<
"QIOSurfaceGraphicsBuffer(" << (
const void *)graphicsBuffer;
150 if (graphicsBuffer) {
151 debug <<
", surface=" << graphicsBuffer->m_surface;
152 debug <<
", size=" << graphicsBuffer->
size();
void setColorSpace(QCFType< CGColorSpaceRef > colorSpace)
QIOSurfaceGraphicsBuffer(const QSize &size, const QPixelFormat &format)
bool doLock(AccessTypes access, const QRect &rect) override
This function should be reimplemented by subclasses.
int bytesPerLine() const override
Accessor for bytes per line in the graphics buffer.
const uchar * data() const override
Accessor for the bytes of the buffer.
~QIOSurfaceGraphicsBuffer()
void doUnlock() override
This function should remove all locks set on the buffer.
\inmodule QtCore\reentrant
Combined button and popup list for selecting options.
CFPropertyListRef CGColorSpaceCopyPropertyList(CGColorSpaceRef space)
IOSurfaceLockOptions lockOptionsForAccess(QPlatformGraphicsBuffer::AccessTypes access)
QDebug operator<<(QDebug debug, const QIOSurfaceGraphicsBuffer *graphicsBuffer)
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
struct CGColorSpace * CGColorSpaceRef
#define Q_ASSERT_X(cond, x, msg)