managed_tile_state.h revision 3551c9c881056c480085172ff9840cab31610854
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. 4 5#ifndef CC_RESOURCES_MANAGED_TILE_STATE_H_ 6#define CC_RESOURCES_MANAGED_TILE_STATE_H_ 7 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 14namespace cc { 15 16class TileManager; 17 18// Tile manager classifying tiles into a few basic bins: 19enum ManagedTileBin { 20 NOW_AND_READY_TO_DRAW_BIN = 0, // Ready to draw and within viewport. 21 NOW_BIN = 1, // Needed ASAP. 22 SOON_BIN = 2, // Impl-side version of prepainting. 23 EVENTUALLY_AND_ACTIVE_BIN = 3, // Nice to have, and has a task or resource. 24 EVENTUALLY_BIN = 4, // Nice to have, if we've got memory and time. 25 NEVER_AND_ACTIVE_BIN = 5, // Dont bother, but has a task or resource. 26 NEVER_BIN = 6, // Dont bother. 27 NUM_BINS = 7 28 // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding 29 // or reordering fields. 30}; 31scoped_ptr<base::Value> ManagedTileBinAsValue( 32 ManagedTileBin bin); 33 34enum ManagedTileBinPriority { 35 HIGH_PRIORITY_BIN = 0, 36 LOW_PRIORITY_BIN = 1, 37 NUM_BIN_PRIORITIES = 2 38}; 39scoped_ptr<base::Value> ManagedTileBinPriorityAsValue( 40 ManagedTileBinPriority bin); 41 42// This is state that is specific to a tile that is 43// managed by the TileManager. 44class CC_EXPORT ManagedTileState { 45 public: 46 class CC_EXPORT TileVersion { 47 public: 48 enum Mode { 49 RESOURCE_MODE, 50 SOLID_COLOR_MODE, 51 PICTURE_PILE_MODE, 52 NUM_MODES 53 }; 54 55 TileVersion(); 56 ~TileVersion(); 57 58 Mode mode() const { 59 return mode_; 60 } 61 62 bool IsReadyToDraw() const; 63 64 ResourceProvider::ResourceId get_resource_id() const { 65 DCHECK(mode_ == RESOURCE_MODE); 66 DCHECK(resource_); 67 68 return resource_->id(); 69 } 70 71 SkColor get_solid_color() const { 72 DCHECK(mode_ == SOLID_COLOR_MODE); 73 74 return solid_color_; 75 } 76 77 bool contents_swizzled() const { 78 DCHECK(resource_); 79 return !PlatformColor::SameComponentOrder(resource_->format()); 80 } 81 82 bool requires_resource() const { 83 return mode_ == RESOURCE_MODE || 84 mode_ == PICTURE_PILE_MODE; 85 } 86 87 size_t GPUMemoryUsageInBytes() const; 88 89 void SetSolidColorForTesting(SkColor color) { 90 set_solid_color(color); 91 } 92 void SetHasTextForTesting(bool has_text) { 93 has_text_ = has_text; 94 } 95 96 private: 97 friend class TileManager; 98 friend class PrioritizedTileSet; 99 friend class Tile; 100 friend class ManagedTileState; 101 102 void set_use_resource() { 103 mode_ = RESOURCE_MODE; 104 } 105 106 void set_solid_color(const SkColor& color) { 107 mode_ = SOLID_COLOR_MODE; 108 solid_color_ = color; 109 } 110 111 void set_has_text(bool has_text) { 112 has_text_ = has_text; 113 } 114 115 void set_rasterize_on_demand() { 116 mode_ = PICTURE_PILE_MODE; 117 } 118 119 Mode mode_; 120 SkColor solid_color_; 121 bool has_text_; 122 scoped_ptr<ResourcePool::Resource> resource_; 123 RasterWorkerPool::RasterTask raster_task_; 124 }; 125 126 ManagedTileState(); 127 ~ManagedTileState(); 128 129 scoped_ptr<base::Value> AsValue() const; 130 131 // Persisted state: valid all the time. 132 TileVersion tile_versions[NUM_RASTER_MODES]; 133 RasterMode raster_mode; 134 135 // Ephemeral state, valid only during TileManager::ManageTiles. 136 bool is_in_never_bin_on_both_trees() const { 137 return (bin[HIGH_PRIORITY_BIN] == NEVER_BIN || 138 bin[HIGH_PRIORITY_BIN] == NEVER_AND_ACTIVE_BIN) && 139 (bin[LOW_PRIORITY_BIN] == NEVER_BIN || 140 bin[LOW_PRIORITY_BIN] == NEVER_AND_ACTIVE_BIN); 141 } 142 143 ManagedTileBin bin[NUM_BIN_PRIORITIES]; 144 ManagedTileBin tree_bin[NUM_TREES]; 145 146 // The bin that the tile would have if the GPU memory manager had 147 // a maximally permissive policy, send to the GPU memory manager 148 // to determine policy. 149 ManagedTileBin gpu_memmgr_stats_bin; 150 TileResolution resolution; 151 bool required_for_activation; 152 float time_to_needed_in_seconds; 153 float distance_to_visible_in_pixels; 154 bool visible_and_ready_to_draw; 155 156 // Priority for this state from the last time we assigned memory. 157 unsigned scheduled_priority; 158}; 159 160} // namespace cc 161 162#endif // CC_RESOURCES_MANAGED_TILE_STATE_H_ 163