Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1133007 - (LayerScope) Prevent sending duplicate texture image #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified css/layers-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/slider-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/slider-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/texture-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/zoom-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/zoom-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/zoom-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 52 additions & 26 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,54 +91,55 @@ LayerScope.Frame = function (stamp) {

// Don't append any functions to this object, since we will
// serialize/deserialize this object into JSON string.
LayerScope.TextureNode = function(name, target, texID, layerRef, contextRef) {
LayerScope.TextureNode = function(name, target, layerRef, contextRef, contentID) {
this.name = name;
this.target = target;

// Don't keep layer or texture object here. Instead, keep id of them.
// So that we don't need relink action in LayerScope.Storage.load.
this.layerRef = layerRef;
this.contextRef = contextRef;
this.texID = texID;
this.contentID = contentID;
}

LayerScope.TexturePool = function () {
LayerScope.ImageDataPool = function () {
this._cacheImages = {};
this._ctx = $("<canvas>").width(1).height(1)[0].getContext("2d");
};

LayerScope.TexturePool.prototype.findTexture = function (hash) {
if (!hash) {
LayerScope.ImageDataPool.prototype.findImage = function (key) {
if (key == null || key == undefined) {
console.log("ImageDataPool invalid key");
return null;
}

console.assert(hash in this._cacheImages, "Try to find a key which does not exist.");
return this._cacheImages[hash];
console.assert(key in this._cacheImages, "Try to find a key which does not exist.");
return this._cacheImages[key];
}

LayerScope.TexturePool.prototype.addTexture = function (key, value, width, height) {
LayerScope.ImageDataPool.prototype.addImageData = function (key, value) {
if (this._cacheImages[key] !== undefined) {
console.log("TexturePool hash collision detected");
console.log("ImageDataPool hash collision detected");
return;
}
var texture = { imageData: value, width: width, height: height };
this._cacheImages[key] = texture;
}

LayerScope.TexturePool.prototype.createTexture = function (source, width, height, format, stride) {
var hash = sha1.hash(source);
this._cacheImages[key] = value;
}

LayerScope.ImageDataPool.prototype.createTexture = function (key, source, width, height, format, stride) {
if (width == 0 || height == 0) {
console.log("Viewer receive invalid texture info.");
console.log("ImageDataPool.createTexture: invalid value.");
return null;
}

if (key === null ||key === undefined) {
console.log("ImageDataPool.createTexture: invalid key.");
return null;
}
var texture = {};
texture.width = width;
texture.height = height;

// Cache matchs.
if (hash in this._cacheImages) {
return hash;
if (key in this._cacheImages) {
return;
}

// Generate a new cache image for this source.
Expand All @@ -152,13 +153,13 @@ LayerScope.TexturePool.prototype.createTexture = function (source, width, height
}

// Create a buffer.
texture.imageData = this._ctx.createImageData(width, height);
var imageData = this._ctx.createImageData(width, height);

// Fill this buffer by source image.
if (stride == width * 4) {
texture.imageData.data.set(source);
imageData.data.set(source);
} else {
let dstData = texture.imageDaga.data;
let dstData = imageDaga.data;
for (let j = 0; j < height; j++) {
for (let i = 0; i < width; i++) {
dstData[j * width * 4 + i * 4 + 0] = source[j * stride + i * 4 + 0];
Expand All @@ -168,12 +169,10 @@ LayerScope.TexturePool.prototype.createTexture = function (source, width, height
}
}
}
this._cacheImages[hash] = texture;

return hash;
this._cacheImages[key] = imageData;
};


LayerScope.TaskChain = {
_tasks: [],
_currentTask: 0,
Expand Down Expand Up @@ -213,3 +212,30 @@ LayerScope.TaskChain = {
this._currentTask = 0;
}
};

LayerScope.MessageCenter = {
_handlers: {},

subscribe: function RMC_subscribe(msgName, o) {
if (!(msgName in this._handlers)) {
this._handlers[msgName] = [];
}

if (!(o in this._handlers[msgName])) {
this._handlers[msgName].push(o);
}
},

fire: function RMC_fire(msgName, value) {
if (!(msgName in this._handlers)) {
return;
}

let handlers = this._handlers[msgName];
for (let i = 0; i < handlers.length; i++) {
let o = handlers[i];
o.notify(msgName, value);
}
}
};

34 changes: 22 additions & 12 deletions js/dataprocesser.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,32 @@ LayerScope.ProtoDataProcesser = {
high: pcolor.layerref.getHighBitsUnsigned()}
};
},
_getRefTexData: function R_getRefImage(preftexture) {
let tn = new LayerScope.TextureNode("name",
"1",
preftexture.layerref,
"2D",
preftexture.contentid);

return tn;
},

/**
* Convert raw data buffer into a image
* @param {ArrayBuffer} data The raw ArrayBuffer
* @param {object} texData Texture data object
* @return {object} Image data
*/
_getTexData: function R_getImage(ptexture) {
// Create a texture in texture pool, if need.
var source = new Uint8Array(ptexture.data.toArrayBuffer());
let key = this._graph.texturePool.createTexture(source,
ptexture.width,
ptexture.height,
ptexture.dataformat,
ptexture.stride);
if (!!ptexture.data) {
var source = new Uint8Array(ptexture.data.toArrayBuffer());
this._graph.imageDataPool.createTexture(ptexture.contentid,
source,
ptexture.width,
ptexture.height,
ptexture.dataformat,
ptexture.stride);
}

// Create a texture node
let layerRef = {
Expand All @@ -157,12 +169,10 @@ LayerScope.ProtoDataProcesser = {
};
let tn = new LayerScope.TextureNode(ptexture.name,
ptexture.target,
key,
layerRef,
ptexture.glcontext);
ptexture.layerref,
ptexture.glcontext,
ptexture.contentid);

// Associate texure node with texture pool by key.
tn.texID = key;
return tn;
},
/**
Expand Down
Loading