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

Side by Side 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: rebase Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 ResourceProvider::Child::Child() {} 211 ResourceProvider::Child::Child() {}
212 212
213 ResourceProvider::Child::~Child() {} 213 ResourceProvider::Child::~Child() {}
214 214
215 scoped_ptr<ResourceProvider> ResourceProvider::Create( 215 scoped_ptr<ResourceProvider> ResourceProvider::Create(
216 OutputSurface* output_surface, 216 OutputSurface* output_surface,
217 SharedBitmapManager* shared_bitmap_manager, 217 SharedBitmapManager* shared_bitmap_manager,
218 int highp_threshold_min, 218 int highp_threshold_min,
219 bool use_rgba_4444_texture_format) { 219 bool use_rgba_4444_texture_format,
220 size_t texture_id_allocation_chunk_size) {
220 scoped_ptr<ResourceProvider> resource_provider( 221 scoped_ptr<ResourceProvider> resource_provider(
221 new ResourceProvider(output_surface, 222 new ResourceProvider(output_surface,
222 shared_bitmap_manager, 223 shared_bitmap_manager,
223 highp_threshold_min, 224 highp_threshold_min,
224 use_rgba_4444_texture_format)); 225 use_rgba_4444_texture_format,
226 texture_id_allocation_chunk_size));
225 227
226 bool success = false; 228 bool success = false;
227 if (resource_provider->Context3d()) { 229 if (resource_provider->Context3d()) {
228 success = resource_provider->InitializeGL(); 230 success = resource_provider->InitializeGL();
229 } else { 231 } else {
230 resource_provider->InitializeSoftware(); 232 resource_provider->InitializeSoftware();
231 success = true; 233 success = true;
232 } 234 }
233 235
234 if (!success) 236 if (!success)
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 642
641 if (resource->external) { 643 if (resource->external) {
642 if (!resource->gl_id && resource->mailbox.IsTexture()) { 644 if (!resource->gl_id && resource->mailbox.IsTexture()) {
643 WebGraphicsContext3D* context3d = Context3d(); 645 WebGraphicsContext3D* context3d = Context3d();
644 DCHECK(context3d); 646 DCHECK(context3d);
645 if (resource->mailbox.sync_point()) { 647 if (resource->mailbox.sync_point()) {
646 GLC(context3d, 648 GLC(context3d,
647 context3d->waitSyncPoint(resource->mailbox.sync_point())); 649 context3d->waitSyncPoint(resource->mailbox.sync_point()));
648 resource->mailbox.ResetSyncPoint(); 650 resource->mailbox.ResetSyncPoint();
649 } 651 }
650 resource->gl_id = context3d->createTexture(); 652 resource->gl_id = NextTextureId();
651 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); 653 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id));
652 GLC(context3d, 654 GLC(context3d,
653 context3d->consumeTextureCHROMIUM(resource->target, 655 context3d->consumeTextureCHROMIUM(resource->target,
654 resource->mailbox.data())); 656 resource->mailbox.data()));
655 } 657 }
656 } 658 }
657 659
658 resource->lock_for_read_count++; 660 resource->lock_for_read_count++;
659 if (resource->enable_read_lock_fences) 661 if (resource->enable_read_lock_fences)
660 resource->read_lock_fence = current_read_lock_fence_; 662 resource->read_lock_fence = current_read_lock_fence_;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); 786 sk_canvas_.reset(new SkCanvas(sk_bitmap_));
785 } 787 }
786 788
787 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { 789 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
788 resource_provider_->UnlockForWrite(resource_id_); 790 resource_provider_->UnlockForWrite(resource_id_);
789 } 791 }
790 792
791 ResourceProvider::ResourceProvider(OutputSurface* output_surface, 793 ResourceProvider::ResourceProvider(OutputSurface* output_surface,
792 SharedBitmapManager* shared_bitmap_manager, 794 SharedBitmapManager* shared_bitmap_manager,
793 int highp_threshold_min, 795 int highp_threshold_min,
794 bool use_rgba_4444_texture_format) 796 bool use_rgba_4444_texture_format,
797 size_t texture_id_allocation_chunk_size)
795 : output_surface_(output_surface), 798 : output_surface_(output_surface),
796 shared_bitmap_manager_(shared_bitmap_manager), 799 shared_bitmap_manager_(shared_bitmap_manager),
797 lost_output_surface_(false), 800 lost_output_surface_(false),
798 highp_threshold_min_(highp_threshold_min), 801 highp_threshold_min_(highp_threshold_min),
799 next_id_(1), 802 next_id_(1),
800 next_child_(1), 803 next_child_(1),
801 default_resource_type_(InvalidType), 804 default_resource_type_(InvalidType),
802 use_texture_storage_ext_(false), 805 use_texture_storage_ext_(false),
803 use_texture_usage_hint_(false), 806 use_texture_usage_hint_(false),
804 use_shallow_flush_(false), 807 use_shallow_flush_(false),
805 max_texture_size_(0), 808 max_texture_size_(0),
806 best_texture_format_(RGBA_8888), 809 best_texture_format_(RGBA_8888),
807 use_rgba_4444_texture_format_(use_rgba_4444_texture_format) { 810 use_rgba_4444_texture_format_(use_rgba_4444_texture_format),
811 texture_id_allocation_chunk_size_(texture_id_allocation_chunk_size) {
808 DCHECK(output_surface_->HasClient()); 812 DCHECK(output_surface_->HasClient());
813 DCHECK(texture_id_allocation_chunk_size_);
809 } 814 }
810 815
811 void ResourceProvider::InitializeSoftware() { 816 void ResourceProvider::InitializeSoftware() {
812 DCHECK(thread_checker_.CalledOnValidThread()); 817 DCHECK(thread_checker_.CalledOnValidThread());
813 DCHECK_NE(Bitmap, default_resource_type_); 818 DCHECK_NE(Bitmap, default_resource_type_);
814 819
815 CleanUpGLIfNeeded(); 820 CleanUpGLIfNeeded();
816 821
817 default_resource_type_ = Bitmap; 822 default_resource_type_ = Bitmap;
818 max_texture_size_ = INT_MAX / 2; 823 max_texture_size_ = INT_MAX / 2;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 if (default_resource_type_ != GLTexture) { 861 if (default_resource_type_ != GLTexture) {
857 // We are not in GL mode, but double check before returning. 862 // We are not in GL mode, but double check before returning.
858 DCHECK(!context3d); 863 DCHECK(!context3d);
859 DCHECK(!texture_uploader_); 864 DCHECK(!texture_uploader_);
860 return; 865 return;
861 } 866 }
862 867
863 DCHECK(context3d); 868 DCHECK(context3d);
864 context3d->makeContextCurrent(); 869 context3d->makeContextCurrent();
865 texture_uploader_.reset(); 870 texture_uploader_.reset();
871 if (!unused_texture_ids_.empty()) {
872 size_t size = unused_texture_ids_.size();
873 scoped_ptr<WebKit::WebGLId[]> ids(new WebKit::WebGLId[size]);
874 for (size_t i = 0; i < size; ++i)
875 ids[i] = unused_texture_ids_[i];
876 GLC(context3d, context3d->deleteTextures(size, ids.get()));
877 unused_texture_ids_.clear();
878 }
866 Finish(); 879 Finish();
867 } 880 }
868 881
869 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { 882 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) {
870 DCHECK(thread_checker_.CalledOnValidThread()); 883 DCHECK(thread_checker_.CalledOnValidThread());
871 884
872 Child child_info; 885 Child child_info;
873 child_info.return_callback = return_callback; 886 child_info.return_callback = return_callback;
874 887
875 int child = next_child_++; 888 int child = next_child_++;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 } else { 994 } else {
982 unsigned texture_id; 995 unsigned texture_id;
983 // NOTE: If the parent is a browser and the child a renderer, the parent 996 // NOTE: If the parent is a browser and the child a renderer, the parent
984 // is not supposed to have its context wait, because that could induce 997 // is not supposed to have its context wait, because that could induce
985 // deadlocks and/or security issues. The caller is responsible for 998 // deadlocks and/or security issues. The caller is responsible for
986 // waiting asynchronously, and resetting sync_point before calling this. 999 // waiting asynchronously, and resetting sync_point before calling this.
987 // However if the parent is a renderer (e.g. browser tag), it may be ok 1000 // However if the parent is a renderer (e.g. browser tag), it may be ok
988 // (and is simpler) to wait. 1001 // (and is simpler) to wait.
989 if (it->sync_point) 1002 if (it->sync_point)
990 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 1003 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
991 GLC(context3d, texture_id = context3d->createTexture()); 1004 texture_id = NextTextureId();
992 GLC(context3d, context3d->bindTexture(it->target, texture_id)); 1005 GLC(context3d, context3d->bindTexture(it->target, texture_id));
993 GLC(context3d, 1006 GLC(context3d,
994 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name)); 1007 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name));
995 resource = Resource(texture_id, 1008 resource = Resource(texture_id,
996 it->size, 1009 it->size,
997 it->target, 1010 it->target,
998 it->filter, 1011 it->filter,
999 0, 1012 0,
1000 GL_CLAMP_TO_EDGE, 1013 GL_CLAMP_TO_EDGE,
1001 TextureUsageAny, 1014 TextureUsageAny,
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 } 1552 }
1540 1553
1541 void ResourceProvider::LazyCreate(Resource* resource) { 1554 void ResourceProvider::LazyCreate(Resource* resource) {
1542 if (resource->type != GLTexture || resource->gl_id != 0) 1555 if (resource->type != GLTexture || resource->gl_id != 0)
1543 return; 1556 return;
1544 1557
1545 // Early out for resources that don't require texture creation. 1558 // Early out for resources that don't require texture creation.
1546 if (resource->texture_pool == 0) 1559 if (resource->texture_pool == 0)
1547 return; 1560 return;
1548 1561
1562 resource->gl_id = NextTextureId();
1563
1549 WebGraphicsContext3D* context3d = Context3d(); 1564 WebGraphicsContext3D* context3d = Context3d();
1550 DCHECK(context3d); 1565 DCHECK(context3d);
1551 1566
1552 // Create and set texture properties. Allocation is delayed until needed. 1567 // Create and set texture properties. Allocation is delayed until needed.
1553 GLC(context3d, resource->gl_id = context3d->createTexture());
1554 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); 1568 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id));
1555 GLC(context3d, 1569 GLC(context3d,
1556 context3d->texParameteri( 1570 context3d->texParameteri(
1557 resource->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1571 resource->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1558 GLC(context3d, 1572 GLC(context3d,
1559 context3d->texParameteri( 1573 context3d->texParameteri(
1560 resource->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 1574 resource->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
1561 GLC(context3d, 1575 GLC(context3d,
1562 context3d->texParameteri( 1576 context3d->texParameteri(
1563 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode)); 1577 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode));
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 GLint active_unit = 0; 1736 GLint active_unit = 0;
1723 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1737 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1724 return active_unit; 1738 return active_unit;
1725 } 1739 }
1726 1740
1727 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1741 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1728 ContextProvider* context_provider = output_surface_->context_provider(); 1742 ContextProvider* context_provider = output_surface_->context_provider();
1729 return context_provider ? context_provider->Context3d() : NULL; 1743 return context_provider ? context_provider->Context3d() : NULL;
1730 } 1744 }
1731 1745
1746 unsigned ResourceProvider::NextTextureId() {
1747 if (unused_texture_ids_.empty()) {
1748 size_t size = texture_id_allocation_chunk_size_;
1749 scoped_ptr<WebKit::WebGLId[]> ids(new WebKit::WebGLId[size]);
1750 WebGraphicsContext3D* context3d = Context3d();
1751 DCHECK(context3d);
1752 GLC(context3d, context3d->genTextures(size, ids.get()));
1753 unused_texture_ids_.assign(ids.get(), ids.get() + size);
1754 }
1755
1756 unsigned gl_id = unused_texture_ids_.front();
1757 unused_texture_ids_.pop_front();
1758
1759 return gl_id;
1760 }
1761
1732 } // namespace cc 1762 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698