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_worker_pool.h"
11 #include "cc/resources/resource_pool.h"
12 #include "cc/resources/resource_provider.h"
13 #include "cc/resources/scoped_resource.h"
19 // Tile manager classifying tiles into a few basic bins:
21 NOW_AND_READY_TO_DRAW_BIN = 0, // Ready to draw and within viewport.
22 NOW_BIN = 1, // Needed ASAP.
23 SOON_BIN = 2, // Impl-side version of prepainting.
24 EVENTUALLY_AND_ACTIVE_BIN = 3, // Nice to have, and has a task or resource.
25 EVENTUALLY_BIN = 4, // Nice to have, if we've got memory and time.
26 AT_LAST_AND_ACTIVE_BIN = 5, // Only do this after all other bins.
27 AT_LAST_BIN = 6, // Only do this after all other bins.
28 NEVER_BIN = 7, // Dont bother.
30 // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
31 // or reordering fields.
33 scoped_ptr<base::Value> ManagedTileBinAsValue(ManagedTileBin bin);
35 // This is state that is specific to a tile that is
36 // managed by the TileManager.
37 class CC_EXPORT ManagedTileState {
39 class CC_EXPORT TileVersion {
41 enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE };
46 Mode mode() const { return mode_; }
48 bool IsReadyToDraw() const;
50 ResourceProvider::ResourceId get_resource_id() const {
51 DCHECK(mode_ == RESOURCE_MODE);
54 return resource_->id();
57 SkColor get_solid_color() const {
58 DCHECK(mode_ == SOLID_COLOR_MODE);
63 bool contents_swizzled() const {
65 return !PlatformColor::SameComponentOrder(resource_->format());
68 bool requires_resource() const {
69 return mode_ == RESOURCE_MODE || mode_ == PICTURE_PILE_MODE;
72 size_t GPUMemoryUsageInBytes() const;
74 void SetSolidColorForTesting(SkColor color) { set_solid_color(color); }
75 void SetHasTextForTesting(bool has_text) { has_text_ = has_text; }
78 friend class TileManager;
79 friend class PrioritizedTileSet;
81 friend class ManagedTileState;
83 void set_use_resource() { mode_ = RESOURCE_MODE; }
85 void set_solid_color(const SkColor& color) {
86 mode_ = SOLID_COLOR_MODE;
90 void set_has_text(bool has_text) { has_text_ = has_text; }
92 void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; }
97 scoped_ptr<ScopedResource> resource_;
98 RasterWorkerPool::RasterTask raster_task_;
104 scoped_ptr<base::Value> AsValue() const;
106 // Persisted state: valid all the time.
107 TileVersion tile_versions[NUM_RASTER_MODES];
108 RasterMode raster_mode;
112 TileResolution resolution;
113 bool required_for_activation;
114 TilePriority::PriorityBin priority_bin;
115 float distance_to_visible;
116 bool visible_and_ready_to_draw;
118 // Priority for this state from the last time we assigned memory.
119 unsigned scheduled_priority;
124 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_