OLD | NEW |
| (Empty) |
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/resource_pool.h" | |
11 #include "cc/resources/resource_provider.h" | |
12 #include "cc/resources/scoped_resource.h" | |
13 #include "cc/resources/tile_priority.h" | |
14 #include "cc/resources/tile_task_runner.h" | |
15 | |
16 namespace cc { | |
17 | |
18 // This is state that is specific to a tile that is | |
19 // managed by the TileManager. | |
20 class CC_EXPORT ManagedTileState { | |
21 public: | |
22 // This class holds all the state relevant to drawing a tile. | |
23 class CC_EXPORT DrawInfo { | |
24 public: | |
25 enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE }; | |
26 | |
27 DrawInfo(); | |
28 ~DrawInfo(); | |
29 | |
30 Mode mode() const { return mode_; } | |
31 | |
32 bool IsReadyToDraw() const; | |
33 | |
34 ResourceProvider::ResourceId get_resource_id() const { | |
35 DCHECK(mode_ == RESOURCE_MODE); | |
36 DCHECK(resource_); | |
37 | |
38 return resource_->id(); | |
39 } | |
40 | |
41 SkColor get_solid_color() const { | |
42 DCHECK(mode_ == SOLID_COLOR_MODE); | |
43 | |
44 return solid_color_; | |
45 } | |
46 | |
47 bool contents_swizzled() const { | |
48 DCHECK(resource_); | |
49 return !PlatformColor::SameComponentOrder(resource_->format()); | |
50 } | |
51 | |
52 bool requires_resource() const { | |
53 return mode_ == RESOURCE_MODE || mode_ == PICTURE_PILE_MODE; | |
54 } | |
55 | |
56 inline bool has_resource() const { return !!resource_; } | |
57 | |
58 void SetSolidColorForTesting(SkColor color) { set_solid_color(color); } | |
59 void SetResourceForTesting(scoped_ptr<ScopedResource> resource) { | |
60 resource_ = resource.Pass(); | |
61 } | |
62 | |
63 private: | |
64 friend class TileManager; | |
65 friend class PrioritizedTileSet; | |
66 friend class Tile; | |
67 friend class ManagedTileState; | |
68 | |
69 void set_use_resource() { mode_ = RESOURCE_MODE; } | |
70 | |
71 void set_solid_color(const SkColor& color) { | |
72 mode_ = SOLID_COLOR_MODE; | |
73 solid_color_ = color; | |
74 } | |
75 | |
76 void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; } | |
77 | |
78 Mode mode_; | |
79 SkColor solid_color_; | |
80 scoped_ptr<ScopedResource> resource_; | |
81 }; | |
82 | |
83 ManagedTileState(); | |
84 ~ManagedTileState(); | |
85 | |
86 void AsValueInto(base::debug::TracedValue* dict) const; | |
87 | |
88 // Persisted state: valid all the time. | |
89 DrawInfo draw_info; | |
90 scoped_refptr<RasterTask> raster_task; | |
91 | |
92 TileResolution resolution; | |
93 TilePriority::PriorityBin priority_bin; | |
94 | |
95 // Priority for this state from the last time we assigned memory. | |
96 unsigned scheduled_priority; | |
97 }; | |
98 | |
99 } // namespace cc | |
100 | |
101 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_ | |
OLD | NEW |