Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / resources / managed_tile_state.h
blobb3d80bb3aaf73d0896e5e241345927044de36536
1 // Copyright 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.
5 #ifndef CC_RESOURCES_MANAGED_TILE_STATE_H_
6 #define CC_RESOURCES_MANAGED_TILE_STATE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/resources/platform_color.h"
10 #include "cc/resources/raster_mode.h"
11 #include "cc/resources/rasterizer.h"
12 #include "cc/resources/resource_pool.h"
13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/scoped_resource.h"
15 #include "cc/resources/tile_priority.h"
17 namespace cc {
19 class TileManager;
21 // Tile manager classifying tiles into a few basic bins:
22 enum ManagedTileBin {
23 NOW_AND_READY_TO_DRAW_BIN = 0, // Ready to draw and within viewport.
24 NOW_BIN = 1, // Needed ASAP.
25 SOON_BIN = 2, // Impl-side version of prepainting.
26 EVENTUALLY_AND_ACTIVE_BIN = 3, // Nice to have, and has a task or resource.
27 EVENTUALLY_BIN = 4, // Nice to have, if we've got memory and time.
28 AT_LAST_AND_ACTIVE_BIN = 5, // Only do this after all other bins.
29 AT_LAST_BIN = 6, // Only do this after all other bins.
30 NEVER_BIN = 7, // Dont bother.
31 NUM_BINS = 8
32 // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
33 // or reordering fields.
35 scoped_ptr<base::Value> ManagedTileBinAsValue(ManagedTileBin bin);
37 // This is state that is specific to a tile that is
38 // managed by the TileManager.
39 class CC_EXPORT ManagedTileState {
40 public:
41 class CC_EXPORT TileVersion {
42 public:
43 enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE };
45 TileVersion();
46 ~TileVersion();
48 Mode mode() const { return mode_; }
50 bool IsReadyToDraw() const;
52 ResourceProvider::ResourceId get_resource_id() const {
53 DCHECK(mode_ == RESOURCE_MODE);
54 DCHECK(resource_);
56 return resource_->id();
59 SkColor get_solid_color() const {
60 DCHECK(mode_ == SOLID_COLOR_MODE);
62 return solid_color_;
65 bool contents_swizzled() const {
66 DCHECK(resource_);
67 return !PlatformColor::SameComponentOrder(resource_->format());
70 bool requires_resource() const {
71 return mode_ == RESOURCE_MODE || mode_ == PICTURE_PILE_MODE;
74 inline bool has_resource() const { return !!resource_; }
76 size_t GPUMemoryUsageInBytes() const;
78 void SetSolidColorForTesting(SkColor color) { set_solid_color(color); }
79 void SetHasTextForTesting(bool has_text) { has_text_ = has_text; }
80 void SetResourceForTesting(scoped_ptr<ScopedResource> resource) {
81 resource_ = resource.Pass();
84 private:
85 friend class TileManager;
86 friend class PrioritizedTileSet;
87 friend class Tile;
88 friend class ManagedTileState;
90 void set_use_resource() { mode_ = RESOURCE_MODE; }
92 void set_solid_color(const SkColor& color) {
93 mode_ = SOLID_COLOR_MODE;
94 solid_color_ = color;
97 void set_has_text(bool has_text) { has_text_ = has_text; }
99 void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; }
101 Mode mode_;
102 SkColor solid_color_;
103 bool has_text_;
104 scoped_ptr<ScopedResource> resource_;
105 scoped_refptr<RasterTask> raster_task_;
108 ManagedTileState();
109 ~ManagedTileState();
111 scoped_ptr<base::Value> AsValue() const;
113 // Persisted state: valid all the time.
114 TileVersion tile_versions[NUM_RASTER_MODES];
115 RasterMode raster_mode;
117 ManagedTileBin bin;
119 TileResolution resolution;
120 bool required_for_activation;
121 TilePriority::PriorityBin priority_bin;
122 float distance_to_visible;
123 bool visible_and_ready_to_draw;
125 // Priority for this state from the last time we assigned memory.
126 unsigned scheduled_priority;
129 } // namespace cc
131 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_