44 * @extends Renderer
55 * @cat drivers.canvas
66 */
7+
78/* @echo EXPORT */
89class DisplayObjectRendererCanvas extends Renderer {
910 constructor ( ) {
@@ -23,6 +24,11 @@ class DisplayObjectRendererCanvas extends Renderer {
2324
2425 /** @private @type {boolean } */
2526 this . mIsClipped = false ;
27+
28+ this . mIsCached = false ;
29+
30+ /** @private @type {Matrix|null } */
31+ this . mBakeInvertedMatrix = null ;
2632 }
2733
2834 /** @inheritDoc */
@@ -33,15 +39,28 @@ class DisplayObjectRendererCanvas extends Renderer {
3339 this . endPassRequired = this . mIsClipped ;
3440
3541 if ( gameObject . mCacheAsBitmap === true ) {
36- let isStatic = gameObject . checkStatic ( true ) ;
37- if ( isStatic === true && this . mCacheAsBitmapDirty === true ) {
38- gameObject . setTransformDirty ( ) ;
39- this . __refreshBitmapCache ( ) ;
40- this . mCacheAsBitmapDirty = false ;
41- this . endPassRequired = false ;
42- } else if ( isStatic === false ) {
43- this . mCacheAsBitmapDirty = true ;
44- gameObject . mDirty |= DirtyFlag . RENDER ;
42+ if ( gameObject . mCacheAsBitmapDynamic === false ) {
43+ if ( this . mIsCached === false ) {
44+ this . mIsCached = true ;
45+ gameObject . setTransformDirty ( ) ;
46+ this . __refreshBitmapCache ( ) ;
47+ this . mCacheAsBitmapDirty = false ;
48+ this . endPassRequired = false ;
49+ } else {
50+ gameObject . mDirty |= DirtyFlag . RENDER ;
51+ }
52+ } else {
53+ let isStatic = gameObject . checkStatic ( true ) ;
54+
55+ if ( isStatic === true && this . mCacheAsBitmapDirty === true ) {
56+ gameObject . setTransformDirty ( ) ;
57+ this . __refreshBitmapCache ( ) ;
58+ this . mCacheAsBitmapDirty = false ;
59+ this . endPassRequired = false ;
60+ } else if ( isStatic === false ) {
61+ this . mCacheAsBitmapDirty = true ;
62+ gameObject . mDirty |= DirtyFlag . RENDER ;
63+ }
4564 }
4665 }
4766
@@ -78,9 +97,18 @@ class DisplayObjectRendererCanvas extends Renderer {
7897 let gameObject = /** @type {DisplayObject } */ ( this . gameObject ) ;
7998 let transform = gameObject . worldTransformation ;
8099
81- if ( this . skipChildren === true )
100+ if ( this . skipChildren === true ) {
82101 transform = this . mCacheAsBitmapMatrixCache ;
83102
103+ if ( gameObject . mCacheAsBitmapDynamic === false ) {
104+ transform = new Matrix ( )
105+ . append ( this . gameObject . worldTransformation )
106+ . append ( this . mBakeInvertedMatrix )
107+ . append ( this . mCacheAsBitmapMatrixCache )
108+ }
109+ }
110+
111+
84112 if ( this . skipChildren === true || this . endPassRequired === true ) {
85113 driver . setSnapToPixels ( gameObject . snapToPixels ) ;
86114 driver . setTransform ( transform ) ;
@@ -135,6 +163,7 @@ class DisplayObjectRendererCanvas extends Renderer {
135163 this . mCacheAsBitmapMatrixCache . data [ 4 ] = - this . mCacheAsBitmapMatrixCache . data [ 4 ] ;
136164 this . mCacheAsBitmapMatrixCache . data [ 5 ] = - this . mCacheAsBitmapMatrixCache . data [ 5 ] ;
137165
166+ this . mBakeInvertedMatrix = this . gameObject . worldTransformation . clone ( ) . invert ( ) ;
138167 //this.mCacheTexture.__dumpToDocument();
139168 }
140169}
0 commit comments