1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 tvcm.exportTo('cc', function() {
12 function PictureAsImageData(picture, errorOrImageData) {
13 this.picture_ = picture;
14 if (errorOrImageData instanceof ImageData) {
15 this.error_ = undefined;
16 this.imageData_ = errorOrImageData;
18 this.error_ = errorOrImageData;
19 this.imageData_ = undefined;
24 * Creates a new pending PictureAsImageData (no image data and no error).
26 * @return {PictureAsImageData} a new pending PictureAsImageData.
28 PictureAsImageData.Pending = function(picture) {
29 return new PictureAsImageData(picture, undefined);
32 PictureAsImageData.prototype = {
42 return this.imageData_;
45 isPending: function() {
46 return this.error_ === undefined && this.imageData_ === undefined;
49 asCanvas: function() {
53 var canvas = document.createElement('canvas');
54 var ctx = canvas.getContext('2d');
56 canvas.width = this.imageData_.width;
57 canvas.height = this.imageData_.height;
58 ctx.putImageData(this.imageData_, 0, 0);
64 PictureAsImageData: PictureAsImageData