Commit 47af6a0b authored by Owen W. Taylor's avatar Owen W. Taylor

Nice looking scaledown with mipmap emulation

Add MutterTextureTower, an abstraction for getting a image with
the right level of detail for rendering at a particular scale,
by manually scaling down by powers of two.

This results in much better looking scaled window images when
mipmaps can't be used with texture_from_pixmap (which is the
typical case for current GL drivers.)

When framebuffer objects are available, they are used to do
the scaledown using the GPU without having to pull the data
back from video memory. A software codepath is also available
for the case when FBO's are not present, though performance
will suffer
parent 988d2ffa
......@@ -28,6 +28,8 @@ mutter_SOURCES= \
compositor/mutter-plugin-manager.c \
compositor/mutter-plugin-manager.h \
compositor/mutter-shaped-texture.c \
compositor/mutter-texture-tower.c \
compositor/mutter-texture-tower.h \
compositor/mutter-window.c \
compositor/mutter-window-private.h \
compositor/mutter-window-group.c \
......@@ -26,19 +26,27 @@
#include <config.h>
#include "mutter-shaped-texture.h"
#include "mutter-texture-tower.h"
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include <string.h>
static void mutter_shaped_texture_dispose (GObject *object);
static void mutter_shaped_texture_finalize (GObject *object);
static void mutter_shaped_texture_notify (GObject *object,
GParamSpec *pspec);
static void mutter_shaped_texture_paint (ClutterActor *actor);
static void mutter_shaped_texture_pick (ClutterActor *actor,
const ClutterColor *color);
static void mutter_shaped_texture_update_area (ClutterX11TexturePixmap *texture,
int x,
int y,
int width,
int height);
static void mutter_shaped_texture_dirty_mask (MutterShapedTexture *stex);
......@@ -55,6 +63,7 @@ G_DEFINE_TYPE (MutterShapedTexture, mutter_shaped_texture,
struct _MutterShapedTexturePrivate
MutterTextureTower *paint_tower;
CoglHandle mask_texture;
CoglHandle material;
CoglHandle material_unshaped;
......@@ -74,13 +83,17 @@ mutter_shaped_texture_class_init (MutterShapedTextureClass *klass)
GObjectClass *gobject_class = (GObjectClass *) klass;
ClutterActorClass *actor_class = (ClutterActorClass *) klass;
ClutterX11TexturePixmapClass *x11_texture_class = (ClutterX11TexturePixmapClass *) klass;
gobject_class->dispose = mutter_shaped_texture_dispose;
gobject_class->finalize = mutter_shaped_texture_finalize;
gobject_class->notify = mutter_shaped_texture_notify;
actor_class->paint = mutter_shaped_texture_paint;
actor_class->pick = mutter_shaped_texture_pick;
x11_texture_class->update_area = mutter_shaped_texture_update_area;
g_type_class_add_private (klass, sizeof (MutterShapedTexturePrivate));
......@@ -93,6 +106,7 @@ mutter_shaped_texture_init (MutterShapedTexture *self)
priv->rectangles = g_array_new (FALSE, FALSE, sizeof (XRectangle));
priv->paint_tower = mutter_texture_tower_new ();
priv->mask_texture = COGL_INVALID_HANDLE;
......@@ -102,6 +116,10 @@ mutter_shaped_texture_dispose (GObject *object)
MutterShapedTexture *self = (MutterShapedTexture *) object;
MutterShapedTexturePrivate *priv = self->priv;
if (priv->paint_tower)
mutter_texture_tower_free (priv->paint_tower);
priv->paint_tower = NULL;
mutter_shaped_texture_dirty_mask (self);
if (priv->material != COGL_INVALID_HANDLE)
......@@ -138,6 +156,28 @@ mutter_shaped_texture_finalize (GObject *object)
G_OBJECT_CLASS (mutter_shaped_texture_parent_class)->finalize (object);
static void
mutter_shaped_texture_notify (GObject *object,
GParamSpec *pspec)
if (G_OBJECT_CLASS (mutter_shaped_texture_parent_class)->notify)
G_OBJECT_CLASS (mutter_shaped_texture_parent_class)->notify (object, pspec);
/* It seems like we could just do this out of update_area(), but unfortunately,
* clutter_glx_texture_pixmap() doesn't call through the vtable on the
* initial update_area, so we need to look for changes to the texture
* explicitly.
if (strcmp (pspec->name, "cogl-texture") == 0)
MutterShapedTexture *stex = (MutterShapedTexture *) object;
MutterShapedTexturePrivate *priv = stex->priv;
mutter_texture_tower_set_base_texture (priv->paint_tower,
clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (stex)));
static void
mutter_shaped_texture_dirty_mask (MutterShapedTexture *stex)
......@@ -269,7 +309,30 @@ mutter_shaped_texture_paint (ClutterActor *actor)
clutter_actor_realize (CLUTTER_ACTOR (stex));
paint_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (stex));
/* If mipmaps are supported, then the texture filter quality will
* still be HIGH here. In that case we just want to use the base
* texture. If mipmaps are not support then
* on_glx_texture_pixmap_pre_paint() will have reset the texture
* filter quality to MEDIUM, and we should use the MutterTextureTower
* mipmap emulation.
* is an RFE
* for a better way of handling this.
* While it would be nice to have direct access to the 'can_mipmap'
* boolean in ClutterGLXTexturePixmap, since since MutterTextureTower
* creates the scaled down images on demand there is no substantial
* overhead from doing the work to create and update the tower and
* not using it, other than the memory allocated for the MutterTextureTower
* structure itself.
if (clutter_texture_get_filter_quality (CLUTTER_TEXTURE (stex)) == CLUTTER_TEXTURE_QUALITY_HIGH)
paint_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (stex));
paint_tex = mutter_texture_tower_get_paint_texture (priv->paint_tower);
if (paint_tex == COGL_INVALID_HANDLE)
tex_width = cogl_texture_get_width (paint_tex);
tex_height = cogl_texture_get_height (paint_tex);
......@@ -277,9 +340,6 @@ mutter_shaped_texture_paint (ClutterActor *actor)
if (tex_width == 0 || tex_height == 0) /* no contents yet */
if (paint_tex == COGL_INVALID_HANDLE)
if (priv->rectangles->len < 1)
/* If there are no rectangles use a single-layer texture */
......@@ -438,6 +498,22 @@ mutter_shaped_texture_pick (ClutterActor *actor,
static void
mutter_shaped_texture_update_area (ClutterX11TexturePixmap *texture,
int x,
int y,
int width,
int height)
MutterShapedTexture *stex = (MutterShapedTexture *) texture;
MutterShapedTexturePrivate *priv = stex->priv;
CLUTTER_X11_TEXTURE_PIXMAP_CLASS (mutter_shaped_texture_parent_class)->update_area (texture,
x, y, width, height);
mutter_texture_tower_update_area (priv->paint_tower, x, y, width, height);
ClutterActor *
mutter_shaped_texture_new (void)
This diff is collapsed.
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
* MutterTextureTower
* Mipmap emulation by creation of scaled down images
* Copyright (C) 2009 Red Hat, Inc.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
#include <clutter/clutter.h>
* SECTION:MutterTextureTower
* @short_description: mipmap emulation by creation of scaled down images
* A #MutterTextureTower is used to get good looking scaled down images when
* we can't use the GL drivers mipmap support. There are two separate reasons
* - Some cards (including radeon cards <= r5xx) only support
* TEXTURE_RECTANGLE_ARB and not NPOT textures. Rectangular textures
* are defined not to support mipmapping.
* - Even when NPOT textures are available, the combination of NPOT
* textures, texture_from_pixmap, and mipmapping doesn't typically
* work, since the X server doesn't allocate pixmaps in the right
* layout for mipmapping.
* So, what we do is create the "mipmap" levels ourselves by successive
* power-of-two scaledowns, and when rendering pick the single texture
* that best matches the scale we are rendering at. (Since we aren't
* typically using perspective transforms, we'll frequently have a single
* scale for the entire texture.)
typedef struct _MutterTextureTower MutterTextureTower;
MutterTextureTower *mutter_texture_tower_new (void);
void mutter_texture_tower_free (MutterTextureTower *tower);
void mutter_texture_tower_set_base_texture (MutterTextureTower *tower,
CoglHandle texture);
void mutter_texture_tower_update_area (MutterTextureTower *tower,
int x,
int y,
int width,
int height);
CoglHandle mutter_texture_tower_get_paint_texture (MutterTextureTower *tower);
#endif /* __MUTTER_TEXTURE_TOWER_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment