summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-07 08:18:37 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-07 08:18:37 +0000
commitd142a47d7d7322e262c43b244cc61f570a352d17 (patch)
treed7a877de2e772168086bc0790118995d9c7497a6
parent81a40f9fdbe68b86147ec62d84a546a11824c084 (diff)
downloadchromium_src-d142a47d7d7322e262c43b244cc61f570a352d17.zip
chromium_src-d142a47d7d7322e262c43b244cc61f570a352d17.tar.gz
chromium_src-d142a47d7d7322e262c43b244cc61f570a352d17.tar.bz2
cc: Use asynchronous set pixels API for impl-side painting.
BUG=161338 TEST=manual Review URL: https://chromiumcodereview.appspot.com/11348384 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171721 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--cc/layer_tree_host_impl.cc9
-rw-r--r--cc/layer_tree_host_impl.h2
-rw-r--r--cc/picture_layer_impl.cc4
-rw-r--r--cc/picture_layer_tiling_set.cc2
-rw-r--r--cc/test/fake_tile_manager_client.h2
-rw-r--r--cc/tile.cc9
-rw-r--r--cc/tile.h4
-rw-r--r--cc/tile_manager.cc56
-rw-r--r--cc/tile_manager.h13
9 files changed, 78 insertions, 23 deletions
diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc
index f006620..c295e92 100644
--- a/cc/layer_tree_host_impl.cc
+++ b/cc/layer_tree_host_impl.cc
@@ -712,6 +712,9 @@ bool LayerTreeHostImpl::prepareToDraw(FrameData& frame)
TRACE_EVENT0("cc", "LayerTreeHostImpl::prepareToDraw");
DCHECK(canDraw());
+ if (m_tileManager)
+ m_tileManager->CheckForCompletedSetPixels();
+
frame.renderSurfaceLayerList = &m_renderSurfaceLayerList;
frame.renderPasses.clear();
frame.renderPassesById.clear();
@@ -758,8 +761,12 @@ void LayerTreeHostImpl::ScheduleManageTiles()
m_client->setNeedsManageTilesOnImplThread();
}
-void LayerTreeHostImpl::ScheduleRedraw()
+void LayerTreeHostImpl::ScheduleCheckForCompletedSetPixels()
{
+ // CheckForCompletedSetPixels() should be called before we draw and
+ // preferably only once per vsync interval. For now just make sure
+ // a redraw is scheduled and call CheckForCompletedSetPixels() in
+ // prepareToDraw().
if (m_client)
m_client->setNeedsRedrawOnImplThread();
}
diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h
index f9059a4..07afc90 100644
--- a/cc/layer_tree_host_impl.h
+++ b/cc/layer_tree_host_impl.h
@@ -177,7 +177,7 @@ public:
// TileManagerClient implementation.
virtual void ScheduleManageTiles() OVERRIDE;
- virtual void ScheduleRedraw() OVERRIDE;
+ virtual void ScheduleCheckForCompletedSetPixels() OVERRIDE;
// WebCompositorOutputSurfaceClient implementation.
virtual void onVSyncParametersChanged(double monotonicTimebase, double intervalInSeconds) OVERRIDE;
diff --git a/cc/picture_layer_impl.cc b/cc/picture_layer_impl.cc
index 91ed959..4959d42 100644
--- a/cc/picture_layer_impl.cc
+++ b/cc/picture_layer_impl.cc
@@ -56,7 +56,7 @@ void PictureLayerImpl::appendQuads(QuadSink& quadSink,
++iter) {
SkColor color;
float width;
- if (*iter && iter->resource_id()) {
+ if (*iter && iter->GetResourceId()) {
color = DebugColors::TileBorderColor();
width = DebugColors::TileBorderWidth(layerTreeHostImpl());
} else {
@@ -77,7 +77,7 @@ void PictureLayerImpl::appendQuads(QuadSink& quadSink,
++iter) {
ResourceProvider::ResourceId resource = 0;
if (*iter)
- resource = iter->resource_id();
+ resource = iter->GetResourceId();
gfx::Rect geometry_rect = iter.geometry_rect();
diff --git a/cc/picture_layer_tiling_set.cc b/cc/picture_layer_tiling_set.cc
index 372ba2f..f8f8ac9 100644
--- a/cc/picture_layer_tiling_set.cc
+++ b/cc/picture_layer_tiling_set.cc
@@ -105,7 +105,7 @@ PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() {
// Loop until we find a valid place to stop.
while (true) {
- while (tiling_iter_ && !tiling_iter_->resource_id()) {
+ while (tiling_iter_ && !tiling_iter_->GetResourceId()) {
missing_region_.Union(tiling_iter_.geometry_rect());
++tiling_iter_;
}
diff --git a/cc/test/fake_tile_manager_client.h b/cc/test/fake_tile_manager_client.h
index 8458350..118cbdd 100644
--- a/cc/test/fake_tile_manager_client.h
+++ b/cc/test/fake_tile_manager_client.h
@@ -15,7 +15,7 @@ class FakeTileManagerClient : public TileManagerClient {
// TileManagerClient implementation.
virtual void ScheduleManageTiles() OVERRIDE {}
- virtual void ScheduleRedraw() OVERRIDE {}
+ virtual void ScheduleCheckForCompletedSetPixels() OVERRIDE {}
};
} // namespace cc
diff --git a/cc/tile.cc b/cc/tile.cc
index 1b04a5d..9ebaa51 100644
--- a/cc/tile.cc
+++ b/cc/tile.cc
@@ -33,6 +33,15 @@ void Tile::set_priority(WhichTree tree, const TilePriority& priority) {
priority_[tree] = priority;
}
+ResourceProvider::ResourceId Tile::GetResourceId() const {
+ if (!managed_state_.resource)
+ return 0;
+ if (managed_state_.resource_is_being_initialized)
+ return 0;
+
+ return managed_state_.resource->id();
+}
+
size_t Tile::bytes_consumed_if_allocated() const {
DCHECK(format_ == GL_RGBA);
return 4 * tile_size_.width() * tile_size_.height();
diff --git a/cc/tile.h b/cc/tile.h
index f3702f7..0c8e05d 100644
--- a/cc/tile.h
+++ b/cc/tile.h
@@ -45,9 +45,7 @@ class CC_EXPORT Tile : public base::RefCounted<Tile> {
void set_priority(WhichTree tree, const TilePriority& priority);
// Returns 0 if not drawable.
- ResourceProvider::ResourceId resource_id() const {
- return managed_state_.resource ? managed_state_.resource->id() : 0;
- }
+ ResourceProvider::ResourceId GetResourceId() const;
const gfx::Rect& opaque_rect() const { return opaque_rect_; }
diff --git a/cc/tile_manager.cc b/cc/tile_manager.cc
index 80c2c74..53ef4da 100644
--- a/cc/tile_manager.cc
+++ b/cc/tile_manager.cc
@@ -116,7 +116,8 @@ TileManager::TileManager(
: client_(client),
resource_pool_(ResourcePool::Create(resource_provider,
Renderer::ImplPool)),
- manage_tiles_pending_(false) {
+ manage_tiles_pending_(false),
+ check_for_completed_set_pixels_pending_(false) {
// Initialize all threads.
const std::string thread_name_prefix = kRasterThreadNamePrefix;
while (raster_threads_.size() < num_raster_threads) {
@@ -175,6 +176,13 @@ void TileManager::ScheduleManageTiles() {
manage_tiles_pending_ = true;
}
+void TileManager::ScheduleCheckForCompletedSetPixels() {
+ if (check_for_completed_set_pixels_pending_)
+ return;
+ client_->ScheduleCheckForCompletedSetPixels();
+ check_for_completed_set_pixels_pending_ = true;
+}
+
class BinComparator {
public:
bool operator() (const Tile* a, const Tile* b) const {
@@ -279,6 +287,29 @@ void TileManager::ManageTiles() {
DispatchMoreRasterTasks();
}
+void TileManager::CheckForCompletedSetPixels() {
+ check_for_completed_set_pixels_pending_ = false;
+
+ while (!tiles_with_pending_set_pixels_.empty()) {
+ Tile* tile = tiles_with_pending_set_pixels_.front();
+ DCHECK(tile->managed_state().resource);
+
+ // Set pixel tasks complete in the order they are posted.
+ if (!resource_pool_->resource_provider()->didSetPixelsComplete(
+ tile->managed_state().resource->id())) {
+ ScheduleCheckForCompletedSetPixels();
+ break;
+ }
+
+ // It's now safe to release the pixel buffer.
+ resource_pool_->resource_provider()->releasePixelBuffer(
+ tile->managed_state().resource->id());
+
+ DidFinishTileInitialization(tile);
+ tiles_with_pending_set_pixels_.pop();
+ }
+}
+
void TileManager::renderingStats(RenderingStats* stats) {
stats->totalRasterizeTimeInSeconds =
rendering_stats_.totalRasterizeTimeInSeconds;
@@ -420,16 +451,20 @@ void TileManager::OnRasterTaskCompleted(
// Finish resource initialization if |can_use_gpu_memory| is true.
if (managed_tile_state.can_use_gpu_memory) {
- resource_pool_->resource_provider()->setPixelsFromBuffer(resource->id());
- resource_pool_->resource_provider()->releasePixelBuffer(resource->id());
-
- // The component order may be bgra if we uploaded bgra pixels to rgba
+ // The component order may be bgra if we're uploading bgra pixels to rgba
// texture. Mark contents as swizzled if image component order is
// different than texture format.
managed_tile_state.contents_swizzled =
!PlatformColor::sameComponentOrder(tile->format_);
- DidFinishTileInitialization(tile, resource.Pass());
+ // Tile resources can't be freed until upload has completed.
+ managed_tile_state.can_be_freed = false;
+
+ resource_pool_->resource_provider()->beginSetPixels(resource->id());
+ managed_tile_state.resource = resource.Pass();
+ tiles_with_pending_set_pixels_.push(tile);
+
+ ScheduleCheckForCompletedSetPixels();
} else {
resource_pool_->resource_provider()->releasePixelBuffer(resource->id());
resource_pool_->ReleaseResource(resource.Pass());
@@ -439,14 +474,11 @@ void TileManager::OnRasterTaskCompleted(
DispatchMoreRasterTasks();
}
-void TileManager::DidFinishTileInitialization(
- Tile* tile, scoped_ptr<ResourcePool::Resource> resource) {
+void TileManager::DidFinishTileInitialization(Tile* tile) {
ManagedTileState& managed_tile_state = tile->managed_state();
- DCHECK(!managed_tile_state.resource);
- managed_tile_state.resource = resource.Pass();
+ DCHECK(managed_tile_state.resource);
managed_tile_state.resource_is_being_initialized = false;
- // TODO(qinmin): Make this conditional on managed_tile_state.bin == NOW_BIN.
- client_->ScheduleRedraw();
+ managed_tile_state.can_be_freed = true;
}
}
diff --git a/cc/tile_manager.h b/cc/tile_manager.h
index 43c9064..31826ae 100644
--- a/cc/tile_manager.h
+++ b/cc/tile_manager.h
@@ -5,6 +5,7 @@
#ifndef CC_TILE_MANAGER_H_
#define CC_TILE_MANAGER_H_
+#include <queue>
#include <vector>
#include "base/memory/scoped_ptr.h"
@@ -23,7 +24,7 @@ struct RenderingStats;
class CC_EXPORT TileManagerClient {
public:
virtual void ScheduleManageTiles() = 0;
- virtual void ScheduleRedraw() = 0;
+ virtual void ScheduleCheckForCompletedSetPixels() = 0;
protected:
virtual ~TileManagerClient() {}
@@ -74,6 +75,7 @@ class CC_EXPORT TileManager {
void SetGlobalState(const GlobalStateThatImpactsTilePriority& state);
void ManageTiles();
+ void CheckForCompletedSetPixels();
void renderingStats(RenderingStats* stats);
@@ -88,6 +90,7 @@ class CC_EXPORT TileManager {
void AssignGpuMemoryToTiles();
void FreeResourcesForTile(Tile*);
void ScheduleManageTiles();
+ void ScheduleCheckForCompletedSetPixels();
void DispatchMoreRasterTasks();
void DispatchOneRasterTask(RasterThread*, scoped_refptr<Tile>);
void OnRasterTaskCompleted(
@@ -95,11 +98,12 @@ class CC_EXPORT TileManager {
scoped_ptr<ResourcePool::Resource>,
scoped_refptr<PicturePileImpl>,
RenderingStats*);
- void DidFinishTileInitialization(Tile*, scoped_ptr<ResourcePool::Resource>);
+ void DidFinishTileInitialization(Tile*);
TileManagerClient* client_;
scoped_ptr<ResourcePool> resource_pool_;
bool manage_tiles_pending_;
+ bool check_for_completed_set_pixels_pending_;
GlobalStateThatImpactsTilePriority global_state_;
@@ -107,10 +111,15 @@ class CC_EXPORT TileManager {
TileVector tiles_;
TileVector tiles_that_need_to_be_rasterized_;
+ typedef std::queue<scoped_refptr<Tile> > TileQueue;
+ TileQueue tiles_with_pending_set_pixels_;
+
typedef ScopedPtrVector<RasterThread> RasterThreadVector;
RasterThreadVector raster_threads_;
RenderingStats rendering_stats_;
+
+ DISALLOW_COPY_AND_ASSIGN(TileManager);
};
} // namespace cc