@next2d/display 1.15.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { Event as Next2DEvent, EventDispatcher } from "@next2d/events";
2
2
  import { Transform, Rectangle, Point } from "@next2d/geom";
3
- import { $getEvent, $getInstanceId, $currentMousePoint, $currentPlayer, $poolColorTransform, $rendererWorker, $poolMatrix, $hitContext, $variables } from "@next2d/util";
4
- import { $doUpdated, $clamp, $getArray, $boundsMatrix, $Math, $poolBoundsObject, $Infinity, $getBoundsObject, $isNaN, $Deg2Rad, $Number, $Rad2Deg, $SHORT_INT_MIN, $SHORT_INT_MAX, $MATRIX_ARRAY_IDENTITY, $multiplicationMatrix, $poolFloat32Array6, $getMap, $poolMap, $getFloat32Array6 } from "@next2d/share";
3
+ import { $getEvent, $getInstanceId, $currentMousePoint, $poolColorTransform, $rendererWorker, $poolMatrix, $hitContext, $variables } from "@next2d/util";
4
+ import { $doUpdated, $clamp, $getArray, $boundsMatrix, $Math, $poolBoundsObject, $Infinity, $getBoundsObject, $isNaN, $Deg2Rad, $Number, $Rad2Deg, $SHORT_INT_MIN, $SHORT_INT_MAX, $MATRIX_ARRAY_IDENTITY, $multiplicationMatrix, $poolFloat32Array6, $getMap, $poolMap, $getFloat32Array6, $devicePixelRatio, $poolArray, $cacheStore } from "@next2d/share";
5
5
  /**
6
6
  * DisplayObject クラスは、表示リストに含めることのできるすべてのオブジェクトに関する基本クラスです。
7
7
  * DisplayObject クラス自体は、画面上でのコンテンツの描画のための API を含みません。
@@ -107,6 +107,12 @@ export class DisplayObject extends EventDispatcher {
107
107
  * @private
108
108
  */
109
109
  this._$posted = false;
110
+ /**
111
+ * @type {Float32Array}
112
+ * @default null
113
+ * @private
114
+ */
115
+ this._$postArray = null;
110
116
  /**
111
117
  * @type {number}
112
118
  * @default 0
@@ -249,14 +255,22 @@ export class DisplayObject extends EventDispatcher {
249
255
  }
250
256
  set alpha(alpha) {
251
257
  alpha = $clamp(alpha, 0, 1, 0);
258
+ const transform = this._$transform;
252
259
  // clone
253
- const colorTransform = this
254
- ._$transform
255
- .colorTransform;
256
- colorTransform._$colorTransform[3] = alpha;
257
- colorTransform._$colorTransform[7] = 0;
258
- this._$transform.colorTransform = colorTransform;
259
- $poolColorTransform(colorTransform);
260
+ if (!transform._$colorTransform) {
261
+ const colorTransform = transform.colorTransform;
262
+ colorTransform._$colorTransform[3] = alpha;
263
+ colorTransform._$colorTransform[7] = 0;
264
+ transform.colorTransform = colorTransform;
265
+ $poolColorTransform(colorTransform);
266
+ }
267
+ else {
268
+ const colorTransform = transform._$colorTransform;
269
+ colorTransform._$colorTransform[3] = alpha;
270
+ colorTransform._$colorTransform[7] = 0;
271
+ this._$doChanged();
272
+ $doUpdated();
273
+ }
260
274
  }
261
275
  /**
262
276
  * @description 使用するブレンドモードを指定する BlendMode クラスの値です。
@@ -277,7 +291,7 @@ export class DisplayObject extends EventDispatcher {
277
291
  this._$blendMode = transform._$blendMode;
278
292
  return transform._$blendMode;
279
293
  }
280
- const placeObject = this._$getPlaceObject();
294
+ const placeObject = this._$placeObject || this._$getPlaceObject();
281
295
  if (placeObject && placeObject.blendMode) {
282
296
  // cache
283
297
  this._$blendMode = placeObject.blendMode;
@@ -288,7 +302,15 @@ export class DisplayObject extends EventDispatcher {
288
302
  return "normal";
289
303
  }
290
304
  set blendMode(blend_mode) {
291
- this._$transform._$transform(null, null, null, blend_mode);
305
+ const transform = this._$transform;
306
+ if (!transform._$blendMode) {
307
+ transform._$transform(null, null, null, blend_mode);
308
+ }
309
+ else {
310
+ transform._$blendMode = blend_mode;
311
+ this._$doChanged();
312
+ $doUpdated();
313
+ }
292
314
  this._$blendMode = blend_mode;
293
315
  }
294
316
  /**
@@ -323,7 +345,7 @@ export class DisplayObject extends EventDispatcher {
323
345
  this._$filters = clone;
324
346
  return filters;
325
347
  }
326
- const placeObject = this._$getPlaceObject();
348
+ const placeObject = this._$placeObject || this._$getPlaceObject();
327
349
  if (placeObject && placeObject.surfaceFilterList) {
328
350
  // create filter
329
351
  if (!placeObject.filters) {
@@ -553,7 +575,10 @@ export class DisplayObject extends EventDispatcher {
553
575
  return;
554
576
  }
555
577
  const transform = this._$transform;
556
- const matrix = transform.matrix;
578
+ const hasMatrix = transform._$matrix !== null;
579
+ const matrix = hasMatrix
580
+ ? transform._$matrix
581
+ : transform.matrix;
557
582
  const scaleX = $Math.sqrt(matrix.a * matrix.a + matrix.b * matrix.b);
558
583
  const scaleY = $Math.sqrt(matrix.c * matrix.c + matrix.d * matrix.d);
559
584
  if (rotation === 0) {
@@ -583,8 +608,14 @@ export class DisplayObject extends EventDispatcher {
583
608
  matrix.d = scaleY * $Math.cos(radianY);
584
609
  }
585
610
  }
586
- transform.matrix = matrix;
587
- $poolMatrix(matrix);
611
+ if (hasMatrix) {
612
+ this._$doChanged();
613
+ $doUpdated();
614
+ }
615
+ else {
616
+ transform.matrix = matrix;
617
+ $poolMatrix(matrix);
618
+ }
588
619
  this._$rotation = rotation;
589
620
  }
590
621
  /**
@@ -643,7 +674,10 @@ export class DisplayObject extends EventDispatcher {
643
674
  return;
644
675
  }
645
676
  const transform = this._$transform;
646
- const matrix = transform.matrix;
677
+ const hasMatrix = transform._$matrix !== null;
678
+ const matrix = hasMatrix
679
+ ? transform._$matrix
680
+ : transform.matrix;
647
681
  if (matrix.b === 0 || $isNaN(matrix.b)) {
648
682
  matrix.a = scale_x;
649
683
  }
@@ -655,8 +689,14 @@ export class DisplayObject extends EventDispatcher {
655
689
  matrix.b = scale_x * $Math.sin(radianX);
656
690
  matrix.a = scale_x * $Math.cos(radianX);
657
691
  }
658
- transform.matrix = matrix;
659
- $poolMatrix(matrix);
692
+ if (hasMatrix) {
693
+ this._$doChanged();
694
+ $doUpdated();
695
+ }
696
+ else {
697
+ transform.matrix = matrix;
698
+ $poolMatrix(matrix);
699
+ }
660
700
  this._$scaleX = scale_x;
661
701
  }
662
702
  /**
@@ -698,7 +738,10 @@ export class DisplayObject extends EventDispatcher {
698
738
  return;
699
739
  }
700
740
  const transform = this._$transform;
701
- const matrix = transform.matrix;
741
+ const hasMatrix = transform._$matrix !== null;
742
+ const matrix = hasMatrix
743
+ ? transform._$matrix
744
+ : transform.matrix;
702
745
  if (matrix.c === 0 || $isNaN(matrix.c)) {
703
746
  matrix.d = scale_y;
704
747
  }
@@ -710,8 +753,14 @@ export class DisplayObject extends EventDispatcher {
710
753
  matrix.c = -scale_y * $Math.sin(radianY);
711
754
  matrix.d = scale_y * $Math.cos(radianY);
712
755
  }
713
- transform.matrix = matrix;
714
- $poolMatrix(matrix);
756
+ if (hasMatrix) {
757
+ this._$doChanged();
758
+ $doUpdated();
759
+ }
760
+ else {
761
+ transform.matrix = matrix;
762
+ $poolMatrix(matrix);
763
+ }
715
764
  this._$scaleY = scale_y;
716
765
  }
717
766
  /**
@@ -831,10 +880,17 @@ export class DisplayObject extends EventDispatcher {
831
880
  }
832
881
  set x(x) {
833
882
  const transform = this._$transform;
834
- const matrix = transform.matrix;
835
- matrix.tx = x;
836
- transform.matrix = matrix;
837
- $poolMatrix(matrix);
883
+ if (!transform._$matrix) {
884
+ const matrix = transform.matrix;
885
+ matrix.tx = x;
886
+ transform.matrix = matrix;
887
+ $poolMatrix(matrix);
888
+ }
889
+ else {
890
+ transform._$matrix.tx = x;
891
+ this._$doChanged();
892
+ $doUpdated();
893
+ }
838
894
  }
839
895
  /**
840
896
  * @description 親 DisplayObjectContainer のローカル座標を基準にした
@@ -851,10 +907,17 @@ export class DisplayObject extends EventDispatcher {
851
907
  }
852
908
  set y(y) {
853
909
  const transform = this._$transform;
854
- const matrix = transform.matrix;
855
- matrix.ty = y;
856
- transform.matrix = matrix;
857
- $poolMatrix(matrix);
910
+ if (!transform._$matrix) {
911
+ const matrix = transform.matrix;
912
+ matrix.ty = y;
913
+ transform.matrix = matrix;
914
+ $poolMatrix(matrix);
915
+ }
916
+ else {
917
+ transform._$matrix.ty = y;
918
+ this._$doChanged();
919
+ $doUpdated();
920
+ }
858
921
  }
859
922
  /**
860
923
  * @description targetCoordinateSpace オブジェクトの座標系を基準にして、
@@ -1240,72 +1303,76 @@ export class DisplayObject extends EventDispatcher {
1240
1303
  }
1241
1304
  /**
1242
1305
  * @param {CanvasToWebGLContext} context
1243
- * @param {WebGLTexture} target_texture
1244
1306
  * @param {Float32Array} matrix
1245
1307
  * @param {array} filters
1246
1308
  * @param {number} width
1247
1309
  * @param {number} height
1248
- * @return {WebGLTexture}
1310
+ * @param {WebGLTexture} [target_texture = null]
1311
+ * @return {object}
1249
1312
  * @method
1250
1313
  * @private
1251
1314
  */
1252
- _$drawFilter(context, target_texture, matrix, filters, width, height) {
1253
- const player = $currentPlayer();
1254
- const cacheStore = player.cacheStore;
1255
- const cacheKeys = [this._$instanceId, "f"];
1256
- const cache = cacheStore.get(cacheKeys);
1257
- const updated = this._$isFilterUpdated(width, height, matrix, filters, true);
1258
- if (cache && !updated) {
1259
- return cache;
1315
+ _$drawFilter(context, matrix, filters, width, height, target_texture = null) {
1316
+ const cacheKeys = $getArray(this._$instanceId, "f");
1317
+ let position = $cacheStore.get(cacheKeys);
1318
+ const updated = this._$isFilterUpdated(matrix, filters, true);
1319
+ if (position && !updated) {
1320
+ context.cachePosition = position;
1321
+ return position;
1260
1322
  }
1261
1323
  // cache clear
1262
- if (cache) {
1263
- cacheStore.set(cacheKeys, null);
1264
- cache.layerWidth = 0;
1265
- cache.layerHeight = 0;
1266
- cache._$offsetX = 0;
1267
- cache._$offsetY = 0;
1268
- cache.matrix = null;
1269
- cache.colorTransform = null;
1270
- context
1271
- .frameBuffer
1272
- .releaseTexture(cache);
1273
- }
1274
- if (!cache || updated) {
1275
- const texture = this._$applyFilter(context, filters, target_texture, matrix, width, height);
1276
- cacheStore.set(cacheKeys, texture);
1277
- return texture;
1278
- }
1279
- return cache;
1324
+ if (position) {
1325
+ $cacheStore.set(cacheKeys, null);
1326
+ }
1327
+ const manager = context.frameBuffer;
1328
+ const targetTexture = target_texture
1329
+ ? target_texture
1330
+ : context.getTextureFromRect(context.cachePosition);
1331
+ const texture = this._$applyFilter(context, filters, targetTexture, matrix, width, height);
1332
+ manager.textureManager.release(targetTexture);
1333
+ const bounds = this._$getLayerBounds(matrix);
1334
+ position = manager.createCachePosition($Math.ceil($Math.abs(bounds.xMax - bounds.xMin)), $Math.ceil($Math.abs(bounds.yMax - bounds.yMin)));
1335
+ $poolBoundsObject(bounds);
1336
+ position.filterState = true;
1337
+ position.matrix = `${matrix[0]}_${matrix[1]}_${matrix[2]}_${matrix[3]}_0_0`;
1338
+ position.offsetX = texture.offsetX;
1339
+ position.offsetY = texture.offsetY;
1340
+ // 関数先でtextureがreleaseされる
1341
+ context.drawTextureFromRect(texture, position);
1342
+ $cacheStore.set(cacheKeys, position);
1343
+ $poolArray(cacheKeys);
1344
+ return position;
1280
1345
  }
1281
1346
  /**
1282
- * @param {array} [matrix=null]
1347
+ * @param {Float32Array} multi_matrix
1283
1348
  * @returns {object}
1284
1349
  * @private
1285
1350
  */
1286
- _$getLayerBounds(matrix = null) {
1351
+ _$getLayerBounds(multi_matrix) {
1287
1352
  const baseBounds = "_$getBounds" in this && typeof this._$getBounds === "function"
1288
- ? this._$getBounds(matrix)
1353
+ ? this._$getBounds()
1289
1354
  : $getBoundsObject();
1290
- if (!matrix) {
1291
- return baseBounds;
1292
- }
1355
+ const bounds = $boundsMatrix(baseBounds, multi_matrix);
1356
+ $poolBoundsObject(baseBounds);
1293
1357
  const filters = this._$filters || this.filters;
1294
1358
  if (!filters.length) {
1295
- return baseBounds;
1359
+ return bounds;
1296
1360
  }
1297
- let filterBounds = $getBoundsObject(baseBounds.xMin, baseBounds.yMin, baseBounds.xMax - baseBounds.xMin, baseBounds.yMax - baseBounds.yMin);
1298
- $poolBoundsObject(baseBounds);
1361
+ let filterBounds = $getBoundsObject(0, $Math.abs(bounds.xMax - bounds.xMin), 0, $Math.abs(bounds.yMax - bounds.yMin));
1362
+ $poolBoundsObject(bounds);
1363
+ let xScale = +$Math.sqrt(multi_matrix[0] * multi_matrix[0]
1364
+ + multi_matrix[1] * multi_matrix[1]);
1365
+ let yScale = +$Math.sqrt(multi_matrix[2] * multi_matrix[2]
1366
+ + multi_matrix[3] * multi_matrix[3]);
1367
+ xScale /= $devicePixelRatio;
1368
+ yScale /= $devicePixelRatio;
1369
+ xScale *= 2;
1370
+ yScale *= 2;
1299
1371
  for (let idx = 0; idx < filters.length; ++idx) {
1300
1372
  filterBounds = filters[idx]
1301
- ._$generateFilterRect(filterBounds, 0, 0);
1373
+ ._$generateFilterRect(filterBounds, xScale, yScale);
1302
1374
  }
1303
- const xMin = filterBounds.xMin;
1304
- const xMax = filterBounds.xMin + filterBounds.xMax;
1305
- const yMin = filterBounds.yMin;
1306
- const yMax = filterBounds.yMin + filterBounds.yMax;
1307
- $poolBoundsObject(filterBounds);
1308
- return $getBoundsObject(xMin, xMax, yMin, yMax);
1375
+ return filterBounds;
1309
1376
  }
1310
1377
  /**
1311
1378
  * @return {void}
@@ -1372,8 +1439,6 @@ export class DisplayObject extends EventDispatcher {
1372
1439
  return false;
1373
1440
  }
1374
1441
  /**
1375
- * @param {number} width
1376
- * @param {number} height
1377
1442
  * @param {Float32Array} matrix
1378
1443
  * @param {array} [filters=null]
1379
1444
  * @param {boolean} [can_apply=false]
@@ -1382,7 +1447,7 @@ export class DisplayObject extends EventDispatcher {
1382
1447
  * @return {boolean}
1383
1448
  * @private
1384
1449
  */
1385
- _$isFilterUpdated(width, height, matrix, filters = null, can_apply = false, position_x = 0, position_y = 0) {
1450
+ _$isFilterUpdated(matrix, filters = null, can_apply = false) {
1386
1451
  // cache flag
1387
1452
  if (this._$isUpdated()) {
1388
1453
  return true;
@@ -1397,19 +1462,15 @@ export class DisplayObject extends EventDispatcher {
1397
1462
  }
1398
1463
  }
1399
1464
  // check status
1400
- const player = $currentPlayer();
1401
- const cache = player.cacheStore.get([this._$instanceId, "f"]);
1402
- switch (true) {
1403
- case cache === null:
1404
- case cache.filterState !== can_apply:
1405
- case cache.layerWidth !== $Math.ceil(width):
1406
- case cache.layerHeight !== $Math.ceil(height):
1407
- case cache.matrix !==
1408
- matrix[0] + "_" + matrix[1] + "_" + matrix[2] + "_" + matrix[3] + "_" +
1409
- position_x + "_" + position_y:
1410
- return true;
1411
- default:
1412
- break;
1465
+ const cache = $cacheStore.get([this._$instanceId, "f"]);
1466
+ if (!cache) {
1467
+ return true;
1468
+ }
1469
+ if (cache.filterState !== can_apply) {
1470
+ return true;
1471
+ }
1472
+ if (cache.matrix !== `${matrix[0]}_${matrix[1]}_${matrix[2]}_${matrix[3]}`) {
1473
+ return true;
1413
1474
  }
1414
1475
  return false;
1415
1476
  }
@@ -1462,15 +1523,8 @@ export class DisplayObject extends EventDispatcher {
1462
1523
  context._$offsetX = 0;
1463
1524
  context._$offsetY = 0;
1464
1525
  // set offset
1465
- texture._$offsetX = offsetX;
1466
- texture._$offsetY = offsetY;
1467
- // cache texture
1468
- texture.matrix =
1469
- matrix[0] + "_" + matrix[1] + "_"
1470
- + matrix[2] + "_" + matrix[3];
1471
- texture.filterState = true;
1472
- texture.layerWidth = width;
1473
- texture.layerHeight = height;
1526
+ texture.offsetX = offsetX;
1527
+ texture.offsetY = offsetY;
1474
1528
  context._$bind(currentAttachment);
1475
1529
  manager.releaseAttachment(attachment, false);
1476
1530
  return texture;
@@ -1494,35 +1548,20 @@ export class DisplayObject extends EventDispatcher {
1494
1548
  /**
1495
1549
  * @param {CanvasToWebGLContext} context
1496
1550
  * @param {Float32Array} matrix
1497
- * @return {Float32Array|boolean|null}
1551
+ * @return {boolean}
1498
1552
  * @method
1499
1553
  * @private
1500
1554
  */
1501
1555
  _$startClip(context, matrix) {
1502
- let clipMatrix = null;
1503
- // ネストしてない初回のマスクだけ実行
1504
- // ネストしてる場合は初回に作られたbufferを流用
1505
- if (!context.cacheAttachment) {
1506
- let multiMatrix = matrix;
1507
- const rawMatrix = this._$transform._$rawMatrix();
1508
- if (rawMatrix[0] !== 1 || rawMatrix[1] !== 0
1509
- || rawMatrix[2] !== 0 || rawMatrix[3] !== 1
1510
- || rawMatrix[4] !== 0 || rawMatrix[5] !== 0) {
1511
- multiMatrix = $multiplicationMatrix(matrix, rawMatrix);
1512
- }
1513
- const baseBounds = "_$getBounds" in this && typeof this._$getBounds === "function"
1514
- ? this._$getBounds()
1515
- : $getBoundsObject();
1516
- const bounds = $boundsMatrix(baseBounds, multiMatrix);
1517
- $poolBoundsObject(baseBounds);
1518
- clipMatrix = context._$startClip(matrix, bounds);
1519
- $poolBoundsObject(bounds);
1520
- if (multiMatrix !== matrix) {
1521
- $poolFloat32Array6(multiMatrix);
1522
- }
1523
- if (!clipMatrix) {
1524
- return false;
1525
- }
1556
+ context.drawInstacedArray();
1557
+ // マスクの描画反映を限定
1558
+ const bounds = "_$getBounds" in this && typeof this._$getBounds === "function"
1559
+ ? this._$getBounds(matrix)
1560
+ : $getBoundsObject();
1561
+ const result = context._$startClip(bounds);
1562
+ $poolBoundsObject(bounds);
1563
+ if (!result) {
1564
+ return false;
1526
1565
  }
1527
1566
  // start clip
1528
1567
  context._$enterClip();
@@ -1534,7 +1573,7 @@ export class DisplayObject extends EventDispatcher {
1534
1573
  context._$updateContainerClipFlag(true);
1535
1574
  }
1536
1575
  // @ts-ignore
1537
- this._$clip(context, clipMatrix || matrix);
1576
+ this._$clip(context, matrix);
1538
1577
  this._$updated = false;
1539
1578
  // container clip
1540
1579
  if (containerClip) {
@@ -1545,7 +1584,7 @@ export class DisplayObject extends EventDispatcher {
1545
1584
  }
1546
1585
  // mask end
1547
1586
  context._$endClipDef();
1548
- return clipMatrix;
1587
+ return true;
1549
1588
  }
1550
1589
  /**
1551
1590
  * @return {void}
@@ -191,11 +191,11 @@ export declare class DisplayObjectContainer extends InteractiveObject {
191
191
  */
192
192
  _$getBounds(matrix?: Float32Array | null): BoundsImpl;
193
193
  /**
194
- * @param {array} [matrix=null]
194
+ * @param {Float32Array} multi_matrix
195
195
  * @return {object}
196
196
  * @private
197
197
  */
198
- _$getLayerBounds(matrix?: Float32Array | null): BoundsImpl;
198
+ _$getLayerBounds(multi_matrix: Float32Array): BoundsImpl;
199
199
  /**
200
200
  * @return {array}
201
201
  * @private