summarylogtreecommitdiffstats
path: root/mr2506.patch
blob: 2ae479997de92d8a41e159a4d21bc30f1a6f8c7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
Author: Neil Moore <dar13.dev@gmail.com>
Source: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2506
Editor: Sung Mingi <FiestaLake@protonmail.com>
Commit: 877dc33545e76cf71358d304caf39755b74081a7
Last Updated: 07/28/22 (Mutter 42.3+r4+gd96efc7b1-2)
---

By avoiding StScrollViewFade we avoid offscreening and therefore
avoid painting everything twice to get it on screen. So this almost
halves the render time of the icon grid.

(v2) Move the original functionality into its own separate class.

---
diff --git a/src/compositor/clutter-utils.c b/src/compositor/clutter-utils.c
index 86d788562e383c38961de1b385bb7bbf16424d28..95839c2df2eeb1498fbd124365117297ba67d2e0 100644
--- a/src/compositor/clutter-utils.c
+++ b/src/compositor/clutter-utils.c
@@ -69,8 +69,7 @@ gboolean
 meta_actor_vertices_are_untransformed (graphene_point3d_t *verts,
                                        float               widthf,
                                        float               heightf,
-                                       int                *x_origin,
-                                       int                *y_origin)
+                                       MetaTransforms     *out_transforms)
 {
   int width, height;
   int v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y;
@@ -90,6 +89,14 @@ meta_actor_vertices_are_untransformed (graphene_point3d_t *verts,
   x = v0x >> 8;
   y = v0y >> 8;
 
+  if (out_transforms)
+    {
+      out_transforms->x_origin = x;
+      out_transforms->y_origin = y;
+      out_transforms->x_scale = (v1x - v0x) / (float) width;
+      out_transforms->y_scale = (v2y - v0y) / (float) height;
+    }
+
   /* At integral coordinates? */
   if (x * 256 != v0x || y * 256 != v0y)
     return FALSE;
@@ -103,11 +110,6 @@ meta_actor_vertices_are_untransformed (graphene_point3d_t *verts,
       v3x != v1x || v3y != v2y)
     return FALSE;
 
-  if (x_origin)
-    *x_origin = x;
-  if (y_origin)
-    *y_origin = y;
-
   return TRUE;
 }
 
@@ -137,8 +139,7 @@ meta_actor_painting_untransformed (CoglFramebuffer *fb,
                                    int              paint_height,
                                    int              sample_width,
                                    int              sample_height,
-                                   int             *x_origin,
-                                   int             *y_origin)
+                                   MetaTransforms  *out_transforms)
 {
   graphene_matrix_t modelview, projection, modelview_projection;
   graphene_point3d_t vertices[4];
@@ -183,6 +184,6 @@ meta_actor_painting_untransformed (CoglFramebuffer *fb,
 
   return meta_actor_vertices_are_untransformed (vertices,
                                                 sample_width, sample_height,
-                                                x_origin, y_origin);
+                                                out_transforms);
 }
 
diff --git a/src/compositor/clutter-utils.h b/src/compositor/clutter-utils.h
index 8ed0e2a4d127d037a0371d01d1d7dbd349adc161..921551aafbb501606c0404f9d47ebad492d83e54 100644
--- a/src/compositor/clutter-utils.h
+++ b/src/compositor/clutter-utils.h
@@ -23,18 +23,21 @@
 
 #include "clutter/clutter.h"
 
+typedef struct {
+  int x_origin, y_origin;
+  float x_scale, y_scale;
+} MetaTransforms;
+
 gboolean meta_actor_vertices_are_untransformed (graphene_point3d_t *verts,
                                                 float               widthf,
                                                 float               heightf,
-                                                int                *x_origin,
-                                                int                *y_origin);
+                                                MetaTransforms     *out_transforms);
 
 gboolean meta_actor_painting_untransformed (CoglFramebuffer *fb,
                                             int              paint_width,
                                             int              paint_height,
                                             int              sample_widthf,
                                             int              sample_heightf,
-                                            int             *x_origin,
-                                            int             *y_origin);
+                                            MetaTransforms  *out_transforms);
 
 #endif /* __META_CLUTTER_UTILS_H__ */
diff --git a/src/compositor/meta-background-content.c b/src/compositor/meta-background-content.c
index 2e8c923b47723a365573a79efee71177fd9d9ce4..e472c3c5dc679668fa10054808637c676e0d262f 100644
--- a/src/compositor/meta-background-content.c
+++ b/src/compositor/meta-background-content.c
@@ -548,7 +548,7 @@ setup_pipeline (MetaBackgroundContent *self,
                                          actor_pixel_rect->height,
                                          self->texture_width,
                                          self->texture_height,
-                                         NULL, NULL))
+                                         NULL))
     {
       min_filter = COGL_PIPELINE_FILTER_NEAREST;
       mag_filter = COGL_PIPELINE_FILTER_NEAREST;
diff --git a/src/compositor/meta-cullable.c b/src/compositor/meta-cullable.c
index 6f38c5e47c8f8e219bd195fc2da274c97ba298ec..e306c56e287752ab9e09ec3958e205de3a4d47a9 100644
--- a/src/compositor/meta-cullable.c
+++ b/src/compositor/meta-cullable.c
@@ -175,7 +175,7 @@ meta_cullable_default_is_untransformed (MetaCullable *cullable)
   clutter_actor_get_abs_allocation_vertices (CLUTTER_ACTOR (cullable), verts);
 
   return meta_actor_vertices_are_untransformed (verts, width, height,
-                                                NULL, NULL);
+                                                NULL);
 }
 
 static void
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index d7cba799ea7c7bd1da7325084628f8bc04cc5155..b8e4dff5d5e9700886c831cca25a8e23c2201455 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -41,7 +41,7 @@
 
 #include "cogl/cogl.h"
 #include "compositor/clutter-utils.h"
-#include "compositor/meta-texture-tower.h"
+#include "compositor/meta-texture-mipmap.h"
 #include "compositor/region-utils.h"
 #include "core/boxes-private.h"
 #include "meta/meta-shaped-texture.h"
@@ -82,8 +82,6 @@ struct _MetaShapedTexture
 {
   GObject parent;
 
-  MetaTextureTower *paint_tower;
-
   CoglTexture *texture;
   CoglTexture *mask_texture;
   CoglSnippet *snippet;
@@ -96,6 +94,8 @@ struct _MetaShapedTexture
   CoglPipeline *unblended_pipeline;
   CoglPipeline *unblended_tower_pipeline;
 
+  MetaTextureMipmap *texture_mipmap;
+
   gboolean is_y_inverted;
 
   /* The region containing only fully opaque pixels */
@@ -154,8 +154,7 @@ invalidate_size (MetaShapedTexture *stex)
 static void
 meta_shaped_texture_init (MetaShapedTexture *stex)
 {
-  stex->paint_tower = meta_texture_tower_new ();
-
+  stex->texture_mipmap = meta_texture_mipmap_new ();
   stex->buffer_scale = 1;
   stex->texture = NULL;
   stex->mask_texture = NULL;
@@ -259,9 +258,7 @@ meta_shaped_texture_dispose (GObject *object)
 
   g_clear_handle_id (&stex->remipmap_timeout_id, g_source_remove);
 
-  if (stex->paint_tower)
-    meta_texture_tower_free (stex->paint_tower);
-  stex->paint_tower = NULL;
+  g_clear_pointer (&stex->texture_mipmap, meta_texture_mipmap_free);
 
   g_clear_pointer (&stex->texture, cogl_object_unref);
 
@@ -618,13 +615,8 @@ set_cogl_texture (MetaShapedTexture *stex,
       update_size (stex);
     }
 
-  /* NB: We don't queue a redraw of the actor here because we don't
-   * know how much of the buffer has changed with respect to the
-   * previous buffer. We only queue a redraw in response to surface
-   * damage. */
-
-  if (stex->create_mipmaps)
-    meta_texture_tower_set_base_texture (stex->paint_tower, cogl_tex);
+  meta_texture_mipmap_set_base_texture (stex->texture_mipmap, stex->texture);
+  meta_texture_mipmap_invalidate (stex->texture_mipmap);
 }
 
 static gboolean
@@ -652,11 +644,14 @@ flip_ints (int *x,
   *y = tmp;
 }
 
+static CoglTexture *
+select_texture_for_paint (MetaShapedTexture   *stex,
+                          ClutterPaintContext *paint_context);
+
 static void
 do_paint_content (MetaShapedTexture   *stex,
                   ClutterPaintNode    *root_node,
                   ClutterPaintContext *paint_context,
-                  CoglTexture         *paint_tex,
                   ClutterActorBox     *alloc,
                   uint8_t              opacity)
 {
@@ -665,7 +660,9 @@ do_paint_content (MetaShapedTexture   *stex,
   gboolean use_opaque_region;
   cairo_region_t *blended_tex_region;
   CoglContext *ctx;
-  CoglPipelineFilter filter;
+  CoglPipelineFilter min_filter, mag_filter;
+  MetaTransforms transforms;
+  CoglTexture *paint_tex = stex->texture;
   CoglFramebuffer *framebuffer;
   int sample_width, sample_height;
   gboolean debug_paint_opaque_region;
@@ -712,10 +709,31 @@ do_paint_content (MetaShapedTexture   *stex,
   if (meta_actor_painting_untransformed (framebuffer,
                                          dst_width, dst_height,
                                          sample_width, sample_height,
-                                         NULL, NULL))
-    filter = COGL_PIPELINE_FILTER_NEAREST;
+                                         &transforms))
+    {
+      min_filter = COGL_PIPELINE_FILTER_NEAREST;
+      mag_filter = COGL_PIPELINE_FILTER_NEAREST;
+
+      /* Back to normal desktop viewing. Save some memory */
+      meta_texture_mipmap_clear (stex->texture_mipmap);
+    }
   else
-    filter = COGL_PIPELINE_FILTER_LINEAR;
+    {
+      min_filter = COGL_PIPELINE_FILTER_LINEAR;
+      mag_filter = COGL_PIPELINE_FILTER_LINEAR;
+
+      /* If we're painting a texture below half its native resolution
+       * then mipmapping is required to avoid aliasing. If it's above
+       * half then sticking with COGL_PIPELINE_FILTER_LINEAR will look
+       * and perform better.
+       */
+      if (stex->create_mipmaps &&
+          transforms.x_scale < 0.5 &&
+          transforms.y_scale < 0.5)
+        {
+          paint_tex = select_texture_for_paint (stex, paint_context);
+        }
+    }
 
   ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
 
@@ -777,7 +795,7 @@ do_paint_content (MetaShapedTexture   *stex,
 
           opaque_pipeline = get_unblended_pipeline (stex, ctx, paint_tex);
           cogl_pipeline_set_layer_texture (opaque_pipeline, 0, paint_tex);
-          cogl_pipeline_set_layer_filters (opaque_pipeline, 0, filter, filter);
+          cogl_pipeline_set_layer_filters (opaque_pipeline, 0, min_filter, mag_filter);
 
           n_rects = cairo_region_num_rectangles (region);
           for (i = 0; i < n_rects; i++)
@@ -825,11 +843,11 @@ do_paint_content (MetaShapedTexture   *stex,
         {
           blended_pipeline = get_masked_pipeline (stex, ctx, paint_tex);
           cogl_pipeline_set_layer_texture (blended_pipeline, 1, stex->mask_texture);
-          cogl_pipeline_set_layer_filters (blended_pipeline, 1, filter, filter);
+          cogl_pipeline_set_layer_filters (blended_pipeline, 1, min_filter, mag_filter);
         }
 
       cogl_pipeline_set_layer_texture (blended_pipeline, 0, paint_tex);
-      cogl_pipeline_set_layer_filters (blended_pipeline, 0, filter, filter);
+      cogl_pipeline_set_layer_filters (blended_pipeline, 0, min_filter, mag_filter);
 
       CoglColor color;
       cogl_color_init_from_4ub (&color, opacity, opacity, opacity, opacity);
@@ -913,8 +931,7 @@ select_texture_for_paint (MetaShapedTexture   *stex,
       if (age >= MIN_MIPMAP_AGE_USEC ||
           stex->fast_updates < MIN_FAST_UPDATES_BEFORE_UNMIPMAP)
         {
-          texture = meta_texture_tower_get_paint_texture (stex->paint_tower,
-                                                          paint_context);
+          texture = meta_texture_mipmap_get_paint_texture (stex->texture_mipmap);
         }
     }
 
@@ -946,7 +963,6 @@ meta_shaped_texture_paint_content (ClutterContent      *content,
 {
   MetaShapedTexture *stex = META_SHAPED_TEXTURE (content);
   ClutterActorBox alloc;
-  CoglTexture *paint_tex = NULL;
   uint8_t opacity;
 
   if (stex->clip_region && cairo_region_is_empty (stex->clip_region))
@@ -967,14 +983,13 @@ meta_shaped_texture_paint_content (ClutterContent      *content,
    * Setting the texture quality to high without SGIS_generate_mipmap
    * support for TFP textures will result in fallbacks to XGetImage.
    */
-  paint_tex = select_texture_for_paint (stex, paint_context);
-  if (!paint_tex)
+  if (stex->texture == NULL)
     return;
 
   opacity = clutter_actor_get_paint_opacity (actor);
   clutter_actor_get_content_box (actor, &alloc);
 
-  do_paint_content (stex, root_node, paint_context, paint_tex, &alloc, opacity);
+  do_paint_content (stex, root_node, paint_context, &alloc, opacity);
 }
 
 static gboolean
@@ -1012,10 +1027,10 @@ meta_shaped_texture_set_create_mipmaps (MetaShapedTexture *stex,
 
   if (create_mipmaps != stex->create_mipmaps)
     {
-      CoglTexture *base_texture;
       stex->create_mipmaps = create_mipmaps;
-      base_texture = create_mipmaps ? stex->texture : NULL;
-      meta_texture_tower_set_base_texture (stex->paint_tower, base_texture);
+
+      if (!stex->create_mipmaps)
+        meta_texture_mipmap_clear (stex->texture_mipmap);
     }
 }
 
@@ -1144,11 +1159,7 @@ meta_shaped_texture_update_area (MetaShapedTexture     *stex,
                                      clip);
     }
 
-  meta_texture_tower_update_area (stex->paint_tower,
-                                  x,
-                                  y,
-                                  width,
-                                  height);
+  meta_texture_mipmap_invalidate (stex->texture_mipmap);
 
   stex->prev_invalidation = stex->last_invalidation;
   stex->last_invalidation = g_get_monotonic_time ();
@@ -1214,8 +1225,6 @@ meta_shaped_texture_set_snippet (MetaShapedTexture *stex,
   g_clear_pointer (&stex->snippet, cogl_object_unref);
   if (snippet)
     stex->snippet = cogl_object_ref (snippet);
-
-  meta_texture_tower_set_snippet (stex->paint_tower, snippet);
 }
 
 /**
diff --git a/src/compositor/meta-surface-actor.c b/src/compositor/meta-surface-actor.c
index c2bf6696a2092882215da37ef865ddaeb79bf5e4..fcd94b86d3a3e3e0df6923095196a9ee3c4a5e6c 100644
--- a/src/compositor/meta-surface-actor.c
+++ b/src/compositor/meta-surface-actor.c
@@ -331,7 +331,7 @@ meta_surface_actor_is_untransformed (MetaCullable *cullable)
   return meta_actor_vertices_are_untransformed (verts,
                                                 width * geometry_scale,
                                                 height * geometry_scale,
-                                                NULL, NULL);
+                                                NULL);
 }
 
 static void
diff --git a/src/compositor/meta-texture-mipmap.c b/src/compositor/meta-texture-mipmap.c
new file mode 100644
index 0000000000000000000000000000000000000000..2ee9190e2781b857d3ee41b6fbfe94cc07567ba1
--- /dev/null
+++ b/src/compositor/meta-texture-mipmap.c
@@ -0,0 +1,240 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * MetaTextureMipmap
+ *
+ * Mipmap management object using OpenGL
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "compositor/meta-texture-mipmap.h"
+
+#include <math.h>
+#include <string.h>
+
+struct _MetaTextureMipmap
+{
+  CoglTexture *base_texture;
+  CoglTexture *mipmap_texture;
+  CoglPipeline *pipeline;
+  CoglFramebuffer *fb;
+  gboolean invalid;
+};
+
+/**
+ * meta_texture_mipmap_new:
+ *
+ * Creates a new mipmap handler. The base texture has to be set with
+ * meta_texture_mipmap_set_base_texture() before use.
+ *
+ * Return value: the new texture mipmap handler. Free with meta_texture_mipmap_free()
+ */
+MetaTextureMipmap *
+meta_texture_mipmap_new (void)
+{
+  MetaTextureMipmap *mipmap;
+
+  mipmap = g_new0 (MetaTextureMipmap, 1);
+
+  return mipmap;
+}
+
+/**
+ * meta_texture_mipmap_free:
+ * @mipmap: a #MetaTextureMipmap
+ *
+ * Frees a texture mipmap handler created with meta_texture_mipmap_new().
+ */
+void
+meta_texture_mipmap_free (MetaTextureMipmap *mipmap)
+{
+  g_return_if_fail (mipmap != NULL);
+
+  cogl_clear_object (&mipmap->pipeline);
+
+  meta_texture_mipmap_set_base_texture (mipmap, NULL);
+
+  g_free (mipmap);
+}
+
+/**
+ * meta_texture_mipmap_set_base_texture:
+ * @mipmap: a #MetaTextureMipmap
+ * @texture: the new texture used as a base for scaled down versions
+ *
+ * Sets the base texture that is the scaled texture that the
+ * scaled textures of the tower are derived from. The texture itself
+ * will be used as level 0 of the tower and will be referenced until
+ * unset or until the tower is freed.
+ */
+void
+meta_texture_mipmap_set_base_texture (MetaTextureMipmap *mipmap,
+                                      CoglTexture      *texture)
+{
+  g_return_if_fail (mipmap != NULL);
+
+  if (texture == mipmap->base_texture)
+    return;
+
+  if (mipmap->base_texture != NULL)
+    {
+      cogl_object_unref (mipmap->base_texture);
+    }
+
+  mipmap->base_texture = texture;
+
+  if (mipmap->base_texture != NULL)
+    {
+      cogl_object_ref (mipmap->base_texture);
+      mipmap->invalid = TRUE;
+    }
+}
+
+void
+meta_texture_mipmap_invalidate (MetaTextureMipmap *mipmap)
+{
+  g_return_if_fail (mipmap != NULL);
+
+  mipmap->invalid = TRUE;
+}
+
+static void
+free_mipmaps (MetaTextureMipmap *mipmap)
+{
+  g_clear_object (&mipmap->fb);
+  cogl_clear_object (&mipmap->mipmap_texture);
+}
+
+void
+meta_texture_mipmap_clear (MetaTextureMipmap *mipmap)
+{
+  g_return_if_fail (mipmap != NULL);
+
+  free_mipmaps (mipmap);
+}
+
+static void
+ensure_mipmap_texture (MetaTextureMipmap *mipmap)
+{
+  CoglContext *ctx =
+    clutter_backend_get_cogl_context (clutter_get_default_backend ());
+  int width, height;
+
+  /* Let's avoid spending any texture memory copying the base level texture
+   * because we'll never need that one and it would have used most of the
+   * memory;
+   *    S(0) = W x H
+   *    S(n) = S(n-1) / 4
+   *    sum to infinity of S(n) = 4/3 * S(0)
+   * So subtracting S(0) means even infinite mipmap levels only need one third
+   * of the original texture's memory. Finite levels need less.
+   *
+   * The fact that mipmap level 0 of mipmap texture is half the
+   * resolution of original texture makes no visual difference, so long as you're
+   * never trying to view a level of detail higher than half. If you need that
+   * then just use the original texture instead of mipmap texture, which is
+   * faster anyway.
+   */
+  width = cogl_texture_get_width (mipmap->base_texture) / 2;
+  height = cogl_texture_get_height (mipmap->base_texture) / 2;
+
+  if (!width || !height)
+    {
+      free_mipmaps (mipmap);
+      return;
+    }
+
+  if (!mipmap->mipmap_texture ||
+      cogl_texture_get_width (mipmap->mipmap_texture) != width ||
+      cogl_texture_get_height (mipmap->mipmap_texture) != height)
+    {
+      CoglOffscreen *offscreen;
+      CoglTexture2D *tex2d;
+
+      free_mipmaps (mipmap);
+
+      tex2d = cogl_texture_2d_new_with_size (ctx, width, height);
+      if (!tex2d)
+        return;
+
+      mipmap->mipmap_texture = COGL_TEXTURE (tex2d);
+
+      offscreen = cogl_offscreen_new_with_texture (mipmap->mipmap_texture);
+      if (!offscreen)
+        {
+          free_mipmaps (mipmap);
+          return;
+        }
+
+      mipmap->fb = COGL_FRAMEBUFFER (offscreen);
+
+      if (!cogl_framebuffer_allocate (mipmap->fb, NULL))
+        {
+          free_mipmaps (mipmap);
+          return;
+        }
+
+      cogl_framebuffer_orthographic (mipmap->fb,
+                                     0, 0, width, height, -1.0, 1.0);
+
+      mipmap->invalid = TRUE;
+    }
+
+  if (mipmap->invalid)
+    {
+      if (!mipmap->pipeline)
+        {
+          mipmap->pipeline = cogl_pipeline_new (ctx);
+          cogl_pipeline_set_blend (mipmap->pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL);
+          cogl_pipeline_set_layer_filters (mipmap->pipeline, 0,
+                                           COGL_PIPELINE_FILTER_LINEAR,
+                                           COGL_PIPELINE_FILTER_LINEAR);
+        }
+
+      cogl_pipeline_set_layer_texture (mipmap->pipeline, 0, mipmap->base_texture);
+      cogl_framebuffer_draw_textured_rectangle (mipmap->fb,
+                                                mipmap->pipeline,
+                                                0, 0, width, height,
+                                                0.0, 0.0, 1.0, 1.0);
+
+      mipmap->invalid = FALSE;
+    }
+}
+
+/**
+ * meta_texture_tower_get_paint_texture:
+ * @mipmap: a #MetaTextureMipmap
+ *
+ * Gets the texture from the tower that best matches the current
+ * rendering scale. (On the assumption here the texture is going to
+ * be rendered with vertex coordinates that correspond to its
+ * size in pixels, so a 200x200 texture will be rendered on the
+ * rectangle (0, 0, 200, 200).
+ *
+ * Return value: the COGL texture handle to use for painting, or
+ *  %NULL if no base texture has yet been set.
+ */
+CoglTexture *
+meta_texture_mipmap_get_paint_texture (MetaTextureMipmap *mipmap)
+{
+  g_return_val_if_fail (mipmap != NULL, NULL);
+
+  ensure_mipmap_texture (mipmap);
+
+  return mipmap->mipmap_texture;
+}
diff --git a/src/compositor/meta-texture-mipmap.h b/src/compositor/meta-texture-mipmap.h
new file mode 100644
index 0000000000000000000000000000000000000000..fd83a49c27e83740de19f35cceba29f1697afa8e
--- /dev/null
+++ b/src/compositor/meta-texture-mipmap.h
@@ -0,0 +1,54 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * MetaTextureMipmap
+ *
+ * Mipmap management object using OpenGL
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef META_TEXTURE_MIPMAP_H
+#define META_TEXTURE_MIPMAP_H
+
+#include "clutter/clutter.h"
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION:MetaTextureMipmap
+ * @short_description: mipmap handling for textures
+ *
+ * A #MetaTextureMipmap is used to get GL mipmaps for a texture
+ */
+
+typedef struct _MetaTextureMipmap MetaTextureMipmap;
+
+MetaTextureMipmap *meta_texture_mipmap_new (void);
+
+void meta_texture_mipmap_free (MetaTextureMipmap *mipmap);
+
+void meta_texture_mipmap_set_base_texture (MetaTextureMipmap *mipmap,
+                                           CoglTexture *texture);
+
+CoglTexture *meta_texture_mipmap_get_paint_texture (MetaTextureMipmap *mipmap);
+
+void meta_texture_mipmap_invalidate (MetaTextureMipmap *mipmap);
+
+void meta_texture_mipmap_clear (MetaTextureMipmap *mipmap);
+
+G_END_DECLS
+
+#endif /* META_TEXTURE_MIPMAP_H */
diff --git a/src/compositor/meta-texture-tower.c b/src/compositor/meta-texture-tower.c
deleted file mode 100644
index 510e85f7968eb09edaace5479a0ac9d43f4d9728..0000000000000000000000000000000000000000
--- a/src/compositor/meta-texture-tower.c
+++ /dev/null
@@ -1,513 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * MetaTextureTower
- *
- * 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
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <string.h>
-
-#include "compositor/meta-texture-tower.h"
-
-#ifndef M_LOG2E
-#define M_LOG2E 1.4426950408889634074
-#endif
-
-#define MAX_TEXTURE_LEVELS 12
-
-/* If the texture format in memory doesn't match this, then Mesa
- * will do the conversion, so things will still work, but it might
- * be slow depending on how efficient Mesa is. These should be the
- * native formats unless the display is 16bpp. If conversions
- * here are a bottleneck, investigate whether we are converting when
- * storing window data *into* the texture before adding extra code
- * to handle multiple texture formats.
- */
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define TEXTURE_FORMAT COGL_PIXEL_FORMAT_BGRA_8888_PRE
-#else
-#define TEXTURE_FORMAT COGL_PIXEL_FORMAT_ARGB_8888_PRE
-#endif
-
-typedef struct
-{
-  guint16 x1;
-  guint16 y1;
-  guint16 x2;
-  guint16 y2;
-} Box;
-
-struct _MetaTextureTower
-{
-  int n_levels;
-  CoglTexture *textures[MAX_TEXTURE_LEVELS];
-  CoglOffscreen *fbos[MAX_TEXTURE_LEVELS];
-  Box invalid[MAX_TEXTURE_LEVELS];
-  CoglPipeline *pipeline_template;
-  CoglSnippet *snippet;
-};
-
-/**
- * meta_texture_tower_new:
- *
- * Creates a new texture tower. The base texture has to be set with
- * meta_texture_tower_set_base_texture() before use.
- *
- * Return value: the new texture tower. Free with meta_texture_tower_free()
- */
-MetaTextureTower *
-meta_texture_tower_new (void)
-{
-  MetaTextureTower *tower;
-
-  tower = g_new0 (MetaTextureTower, 1);
-
-  return tower;
-}
-
-/**
- * meta_texture_tower_free:
- * @tower: a #MetaTextureTower
- *
- * Frees a texture tower created with meta_texture_tower_new().
- */
-void
-meta_texture_tower_free (MetaTextureTower *tower)
-{
-  g_return_if_fail (tower != NULL);
-
-  if (tower->pipeline_template != NULL)
-    cogl_object_unref (tower->pipeline_template);
-
-  meta_texture_tower_set_base_texture (tower, NULL);
-  cogl_clear_object (&tower->snippet);
-
-  g_free (tower);
-}
-
-/**
- * meta_texture_tower_set_base_texture:
- * @tower: a #MetaTextureTower
- * @texture: the new texture used as a base for scaled down versions
- *
- * Sets the base texture that is the scaled texture that the
- * scaled textures of the tower are derived from. The texture itself
- * will be used as level 0 of the tower and will be referenced until
- * unset or until the tower is freed.
- */
-void
-meta_texture_tower_set_base_texture (MetaTextureTower *tower,
-                                     CoglTexture      *texture)
-{
-  int i;
-
-  g_return_if_fail (tower != NULL);
-
-  if (texture == tower->textures[0])
-    return;
-
-  if (tower->textures[0] != NULL)
-    {
-      for (i = 1; i < tower->n_levels; i++)
-        {
-          cogl_clear_object (&tower->textures[i]);
-          g_clear_object (&tower->fbos[i]);
-        }
-
-      cogl_object_unref (tower->textures[0]);
-    }
-
-  tower->textures[0] = texture;
-
-  if (tower->textures[0] != NULL)
-    {
-      int width, height;
-
-      cogl_object_ref (tower->textures[0]);
-
-      width = cogl_texture_get_width (tower->textures[0]);
-      height = cogl_texture_get_height (tower->textures[0]);
-
-      tower->n_levels = 1 + MAX ((int)(M_LOG2E * log (width)), (int)(M_LOG2E * log (height)));
-      tower->n_levels = MIN (tower->n_levels, MAX_TEXTURE_LEVELS);
-
-      meta_texture_tower_update_area (tower, 0, 0, width, height);
-    }
-  else
-    {
-      tower->n_levels = 0;
-    }
-}
-
-/**
- * meta_texture_tower_update_area:
- * @tower: a #MetaTextureTower
- * @x: X coordinate of upper left of rectangle that changed
- * @y: Y coordinate of upper left of rectangle that changed
- * @width: width of rectangle that changed
- * @height: height rectangle that changed
- *
- * Mark a region of the base texture as having changed; the next
- * time a scaled down version of the base texture is retrieved,
- * the appropriate area of the scaled down texture will be updated.
- */
-void
-meta_texture_tower_update_area (MetaTextureTower *tower,
-                                int               x,
-                                int               y,
-                                int               width,
-                                int               height)
-{
-  int texture_width, texture_height;
-  Box invalid;
-  int i;
-
-  g_return_if_fail (tower != NULL);
-
-  if (tower->textures[0] == NULL)
-    return;
-
-  texture_width = cogl_texture_get_width (tower->textures[0]);
-  texture_height = cogl_texture_get_height (tower->textures[0]);
-
-  invalid.x1 = x;
-  invalid.y1 = y;
-  invalid.x2 = x + width;
-  invalid.y2 = y + height;
-
-  for (i = 1; i < tower->n_levels; i++)
-    {
-      texture_width = MAX (1, texture_width / 2);
-      texture_height = MAX (1, texture_height / 2);
-
-      invalid.x1 = invalid.x1 / 2;
-      invalid.y1 = invalid.y1 / 2;
-      invalid.x2 = MIN (texture_width, (invalid.x2 + 1) / 2);
-      invalid.y2 = MIN (texture_height, (invalid.y2 + 1) / 2);
-
-      if (tower->invalid[i].x1 == tower->invalid[i].x2 ||
-          tower->invalid[i].y1 == tower->invalid[i].y2)
-        {
-          tower->invalid[i] = invalid;
-        }
-      else
-        {
-          tower->invalid[i].x1 = MIN (tower->invalid[i].x1, invalid.x1);
-          tower->invalid[i].y1 = MIN (tower->invalid[i].y1, invalid.y1);
-          tower->invalid[i].x2 = MAX (tower->invalid[i].x2, invalid.x2);
-          tower->invalid[i].y2 = MAX (tower->invalid[i].y2, invalid.y2);
-        }
-    }
-}
-
-void
-meta_texture_tower_set_snippet (MetaTextureTower *tower,
-                                CoglSnippet      *snippet)
-{
-  int i;
-
-  if (tower->snippet == snippet)
-    return;
-
-  g_clear_pointer (&tower->snippet, cogl_object_unref);
-
-  if (snippet)
-    tower->snippet = cogl_object_ref (snippet);
-
-  for (i = 1; i < tower->n_levels; i++)
-    {
-      cogl_clear_object (&tower->textures[i]);
-      g_clear_object (&tower->fbos[i]);
-    }
-  cogl_clear_object (&tower->pipeline_template);
-}
-
-/* It generally looks worse if we scale up a window texture by even a
- * small amount than if we scale it down using bilinear filtering, so
- * we always pick the *larger* adjacent level. */
-#define LOD_BIAS (-0.49)
-
-/* This determines the appropriate level of detail to use when drawing the
- * texture, in a way that corresponds to what the GL specification does
- * when mip-mapping. This is probably fancier and slower than what we need,
- * but we do the computation only once each time we paint a window, and
- * its easier to just use the equations from the specification than to
- * come up with something simpler.
- *
- * If window is being painted at an angle from the viewer, then we have to
- * pick a point in the texture; we use the middle of the texture (which is
- * why the width/height are passed in.) This is not the normal case for
- * Meta.
- */
-static int
-get_paint_level (ClutterPaintContext *paint_context,
-                 int                  width,
-                 int                  height)
-{
-  CoglFramebuffer *framebuffer;
-  graphene_matrix_t projection, modelview, pm;
-  float xx, xy, xw;
-  float yx, yy, yw;
-  float wx, wy, ww;
-  float v[4];
-  double viewport_width, viewport_height;
-  double u0, v0;
-  double xc, yc, wc;
-  double dxdu_, dxdv_, dydu_, dydv_;
-  double det_, det_sq;
-  double rho_sq;
-  double lambda;
-
-  /* See
-   * http://www.opengl.org/registry/doc/glspec32.core.20090803.pdf
-   * Section 3.8.9, p. 1.6.2. Here we have
-   *
-   *  u(x,y) = x_o;
-   *  v(x,y) = y_o;
-   *
-   * Since we are mapping 1:1 from object coordinates into pixel
-   * texture coordinates, the clip coordinates are:
-   *
-   *  (x_c)                               (x_o)        (u)
-   *  (y_c) = (M_projection)(M_modelview) (y_o) = (PM) (v)
-   *  (z_c)                               (z_o)        (0)
-   *  (w_c)                               (w_o)        (1)
-   */
-
-  framebuffer = clutter_paint_context_get_framebuffer (paint_context);
-  cogl_framebuffer_get_projection_matrix (framebuffer, &projection);
-  cogl_framebuffer_get_modelview_matrix (framebuffer, &modelview);
-
-  graphene_matrix_multiply (&modelview, &projection, &pm);
-
-  xx = graphene_matrix_get_value (&pm, 0, 0);
-  xy = graphene_matrix_get_value (&pm, 0, 1);
-  xw = graphene_matrix_get_value (&pm, 0, 3);
-  yx = graphene_matrix_get_value (&pm, 1, 0);
-  yy = graphene_matrix_get_value (&pm, 1, 1);
-  yw = graphene_matrix_get_value (&pm, 1, 3);
-  wx = graphene_matrix_get_value (&pm, 3, 0);
-  wy = graphene_matrix_get_value (&pm, 3, 1);
-  ww = graphene_matrix_get_value (&pm, 3, 3);
-
-  cogl_framebuffer_get_viewport4fv (framebuffer, v);
-  viewport_width = v[2];
-  viewport_height = v[3];
-
-  u0 = width / 2.;
-  v0 = height / 2.;
-
-  xc = xx * u0 + yx * v0 + wx;
-  yc = xy * u0 + yy * v0 + wy;
-  wc = xw * u0 + yw * v0 + ww;
-
-  /* We'll simplify the equations below for a bit of micro-optimization.
-   * The commented out code is the unsimplified version.
-
-  // Partial derivates of window coordinates:
-  //
-  //  x_w = 0.5 * viewport_width * x_c / w_c + viewport_center_x
-  //  y_w = 0.5 * viewport_height * y_c / w_c + viewport_center_y
-  //
-  // with respect to u, v, using
-  // d(a/b)/dx = da/dx * (1/b) - a * db/dx / (b^2)
-
-  dxdu = 0.5 * viewport_width * (xx - xw * (xc/wc)) / wc;
-  dxdv = 0.5 * viewport_width * (yx - yw * (xc/wc)) / wc;
-  dydu = 0.5 * viewport_height * (xy - xw * (yc/wc)) / wc;
-  dydv = 0.5 * viewport_height * (yy - yw * (yc/wc)) / wc;
-
-  // Compute the inverse partials as the matrix inverse
-  det = dxdu * dydv - dxdv * dydu;
-
-  dudx =   dydv / det;
-  dudy = - dxdv / det;
-  dvdx = - dydu / det;
-  dvdy =   dvdu / det;
-
-  // Scale factor; maximum of the distance in texels for a change of 1 pixel
-  // in the X direction or 1 pixel in the Y direction
-  rho = MAX (sqrt (dudx * dudx + dvdx * dvdx), sqrt(dudy * dudy + dvdy * dvdy));
-
-  // Level of detail
-  lambda = log2 (rho) + LOD_BIAS;
-  */
-
-  /* dxdu * wc, etc */
-  dxdu_ = 0.5 * viewport_width * (xx - xw * (xc/wc));
-  dxdv_ = 0.5 * viewport_width * (yx - yw * (xc/wc));
-  dydu_ = 0.5 * viewport_height * (xy - xw * (yc/wc));
-  dydv_ = 0.5 * viewport_height * (yy - yw * (yc/wc));
-
-  /* det * wc^2 */
-  det_ = dxdu_ * dydv_ - dxdv_ * dydu_;
-  det_sq = det_ * det_;
-  if (det_sq == 0.0)
-    return -1;
-
-  /* (rho * det * wc)^2 */
-  rho_sq = MAX (dydv_ * dydv_ + dydu_ * dydu_, dxdv_ * dxdv_ + dxdu_ * dxdu_);
-  lambda = 0.5 * M_LOG2E * log (rho_sq * wc * wc / det_sq) + LOD_BIAS;
-
-#if 0
-  g_print ("%g %g %g\n", 0.5 * viewport_width * xx / ww, 0.5 * viewport_height * yy / ww, lambda);
-#endif
-
-  if (lambda <= 0.)
-    return 0;
-  else
-    return (int)(0.5 + lambda);
-}
-
-static void
-texture_tower_create_texture (MetaTextureTower *tower,
-                              int               level,
-                              int               width,
-                              int               height)
-{
-  CoglContext *ctx =
-    clutter_backend_get_cogl_context (clutter_get_default_backend ());
-
-  tower->textures[level] =
-    COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
-
-  tower->invalid[level].x1 = 0;
-  tower->invalid[level].y1 = 0;
-  tower->invalid[level].x2 = width;
-  tower->invalid[level].y2 = height;
-}
-
-static void
-texture_tower_revalidate (MetaTextureTower *tower,
-                          int               level)
-{
-  CoglTexture *source_texture = tower->textures[level - 1];
-  int source_texture_width = cogl_texture_get_width (source_texture);
-  int source_texture_height = cogl_texture_get_height (source_texture);
-  CoglTexture *dest_texture = tower->textures[level];
-  int dest_texture_width = cogl_texture_get_width (dest_texture);
-  int dest_texture_height = cogl_texture_get_height (dest_texture);
-  Box *invalid = &tower->invalid[level];
-  CoglFramebuffer *fb;
-  GError *catch_error = NULL;
-  CoglPipeline *pipeline;
-
-  if (tower->fbos[level] == NULL)
-    tower->fbos[level] = cogl_offscreen_new_with_texture (dest_texture);
-
-  fb = COGL_FRAMEBUFFER (tower->fbos[level]);
-
-  if (!cogl_framebuffer_allocate (fb, &catch_error))
-    {
-      g_error_free (catch_error);
-      return;
-    }
-
-  cogl_framebuffer_orthographic (fb, 0, 0, dest_texture_width, dest_texture_height, -1., 1.);
-
-  if (!tower->pipeline_template)
-    {
-      CoglContext *ctx =
-        clutter_backend_get_cogl_context (clutter_get_default_backend ());
-      tower->pipeline_template = cogl_pipeline_new (ctx);
-      cogl_pipeline_set_blend (tower->pipeline_template, "RGBA = ADD (SRC_COLOR, 0)", NULL);
-    }
-
-  pipeline = cogl_pipeline_copy (tower->pipeline_template);
-  cogl_pipeline_set_layer_texture (pipeline, 0, tower->textures[level - 1]);
-
-  if (tower->snippet && level == 1)
-    cogl_pipeline_add_layer_snippet (pipeline, 0, tower->snippet);
-
-  cogl_framebuffer_draw_textured_rectangle (fb, pipeline,
-                                            invalid->x1, invalid->y1,
-                                            invalid->x2, invalid->y2,
-                                            (2. * invalid->x1) / source_texture_width,
-                                            (2. * invalid->y1) / source_texture_height,
-                                            (2. * invalid->x2) / source_texture_width,
-                                            (2. * invalid->y2) / source_texture_height);
-
-  cogl_object_unref (pipeline);
-
-  tower->invalid[level].x1 = tower->invalid[level].x2 = 0;
-  tower->invalid[level].y1 = tower->invalid[level].y2 = 0;
-}
-
-/**
- * meta_texture_tower_get_paint_texture:
- * @tower: a #MetaTextureTower
- * @paint_context: a #ClutterPaintContext
- *
- * Gets the texture from the tower that best matches the current
- * rendering scale. (On the assumption here the texture is going to
- * be rendered with vertex coordinates that correspond to its
- * size in pixels, so a 200x200 texture will be rendered on the
- * rectangle (0, 0, 200, 200).
- *
- * Return value: the COGL texture handle to use for painting, or
- *  %NULL if no base texture has yet been set.
- */
-CoglTexture *
-meta_texture_tower_get_paint_texture (MetaTextureTower    *tower,
-                                      ClutterPaintContext *paint_context)
-{
-  int texture_width, texture_height;
-  int level;
-
-  g_return_val_if_fail (tower != NULL, NULL);
-
-  if (tower->textures[0] == NULL)
-    return NULL;
-
-  texture_width = cogl_texture_get_width (tower->textures[0]);
-  texture_height = cogl_texture_get_height (tower->textures[0]);
-
-  level = get_paint_level (paint_context, texture_width, texture_height);
-  if (level < 0) /* singular paint matrix, scaled to nothing */
-    return NULL;
-  level = MIN (level, tower->n_levels - 1);
-
-  if (tower->textures[level] == NULL ||
-      (tower->invalid[level].x2 != tower->invalid[level].x1 &&
-       tower->invalid[level].y2 != tower->invalid[level].y1))
-    {
-      int i;
-
-      for (i = 1; i <= level; i++)
-        {
-          /* Use "floor" convention here to be consistent with the NPOT texture extension */
-          texture_width = MAX (1, texture_width / 2);
-          texture_height = MAX (1, texture_height / 2);
-
-          if (tower->textures[i] == NULL)
-            texture_tower_create_texture (tower, i, texture_width, texture_height);
-        }
-
-      for (i = 1; i <= level; i++)
-        {
-          if (tower->invalid[level].x2 != tower->invalid[level].x1 &&
-              tower->invalid[level].y2 != tower->invalid[level].y1)
-            texture_tower_revalidate (tower, i);
-        }
-    }
-
-  return tower->textures[level];
-}
diff --git a/src/compositor/meta-texture-tower.h b/src/compositor/meta-texture-tower.h
deleted file mode 100644
index 5522dfbb16ac9b207e979065413ac3c06f1ac974..0000000000000000000000000000000000000000
--- a/src/compositor/meta-texture-tower.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * MetaTextureTower
- *
- * 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
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __META_TEXTURE_TOWER_H__
-#define __META_TEXTURE_TOWER_H__
-
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-/**
- * SECTION:MetaTextureTower
- * @short_description: mipmap emulation by creation of scaled down images
- *
- * A #MetaTextureTower 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 _MetaTextureTower MetaTextureTower;
-
-MetaTextureTower *meta_texture_tower_new               (void);
-void              meta_texture_tower_free              (MetaTextureTower *tower);
-void              meta_texture_tower_set_base_texture  (MetaTextureTower *tower,
-                                                        CoglTexture      *texture);
-void              meta_texture_tower_update_area       (MetaTextureTower *tower,
-                                                        int               x,
-                                                        int               y,
-                                                        int               width,
-                                                        int               height);
-CoglTexture      *meta_texture_tower_get_paint_texture (MetaTextureTower    *tower,
-                                                        ClutterPaintContext *paint_context);
-
-void meta_texture_tower_set_snippet (MetaTextureTower *tower,
-                                     CoglSnippet      *snippet);
-
-G_END_DECLS
-
-#endif /* __META_TEXTURE_TOWER_H__ */
diff --git a/src/compositor/meta-window-group.c b/src/compositor/meta-window-group.c
index 16ff2db097e17210d319d1dadcf00a6a55ef3cc1..c6af609aea50f38b444f8e0436fa1008322fadce 100644
--- a/src/compositor/meta-window-group.c
+++ b/src/compositor/meta-window-group.c
@@ -92,6 +92,7 @@ meta_window_group_paint (ClutterActor        *actor,
     {
       CoglFramebuffer *fb;
       ClutterStageView *view;
+      MetaTransforms trans;
 
       fb = clutter_paint_context_get_framebuffer (paint_context);
       view = clutter_paint_context_get_stage_view (paint_context);
@@ -102,13 +103,15 @@ meta_window_group_paint (ClutterActor        *actor,
                                               screen_height,
                                               screen_width,
                                               screen_height,
-                                              &paint_x_origin,
-                                              &paint_y_origin) ||
+                                              &trans) ||
           !meta_cullable_is_untransformed (META_CULLABLE (actor)))
         {
           parent_actor_class->paint (actor, paint_context);
           return;
         }
+
+      paint_x_origin = trans.x_origin;
+      paint_y_origin = trans.y_origin;
     }
   else
     {
diff --git a/src/meson.build b/src/meson.build
index 13a69c1a6..4e61307d6 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -344,8 +344,8 @@ mutter_sources = [
   'compositor/meta-surface-actor-x11.h',
   'compositor/meta-sync-ring.c',
   'compositor/meta-sync-ring.h',
-  'compositor/meta-texture-tower.c',
-  'compositor/meta-texture-tower.h',
+  'compositor/meta-texture-mipmap.c',
+  'compositor/meta-texture-mipmap.h',
   'compositor/meta-window-actor.c',
   'compositor/meta-window-actor-private.h',
   'compositor/meta-window-actor-x11.c',