Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsfb_fillrectangle_argb.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsgui/fb/mmsfbconv.h"
00034 
00035 #ifdef __HAVE_PF_ARGB__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_fillrectangle_argb(MMSFBSurfacePlanes *dst_planes, int dst_height,
00040                               int dx, int dy, int dw, int dh, MMSFBColor color) {
00041     // first time?
00042     static bool firsttime = true;
00043     if (firsttime) {
00044         printf("DISKO: Using accelerated fill rectangle to ARGB.\n");
00045         firsttime = false;
00046     }
00047 
00048     // get the first destination ptr/pitch
00049     unsigned int *dst = (unsigned int *)dst_planes->ptr;
00050     int dst_pitch = dst_planes->pitch;
00051 
00052     // prepare...
00053     int dst_pitch_pix = dst_pitch >> 2;
00054     dst+= dx + dy * dst_pitch_pix;
00055 
00056     unsigned int *dst_end = dst + dst_pitch_pix * dh;
00057 #ifndef __HAVE_SSE__
00058     int dst_pitch_diff = dst_pitch_pix - dw;
00059 #endif
00060 
00061     // prepare the color
00062     register unsigned int A = color.a;
00063     register unsigned int SRC;
00064     SRC =     (A << 24)
00065             | (color.r << 16)
00066             | (color.g << 8)
00067             | color.b;
00068 
00069     if (color.r != A || color.g != A || color.b != A) {
00070         // different values for r, g, b, a
00071         // copy pixel directly to the destination
00072         // for all lines
00073         while (dst < dst_end) {
00074             // for all pixels in the line
00075 #ifdef __HAVE_SSE__
00076             // fill memory 4-byte-wise (much faster than loop see below)
00077     //      __asm__ __volatile__ ( "\tcld\n\trep stosl" : : "D" (dst), "a" (SRC), "c" (dw));
00078             short d0, d1, d2;
00079             __asm__ __volatile__ ( "\tcld\n\trep stosl" \
00080                     : "=&D" (d0), "=&a" (d1), "=&c" (d2) \
00081                     : "0" (dst), "1" (SRC), "2" (dw) \
00082                     : "memory", "cc");
00083 
00084             // go to the next line
00085             dst+= dst_pitch_pix;
00086 #else
00087             unsigned int *line_end = dst + dw;
00088             while (dst < line_end) {
00089                 *dst = SRC;
00090                 dst++;
00091             }
00092 
00093             // go to the next line
00094             dst+= dst_pitch_diff;
00095 #endif
00096         }
00097     }
00098     else {
00099         // r, g, b, a values are equal, so clear it with value from A
00100         register int mw = dw << 2;
00101         if (mw != dst_pitch) {
00102             // for all lines
00103             while (dst < dst_end) {
00104                 // reset all pixels in the line
00105                 memset(dst, A, mw);
00106 
00107                 // go to the next line
00108                 dst+= dst_pitch_pix;
00109             }
00110         }
00111         else {
00112             // clear one big block
00113             memset(dst, A, (int)((char*)dst_end - (char*)dst));
00114         }
00115     }
00116 }
00117 
00118 #endif

Generated by doxygen