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/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"
18 // This is state that is specific to a tile that is
19 // managed by the TileManager.
20 class CC_EXPORT ManagedTileState
{
22 // This class holds all the state relevant to drawing a tile.
23 class CC_EXPORT DrawInfo
{
25 enum Mode
{ RESOURCE_MODE
, SOLID_COLOR_MODE
, PICTURE_PILE_MODE
};
30 Mode
mode() const { return mode_
; }
32 bool IsReadyToDraw() const;
34 ResourceProvider::ResourceId
get_resource_id() const {
35 DCHECK(mode_
== RESOURCE_MODE
);
38 return resource_
->id();
41 SkColor
get_solid_color() const {
42 DCHECK(mode_
== SOLID_COLOR_MODE
);
47 bool contents_swizzled() const {
49 return !PlatformColor::SameComponentOrder(resource_
->format());
52 bool requires_resource() const {
53 return mode_
== RESOURCE_MODE
|| mode_
== PICTURE_PILE_MODE
;
56 inline bool has_resource() const { return !!resource_
; }
58 void SetSolidColorForTesting(SkColor color
) { set_solid_color(color
); }
59 void SetResourceForTesting(scoped_ptr
<ScopedResource
> resource
) {
60 resource_
= resource
.Pass();
64 friend class TileManager
;
65 friend class PrioritizedTileSet
;
67 friend class ManagedTileState
;
69 void set_use_resource() { mode_
= RESOURCE_MODE
; }
71 void set_solid_color(const SkColor
& color
) {
72 mode_
= SOLID_COLOR_MODE
;
76 void set_rasterize_on_demand() { mode_
= PICTURE_PILE_MODE
; }
80 scoped_ptr
<ScopedResource
> resource_
;
86 void AsValueInto(base::debug::TracedValue
* dict
) const;
88 // Persisted state: valid all the time.
90 scoped_refptr
<RasterTask
> raster_task
;
92 TileResolution resolution
;
93 TilePriority::PriorityBin priority_bin
;
95 // Priority for this state from the last time we assigned memory.
96 unsigned scheduled_priority
;
101 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_