Skip to content

Commit

Permalink
#21 OffscreenCanvasの実装(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Feb 15, 2023
1 parent 8e719c3 commit ac59dda
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 59 deletions.
3 changes: 0 additions & 3 deletions src/next2d/display/DisplayObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1933,9 +1933,6 @@ class DisplayObject extends EventDispatcher
*/
_$postProperty ()
{
this._$posted = true;
this._$updated = false;

const message = {
"command": "setProperty",
"instanceId": this._$instanceId,
Expand Down
3 changes: 3 additions & 0 deletions src/next2d/display/DisplayObjectContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2370,5 +2370,8 @@ class DisplayObjectContainer extends InteractiveObject
.postMessage(message, options);

Util.$poolArray(options);

this._$posted = true;
this._$updated = false;
}
}
28 changes: 17 additions & 11 deletions src/next2d/display/Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,9 @@ class Graphics

// cache current buffer
const currentAttachment = context.frameBuffer.currentAttachment;
if (xMin > currentAttachment.width || yMin > currentAttachment.height) {
if (xMin > currentAttachment.width
|| yMin > currentAttachment.height
) {
return;
}

Expand Down Expand Up @@ -1619,21 +1621,25 @@ class Graphics
*/
_$restart ()
{
if (this._$displayObject
&& !this._$displayObject._$isUpdated()
) {
this._$displayObject._$doChanged();
Util.$isUpdated = true;
if (this._$displayObject) {

this._$displayObject._$posted = false;
this._$buffer = null;

Util
.$cacheStore()
.removeCache(this._$displayObject._$instanceId);
if (!this._$displayObject._$isUpdated()) {

this._$displayObject._$doChanged();
Util.$isUpdated = true;

if (this._$displayObject._$characterId) {
Util
.$cacheStore()
.removeCache(this._$displayObject._$characterId);
.removeCache(this._$displayObject._$instanceId);

if (this._$displayObject._$characterId) {
Util
.$cacheStore()
.removeCache(this._$displayObject._$characterId);
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/next2d/display/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,5 +592,8 @@ class Shape extends DisplayObject
.postMessage(message);

}

this._$posted = true;
this._$updated = false;
}
}
3 changes: 3 additions & 0 deletions src/next2d/media/Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,5 +1159,8 @@ class Video extends DisplayObject
Util.$rendererWorker.postMessage(message, options);

Util.$poolArray(options);

this._$posted = true;
this._$updated = false;
}
}
38 changes: 16 additions & 22 deletions src/next2d/text/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,6 @@ class TextField extends InteractiveObject
*/
this._$textData = null;

/**
* @type {boolean}
* @default true
* @private
*/
this._$renew = true;

/**
* @type {number}
* @default null
Expand Down Expand Up @@ -961,10 +954,10 @@ class TextField extends InteractiveObject

text = `${text}`;
if (text !== this._$text) {
this._$text = text;
this._$htmlText = "";
this._$cacheText = "";
this._$isHTML = false;
this._$text = text;
this._$htmlText = "";
this._$cacheText = "";
this._$isHTML = false;

if (!this._$textAppending) {
this._$textFormatTable = [];
Expand Down Expand Up @@ -2153,7 +2146,6 @@ class TextField extends InteractiveObject
*/
_$reset ()
{
this._$renew = true;
this._$textData = null;
this._$imageData = null;
this._$textHeight = null;
Expand Down Expand Up @@ -2696,7 +2688,7 @@ class TextField extends InteractiveObject
let texture = cacheStore.get(cacheKeys);

// texture is small or renew
if (this._$renew || this._$isUpdated()) {
if (this._$isUpdated()) {
cacheStore.removeCache(instanceId);
texture = null;
}
Expand All @@ -2708,8 +2700,6 @@ class TextField extends InteractiveObject
const baseWidth = $Math.ceil($Math.abs(baseBounds.xMax - baseBounds.xMin) * xScale);
const baseHeight = $Math.ceil($Math.abs(baseBounds.yMax - baseBounds.yMin) * yScale);

this._$renew = false;

// alpha reset
multiColor[3] = 1;

Expand Down Expand Up @@ -3430,15 +3420,16 @@ class TextField extends InteractiveObject

const message = super._$postProperty();

message.xMin = this._$bounds.xMin;
message.yMin = this._$bounds.yMin;
message.xMax = this._$bounds.xMax;
message.yMax = this._$bounds.yMax;

message.textAreaActive = this._$textAreaActive;
if (this._$renew || this._$isUpdated()) {

this._$renew = false;
const bounds = this._$getBounds(null);
message.xMin = bounds.xMin;
message.yMin = bounds.yMin;
message.xMax = bounds.xMax;
message.yMax = bounds.yMax;
Util.$poolBoundsObject(bounds);

if (this._$isUpdated()) {

message.textData = this._$getTextData();
message.scrollV = this.scrollV;
Expand Down Expand Up @@ -3472,5 +3463,8 @@ class TextField extends InteractiveObject
Util
.$rendererWorker
.postMessage(message);

this._$posted = true;
this._$updated = false;
}
}
14 changes: 9 additions & 5 deletions src/player/Next2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,20 @@ class Next2D
{
const player = this._$player;

player._$loadStatus = Player.LOAD_END;
player._$mode = "create";
player._$stage.frameRate = fps | 0;

// setup
player.width = width | 0;
player.height = height | 0;
player.setOptions(options);

return player._$stage.addChild(new Sprite());
player._$loadStatus = Player.LOAD_END;
player._$mode = "create";
player._$stage._$frameRate = fps | 0;

const root = player._$stage.addChild(new Sprite());

player.play();

return root;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/renderer/RenderBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ class CommandController
* @param {HTMLCanvasElement} canvas
* @param {number} [samples=4]
* @param {number} [devicePixelRatio=2]
* @param {boolean} [is_safari=false]
* @return {void}
* @method
* @public
*/
initialize (canvas, samples = 4, devicePixelRatio = 2)
initialize (canvas, samples = 4, devicePixelRatio = 2, is_safari = false)
{
// update
$devicePixelRatio = devicePixelRatio;
Util.$isSafari = !!is_safari;

const player = Util.$renderPlayer;
player._$samples = samples;
Expand Down
25 changes: 8 additions & 17 deletions src/renderer/RenderTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ class RenderTextField extends RenderDisplayObject
{
super();

/**
* @type {boolean}
* @default false
* @private
*/
this._$renew = false;

/**
* @type {boolean}
* @default false
Expand Down Expand Up @@ -367,7 +360,6 @@ class RenderTextField extends RenderDisplayObject
}

const baseBounds = this._$getBounds(null);

baseBounds.xMin -= this._$thickness;
baseBounds.xMax += this._$thickness;
baseBounds.yMin -= this._$thickness;
Expand Down Expand Up @@ -469,7 +461,7 @@ class RenderTextField extends RenderDisplayObject
let texture = cacheStore.get(cacheKeys);

// texture is small or renew
if (this._$renew) {
if (this._$isUpdated()) {
cacheStore.removeCache(instanceId);
texture = null;
}
Expand All @@ -481,8 +473,6 @@ class RenderTextField extends RenderDisplayObject
const baseWidth = $Math.ceil($Math.abs(baseBounds.xMax - baseBounds.xMin) * xScale);
const baseHeight = $Math.ceil($Math.abs(baseBounds.yMax - baseBounds.yMin) * yScale);

this._$renew = false;

// alpha reset
multiColor[3] = 1;

Expand Down Expand Up @@ -650,17 +640,17 @@ class RenderTextField extends RenderDisplayObject

let yOffset = 0;
if (this._$verticalAlign !== TextFormatVerticalAlign.TOP
&& this.height > this.textHeight
&& this.height > this._$textHeight
) {

switch (this._$verticalAlign) {

case TextFormatVerticalAlign.MIDDLE:
yOffset = (this.height - this.textHeight + 2) / 2;
yOffset = (this.height - this._$textHeight + 2) / 2;
break;

case TextFormatVerticalAlign.BOTTOM:
yOffset = this.height - this.textHeight + 2;
yOffset = this.height - this._$textHeight + 2;
break;

}
Expand Down Expand Up @@ -710,7 +700,7 @@ class RenderTextField extends RenderDisplayObject

currentV++;

if (this.scrollV > currentV) {
if (this._$scrollV > currentV) {
continue;
}

Expand Down Expand Up @@ -740,7 +730,7 @@ class RenderTextField extends RenderDisplayObject

case TextMode.TEXT:
{
if (this.scrollV > currentV) {
if (this._$scrollV > currentV) {
continue;
}

Expand Down Expand Up @@ -834,6 +824,8 @@ class RenderTextField extends RenderDisplayObject
this._$yMax = 0;
this._$textData = null;

this._$textAreaActive = false;

super._$remove();

Util.$textFields.push(this);
Expand All @@ -852,7 +844,6 @@ class RenderTextField extends RenderDisplayObject
// update property
this._$textAreaActive = !!object.textAreaActive;

this._$renew = true;
this._$textData = object.textData;
this._$wordWrap = !!object.wordWrap;

Expand Down

0 comments on commit ac59dda

Please sign in to comment.