summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/core/icon.h8
-rw-r--r--include/core/screen.h33
-rw-r--r--include/opengl/texture.h23
-rw-r--r--plugins/opengl/screen.cpp18
-rw-r--r--plugins/opengl/texture.cpp38
-rw-r--r--plugins/opengl/window.cpp7
-rw-r--r--src/icon.cpp15
-rw-r--r--src/screen.cpp104
-rw-r--r--src/window.cpp11
9 files changed, 114 insertions, 143 deletions
diff --git a/include/core/icon.h b/include/core/icon.h
index 3e60677..ba3ad38 100644
--- a/include/core/icon.h
+++ b/include/core/icon.h
@@ -28,6 +28,8 @@
#ifndef _COMPICON_H
#define _COMPICON_H
+#include <core/size.h>
+
class CompScreen;
class CompIcon {
@@ -35,13 +37,11 @@ class CompIcon {
CompIcon (CompScreen *screen, unsigned width, unsigned int height);
~CompIcon ();
- unsigned int width () const;
- unsigned int height () const;
+ const CompSize & size () const;
unsigned char* data ();
private:
- int mWidth;
- unsigned int mHeight;
+ CompSize mSize;
unsigned char *mData;
};
diff --git a/include/core/screen.h b/include/core/screen.h
index 595ee46..8a75ad9 100644
--- a/include/core/screen.h
+++ b/include/core/screen.h
@@ -102,12 +102,10 @@ class ScreenInterface : public WrapableInterface<CompScreen, ScreenInterface> {
virtual void handleCompizEvent (const char * plugin, const char *event,
CompOption::Vector &options);
- virtual bool fileToImage (const char *path, const char *name,
- int *width, int *height,
- int *stride, void **data);
- virtual bool imageToFile (const char *path, const char *name,
- const char *format, int width, int height,
- int stride, void *data);
+ virtual bool fileToImage (CompString &path, CompSize &size,
+ int &stride, void *&data);
+ virtual bool imageToFile (CompString &path, CompString &format,
+ CompSize &size, int stride, void *data);
virtual CompMatch::Expression *matchInitExp (const CompString value);
@@ -193,19 +191,15 @@ class CompScreen :
CompWindow * findTopLevelWindow (Window id,
bool override_redirect = false);
- bool readImageFromFile (const char *name,
- int *width,
- int *height,
- void **data);
+ bool readImageFromFile (CompString &name,
+ CompSize &size,
+ void *&data);
- bool writeImageToFile (const char *path,
- const char *name,
+ bool writeImageToFile (CompString &path,
const char *format,
- int width,
- int height,
+ CompSize &size,
void *data);
-
unsigned int getWindowProp (Window id,
Atom property,
unsigned int defaultValue);
@@ -338,11 +332,10 @@ class CompScreen :
WRAPABLE_HND (7, ScreenInterface, void, handleCompizEvent,
const char *, const char *, CompOption::Vector &)
- WRAPABLE_HND (8, ScreenInterface, bool, fileToImage, const char *,
- const char *, int *, int *, int *, void **data)
- WRAPABLE_HND (9, ScreenInterface, bool, imageToFile, const char *,
- const char *, const char *, int, int, int, void *)
-
+ WRAPABLE_HND (8, ScreenInterface, bool, fileToImage, CompString &,
+ CompSize &, int &, void *&);
+ WRAPABLE_HND (9, ScreenInterface, bool, imageToFile, CompString &,
+ CompString &, CompSize &, int, void *);
WRAPABLE_HND (10, ScreenInterface, CompMatch::Expression *,
matchInitExp, const CompString);
diff --git a/include/opengl/texture.h b/include/opengl/texture.h
index a768e22..22aeab4 100644
--- a/include/opengl/texture.h
+++ b/include/opengl/texture.h
@@ -105,19 +105,16 @@ class GLTexture {
int height,
int depth);
- static List imageBufferToTexture (const char *image,
- unsigned int width,
- unsigned int height);
-
- static List imageDataToTexture (const char *image,
- unsigned int width,
- unsigned int height,
- GLenum format,
- GLenum type);
-
- static List readImageToTexture (const char *imageFileName,
- unsigned int *returnWidth,
- unsigned int *returnHeight);
+ static List imageBufferToTexture (const char *image,
+ CompSize size);
+
+ static List imageDataToTexture (const char *image,
+ CompSize size,
+ GLenum format,
+ GLenum type);
+
+ static List readImageToTexture (CompString &imageFileName,
+ CompSize &size);
friend class PrivateTexture;
diff --git a/plugins/opengl/screen.cpp b/plugins/opengl/screen.cpp
index d2196e9..9fbb5a6 100644
--- a/plugins/opengl/screen.cpp
+++ b/plugins/opengl/screen.cpp
@@ -782,8 +782,12 @@ PrivateGLScreen::updateScreenBackground ()
}
if (backgroundTextures.empty () && backgroundImage)
- backgroundTextures =
- GLTexture::readImageToTexture (backgroundImage, &width, &height);
+ {
+ CompSize size;
+ CompString fileName (backgroundImage);
+
+ backgroundTextures = GLTexture::readImageToTexture (fileName, size);
+ }
if (!backgroundTextures.empty ())
{
@@ -1152,16 +1156,20 @@ GLTexture *
GLScreen::defaultIcon ()
{
CompIcon *i = screen->defaultIcon ();
+ CompSize size;
- if (!i || !i->width () || !i->height ())
+ if (!i)
+ return NULL;
+
+ size = i->size ();
+ if (!size.width () || !size.height ())
return NULL;
if (priv->defaultIcon.icon == i)
return priv->defaultIcon.textures[0];
priv->defaultIcon.textures =
- GLTexture::imageBufferToTexture ((char *) i->data (),
- i->width (), i->height ());
+ GLTexture::imageBufferToTexture ((char *) i->data (), size);
if (priv->defaultIcon.textures.size () == 1)
priv->defaultIcon.icon = i;
diff --git a/plugins/opengl/texture.cpp b/plugins/opengl/texture.cpp
index 3f5a2c3..c0f2f06 100644
--- a/plugins/opengl/texture.cpp
+++ b/plugins/opengl/texture.cpp
@@ -348,51 +348,43 @@ PrivateTexture::loadImageData (const char *image,
}
GLTexture::List
-GLTexture::imageBufferToTexture (const char *image,
- unsigned int width,
- unsigned int height)
+GLTexture::imageBufferToTexture (const char *image,
+ CompSize size)
{
#if IMAGE_BYTE_ORDER == MSBFirst
- return PrivateTexture::loadImageData (image, width, height,
+ return PrivateTexture::loadImageData (image, size.width (), size.height (),
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV);
#else
- return PrivateTexture::loadImageData (image, width, height,
+ return PrivateTexture::loadImageData (image, size.width (), size.height (),
GL_BGRA, GL_UNSIGNED_BYTE);
#endif
}
GLTexture::List
-GLTexture::imageDataToTexture (const char *image,
- unsigned int width,
- unsigned int height,
- GLenum format,
- GLenum type)
+GLTexture::imageDataToTexture (const char *image,
+ CompSize size,
+ GLenum format,
+ GLenum type)
{
- return PrivateTexture::loadImageData (image, width, height, format, type);
+ return PrivateTexture::loadImageData (image, size.width (), size.height (),
+ format, type);
}
GLTexture::List
-GLTexture::readImageToTexture (const char *imageFileName,
- unsigned int *returnWidth,
- unsigned int *returnHeight)
+GLTexture::readImageToTexture (CompString &imageFileName,
+ CompSize &size)
{
- void *image;
- int width, height;
+ void *image;
- if (screen->readImageFromFile (imageFileName, &width, &height, &image))
+ if (screen->readImageFromFile (imageFileName, size, image))
return GLTexture::List ();
GLTexture::List rv =
- GLTexture::imageBufferToTexture ((char *)image, width, height);
+ GLTexture::imageBufferToTexture ((char *)image, size);
free (image);
- if (returnWidth)
- *returnWidth = width;
- if (returnHeight)
- *returnHeight = height;
-
return rv;
}
diff --git a/plugins/opengl/window.cpp b/plugins/opengl/window.cpp
index f4f4ef8..b08d73d 100644
--- a/plugins/opengl/window.cpp
+++ b/plugins/opengl/window.cpp
@@ -323,11 +323,13 @@ GLWindow::getIcon (int width, int height)
{
GLIcon icon;
CompIcon *i = priv->window->getIcon (width, height);
+ CompSize size;
if (!i)
return NULL;
- if (!i->width () || !i->height ())
+ size = i->size ();
+ if (!size.width () || !size.height ())
return NULL;
foreach (GLIcon &icon, priv->icons)
@@ -335,8 +337,7 @@ GLWindow::getIcon (int width, int height)
return icon.textures[0];
icon.icon = i;
- icon.textures = GLTexture::imageBufferToTexture ((char *) i->data (),
- i->width (), i->height ());
+ icon.textures = GLTexture::imageBufferToTexture ((char *) i->data (), size);
if (icon.textures.size () > 1 || icon.textures.size () == 0)
return NULL;
diff --git a/src/icon.cpp b/src/icon.cpp
index 46cd537..aa17e35 100644
--- a/src/icon.cpp
+++ b/src/icon.cpp
@@ -29,8 +29,7 @@
CompIcon::CompIcon (CompScreen *screen, unsigned int width,
unsigned int height) :
- mWidth (width),
- mHeight (height),
+ mSize (width, height),
mData (new unsigned char[width * height * 4])
{
}
@@ -40,16 +39,10 @@ CompIcon::~CompIcon ()
delete mData;
}
-unsigned int
-CompIcon::width () const
+const CompSize &
+CompIcon::size () const
{
- return mWidth;
-}
-
-unsigned int
-CompIcon::height () const
-{
- return mHeight;
+ return mSize;
}
unsigned char*
diff --git a/src/screen.cpp b/src/screen.cpp
index 8d74862..7e8c3b8 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -1298,52 +1298,46 @@ PrivateScreen::handleSelectionClear (XEvent *event)
#define HOME_IMAGEDIR ".compiz/images"
bool
-CompScreen::readImageFromFile (const char *name,
- int *width,
- int *height,
- void **data)
+CompScreen::readImageFromFile (CompString &name,
+ CompSize &size,
+ void *&data)
{
- Bool status;
+ bool status;
int stride;
- status = fileToImage (NULL, name, width, height, &stride, data);
+ status = fileToImage (name, size, stride, data);
if (!status)
{
- char *home;
-
- home = getenv ("HOME");
+ char *home = getenv ("HOME");
+ CompString path;
if (home)
{
- char *path;
-
- path = (char *) malloc (strlen (home) + strlen (HOME_IMAGEDIR) + 2);
- if (path)
- {
- sprintf (path, "%s/%s", home, HOME_IMAGEDIR);
- status = fileToImage (path, name, width, height, &stride, data);
+ path = home;
+ path += "/";
+ path += HOME_IMAGEDIR;
+ path += name;
- free (path);
+ status = fileToImage (path, size, stride, data);
- if (status)
- return TRUE;
- }
+ if (status)
+ return true;
}
- status = fileToImage (IMAGEDIR, name, width, height, &stride, data);
+ path = IMAGEDIR + name;
+ status = fileToImage (path, size, stride, data);
}
return status;
}
bool
-CompScreen::writeImageToFile (const char *path,
- const char *name,
+CompScreen::writeImageToFile (CompString &path,
const char *format,
- int width,
- int height,
+ CompSize &size,
void *data)
{
- return imageToFile (path, name, format, width, height, width * 4, data);
+ CompString formatString (format);
+ return imageToFile (path, formatString, size, size.width () * 4, data);
}
Window
@@ -1372,29 +1366,24 @@ PrivateScreen::getActiveWindow (Window root)
bool
-CompScreen::fileToImage (const char *path,
- const char *name,
- int *width,
- int *height,
- int *stride,
- void **data)
-{
- WRAPABLE_HND_FUNC_RETURN(8, bool, fileToImage, path, name, width, height,
- stride, data)
+CompScreen::fileToImage (CompString &name,
+ CompSize &size,
+ int &stride,
+ void *&data)
+{
+ WRAPABLE_HND_FUNC_RETURN(8, bool, fileToImage, name, size, stride, data);
return false;
}
bool
-CompScreen::imageToFile (const char *path,
- const char *name,
- const char *format,
- int width,
- int height,
+CompScreen::imageToFile (CompString &path,
+ CompString &format,
+ CompSize &size,
int stride,
void *data)
{
- WRAPABLE_HND_FUNC_RETURN(9, bool, imageToFile, path, name, format, width,
- height, stride, data)
+ WRAPABLE_HND_FUNC_RETURN(9, bool, imageToFile, path, format, size,
+ stride, data)
return false;
}
@@ -1856,23 +1845,19 @@ ScreenInterface::handleCompizEvent (const char *plugin,
WRAPABLE_DEF (handleCompizEvent, plugin, event, options)
bool
-ScreenInterface::fileToImage (const char *path,
- const char *name,
- int *width,
- int *height,
- int *stride,
- void **data)
- WRAPABLE_DEF (fileToImage, path, name, width, height, stride, data)
+ScreenInterface::fileToImage (CompString &name,
+ CompSize &size,
+ int &stride,
+ void *&data)
+ WRAPABLE_DEF (fileToImage, name, size, stride, data)
bool
-ScreenInterface::imageToFile (const char *path,
- const char *name,
- const char *format,
- int width,
- int height,
+ScreenInterface::imageToFile (CompString &path,
+ CompString &format,
+ CompSize &size,
int stride,
void *data)
- WRAPABLE_DEF (imageToFile, path, name, format, width, height, stride, data)
+ WRAPABLE_DEF (imageToFile, path, format, size, stride, data)
CompMatch::Expression *
ScreenInterface::matchInitExp (const CompString value)
@@ -4045,7 +4030,7 @@ PrivateScreen::updateDefaultIcon ()
{
CompString file = priv->opt[COMP_OPTION_DEFAULT_ICON].value ().s ();
void *data;
- int width, height;
+ CompSize size;
if (priv->defaultIcon)
{
@@ -4053,12 +4038,13 @@ PrivateScreen::updateDefaultIcon ()
priv->defaultIcon = NULL;
}
- if (!screen->readImageFromFile (file.c_str (), &width, &height, &data))
+ if (!screen->readImageFromFile (file, size, data))
return false;
- priv->defaultIcon = new CompIcon (screen, width, height);
+ priv->defaultIcon = new CompIcon (screen, size.width (), size.height ());
- memcpy (priv->defaultIcon->data (), data, width * height * sizeof (CARD32));
+ memcpy (priv->defaultIcon->data (), data,
+ size.width () * size.height () * sizeof (CARD32));
free (data);
diff --git a/src/window.cpp b/src/window.cpp
index 3297d38..2437a6e 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -3714,15 +3714,16 @@ CompWindow::getIcon (int width, int height)
for (i = 0; i < priv->icons.size (); i++)
{
- if ((int) priv->icons[i]->width () > width ||
- (int) priv->icons[i]->height () > height)
+ const CompSize &iconSize = priv->icons[i]->size ();
+
+ if ((int) iconSize.width () > width ||
+ (int) iconSize.height () > height)
continue;
if (icon)
{
- diff = wh - (priv->icons[i]->width () +
- priv->icons[i]->height ());
- oldDiff = wh - (icon->width () + icon->height ());
+ diff = wh - (iconSize.width () + iconSize.height ());
+ oldDiff = wh - (icon->size ().width () + icon->size ().height ());
if (diff < oldDiff)
icon = priv->icons[i];