Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / resources / managed_tile_state.h
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/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"
15
16 namespace cc {
17
18 class TileManager;
19
20 // Tile manager classifying tiles into a few basic bins:
21 enum ManagedTileBin {
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.
30   NUM_BINS = 8
31   // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
32   // or reordering fields.
33 };
34 scoped_ptr<base::Value> ManagedTileBinAsValue(ManagedTileBin bin);
35
36 // This is state that is specific to a tile that is
37 // managed by the TileManager.
38 class CC_EXPORT ManagedTileState {
39  public:
40   // This class holds all the state relevant to drawing a tile.
41   class CC_EXPORT DrawInfo {
42    public:
43     enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE };
44
45     DrawInfo();
46     ~DrawInfo();
47
48     Mode mode() const { return mode_; }
49
50     bool IsReadyToDraw() const;
51
52     ResourceProvider::ResourceId get_resource_id() const {
53       DCHECK(mode_ == RESOURCE_MODE);
54       DCHECK(resource_);
55
56       return resource_->id();
57     }
58
59     SkColor get_solid_color() const {
60       DCHECK(mode_ == SOLID_COLOR_MODE);
61
62       return solid_color_;
63     }
64
65     bool contents_swizzled() const {
66       DCHECK(resource_);
67       return !PlatformColor::SameComponentOrder(resource_->format());
68     }
69
70     bool requires_resource() const {
71       return mode_ == RESOURCE_MODE || mode_ == PICTURE_PILE_MODE;
72     }
73
74     inline bool has_resource() const { return !!resource_; }
75
76     void SetSolidColorForTesting(SkColor color) { set_solid_color(color); }
77     void SetResourceForTesting(scoped_ptr<ScopedResource> resource) {
78       resource_ = resource.Pass();
79     }
80
81    private:
82     friend class TileManager;
83     friend class PrioritizedTileSet;
84     friend class Tile;
85     friend class ManagedTileState;
86
87     void set_use_resource() { mode_ = RESOURCE_MODE; }
88
89     void set_solid_color(const SkColor& color) {
90       mode_ = SOLID_COLOR_MODE;
91       solid_color_ = color;
92     }
93
94     void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; }
95
96     Mode mode_;
97     SkColor solid_color_;
98     scoped_ptr<ScopedResource> resource_;
99   };
100
101   ManagedTileState();
102   ~ManagedTileState();
103
104   void AsValueInto(base::debug::TracedValue* dict) const;
105
106   // Persisted state: valid all the time.
107   DrawInfo draw_info;
108   scoped_refptr<RasterTask> raster_task;
109
110   ManagedTileBin bin;
111
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;
117
118   // Priority for this state from the last time we assigned memory.
119   unsigned scheduled_priority;
120 };
121
122 }  // namespace cc
123
124 #endif  // CC_RESOURCES_MANAGED_TILE_STATE_H_