| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 Resource* resource = GetResource(id); | 251 Resource* resource = GetResource(id); |
| 252 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 252 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
| 253 resource->lost; | 253 resource->lost; |
| 254 } | 254 } |
| 255 | 255 |
| 256 bool ResourceProvider::IsLost(ResourceId id) { | 256 bool ResourceProvider::IsLost(ResourceId id) { |
| 257 Resource* resource = GetResource(id); | 257 Resource* resource = GetResource(id); |
| 258 return resource->lost; | 258 return resource->lost; |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool ResourceProvider::IsExported(ResourceId id) { |
| 262 Resource* resource = GetResource(id); |
| 263 return resource->exported_count > 0; |
| 264 } |
| 265 |
| 261 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 266 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 262 gfx::Size size, | 267 gfx::Size size, |
| 263 GLint wrap_mode, | 268 GLint wrap_mode, |
| 264 TextureUsageHint hint, | 269 TextureUsageHint hint, |
| 265 ResourceFormat format) { | 270 ResourceFormat format) { |
| 266 DCHECK(!size.IsEmpty()); | 271 DCHECK(!size.IsEmpty()); |
| 267 switch (default_resource_type_) { | 272 switch (default_resource_type_) { |
| 268 case GLTexture: | 273 case GLTexture: |
| 269 return CreateGLTexture( | 274 return CreateGLTexture( |
| 270 size, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, wrap_mode, hint, format); | 275 size, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, wrap_mode, hint, format); |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 } | 790 } |
| 786 | 791 |
| 787 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 792 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 788 resource_provider_->UnlockForWrite(resource_id_); | 793 resource_provider_->UnlockForWrite(resource_id_); |
| 789 } | 794 } |
| 790 | 795 |
| 791 ResourceProvider::ResourceProvider(OutputSurface* output_surface, | 796 ResourceProvider::ResourceProvider(OutputSurface* output_surface, |
| 792 SharedBitmapManager* shared_bitmap_manager, | 797 SharedBitmapManager* shared_bitmap_manager, |
| 793 int highp_threshold_min, | 798 int highp_threshold_min, |
| 794 bool use_rgba_4444_texture_format) | 799 bool use_rgba_4444_texture_format) |
| 795 : output_surface_(output_surface), | 800 : client_(NULL), |
| 801 output_surface_(output_surface), |
| 796 shared_bitmap_manager_(shared_bitmap_manager), | 802 shared_bitmap_manager_(shared_bitmap_manager), |
| 797 lost_output_surface_(false), | 803 lost_output_surface_(false), |
| 798 highp_threshold_min_(highp_threshold_min), | 804 highp_threshold_min_(highp_threshold_min), |
| 799 next_id_(1), | 805 next_id_(1), |
| 800 next_child_(1), | 806 next_child_(1), |
| 801 default_resource_type_(InvalidType), | 807 default_resource_type_(InvalidType), |
| 802 use_texture_storage_ext_(false), | 808 use_texture_storage_ext_(false), |
| 803 use_texture_usage_hint_(false), | 809 use_texture_usage_hint_(false), |
| 804 use_shallow_flush_(false), | 810 use_shallow_flush_(false), |
| 805 max_texture_size_(0), | 811 max_texture_size_(0), |
| 806 best_texture_format_(RGBA_8888), | 812 best_texture_format_(RGBA_8888), |
| 807 use_rgba_4444_texture_format_(use_rgba_4444_texture_format) { | 813 use_rgba_4444_texture_format_(use_rgba_4444_texture_format) { |
| 808 DCHECK(output_surface_->HasClient()); | 814 DCHECK(output_surface_->HasClient()); |
| 809 } | 815 } |
| 810 | 816 |
| 817 void ResourceProvider::SetClient(ResourceProviderClient* client) { |
| 818 client_ = client; |
| 819 } |
| 820 |
| 811 void ResourceProvider::InitializeSoftware() { | 821 void ResourceProvider::InitializeSoftware() { |
| 812 DCHECK(thread_checker_.CalledOnValidThread()); | 822 DCHECK(thread_checker_.CalledOnValidThread()); |
| 813 DCHECK_NE(Bitmap, default_resource_type_); | 823 DCHECK_NE(Bitmap, default_resource_type_); |
| 814 | 824 |
| 815 CleanUpGLIfNeeded(); | 825 CleanUpGLIfNeeded(); |
| 816 | 826 |
| 817 default_resource_type_ = Bitmap; | 827 default_resource_type_ = Bitmap; |
| 818 max_texture_size_ = INT_MAX / 2; | 828 max_texture_size_ = INT_MAX / 2; |
| 819 best_texture_format_ = RGBA_8888; | 829 best_texture_format_ = RGBA_8888; |
| 820 } | 830 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (context3d) | 927 if (context3d) |
| 918 context3d->makeContextCurrent(); | 928 context3d->makeContextCurrent(); |
| 919 bool need_sync_point = false; | 929 bool need_sync_point = false; |
| 920 for (ResourceIdArray::const_iterator it = resources.begin(); | 930 for (ResourceIdArray::const_iterator it = resources.begin(); |
| 921 it != resources.end(); | 931 it != resources.end(); |
| 922 ++it) { | 932 ++it) { |
| 923 TransferableResource resource; | 933 TransferableResource resource; |
| 924 TransferResource(context3d, *it, &resource); | 934 TransferResource(context3d, *it, &resource); |
| 925 if (!resource.sync_point && !resource.is_software) | 935 if (!resource.sync_point && !resource.is_software) |
| 926 need_sync_point = true; | 936 need_sync_point = true; |
| 927 ++resources_.find(*it)->second.exported_count; | 937 ResourceMap::iterator resource_it = resources_.find(*it); |
| 938 if (resource_it->second.exported_count == 0) { |
| 939 if (client_) |
| 940 client_->ResourceExported(*it); |
| 941 } |
| 942 ++resource_it->second.exported_count; |
| 928 list->push_back(resource); | 943 list->push_back(resource); |
| 929 } | 944 } |
| 930 if (need_sync_point) { | 945 if (need_sync_point) { |
| 931 unsigned int sync_point = context3d->insertSyncPoint(); | 946 unsigned int sync_point = context3d->insertSyncPoint(); |
| 932 for (TransferableResourceArray::iterator it = list->begin(); | 947 for (TransferableResourceArray::iterator it = list->begin(); |
| 933 it != list->end(); | 948 it != list->end(); |
| 934 ++it) { | 949 ++it) { |
| 935 if (!it->sync_point) | 950 if (!it->sync_point) |
| 936 it->sync_point = sync_point; | 951 it->sync_point = sync_point; |
| 937 } | 952 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 CompareResourceMapIteratorsByChildId); | 1100 CompareResourceMapIteratorsByChildId); |
| 1086 | 1101 |
| 1087 for (size_t i = 0; i < sorted_resources.size(); ++i) { | 1102 for (size_t i = 0; i < sorted_resources.size(); ++i) { |
| 1088 ReturnedResource& returned = sorted_resources[i].first; | 1103 ReturnedResource& returned = sorted_resources[i].first; |
| 1089 ResourceMap::iterator& map_iterator = sorted_resources[i].second; | 1104 ResourceMap::iterator& map_iterator = sorted_resources[i].second; |
| 1090 ResourceId local_id = map_iterator->first; | 1105 ResourceId local_id = map_iterator->first; |
| 1091 Resource* resource = &map_iterator->second; | 1106 Resource* resource = &map_iterator->second; |
| 1092 | 1107 |
| 1093 CHECK_GE(resource->exported_count, returned.count); | 1108 CHECK_GE(resource->exported_count, returned.count); |
| 1094 resource->exported_count -= returned.count; | 1109 resource->exported_count -= returned.count; |
| 1110 if (resource->exported_count == 0) { |
| 1111 if (client_) |
| 1112 client_->ResourceReturned(local_id); |
| 1113 } |
| 1095 resource->lost |= returned.lost; | 1114 resource->lost |= returned.lost; |
| 1096 if (resource->exported_count) | 1115 if (resource->exported_count) |
| 1097 continue; | 1116 continue; |
| 1098 | 1117 |
| 1099 if (resource->gl_id) { | 1118 if (resource->gl_id) { |
| 1100 if (returned.sync_point) | 1119 if (returned.sync_point) |
| 1101 GLC(context3d, context3d->waitSyncPoint(returned.sync_point)); | 1120 GLC(context3d, context3d->waitSyncPoint(returned.sync_point)); |
| 1102 } else if (!resource->shared_bitmap) { | 1121 } else if (!resource->shared_bitmap) { |
| 1103 resource->mailbox = | 1122 resource->mailbox = |
| 1104 TextureMailbox(resource->mailbox.name(), returned.sync_point); | 1123 TextureMailbox(resource->mailbox.name(), returned.sync_point); |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1742 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1724 return active_unit; | 1743 return active_unit; |
| 1725 } | 1744 } |
| 1726 | 1745 |
| 1727 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1746 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1728 ContextProvider* context_provider = output_surface_->context_provider(); | 1747 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1729 return context_provider ? context_provider->Context3d() : NULL; | 1748 return context_provider ? context_provider->Context3d() : NULL; |
| 1730 } | 1749 } |
| 1731 | 1750 |
| 1732 } // namespace cc | 1751 } // namespace cc |
| OLD | NEW |