Revision: 3820 http://vexi.svn.sourceforge.net/vexi/?rev=3820&view=rev Author: clrg Date: 2010-03-23 01:39:34 +0000 (Tue, 23 Mar 2010)
Log Message: ----------- Feature: abort reflow/render -> js can affect live reflow Modified Paths: -------------- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp trunk/core/org.vexi.core/src/org/vexi/core/Surface.java Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2010-03-19 15:54:47 UTC (rev 3819) +++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2010-03-23 01:39:34 UTC (rev 3820) @@ -431,7 +431,7 @@ //#repeat width/height WIDTH/HEIGHT if (width != this.width) { PUT_BOX_FIELD(SC_width,JSU.N(width),this.width = width,WIDTH_TRAP) - setPlace(); + setPlaceAndCatchExceptions(); } //#end dirtyInPlace(clean); @@ -451,7 +451,7 @@ //#repeat width/height WIDTH/HEIGHT if (width != this.width) { PUT_BOX_FIELD(SC_width,JSU.N(width),this.width = width,WIDTH_TRAP) - setPlace(); + setPlaceAndCatchExceptions(); } //#end dirtyInPlace(clean); @@ -460,34 +460,62 @@ // Reflow //////////////////////////////////////////////////////////////////////////////////////// - private final void setConstrain() { set(CONSTRAIN); setConstrainInTree(); } - private final void setConstrainInTree() { + private final void setConstrain() throws JSExn { set(CONSTRAIN); setConstrainInTree(); } + private final void setParentConstrain() throws JSExn { + if (parent != null) { + parent.setConstrain(); + } + } + private final void setConstrainAndCatchExceptions () { + try { + set(CONSTRAIN); + setConstrainInTree(); + } catch(JSExn e) { + Log.warn(Box.class,"Caught exception due to Surface.abort during constrain"); + e.printStackTrace(Logger.WARN, Log.user, Box.class); + } + } + private final void setConstrainInTree() throws JSExn { Box b=this; // FIXME: box tree is getting into inconsistent states with CONSTRAIN_DESCENDENT - while (b.test(DISPLAY) && (b=b.parent)!=null) {// && !b.test(CONSTRAIN_DESCENDENT)) { + while (b.test(DISPLAY) && b.parent!=null) {// && !b.parent.test(CONSTRAIN_DESCENDENT)) { + b = b.parent; b.set(CONSTRAIN_DESCENDENT); } + Surface s = b.getSurface(); + if (s!=null) { + s.abortReflow(); + } } - private final void setParentConstrain() { + + private final void setPlace() throws JSExn { set(PLACE); setPlaceInTree(); } + private final void setParentPlace() throws JSExn { if (parent != null) { - parent.setConstrain(); + parent.setPlace(); } } - - private final void setPlace() { set(PLACE); setPlaceInTree(); } - private final void setPlaceInTree() { + private final void setPlaceAndCatchExceptions () { + try { + set(PLACE); + setPlaceInTree(); + } catch(JSExn e) { + Log.warn(Box.class,"Caught exception due to Surface.abort during place"); + e.printStackTrace(Logger.WARN, Log.user, Box.class); + } + } + private final void setPlaceInTree() throws JSExn { Box b=this; - while (b.test(DISPLAY) && (b=b.parent)!=null && !b.test(PLACE_DESCENDENT)) { + while (b.test(DISPLAY) && b.parent!=null && !b.parent.test(PLACE_DESCENDENT)) { + b = b.parent; b.set(PLACE_DESCENDENT); } - } - private final void setParentPlace() { - if (parent != null) { - parent.setPlace(); + Surface s = b.getSurface(); + if (s!=null) { + s.abortReflow(); } } - private final void requestReflow() { + private final void requestReflow() throws JSExn { if (test(CONSTRAIN) || test(CONSTRAIN_DESCENDENT)) { setConstrainInTree(); } @@ -530,11 +558,16 @@ } /** should only be invoked on the root box */ - public boolean reflow(int w, int h) { + public boolean reflow(Surface fromSurface, int w, int h) { if ((flags & REFLOW) == 0 && w==width && h==height) { return false; } constrain(); + if (fromSurface.renderAborted()) { + // if the current reflow/render has been aborted then + // defer place() until contraining has been completed + return false; + } tryResize(w, h, true); boolean mouseUpdateRequired = test(PLACE|PLACE_DESCENDENT); place(test(PLACE_CLEAN)); @@ -620,9 +653,9 @@ if (newwidth != contentwidth) { if (parent != null) { PUT_BOX_FIELD(SC_contentwidth,JSU.N(newwidth),contentwidth=newwidth,CONTENTWIDTH_TRAP) - setPlace(); + setPlaceAndCatchExceptions(); parent.set(PLACE); - parent.setConstrain(); + parent.setConstrainAndCatchExceptions(); } else { // constrain contentwidth to frame width if (getSurface()!=null && !test(SHRINK)) { @@ -630,7 +663,7 @@ } if (newwidth != contentwidth) { PUT_BOX_FIELD(SC_contentwidth,JSU.N(newwidth),contentwidth=newwidth,CONTENTWIDTH_TRAP) - setPlace(); + setPlaceAndCatchExceptions(); } } } Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java 2010-03-19 15:54:47 UTC (rev 3819) +++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java 2010-03-23 01:39:34 UTC (rev 3820) @@ -62,9 +62,6 @@ /** all instances of Surface which need to be refreshed by the Platform.Scheduler */ public static Vec allSurfaces = new Vec(); - - /** when set to true, render() should abort as soon as possible and restart the rendering process */ - public volatile boolean abort = false; // these three variables are used to ensure that user resizes trump programmatic resizes public volatile int pendingWidth = 0; @@ -667,6 +664,18 @@ // unused - private static Affine identity = Affine.identity(); + + /** when set to true, render() should abort as soon as possible and restart the rendering process */ + private volatile boolean abort = false; + private int abortcount; + public boolean renderAborted() { return abort; } + public void abortReflow() throws JSExn { + if (abortcount>=1000) { + throw new JSExn("Reflow appears to be getting aborted indefinitely"); + } + abort = true; + } + /** runs the pre-render() and render() pipelines in the root Box to regenerate the backbuffer, then blits it to the screen */ public synchronized void render() { scheduled = false; @@ -675,8 +684,10 @@ return; } // make sure the root is properly sized + abortcount = 0; do { abort = false; + abortcount ++; // pending size update means the user resized the window if (pendingWidth != root.width || pendingHeight != root.height) { // ensure scar is always shown @@ -689,7 +700,7 @@ // reflow to new size as set by the frame int cwidth = root.contentwidth; int cheight = root.contentheight; - mouseUpdateRequired = root.reflow(pendingWidth, pendingHeight) || mouseUpdateRequired; + mouseUpdateRequired = root.reflow(this, pendingWidth, pendingHeight) || mouseUpdateRequired; if (Box.testShrink(root) && (cwidth!=root.contentwidth || cheight!=root.contentheight)) { setMinimumSize(root.contentwidth, root.contentheight); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn