| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 23 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 24 #include "third_party/khronos/GLES2/gl2.h" | 24 #include "third_party/khronos/GLES2/gl2.h" |
| 25 #include "third_party/khronos/GLES2/gl2ext.h" | 25 #include "third_party/khronos/GLES2/gl2ext.h" |
| 26 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
| 27 #include "ui/gfx/vector2d.h" | 27 #include "ui/gfx/vector2d.h" |
| 28 | 28 |
| 29 using WebKit::WebGraphicsContext3D; | 29 using WebKit::WebGraphicsContext3D; |
| 30 | 30 |
| 31 namespace cc { | 31 namespace cc { |
| 32 | 32 |
| 33 class IdAllocator { |
| 34 public: |
| 35 virtual ~IdAllocator() {} |
| 36 |
| 37 virtual unsigned NextId() = 0; |
| 38 |
| 39 protected: |
| 40 IdAllocator(WebGraphicsContext3D* context3d, size_t id_allocation_chunk_size) |
| 41 : context3d_(context3d), |
| 42 id_allocation_chunk_size_(id_allocation_chunk_size), |
| 43 ids_(new WebKit::WebGLId[id_allocation_chunk_size]), |
| 44 next_id_index_(id_allocation_chunk_size) { |
| 45 DCHECK(id_allocation_chunk_size_); |
| 46 } |
| 47 |
| 48 WebGraphicsContext3D* context3d_; |
| 49 const size_t id_allocation_chunk_size_; |
| 50 scoped_ptr<WebKit::WebGLId[]> ids_; |
| 51 size_t next_id_index_; |
| 52 }; |
| 53 |
| 33 namespace { | 54 namespace { |
| 34 | 55 |
| 35 // Measured in seconds. | 56 // Measured in seconds. |
| 36 const double kSoftwareUploadTickRate = 0.000250; | 57 const double kSoftwareUploadTickRate = 0.000250; |
| 37 const double kTextureUploadTickRate = 0.004; | 58 const double kTextureUploadTickRate = 0.004; |
| 38 | 59 |
| 39 GLenum TextureToStorageFormat(ResourceFormat format) { | 60 GLenum TextureToStorageFormat(ResourceFormat format) { |
| 40 GLenum storage_format = GL_RGBA8_OES; | 61 GLenum storage_format = GL_RGBA8_OES; |
| 41 switch (format) { | 62 switch (format) { |
| 42 case RGBA_8888: | 63 case RGBA_8888: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Active unit being GL_TEXTURE0 is effectively the ground state. | 104 // Active unit being GL_TEXTURE0 is effectively the ground state. |
| 84 if (unit_ != GL_TEXTURE0) | 105 if (unit_ != GL_TEXTURE0) |
| 85 GLC(context3d_, context3d_->activeTexture(GL_TEXTURE0)); | 106 GLC(context3d_, context3d_->activeTexture(GL_TEXTURE0)); |
| 86 } | 107 } |
| 87 | 108 |
| 88 private: | 109 private: |
| 89 WebGraphicsContext3D* context3d_; | 110 WebGraphicsContext3D* context3d_; |
| 90 GLenum unit_; | 111 GLenum unit_; |
| 91 }; | 112 }; |
| 92 | 113 |
| 114 class TextureIdAllocator : public IdAllocator { |
| 115 public: |
| 116 TextureIdAllocator(WebGraphicsContext3D* context3d, |
| 117 size_t texture_id_allocation_chunk_size) |
| 118 : IdAllocator(context3d, texture_id_allocation_chunk_size) { |
| 119 } |
| 120 virtual ~TextureIdAllocator() { |
| 121 context3d_->deleteTextures(id_allocation_chunk_size_ - next_id_index_, |
| 122 ids_.get() + next_id_index_); |
| 123 } |
| 124 |
| 125 // Overridden from IdAllocator: |
| 126 virtual unsigned NextId() OVERRIDE { |
| 127 if (next_id_index_ == id_allocation_chunk_size_) { |
| 128 context3d_->genTextures(id_allocation_chunk_size_, ids_.get()); |
| 129 next_id_index_ = 0; |
| 130 } |
| 131 |
| 132 return ids_[next_id_index_++]; |
| 133 } |
| 134 |
| 135 private: |
| 136 DISALLOW_COPY_AND_ASSIGN(TextureIdAllocator); |
| 137 }; |
| 138 |
| 139 class BufferIdAllocator : public IdAllocator { |
| 140 public: |
| 141 BufferIdAllocator(WebGraphicsContext3D* context3d, |
| 142 size_t buffer_id_allocation_chunk_size) |
| 143 : IdAllocator(context3d, buffer_id_allocation_chunk_size) { |
| 144 } |
| 145 virtual ~BufferIdAllocator() { |
| 146 context3d_->deleteBuffers(id_allocation_chunk_size_ - next_id_index_, |
| 147 ids_.get() + next_id_index_); |
| 148 } |
| 149 |
| 150 // Overridden from IdAllocator: |
| 151 virtual unsigned NextId() OVERRIDE { |
| 152 if (next_id_index_ == id_allocation_chunk_size_) { |
| 153 context3d_->genBuffers(id_allocation_chunk_size_, ids_.get()); |
| 154 next_id_index_ = 0; |
| 155 } |
| 156 |
| 157 return ids_[next_id_index_++]; |
| 158 } |
| 159 |
| 160 private: |
| 161 DISALLOW_COPY_AND_ASSIGN(BufferIdAllocator); |
| 162 }; |
| 163 |
| 93 } // namespace | 164 } // namespace |
| 94 | 165 |
| 95 ResourceProvider::Resource::Resource() | 166 ResourceProvider::Resource::Resource() |
| 96 : child_id(0), | 167 : child_id(0), |
| 97 gl_id(0), | 168 gl_id(0), |
| 98 gl_pixel_buffer_id(0), | 169 gl_pixel_buffer_id(0), |
| 99 gl_upload_query_id(0), | 170 gl_upload_query_id(0), |
| 100 pixels(NULL), | 171 pixels(NULL), |
| 101 pixel_buffer(NULL), | 172 pixel_buffer(NULL), |
| 102 lock_for_read_count(0), | 173 lock_for_read_count(0), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 281 |
| 211 ResourceProvider::Child::Child() {} | 282 ResourceProvider::Child::Child() {} |
| 212 | 283 |
| 213 ResourceProvider::Child::~Child() {} | 284 ResourceProvider::Child::~Child() {} |
| 214 | 285 |
| 215 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 286 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| 216 OutputSurface* output_surface, | 287 OutputSurface* output_surface, |
| 217 SharedBitmapManager* shared_bitmap_manager, | 288 SharedBitmapManager* shared_bitmap_manager, |
| 218 int highp_threshold_min, | 289 int highp_threshold_min, |
| 219 bool use_rgba_4444_texture_format, | 290 bool use_rgba_4444_texture_format, |
| 220 size_t texture_id_allocation_chunk_size) { | 291 size_t id_allocation_chunk_size) { |
| 221 scoped_ptr<ResourceProvider> resource_provider( | 292 scoped_ptr<ResourceProvider> resource_provider( |
| 222 new ResourceProvider(output_surface, | 293 new ResourceProvider(output_surface, |
| 223 shared_bitmap_manager, | 294 shared_bitmap_manager, |
| 224 highp_threshold_min, | 295 highp_threshold_min, |
| 225 use_rgba_4444_texture_format, | 296 use_rgba_4444_texture_format, |
| 226 texture_id_allocation_chunk_size)); | 297 id_allocation_chunk_size)); |
| 227 | 298 |
| 228 bool success = false; | 299 bool success = false; |
| 229 if (resource_provider->Context3d()) { | 300 if (resource_provider->Context3d()) { |
| 230 success = resource_provider->InitializeGL(); | 301 success = resource_provider->InitializeGL(); |
| 231 } else { | 302 } else { |
| 232 resource_provider->InitializeSoftware(); | 303 resource_provider->InitializeSoftware(); |
| 233 success = true; | 304 success = true; |
| 234 } | 305 } |
| 235 | 306 |
| 236 if (!success) | 307 if (!success) |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 713 |
| 643 if (resource->external) { | 714 if (resource->external) { |
| 644 if (!resource->gl_id && resource->mailbox.IsTexture()) { | 715 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
| 645 WebGraphicsContext3D* context3d = Context3d(); | 716 WebGraphicsContext3D* context3d = Context3d(); |
| 646 DCHECK(context3d); | 717 DCHECK(context3d); |
| 647 if (resource->mailbox.sync_point()) { | 718 if (resource->mailbox.sync_point()) { |
| 648 GLC(context3d, | 719 GLC(context3d, |
| 649 context3d->waitSyncPoint(resource->mailbox.sync_point())); | 720 context3d->waitSyncPoint(resource->mailbox.sync_point())); |
| 650 resource->mailbox.ResetSyncPoint(); | 721 resource->mailbox.ResetSyncPoint(); |
| 651 } | 722 } |
| 652 resource->gl_id = NextTextureId(); | 723 resource->gl_id = texture_id_allocator_->NextId(); |
| 653 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); | 724 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); |
| 654 GLC(context3d, | 725 GLC(context3d, |
| 655 context3d->consumeTextureCHROMIUM(resource->target, | 726 context3d->consumeTextureCHROMIUM(resource->target, |
| 656 resource->mailbox.data())); | 727 resource->mailbox.data())); |
| 657 } | 728 } |
| 658 } | 729 } |
| 659 | 730 |
| 660 resource->lock_for_read_count++; | 731 resource->lock_for_read_count++; |
| 661 if (resource->enable_read_lock_fences) | 732 if (resource->enable_read_lock_fences) |
| 662 resource->read_lock_fence = current_read_lock_fence_; | 733 resource->read_lock_fence = current_read_lock_fence_; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 858 } |
| 788 | 859 |
| 789 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 860 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 790 resource_provider_->UnlockForWrite(resource_id_); | 861 resource_provider_->UnlockForWrite(resource_id_); |
| 791 } | 862 } |
| 792 | 863 |
| 793 ResourceProvider::ResourceProvider(OutputSurface* output_surface, | 864 ResourceProvider::ResourceProvider(OutputSurface* output_surface, |
| 794 SharedBitmapManager* shared_bitmap_manager, | 865 SharedBitmapManager* shared_bitmap_manager, |
| 795 int highp_threshold_min, | 866 int highp_threshold_min, |
| 796 bool use_rgba_4444_texture_format, | 867 bool use_rgba_4444_texture_format, |
| 797 size_t texture_id_allocation_chunk_size) | 868 size_t id_allocation_chunk_size) |
| 798 : output_surface_(output_surface), | 869 : output_surface_(output_surface), |
| 799 shared_bitmap_manager_(shared_bitmap_manager), | 870 shared_bitmap_manager_(shared_bitmap_manager), |
| 800 lost_output_surface_(false), | 871 lost_output_surface_(false), |
| 801 highp_threshold_min_(highp_threshold_min), | 872 highp_threshold_min_(highp_threshold_min), |
| 802 next_id_(1), | 873 next_id_(1), |
| 803 next_child_(1), | 874 next_child_(1), |
| 804 default_resource_type_(InvalidType), | 875 default_resource_type_(InvalidType), |
| 805 use_texture_storage_ext_(false), | 876 use_texture_storage_ext_(false), |
| 806 use_texture_usage_hint_(false), | 877 use_texture_usage_hint_(false), |
| 807 use_shallow_flush_(false), | 878 use_shallow_flush_(false), |
| 808 max_texture_size_(0), | 879 max_texture_size_(0), |
| 809 best_texture_format_(RGBA_8888), | 880 best_texture_format_(RGBA_8888), |
| 810 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 881 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), |
| 811 texture_id_allocation_chunk_size_(texture_id_allocation_chunk_size) { | 882 id_allocation_chunk_size_(id_allocation_chunk_size) { |
| 812 DCHECK(output_surface_->HasClient()); | 883 DCHECK(output_surface_->HasClient()); |
| 813 DCHECK(texture_id_allocation_chunk_size_); | 884 DCHECK(id_allocation_chunk_size_); |
| 814 } | 885 } |
| 815 | 886 |
| 816 void ResourceProvider::InitializeSoftware() { | 887 void ResourceProvider::InitializeSoftware() { |
| 817 DCHECK(thread_checker_.CalledOnValidThread()); | 888 DCHECK(thread_checker_.CalledOnValidThread()); |
| 818 DCHECK_NE(Bitmap, default_resource_type_); | 889 DCHECK_NE(Bitmap, default_resource_type_); |
| 819 | 890 |
| 820 CleanUpGLIfNeeded(); | 891 CleanUpGLIfNeeded(); |
| 821 | 892 |
| 822 default_resource_type_ = Bitmap; | 893 default_resource_type_ = Bitmap; |
| 823 max_texture_size_ = INT_MAX / 2; | 894 max_texture_size_ = INT_MAX / 2; |
| 824 best_texture_format_ = RGBA_8888; | 895 best_texture_format_ = RGBA_8888; |
| 825 } | 896 } |
| 826 | 897 |
| 827 bool ResourceProvider::InitializeGL() { | 898 bool ResourceProvider::InitializeGL() { |
| 828 DCHECK(thread_checker_.CalledOnValidThread()); | 899 DCHECK(thread_checker_.CalledOnValidThread()); |
| 829 DCHECK(!texture_uploader_); | 900 DCHECK(!texture_uploader_); |
| 830 DCHECK_NE(GLTexture, default_resource_type_); | 901 DCHECK_NE(GLTexture, default_resource_type_); |
| 902 DCHECK(!texture_id_allocator_); |
| 903 DCHECK(!buffer_id_allocator_); |
| 831 | 904 |
| 832 WebGraphicsContext3D* context3d = Context3d(); | 905 WebGraphicsContext3D* context3d = Context3d(); |
| 833 DCHECK(context3d); | 906 DCHECK(context3d); |
| 834 | 907 |
| 835 if (!context3d->makeContextCurrent()) | 908 if (!context3d->makeContextCurrent()) |
| 836 return false; | 909 return false; |
| 837 | 910 |
| 838 default_resource_type_ = GLTexture; | 911 default_resource_type_ = GLTexture; |
| 839 | 912 |
| 840 const ContextProvider::Capabilities& caps = | 913 const ContextProvider::Capabilities& caps = |
| 841 output_surface_->context_provider()->ContextCapabilities(); | 914 output_surface_->context_provider()->ContextCapabilities(); |
| 842 | 915 |
| 843 bool use_map_sub = caps.map_sub; | 916 bool use_map_sub = caps.map_sub; |
| 844 bool use_bgra = caps.texture_format_bgra8888; | 917 bool use_bgra = caps.texture_format_bgra8888; |
| 845 use_texture_storage_ext_ = caps.texture_storage; | 918 use_texture_storage_ext_ = caps.texture_storage; |
| 846 use_shallow_flush_ = caps.shallow_flush; | 919 use_shallow_flush_ = caps.shallow_flush; |
| 847 use_texture_usage_hint_ = caps.texture_usage; | 920 use_texture_usage_hint_ = caps.texture_usage; |
| 848 use_compressed_texture_etc1_ = caps.texture_format_etc1; | 921 use_compressed_texture_etc1_ = caps.texture_format_etc1; |
| 849 | 922 |
| 850 texture_uploader_ = | 923 texture_uploader_ = |
| 851 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 924 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); |
| 852 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 925 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
| 853 &max_texture_size_)); | 926 &max_texture_size_)); |
| 854 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 927 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
| 855 | 928 |
| 929 texture_id_allocator_.reset( |
| 930 new TextureIdAllocator(context3d, id_allocation_chunk_size_)); |
| 931 buffer_id_allocator_.reset( |
| 932 new BufferIdAllocator(context3d, id_allocation_chunk_size_)); |
| 933 |
| 856 return true; | 934 return true; |
| 857 } | 935 } |
| 858 | 936 |
| 859 void ResourceProvider::CleanUpGLIfNeeded() { | 937 void ResourceProvider::CleanUpGLIfNeeded() { |
| 860 WebGraphicsContext3D* context3d = Context3d(); | 938 WebGraphicsContext3D* context3d = Context3d(); |
| 861 if (default_resource_type_ != GLTexture) { | 939 if (default_resource_type_ != GLTexture) { |
| 862 // We are not in GL mode, but double check before returning. | 940 // We are not in GL mode, but double check before returning. |
| 863 DCHECK(!context3d); | 941 DCHECK(!context3d); |
| 864 DCHECK(!texture_uploader_); | 942 DCHECK(!texture_uploader_); |
| 865 return; | 943 return; |
| 866 } | 944 } |
| 867 | 945 |
| 868 DCHECK(context3d); | 946 DCHECK(context3d); |
| 869 context3d->makeContextCurrent(); | 947 context3d->makeContextCurrent(); |
| 870 texture_uploader_.reset(); | 948 texture_uploader_.reset(); |
| 871 if (!unused_texture_ids_.empty()) { | 949 texture_id_allocator_.reset(); |
| 872 size_t size = unused_texture_ids_.size(); | 950 buffer_id_allocator_.reset(); |
| 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 } | |
| 879 Finish(); | 951 Finish(); |
| 880 } | 952 } |
| 881 | 953 |
| 882 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { | 954 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { |
| 883 DCHECK(thread_checker_.CalledOnValidThread()); | 955 DCHECK(thread_checker_.CalledOnValidThread()); |
| 884 | 956 |
| 885 Child child_info; | 957 Child child_info; |
| 886 child_info.return_callback = return_callback; | 958 child_info.return_callback = return_callback; |
| 887 | 959 |
| 888 int child = next_child_++; | 960 int child = next_child_++; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 } else { | 1066 } else { |
| 995 unsigned texture_id; | 1067 unsigned texture_id; |
| 996 // NOTE: If the parent is a browser and the child a renderer, the parent | 1068 // NOTE: If the parent is a browser and the child a renderer, the parent |
| 997 // is not supposed to have its context wait, because that could induce | 1069 // is not supposed to have its context wait, because that could induce |
| 998 // deadlocks and/or security issues. The caller is responsible for | 1070 // deadlocks and/or security issues. The caller is responsible for |
| 999 // waiting asynchronously, and resetting sync_point before calling this. | 1071 // waiting asynchronously, and resetting sync_point before calling this. |
| 1000 // However if the parent is a renderer (e.g. browser tag), it may be ok | 1072 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| 1001 // (and is simpler) to wait. | 1073 // (and is simpler) to wait. |
| 1002 if (it->sync_point) | 1074 if (it->sync_point) |
| 1003 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 1075 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 1004 texture_id = NextTextureId(); | 1076 texture_id = texture_id_allocator_->NextId(); |
| 1005 GLC(context3d, context3d->bindTexture(it->target, texture_id)); | 1077 GLC(context3d, context3d->bindTexture(it->target, texture_id)); |
| 1006 GLC(context3d, | 1078 GLC(context3d, |
| 1007 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name)); | 1079 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name)); |
| 1008 resource = Resource(texture_id, | 1080 resource = Resource(texture_id, |
| 1009 it->size, | 1081 it->size, |
| 1010 it->target, | 1082 it->target, |
| 1011 it->filter, | 1083 it->filter, |
| 1012 0, | 1084 0, |
| 1013 GL_CLAMP_TO_EDGE, | 1085 GL_CLAMP_TO_EDGE, |
| 1014 TextureUsageAny, | 1086 TextureUsageAny, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 Resource* resource = GetResource(id); | 1351 Resource* resource = GetResource(id); |
| 1280 DCHECK(!resource->external); | 1352 DCHECK(!resource->external); |
| 1281 DCHECK_EQ(resource->exported_count, 0); | 1353 DCHECK_EQ(resource->exported_count, 0); |
| 1282 DCHECK(!resource->image_id); | 1354 DCHECK(!resource->image_id); |
| 1283 DCHECK_NE(ETC1, resource->format); | 1355 DCHECK_NE(ETC1, resource->format); |
| 1284 | 1356 |
| 1285 if (resource->type == GLTexture) { | 1357 if (resource->type == GLTexture) { |
| 1286 WebGraphicsContext3D* context3d = Context3d(); | 1358 WebGraphicsContext3D* context3d = Context3d(); |
| 1287 DCHECK(context3d); | 1359 DCHECK(context3d); |
| 1288 if (!resource->gl_pixel_buffer_id) | 1360 if (!resource->gl_pixel_buffer_id) |
| 1289 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 1361 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
| 1290 context3d->bindBuffer( | 1362 context3d->bindBuffer( |
| 1291 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1363 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1292 resource->gl_pixel_buffer_id); | 1364 resource->gl_pixel_buffer_id); |
| 1293 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1365 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; |
| 1294 context3d->bufferData( | 1366 context3d->bufferData( |
| 1295 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1367 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1296 resource->size.height() * RoundUp(bytes_per_pixel | 1368 resource->size.height() * RoundUp(bytes_per_pixel |
| 1297 * resource->size.width(), 4u), | 1369 * resource->size.width(), 4u), |
| 1298 NULL, | 1370 NULL, |
| 1299 GL_DYNAMIC_DRAW); | 1371 GL_DYNAMIC_DRAW); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 } | 1624 } |
| 1553 | 1625 |
| 1554 void ResourceProvider::LazyCreate(Resource* resource) { | 1626 void ResourceProvider::LazyCreate(Resource* resource) { |
| 1555 if (resource->type != GLTexture || resource->gl_id != 0) | 1627 if (resource->type != GLTexture || resource->gl_id != 0) |
| 1556 return; | 1628 return; |
| 1557 | 1629 |
| 1558 // Early out for resources that don't require texture creation. | 1630 // Early out for resources that don't require texture creation. |
| 1559 if (resource->texture_pool == 0) | 1631 if (resource->texture_pool == 0) |
| 1560 return; | 1632 return; |
| 1561 | 1633 |
| 1562 resource->gl_id = NextTextureId(); | 1634 resource->gl_id = texture_id_allocator_->NextId(); |
| 1563 | 1635 |
| 1564 WebGraphicsContext3D* context3d = Context3d(); | 1636 WebGraphicsContext3D* context3d = Context3d(); |
| 1565 DCHECK(context3d); | 1637 DCHECK(context3d); |
| 1566 | 1638 |
| 1567 // Create and set texture properties. Allocation is delayed until needed. | 1639 // Create and set texture properties. Allocation is delayed until needed. |
| 1568 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); | 1640 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); |
| 1569 GLC(context3d, | 1641 GLC(context3d, |
| 1570 context3d->texParameteri( | 1642 context3d->texParameteri( |
| 1571 resource->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 1643 resource->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 1572 GLC(context3d, | 1644 GLC(context3d, |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 GLint active_unit = 0; | 1808 GLint active_unit = 0; |
| 1737 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1809 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1738 return active_unit; | 1810 return active_unit; |
| 1739 } | 1811 } |
| 1740 | 1812 |
| 1741 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1813 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1742 ContextProvider* context_provider = output_surface_->context_provider(); | 1814 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1743 return context_provider ? context_provider->Context3d() : NULL; | 1815 return context_provider ? context_provider->Context3d() : NULL; |
| 1744 } | 1816 } |
| 1745 | 1817 |
| 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 | |
| 1762 } // namespace cc | 1818 } // namespace cc |
| OLD | NEW |