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/rasterizer.h"
11 #include "cc/resources/resource_pool.h"
12 #include "cc/resources/resource_provider.h"
13 #include "cc/resources/scoped_resource.h"
14 #include "cc/resources/tile_priority.h"
20 // Tile manager classifying tiles into a few basic bins:
22 NOW_AND_READY_TO_DRAW_BIN
= 0, // Ready to draw and within viewport.
23 NOW_BIN
= 1, // Needed ASAP.
24 SOON_BIN
= 2, // Impl-side version of prepainting.
25 EVENTUALLY_AND_ACTIVE_BIN
= 3, // Nice to have, and has a task or resource.
26 EVENTUALLY_BIN
= 4, // Nice to have, if we've got memory and time.
27 AT_LAST_AND_ACTIVE_BIN
= 5, // Only do this after all other bins.
28 AT_LAST_BIN
= 6, // Only do this after all other bins.
29 NEVER_BIN
= 7, // Dont bother.
31 // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
32 // or reordering fields.
34 scoped_ptr
<base::Value
> ManagedTileBinAsValue(ManagedTileBin bin
);
36 // This is state that is specific to a tile that is
37 // managed by the TileManager.
38 class CC_EXPORT ManagedTileState
{
40 // This class holds all the state relevant to drawing a tile.
41 class CC_EXPORT DrawInfo
{
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 void SetSolidColorForTesting(SkColor color
) { set_solid_color(color
); }
77 void SetResourceForTesting(scoped_ptr
<ScopedResource
> resource
) {
78 resource_
= resource
.Pass();
82 friend class TileManager
;
83 friend class PrioritizedTileSet
;
85 friend class ManagedTileState
;
87 void set_use_resource() { mode_
= RESOURCE_MODE
; }
89 void set_solid_color(const SkColor
& color
) {
90 mode_
= SOLID_COLOR_MODE
;
94 void set_rasterize_on_demand() { mode_
= PICTURE_PILE_MODE
; }
98 scoped_ptr
<ScopedResource
> resource_
;
104 void AsValueInto(base::debug::TracedValue
* dict
) const;
106 // Persisted state: valid all the time.
108 scoped_refptr
<RasterTask
> raster_task
;
112 TileResolution resolution
;
113 bool required_for_activation
;
114 TilePriority::PriorityBin priority_bin
;
115 float distance_to_visible
;
116 bool visible_and_ready_to_draw
;
118 // Priority for this state from the last time we assigned memory.
119 unsigned scheduled_priority
;
124 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_