Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1000)

Unified Diff: cc/resources/resource_provider.cc

Issue 49163004: cc: Reduce command buffer flushes related to creating texture ids. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add LayerTreeSettings::texture_id_allocation_chunk_size Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/resources/resource_provider.cc
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 874fe3f641907df4c4e2b198316ce662d639b2a2..36c6f9e62727549997d32875d1fd6e7182a754e9 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -216,12 +216,14 @@ scoped_ptr<ResourceProvider> ResourceProvider::Create(
OutputSurface* output_surface,
SharedBitmapManager* shared_bitmap_manager,
int highp_threshold_min,
- bool use_rgba_4444_texture_format) {
+ bool use_rgba_4444_texture_format,
+ size_t texture_id_allocation_chunk_size) {
scoped_ptr<ResourceProvider> resource_provider(
new ResourceProvider(output_surface,
shared_bitmap_manager,
highp_threshold_min,
- use_rgba_4444_texture_format));
+ use_rgba_4444_texture_format,
+ texture_id_allocation_chunk_size));
bool success = false;
if (resource_provider->Context3d()) {
@@ -647,7 +649,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
context3d->waitSyncPoint(resource->mailbox.sync_point()));
resource->mailbox.ResetSyncPoint();
}
- resource->gl_id = context3d->createTexture();
+ resource->gl_id = NextTextureId();
GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id));
GLC(context3d,
context3d->consumeTextureCHROMIUM(resource->target,
@@ -791,7 +793,8 @@ ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
ResourceProvider::ResourceProvider(OutputSurface* output_surface,
SharedBitmapManager* shared_bitmap_manager,
int highp_threshold_min,
- bool use_rgba_4444_texture_format)
+ bool use_rgba_4444_texture_format,
+ size_t texture_id_allocation_chunk_size)
: output_surface_(output_surface),
shared_bitmap_manager_(shared_bitmap_manager),
lost_output_surface_(false),
@@ -804,8 +807,10 @@ ResourceProvider::ResourceProvider(OutputSurface* output_surface,
use_shallow_flush_(false),
max_texture_size_(0),
best_texture_format_(RGBA_8888),
- use_rgba_4444_texture_format_(use_rgba_4444_texture_format) {
+ use_rgba_4444_texture_format_(use_rgba_4444_texture_format),
+ texture_id_allocation_chunk_size_(texture_id_allocation_chunk_size) {
DCHECK(output_surface_->HasClient());
+ DCHECK(texture_id_allocation_chunk_size_);
}
void ResourceProvider::InitializeSoftware() {
@@ -863,6 +868,14 @@ void ResourceProvider::CleanUpGLIfNeeded() {
DCHECK(context3d);
context3d->makeContextCurrent();
texture_uploader_.reset();
+ if (!unused_texture_ids_.empty()) {
+ size_t size = unused_texture_ids_.size();
+ scoped_ptr<WebKit::WebGLId[]> ids(new WebKit::WebGLId[size]);
+ for (size_t i = 0; i < size; ++i)
+ ids[i] = unused_texture_ids_[i];
+ GLC(context3d, context3d->deleteTextures(size, ids.get()));
+ unused_texture_ids_.clear();
+ }
Finish();
}
@@ -988,7 +1001,7 @@ void ResourceProvider::ReceiveFromChild(
// (and is simpler) to wait.
if (it->sync_point)
GLC(context3d, context3d->waitSyncPoint(it->sync_point));
- GLC(context3d, texture_id = context3d->createTexture());
+ texture_id = NextTextureId();
GLC(context3d, context3d->bindTexture(it->target, texture_id));
GLC(context3d,
context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name));
@@ -1546,11 +1559,12 @@ void ResourceProvider::LazyCreate(Resource* resource) {
if (resource->texture_pool == 0)
return;
+ resource->gl_id = NextTextureId();
+
WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
// Create and set texture properties. Allocation is delayed until needed.
- GLC(context3d, resource->gl_id = context3d->createTexture());
GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id));
GLC(context3d,
context3d->texParameteri(
@@ -1729,4 +1743,20 @@ WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
return context_provider ? context_provider->Context3d() : NULL;
}
+unsigned ResourceProvider::NextTextureId() {
+ if (unused_texture_ids_.empty()) {
+ size_t size = texture_id_allocation_chunk_size_;
+ scoped_ptr<WebKit::WebGLId[]> ids(new WebKit::WebGLId[size]);
+ WebGraphicsContext3D* context3d = Context3d();
+ DCHECK(context3d);
+ GLC(context3d, context3d->genTextures(size, ids.get()));
+ unused_texture_ids_.assign(ids.get(), ids.get() + size);
+ }
+
+ unsigned gl_id = unused_texture_ids_.front();
+ unused_texture_ids_.pop_front();
piman 2013/10/31 01:32:58 nit: why a deque rather than a vector? You can tak
reveman 2013/10/31 13:38:31 I think we should give out ids in the order they a
+
+ return gl_id;
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698