Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c60f5c

Browse filesBrowse files
committed
updated for new cairo_container
1 parent 16dd041 commit 3c60f5c
Copy full SHA for 3c60f5c

File tree

Expand file treeCollapse file tree

3 files changed

+69
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+69
-8
lines changed

‎litehtml

Copy file name to clipboard

‎src/web_page.cpp

Copy file name to clipboardExpand all lines: src/web_page.cpp
+25-5Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ void litebrowser::web_page::set_base_url(const char* base_url)
9292
}
9393
}
9494

95-
Glib::RefPtr<Gdk::Pixbuf> litebrowser::web_page::get_image(const std::string& url)
95+
cairo_surface_t* litebrowser::web_page::get_image(const std::string& url)
9696
{
9797
std::unique_lock<std::mutex> lock(m_images_sync);
9898
auto img = m_images.find(url);
9999
if(img != m_images.end())
100100
{
101-
return img->second;
101+
return img->second.get();
102102
}
103-
return Glib::RefPtr<Gdk::Pixbuf>(nullptr);
103+
return nullptr;
104104
}
105105

106106
void litebrowser::web_page::show_hash(const litehtml::string& hash)
@@ -258,7 +258,7 @@ void litebrowser::web_page::on_image_downloaded(std::shared_ptr<image_file> data
258258
{
259259
{
260260
std::unique_lock<std::mutex> lock(m_images_sync);
261-
m_images[data->url()] = ptr;
261+
m_images[data->url()] = surface_from_pixbuf(ptr);
262262
}
263263
if(data->redraw_only())
264264
{
@@ -285,7 +285,7 @@ void litebrowser::web_page::load_image(const char *src, const char *baseurl, boo
285285
return;
286286
} else
287287
{
288-
m_images[url] = Glib::RefPtr<Gdk::Pixbuf>(nullptr);
288+
m_images[url] = cairo_surface_wrapper();
289289
}
290290
}
291291

@@ -295,6 +295,26 @@ void litebrowser::web_page::load_image(const char *src, const char *baseurl, boo
295295
http_request(url, cb_on_data, cb_on_finish);
296296
}
297297

298+
litebrowser::cairo_surface_wrapper litebrowser::web_page::surface_from_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& bmp)
299+
{
300+
cairo_surface_t* ret;
301+
302+
if(bmp->get_has_alpha())
303+
{
304+
ret = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bmp->get_width(), bmp->get_height());
305+
} else
306+
{
307+
ret = cairo_image_surface_create(CAIRO_FORMAT_RGB24, bmp->get_width(), bmp->get_height());
308+
}
309+
310+
Cairo::RefPtr<Cairo::Surface> surface(new Cairo::Surface(ret, false));
311+
Cairo::RefPtr<Cairo::Context> ctx = Cairo::Context::create(surface);
312+
Gdk::Cairo::set_source_pixbuf(ctx, bmp, 0.0, 0.0);
313+
ctx->paint();
314+
315+
return cairo_surface_wrapper(ret);
316+
}
317+
298318
void litebrowser::web_page::http_request(const std::string &url,
299319
const std::function<void(void *, size_t, size_t, size_t)> &cb_on_data,
300320
const std::function<void(u_int32_t, u_int32_t, const std::string &, const std::string &)> &cb_on_finish)

‎src/web_page.h

Copy file name to clipboardExpand all lines: src/web_page.h
+43-2Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,46 @@ namespace litebrowser
5050
bool redraw_only() const { return m_redraw_on_ready; }
5151
};
5252

53+
class cairo_surface_wrapper
54+
{
55+
cairo_surface_t* surface;
56+
public:
57+
cairo_surface_wrapper() : surface(nullptr) {}
58+
cairo_surface_wrapper(cairo_surface_wrapper& v) : surface(v.surface)
59+
{
60+
if(v.surface)
61+
{
62+
surface = cairo_surface_reference(v.surface);
63+
}
64+
}
65+
explicit cairo_surface_wrapper(cairo_surface_t* v) : surface(v) {}
66+
cairo_surface_wrapper(cairo_surface_wrapper&& v) noexcept
67+
{
68+
surface = v.surface;
69+
v.surface = nullptr;
70+
}
71+
cairo_surface_wrapper& operator=(const cairo_surface_wrapper& v)
72+
{
73+
if(surface != v.surface)
74+
{
75+
if(surface)
76+
{
77+
cairo_surface_destroy(surface);
78+
}
79+
surface = cairo_surface_reference(v.surface);
80+
}
81+
return *this;
82+
}
83+
~cairo_surface_wrapper()
84+
{
85+
if(surface)
86+
{
87+
cairo_surface_destroy(surface);
88+
}
89+
}
90+
cairo_surface_t* get() { return cairo_surface_reference(surface); }
91+
};
92+
5393
class web_page : public container_linux,
5494
public std::enable_shared_from_this<web_page>
5595
{
@@ -62,7 +102,7 @@ namespace litebrowser
62102
std::string m_hash;
63103
html_host_interface* m_html_host;
64104
std::mutex m_images_sync;
65-
std::map<litehtml::string, Glib::RefPtr<Gdk::Pixbuf>> m_images;
105+
std::map<litehtml::string, cairo_surface_wrapper> m_images;
66106
litebrowser::http_requests_pool m_requests_pool;
67107

68108
public:
@@ -79,9 +119,10 @@ namespace litebrowser
79119
void import_css(litehtml::string& text, const litehtml::string& url, litehtml::string& baseurl) override;
80120
void set_caption(const char* caption) override;
81121
void set_base_url(const char* base_url) override;
82-
Glib::RefPtr<Gdk::Pixbuf> get_image(const std::string& url) override;
122+
cairo_surface_t* get_image(const std::string& url) override;
83123
void make_url( const char* url, const char* basepath, litehtml::string& out ) override;
84124
void load_image(const char* src, const char* baseurl, bool redraw_on_ready) override;
125+
static cairo_surface_wrapper surface_from_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& bmp);
85126

86127
void show_hash(const litehtml::string& hash);
87128
void show_hash_and_reset()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.