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.
5 #ifndef CC_RESOURCES_MANAGED_TILE_STATE_H_
6 #define CC_RESOURCES_MANAGED_TILE_STATE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/resources/platform_color.h"
10 #include "cc/resources/raster_mode.h"
11 #include "cc/resources/rasterizer.h"
12 #include "cc/resources/resource_pool.h"
13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/scoped_resource.h"
15 #include "cc/resources/tile_priority.h"
21 // Tile manager classifying tiles into a few basic bins:
23 NOW_AND_READY_TO_DRAW_BIN
= 0, // Ready to draw and within viewport.
24 NOW_BIN
= 1, // Needed ASAP.
25 SOON_BIN
= 2, // Impl-side version of prepainting.
26 EVENTUALLY_AND_ACTIVE_BIN
= 3, // Nice to have, and has a task or resource.
27 EVENTUALLY_BIN
= 4, // Nice to have, if we've got memory and time.
28 AT_LAST_AND_ACTIVE_BIN
= 5, // Only do this after all other bins.
29 AT_LAST_BIN
= 6, // Only do this after all other bins.
30 NEVER_BIN
= 7, // Dont bother.
32 // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
33 // or reordering fields.
35 scoped_ptr
<base::Value
> ManagedTileBinAsValue(ManagedTileBin bin
);
37 // This is state that is specific to a tile that is
38 // managed by the TileManager.
39 class CC_EXPORT ManagedTileState
{
41 class CC_EXPORT TileVersion
{
43 enum Mode
{ RESOURCE_MODE
, SOLID_COLOR_MODE
, PICTURE_PILE_MODE
};
48 Mode
mode() const { return mode_
; }
50 bool IsReadyToDraw() const;
52 ResourceProvider::ResourceId
get_resource_id() const {
53 DCHECK(mode_
== RESOURCE_MODE
);
56 return resource_
->id();
59 SkColor
get_solid_color() const {
60 DCHECK(mode_
== SOLID_COLOR_MODE
);
65 bool contents_swizzled() const {
67 return !PlatformColor::SameComponentOrder(resource_
->format());
70 bool requires_resource() const {
71 return mode_
== RESOURCE_MODE
|| mode_
== PICTURE_PILE_MODE
;
74 inline bool has_resource() const { return !!resource_
; }
76 size_t GPUMemoryUsageInBytes() const;
78 void SetSolidColorForTesting(SkColor color
) { set_solid_color(color
); }
79 void SetResourceForTesting(scoped_ptr
<ScopedResource
> resource
) {
80 resource_
= resource
.Pass();
84 friend class TileManager
;
85 friend class PrioritizedTileSet
;
87 friend class ManagedTileState
;
89 void set_use_resource() { mode_
= RESOURCE_MODE
; }
91 void set_solid_color(const SkColor
& color
) {
92 mode_
= SOLID_COLOR_MODE
;
96 void set_rasterize_on_demand() { mode_
= PICTURE_PILE_MODE
; }
100 scoped_ptr
<ScopedResource
> resource_
;
101 scoped_refptr
<RasterTask
> raster_task_
;
107 void AsValueInto(base::debug::TracedValue
* dict
) const;
109 // Persisted state: valid all the time.
110 TileVersion tile_versions
[NUM_RASTER_MODES
];
111 RasterMode raster_mode
;
115 TileResolution resolution
;
116 bool required_for_activation
;
117 TilePriority::PriorityBin priority_bin
;
118 float distance_to_visible
;
119 bool visible_and_ready_to_draw
;
121 // Priority for this state from the last time we assigned memory.
122 unsigned scheduled_priority
;
127 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_