| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 <link rel="import" href="/tracing/base/base.html"> | 7 <link rel="import" href="/tracing/base/base.html"> |
| 8 <script> | 8 <script> |
| 9 'use strict'; | 9 'use strict'; |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 mergeCurRight_: 0, | 60 mergeCurRight_: 0, |
| 61 mergedColorId_: 0, | 61 mergedColorId_: 0, |
| 62 mergedAlpha_: 0, | 62 mergedAlpha_: 0, |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * Changes the y position and height for subsequent fillRect | 65 * Changes the y position and height for subsequent fillRect |
| 66 * calls. x and width are specifieid on the fillRect calls. | 66 * calls. x and width are specifieid on the fillRect calls. |
| 67 */ | 67 */ |
| 68 setYandH: function(y, h) { | 68 setYandH: function(y, h) { |
| 69 if (this.y_ === y && | 69 if (this.y_ === y && |
| 70 this.h_ === h) | 70 this.h_ === h) { |
| 71 return; | 71 return; |
| 72 } |
| 72 this.flush(); | 73 this.flush(); |
| 73 this.y_ = y; | 74 this.y_ = y; |
| 74 this.h_ = h; | 75 this.h_ = h; |
| 75 }, | 76 }, |
| 76 | 77 |
| 77 /** | 78 /** |
| 78 * Fills rectangle at the specified location, if visible. If the | 79 * Fills rectangle at the specified location, if visible. If the |
| 79 * rectangle is subpixel, it will be merged with adjacent rectangles. | 80 * rectangle is subpixel, it will be merged with adjacent rectangles. |
| 80 * The drawing operation may not take effect until flush is called. | 81 * The drawing operation may not take effect until flush is called. |
| 81 * @param {number} colorId The color of this rectangle, as an index | 82 * @param {number} colorId The color of this rectangle, as an index |
| 82 * in the renderer's color pallete. | 83 * in the renderer's color pallete. |
| 83 * @param {number} alpha The opacity of the rectangle as 0.0-1.0 number. | 84 * @param {number} alpha The opacity of the rectangle as 0.0-1.0 number. |
| 84 */ | 85 */ |
| 85 fillRect: function(x, w, colorId, alpha) { | 86 fillRect: function(x, w, colorId, alpha) { |
| 86 var r = x + w; | 87 var r = x + w; |
| 87 if (w < this.minRectSize_) { | 88 if (w < this.minRectSize_) { |
| 88 if (r - this.mergeStartX_ > this.maxMergeDist_) | 89 if (r - this.mergeStartX_ > this.maxMergeDist_) { |
| 89 this.flush(); | 90 this.flush(); |
| 91 } |
| 90 if (!this.merging_) { | 92 if (!this.merging_) { |
| 91 this.merging_ = true; | 93 this.merging_ = true; |
| 92 this.mergeStartX_ = x; | 94 this.mergeStartX_ = x; |
| 93 this.mergeCurRight_ = r; | 95 this.mergeCurRight_ = r; |
| 94 this.mergedColorId_ = colorId; | 96 this.mergedColorId_ = colorId; |
| 95 this.mergedAlpha_ = alpha; | 97 this.mergedAlpha_ = alpha; |
| 96 } else { | 98 } else { |
| 97 this.mergeCurRight_ = r; | 99 this.mergeCurRight_ = r; |
| 98 | 100 |
| 99 if (this.mergedAlpha_ < alpha || | 101 if (this.mergedAlpha_ < alpha || |
| 100 (this.mergedAlpha_ === alpha && this.mergedColorId_ < colorId)) { | 102 (this.mergedAlpha_ === alpha && this.mergedColorId_ < colorId)) { |
| 101 this.mergedAlpha_ = alpha; | 103 this.mergedAlpha_ = alpha; |
| 102 this.mergedColorId_ = colorId; | 104 this.mergedColorId_ = colorId; |
| 103 } | 105 } |
| 104 } | 106 } |
| 105 } else { | 107 } else { |
| 106 if (this.merging_) | 108 if (this.merging_) { |
| 107 this.flush(); | 109 this.flush(); |
| 110 } |
| 108 this.ctx_.fillStyle = this.pallette_[colorId]; | 111 this.ctx_.fillStyle = this.pallette_[colorId]; |
| 109 this.ctx_.globalAlpha = alpha; | 112 this.ctx_.globalAlpha = alpha; |
| 110 this.ctx_.fillRect(x, this.y_, w, this.h_); | 113 this.ctx_.fillRect(x, this.y_, w, this.h_); |
| 111 } | 114 } |
| 112 }, | 115 }, |
| 113 | 116 |
| 114 /** | 117 /** |
| 115 * Commits any pending fillRect operations to the underlying graphics | 118 * Commits any pending fillRect operations to the underlying graphics |
| 116 * context. | 119 * context. |
| 117 */ | 120 */ |
| 118 flush: function() { | 121 flush: function() { |
| 119 if (this.merging_) { | 122 if (this.merging_) { |
| 120 this.ctx_.fillStyle = this.pallette_[this.mergedColorId_]; | 123 this.ctx_.fillStyle = this.pallette_[this.mergedColorId_]; |
| 121 this.ctx_.globalAlpha = this.mergedAlpha_; | 124 this.ctx_.globalAlpha = this.mergedAlpha_; |
| 122 this.ctx_.fillRect(this.mergeStartX_, this.y_, | 125 this.ctx_.fillRect(this.mergeStartX_, this.y_, |
| 123 this.mergeCurRight_ - this.mergeStartX_, this.h_); | 126 this.mergeCurRight_ - this.mergeStartX_, this.h_); |
| 124 this.merging_ = false; | 127 this.merging_ = false; |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 }; | 130 }; |
| 128 | 131 |
| 129 return { | 132 return { |
| 130 FastRectRenderer, | 133 FastRectRenderer, |
| 131 }; | 134 }; |
| 132 }); | 135 }); |
| 133 </script> | 136 </script> |
| OLD | NEW |