Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / picture_as_image_data.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tvcm.html">
9 <script>
10 'use strict';
11
12 tvcm.exportTo('cc', function() {
13   /**
14    * @constructor
15    */
16   function PictureAsImageData(picture, errorOrImageData) {
17     this.picture_ = picture;
18     if (errorOrImageData instanceof ImageData) {
19       this.error_ = undefined;
20       this.imageData_ = errorOrImageData;
21     } else {
22       this.error_ = errorOrImageData;
23       this.imageData_ = undefined;
24     }
25   };
26
27   /**
28    * Creates a new pending PictureAsImageData (no image data and no error).
29    *
30    * @return {PictureAsImageData} a new pending PictureAsImageData.
31    */
32   PictureAsImageData.Pending = function(picture) {
33     return new PictureAsImageData(picture, undefined);
34   };
35
36   PictureAsImageData.prototype = {
37     get picture() {
38       return this.picture_;
39     },
40
41     get error() {
42       return this.error_;
43     },
44
45     get imageData() {
46       return this.imageData_;
47     },
48
49     isPending: function() {
50       return this.error_ === undefined && this.imageData_ === undefined;
51     },
52
53     asCanvas: function() {
54       if (!this.imageData_)
55         return;
56
57       var canvas = document.createElement('canvas');
58       var ctx = canvas.getContext('2d');
59
60       canvas.width = this.imageData_.width;
61       canvas.height = this.imageData_.height;
62       ctx.putImageData(this.imageData_, 0, 0);
63       return canvas;
64     }
65   };
66
67   return {
68     PictureAsImageData: PictureAsImageData
69   };
70 });
71 </script>