managed_tile_state.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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#include "cc/resources/tile_manager.h" 14 15namespace cc { 16 17// This is state that is specific to a tile that is 18// managed by the TileManager. 19class CC_EXPORT ManagedTileState { 20 public: 21 class CC_EXPORT TileVersion { 22 public: 23 enum Mode { 24 RESOURCE_MODE, 25 SOLID_COLOR_MODE, 26 PICTURE_PILE_MODE, 27 NUM_MODES 28 }; 29 30 TileVersion(); 31 ~TileVersion(); 32 33 Mode mode() const { 34 return mode_; 35 } 36 37 bool IsReadyToDraw() const; 38 39 ResourceProvider::ResourceId get_resource_id() const { 40 DCHECK(mode_ == RESOURCE_MODE); 41 DCHECK(resource_); 42 43 return resource_->id(); 44 } 45 46 SkColor get_solid_color() const { 47 DCHECK(mode_ == SOLID_COLOR_MODE); 48 49 return solid_color_; 50 } 51 52 bool contents_swizzled() const { 53 DCHECK(resource_); 54 return !PlatformColor::SameComponentOrder(resource_->format()); 55 } 56 57 bool requires_resource() const { 58 return mode_ == RESOURCE_MODE || 59 mode_ == PICTURE_PILE_MODE; 60 } 61 62 size_t GPUMemoryUsageInBytes() const; 63 64 void SetResourceForTesting(scoped_ptr<ResourcePool::Resource> resource) { 65 resource_ = resource.Pass(); 66 } 67 const ResourcePool::Resource* GetResourceForTesting() const { 68 return resource_.get(); 69 } 70 void SetSolidColorForTesting(SkColor color) { 71 set_solid_color(color); 72 } 73 void SetHasTextForTesting(bool has_text) { 74 has_text_ = has_text; 75 } 76 77 private: 78 friend class TileManager; 79 friend class Tile; 80 friend class ManagedTileState; 81 82 void set_use_resource() { 83 mode_ = RESOURCE_MODE; 84 } 85 86 void set_solid_color(const SkColor& color) { 87 mode_ = SOLID_COLOR_MODE; 88 solid_color_ = color; 89 } 90 91 void set_has_text(bool has_text) { 92 has_text_ = has_text; 93 } 94 95 void set_rasterize_on_demand() { 96 mode_ = PICTURE_PILE_MODE; 97 } 98 99 Mode mode_; 100 SkColor solid_color_; 101 bool has_text_; 102 scoped_ptr<ResourcePool::Resource> resource_; 103 RasterWorkerPool::RasterTask raster_task_; 104 }; 105 106 ManagedTileState(); 107 ~ManagedTileState(); 108 109 scoped_ptr<base::Value> AsValue() const; 110 111 // Persisted state: valid all the time. 112 TileVersion tile_versions[NUM_RASTER_MODES]; 113 RasterMode raster_mode; 114 115 // Ephemeral state, valid only during TileManager::ManageTiles. 116 bool is_in_never_bin_on_both_trees() const { 117 return bin[HIGH_PRIORITY_BIN] == NEVER_BIN && 118 bin[LOW_PRIORITY_BIN] == NEVER_BIN; 119 } 120 bool is_in_now_bin_on_either_tree() const { 121 return bin[HIGH_PRIORITY_BIN] == NOW_BIN || 122 bin[LOW_PRIORITY_BIN] == NOW_BIN; 123 } 124 125 TileManagerBin bin[NUM_BIN_PRIORITIES]; 126 TileManagerBin tree_bin[NUM_TREES]; 127 128 // The bin that the tile would have if the GPU memory manager had 129 // a maximally permissive policy, send to the GPU memory manager 130 // to determine policy. 131 TileManagerBin gpu_memmgr_stats_bin; 132 TileResolution resolution; 133 bool required_for_activation; 134 float time_to_needed_in_seconds; 135 float distance_to_visible_in_pixels; 136}; 137 138} // namespace cc 139 140#endif // CC_RESOURCES_MANAGED_TILE_STATE_H_ 141