Only create a worker if an operation is provided
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
goog.provide('ol.raster.IdentityOp');
|
|
||||||
goog.provide('ol.raster.Operation');
|
goog.provide('ol.raster.Operation');
|
||||||
goog.provide('ol.raster.OperationType');
|
goog.provide('ol.raster.OperationType');
|
||||||
|
|
||||||
@@ -31,13 +30,3 @@ ol.raster.OperationType = {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.raster.Operation;
|
ol.raster.Operation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The identity operation. Returns the supplied input data as output.
|
|
||||||
* @param {(Array.<ol.raster.Pixel>|Array.<ImageData>)} inputs Input data.
|
|
||||||
* @return {(Array.<ol.raster.Pixel>|Array.<ImageData>)} The output data.
|
|
||||||
*/
|
|
||||||
ol.raster.IdentityOp = function(inputs) {
|
|
||||||
return inputs;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ goog.require('ol.ext.pixelworks');
|
|||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.layer.Image');
|
goog.require('ol.layer.Image');
|
||||||
goog.require('ol.layer.Tile');
|
goog.require('ol.layer.Tile');
|
||||||
goog.require('ol.raster.IdentityOp');
|
|
||||||
goog.require('ol.raster.OperationType');
|
goog.require('ol.raster.OperationType');
|
||||||
goog.require('ol.renderer.canvas.ImageLayer');
|
goog.require('ol.renderer.canvas.ImageLayer');
|
||||||
goog.require('ol.renderer.canvas.TileLayer');
|
goog.require('ol.renderer.canvas.TileLayer');
|
||||||
@@ -39,6 +38,12 @@ goog.require('ol.source.Tile');
|
|||||||
*/
|
*/
|
||||||
ol.source.Raster = function(options) {
|
ol.source.Raster = function(options) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {*}
|
||||||
|
*/
|
||||||
|
this.worker_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.raster.OperationType}
|
* @type {ol.raster.OperationType}
|
||||||
@@ -46,21 +51,12 @@ ol.source.Raster = function(options) {
|
|||||||
this.operationType_ = goog.isDef(options.operationType) ?
|
this.operationType_ = goog.isDef(options.operationType) ?
|
||||||
options.operationType : ol.raster.OperationType.PIXEL;
|
options.operationType : ol.raster.OperationType.PIXEL;
|
||||||
|
|
||||||
var operation = goog.isDef(options.operation) ?
|
|
||||||
options.operation : ol.raster.IdentityOp;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.threads_ = goog.isDef(options.threads) ? options.threads : 1;
|
this.threads_ = goog.isDef(options.threads) ? options.threads : 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {*}
|
|
||||||
*/
|
|
||||||
this.worker_ = this.createWorker_(operation, options.lib, this.threads_);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<ol.renderer.canvas.Layer>}
|
* @type {Array.<ol.renderer.canvas.Layer>}
|
||||||
@@ -135,44 +131,31 @@ ol.source.Raster = function(options) {
|
|||||||
wantedTiles: {}
|
wantedTiles: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {});
|
||||||
// TODO: pass along any relevant options
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (goog.isDef(options.operation)) {
|
||||||
|
this.setOperation(options.operation, options.lib);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.source.Raster, ol.source.Image);
|
goog.inherits(ol.source.Raster, ol.source.Image);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a worker.
|
* Set the operation.
|
||||||
* @param {ol.raster.Operation} operation The operation.
|
|
||||||
* @param {Object=} opt_lib Optional lib functions.
|
|
||||||
* @param {number=} opt_threads Number of threads.
|
|
||||||
* @return {*} The worker.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ol.source.Raster.prototype.createWorker_ =
|
|
||||||
function(operation, opt_lib, opt_threads) {
|
|
||||||
return new ol.ext.pixelworks.Processor({
|
|
||||||
operation: operation,
|
|
||||||
imageOps: this.operationType_ === ol.raster.OperationType.IMAGE,
|
|
||||||
queue: 1,
|
|
||||||
lib: opt_lib,
|
|
||||||
threads: opt_threads
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the operation.
|
|
||||||
* @param {ol.raster.Operation} operation New operation.
|
* @param {ol.raster.Operation} operation New operation.
|
||||||
* @param {Object=} opt_lib Functions that will be available to operations run
|
* @param {Object=} opt_lib Functions that will be available to operations run
|
||||||
* in a worker.
|
* in a worker.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.source.Raster.prototype.setOperation = function(operation, opt_lib) {
|
ol.source.Raster.prototype.setOperation = function(operation, opt_lib) {
|
||||||
this.worker_ = this.createWorker_(operation, opt_lib, this.threads_);
|
this.worker_ = new ol.ext.pixelworks.Processor({
|
||||||
|
operation: operation,
|
||||||
|
imageOps: this.operationType_ === ol.raster.OperationType.IMAGE,
|
||||||
|
queue: 1,
|
||||||
|
lib: opt_lib,
|
||||||
|
threads: this.threads_
|
||||||
|
});
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user