@@ -247,43 +247,17 @@ void container_linux::draw_list_marker( litehtml::uint_ptr hdc, const litehtml::
247
247
}
248
248
}
249
249
250
- void container_linux::load_image ( const char * src, const char * baseurl, bool /* redraw_on_ready*/ )
251
- {
252
- litehtml::string url;
253
- make_url (src, baseurl, url);
254
- if (m_images.find (url) == m_images.end ())
255
- {
256
- try
257
- {
258
- Glib::RefPtr<Gdk::Pixbuf> img = get_image (url.c_str (), true );
259
- if (img)
260
- {
261
- m_images[url.c_str ()] = img;
262
- }
263
- } catch (...)
264
- {
265
- m_images[url.c_str ()] = Glib::RefPtr<Gdk::Pixbuf>(nullptr );
266
- }
267
- }
268
- }
269
-
270
250
void container_linux::get_image_size ( const char * src, const char * baseurl, litehtml::size& sz )
271
251
{
272
252
litehtml::string url;
273
253
make_url (src, baseurl, url);
274
254
275
- auto img = m_images.find (url);
276
- if (img != m_images.end ())
277
- {
278
- if (img->second )
279
- {
280
- sz.width = img->second ->get_width ();
281
- sz.height = img->second ->get_height ();
282
- } else
283
- {
284
- sz.width = 0 ;
285
- sz.height = 0 ;
286
- }
255
+ auto img = get_image (url);
256
+ if (img)
257
+ {
258
+ sz.width = cairo_image_surface_get_width (img);
259
+ sz.height = cairo_image_surface_get_height (img);
260
+ cairo_surface_destroy (img);
287
261
} else
288
262
{
289
263
sz.width = 0 ;
@@ -323,21 +297,17 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const std::vector
323
297
std::string url;
324
298
make_url (bg.image .c_str (), bg.baseurl .c_str (), url);
325
299
326
- // lock_images_cache();
327
- auto img_i = m_images.find (url);
328
- if (img_i != m_images.end () && img_i->second )
300
+ auto bgbmp = get_image (url);
301
+ if (bgbmp)
329
302
{
330
- Glib::RefPtr<Gdk::Pixbuf> bgbmp = img_i->second ;
331
-
332
- Glib::RefPtr<Gdk::Pixbuf> new_img;
333
- if (bg.image_size .width != bgbmp->get_width () || bg.image_size .height != bgbmp->get_height ())
303
+ if (bg.image_size .width != cairo_image_surface_get_width (bgbmp) || bg.image_size .height != cairo_image_surface_get_height (bgbmp))
334
304
{
335
- new_img = bgbmp->scale_simple (bg.image_size .width , bg.image_size .height , Gdk::INTERP_BILINEAR);
305
+ auto new_img = scale_surface (bgbmp, bg.image_size .width , bg.image_size .height );
306
+ cairo_surface_destroy (bgbmp);
336
307
bgbmp = new_img;
337
308
}
338
309
339
- cairo_surface_t * img = surface_from_pixbuf (bgbmp);
340
- cairo_pattern_t *pattern = cairo_pattern_create_for_surface (img);
310
+ cairo_pattern_t *pattern = cairo_pattern_create_for_surface (bgbmp);
341
311
cairo_matrix_t flib_m;
342
312
cairo_matrix_init_identity (&flib_m);
343
313
cairo_matrix_translate (&flib_m, -bg.position_x , -bg.position_y );
@@ -347,18 +317,18 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const std::vector
347
317
switch (bg.repeat )
348
318
{
349
319
case litehtml::background_repeat_no_repeat:
350
- draw_pixbuf (cr, bgbmp, bg.position_x , bg.position_y , bgbmp-> get_width ( ), bgbmp-> get_height ( ));
320
+ draw_pixbuf (cr, bgbmp, bg.position_x , bg.position_y , cairo_image_surface_get_width (bgbmp ), cairo_image_surface_get_height (bgbmp ));
351
321
break ;
352
322
353
323
case litehtml::background_repeat_repeat_x:
354
324
cairo_set_source (cr, pattern);
355
- cairo_rectangle (cr, bg.clip_box .left (), bg.position_y , bg.clip_box .width , bgbmp-> get_height ( ));
325
+ cairo_rectangle (cr, bg.clip_box .left (), bg.position_y , bg.clip_box .width , cairo_image_surface_get_height (bgbmp ));
356
326
cairo_fill (cr);
357
327
break ;
358
328
359
329
case litehtml::background_repeat_repeat_y:
360
330
cairo_set_source (cr, pattern);
361
- cairo_rectangle (cr, bg.position_x , bg.clip_box .top (), bgbmp-> get_width ( ), bg.clip_box .height );
331
+ cairo_rectangle (cr, bg.position_x , bg.clip_box .top (), cairo_image_surface_get_width (bgbmp ), bg.clip_box .height );
362
332
cairo_fill (cr);
363
333
break ;
364
334
@@ -370,9 +340,8 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const std::vector
370
340
}
371
341
372
342
cairo_pattern_destroy (pattern);
373
- cairo_surface_destroy (img );
343
+ cairo_surface_destroy (bgbmp );
374
344
}
375
- // unlock_images_cache();
376
345
}
377
346
378
347
cairo_restore (cr);
@@ -681,25 +650,38 @@ void container_linux::rounded_rectangle( cairo_t* cr, const litehtml::position &
681
650
}
682
651
}
683
652
684
- void container_linux::draw_pixbuf (cairo_t * cr, const Glib::RefPtr<Gdk::Pixbuf>& bmp, int x, int y, int cx, int cy)
653
+ cairo_surface_t * container_linux::scale_surface (cairo_surface_t * surface, int width, int height)
654
+ {
655
+ int s_width = cairo_image_surface_get_width (surface);
656
+ int s_height = cairo_image_surface_get_height (surface);
657
+ cairo_surface_t *result = cairo_surface_create_similar (surface, cairo_surface_get_content (surface), width, height);
658
+ cairo_t *cr = cairo_create (result);
659
+ cairo_scale (cr, (double ) width / (double ) s_width, (double ) height / (double ) s_height);
660
+ cairo_set_source_surface (cr, surface, 0 , 0 );
661
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
662
+ cairo_paint (cr);
663
+ cairo_destroy (cr);
664
+ return result;
665
+ }
666
+
667
+ void container_linux::draw_pixbuf (cairo_t * cr, cairo_surface_t * bmp, int x, int y, int cx, int cy)
685
668
{
686
669
cairo_save (cr);
687
670
688
671
{
689
- Cairo::RefPtr<Cairo::Context> crobj (new Cairo::Context (cr, false ));
690
-
691
- cairo_matrix_t flib_m;
692
- cairo_matrix_init (&flib_m, 1 , 0 , 0 , -1 , 0 , 0 );
672
+ cairo_matrix_t flip_m;
673
+ cairo_matrix_init (&flip_m, 1 , 0 , 0 , -1 , 0 , 0 );
693
674
694
- if (cx != bmp-> get_width ( ) || cy != bmp-> get_height ( ))
675
+ if (cx != cairo_image_surface_get_width (bmp ) || cy != cairo_image_surface_get_height (bmp ))
695
676
{
696
- Glib::RefPtr<Gdk::Pixbuf> new_img = bmp->scale_simple (cx, cy, Gdk::INTERP_BILINEAR);
697
- Gdk::Cairo::set_source_pixbuf (crobj, new_img, x, y);
698
- crobj->paint ();
677
+ auto bmp_scaled = scale_surface (bmp, cx, cy);
678
+ cairo_set_source_surface (cr, bmp_scaled, x, y);
679
+ cairo_paint (cr);
680
+ cairo_surface_destroy (bmp_scaled);
699
681
} else
700
682
{
701
- Gdk::Cairo::set_source_pixbuf (crobj , bmp, x, y);
702
- crobj-> paint ( );
683
+ cairo_set_source_surface (cr , bmp, x, y);
684
+ cairo_paint (cr );
703
685
}
704
686
}
705
687
0 commit comments