OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_MANAGED_TILE_STATE_H_ | 5 #ifndef CC_RESOURCES_MANAGED_TILE_STATE_H_ |
6 #define CC_RESOURCES_MANAGED_TILE_STATE_H_ | 6 #define CC_RESOURCES_MANAGED_TILE_STATE_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "cc/resources/platform_color.h" | 9 #include "cc/resources/platform_color.h" |
10 #include "cc/resources/raster_worker_pool.h" | 10 #include "cc/resources/raster_worker_pool.h" |
11 #include "cc/resources/resource_pool.h" | 11 #include "cc/resources/resource_pool.h" |
12 #include "cc/resources/resource_provider.h" | 12 #include "cc/resources/resource_provider.h" |
13 #include "cc/resources/tile_manager.h" | 13 #include "cc/resources/tile_manager.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 | 16 |
17 enum TileVersionMemoryState { | |
18 NOT_ALLOWED_TO_USE_MEMORY, | |
19 CAN_USE_MEMORY, | |
20 USING_UNRELEASABLE_MEMORY, | |
21 USING_RELEASABLE_MEMORY | |
22 }; | |
23 | |
24 // This is state that is specific to a tile that is | 17 // This is state that is specific to a tile that is |
25 // managed by the TileManager. | 18 // managed by the TileManager. |
26 class CC_EXPORT ManagedTileState { | 19 class CC_EXPORT ManagedTileState { |
27 public: | 20 public: |
28 class CC_EXPORT TileVersion { | 21 class CC_EXPORT TileVersion { |
29 public: | 22 public: |
30 enum Mode { | 23 enum Mode { |
31 RESOURCE_MODE, | 24 RESOURCE_MODE, |
32 SOLID_COLOR_MODE, | 25 SOLID_COLOR_MODE, |
33 PICTURE_PILE_MODE, | 26 PICTURE_PILE_MODE, |
34 NUM_MODES | 27 NUM_MODES |
35 }; | 28 }; |
36 | 29 |
37 TileVersion(); | 30 TileVersion(); |
38 ~TileVersion(); | 31 ~TileVersion(); |
39 | 32 |
40 Mode mode() const { | 33 Mode mode() const { |
41 return mode_; | 34 return mode_; |
42 } | 35 } |
43 | 36 |
44 bool IsReadyToDraw() const; | 37 bool IsReadyToDraw() const; |
45 | 38 |
46 ResourceProvider::ResourceId get_resource_id() const { | 39 ResourceProvider::ResourceId get_resource_id() const { |
47 DCHECK(mode_ == RESOURCE_MODE); | 40 DCHECK(mode_ == RESOURCE_MODE); |
48 DCHECK(resource_id_); | 41 DCHECK(resource_id_); |
49 DCHECK(memory_state_ == USING_RELEASABLE_MEMORY || forced_upload_); | 42 DCHECK(resource_ || (resource_id_ && forced_upload_)); |
50 return resource_id_; | 43 return (resource_ ? resource_->id() : resource_id_); |
reveman
2013/06/03 18:07:23
nit: resource_->id() should be the same as resourc
vmpstr
2013/06/03 18:25:48
Done.
| |
51 } | 44 } |
52 | 45 |
53 SkColor get_solid_color() const { | 46 SkColor get_solid_color() const { |
54 DCHECK(mode_ == SOLID_COLOR_MODE); | 47 DCHECK(mode_ == SOLID_COLOR_MODE); |
55 | 48 |
56 return solid_color_; | 49 return solid_color_; |
57 } | 50 } |
58 | 51 |
59 bool contents_swizzled() const { | 52 bool contents_swizzled() const { |
60 return !PlatformColor::SameComponentOrder(resource_format_); | 53 return !PlatformColor::SameComponentOrder(resource_format_); |
61 } | 54 } |
62 | 55 |
63 bool requires_resource() const { | 56 bool requires_resource() const { |
64 return mode_ == RESOURCE_MODE || | 57 return mode_ == RESOURCE_MODE || |
65 mode_ == PICTURE_PILE_MODE; | 58 mode_ == PICTURE_PILE_MODE; |
66 } | 59 } |
67 | 60 |
68 size_t GPUMemoryUsageInBytes() const; | 61 size_t GPUMemoryUsageInBytes() const; |
69 | 62 |
70 void SetResourceForTesting(scoped_ptr<ResourcePool::Resource> resource) { | 63 void SetResourceForTesting(scoped_ptr<ResourcePool::Resource> resource) { |
71 resource_ = resource.Pass(); | 64 resource_ = resource.Pass(); |
72 resource_id_ = resource_->id(); | 65 resource_id_ = resource_->id(); |
73 } | 66 } |
74 | 67 |
75 scoped_ptr<ResourcePool::Resource>& GetResourceForTesting() { | 68 scoped_ptr<ResourcePool::Resource>& GetResourceForTesting() { |
76 return resource_; | 69 return resource_; |
77 } | 70 } |
78 | 71 |
79 void SetMemoryStateForTesting(TileVersionMemoryState state) { | |
80 memory_state_ = state; | |
81 } | |
82 | |
83 private: | 72 private: |
84 friend class TileManager; | 73 friend class TileManager; |
85 friend class Tile; | 74 friend class Tile; |
86 friend class ManagedTileState; | 75 friend class ManagedTileState; |
87 | 76 |
88 void set_use_resource() { | 77 void set_use_resource() { |
89 mode_ = RESOURCE_MODE; | 78 mode_ = RESOURCE_MODE; |
90 if (memory_state_ == NOT_ALLOWED_TO_USE_MEMORY) | |
91 memory_state_ = CAN_USE_MEMORY; | |
92 } | 79 } |
93 | 80 |
94 void set_solid_color(const SkColor& color) { | 81 void set_solid_color(const SkColor& color) { |
95 mode_ = SOLID_COLOR_MODE; | 82 mode_ = SOLID_COLOR_MODE; |
96 solid_color_ = color; | 83 solid_color_ = color; |
97 memory_state_ = NOT_ALLOWED_TO_USE_MEMORY; | |
98 resource_id_ = 0; | 84 resource_id_ = 0; |
99 } | 85 } |
100 | 86 |
101 void set_rasterize_on_demand() { | 87 void set_rasterize_on_demand() { |
102 mode_ = PICTURE_PILE_MODE; | 88 mode_ = PICTURE_PILE_MODE; |
103 memory_state_ = NOT_ALLOWED_TO_USE_MEMORY; | |
104 resource_id_ = 0; | 89 resource_id_ = 0; |
105 } | 90 } |
106 | 91 |
107 Mode mode_; | 92 Mode mode_; |
108 SkColor solid_color_; | 93 SkColor solid_color_; |
109 | 94 |
110 // TODO(reveman): Eliminate the need for both |resource_id_| | 95 // TODO(reveman): Eliminate the need for both |resource_id_| |
111 // and |resource| by re-factoring the "force upload" | 96 // and |resource| by re-factoring the "force upload" |
112 // mechanism. crbug.com/245767 | 97 // mechanism. crbug.com/245767 |
113 ResourceProvider::ResourceId resource_id_; | 98 ResourceProvider::ResourceId resource_id_; |
114 scoped_ptr<ResourcePool::Resource> resource_; | 99 scoped_ptr<ResourcePool::Resource> resource_; |
115 GLenum resource_format_; | 100 GLenum resource_format_; |
116 TileVersionMemoryState memory_state_; | |
117 bool forced_upload_; | 101 bool forced_upload_; |
118 }; | 102 }; |
119 | 103 |
120 | 104 |
121 ManagedTileState(); | 105 ManagedTileState(); |
122 ~ManagedTileState(); | 106 ~ManagedTileState(); |
123 | 107 |
124 scoped_ptr<base::Value> AsValue() const; | 108 scoped_ptr<base::Value> AsValue() const; |
125 | 109 |
126 // Persisted state: valid all the time. | 110 // Persisted state: valid all the time. |
(...skipping 21 matching lines...) Expand all Loading... | |
148 TileManagerBin gpu_memmgr_stats_bin; | 132 TileManagerBin gpu_memmgr_stats_bin; |
149 TileResolution resolution; | 133 TileResolution resolution; |
150 bool required_for_activation; | 134 bool required_for_activation; |
151 float time_to_needed_in_seconds; | 135 float time_to_needed_in_seconds; |
152 float distance_to_visible_in_pixels; | 136 float distance_to_visible_in_pixels; |
153 }; | 137 }; |
154 | 138 |
155 } // namespace cc | 139 } // namespace cc |
156 | 140 |
157 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_ | 141 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_ |
OLD | NEW |