OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * The overlay displaying the image. | 8 * The overlay displaying the image. |
9 * | 9 * |
10 * @param {HTMLElement} container The container element. | 10 * @param {HTMLElement} container The container element. |
11 * @param {Viewport} viewport The viewport. | 11 * @param {Viewport} viewport The viewport. |
12 * @constructor | 12 * @constructor |
13 * @extends {ImageBuffer.Overlay} | 13 * @extends {ImageBuffer.Overlay} |
14 */ | 14 */ |
15 function ImageView(container, viewport) { | 15 function ImageView(container, viewport) { |
16 ImageBuffer.Overlay.call(this); | 16 ImageBuffer.Overlay.call(this); |
17 | 17 |
18 this.container_ = container; | 18 this.container_ = container; |
19 this.viewport_ = viewport; | 19 this.viewport_ = viewport; |
20 this.document_ = container.ownerDocument; | 20 this.document_ = container.ownerDocument; |
21 this.contentGeneration_ = 0; | 21 this.contentGeneration_ = 0; |
22 this.displayedContentGeneration_ = 0; | 22 this.displayedContentGeneration_ = 0; |
23 this.displayedViewportGeneration_ = 0; | |
24 | 23 |
25 this.imageLoader_ = new ImageUtil.ImageLoader(this.document_); | 24 this.imageLoader_ = new ImageUtil.ImageLoader(this.document_); |
26 // We have a separate image loader for prefetch which does not get cancelled | 25 // We have a separate image loader for prefetch which does not get cancelled |
27 // when the selection changes. | 26 // when the selection changes. |
28 this.prefetchLoader_ = new ImageUtil.ImageLoader(this.document_); | 27 this.prefetchLoader_ = new ImageUtil.ImageLoader(this.document_); |
29 | 28 |
30 // The content cache is used for prefetching the next image when going | 29 // The content cache is used for prefetching the next image when going |
31 // through the images sequentially. The real life photos can be large | 30 // through the images sequentially. The real life photos can be large |
32 // (18Mpix = 72Mb pixel array) so we want only the minimum amount of caching. | 31 // (18Mpix = 72Mb pixel array) so we want only the minimum amount of caching. |
33 this.contentCache_ = new ImageView.Cache(2); | 32 this.contentCache_ = new ImageView.Cache(2); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 ImageView.prototype.getZIndex = function() { return -1; }; | 96 ImageView.prototype.getZIndex = function() { return -1; }; |
98 | 97 |
99 /** | 98 /** |
100 * @override | 99 * @override |
101 */ | 100 */ |
102 ImageView.prototype.draw = function() { | 101 ImageView.prototype.draw = function() { |
103 if (!this.contentCanvas_) // Do nothing if the image content is not set. | 102 if (!this.contentCanvas_) // Do nothing if the image content is not set. |
104 return; | 103 return; |
105 | 104 |
106 var forceRepaint = false; | 105 var forceRepaint = false; |
107 | 106 var deviceBounds = this.viewport_.getDeviceBounds(); |
108 if (this.displayedViewportGeneration_ !== | 107 if (deviceBounds.width != this.screenImage_.width || |
109 this.viewport_.getCacheGeneration()) { | 108 deviceBounds.height != this.screenImage_.height) { |
110 this.displayedViewportGeneration_ = this.viewport_.getCacheGeneration(); | |
111 | |
112 this.setupDeviceBuffer(this.screenImage_); | 109 this.setupDeviceBuffer(this.screenImage_); |
113 | |
114 forceRepaint = true; | 110 forceRepaint = true; |
115 } | 111 } |
116 | 112 |
117 if (forceRepaint || | 113 if (forceRepaint || |
118 this.displayedContentGeneration_ !== this.contentGeneration_) { | 114 this.displayedContentGeneration_ !== this.contentGeneration_) { |
119 this.displayedContentGeneration_ = this.contentGeneration_; | 115 this.displayedContentGeneration_ = this.contentGeneration_; |
120 | |
121 ImageUtil.trace.resetTimer('paint'); | 116 ImageUtil.trace.resetTimer('paint'); |
122 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_)); | 117 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_)); |
123 ImageUtil.trace.reportTimer('paint'); | 118 ImageUtil.trace.reportTimer('paint'); |
124 } | 119 } |
125 }; | 120 }; |
126 | 121 |
127 /** | 122 /** |
128 * Applies the viewport change that does not affect the screen cache size (zoom | 123 * Applies the viewport change that does not affect the screen cache size (zoom |
129 * change or offset change) with animation. | 124 * change or offset change) with animation. |
130 */ | 125 */ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 170 |
176 /** | 171 /** |
177 * Copies an image fragment from a full resolution canvas to a device resolution | 172 * Copies an image fragment from a full resolution canvas to a device resolution |
178 * canvas. | 173 * canvas. |
179 * | 174 * |
180 * @param {HTMLCanvasElement} canvas Canvas containing whole image. The canvas | 175 * @param {HTMLCanvasElement} canvas Canvas containing whole image. The canvas |
181 * may not be full resolution (scaled). | 176 * may not be full resolution (scaled). |
182 * @param {Rect} imageRect Rectangle region of the canvas to be rendered. | 177 * @param {Rect} imageRect Rectangle region of the canvas to be rendered. |
183 */ | 178 */ |
184 ImageView.prototype.paintDeviceRect = function(canvas, imageRect) { | 179 ImageView.prototype.paintDeviceRect = function(canvas, imageRect) { |
185 // Check canvas size. | |
186 var deviceBounds = this.viewport_.getDeviceBounds(); | |
187 if (this.screenImage_.width != deviceBounds.width || | |
188 this.screenImage_.height != deviceBounds.height) { | |
189 console.error('The size of canvas is invalid.', (new Error).stack); | |
190 return; | |
191 } | |
192 | |
193 // Map the rectangle in full resolution image to the rectangle in the device | 180 // Map the rectangle in full resolution image to the rectangle in the device |
194 // canvas. | 181 // canvas. |
| 182 var deviceBounds = this.viewport_.getDeviceBounds(); |
195 var scaleX = deviceBounds.width / canvas.width; | 183 var scaleX = deviceBounds.width / canvas.width; |
196 var scaleY = deviceBounds.height / canvas.height; | 184 var scaleY = deviceBounds.height / canvas.height; |
197 var deviceRect = new Rect( | 185 var deviceRect = new Rect( |
198 imageRect.left * scaleX, | 186 imageRect.left * scaleX, |
199 imageRect.top * scaleY, | 187 imageRect.top * scaleY, |
200 imageRect.width * scaleX, | 188 imageRect.width * scaleX, |
201 imageRect.height * scaleY); | 189 imageRect.height * scaleY); |
202 | 190 |
203 Rect.drawImage( | 191 Rect.drawImage( |
204 this.screenImage_.getContext('2d'), canvas, deviceRect, imageRect); | 192 this.screenImage_.getContext('2d'), canvas, deviceRect, imageRect); |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 }; | 954 }; |
967 | 955 |
968 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; | 956 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; |
969 | 957 |
970 /** | 958 /** |
971 * @override | 959 * @override |
972 */ | 960 */ |
973 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { | 961 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { |
974 return viewport.getInverseTransformForRotatedImage(this.orientation_); | 962 return viewport.getInverseTransformForRotatedImage(this.orientation_); |
975 }; | 963 }; |
OLD | NEW |