Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/animation/AnimationModel.js

Issue 2672983002: [DevTools] Separate ScreenCaptureModel out of ResourceTreeModel. (Closed)
Patch Set: rebased Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 /** 5 /**
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 Animation.AnimationModel = class extends SDK.SDKModel { 8 Animation.AnimationModel = class extends SDK.SDKModel {
9 /** 9 /**
10 * @param {!SDK.Target} target 10 * @param {!SDK.Target} target
11 */ 11 */
12 constructor(target) { 12 constructor(target) {
13 super(target); 13 super(target);
14 this._runtimeModel = target.runtimeModel; 14 this._runtimeModel = target.runtimeModel;
15 this._agent = target.animationAgent(); 15 this._agent = target.animationAgent();
16 target.registerAnimationDispatcher(new Animation.AnimationDispatcher(this)); 16 target.registerAnimationDispatcher(new Animation.AnimationDispatcher(this));
17 /** @type {!Map.<string, !Animation.AnimationModel.Animation>} */ 17 /** @type {!Map.<string, !Animation.AnimationModel.Animation>} */
18 this._animationsById = new Map(); 18 this._animationsById = new Map();
19 /** @type {!Map.<string, !Animation.AnimationModel.AnimationGroup>} */ 19 /** @type {!Map.<string, !Animation.AnimationModel.AnimationGroup>} */
20 this._animationGroups = new Map(); 20 this._animationGroups = new Map();
21 /** @type {!Array.<string>} */ 21 /** @type {!Array.<string>} */
22 this._pendingAnimations = []; 22 this._pendingAnimations = [];
23 this._playbackRate = 1; 23 this._playbackRate = 1;
24 var resourceTreeModel = 24 var resourceTreeModel =
25 /** @type {!SDK.ResourceTreeModel} */ (SDK.ResourceTreeModel.fromTarget( target)); 25 /** @type {!SDK.ResourceTreeModel} */ (SDK.ResourceTreeModel.fromTarget( target));
26 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.MainFrameNav igated, this._reset, this); 26 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.MainFrameNav igated, this._reset, this);
27 this._screenshotCapture = 27 var screenCaptureModel = target.model(SDK.ScreenCaptureModel);
28 new Animation.AnimationModel.ScreenshotCapture(this, target.pageAgent(), resourceTreeModel); 28 if (screenCaptureModel)
29 this._screenshotCapture = new Animation.AnimationModel.ScreenshotCapture(t his, screenCaptureModel);
29 } 30 }
30 31
31 _reset() { 32 _reset() {
32 this._animationsById.clear(); 33 this._animationsById.clear();
33 this._animationGroups.clear(); 34 this._animationGroups.clear();
34 this._pendingAnimations = []; 35 this._pendingAnimations = [];
35 this.dispatchEventToListeners(Animation.AnimationModel.Events.ModelReset); 36 this.dispatchEventToListeners(Animation.AnimationModel.Events.ModelReset);
36 } 37 }
37 38
38 /** 39 /**
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 for (var group of this._animationGroups.values()) { 88 for (var group of this._animationGroups.values()) {
88 if (group._matches(incomingGroup)) { 89 if (group._matches(incomingGroup)) {
89 matchedGroup = group; 90 matchedGroup = group;
90 group._update(incomingGroup); 91 group._update(incomingGroup);
91 break; 92 break;
92 } 93 }
93 } 94 }
94 95
95 if (!matchedGroup) { 96 if (!matchedGroup) {
96 this._animationGroups.set(incomingGroup.id(), incomingGroup); 97 this._animationGroups.set(incomingGroup.id(), incomingGroup);
97 this._screenshotCapture.captureScreenshots(incomingGroup.finiteDuration(), incomingGroup._screenshots); 98 if (this._screenshotCapture)
99 this._screenshotCapture.captureScreenshots(incomingGroup.finiteDuration( ), incomingGroup._screenshots);
98 } 100 }
99 this.dispatchEventToListeners(Animation.AnimationModel.Events.AnimationGroup Started, matchedGroup || incomingGroup); 101 this.dispatchEventToListeners(Animation.AnimationModel.Events.AnimationGroup Started, matchedGroup || incomingGroup);
100 return !!matchedGroup; 102 return !!matchedGroup;
101 } 103 }
102 104
103 /** 105 /**
104 * @return {!Animation.AnimationModel.AnimationGroup} 106 * @return {!Animation.AnimationModel.AnimationGroup}
105 */ 107 */
106 _createGroupFromPendingAnimations() { 108 _createGroupFromPendingAnimations() {
107 console.assert(this._pendingAnimations.length); 109 console.assert(this._pendingAnimations.length);
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 this._animationModel.animationStarted(payload); 770 this._animationModel.animationStarted(payload);
769 } 771 }
770 }; 772 };
771 773
772 /** 774 /**
773 * @unrestricted 775 * @unrestricted
774 */ 776 */
775 Animation.AnimationModel.ScreenshotCapture = class { 777 Animation.AnimationModel.ScreenshotCapture = class {
776 /** 778 /**
777 * @param {!Animation.AnimationModel} animationModel 779 * @param {!Animation.AnimationModel} animationModel
778 * @param {!Protocol.PageAgent} pageAgent 780 * @param {!SDK.ScreenCaptureModel} screenCaptureModel
779 * @param {!SDK.ResourceTreeModel} resourceTreeModel
780 */ 781 */
781 constructor(animationModel, pageAgent, resourceTreeModel) { 782 constructor(animationModel, screenCaptureModel) {
782 /** @type {!Array<!Animation.AnimationModel.ScreenshotCapture.Request>} */ 783 /** @type {!Array<!Animation.AnimationModel.ScreenshotCapture.Request>} */
783 this._requests = []; 784 this._requests = [];
784 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.ScreencastFr ame, this._screencastFrame, this); 785 this._screenCaptureModel = screenCaptureModel;
785 this._pageAgent = pageAgent;
786 this._animationModel = animationModel; 786 this._animationModel = animationModel;
787 this._animationModel.addEventListener(Animation.AnimationModel.Events.ModelR eset, this._stopScreencast, this); 787 this._animationModel.addEventListener(Animation.AnimationModel.Events.ModelR eset, this._stopScreencast, this);
788 } 788 }
789 789
790 /** 790 /**
791 * @param {number} duration 791 * @param {number} duration
792 * @param {!Array<string>} screenshots 792 * @param {!Array<string>} screenshots
793 */ 793 */
794 captureScreenshots(duration, screenshots) { 794 captureScreenshots(duration, screenshots) {
795 var screencastDuration = Math.min(duration / this._animationModel._playbackR ate, 3000); 795 var screencastDuration = Math.min(duration / this._animationModel._playbackR ate, 3000);
796 var endTime = screencastDuration + window.performance.now(); 796 var endTime = screencastDuration + window.performance.now();
797 this._requests.push({endTime: endTime, screenshots: screenshots}); 797 this._requests.push({endTime: endTime, screenshots: screenshots});
798 798
799 if (!this._endTime || endTime > this._endTime) { 799 if (!this._endTime || endTime > this._endTime) {
800 clearTimeout(this._stopTimer); 800 clearTimeout(this._stopTimer);
801 this._stopTimer = setTimeout(this._stopScreencast.bind(this), screencastDu ration); 801 this._stopTimer = setTimeout(this._stopScreencast.bind(this), screencastDu ration);
802 this._endTime = endTime; 802 this._endTime = endTime;
803 } 803 }
804 804
805 if (this._capturing) 805 if (this._capturing)
806 return; 806 return;
807 this._capturing = true; 807 this._capturing = true;
808 this._pageAgent.startScreencast('jpeg', 80, undefined, 300, 2); 808 this._screenCaptureModel.startScreencast(
809 'jpeg', 80, undefined, 300, 2, this._screencastFrame.bind(this), visible => {});
809 } 810 }
810 811
811 /** 812 /**
812 * @param {!Common.Event} event 813 * @param {string} base64Data
814 * @param {!Protocol.Page.ScreencastFrameMetadata} metadata
813 */ 815 */
814 _screencastFrame(event) { 816 _screencastFrame(base64Data, metadata) {
815 /** 817 /**
816 * @param {!Animation.AnimationModel.ScreenshotCapture.Request} request 818 * @param {!Animation.AnimationModel.ScreenshotCapture.Request} request
817 * @return {boolean} 819 * @return {boolean}
818 */ 820 */
819 function isAnimating(request) { 821 function isAnimating(request) {
820 return request.endTime >= now; 822 return request.endTime >= now;
821 } 823 }
822 824
823 if (!this._capturing) 825 if (!this._capturing)
824 return; 826 return;
825 827
826 var base64Data = /** type {string} */ (event.data['data']);
827 var now = window.performance.now(); 828 var now = window.performance.now();
828 this._requests = this._requests.filter(isAnimating); 829 this._requests = this._requests.filter(isAnimating);
829 for (var request of this._requests) 830 for (var request of this._requests)
830 request.screenshots.push(base64Data); 831 request.screenshots.push(base64Data);
831 } 832 }
832 833
833 _stopScreencast() { 834 _stopScreencast() {
834 if (!this._capturing) 835 if (!this._capturing)
835 return; 836 return;
836 837
837 delete this._stopTimer; 838 delete this._stopTimer;
838 delete this._endTime; 839 delete this._endTime;
839 this._requests = []; 840 this._requests = [];
840 this._capturing = false; 841 this._capturing = false;
841 this._pageAgent.stopScreencast(); 842 this._screenCaptureModel.stopScreencast();
842 } 843 }
843 }; 844 };
844 845
845 /** @typedef {{ endTime: number, screenshots: !Array.<string>}} */ 846 /** @typedef {{ endTime: number, screenshots: !Array.<string>}} */
846 Animation.AnimationModel.ScreenshotCapture.Request; 847 Animation.AnimationModel.ScreenshotCapture.Request;
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698