Upstream version 5.34.104.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_worker_pool.h"
11 #include "cc/resources/resource_pool.h"
12 #include "cc/resources/resource_provider.h"
13 #include "cc/resources/scoped_resource.h"
14
15 namespace cc {
16
17 class TileManager;
18
19 // Tile manager classifying tiles into a few basic bins:
20 enum ManagedTileBin {
21   NOW_AND_READY_TO_DRAW_BIN = 0,  // Ready to draw and within viewport.
22   NOW_BIN = 1,                    // Needed ASAP.
23   SOON_BIN = 2,                   // Impl-side version of prepainting.
24   EVENTUALLY_AND_ACTIVE_BIN = 3,  // Nice to have, and has a task or resource.
25   EVENTUALLY_BIN = 4,             // Nice to have, if we've got memory and time.
26   AT_LAST_AND_ACTIVE_BIN = 5,     // Only do this after all other bins.
27   AT_LAST_BIN = 6,                // Only do this after all other bins.
28   NEVER_BIN = 7,                  // Dont bother.
29   NUM_BINS = 8
30   // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
31   // or reordering fields.
32 };
33 scoped_ptr<base::Value> ManagedTileBinAsValue(ManagedTileBin bin);
34
35 // This is state that is specific to a tile that is
36 // managed by the TileManager.
37 class CC_EXPORT ManagedTileState {
38  public:
39   class CC_EXPORT TileVersion {
40    public:
41     enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE };
42
43     TileVersion();
44     ~TileVersion();
45
46     Mode mode() const { return mode_; }
47
48     bool IsReadyToDraw() const;
49
50     ResourceProvider::ResourceId get_resource_id() const {
51       DCHECK(mode_ == RESOURCE_MODE);
52       DCHECK(resource_);
53
54       return resource_->id();
55     }
56
57     SkColor get_solid_color() const {
58       DCHECK(mode_ == SOLID_COLOR_MODE);
59
60       return solid_color_;
61     }
62
63     bool contents_swizzled() const {
64       DCHECK(resource_);
65       return !PlatformColor::SameComponentOrder(resource_->format());
66     }
67
68     bool requires_resource() const {
69       return mode_ == RESOURCE_MODE || mode_ == PICTURE_PILE_MODE;
70     }
71
72     size_t GPUMemoryUsageInBytes() const;
73
74     void SetSolidColorForTesting(SkColor color) { set_solid_color(color); }
75     void SetHasTextForTesting(bool has_text) { has_text_ = has_text; }
76
77    private:
78     friend class TileManager;
79     friend class PrioritizedTileSet;
80     friend class Tile;
81     friend class ManagedTileState;
82
83     void set_use_resource() { mode_ = RESOURCE_MODE; }
84
85     void set_solid_color(const SkColor& color) {
86       mode_ = SOLID_COLOR_MODE;
87       solid_color_ = color;
88     }
89
90     void set_has_text(bool has_text) { has_text_ = has_text; }
91
92     void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; }
93
94     Mode mode_;
95     SkColor solid_color_;
96     bool has_text_;
97     scoped_ptr<ScopedResource> resource_;
98     RasterWorkerPool::RasterTask raster_task_;
99   };
100
101   ManagedTileState();
102   ~ManagedTileState();
103
104   scoped_ptr<base::Value> AsValue() const;
105
106   // Persisted state: valid all the time.
107   TileVersion tile_versions[NUM_RASTER_MODES];
108   RasterMode raster_mode;
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_