Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #264 from silexlabs/performance

bug fixes for im demo
  • Loading branch information...
commit e1eda32491ec20935f3d9d538d6162f5916e9092 2 parents b562be3 + ac999df
@yanhick yanhick authored
View
14 src/cocktail/core/css/CoreStyle.hx
@@ -64,7 +64,7 @@ class CoreStyle
public var marginLeft(get_marginLeft, null):CSSPropertyValue;
public var marginRight(get_marginRight, null):CSSPropertyValue;
public var marginTop(get_marginTop, null):CSSPropertyValue;
- public var marginBottom(get_marginTop, null):CSSPropertyValue;
+ public var marginBottom(get_marginBottom, null):CSSPropertyValue;
public var paddingLeft(get_paddingLeft, null):CSSPropertyValue;
public var paddingRight(get_paddingRight, null):CSSPropertyValue;
@@ -1066,6 +1066,18 @@ class CoreStyle
{
switch(propertyName)
{
+ case CSSConstants.MIN_HEIGHT:
+ return CSSConstants.HEIGHT;
+
+ case CSSConstants.MAX_HEIGHT:
+ return CSSConstants.MAX_HEIGHT;
+
+ case CSSConstants.MIN_WIDTH:
+ return CSSConstants.MIN_WIDTH;
+
+ case CSSConstants.MAX_WIDTH:
+ return CSSConstants.MAX_WIDTH;
+
default:
return propertyName;
}
View
1  src/cocktail/core/invalidation/InvalidationManager.hx
@@ -339,6 +339,7 @@ class InvalidationManager
//same as for layout
if (_documentNeedsRendering == true)
{
+ _htmlDocument.documentElement.elementRenderer.layerRenderer.updateLayerAlpha(1.0);
_htmlDocument.documentElement.elementRenderer.layerRenderer.render(_htmlDocument.window.innerWidth, _htmlDocument.window.innerHeight);
_documentNeedsRendering = false;
}
View
108 src/cocktail/core/layer/LayerRenderer.hx
@@ -173,6 +173,18 @@ class LayerRenderer extends FastNode<LayerRenderer>
private var _needsBitmapSizeUpdate:Bool;
/**
+ * This is the alpha, from 0 to 1 which
+ * should be used when rendering all
+ * the element renderer of this
+ * layer.
+ *
+ * This is the combined value of
+ * the alphas of this layer
+ * and its ancestors
+ */
+ private var _alpha:Float;
+
+ /**
* class constructor. init class attributes
*/
public function new(rootElementRenderer:ElementRenderer)
@@ -192,6 +204,8 @@ class LayerRenderer extends FastNode<LayerRenderer>
_needsGraphicsContextUpdate = true;
_needsStackingContextUpdate = true;
+ _alpha = 1.0;
+
_windowWidth = 0;
_windowHeight = 0;
}
@@ -247,6 +261,54 @@ class LayerRenderer extends FastNode<LayerRenderer>
}
/**
+ * Update the alpha of this layer before
+ * rendering. It is obtained by
+ * combining the alpha of the root element
+ * renderer with the alpha of the parent layer.
+ *
+ * For instance if the parent alpha is 0.5 and
+ * this layer's root element renderer is 0.5,
+ * then this layer alpha will be 0.25
+ *
+ * @param parentAlpha the alpha of the parent
+ * layer
+ */
+ public function updateLayerAlpha(parentAlpha:Float):Void
+ {
+ //default to 1 if the layer is opaque
+ var layerAlpha:Float = 1.0;
+
+ //get opacity of root element renderer if transparent
+ if (rootElementRenderer.isTransparent() == true)
+ {
+ var coreStyle:CoreStyle = rootElementRenderer.coreStyle;
+
+ switch(coreStyle.opacity)
+ {
+ case NUMBER(value):
+ layerAlpha = value;
+
+ case ABSOLUTE_LENGTH(value):
+ layerAlpha = value;
+
+ default:
+ }
+ }
+
+ //combine alpha with parent alpha
+ _alpha = layerAlpha * parentAlpha;
+
+ //update the whole layer tree recursively
+ var child:LayerRenderer = firstChild;
+ while (child != null)
+ {
+ child.updateLayerAlpha(_alpha);
+ child = child.nextSibling;
+ }
+
+ }
+
+ /**
* Called by the docuement before rendering when
* the stacking context of the layer tree needs to
* be updated
@@ -802,32 +864,6 @@ class LayerRenderer extends FastNode<LayerRenderer>
clear();
}
}
-
- //init transparency on the graphicContext if the element is transparent. Everything
- //painted afterwards will have an alpha equal to the opacity style
- //
- //TODO 1 : will not work if child layer also have alpha, alpha
- //won't be combined properly. Should GraphicsContext have offscreen bitmap
- //for each transparent layer and compose them when transparency end ?
- if (rootElementRenderer.isTransparent() == true)
- {
- var coreStyle:CoreStyle = rootElementRenderer.coreStyle;
-
- //get the current opacity value
- var opacity:Float = 0.0;
- switch(coreStyle.opacity)
- {
- case NUMBER(value):
- opacity = value;
-
- case ABSOLUTE_LENGTH(value):
- opacity = value;
-
- default:
- }
-
- graphicsContext.graphics.beginTransparency(opacity);
- }
//render first negative z-index child LayerRenderer from most
//negative to least negative
@@ -841,9 +877,22 @@ class LayerRenderer extends FastNode<LayerRenderer>
//their own graphic context, layer which don't always gets re-painted
if (_needsRendering == true)
{
+ //if this layer is transparent, start a transparent
+ //layer with the graphics context
+ if (_alpha != 1.0)
+ {
+ graphicsContext.graphics.beginTransparency(_alpha);
+ }
+
//render the rootElementRenderer itself which will also
//render all ElementRenderer belonging to this LayerRenderer
rootElementRenderer.render(graphicsContext);
+
+ //end transparency layer
+ if (_alpha != 1.0)
+ {
+ graphicsContext.graphics.endTransparency();
+ }
}
//render zero and auto z-index child LayerRenderer, in tree order
@@ -861,13 +910,6 @@ class LayerRenderer extends FastNode<LayerRenderer>
positiveZIndexChildLayerRenderers[i].render(windowWidth, windowHeight);
}
- //stop transparency so that subsequent painted element won't be transparent
- //if they don't themselves have an opacity inferior to 1
- if (rootElementRenderer.isTransparent() == true)
- {
- graphicsContext.graphics.endTransparency();
- }
-
//scrollbars are always rendered last as they should always be the top
//element of their layer
rootElementRenderer.renderScrollBars(graphicsContext, windowWidth, windowHeight);
View
2  src/cocktail/core/linebox/TextLineBox.hx
@@ -120,8 +120,6 @@ class TextLineBox extends LineBox
bitmapBounds.y = leadedAscent;
bitmapBounds.width = bounds.width;
bitmapBounds.height = bounds.height;
- //TODO 1 : there is memory leak, when text is disposed, its bitmap
- //data is not
_nativeTextBitmap = _nativeText.getBitmap(bitmapBounds);
}
View
2  src/cocktail/core/renderer/FlowBoxRenderer.hx
@@ -234,7 +234,7 @@ class FlowBoxRenderer extends BoxRenderer
{
var usedValues:UsedValuesVO = elementRenderer.coreStyle.usedValues;
return containingHTMLElementHeight - usedValues.height - usedValues.paddingTop -
- usedValues.paddingBottom - usedValues.bottom;
+ usedValues.paddingBottom - usedValues.bottom - usedValues.marginBottom;
}
//////////////////////////////////////////////////////////////////////////////////////////
Please sign in to comment.
Something went wrong with that request. Please try again.