Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 8 | #include "base/memory/scoped_ptr.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 9 | #include "cc/resources/platform_color.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 10 | #include "cc/resources/raster_worker_pool.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 11 | #include "cc/resources/resource_pool.h" |
| 12 | #include "cc/resources/resource_provider.h" |
| 13 | #include "cc/resources/tile_manager.h" |
| 14 | |
| 15 | namespace cc { |
| 16 | |
| 17 | // This is state that is specific to a tile that is |
| 18 | // managed by the TileManager. |
| 19 | class CC_EXPORT ManagedTileState { |
| 20 | public: |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 21 | class CC_EXPORT TileVersion { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 22 | public: |
| 23 | enum Mode { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 24 | RESOURCE_MODE, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | SOLID_COLOR_MODE, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 26 | PICTURE_PILE_MODE, |
| 27 | NUM_MODES |
| 28 | }; |
| 29 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 30 | TileVersion(); |
| 31 | ~TileVersion(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 32 | |
| 33 | Mode mode() const { |
| 34 | return mode_; |
| 35 | } |
| 36 | |
| 37 | bool IsReadyToDraw() const; |
| 38 | |
| 39 | ResourceProvider::ResourceId get_resource_id() const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 40 | DCHECK(mode_ == RESOURCE_MODE); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 41 | |
| 42 | // We have to have a resource ID here. |
| 43 | DCHECK(resource_id_); |
| 44 | // If we have a resource, it implies IDs are equal. |
| 45 | DCHECK(!resource_ || (resource_id_ == resource_->id())); |
| 46 | // If we don't have a resource, it implies that we're in forced upload. |
| 47 | DCHECK(resource_ || (resource_id_ && forced_upload_)); |
| 48 | |
| 49 | return resource_id_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | SkColor get_solid_color() const { |
| 53 | DCHECK(mode_ == SOLID_COLOR_MODE); |
| 54 | |
| 55 | return solid_color_; |
| 56 | } |
| 57 | |
| 58 | bool contents_swizzled() const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 59 | return !PlatformColor::SameComponentOrder(resource_format_); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | bool requires_resource() const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 63 | return mode_ == RESOURCE_MODE || |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 64 | mode_ == PICTURE_PILE_MODE; |
| 65 | } |
| 66 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 67 | size_t GPUMemoryUsageInBytes() const; |
| 68 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 69 | void SetResourceForTesting(scoped_ptr<ResourcePool::Resource> resource) { |
| 70 | resource_ = resource.Pass(); |
| 71 | resource_id_ = resource_->id(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 74 | scoped_ptr<ResourcePool::Resource>& GetResourceForTesting() { |
| 75 | return resource_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 78 | private: |
| 79 | friend class TileManager; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 80 | friend class Tile; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 81 | friend class ManagedTileState; |
| 82 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 83 | void set_use_resource() { |
| 84 | mode_ = RESOURCE_MODE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void set_solid_color(const SkColor& color) { |
| 88 | mode_ = SOLID_COLOR_MODE; |
| 89 | solid_color_ = color; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 90 | resource_id_ = 0; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void set_rasterize_on_demand() { |
| 94 | mode_ = PICTURE_PILE_MODE; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 95 | resource_id_ = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | Mode mode_; |
| 99 | SkColor solid_color_; |
| 100 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 101 | // TODO(reveman): Eliminate the need for both |resource_id_| |
| 102 | // and |resource| by re-factoring the "force upload" |
| 103 | // mechanism. crbug.com/245767 |
| 104 | ResourceProvider::ResourceId resource_id_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 105 | scoped_ptr<ResourcePool::Resource> resource_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 106 | GLenum resource_format_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 107 | bool forced_upload_; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 108 | RasterWorkerPool::RasterTask raster_task_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | |
| 112 | ManagedTileState(); |
| 113 | ~ManagedTileState(); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 114 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 115 | scoped_ptr<base::Value> AsValue() const; |
| 116 | |
| 117 | // Persisted state: valid all the time. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 118 | TileVersion tile_versions[NUM_RASTER_MODES]; |
| 119 | TileRasterMode raster_mode; |
| 120 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 121 | bool picture_pile_analyzed; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame^] | 122 | PicturePileImpl::Analysis picture_pile_analysis; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 123 | |
| 124 | // Ephemeral state, valid only during TileManager::ManageTiles. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 125 | bool is_in_never_bin_on_both_trees() const { |
| 126 | return bin[HIGH_PRIORITY_BIN] == NEVER_BIN && |
| 127 | bin[LOW_PRIORITY_BIN] == NEVER_BIN; |
| 128 | } |
| 129 | bool is_in_now_bin_on_either_tree() const { |
| 130 | return bin[HIGH_PRIORITY_BIN] == NOW_BIN || |
| 131 | bin[LOW_PRIORITY_BIN] == NOW_BIN; |
| 132 | } |
| 133 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 134 | TileManagerBin bin[NUM_BIN_PRIORITIES]; |
| 135 | TileManagerBin tree_bin[NUM_TREES]; |
| 136 | |
| 137 | // The bin that the tile would have if the GPU memory manager had |
| 138 | // a maximally permissive policy, send to the GPU memory manager |
| 139 | // to determine policy. |
| 140 | TileManagerBin gpu_memmgr_stats_bin; |
| 141 | TileResolution resolution; |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 142 | bool required_for_activation; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 143 | float time_to_needed_in_seconds; |
| 144 | float distance_to_visible_in_pixels; |
| 145 | }; |
| 146 | |
| 147 | } // namespace cc |
| 148 | |
| 149 | #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_ |