src/gui/embedded/qscreen_qws.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QSCREEN_QWS_H
       
    43 #define QSCREEN_QWS_H
       
    44 
       
    45 #include <QtCore/qnamespace.h>
       
    46 #include <QtCore/qpoint.h>
       
    47 #include <QtCore/qlist.h>
       
    48 #include <QtGui/qrgb.h>
       
    49 #include <QtCore/qrect.h>
       
    50 #include <QtGui/qimage.h>
       
    51 #include <QtGui/qregion.h>
       
    52 
       
    53 struct fb_cmap;
       
    54 
       
    55 QT_BEGIN_HEADER
       
    56 
       
    57 QT_BEGIN_NAMESPACE
       
    58 
       
    59 QT_MODULE(Gui)
       
    60 
       
    61 class QScreenCursor;
       
    62 class QBrush;
       
    63 class QWSWindow;
       
    64 class QWSWindowSurface;
       
    65 class QGraphicsSystem;
       
    66 class QPixmapData;
       
    67 
       
    68 #ifndef QT_QWS_DEPTH16_RGB
       
    69 #define QT_QWS_DEPTH16_RGB 565
       
    70 #endif
       
    71 static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100);
       
    72 static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10);
       
    73 static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10);
       
    74 static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);
       
    75 static const int qt_green_shift = qt_bbits-(8-qt_gbits);
       
    76 static const int qt_neg_blue_shift = 8-qt_bbits;
       
    77 static const int qt_blue_mask = (1<<qt_bbits)-1;
       
    78 static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits);
       
    79 static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));
       
    80 
       
    81 static const int qt_red_rounding_shift = qt_red_shift + qt_rbits;
       
    82 static const int qt_green_rounding_shift = qt_green_shift + qt_gbits;
       
    83 static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift;
       
    84 
       
    85 
       
    86 inline ushort qt_convRgbTo16(const int r, const int g, const int b)
       
    87 {
       
    88     const int tr = r << qt_red_shift;
       
    89     const int tg = g << qt_green_shift;
       
    90     const int tb = b >> qt_neg_blue_shift;
       
    91 
       
    92     return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
       
    93 }
       
    94 
       
    95 inline ushort qt_convRgbTo16(QRgb c)
       
    96 {
       
    97     const int tr = qRed(c) << qt_red_shift;
       
    98     const int tg = qGreen(c) << qt_green_shift;
       
    99     const int tb = qBlue(c) >> qt_neg_blue_shift;
       
   100 
       
   101     return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
       
   102 }
       
   103 
       
   104 inline QRgb qt_conv16ToRgb(ushort c)
       
   105 {
       
   106     const int r=(c & qt_red_mask);
       
   107     const int g=(c & qt_green_mask);
       
   108     const int b=(c & qt_blue_mask);
       
   109     const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift;
       
   110     const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift;
       
   111     const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift;
       
   112 
       
   113     return qRgb(tr,tg,tb);
       
   114 }
       
   115 
       
   116 inline void qt_conv16ToRgb(ushort c, int& r, int& g, int& b)
       
   117 {
       
   118     const int tr=(c & qt_red_mask);
       
   119     const int tg=(c & qt_green_mask);
       
   120     const int tb=(c & qt_blue_mask);
       
   121     r = tr >> qt_red_shift | tr >> qt_red_rounding_shift;
       
   122     g = tg >> qt_green_shift | tg >> qt_green_rounding_shift;
       
   123     b = tb << qt_neg_blue_shift | tb >> qt_blue_rounding_shift;
       
   124 }
       
   125 
       
   126 const int SourceSolid=0;
       
   127 const int SourcePixmap=1;
       
   128 
       
   129 #ifndef QT_NO_QWS_CURSOR
       
   130 
       
   131 class QScreenCursor;
       
   132 extern QScreenCursor *qt_screencursor;
       
   133 extern bool qt_sw_cursor;
       
   134 
       
   135 class Q_GUI_EXPORT QScreenCursor
       
   136 {
       
   137 public:
       
   138     QScreenCursor();
       
   139     virtual ~QScreenCursor();
       
   140 
       
   141     virtual void set(const QImage &image, int hotx, int hoty);
       
   142     virtual void move(int x, int y);
       
   143     virtual void show();
       
   144     virtual void hide();
       
   145 
       
   146     bool supportsAlphaCursor() const { return supportsAlpha; }
       
   147 
       
   148     static bool enabled() { return qt_sw_cursor; }
       
   149 
       
   150     QRect boundingRect() const { return QRect(pos - hotspot, size); }
       
   151     QImage image() const { return cursor; }
       
   152     bool isVisible() const { return enable; }
       
   153     bool isAccelerated() const { return hwaccel; }
       
   154 
       
   155     static void initSoftwareCursor();
       
   156     static QScreenCursor* instance() { return qt_screencursor; }
       
   157 
       
   158 protected:
       
   159     QImage cursor;
       
   160 
       
   161     QSize size;
       
   162     QPoint pos;
       
   163     QPoint hotspot;
       
   164     uint enable : 1;
       
   165     uint hwaccel : 1;
       
   166     uint supportsAlpha : 1;
       
   167 
       
   168 private:
       
   169     friend class QProxyScreenCursor;
       
   170 };
       
   171 
       
   172 #endif // QT_NO_QWS_CURSOR
       
   173 
       
   174 // A (used) chunk of offscreen memory
       
   175 
       
   176 class QPoolEntry
       
   177 {
       
   178 public:
       
   179     unsigned int start;
       
   180     unsigned int end;
       
   181     int clientId;
       
   182 };
       
   183 
       
   184 class QScreen;
       
   185 class QScreenPrivate;
       
   186 class QPixmapDataFactory;
       
   187 
       
   188 extern Q_GUI_EXPORT QScreen *qt_screen;
       
   189 typedef void(*ClearCacheFunc)(QScreen *obj, int);
       
   190 
       
   191 class Q_GUI_EXPORT QScreen {
       
   192 
       
   193 public:
       
   194     enum ClassId { LinuxFBClass, TransformedClass, VNCClass, MultiClass,
       
   195                    VFbClass, DirectFBClass, SvgalibClass, ProxyClass,
       
   196                    GLClass, CustomClass = 1024 };
       
   197 
       
   198     QScreen(int display_id, ClassId classId);
       
   199     explicit QScreen(int display_id);
       
   200     virtual ~QScreen();
       
   201     static QScreen* instance() { return qt_screen; }
       
   202     virtual bool initDevice() = 0;
       
   203     virtual bool connect(const QString &displaySpec) = 0;
       
   204     virtual void disconnect() = 0;
       
   205     virtual void shutdownDevice();
       
   206     virtual void setMode(int,int,int) = 0;
       
   207     virtual bool supportsDepth(int) const;
       
   208 
       
   209     virtual void save();
       
   210     virtual void restore();
       
   211     virtual void blank(bool on);
       
   212 
       
   213     virtual int pixmapOffsetAlignment() { return 64; }
       
   214     virtual int pixmapLinestepAlignment() { return 64; }
       
   215     virtual int sharedRamSize(void *) { return 0; }
       
   216 
       
   217     virtual bool onCard(const unsigned char *) const;
       
   218     virtual bool onCard(const unsigned char *, ulong& out_offset) const;
       
   219 
       
   220     enum PixelType { NormalPixel, BGRPixel };
       
   221 
       
   222     // sets a single color in the colormap
       
   223     virtual void set(unsigned int,unsigned int,unsigned int,unsigned int);
       
   224     // allocates a color
       
   225     virtual int alloc(unsigned int,unsigned int,unsigned int);
       
   226 
       
   227     int width() const { return w; }
       
   228     int height() const { return h; }
       
   229     int depth() const { return d; }
       
   230     virtual int pixmapDepth() const;
       
   231     PixelType pixelType() const { return pixeltype; }
       
   232     int linestep() const { return lstep; }
       
   233     int deviceWidth() const { return dw; }
       
   234     int deviceHeight() const { return dh; }
       
   235     uchar * base() const { return data; }
       
   236     // Ask for memory from card cache with alignment
       
   237     virtual uchar * cache(int) { return 0; }
       
   238     virtual void uncache(uchar *) {}
       
   239 
       
   240     QImage::Format pixelFormat() const;
       
   241 
       
   242     int screenSize() const { return size; }
       
   243     int totalSize() const { return mapsize; }
       
   244 
       
   245     QRgb * clut() { return screenclut; }
       
   246     int numCols() { return screencols; }
       
   247 
       
   248     virtual QSize mapToDevice(const QSize &) const;
       
   249     virtual QSize mapFromDevice(const QSize &) const;
       
   250     virtual QPoint mapToDevice(const QPoint &, const QSize &) const;
       
   251     virtual QPoint mapFromDevice(const QPoint &, const QSize &) const;
       
   252     virtual QRect mapToDevice(const QRect &, const QSize &) const;
       
   253     virtual QRect mapFromDevice(const QRect &, const QSize &) const;
       
   254     virtual QImage mapToDevice(const QImage &) const;
       
   255     virtual QImage mapFromDevice(const QImage &) const;
       
   256     virtual QRegion mapToDevice(const QRegion &, const QSize &) const;
       
   257     virtual QRegion mapFromDevice(const QRegion &, const QSize &) const;
       
   258     virtual int transformOrientation() const;
       
   259     virtual bool isTransformed() const;
       
   260     virtual bool isInterlaced() const;
       
   261 
       
   262     virtual void setDirty(const QRect&);
       
   263 
       
   264     virtual int memoryNeeded(const QString&);
       
   265 
       
   266     virtual void haltUpdates();
       
   267     virtual void resumeUpdates();
       
   268 
       
   269     // composition manager methods
       
   270     virtual void exposeRegion(QRegion r, int changing);
       
   271 
       
   272     // these work directly on the screen
       
   273     virtual void blit(const QImage &img, const QPoint &topLeft, const QRegion &region);
       
   274     virtual void solidFill(const QColor &color, const QRegion &region);
       
   275     void blit(QWSWindow *bs, const QRegion &clip);
       
   276 
       
   277     virtual QWSWindowSurface* createSurface(QWidget *widget) const;
       
   278     virtual QWSWindowSurface* createSurface(const QString &key) const;
       
   279 
       
   280     virtual QList<QScreen*> subScreens() const { return QList<QScreen*>(); }
       
   281     virtual QRegion region() const { return QRect(offset(), QSize(w, h)); }
       
   282     int subScreenIndexAt(const QPoint &p) const;
       
   283 
       
   284     void setOffset(const QPoint &p);
       
   285     QPoint offset() const;
       
   286 
       
   287     int physicalWidth() const { return physWidth; }   // physical display size in mm
       
   288     int physicalHeight() const { return physHeight; } // physical display size in mm
       
   289 
       
   290     QPixmapDataFactory* pixmapDataFactory() const; // Deprecated, will be removed in 4.6
       
   291     QGraphicsSystem* graphicsSystem() const;
       
   292 
       
   293 #ifdef QT_QWS_CLIENTBLIT
       
   294     bool supportsBlitInClients() const;
       
   295     void setSupportsBlitInClients(bool);
       
   296 #endif
       
   297 
       
   298     ClassId classId() const;
       
   299 
       
   300 protected:
       
   301     void setPixelFormat(QImage::Format format);
       
   302     void setPixmapDataFactory(QPixmapDataFactory *factory); // Deprecated, will be removed in 4.6
       
   303     void setGraphicsSystem(QGraphicsSystem* system);
       
   304 
       
   305     QRgb screenclut[256];
       
   306     int screencols;
       
   307 
       
   308     uchar * data;
       
   309 
       
   310     // Table of allocated lumps, kept in sorted highest-to-lowest order
       
   311     // The table itself is allocated at the bottom of offscreen memory
       
   312     // i.e. it's similar to having a stack (the table) and a heap
       
   313     // (the allocated blocks). Freed space is implicitly described
       
   314     // by the gaps between the allocated lumps (this saves entries and
       
   315     // means we don't need to worry about coalescing freed lumps)
       
   316 
       
   317     QPoolEntry * entries;
       
   318     int * entryp;
       
   319     unsigned int * lowest;
       
   320 
       
   321     int w;
       
   322     int lstep;
       
   323     int h;
       
   324     int d;
       
   325     PixelType pixeltype;
       
   326     bool grayscale;
       
   327 
       
   328     int dw;
       
   329     int dh;
       
   330 
       
   331     int size;               // Screen size
       
   332     int mapsize;       // Total mapped memory
       
   333 
       
   334     int displayId;
       
   335 
       
   336     int physWidth;
       
   337     int physHeight;
       
   338 
       
   339     friend class QWSServer;
       
   340     friend class QWSServerPrivate;
       
   341     static ClearCacheFunc clearCacheFunc;
       
   342 
       
   343 private:
       
   344     void compose(int level, const QRegion &exposed, QRegion &blend,
       
   345                  QImage **blendbuffer, int changing_level);
       
   346     void paintBackground(const QRegion &);
       
   347 
       
   348     friend class QWSOnScreenSurface;
       
   349     static bool isWidgetPaintOnScreen(const QWidget *w);
       
   350 
       
   351 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
       
   352     void setFrameBufferLittleEndian(bool littleEndian);
       
   353     bool frameBufferLittleEndian() const;
       
   354     friend class QVNCScreen;
       
   355     friend class QLinuxFbScreen;
       
   356     friend class QVFbScreen;
       
   357     friend class QProxyScreen;
       
   358 #endif
       
   359     friend void qt_solidFill_setup(QScreen*, const QColor&, const QRegion&);
       
   360     friend void qt_blit_setup(QScreen *screen, const QImage &image,
       
   361                               const QPoint &topLeft, const QRegion &region);
       
   362 #ifdef QT_QWS_DEPTH_GENERIC
       
   363     friend void qt_set_generic_blit(QScreen *screen, int bpp,
       
   364                                     int len_red, int len_green, int len_blue,
       
   365                                     int len_alpha, int off_red, int off_green,
       
   366                                     int off_blue, int off_alpha);
       
   367 #endif
       
   368 
       
   369     QScreenPrivate *d_ptr;
       
   370 };
       
   371 
       
   372 // This lives in loadable modules
       
   373 
       
   374 #ifndef QT_LOADABLE_MODULES
       
   375 extern "C" QScreen * qt_get_screen(int display_id, const char* spec);
       
   376 #endif
       
   377 
       
   378 // This is in main lib, loads the right module, calls qt_get_screen
       
   379 // In non-loadable cases just aliases to qt_get_screen
       
   380 
       
   381 const unsigned char * qt_probe_bus();
       
   382 
       
   383 QT_END_NAMESPACE
       
   384 
       
   385 QT_END_HEADER
       
   386 
       
   387 #endif // QSCREEN_QWS_H