summaryrefslogtreecommitdiffstats
path: root/cc/tile_manager.h
blob: 8f6bf8811b1f3083bb496c46a48e0bf08cf7971a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TILE_MANAGER_H_
#define CC_TILE_MANAGER_H_

#include <vector>

#include "base/values.h"
#include "cc/layer_tree_host_impl.h"
#include "cc/tile_priority.h"

namespace cc {

class Tile;
class TileVersion;
class ResourceProvider;

class TileManagerClient {
 public:
  virtual void ScheduleManageTiles() = 0;

 protected:
  virtual ~TileManagerClient() {}
};

// Tile manager classifying tiles into a few basic
// bins:
enum TileManagerBin {
  NOW_BIN = 0, // Needed ASAP.
  SOON_BIN = 1, // Impl-side version of prepainting.
  EVENTUALLY_BIN = 2, // Nice to have, if we've got memory and time.
  NEVER_BIN = 3, // Dont bother.
  NUM_BINS = 4
};

// This is state that is specific to a tile that is
// managed by the TileManager.
class ManagedTileState {
 public:
  ManagedTileState()
    : can_use_gpu_memory(false)
    , resource_id(0)
    , resource_id_can_be_freed(0) {}

  // Persisted state: valid all the time.
  bool can_use_gpu_memory;
  ResourceProvider::ResourceId resource_id;
  bool resource_id_can_be_freed;

  // Ephemeral state, valid only during Manage.
  TileManagerBin bin;
  TileResolution resolution;
  float time_to_needed_in_seconds;
};

// This class manages tiles, deciding which should get rasterized and which
// should no longer have any memory assigned to them. Tile objects are "owned"
// by layers; they automatically register with the manager when they are
// created, and unregister from the manager when they are deleted.
class TileManager {
 public:
  TileManager(TileManagerClient* client);
  ~TileManager();

  void SetGlobalState(const GlobalStateThatImpactsTilePriority& state);
  void ManageTiles();

 protected:
  // Methods called by Tile
  friend class Tile;
  void RegisterTile(Tile*);
  void UnregisterTile(Tile*);
  void WillModifyTilePriority(Tile*, WhichTree, const TilePriority& new_priority);

 private:
  void FreeResourcesForTile(Tile*);
  void ScheduleManageTiles();
  void ScheduleMorePaintingJobs();

  TileManagerClient* client_;
  bool manage_tiles_pending_;

  GlobalStateThatImpactsTilePriority global_state_;

  typedef std::vector<Tile*> TileVector;
  TileVector tiles_;
  TileVector tiles_that_need_to_be_painted_;
};

}  // namespace cc

#endif  // CC_TILE_MANAGER_H_