Enable Enhanced Bookmark on Android Tablet
[chromium-blink-merge.git] / cc / resources / managed_tile_state.h
blobfaba93cc2c6e1cf295a1a53a60973eabd4584f03
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"
16 namespace cc {
18 // This is state that is specific to a tile that is
19 // managed by the TileManager.
20 class CC_EXPORT ManagedTileState {
21 public:
22 // This class holds all the state relevant to drawing a tile.
23 class CC_EXPORT DrawInfo {
24 public:
25 enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, PICTURE_PILE_MODE };
27 DrawInfo();
28 ~DrawInfo();
30 Mode mode() const { return mode_; }
32 bool IsReadyToDraw() const;
34 ResourceProvider::ResourceId get_resource_id() const {
35 DCHECK(mode_ == RESOURCE_MODE);
36 DCHECK(resource_);
38 return resource_->id();
41 SkColor get_solid_color() const {
42 DCHECK(mode_ == SOLID_COLOR_MODE);
44 return solid_color_;
47 bool contents_swizzled() const {
48 DCHECK(resource_);
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();
63 private:
64 friend class TileManager;
65 friend class PrioritizedTileSet;
66 friend class Tile;
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;
73 solid_color_ = color;
76 void set_rasterize_on_demand() { mode_ = PICTURE_PILE_MODE; }
78 Mode mode_;
79 SkColor solid_color_;
80 scoped_ptr<ScopedResource> resource_;
83 ManagedTileState();
84 ~ManagedTileState();
86 void AsValueInto(base::debug::TracedValue* dict) const;
88 // Persisted state: valid all the time.
89 DrawInfo draw_info;
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;
99 } // namespace cc
101 #endif // CC_RESOURCES_MANAGED_TILE_STATE_H_