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. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 * @override | 94 * @override |
95 */ | 95 */ |
96 ImageView.prototype.getZIndex = function() { return -1; }; | 96 ImageView.prototype.getZIndex = function() { return -1; }; |
97 | 97 |
98 /** | 98 /** |
99 * @override | 99 * @override |
100 */ | 100 */ |
101 ImageView.prototype.draw = function() { | 101 ImageView.prototype.draw = function() { |
102 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. |
103 return; | 103 return; |
104 | 104 if (this.setupDeviceBuffer(this.screenImage_) || |
105 var forceRepaint = false; | |
106 var deviceBounds = this.viewport_.getDeviceBounds(); | |
107 if (deviceBounds.width != this.screenImage_.width || | |
108 deviceBounds.height != this.screenImage_.height) { | |
109 this.setupDeviceBuffer(this.screenImage_); | |
110 forceRepaint = true; | |
111 } | |
112 | |
113 if (forceRepaint || | |
114 this.displayedContentGeneration_ !== this.contentGeneration_) { | 105 this.displayedContentGeneration_ !== this.contentGeneration_) { |
115 this.displayedContentGeneration_ = this.contentGeneration_; | 106 this.displayedContentGeneration_ = this.contentGeneration_; |
116 ImageUtil.trace.resetTimer('paint'); | 107 ImageUtil.trace.resetTimer('paint'); |
117 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_)); | 108 this.paintDeviceRect(this.contentCanvas_, new Rect(this.contentCanvas_)); |
118 ImageUtil.trace.reportTimer('paint'); | 109 ImageUtil.trace.reportTimer('paint'); |
119 } | 110 } |
120 }; | 111 }; |
121 | 112 |
122 /** | 113 /** |
123 * Applies the viewport change that does not affect the screen cache size (zoom | 114 * Applies the viewport change that does not affect the screen cache size (zoom |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 var canvas = this.document_.createElement('canvas'); | 195 var canvas = this.document_.createElement('canvas'); |
205 canvas.className = 'image'; | 196 canvas.className = 'image'; |
206 this.container_.appendChild(canvas); | 197 this.container_.appendChild(canvas); |
207 return canvas; | 198 return canvas; |
208 }; | 199 }; |
209 | 200 |
210 /** | 201 /** |
211 * Sets up the canvas as a buffer in the device resolution. | 202 * Sets up the canvas as a buffer in the device resolution. |
212 * | 203 * |
213 * @param {HTMLCanvasElement} canvas The buffer canvas. | 204 * @param {HTMLCanvasElement} canvas The buffer canvas. |
| 205 * @return {boolean} True if the canvas needs to be rendered. |
214 */ | 206 */ |
215 ImageView.prototype.setupDeviceBuffer = function(canvas) { | 207 ImageView.prototype.setupDeviceBuffer = function(canvas) { |
216 // Set the canvas position and size in device pixels. | 208 // Set the canvas position and size in device pixels. |
217 var deviceRect = this.viewport_.getDeviceBounds(); | 209 var deviceRect = this.viewport_.getDeviceBounds(); |
218 if (canvas.width !== deviceRect.width) | 210 var needRepaint = false; |
| 211 if (canvas.width !== deviceRect.width) { |
219 canvas.width = deviceRect.width; | 212 canvas.width = deviceRect.width; |
220 if (canvas.height !== deviceRect.height) | 213 needRepaint = true; |
| 214 } |
| 215 if (canvas.height !== deviceRect.height) { |
221 canvas.height = deviceRect.height; | 216 canvas.height = deviceRect.height; |
| 217 needRepaint = true; |
| 218 } |
222 | 219 |
223 // Center the image. | 220 // Center the image. |
224 var imageBoudns = this.viewport_.getImageElementBoundsOnScreen(); | 221 var imageBounds = this.viewport_.getImageElementBoundsOnScreen(); |
225 canvas.style.left = imageBoudns.left + 'px'; | 222 canvas.style.left = imageBounds.left + 'px'; |
226 canvas.style.top = imageBoudns.top + 'px'; | 223 canvas.style.top = imageBounds.top + 'px'; |
| 224 canvas.style.width = imageBounds.width + 'px'; |
| 225 canvas.style.height = imageBounds.height + 'px'; |
227 | 226 |
228 // Scale the canvas down to screen pixels. | |
229 this.setTransform(canvas); | 227 this.setTransform(canvas); |
| 228 |
| 229 return needRepaint; |
230 }; | 230 }; |
231 | 231 |
232 /** | 232 /** |
233 * @return {ImageData} A new ImageData object with a copy of the content. | 233 * @return {ImageData} A new ImageData object with a copy of the content. |
234 */ | 234 */ |
235 ImageView.prototype.copyScreenImageData = function() { | 235 ImageView.prototype.copyScreenImageData = function() { |
236 return this.screenImage_.getContext('2d').getImageData( | 236 return this.screenImage_.getContext('2d').getImageData( |
237 0, 0, this.screenImage_.width, this.screenImage_.height); | 237 0, 0, this.screenImage_.width, this.screenImage_.height); |
238 }; | 238 }; |
239 | 239 |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 * Obtains the CSS transformation string of the effect. | 820 * Obtains the CSS transformation string of the effect. |
821 * @param {DOMCanvas} element Canvas element to be applied the transforamtion. | 821 * @param {DOMCanvas} element Canvas element to be applied the transforamtion. |
822 * @param {Viewport} viewport Current viewport. | 822 * @param {Viewport} viewport Current viewport. |
823 * @return CSS transformation description. | 823 * @return CSS transformation description. |
824 */ | 824 */ |
825 ImageView.Effect.prototype.transform = function(element, viewport) { | 825 ImageView.Effect.prototype.transform = function(element, viewport) { |
826 throw new Error('Not implemented.'); | 826 throw new Error('Not implemented.'); |
827 }; | 827 }; |
828 | 828 |
829 /** | 829 /** |
830 * Default effect. It is not a no-op as it needs to adjust a canvas scale | 830 * Default effect. |
831 * for devicePixelRatio. | |
832 * | 831 * |
833 * @constructor | 832 * @constructor |
834 * @extends {ImageView.Effect} | 833 * @extends {ImageView.Effect} |
835 */ | 834 */ |
836 ImageView.Effect.None = function() { | 835 ImageView.Effect.None = function() { |
837 ImageView.Effect.call(this, 0, 'easy-out'); | 836 ImageView.Effect.call(this, 0, 'easy-out'); |
838 }; | 837 }; |
839 | 838 |
840 /** | 839 /** |
841 * Inherits from ImageView.Effect. | 840 * Inherits from ImageView.Effect. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 /** | 880 /** |
882 * @override | 881 * @override |
883 */ | 882 */ |
884 ImageView.Effect.Slide.prototype.transform = function(element, viewport) { | 883 ImageView.Effect.Slide.prototype.transform = function(element, viewport) { |
885 return viewport.getShiftTransformation(this.shift_); | 884 return viewport.getShiftTransformation(this.shift_); |
886 }; | 885 }; |
887 | 886 |
888 /** | 887 /** |
889 * Zoom effect. | 888 * Zoom effect. |
890 * | 889 * |
891 * Animates the original rectangle to the target rectangle. Both parameters | 890 * Animates the original rectangle to the target rectangle. |
892 * should be given in device coordinates (accounting for devicePixelRatio). | |
893 * | 891 * |
894 * @param {number} previousImageWidth Width of the full resolution image. | 892 * @param {number} previousImageWidth Width of the full resolution image. |
895 * @param {number} previousImageHeight Hieght of the full resolution image. | 893 * @param {number} previousImageHeight Hieght of the full resolution image. |
896 * @param {Rect} imageCropRect Crop rectangle in the full resolution image. | 894 * @param {Rect} imageCropRect Crop rectangle in the full resolution image. |
897 * @param {number=} opt_duration Duration of the effect. | 895 * @param {number=} opt_duration Duration of the effect. |
898 * @constructor | 896 * @constructor |
899 * @extends {ImageView.Effect} | 897 * @extends {ImageView.Effect} |
900 */ | 898 */ |
901 ImageView.Effect.Zoom = function( | 899 ImageView.Effect.Zoom = function( |
902 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) { | 900 previousImageWidth, previousImageHeight, imageCropRect, opt_duration) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 }; | 954 }; |
957 | 955 |
958 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; | 956 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; |
959 | 957 |
960 /** | 958 /** |
961 * @override | 959 * @override |
962 */ | 960 */ |
963 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { | 961 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { |
964 return viewport.getInverseTransformForRotatedImage(this.orientation_); | 962 return viewport.getInverseTransformForRotatedImage(this.orientation_); |
965 }; | 963 }; |
OLD | NEW |