• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5'use strict';
6
7base.exportTo('cc', function() {
8
9  /**
10   * @constructor
11   */
12  function PictureAsCanvas(picture, errorOrCanvas) {
13    this.picture_ = picture;
14    if (errorOrCanvas instanceof HTMLCanvasElement) {
15      this.error_ = undefined;
16      this.canvas_ = errorOrCanvas;
17    } else {
18      this.error_ = errorOrCanvas;
19      this.canvas_ = undefined;
20    }
21  };
22
23  /**
24   * Creates a new pending PictureAsCanvas (no canvas and no error).
25   *
26   * @return {PictureAsCanvas} a new pending PictureAsCanvas.
27   */
28  PictureAsCanvas.Pending = function(picture) {
29    return new PictureAsCanvas(picture, undefined);
30  };
31
32  PictureAsCanvas.prototype = {
33    get picture() {
34      return this.picture_;
35    },
36
37    get error() {
38      return this.error_;
39    },
40
41    get canvas() {
42      return this.canvas_;
43    },
44
45    isPending: function() {
46      return this.error_ === undefined && this.canvas_ === undefined;
47    }
48  };
49
50  return {
51    PictureAsCanvas: PictureAsCanvas
52  };
53});
54