summaryrefslogtreecommitdiffstats
path: root/cc/tiles/tile_draw_info.h
blob: 6d694ebf1e2e41c4ca238ecbb0463d3a2e510402 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TILES_TILE_DRAW_INFO_H_
#define CC_TILES_TILE_DRAW_INFO_H_

#include "base/memory/scoped_ptr.h"
#include "base/trace_event/trace_event_argument.h"
#include "cc/raster/tile_task_runner.h"
#include "cc/resources/platform_color.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/scoped_resource.h"

namespace cc {

// This class holds all the state relevant to drawing a tile.
class CC_EXPORT TileDrawInfo {
 public:
  enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, OOM_MODE };

  TileDrawInfo();
  ~TileDrawInfo();

  Mode mode() const { return mode_; }

  bool IsReadyToDraw() const {
    switch (mode_) {
      case RESOURCE_MODE:
        return !!resource_;
      case SOLID_COLOR_MODE:
      case OOM_MODE:
        return true;
    }
    NOTREACHED();
    return false;
  }
  bool NeedsRaster() const {
    switch (mode_) {
      case RESOURCE_MODE:
        return !resource_;
      case SOLID_COLOR_MODE:
        return false;
      case OOM_MODE:
        return true;
    }
    NOTREACHED();
    return false;
  }

  ResourceId resource_id() const {
    DCHECK(mode_ == RESOURCE_MODE);
    DCHECK(resource_);
    return resource_->id();
  }

  gfx::Size resource_size() const {
    DCHECK(mode_ == RESOURCE_MODE);
    DCHECK(resource_);
    return resource_->size();
  }

  SkColor solid_color() const {
    DCHECK(mode_ == SOLID_COLOR_MODE);
    return solid_color_;
  }

  bool contents_swizzled() const { return contents_swizzled_; }

  bool requires_resource() const {
    return mode_ == RESOURCE_MODE || mode_ == OOM_MODE;
  }

  inline bool has_resource() const { return !!resource_; }

  inline bool has_compressed_resource() const {
    return resource_ ? IsResourceFormatCompressed(resource_->format()) : false;
  }

  void SetSolidColorForTesting(SkColor color) { set_solid_color(color); }

  void AsValueInto(base::trace_event::TracedValue* state) const;

  void set_was_ever_ready_to_draw() { was_ever_ready_to_draw_ = true; }
  void set_was_ever_used_to_draw() { was_ever_used_to_draw_ = true; }

 private:
  friend class Tile;
  friend class TileManager;

  void set_use_resource() { mode_ = RESOURCE_MODE; }

  void set_solid_color(const SkColor& color) {
    mode_ = SOLID_COLOR_MODE;
    solid_color_ = color;
  }

  void set_oom() { mode_ = OOM_MODE; }

  Mode mode_;
  SkColor solid_color_;
  Resource* resource_;
  bool contents_swizzled_;

  // Used for gathering UMA stats.
  bool was_ever_ready_to_draw_;
  bool was_ever_used_to_draw_;
};

}  // namespace cc

#endif  // CC_TILES_TILE_DRAW_INFO_H_