Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqnxbuffer.cpp
Go to the documentation of this file.
1// Copyright (C) 2011 - 2012 Research In Motion
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qqnxglobal.h"
5
6#include "qqnxbuffer.h"
7
8#include <QtCore/QDebug>
9
10#include <errno.h>
11#include <sys/mman.h>
12
13#if defined(QQNXBUFFER_DEBUG)
14#define qBufferDebug qDebug
15#else
16#define qBufferDebug QT_NO_QDEBUG_MACRO
17#endif
18
20
22 : m_buffer(0)
23{
24 qBufferDebug("empty");
25}
26
28 : m_buffer(buffer)
29{
30 qBufferDebug("normal");
31
32 // Get size of buffer
33 int size[2];
34 Q_SCREEN_CRITICALERROR(screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_BUFFER_SIZE, size),
35 "Failed to query buffer size");
36
37 // Get stride of buffer
38 int stride;
39 Q_SCREEN_CHECKERROR(screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE, &stride),
40 "Failed to query buffer stride");
41
42 // Get access to buffer's data
43 errno = 0;
44 uchar *dataPtr = nullptr;
46 screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, (void **)&dataPtr),
47 "Failed to query buffer pointer");
48
49 if (Q_UNLIKELY(!dataPtr))
50 qFatal("QQNX: buffer pointer is NULL, errno=%d", errno);
51
52 // Get format of buffer
53 int screenFormat;
55 screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_FORMAT, &screenFormat),
56 "Failed to query buffer format");
57
58 // Convert screen format to QImage format
60 switch (screenFormat) {
61 case SCREEN_FORMAT_RGBX4444:
62 imageFormat = QImage::Format_RGB444;
63 break;
64 case SCREEN_FORMAT_RGBA4444:
66 break;
67 case SCREEN_FORMAT_RGBX5551:
68 imageFormat = QImage::Format_RGB555;
69 break;
70 case SCREEN_FORMAT_RGB565:
71 imageFormat = QImage::Format_RGB16;
72 break;
73 case SCREEN_FORMAT_RGBX8888:
74 imageFormat = QImage::Format_RGB32;
75 break;
76 case SCREEN_FORMAT_RGBA8888:
78 break;
79 default:
80 qFatal("QQNX: unsupported buffer format, format=%d", screenFormat);
81 }
82
83 // wrap buffer in an image
84 m_image = QImage(dataPtr, size[0], size[1], stride, imageFormat);
85}
86
88 : m_buffer(other.m_buffer),
89 m_image(other.m_image)
90{
91 qBufferDebug("copy");
92}
93
95{
97}
98
100{
101 qBufferDebug();
102
103 // Verify native buffer exists
104 if (Q_UNLIKELY(!m_buffer))
105 qFatal("QQNX: can't invalidate cache for null buffer");
106
107 // Evict buffer's data from cache
108 errno = 0;
109 int result = msync(m_image.bits(), m_image.height() * m_image.bytesPerLine(), MS_INVALIDATE | MS_CACHE_ONLY);
110 if (Q_UNLIKELY(result != 0))
111 qFatal("QQNX: failed to invalidate cache, errno=%d", errno);
112}
113
\inmodule QtGui
Definition qimage.h:37
qsizetype bytesPerLine() const
Returns the number of bytes per image scanline.
Definition qimage.cpp:1538
uchar * bits()
Returns a pointer to the first pixel data.
Definition qimage.cpp:1677
int height() const
Returns the height of the image.
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_RGB32
Definition qimage.h:46
@ Format_Invalid
Definition qimage.h:42
@ Format_RGB444
Definition qimage.h:56
@ Format_RGB555
Definition qimage.h:53
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
@ Format_ARGB4444_Premultiplied
Definition qimage.h:57
@ Format_RGB16
Definition qimage.h:49
virtual ~QQnxBuffer()
void invalidateInCache()
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
#define qFatal
Definition qlogging.h:164
GLenum GLuint GLintptr GLsizeiptr size
[1]
const void GLsizei GLsizei stride
GLenum GLuint buffer
GLuint64EXT * result
[6]
#define qBufferDebug
#define Q_SCREEN_CRITICALERROR(x, message)
Definition qqnxglobal.h:16
#define Q_SCREEN_CHECKERROR(x, message)
Definition qqnxglobal.h:13
unsigned char uchar
Definition qtypes.h:27
QSharedPointer< T > other(t)
[5]