Upstream version 6.35.121.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/raster_mode.h"
11 #include "cc/resources/raster_worker_pool.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"
16
17 namespace cc {
18
19 class TileManager;
20
21 // Tile manager classifying tiles into a few basic bins:
22 enum ManagedTileBin {
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.
31   NUM_BINS = 8
32   // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
33   // or reordering fields.
34 };
35 scoped_ptr<base::Value> ManagedTileBinAsValue(ManagedTileBin bin);
36
37 // This is state that is specific to a tile that is
38 // managed by the TileManager.
39 class CC_EXPORT ManagedTileState {
40  public:
41   class CC_EXPORT TileVersion {
42    public:
43     enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE };
44
45     TileVersion();
46     ~TileVersion();
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     size_t GPUMemoryUsageInBytes() const;
77
78     void SetSolidColorForTesting(SkColor color) { set_solid_color(color); }
79     void SetHasTextForTesting(bool has_text) { has_text_ = has_text; }
80     void SetResourceForTesting(scoped_ptr<ScopedResource> resource) {
81       resource_ = resource.Pass();
82     }
83
84    private:
85     friend class TileManager;
86     friend class PrioritizedTileSet;
87     friend class Tile;
88     friend class ManagedTileState;
89
90     void set_use_resource() { mode_ = RESOURCE_MODE; }
91
92     void set_solid_color(const SkColor& color) {
93       mode_ = SOLID_COLOR_MODE;
94       solid_color_ = color;
95     }
96
97     void set_has_text(bool has_text) { has_text_ = has_text; }
98
99     void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; }
100
101     Mode mode_;
102     SkColor solid_color_;
103     bool has_text_;
104     scoped_ptr<ScopedResource> resource_;
105     scoped_refptr<internal::RasterWorkerPoolTask> raster_task_;
106   };
107
108   ManagedTileState();
109   ~ManagedTileState();
110
111   scoped_ptr<base::Value> AsValue() const;
112
113   // Persisted state: valid all the time.
114   TileVersion tile_versions[NUM_RASTER_MODES];
115   RasterMode raster_mode;
116
117   ManagedTileBin bin;
118
119   TileResolution resolution;
120   bool required_for_activation;
121   TilePriority::PriorityBin priority_bin;
122   float distance_to_visible;
123   bool visible_and_ready_to_draw;
124
125   // Priority for this state from the last time we assigned memory.
126   unsigned scheduled_priority;
127 };
128
129 }  // namespace cc
130
131 #endif  // CC_RESOURCES_MANAGED_TILE_STATE_H_