Skip to content

Commit

Permalink
Send more information to the recorder client
Browse files Browse the repository at this point in the history
This commit adds a transform argument to the frame event to tell
the client if the frame is y-inverted. It also moves the failure
case to its own event.
  • Loading branch information
giucam committed Dec 16, 2014
1 parent 5f2cb0f commit 8894c56
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
23 changes: 17 additions & 6 deletions protocol/lipstick-recorder.xml
Expand Up @@ -51,31 +51,42 @@
record more frames.

The buffer must be a shm buffer, trying to use another
type of buffer will result in frame being sent with the
bad_buffer result.
type of buffer will result in failure to capture the
frame and the failed event will be sent.
</description>
<arg name="buffer" type="object" interface="wl_buffer"/>
</request>

<enum name="result">
<entry name="ok" value="1"/>
<entry name="bad_buffer" value="2"/>
</enum>

<enum name="transform">
<entry name="normal" value="1"/>
<entry name="y_inverted" value="2"/>
</enum>

<event name="frame">
<description summary="notify a frame was recorded, or an error">
The compositor will send this event after a frame was
recorded, or in case an error happened. The client can
call record_frame again to record the next frame.

The value of the 'result' argument will be one of the
values of the 'result' enum.
'time' is the time the compositor recorded that frame,
in milliseconds, with an unspecified base.
</description>
<arg name="result" type="int"/>
<arg name="buffer" type="object" interface="wl_buffer"/>
<arg name="time" type="uint"/>
<arg name="transform" type="int"/>
</event>

<event name="failed">
<description summary="the frame capture failed">
The value of the 'result' argument will be one of the
values of the 'result' enum.
</description>
<arg name="result" type="int"/>
<arg name="buffer" type="object" interface="wl_buffer"/>
</event>

<event name="cancelled">
Expand Down
43 changes: 25 additions & 18 deletions src/compositor/lipstickrecorder.cpp
Expand Up @@ -28,19 +28,26 @@ static uint32_t getTime()
}

static const QEvent::Type FrameEventType = (QEvent::Type)QEvent::registerEventType();
static const QEvent::Type FailedEventType = (QEvent::Type)QEvent::registerEventType();

class FrameEvent : public QEvent
{
public:
FrameEvent(int r, uint32_t t)
FrameEvent(uint32_t t)
: QEvent(FrameEventType)
, result(r)
, time(t)
{
}
{ }
uint32_t time;
};

class FailedEvent : public QEvent
{
public:
FailedEvent(int r)
: QEvent(FailedEventType)
, result(r)
{ }
int result;
uint32_t time;
};

LipstickRecorderManager::LipstickRecorderManager()
Expand Down Expand Up @@ -68,13 +75,13 @@ void LipstickRecorderManager::recordFrame(QWindow *window)
int height = wl_shm_buffer_get_height(buffer);

if (width != window->width() || height != window->height()) {
qApp->postEvent(recorder, new FrameEvent(QtWaylandServer::lipstick_recorder::result_bad_buffer, time));
qApp->postEvent(recorder, new FailedEvent(QtWaylandServer::lipstick_recorder::result_bad_buffer));
continue;
}

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
qApp->postEvent(recorder, new FrameEvent(QtWaylandServer::lipstick_recorder::result_ok, time));
qApp->postEvent(recorder, new FrameEvent(time));

m_requests.remove(window, recorder);
}
Expand Down Expand Up @@ -123,12 +130,6 @@ LipstickRecorder::~LipstickRecorder()
m_manager->remove(m_window, this);
}

void LipstickRecorder::sendFrame(int result, int time)
{
send_frame(result, m_bufferResource, time);
m_bufferResource = Q_NULLPTR;
}

void LipstickRecorder::lipstick_recorder_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
Expand All @@ -152,17 +153,23 @@ void LipstickRecorder::lipstick_recorder_record_frame(Resource *resource, ::wl_r
m_manager->requestFrame(m_window, this);
} else {
m_bufferResource = Q_NULLPTR;
send_frame(result_bad_buffer, buffer, getTime());
send_failed(result_bad_buffer, buffer);
}
}

bool LipstickRecorder::event(QEvent *e)
{
if (e->type() == FrameEventType) {
FrameEvent *fe = static_cast<FrameEvent *>(e);
sendFrame(fe->result, fe->time);
wl_client_flush(client());
return true;
send_frame(m_bufferResource, fe->time, QtWaylandServer::lipstick_recorder::transform_y_inverted);
} else if (e->type() == FailedEventType) {
FailedEvent *fe = static_cast<FailedEvent *>(e);
send_failed(fe->result, m_bufferResource);
} else {
return QObject::event(e);
}
return QObject::event(e);

m_bufferResource = Q_NULLPTR;
wl_client_flush(client());
return true;
}
1 change: 0 additions & 1 deletion src/compositor/lipstickrecorder.h
Expand Up @@ -56,7 +56,6 @@ class LipstickRecorder : public QObject, public QtWaylandServer::lipstick_record
LipstickRecorder(LipstickRecorderManager *manager, wl_client *client, quint32 id, QWindow *window);
~LipstickRecorder();

void sendFrame(int result, int time);
wl_shm_buffer *buffer() const { return m_buffer; }
wl_client *client() const { return m_client; }

Expand Down

0 comments on commit 8894c56

Please sign in to comment.