Refactors Cache into PDFPageViewBuffer
This commit is contained in:
parent
22c62685b0
commit
b930228788
@ -25,7 +25,6 @@
|
|||||||
* @property {number} scale - The page scale display.
|
* @property {number} scale - The page scale display.
|
||||||
* @property {PageViewport} defaultViewport - The page viewport.
|
* @property {PageViewport} defaultViewport - The page viewport.
|
||||||
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
||||||
* @property {Cache} cache - The page cache.
|
|
||||||
* @property {IPDFTextLayerFactory} textLayerFactory
|
* @property {IPDFTextLayerFactory} textLayerFactory
|
||||||
* @property {IPDFAnnotationsLayerFactory} annotationsLayerFactory
|
* @property {IPDFAnnotationsLayerFactory} annotationsLayerFactory
|
||||||
*/
|
*/
|
||||||
@ -45,7 +44,6 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
var scale = options.scale;
|
var scale = options.scale;
|
||||||
var defaultViewport = options.defaultViewport;
|
var defaultViewport = options.defaultViewport;
|
||||||
var renderingQueue = options.renderingQueue;
|
var renderingQueue = options.renderingQueue;
|
||||||
var cache = options.cache;
|
|
||||||
var textLayerFactory = options.textLayerFactory;
|
var textLayerFactory = options.textLayerFactory;
|
||||||
var annotationsLayerFactory = options.annotationsLayerFactory;
|
var annotationsLayerFactory = options.annotationsLayerFactory;
|
||||||
|
|
||||||
@ -59,13 +57,15 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
this.hasRestrictedScaling = false;
|
this.hasRestrictedScaling = false;
|
||||||
|
|
||||||
this.renderingQueue = renderingQueue;
|
this.renderingQueue = renderingQueue;
|
||||||
this.cache = cache;
|
|
||||||
this.textLayerFactory = textLayerFactory;
|
this.textLayerFactory = textLayerFactory;
|
||||||
this.annotationsLayerFactory = annotationsLayerFactory;
|
this.annotationsLayerFactory = annotationsLayerFactory;
|
||||||
|
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
this.resume = null;
|
this.resume = null;
|
||||||
|
|
||||||
|
this.onBeforeDraw = null;
|
||||||
|
this.onAfterDraw = null;
|
||||||
|
|
||||||
this.textLayer = null;
|
this.textLayer = null;
|
||||||
|
|
||||||
this.zoomLayer = null;
|
this.zoomLayer = null;
|
||||||
@ -447,9 +447,9 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
}
|
}
|
||||||
div.setAttribute('data-loaded', true);
|
div.setAttribute('data-loaded', true);
|
||||||
|
|
||||||
// Add the page to the cache at the start of drawing. That way it can be
|
if (self.onBeforeDraw) {
|
||||||
// evicted from the cache and destroyed even if we pause its rendering.
|
self.onBeforeDraw();
|
||||||
this.cache.push(this);
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
beforePrint: function PDFPageView_beforePrint() {
|
beforePrint: function PDFPageView_beforePrint() {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/*globals watchScroll, Cache, DEFAULT_CACHE_SIZE, PDFPageView, UNKNOWN_SCALE,
|
/*globals watchScroll, PDFPageView, UNKNOWN_SCALE,
|
||||||
SCROLLBAR_PADDING, VERTICAL_PADDING, MAX_AUTO_SCALE, CSS_UNITS,
|
SCROLLBAR_PADDING, VERTICAL_PADDING, MAX_AUTO_SCALE, CSS_UNITS,
|
||||||
DEFAULT_SCALE, scrollIntoView, getVisibleElements, RenderingStates,
|
DEFAULT_SCALE, scrollIntoView, getVisibleElements, RenderingStates,
|
||||||
PDFJS, Promise, TextLayerBuilder, PDFRenderingQueue,
|
PDFJS, Promise, TextLayerBuilder, PDFRenderingQueue,
|
||||||
@ -30,6 +30,7 @@ var PresentationModeState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var IGNORE_CURRENT_POSITION_ON_ZOOM = false;
|
var IGNORE_CURRENT_POSITION_ON_ZOOM = false;
|
||||||
|
var DEFAULT_CACHE_SIZE = 10;
|
||||||
|
|
||||||
//#include pdf_rendering_queue.js
|
//#include pdf_rendering_queue.js
|
||||||
//#include pdf_page_view.js
|
//#include pdf_page_view.js
|
||||||
@ -52,6 +53,26 @@ var IGNORE_CURRENT_POSITION_ON_ZOOM = false;
|
|||||||
* @implements {IRenderableView}
|
* @implements {IRenderableView}
|
||||||
*/
|
*/
|
||||||
var PDFViewer = (function pdfViewer() {
|
var PDFViewer = (function pdfViewer() {
|
||||||
|
function PDFPageViewBuffer(size) {
|
||||||
|
var data = [];
|
||||||
|
this.push = function cachePush(view) {
|
||||||
|
var i = data.indexOf(view);
|
||||||
|
if (i >= 0) {
|
||||||
|
data.splice(i, 1);
|
||||||
|
}
|
||||||
|
data.push(view);
|
||||||
|
if (data.length > size) {
|
||||||
|
data.shift().destroy();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.resize = function (newSize) {
|
||||||
|
size = newSize;
|
||||||
|
while (data.length > size) {
|
||||||
|
data.shift().destroy();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructs PDFViewer
|
* @constructs PDFViewer
|
||||||
* @param {PDFViewerOptions} options
|
* @param {PDFViewerOptions} options
|
||||||
@ -212,7 +233,13 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
});
|
});
|
||||||
this.onePageRendered = onePageRendered;
|
this.onePageRendered = onePageRendered;
|
||||||
|
|
||||||
var bindOnAfterDraw = function (pageView) {
|
var bindOnAfterAndBeforeDraw = function (pageView) {
|
||||||
|
pageView.onBeforeDraw = function pdfViewLoadOnBeforeDraw() {
|
||||||
|
// Add the page to the buffer at the start of drawing. That way it can
|
||||||
|
// be evicted from the buffer and destroyed even if we pause its
|
||||||
|
// rendering.
|
||||||
|
self._buffer.push(this);
|
||||||
|
};
|
||||||
// when page is painted, using the image as thumbnail base
|
// when page is painted, using the image as thumbnail base
|
||||||
pageView.onAfterDraw = function pdfViewLoadOnAfterDraw() {
|
pageView.onAfterDraw = function pdfViewLoadOnAfterDraw() {
|
||||||
if (!isOnePageRenderedResolved) {
|
if (!isOnePageRenderedResolved) {
|
||||||
@ -246,11 +273,10 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
scale: scale,
|
scale: scale,
|
||||||
defaultViewport: viewport.clone(),
|
defaultViewport: viewport.clone(),
|
||||||
renderingQueue: this.renderingQueue,
|
renderingQueue: this.renderingQueue,
|
||||||
cache: this.cache,
|
|
||||||
textLayerFactory: textLayerFactory,
|
textLayerFactory: textLayerFactory,
|
||||||
annotationsLayerFactory: this
|
annotationsLayerFactory: this
|
||||||
});
|
});
|
||||||
bindOnAfterDraw(pageView);
|
bindOnAfterAndBeforeDraw(pageView);
|
||||||
this.pages.push(pageView);
|
this.pages.push(pageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,11 +317,11 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_resetView: function () {
|
_resetView: function () {
|
||||||
this.cache = new Cache(DEFAULT_CACHE_SIZE);
|
|
||||||
this.pages = [];
|
this.pages = [];
|
||||||
this._currentPageNumber = 1;
|
this._currentPageNumber = 1;
|
||||||
this._currentScale = UNKNOWN_SCALE;
|
this._currentScale = UNKNOWN_SCALE;
|
||||||
this._currentScaleValue = null;
|
this._currentScaleValue = null;
|
||||||
|
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
|
||||||
this.location = null;
|
this.location = null;
|
||||||
this._pagesRotation = 0;
|
this._pagesRotation = 0;
|
||||||
this._pagesRequests = [];
|
this._pagesRequests = [];
|
||||||
@ -538,7 +564,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
|
|
||||||
var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE,
|
var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE,
|
||||||
2 * visiblePages.length + 1);
|
2 * visiblePages.length + 1);
|
||||||
this.cache.resize(suggestedCacheSize);
|
this._buffer.resize(suggestedCacheSize);
|
||||||
|
|
||||||
this.renderingQueue.renderHighestPriority(visible);
|
this.renderingQueue.renderHighestPriority(visible);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ var UNKNOWN_SCALE = 0;
|
|||||||
var MAX_AUTO_SCALE = 1.25;
|
var MAX_AUTO_SCALE = 1.25;
|
||||||
var SCROLLBAR_PADDING = 40;
|
var SCROLLBAR_PADDING = 40;
|
||||||
var VERTICAL_PADDING = 5;
|
var VERTICAL_PADDING = 5;
|
||||||
var DEFAULT_CACHE_SIZE = 10;
|
|
||||||
|
|
||||||
// optimised CSS custom property getter/setter
|
// optimised CSS custom property getter/setter
|
||||||
var CustomStyle = (function CustomStyleClosure() {
|
var CustomStyle = (function CustomStyleClosure() {
|
||||||
@ -349,23 +348,3 @@ var ProgressBar = (function ProgressBarClosure() {
|
|||||||
|
|
||||||
return ProgressBar;
|
return ProgressBar;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var Cache = function cacheCache(size) {
|
|
||||||
var data = [];
|
|
||||||
this.push = function cachePush(view) {
|
|
||||||
var i = data.indexOf(view);
|
|
||||||
if (i >= 0) {
|
|
||||||
data.splice(i, 1);
|
|
||||||
}
|
|
||||||
data.push(view);
|
|
||||||
if (data.length > size) {
|
|
||||||
data.shift().destroy();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.resize = function (newSize) {
|
|
||||||
size = newSize;
|
|
||||||
while (data.length > size) {
|
|
||||||
data.shift().destroy();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user