diff options
author | Dan Gudmundsson <[email protected]> | 2015-12-10 12:39:19 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2016-02-22 09:54:34 +0100 |
commit | bde2d01506a6368b4d3667d0102c189832563654 (patch) | |
tree | 9d070f2d2a00e2d669bcac4fd03121ca0473d609 /lib/observer/src/observer_app_wx.erl | |
parent | d80e6353e7b827b9fb3d9a9505948dfaa2491cd4 (diff) | |
download | otp-bde2d01506a6368b4d3667d0102c189832563654.tar.gz otp-bde2d01506a6368b4d3667d0102c189832563654.tar.bz2 otp-bde2d01506a6368b4d3667d0102c189832563654.zip |
observer: Optimize drawing of graphs
By allowing changes to the number of minutes displayed and update
frequency, we need to optimize the drawing of the graphs as it can
no longer recalculate everything in each frame drawn.
Only recalculate the changed entries, takes more memory but far less
cpu usage.
While updating the gui, increase the frame-rate a bit so it updates
smoother and decrease pen size for graphs to 1 pixel as it looks better
according to an office voting.
Diffstat (limited to 'lib/observer/src/observer_app_wx.erl')
-rw-r--r-- | lib/observer/src/observer_app_wx.erl | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/lib/observer/src/observer_app_wx.erl b/lib/observer/src/observer_app_wx.erl index a2b7c21993..40e117357c 100644 --- a/lib/observer/src/observer_app_wx.erl +++ b/lib/observer/src/observer_app_wx.erl @@ -29,7 +29,7 @@ -include("observer_defs.hrl"). %% Import drawing wrappers --import(observer_perf_wx, [haveGC/0, +-import(observer_perf_wx, [haveGC/0, make_gc/2, destroy_gc/1, setPen/2, setFont/3, setBrush/2, strokeLine/5, strokeLines/2, drawRoundedRectangle/6, drawText/4, getTextExtent/2]). @@ -244,28 +244,18 @@ handle_event(Event, _State) -> %%%%%%%%%% handle_sync_event(#wx{event = #wxPaint{}},_, #state{app_w=DA, app=App, sel=Sel, paint=Paint, usegc=UseGC}) -> - %% PaintDC must be created in a callback to work on windows. - IsWindows = element(1, os:type()) =:= win32, - %% Avoid Windows flickering hack - DC = if IsWindows -> wx:typeCast(wxBufferedPaintDC:new(DA), wxPaintDC); - true -> wxPaintDC:new(DA) - end, - IsWindows andalso wxDC:clear(DC), - GC = case UseGC of - true -> - GC0 = ?wxGC:create(DC), - %% Argh must handle scrolling when using ?wxGC - {Sx,Sy} = wxScrolledWindow:calcScrolledPosition(DA, {0,0}), - ?wxGC:translate(GC0, Sx,Sy), - GC0; - false -> - wxScrolledWindow:doPrepareDC(DA,DC), - DC - end, + GC = {GC0, DC} = make_gc(DA, UseGC), + case UseGC of + false -> + wxScrolledWindow:doPrepareDC(DA,DC); + true -> + %% Argh must handle scrolling when using ?wxGC + {Sx,Sy} = wxScrolledWindow:calcScrolledPosition(DA, {0,0}), + ?wxGC:translate(GC0, Sx,Sy) + end, %% Nothing is drawn until wxPaintDC is destroyed. - draw({UseGC, GC}, App, Sel, Paint), - UseGC andalso ?wxGC:destroy(GC), - wxPaintDC:destroy(DC), + draw(GC, App, Sel, Paint), + destroy_gc(GC), ok. %%%%%%%%%% handle_call(Event, From, _State) -> @@ -312,15 +302,10 @@ handle_info({delivery, _Pid, app, _Curr, {[], [], [], []}}, handle_info({delivery, Pid, app, Curr, AppData}, State = #state{panel=Panel, appmon=Pid, current=Curr, usegc=UseGC, app_w=AppWin, paint=#paint{font=Font}}) -> - GC = if UseGC -> ?wxGC:create(AppWin); - true -> wxWindowDC:new(AppWin) - end, - FontW = {UseGC, GC}, - setFont(FontW, Font, {0,0,0}), - App = build_tree(AppData, FontW), - if UseGC -> ?wxGC:destroy(GC); - true -> wxWindowDC:destroy(GC) - end, + GC = make_gc(AppWin, UseGC), + setFont(GC, Font, {0,0,0}), + App = build_tree(AppData, GC), + destroy_gc(GC), setup_scrollbar(AppWin, App), wxWindow:refresh(Panel), wxWindow:layout(Panel), |