Skip to content

Commit

Permalink
Revert 278654 "cc: Start using raster/eviction iterators in tile..."
Browse files Browse the repository at this point in the history
> cc: Start using raster/eviction iterators in tile manager
> 
> This patch is a part of the series that enables raster
> and eviction iterators in cc. In particular, this patch
> actually starts using the iterators that have landed
> previously. There should be a perf improvement for the
> manage tiles case. Other than that, there should be no perf
> impact.
> 
> This patch's main contribution is that it opens the door for
> more optimizations to be done in the future. As well, it
> simplifies the logic we have in tile manager.
> 
> BUG=329686
> R=enne, reveman
> 
> Review URL: https://codereview.chromium.org/246673005

BUG=329686, 387669, 387652
TBR=vmpstr@chromium.org

Review URL: https://codereview.chromium.org/354463002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279160 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
vmpstr@google.com committed Jun 23, 2014
1 parent b465946 commit 847389f
Show file tree
Hide file tree
Showing 17 changed files with 1,839 additions and 235 deletions.
3 changes: 3 additions & 0 deletions cc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ component("cc") {
"resources/prioritized_resource.h",
"resources/prioritized_resource_manager.cc",
"resources/prioritized_resource_manager.h",
"resources/prioritized_tile_set.cc",
"resources/prioritized_tile_set.h",
"resources/priority_calculator.cc",
"resources/priority_calculator.h",
"resources/raster_mode.cc",
Expand Down Expand Up @@ -706,6 +708,7 @@ test("cc_unittests") {
"resources/picture_pile_unittest.cc",
"resources/picture_unittest.cc",
"resources/prioritized_resource_unittest.cc",
"resources/prioritized_tile_set_unittest.cc",
"resources/raster_worker_pool_unittest.cc",
"resources/resource_provider_unittest.cc",
"resources/resource_update_controller_unittest.cc",
Expand Down
2 changes: 2 additions & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@
'resources/prioritized_resource.h',
'resources/prioritized_resource_manager.cc',
'resources/prioritized_resource_manager.h',
'resources/prioritized_tile_set.cc',
'resources/prioritized_tile_set.h',
'resources/priority_calculator.cc',
'resources/priority_calculator.h',
'resources/raster_mode.cc',
Expand Down
1 change: 1 addition & 0 deletions cc/cc_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'resources/picture_pile_unittest.cc',
'resources/picture_unittest.cc',
'resources/prioritized_resource_unittest.cc',
'resources/prioritized_tile_set_unittest.cc',
'resources/raster_worker_pool_unittest.cc',
'resources/resource_provider_unittest.cc',
'resources/resource_update_controller_unittest.cc',
Expand Down
20 changes: 13 additions & 7 deletions cc/layers/heads_up_display_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas,
int right,
int top,
int width) const {
if (!memory_entry_.total_bytes_used)
if (!memory_entry_.bytes_total())
return SkRect::MakeEmpty();

const int kPadding = 4;
Expand All @@ -468,7 +468,7 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas,
const int left = bounds().width() - width - right;
const SkRect area = SkRect::MakeXYWH(left, top, width, height);

const double kMegabyte = 1024.0 * 1024.0;
const double megabyte = 1024.0 * 1024.0;

SkPaint paint = CreatePaint();
DrawGraphBackground(canvas, &paint, area);
Expand All @@ -487,14 +487,20 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas,
kFontHeight,
title_pos);

std::string text = base::StringPrintf(
"%6.1f MB used", memory_entry_.total_bytes_used / kMegabyte);
std::string text =
base::StringPrintf("%6.1f MB used",
(memory_entry_.bytes_unreleasable +
memory_entry_.bytes_allocated) / megabyte);
DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos);

if (!memory_entry_.had_enough_memory)
if (memory_entry_.bytes_over) {
paint.setColor(SK_ColorRED);
text = base::StringPrintf("%6.1f MB max ",
memory_entry_.total_budget_in_bytes / kMegabyte);
text = base::StringPrintf("%6.1f MB over",
memory_entry_.bytes_over / megabyte);
} else {
text = base::StringPrintf("%6.1f MB max ",
memory_entry_.total_budget_in_bytes / megabyte);
}
DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos);

return area;
Expand Down
2 changes: 1 addition & 1 deletion cc/resources/memory_history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void MemoryHistory::GetMinAndMax(size_t* min, size_t* max) const {
*max = 0;

for (RingBufferType::Iterator it = ring_buffer_.Begin(); it; ++it) {
size_t bytes_total = it->total_bytes_used;
size_t bytes_total = it->bytes_total();

if (bytes_total < *min)
*min = bytes_total;
Expand Down
13 changes: 9 additions & 4 deletions cc/resources/memory_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ class MemoryHistory {
struct Entry {
Entry()
: total_budget_in_bytes(0),
total_bytes_used(0),
had_enough_memory(false) {}
bytes_allocated(0),
bytes_unreleasable(0),
bytes_over(0) {}

size_t total_budget_in_bytes;
size_t total_bytes_used;
bool had_enough_memory;
size_t bytes_allocated;
size_t bytes_unreleasable;
size_t bytes_over;
size_t bytes_total() const {
return bytes_allocated + bytes_unreleasable + bytes_over;
}
};

void SaveEntry(const Entry& entry);
Expand Down
140 changes: 140 additions & 0 deletions cc/resources/prioritized_tile_set.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2013 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/resources/prioritized_tile_set.h"

#include <algorithm>

#include "cc/resources/managed_tile_state.h"
#include "cc/resources/tile.h"

namespace cc {

class BinComparator {
public:
bool operator()(const Tile* a,
const Tile* b) const {
const ManagedTileState& ams = a->managed_state();
const ManagedTileState& bms = b->managed_state();

if (ams.priority_bin != bms.priority_bin)
return ams.priority_bin < bms.priority_bin;

if (ams.required_for_activation != bms.required_for_activation)
return ams.required_for_activation;

if (ams.resolution != bms.resolution)
return ams.resolution < bms.resolution;

if (ams.distance_to_visible != bms.distance_to_visible)
return ams.distance_to_visible < bms.distance_to_visible;

gfx::Rect a_rect = a->content_rect();
gfx::Rect b_rect = b->content_rect();
if (a_rect.y() != b_rect.y())
return a_rect.y() < b_rect.y();
return a_rect.x() < b_rect.x();
}
};

namespace {

typedef std::vector<Tile*> TileVector;

void SortBinTiles(ManagedTileBin bin, TileVector* tiles) {
switch (bin) {
case NOW_AND_READY_TO_DRAW_BIN:
case NEVER_BIN:
break;
case NOW_BIN:
case SOON_BIN:
case EVENTUALLY_AND_ACTIVE_BIN:
case EVENTUALLY_BIN:
case AT_LAST_AND_ACTIVE_BIN:
case AT_LAST_BIN:
std::sort(tiles->begin(), tiles->end(), BinComparator());
break;
default:
NOTREACHED();
}
}

} // namespace

PrioritizedTileSet::PrioritizedTileSet() {
for (int bin = 0; bin < NUM_BINS; ++bin)
bin_sorted_[bin] = true;
}

PrioritizedTileSet::~PrioritizedTileSet() {}

void PrioritizedTileSet::InsertTile(Tile* tile, ManagedTileBin bin) {
tiles_[bin].push_back(tile);
bin_sorted_[bin] = false;
}

void PrioritizedTileSet::Clear() {
for (int bin = 0; bin < NUM_BINS; ++bin) {
tiles_[bin].clear();
bin_sorted_[bin] = true;
}
}

void PrioritizedTileSet::SortBinIfNeeded(ManagedTileBin bin) {
if (!bin_sorted_[bin]) {
SortBinTiles(bin, &tiles_[bin]);
bin_sorted_[bin] = true;
}
}

PrioritizedTileSet::Iterator::Iterator(
PrioritizedTileSet* tile_set, bool use_priority_ordering)
: tile_set_(tile_set),
current_bin_(NOW_AND_READY_TO_DRAW_BIN),
use_priority_ordering_(use_priority_ordering) {
if (use_priority_ordering_)
tile_set_->SortBinIfNeeded(current_bin_);
iterator_ = tile_set->tiles_[current_bin_].begin();
if (iterator_ == tile_set_->tiles_[current_bin_].end())
AdvanceList();
}

PrioritizedTileSet::Iterator::~Iterator() {}

void PrioritizedTileSet::Iterator::DisablePriorityOrdering() {
use_priority_ordering_ = false;
}

PrioritizedTileSet::Iterator&
PrioritizedTileSet::Iterator::operator++() {
// We can't increment past the end of the tiles.
DCHECK(iterator_ != tile_set_->tiles_[current_bin_].end());

++iterator_;
if (iterator_ == tile_set_->tiles_[current_bin_].end())
AdvanceList();
return *this;
}

Tile* PrioritizedTileSet::Iterator::operator*() {
DCHECK(iterator_ != tile_set_->tiles_[current_bin_].end());
return *iterator_;
}

void PrioritizedTileSet::Iterator::AdvanceList() {
DCHECK(iterator_ == tile_set_->tiles_[current_bin_].end());

while (current_bin_ != NEVER_BIN) {
current_bin_ = static_cast<ManagedTileBin>(current_bin_ + 1);

if (use_priority_ordering_)
tile_set_->SortBinIfNeeded(current_bin_);

iterator_ = tile_set_->tiles_[current_bin_].begin();
if (iterator_ != tile_set_->tiles_[current_bin_].end())
break;
}
}

} // namespace cc
59 changes: 59 additions & 0 deletions cc/resources/prioritized_tile_set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2013 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_RESOURCES_PRIORITIZED_TILE_SET_H_
#define CC_RESOURCES_PRIORITIZED_TILE_SET_H_

#include <vector>

#include "cc/base/cc_export.h"
#include "cc/resources/managed_tile_state.h"

namespace cc {
class Tile;

class CC_EXPORT PrioritizedTileSet {
public:
PrioritizedTileSet();
~PrioritizedTileSet();

void InsertTile(Tile* tile, ManagedTileBin bin);
void Clear();

class CC_EXPORT Iterator {
public:
Iterator(PrioritizedTileSet* set, bool use_priority_ordering);

~Iterator();

void DisablePriorityOrdering();

Iterator& operator++();
Tile* operator->() { return *(*this); }
Tile* operator*();
operator bool() const {
return iterator_ != tile_set_->tiles_[current_bin_].end();
}

private:
void AdvanceList();

PrioritizedTileSet* tile_set_;
ManagedTileBin current_bin_;
std::vector<Tile*>::iterator iterator_;
bool use_priority_ordering_;
};

private:
friend class Iterator;

void SortBinIfNeeded(ManagedTileBin bin);

std::vector<Tile*> tiles_[NUM_BINS];
bool bin_sorted_[NUM_BINS];
};

} // namespace cc

#endif // CC_RESOURCES_PRIORITIZED_TILE_SET_H_
Loading

0 comments on commit 847389f

Please sign in to comment.