diff options
author | Dennis Kasprzyk <onestone@opencompositing.org> | 2008-08-12 21:00:32 +0200 |
---|---|---|
committer | Dennis kasprzyk <onestone@opencompositing.org> | 2008-08-12 21:00:32 +0200 |
commit | 27b751990b322da19ac1ca0f91f8e632b850d107 (patch) | |
tree | 0a579c2b1a91c8892e7614e51dfe4e0b49caf618 | |
parent | 1ed4c1a382fa17c6bfbb195ac6836e5c5bff04da (diff) | |
download | unity-window-decorator-27b751990b322da19ac1ca0f91f8e632b850d107.tar.gz unity-window-decorator-27b751990b322da19ac1ca0f91f8e632b850d107.tar.bz2 |
CompIcon class and CompTexture cleanup.
-rw-r--r-- | include/compicon.h | 25 | ||||
-rw-r--r-- | include/compiz-core.h | 41 | ||||
-rw-r--r-- | include/comptexture.h | 12 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/icon.cpp | 49 | ||||
-rw-r--r-- | src/privatewindow.h | 4 | ||||
-rw-r--r-- | src/screen.cpp | 28 | ||||
-rw-r--r-- | src/texture.cpp | 22 | ||||
-rw-r--r-- | src/window.cpp | 65 |
9 files changed, 127 insertions, 122 deletions
diff --git a/include/compicon.h b/include/compicon.h new file mode 100644 index 0000000..df04fe9 --- /dev/null +++ b/include/compicon.h @@ -0,0 +1,25 @@ +#ifndef _COMPICON_H +#define _COMPICON_H + +#include <comptexture.h> +class CompScreen; + +class CompIcon { + public: + CompIcon (CompScreen *screen, unsigned width, unsigned int height); + ~CompIcon (); + + CompTexture & texture (); + unsigned int width (); + unsigned int height (); + unsigned char* data (); + + private: + CompTexture mTexture; + int mWidth; + unsigned int mHeight; + unsigned char *mData; + bool mUpdateTex; +}; + +#endif
\ No newline at end of file diff --git a/include/compiz-core.h b/include/compiz-core.h index 7830ce8..3d7b47a 100644 --- a/include/compiz-core.h +++ b/include/compiz-core.h @@ -79,8 +79,8 @@ COMPIZ_BEGIN_DECLS # define BITMAP_BIT_ORDER LSBFirst #endif -class CompTexture; -typedef struct _CompIcon CompIcon; +class CompTexture; +class CompIcon; typedef struct _CompWindowExtents CompWindowExtents; typedef struct _CompProgram CompProgram; typedef struct _CompFunction CompFunction; @@ -828,34 +828,6 @@ prepareXCoords (CompScreen *screen, CompOutput *output, float z); - -/* texture.c */ - - -Bool -iconToTexture (CompScreen *screen, - CompIcon *icon); - -Bool -readImageToTexture (CompScreen *screen, - CompTexture *texture, - const char *imageFileName, - unsigned int *returnWidth, - unsigned int *returnHeight); - -/* - -void -enableTextureClampToBorder (CompScreen *screen, - CompTexture *texture, - CompTextureFilter filter); - -void -enableTextureClampToEdge (CompScreen *screen, - CompTexture *texture, - CompTextureFilter filter); - -*/ /* screen.c */ #define COMP_SCREEN_OPTION_DETECT_REFRESH_RATE 0 @@ -1506,15 +1478,6 @@ compReadXmlChunkFromMetadataOptionInfo (const CompMetadataOptionInfo *info, COMPIZ_END_DECLS - -#include <comptexture.h> - -struct _CompIcon { - CompTexture *texture; - int width; - int height; -}; - #include <string> #include <vector> diff --git a/include/comptexture.h b/include/comptexture.h index 73bbab9..b31a2a4 100644 --- a/include/comptexture.h +++ b/include/comptexture.h @@ -1,6 +1,10 @@ #ifndef _COMPTEXTURE_H #define _COMPTEXTURE_H +#include <X11/Xlib-xcb.h> + +#include <GL/gl.h> + #include <boost/shared_ptr.hpp> #define POWER_OF_TWO(v) ((v & (v - 1)) == 0) @@ -57,6 +61,14 @@ class CompTexture { GLenum format, GLenum type); + static bool + readImageToTexture (CompScreen *screen, + CompTexture *texture, + const char *imageFileName, + unsigned int *returnWidth, + unsigned int *returnHeight); + + private: boost::shared_ptr <PrivateTexture> priv; }; diff --git a/src/Makefile.am b/src/Makefile.am index d2877e6..04c8493 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,4 +32,5 @@ compiz_SOURCES = \ rect.cpp \ size.cpp \ point.cpp \ - windowgeometry.cpp + windowgeometry.cpp \ + icon.cpp diff --git a/src/icon.cpp b/src/icon.cpp new file mode 100644 index 0000000..856ceaf --- /dev/null +++ b/src/icon.cpp @@ -0,0 +1,49 @@ +#include <compicon.h> + +CompIcon::CompIcon (CompScreen *screen, unsigned int width, + unsigned int height) : + mTexture (screen), + mWidth (width), + mHeight (height), + mData (new unsigned char[width * height * 4]), + mUpdateTex (true) +{ +} + +CompIcon::~CompIcon () +{ + free (mData); +} + +CompTexture & +CompIcon::texture () +{ + if (mUpdateTex) + { + mUpdateTex = false; + mTexture.reset (); + if (!mTexture.imageBufferToTexture (&mTexture, + reinterpret_cast<const char *> (mData), mWidth, mHeight)) + mTexture.reset (); + } + return mTexture; +} + +unsigned int +CompIcon::width () +{ + return mWidth; +} + +unsigned int +CompIcon::height () +{ + return mHeight; +} + +unsigned char* +CompIcon::data () +{ + mUpdateTex = true; + return mData; +}
\ No newline at end of file diff --git a/src/privatewindow.h b/src/privatewindow.h index 315bf0e..cc3df8b 100644 --- a/src/privatewindow.h +++ b/src/privatewindow.h @@ -219,8 +219,8 @@ class PrivateWindow { CompStruts *struts; - CompIcon **icon; - int nIcon; + std::vector<CompIcon *> icons; + bool noIcons; XRectangle iconGeometry; bool iconGeometrySet; diff --git a/src/screen.cpp b/src/screen.cpp index fa7d360..a4a786c 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -51,6 +51,7 @@ #include <compiz-core.h> #include <compscreen.h> +#include <compicon.h> #include "privatescreen.h" #define NUM_OPTIONS(s) (sizeof ((s)->priv->opt) / sizeof (CompOption)) @@ -888,7 +889,7 @@ PrivateScreen::updateScreenBackground (CompTexture *texture) } if (!texture->name () && backgroundImage) - readImageToTexture (screen, texture, backgroundImage, + CompTexture::readImageToTexture (screen, texture, backgroundImage, &width, &height); if (texture->target () == GL_TEXTURE_2D) @@ -2299,10 +2300,7 @@ CompScreen::~CompScreen () XDestroyWindow (priv->display->dpy (), priv->grabWindow); if (priv->defaultIcon) - { - delete priv->defaultIcon->texture; - free (priv->defaultIcon); - } + delete priv->defaultIcon; glXDestroyContext (priv->display->dpy (), priv->ctx); @@ -3904,36 +3902,22 @@ CompScreen::outputDeviceForGeometry (CompWindow::Geometry gm) bool CompScreen::updateDefaultIcon () { - CompIcon *icon; char *file = priv->opt[COMP_SCREEN_OPTION_DEFAULT_ICON].value.s; void *data; int width, height; if (priv->defaultIcon) { - delete priv->defaultIcon->texture; - free (priv->defaultIcon); + delete priv->defaultIcon; priv->defaultIcon = NULL; } if (!priv->display->readImageFromFile (file, &width, &height, &data)) return false; - icon = (CompIcon *) malloc (sizeof (CompIcon) + width * height * sizeof (CARD32)); - if (!icon) - { - free (data); - return false; - } - - icon->texture = new CompTexture (this); - - icon->width = width; - icon->height = height; - - memcpy (icon + 1, data, + width * height * sizeof (CARD32)); + priv->defaultIcon = new CompIcon (this, width, height); - priv->defaultIcon = icon; + memcpy (priv->defaultIcon->data (), data, width * height * sizeof (CARD32)); free (data); diff --git a/src/texture.cpp b/src/texture.cpp index 0f7b39d..10a2252 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -176,12 +176,12 @@ CompTexture::imageDataToTexture (CompTexture *texture, } -Bool -readImageToTexture (CompScreen *screen, - CompTexture *texture, - const char *imageFileName, - unsigned int *returnWidth, - unsigned int *returnHeight) +bool +CompTexture::readImageToTexture (CompScreen *screen, + CompTexture *texture, + const char *imageFileName, + unsigned int *returnWidth, + unsigned int *returnHeight) { void *image; int width, height; @@ -204,16 +204,6 @@ readImageToTexture (CompScreen *screen, return status; } -Bool -iconToTexture (CompScreen *screen, - CompIcon *icon) -{ - return CompTexture::imageBufferToTexture (icon->texture, - (char *) (icon + 1), - icon->width, - icon->height); -} - bool CompTexture::bindPixmap (Pixmap pixmap, int width, diff --git a/src/window.cpp b/src/window.cpp index 743b4f8..314783d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -41,6 +41,7 @@ #include <compiz-core.h> #include <comptexture.h> +#include <compicon.h> #include "privatewindow.h" @@ -3884,7 +3885,7 @@ CompWindow::getIcon (int width, int height) int i, wh, diff, oldDiff; /* need to fetch icon property */ - if (priv->nIcon == 0) + if (priv->icons.size () == 0 && !priv->noIcons) { Atom actual; int result, format; @@ -3917,29 +3918,13 @@ CompWindow::getIcon (int width, int height) if (iw && ih) { - icon = (CompIcon *) malloc (sizeof (CompIcon) + - iw * ih * sizeof (CARD32)); + icon = new CompIcon (priv->screen, iw, ih); if (!icon) continue; - pIcon = (CompIcon **) realloc (priv->icon, - sizeof (CompIcon *) * (priv->nIcon + 1)); - if (!pIcon) - { - free (icon); - continue; - } - - priv->icon = pIcon; - priv->icon[priv->nIcon] = icon; - priv->nIcon++; - - icon->width = iw; - icon->height = ih; + priv->icons.push_back (icon); - icon->texture = new CompTexture (priv->screen); - - p = (CARD32 *) (icon + 1); + p = (CARD32 *) (icon->data ()); /* EWMH doesn't say if icon data is premultiplied or not but most applications seem to assume data should @@ -3968,32 +3953,34 @@ CompWindow::getIcon (int width, int height) } /* don't fetch property again */ - if (priv->nIcon == 0) - priv->nIcon = -1; + if (priv->icons.size() == 0) + priv->noIcons = true; } /* no icons available for this window */ - if (priv->nIcon == -1) + if (priv->noIcons) return NULL; icon = NULL; wh = width + height; - for (i = 0; i < priv->nIcon; i++) + for (i = 0; i < priv->icons.size (); i++) { - if (priv->icon[i]->width > width || priv->icon[i]->height > height) + if (priv->icons[i]->width () > width || + priv->icons[i]->height () > height) continue; if (icon) { - diff = wh - (priv->icon[i]->width + priv->icon[i]->height); - oldDiff = wh - (icon->width + icon->height); + diff = wh - (priv->icons[i]->width () + + priv->icons[i]->height ()); + oldDiff = wh - (icon->width () + icon->height ()); if (diff < oldDiff) - icon = priv->icon[i]; + icon = priv->icons[i]; } else - icon = priv->icon[i]; + icon = priv->icons[i]; } return icon; @@ -4004,19 +3991,13 @@ CompWindow::freeIcons () { int i; - for (i = 0; i < priv->nIcon; i++) - { - delete priv->icon[i]->texture; - free (priv->icon[i]); - } - - if (priv->icon) + for (unsigned int i = 0; i < priv->icons.size (); i++) { - free (priv->icon); - priv->icon = NULL; + delete priv->icons[i]; } - priv->nIcon = 0; + priv->icons.resize (0); + priv->noIcons = false; } int @@ -5267,8 +5248,8 @@ PrivateWindow::PrivateWindow (CompWindow *window, CompScreen *screen) : struts (0), - icon (0), - nIcon (0), + icons (0), + noIcons (false), iconGeometrySet (false), @@ -5343,7 +5324,7 @@ PrivateWindow::~PrivateWindow () if (struts) free (struts); - if (icon) + if (icons.size ()) window->freeIcons (); if (startupId) |