Merge pull request #5077 from tschaub/more-immediate

Make immediate API uniformly synchronous.
This commit is contained in:
Tim Schaub
2016-03-18 18:00:33 -06:00
12 changed files with 12 additions and 150 deletions

View File

@@ -31,6 +31,8 @@ map.on('postcompose', function(event) {
});
```
A final change to the immediate rendering API is that `vectorContext.drawFeature()` calls are not "immediate" as well. The drawing now occurs synchronously. This means that any `zIndex` in a style passed to `drawFeature()` will be ignored. To achieve `zIndex` ordering, order your calls to `drawFeature()` instead.
#### Removal of `ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK`
The `ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK` define has been removed. The size of the cache can now be defined on every tile based `ol.source`:

View File

@@ -20,9 +20,6 @@ goog.require('ol.vec.Mat4');
* new ol.geom.Polygon([[[0, 0], [100, 100], [100, 0], [0, 0]]]));
* ```
*
* Note that {@link ol.render.canvas.Immediate#drawAsync} and
* {@link ol.render.canvas.Immediate#drawFeature} cannot be used.
*
* @param {CanvasRenderingContext2D} context Canvas context.
* @param {olx.render.ToContextOptions=} opt_options Options.
* @return {ol.render.canvas.Immediate} Canvas Immediate.

View File

@@ -39,13 +39,6 @@ goog.require('ol.vec.Mat4');
ol.render.canvas.Immediate = function(context, pixelRatio, extent, transform, viewRotation) {
goog.base(this);
/**
* @private
* @type {!Object.<string,
* Array.<function(ol.render.canvas.Immediate)>>}
*/
this.callbacksByZIndex_ = {};
/**
* @private
* @type {CanvasRenderingContext2D}
@@ -402,26 +395,6 @@ ol.render.canvas.Immediate.prototype.drawRings_ = function(flatCoordinates, offs
};
/**
* Register a function to be called for rendering at a given zIndex. The
* function will be called asynchronously. The callback will receive a
* reference to {@link ol.render.canvas.Immediate} context for drawing.
*
* @param {number} zIndex Z index.
* @param {function(ol.render.canvas.Immediate)} callback Callback.
* @api
*/
ol.render.canvas.Immediate.prototype.drawAsync = function(zIndex, callback) {
var zIndexKey = zIndex.toString();
var callbacks = this.callbacksByZIndex_[zIndexKey];
if (callbacks !== undefined) {
callbacks.push(callback);
} else {
this.callbacksByZIndex_[zIndexKey] = [callback];
}
};
/**
* Render a circle geometry into the canvas. Rendering is immediate and uses
* the current fill and stroke styles.
@@ -517,11 +490,10 @@ ol.render.canvas.Immediate.prototype.drawGeometry = function(geometry) {
/**
* Render a feature into the canvas. In order to respect the zIndex of the
* style this method draws asynchronously and thus *after* calls to
* drawXxxxGeometry have been finished, effectively drawing the feature
* *on top* of everything else. You probably should be using an
* {@link ol.layer.Vector} instead of calling this method directly.
* Render a feature into the canvas. Note that any `zIndex` on the provided
* style will be ignored - features are rendered immediately in the order that
* this method is called. If you need `zIndex` support, you should be using an
* {@link ol.layer.Vector} instead.
*
* @param {ol.Feature} feature Feature.
* @param {ol.style.Style} style Style.
@@ -533,17 +505,9 @@ ol.render.canvas.Immediate.prototype.drawFeature = function(feature, style) {
!ol.extent.intersects(this.extent_, geometry.getExtent())) {
return;
}
var zIndex = style.getZIndex();
if (zIndex === undefined) {
zIndex = 0;
}
this.drawAsync(zIndex, function(render) {
render.setFillStrokeStyle(style.getFill(), style.getStroke());
render.setImageStyle(style.getImage());
render.setTextStyle(style.getText());
goog.asserts.assert(geometry, 'geometry must be truthy');
render.drawGeometry(geometry);
});
this.setStyle(style);
goog.asserts.assert(geometry, 'geometry must be truthy');
this.drawGeometry(geometry);
};
@@ -734,23 +698,6 @@ ol.render.canvas.Immediate.prototype.drawMultiPolygon = function(geometry) {
};
/**
* FIXME: empty description for jsdoc
*/
ol.render.canvas.Immediate.prototype.flush = function() {
/** @type {Array.<number>} */
var zs = Object.keys(this.callbacksByZIndex_).map(Number);
zs.sort(ol.array.numberSafeCompareFunction);
var i, ii, callbacks, j, jj;
for (i = 0, ii = zs.length; i < ii; ++i) {
callbacks = this.callbacksByZIndex_[zs[i].toString()];
for (j = 0, jj = callbacks.length; j < jj; ++j) {
callbacks[j](this);
}
}
};
/**
* @param {ol.render.canvas.FillState} fillState Fill state.
* @private

View File

@@ -12,13 +12,6 @@ ol.render.VectorContext = function() {
};
/**
* @param {number} zIndex Z index.
* @param {function(ol.render.VectorContext)} callback Callback.
*/
ol.render.VectorContext.prototype.drawAsync = goog.abstractMethod;
/**
* Render a geometry.
*

View File

@@ -1,6 +1,5 @@
goog.provide('ol.render.webgl.Immediate');
goog.require('goog.asserts');
goog.require('ol.array');
goog.require('ol.extent');
goog.require('ol.geom.GeometryType');
goog.require('ol.render.VectorContext');
@@ -64,52 +63,10 @@ ol.render.webgl.Immediate = function(context, center, resolution, rotation, size
*/
this.imageStyle_ = null;
/**
* @private
* @type {!Object.<string,
* Array.<function(ol.render.webgl.Immediate)>>}
*/
this.callbacksByZIndex_ = {};
};
goog.inherits(ol.render.webgl.Immediate, ol.render.VectorContext);
/**
* FIXME: empty description for jsdoc
*/
ol.render.webgl.Immediate.prototype.flush = function() {
/** @type {Array.<number>} */
var zs = Object.keys(this.callbacksByZIndex_).map(Number);
zs.sort(ol.array.numberSafeCompareFunction);
var i, ii, callbacks, j, jj;
for (i = 0, ii = zs.length; i < ii; ++i) {
callbacks = this.callbacksByZIndex_[zs[i].toString()];
for (j = 0, jj = callbacks.length; j < jj; ++j) {
callbacks[j](this);
}
}
};
/**
* Register a function to be called for rendering at a given zIndex. The
* function will be called asynchronously. The callback will receive a
* reference to {@link ol.render.canvas.Immediate} context for drawing.
* @param {number} zIndex Z index.
* @param {function(ol.render.webgl.Immediate)} callback Callback.
* @api
*/
ol.render.webgl.Immediate.prototype.drawAsync = function(zIndex, callback) {
var zIndexKey = zIndex.toString();
var callbacks = this.callbacksByZIndex_[zIndexKey];
if (callbacks !== undefined) {
callbacks.push(callback);
} else {
this.callbacksByZIndex_[zIndexKey] = [callback];
}
};
/**
* Set the rendering style. Note that since this is an immediate rendering API,
* any `zIndex` on the provided style will be ignored.
@@ -157,15 +114,9 @@ ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) {
!ol.extent.intersects(this.extent_, geometry.getExtent())) {
return;
}
var zIndex = style.getZIndex();
if (zIndex === undefined) {
zIndex = 0;
}
this.drawAsync(zIndex, function(render) {
render.setStyle(style);
goog.asserts.assert(geometry, 'geometry must be truthy');
render.drawGeometry(geometry);
});
this.setStyle(style);
goog.asserts.assert(geometry, 'geometry must be truthy');
this.drawGeometry(geometry);
};

View File

@@ -245,12 +245,6 @@ ol.render.webgl.ImageReplay.prototype.getDeleteResourcesFunction = function(cont
};
/**
* @inheritDoc
*/
ol.render.webgl.ImageReplay.prototype.drawAsync = goog.abstractMethod;
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.

View File

@@ -127,7 +127,6 @@ ol.renderer.canvas.Layer.prototype.dispatchComposeEvent_ = function(type, contex
var composeEvent = new ol.render.Event(type, layer, render, frameState,
context, null);
layer.dispatchEvent(composeEvent);
render.flush();
ol.render.canvas.rotateAtOffset(context, rotation, width / 2, height / 2);
}
};

View File

@@ -138,8 +138,6 @@ ol.renderer.canvas.Map.prototype.dispatchComposeEvent_ = function(type, frameSta
var composeEvent = new ol.render.Event(type, map, vectorContext,
frameState, context, null);
map.dispatchEvent(composeEvent);
vectorContext.flush();
}
};

View File

@@ -138,7 +138,6 @@ ol.renderer.dom.Map.prototype.dispatchComposeEvent_ = function(type, frameState)
var composeEvent = new ol.render.Event(type, map, vectorContext,
frameState, context, null);
map.dispatchEvent(composeEvent);
vectorContext.flush();
}
};

View File

@@ -175,7 +175,6 @@ ol.renderer.dom.VectorLayer.prototype.dispatchEvent_ = function(type, frameState
var event = new ol.render.Event(type, layer, render, frameState,
context, null);
layer.dispatchEvent(event);
render.flush();
}
};

View File

@@ -288,8 +288,6 @@ ol.renderer.webgl.Map.prototype.dispatchComposeEvent_ = function(type, frameStat
var composeEvent = new ol.render.Event(type, map, vectorContext,
frameState, null, context);
map.dispatchEvent(composeEvent);
vectorContext.flush();
}
};

View File

@@ -21,21 +21,6 @@ describe('ol.render.canvas.Immediate', function() {
});
});
describe('#flush', function() {
it('calls callback in correct z-order', function() {
var canvas = new ol.render.canvas.Immediate();
var log = [];
canvas.drawAsync(11, function() {
log.push(11);
});
canvas.drawAsync(5, function() {
log.push(5);
});
canvas.flush();
expect(log).to.eql([5, 11]);
});
});
describe('#setStyle()', function() {
it('calls the more specific methods with style parts', function() {
var context = new ol.render.canvas.Immediate();