Permalink
Browse files

Make the 2d rendering path a special option under _prefer2d

  • Loading branch information...
koenbok committed Jul 1, 2014
1 parent 6ae8769 commit d90714799e7e19542a7aab460822af5f9a5ab083
Showing with 33 additions and 2 deletions.
  1. +4 −0 framer/Layer.coffee
  2. +27 −0 framer/LayerStyle.coffee
  3. +2 −2 test/tests/LayerTest.coffee
@@ -56,6 +56,10 @@ class exports.Layer extends BaseClass
Session._LayerList.push @
# Special power setting for 2d rendering path. Only enable this
# if you know what you are doing. See LayerStyle for more info.
@_prefer2d = false
# We have to create the element before we set the defaults
@_createElement()
@_setDefaultCSS()
@@ -71,6 +71,33 @@ exports.LayerStyle =
webkitTransform: (layer) ->
# We have a special rendering path for layers that prefer 2d rendering.
# This definitely decreases performance, but is handy in complex drawing
# scenarios with rounded corners and shadows where gpu drawing gets weird
# results.
if layer._prefer2d
return exports.LayerStyle.webkitTransformPrefer2d(layer)
"
translate3d(#{layer.x}px,#{layer.y}px,#{layer.z}px)
scale(#{layer.scale})
scale3d(#{layer.scaleX},#{layer.scaleY},#{layer.scaleZ})
skew(#{layer.skew}deg,#{layer.skew}deg)
skewX(#{layer.skewX}deg)
skewY(#{layer.skewY}deg)
rotateX(#{layer.rotationX}deg)
rotateY(#{layer.rotationY}deg)
rotateZ(#{layer.rotationZ}deg)
"
webkitTransformPrefer2d: (layer) ->
# This detects if we use 3d properties, if we don't it only uses
# 2d properties to disable gpu rendering.
css = []
if layer.z != 0
@@ -84,7 +84,7 @@ describe "Layer", ->
layer.y.should.equal 50
# layer.style.webkitTransform.should.equal "matrix(1, 0, 0, 1, 100, 0)"
layer.style.webkitTransform.should.equal "translate(100px, 50px)"
layer.style.webkitTransform.should.equal "translate3d(100px, 50px, 0px) scale(1) scale3d(1, 1, 1) skew(0deg, 0deg) skewX(0deg) skewY(0deg) rotateX(0deg) rotateY(0deg) rotateZ(0deg)"
it "should set scale", ->
@@ -95,7 +95,7 @@ describe "Layer", ->
layer.scaleZ = 100
# layer.style.webkitTransform.should.equal "matrix(1, 0, 0, 1, 100, 50)"
layer.style.webkitTransform.should.equal "translate(0px, 0px) scale3d(100, 100, 100)"
layer.style.webkitTransform.should.equal "translate3d(0px, 0px, 0px) scale(1) scale3d(100, 100, 100) skew(0deg, 0deg) skewX(0deg) skewY(0deg) rotateX(0deg) rotateY(0deg) rotateZ(0deg)"
it "should set origin", ->

0 comments on commit d907147

Please sign in to comment.