0

[cc] Tiles and tile manager for impl side painting

BUG=155209
R=enne@chromium.org


Review URL: https://chromiumcodereview.appspot.com/11369130

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166787 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
nduca@chromium.org
2012-11-08 22:42:34 +00:00
parent 09af6658cc
commit 18134fc48b
6 changed files with 208 additions and 0 deletions

@ -222,8 +222,13 @@
'thread_impl.h',
'thread_proxy.cc',
'thread_proxy.h',
'tile.cc',
'tile.h',
'tile_draw_quad.cc',
'tile_draw_quad.h',
'tile_manager.cc',
'tile_manager.h',
'tile_priority.h',
'tiled_layer.cc',
'tiled_layer.h',
'tiled_layer_impl.cc',

26
cc/tile.cc Normal file

@ -0,0 +1,26 @@
// 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.
#include "cc/tile.h"
#include "cc/tile_manager.h"
namespace cc {
Tile::Tile(TileManager* tile_manager,
gfx::Size tile_size,
gfx::Rect rect_inside_picture,
TileQuality quality)
: tile_manager_(tile_manager),
tile_size_(tile_size),
rect_inside_picture_(rect_inside_picture),
quality_(quality) {
tile_manager_->RegisterTile(this);
}
Tile::~Tile() {
tile_manager_->UnregisterTile(this);
}
} // namespace cc

50
cc/tile.h Normal file

@ -0,0 +1,50 @@
// 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_H_
#define CC_TILE_H_
#include "base/memory/ref_counted.h"
#include "cc/picture_pile.h"
#include "cc/resource_provider.h"
#include "cc/tile_priority.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace cc {
class TileManager;
enum TileQuality {
LOW_TILE_QUALITY,
NORMAL_TILE_QUALITY
};
class Tile : public base::RefCounted<Tile> {
public:
Tile(TileManager* tile_manager,
gfx::Size tile_size,
gfx::Rect rect_inside_picture,
TileQuality quality);
void SetPicturePile(int frame_number, scoped_ptr<PicturePile> picture_pile) {}
void SetPriority(int frame_number, TilePriority) {}
bool IsDrawable(int frame_number) { return false; }
ResourceProvider::ResourceId GetDrawableResourceId(int frame_number) { return 0; }
private:
friend class base::RefCounted<Tile>;
friend class TileManager;
~Tile();
TileManager* tile_manager_;
gfx::Rect tile_size_;
gfx::Rect rect_inside_picture_;
TileQuality quality_;
};
} // namespace cc
#endif

33
cc/tile_manager.cc Normal file

@ -0,0 +1,33 @@
// 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.
#include "cc/tile_manager.h"
#include "base/logging.h"
namespace cc {
TileManager::TileManager(TileManagerClient* client) {
}
TileManager::~TileManager() {
DCHECK(registered_tiles_.size() == 0);
}
void TileManager::RegisterTile(Tile* tile) {
registered_tiles_.push_back(tile);
}
void TileManager::UnregisterTile(Tile* tile) {
// TODO(nduca): Known slow. Shrug. Fish need frying.
for (size_t i = 0; i < registered_tiles_.size(); i++) {
if (registered_tiles_[i] == tile) {
registered_tiles_.erase(registered_tiles_.begin() + i);
return;
}
}
DCHECK(false) << "Tile " << tile << " wasnt regitered.";
}
}

47
cc/tile_manager.h Normal file

@ -0,0 +1,47 @@
// 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>
namespace cc {
class Tile;
class ResourceProvider;
class TileManagerClient {
public:
virtual void ScheduleManage() = 0;
protected:
~TileManagerClient() { }
};
// 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 Manage() { }
protected:
// Methods called by Tile
void RegisterTile(Tile*);
void UnregisterTile(Tile*);
private:
friend class Tile;
TileManagerClient* client_;
std::vector<Tile*> registered_tiles_;
};
}
#endif

47
cc/tile_priority.h Normal file

@ -0,0 +1,47 @@
// 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_PRIORTY_H_
#define CC_TILE_PRIORTY_H_
#include "base/memory/ref_counted.h"
#include "cc/picture_pile.h"
#include "cc/tile_priority.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace cc {
struct TilePriority {
// A given layer may have multiple tilings, of differing quality.
// would_be_drawn is set for the tiles that are visible that would be
// drawn if they were chosen.
bool would_be_drawn;
// Set to true for tiles that should be favored during, for example,
// scrolls.
bool on_primary_tree;
// Used to prefer tiles near to the viewport.
float distance_to_viewport;
// TODO(enne): some metric that penalizes blurriness.
};
class TilePriorityComparator {
public:
TilePriorityComparator(bool currently_scrolling)
: currently_scrolling_(currently_scrolling) {}
int compare(const TilePriority& a, const TilePriority& b) {
// TODO(nduca,enne): Implement a comparator using the attributes here.
return 0;
}
private:
bool currently_scrolling_;
};
} // namespace cc
#endif