Skip to content

Commit 9629c24

Browse files
authored
Fix large canvas rendering (at closest zoom levels), with WebEngine (#3711)
* Timeline: Constrain ruler canvas width to 32Kpixels * Timeline: Add canvasMaxWidth() constraint function - Apply it to the progress, waveform, and ruler canvases - Also check max width in canvas redrawing code
1 parent 204efa5 commit 9629c24

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/timeline/index.html

+3-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<div class="playhead-line-small"></div>
4949
</div>
5050
<!-- Ruler extends beyond tracks area at least for a width of vertical scroll bar (or more, like 50px here) -->
51-
<canvas tl-ruler id="ruler" width="{{getTimelineWidth(1024) + 50}}" height="39"></canvas>
51+
<canvas tl-ruler id="ruler" width="{{canvasMaxWidth(getTimelineWidth(1024) + 50)}}px" height="39"></canvas>
5252

5353
<!-- MARKERS -->
5454
<span class="ruler_marker" id="marker_for_{{marker.id}}">
@@ -57,7 +57,7 @@
5757
<br class="cleared">
5858

5959
<!-- PROGRESS BAR -->
60-
<canvas id="progress" width="{{project.duration * pixelsPerSecond}}px" height="3px"></canvas>
60+
<canvas id="progress" width="{{canvasMaxWidth(project.duration * pixelsPerSecond)}}px" height="3px"></canvas>
6161
</div>
6262
<div class="cleared"></div>
6363

@@ -102,7 +102,7 @@
102102
<img class="thumb thumb-start" ng-show="getThumbPath(clip)" ng-src="{{ getThumbPath(clip) }}"/>
103103
</div>
104104
<div ng-show="clip.show_audio" class="audio-container">
105-
<canvas tl-audio height="46px" width="{{ (clip.end - clip.start) * pixelsPerSecond}}px" class="audio"></canvas>
105+
<canvas tl-audio height="46px" width="{{canvasMaxWidth((clip.end - clip.start) * pixelsPerSecond)}}px" class="audio"></canvas>
106106
</div>
107107
</div>
108108

@@ -178,5 +178,3 @@
178178
<!-- END DEBUG SECTION -->
179179
</body>
180180
</html>
181-
182-

src/timeline/js/controllers.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,13 @@ App.controller("TimelineCtrl", function ($scope) {
466466
var start_second = parseFloat(progress[p]["start"]) / fps;
467467
var stop_second = parseFloat(progress[p]["end"]) / fps;
468468

469-
//figure out the actual pixel position
470-
var start_pixel = start_second * $scope.pixelsPerSecond;
471-
var stop_pixel = stop_second * $scope.pixelsPerSecond;
469+
//figure out the actual pixel position, constrained by max width
470+
var start_pixel = $scope.canvasMaxWidth(start_second * $scope.pixelsPerSecond);
471+
var stop_pixel = $scope.canvasMaxWidth(stop_second * $scope.pixelsPerSecond);
472472
var rect_length = stop_pixel - start_pixel;
473-
473+
if (rect_length < 1) {
474+
break;
475+
}
474476
//get the element and draw the rects
475477
ctx.beginPath();
476478
ctx.rect(start_pixel, 0, rect_length, 5);
@@ -642,6 +644,11 @@ App.controller("TimelineCtrl", function ($scope) {
642644
}
643645
};
644646

647+
// Constrain canvas width values to under 32Kpixels
648+
$scope.canvasMaxWidth = function (desired_width) {
649+
return Math.min(32767, desired_width);
650+
};
651+
645652
// Find the furthest right edge on the timeline (and resize it if too small)
646653
$scope.resizeTimeline = function () {
647654
// Unselect all clips

src/timeline/js/directives/ruler.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ App.directive("tlRuler", function ($timeout) {
154154
var scale = scope.project.scale;
155155
var tick_pixels = scope.project.tick_pixels;
156156
var each_tick = tick_pixels / 2;
157-
var pixel_length = scope.getTimelineWidth(1024);
157+
// Don't go over the max supported canvas size
158+
var pixel_length = Math.min(32767,scope.getTimelineWidth(1024));
158159

159160
//draw the ruler
160161
var ctx = element[0].getContext("2d");

src/timeline/js/functions.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,20 @@ function drawAudio(scope, clip_id) {
103103
max = 0.0,
104104
last_x = 0;
105105

106+
// Ensure that the waveform canvas doesn't exceed its max
107+
// dimensions, even if it means we can't draw the full audio.
108+
// (If we try to go over the max width, the whole canvas disappears)
109+
var final_sample = end_sample;
110+
var audio_width = (end_sample - start_sample) / sample_divisor;
111+
var usable_width = scope.canvasMaxWidth(audio_width);
112+
if (audio_width > usable_width) {
113+
// Just go as far as we can, then cut off the remaining waveform
114+
final_sample = (usable_width * sample_divisor) - 1;
115+
}
116+
106117
// Go through all of the (reduced) samples
107118
// And whenever enough are "collected", draw a block
108-
for (var i = start_sample; i < end_sample; i++) {
119+
for (var i = start_sample; i < final_sample; i++) {
109120
// Flip negative values up
110121
sample = Math.abs(clip.audio_data[i]);
111122
// X-Position of *next* sample
@@ -115,7 +126,7 @@ function drawAudio(scope, clip_id) {
115126
avg_cnt++;
116127
max = Math.max(max, sample);
117128

118-
if (x >= last_x + block_width || i === end_sample - 1) {
129+
if (x >= last_x + block_width || i === final_sample - 1) {
119130
// Block wide enough or last block -> draw it
120131

121132
// Draw the slightly transparent max-bar

0 commit comments

Comments
 (0)