aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathias <mathias>2005-01-02 06:27:45 (GMT)
committermathias <mathias>2005-01-02 06:27:45 (GMT)
commit0134038feec6609bfbbe1371e1a65e131ccab502 (patch)
tree72ce1583508f927019c5b6893b777c309d3301a2 /src
parentc7a3200730b3e2948cab3fdb43a786cb1b2f60f1 (diff)
downloadfluxbox_pavel-0134038feec6609bfbbe1371e1a65e131ccab502.zip
fluxbox_pavel-0134038feec6609bfbbe1371e1a65e131ccab502.tar.bz2
fix problems with imlib2 on restart:
only when using "imlib_load_image_with_error_return" as the loading function imlib2 seems to avoid trouble when an image with <filename> doesnt exist. all other loadroutines lead to heavy problems when fluxbox shuts down and tries to restart (memleak(?), distorted xressources etc) i ll analyze this further. another open issue with imlib2 is that it doesnt work when xserver/fluxbox is running in dualscreen-mode (not xinerama), no valid pixmaps are visible on the second head. dunno why (yet).
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/ImageImlib2.cc61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/FbTk/ImageImlib2.cc b/src/FbTk/ImageImlib2.cc
index 82079a3..8a610e9 100644
--- a/src/FbTk/ImageImlib2.cc
+++ b/src/FbTk/ImageImlib2.cc
@@ -30,6 +30,7 @@
30 30
31#include <Imlib2.h> 31#include <Imlib2.h>
32#include <map> 32#include <map>
33#include <iostream>
33 34
34namespace { 35namespace {
35 36
@@ -51,7 +52,7 @@ ImageImlib2::ImageImlib2() {
51 52
52 // TODO: this are the potential candidates, 53 // TODO: this are the potential candidates,
53 // choose only sane ones. open for discussion 54 // choose only sane ones. open for discussion
54 char* format_list[] = { 55 static char* format_list[] = {
55 "PNG", // pngloader 56 "PNG", // pngloader
56 "JPEG", "JPG", "JFI", "JFIF", // jpegloader 57 "JPEG", "JPG", "JFI", "JFIF", // jpegloader
57// "TIFF", "TIF", // tiffloader 58// "TIFF", "TIF", // tiffloader
@@ -73,6 +74,7 @@ ImageImlib2::ImageImlib2() {
73} 74}
74 75
75ImageImlib2::~ImageImlib2() { 76ImageImlib2::~ImageImlib2() {
77
76 ScreenImlibContext it = contexts.begin(); 78 ScreenImlibContext it = contexts.begin();
77 ScreenImlibContext it_end = contexts.end(); 79 ScreenImlibContext it_end = contexts.end();
78 for (; it != it_end; it++) { 80 for (; it != it_end; it++) {
@@ -91,56 +93,73 @@ PixmapWithMask *ImageImlib2::load(const std::string &filename, int screen_num) c
91 93
92 Imlib_Context new_context = imlib_context_new(); 94 Imlib_Context new_context = imlib_context_new();
93 imlib_context_push(new_context); 95 imlib_context_push(new_context);
94 96
95 imlib_context_set_display(dpy); 97 imlib_context_set_display(dpy);
96 imlib_context_set_drawable(RootWindow(dpy, screen_num));
97 imlib_context_set_colormap(DefaultColormap(dpy, screen_num));
98 imlib_context_set_visual(DefaultVisual(dpy, screen_num)); 98 imlib_context_set_visual(DefaultVisual(dpy, screen_num));
99 imlib_context_set_colormap(DefaultColormap(dpy, screen_num));
100 imlib_context_set_drawable(RootWindow(dpy, screen_num));
99 101
100 imlib_context_pop(); 102 imlib_context_pop();
101 103
102 contexts[screen_num] = new_context; 104 contexts[screen_num] = new_context;
103 screen_context = contexts.find(screen_num); 105 screen_context = contexts.find(screen_num);
104 } 106 }
107
105 108
106 if (screen_context == contexts.end()) { 109 if (screen_context == contexts.end()) {
107#ifdef DEBUG 110#ifdef DEBUG
108 cerr << "ImageImlib2::load: error, couldnt find a valid Imlib_Context.\n"; 111 std::cerr << "ImageImlib2::load: error, couldnt find a valid Imlib_Context.\n";
109#endif // DEBUG 112#endif // DEBUG
110 return 0; 113 return 0;
111 } 114 }
112 115
113 // now load the stuff 116 // now load the stuff
114 Imlib_Context context = screen_context->second; 117 Imlib_Context context = screen_context->second;
115 imlib_context_push(context); 118 imlib_context_push(context);
116 Imlib_Image image = imlib_load_image_immediately(filename.c_str()); 119
120 Imlib_Image image = 0;
121 Imlib_Load_Error err;
122
123 // TODO: contact imlib2-authors:
124 //
125 // we use this error-loading + get_data_for_reading_only because
126 // it doesnt memleak imlib2,
127 //
128 // imlib_load_image_immediately
129 // imlib_load_image_without_cache
130 // imlib_load_image_immediately_without_cache
131 //
132 // seem to memleak or trouble imlib2 when something fails. the
133 // imlib_load_image_with_error_return checks for existence etc before
134 // actually doing anything, i ll analyze this further (mathias)
135 image = imlib_load_image_with_error_return(filename.c_str(), &err);
117 if (image) { // loading was ok 136 if (image) { // loading was ok
137
118 imlib_context_set_image(image); 138 imlib_context_set_image(image);
119
120 Pixmap pm = 0, mask = 0; 139 Pixmap pm = 0, mask = 0;
140
141 // force loading/creation of the image
142 imlib_image_get_data_for_reading_only();
143
144 // and render it to the pixmaps
121 imlib_render_pixmaps_for_whole_image(&pm, &mask); 145 imlib_render_pixmaps_for_whole_image(&pm, &mask);
122 146
123 // pm and mask belong to imlib, so we have to copy them 147 // pm and mask belong to imlib2,
124 FbPixmap fbpm; 148 // so we have to copy them
125 FbPixmap fbmask; 149 PixmapWithMask* result = new PixmapWithMask();
126 150 result->pixmap().copy(pm);
127 fbpm.copy(pm); 151 result->mask().copy(mask);
128 fbmask.copy(mask);
129 152
130 // mark pm and mask as freeable in imlib 153 // mark pm and mask as freeable in imlib
131 imlib_free_image(); 154 imlib_free_image_and_decache();
132 imlib_free_pixmap_and_mask(pm); 155 imlib_free_pixmap_and_mask(pm);
133 156
134 imlib_context_pop(); 157 imlib_context_pop();
135 158
136 PixmapWithMask* result = new PixmapWithMask();
137 result->pixmap() = fbpm;
138 result->mask() = fbmask;
139 return result; 159 return result;
140 } 160 } else // loading failure
161 imlib_context_pop();
141 162
142 // loading failure
143 imlib_context_pop();
144 return 0; 163 return 0;
145} 164}
146 165