Performance improvements

This commit is contained in:
cnjinhao 2015-01-09 08:12:20 +08:00
parent 750c3dffd5
commit 9a71f23ddd
16 changed files with 46 additions and 56 deletions

View File

@ -123,7 +123,7 @@ namespace nana
void _m_bground_pre();
void _m_bground_end();
void _m_draw_dynamic_drawing_object();
void _m_use_refresh();
bool _m_lazy_decleared() const;
template<typename Arg, typename Mfptr>
void _m_emit(event_code evt_code, const Arg& arg, Mfptr mfptr)
@ -144,12 +144,14 @@ namespace nana
else
(realizer_->*mfptr)(graphics, arg);
_m_use_refresh();
if (_m_lazy_decleared())
{
_m_draw_dynamic_drawing_object();
_m_bground_end();
}
}
}
}
public:
nana::paint::graphics graphics;
private:

View File

@ -124,7 +124,7 @@ namespace nana{
root_misc(core_window_t * wd, unsigned width, unsigned height)
: window(wd),
root_graph(width, height)
root_graph({ width, height })
{}
};//end struct root_misc

View File

@ -74,7 +74,6 @@ namespace nana
typedef ::nana::native_window_type native_window_type;
graphics();
graphics(unsigned width, unsigned height); ///< size in pixel
graphics(const ::nana::size&); ///< size in pixel
graphics(const graphics&); ///< the resource is not copyed, the two graphics objects refer to the *SAME* resource
graphics& operator=(const graphics&);
@ -85,8 +84,9 @@ namespace nana
drawable_type handle() const;
const void* pixmap() const;
const void* context() const;
void make(unsigned width, unsigned height); ///< Creates a bitmap resource that size is width by height in pixel
void resize(unsigned width, unsigned height);
void make(const ::nana::size&); ///< Creates a bitmap resource that size is width by height in pixel
void resize(const ::nana::size&);
void typeface(const font&); ///< Selects a specified font type into the graphics object.
font typeface() const;
::nana::size text_extent_size(const char_t*) const; ///< Computes the width and height of the specified string of text.

View File

@ -378,11 +378,9 @@ namespace nana
dw->draw(graphics);
}
//If the drawer_trigger didn't declear a lazy refresh, then use the refresh().
void drawer::_m_use_refresh()
bool drawer::_m_lazy_decleared() const
{
if (basic_window::update_state::refresh != core_window_->other.upd_state)
refresh();
return (basic_window::update_state::refresh != core_window_->other.upd_state);
}
}//end namespace detail
}//end namespace nana

View File

@ -183,7 +183,7 @@ namespace nana
//Enable the effect.
data_sect.effects_bground_windows.push_back(wd);
wd->other.glass_buffer.make(wd->dimension.width, wd->dimension.height);
wd->other.glass_buffer.make(wd->dimension);
make_bground(wd);
return true;
}

View File

@ -546,8 +546,8 @@ namespace detail
{
wd->dimension.width = r.width;
wd->dimension.height = r.height;
wd->drawer.graphics.make(r.width, r.height);
wd->root_graph->make(r.width, r.height);
wd->drawer.graphics.make(wd->dimension);
wd->root_graph->make(wd->dimension);
native_interface::move_window(wd->root, r);
arg_resized arg;
@ -612,7 +612,7 @@ namespace detail
if(category::lite_widget_tag::value != wd->other.category)
{
bool graph_state = wd->drawer.graphics.empty();
wd->drawer.graphics.make(sz.width, sz.height);
wd->drawer.graphics.make(sz);
//It shall make a typeface_changed() call when the graphics state is changing.
//Because when a widget is created with zero-size, it may get some wrong result in typeface_changed() call
@ -622,7 +622,7 @@ namespace detail
if(category::root_tag::value == wd->other.category)
{
wd->root_graph->make(sz.width, sz.height);
wd->root_graph->make(sz);
if(false == passive)
native_interface::window_size(wd->root, sz + nana::size(wd->extra_width, wd->extra_height));
}
@ -637,7 +637,7 @@ namespace detail
//update the bground buffer of glass window.
if(wd->effect.bground && wd->parent)
{
wd->other.glass_buffer.make(sz.width, sz.height);
wd->other.glass_buffer.make(sz);
wndlayout_type::make_bground(wd);
}
}
@ -767,7 +767,7 @@ namespace detail
if (!impl_->wd_register.available(wd))
return false;
result.make(wd->drawer.graphics.width(), wd->drawer.graphics.height());
result.make(wd->drawer.graphics.size());
result.bitblt(0, 0, wd->drawer.graphics);
wndlayout_type::paste_children_to_graphics(wd, result);
return true;

View File

@ -547,7 +547,7 @@ namespace nana
draw_method * clone() const override
{
auto p = new draw_graph;
p->graph.make(graph.width(), graph.height());
p->graph.make(graph.size());
graph.paste(p->graph, 0, 0);
return p;
}

View File

@ -172,7 +172,7 @@ namespace API
internal_scope_guard isg;
if(restrict::window_manager.available(iwd))
{
iwd->drawer.graphics.make(iwd->dimension.width, iwd->dimension.height);
iwd->drawer.graphics.make(iwd->dimension);
iwd->drawer.graphics.rectangle(true, iwd->expr_colors->background.get_color());
iwd->drawer.attached(wd, dr);
iwd->drawer.refresh(); //Always redrawe no matter it is visible or invisible. This can make the graphics data correctly.

View File

@ -102,7 +102,7 @@ namespace nana
{
nana::point refpos(1, static_cast<int>(topbar_height) + 1);
nana::paint::graphics gbuf(width, graph.height() - 2 - topbar_height);
nana::paint::graphics gbuf({ width, graph.height() - 2 - topbar_height });
gbuf.rectangle(true, {0xf0, 0xf0, 0xf0});
switch(page_)
@ -599,12 +599,12 @@ namespace nana
nana::point refpos(1, static_cast<int>(topbar_height) + 1);
nana::rectangle r(0, 0, graph.width() - 2, graph.height() - 2 - topbar_height);
nana::paint::graphics dirtybuf(r.width, r.height);
nana::paint::graphics dirtybuf({ r.width, r.height });
dirtybuf.bitblt(r, graph, refpos);
_m_draw(graph);
nana::paint::graphics gbuf(r.width, r.height);
nana::paint::graphics gbuf({ r.width, r.height });
gbuf.bitblt(r, graph, refpos);
_m_perf_transform(tfid, graph, dirtybuf, gbuf, refpos);

View File

@ -831,7 +831,7 @@ namespace nana
if(graph_ptr->empty())
{
graph_ptr = &substitute;
graph_ptr->make(10, 10);
graph_ptr->make({ 10, 10 });
}
return impl->renderer.measure(*graph_ptr, limited, impl->text_align, impl->text_align_v);

View File

@ -2317,7 +2317,7 @@ namespace nana
{
const auto & item = essence_->header.column(essence_->pointer_where.second);
nana::paint::graphics ext_graph(item.pixels, essence_->header_size);
nana::paint::graphics ext_graph({ item.pixels, essence_->header_size });
ext_graph.typeface(essence_->graph->typeface());
int txtop = (essence_->header_size - essence_->text_height) / 2;

View File

@ -1473,7 +1473,7 @@ namespace nana{ namespace widgets
text_area_.area = r;
if(attributes_.enable_counterpart)
attributes_.counterpart.make(r.width, r.height);
attributes_.counterpart.make({ r.width, r.height });
behavior_->pre_calc_lines(width_pixels());
_m_scrollbar();
@ -1529,7 +1529,7 @@ namespace nana{ namespace widgets
{
attributes_.enable_counterpart = enb;
if(enb)
attributes_.counterpart.make(text_area_.area.width, text_area_.area.height);
attributes_.counterpart.make({ text_area_.area.width, text_area_.area.height });
else
attributes_.counterpart.release();
}
@ -2716,7 +2716,7 @@ namespace nana{ namespace widgets
auto px_w = std::accumulate(glyphs, glyphs + len, unsigned{});
::nana::paint::graphics canvas;
canvas.make(px_w, px_h);
canvas.make({ px_w, px_h });
canvas.typeface(graph_.typeface());
::nana::point canvas_text_pos;
@ -2832,7 +2832,7 @@ namespace nana{ namespace widgets
this->_m_draw_parse_string(parser, true, strpos, clr, str, len);
//Draw selected part
paint::graphics graph(glyph_selected, line_h_pixels);
paint::graphics graph({ glyph_selected, line_h_pixels });
graph.typeface(this->graph_.typeface());
graph.rectangle(true, scheme_->selection.get_color());
@ -2920,8 +2920,6 @@ namespace nana{ namespace widgets
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.string(text_pos, ent.begin, endpos - pos);
//graph_.set_text_color(clr); //deprecated
//graph_.string(text_pos + ::nana::point(static_cast<int>(sel_w), 0), ent.begin + (endpos - pos), str_end - endpos);
_m_draw_parse_string(parser, false, text_pos + ::nana::point(static_cast<int>(sel_w), 0), clr, ent.begin + (endpos - pos), str_end - endpos);
}
}

View File

@ -172,7 +172,7 @@ namespace nana
item.image.paste(size, graph, pos);
if(item.enable == false)
{
nana::paint::graphics gh(size.width, size.height);
nana::paint::graphics gh(size);
gh.bitblt(size, graph, pos);
gh.rgb_to_wb();
gh.paste(graph, pos.x, pos.y);

View File

@ -1391,7 +1391,7 @@ namespace nana
comp_attribute_t attr;
if(comp_attribute(component::text, attr))
{
nana::paint::graphics item_graph(item_r_.width, item_r_.height);
nana::paint::graphics item_graph({ item_r_.width, item_r_.height });
item_graph.typeface(graph_->typeface());
renderer_->set_color(widget_->bgcolor(), widget_->fgcolor());

View File

@ -198,16 +198,10 @@ namespace paint
:handle_(nullptr), changed_(false)
{}
graphics::graphics(unsigned width, unsigned height)
:handle_(nullptr), changed_(true)
{
make(width, height);
}
graphics::graphics(const nana::size& sz)
:handle_(nullptr), changed_(true)
{
make(sz.width, sz.height);
make(sz);
}
graphics::graphics(const graphics& rhs)
@ -255,9 +249,9 @@ namespace paint
return (handle_? handle_->context : nullptr);
}
void graphics::make(unsigned width, unsigned height)
void graphics::make(const ::nana::size& sz)
{
if(handle_ == nullptr || size_ != nana::size(width, height))
if(handle_ == nullptr || size_ != sz)
{
//The object will be delete while dwptr_ is performing a release.
drawable_type dw = new nana::detail::drawable_impl_type;
@ -277,12 +271,12 @@ namespace paint
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -static_cast<int>(height);
bmi.bmiHeader.biWidth = sz.width;
bmi.bmiHeader.biHeight = -static_cast<int>(sz.height);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32; // four 8-bit components
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = (width * height) << 2;
bmi.bmiHeader.biSizeImage = (sz.width * sz.height) << 2;
HBITMAP bmp = ::CreateDIBSection(cdc, &bmi, DIB_RGB_COLORS, reinterpret_cast<void**>(&(dw->pixbuf_ptr)), 0, 0);
@ -310,7 +304,7 @@ namespace paint
Display* disp = spec.open_display();
int screen = DefaultScreen(disp);
Window root = ::XRootWindow(disp, screen);
dw->pixmap = ::XCreatePixmap(disp, root, (width ? width : 1), (height ? height : 1), DefaultDepth(disp, screen));
dw->pixmap = ::XCreatePixmap(disp, root, (sz.width ? sz.width : 1), (sz.height ? sz.height : 1), DefaultDepth(disp, screen));
dw->context = ::XCreateGC(disp, dw->pixmap, 0, 0);
#if defined(NANA_UNICODE)
dw->xftdraw = ::XftDrawCreate(disp, dw->pixmap, spec.screen_visual(), spec.colormap());
@ -318,18 +312,16 @@ namespace paint
#endif
if(dw)
{
//dw->fgcolor(0);
dw->set_color(colors::black);
dw->set_text_color(colors::black);
#if defined(NANA_WINDOWS)
dw->bytes_per_line = width * sizeof(pixel_argb_t);
dw->bytes_per_line = sz.width * sizeof(pixel_argb_t);
#else
dw->update_text_color();
#endif
dwptr_ = std::shared_ptr<nana::detail::drawable_impl_type>(dw, detail::drawable_deleter());
dwptr_.reset(dw, detail::drawable_deleter{});
handle_ = dw;
size_.width = width;
size_.height = height;
size_ = sz;
handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, STR("\t"), 1).width;
handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, STR(" "), 1).width;
@ -339,10 +331,10 @@ namespace paint
if(changed_ == false) changed_ = true;
}
void graphics::resize(unsigned width, unsigned height)
void graphics::resize(const ::nana::size& sz)
{
graphics duplicate(*this);
make(width, height);
make(sz);
bitblt(0, 0, duplicate);
}

View File

@ -166,7 +166,7 @@ namespace nana
r.width = endpos - pos.x;
r.height = ts.height;
nana::paint::graphics dum_graph(r.width, r.height);
nana::paint::graphics dum_graph({ r.width, r.height });
dum_graph.bitblt(r, graph, pos);
dum_graph.set_text_color(fgcolor);