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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 raster_bitmap_.reset(); | 594 raster_bitmap_.reset(); |
595 } | 595 } |
596 | 596 |
597 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 597 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
598 | 598 |
599 ResourceProvider::Child::~Child() {} | 599 ResourceProvider::Child::~Child() {} |
600 | 600 |
601 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 601 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
602 OutputSurface* output_surface, | 602 OutputSurface* output_surface, |
603 SharedBitmapManager* shared_bitmap_manager, | 603 SharedBitmapManager* shared_bitmap_manager, |
| 604 BlockingTaskRunner* blocking_main_thread_task_runner, |
604 int highp_threshold_min, | 605 int highp_threshold_min, |
605 bool use_rgba_4444_texture_format, | 606 bool use_rgba_4444_texture_format, |
606 size_t id_allocation_chunk_size, | 607 size_t id_allocation_chunk_size, |
607 bool use_distance_field_text) { | 608 bool use_distance_field_text) { |
608 scoped_ptr<ResourceProvider> resource_provider( | 609 scoped_ptr<ResourceProvider> resource_provider( |
609 new ResourceProvider(output_surface, | 610 new ResourceProvider(output_surface, |
610 shared_bitmap_manager, | 611 shared_bitmap_manager, |
| 612 blocking_main_thread_task_runner, |
611 highp_threshold_min, | 613 highp_threshold_min, |
612 use_rgba_4444_texture_format, | 614 use_rgba_4444_texture_format, |
613 id_allocation_chunk_size, | 615 id_allocation_chunk_size, |
614 use_distance_field_text)); | 616 use_distance_field_text)); |
615 | 617 |
616 if (resource_provider->ContextGL()) | 618 if (resource_provider->ContextGL()) |
617 resource_provider->InitializeGL(); | 619 resource_provider->InitializeGL(); |
618 else | 620 else |
619 resource_provider->InitializeSoftware(); | 621 resource_provider->InitializeSoftware(); |
620 | 622 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); | 772 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); |
771 gl->TexImageIOSurface2DCHROMIUM( | 773 gl->TexImageIOSurface2DCHROMIUM( |
772 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); | 774 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); |
773 resource.allocated = true; | 775 resource.allocated = true; |
774 resources_[id] = resource; | 776 resources_[id] = resource; |
775 return id; | 777 return id; |
776 } | 778 } |
777 | 779 |
778 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 780 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
779 const TextureMailbox& mailbox, | 781 const TextureMailbox& mailbox, |
780 scoped_ptr<SingleReleaseCallback> release_callback) { | 782 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl) { |
781 DCHECK(thread_checker_.CalledOnValidThread()); | 783 DCHECK(thread_checker_.CalledOnValidThread()); |
782 // Just store the information. Mailbox will be consumed in LockForRead(). | 784 // Just store the information. Mailbox will be consumed in LockForRead(). |
783 ResourceId id = next_id_++; | 785 ResourceId id = next_id_++; |
784 DCHECK(mailbox.IsValid()); | 786 DCHECK(mailbox.IsValid()); |
785 Resource& resource = resources_[id]; | 787 Resource& resource = resources_[id]; |
786 if (mailbox.IsTexture()) { | 788 if (mailbox.IsTexture()) { |
787 resource = Resource(0, | 789 resource = Resource(0, |
788 gfx::Size(), | 790 gfx::Size(), |
789 Resource::External, | 791 Resource::External, |
790 mailbox.target(), | 792 mailbox.target(), |
(...skipping 15 matching lines...) Expand all Loading... |
806 } | 808 } |
807 resource = Resource(pixels, | 809 resource = Resource(pixels, |
808 shared_bitmap.release(), | 810 shared_bitmap.release(), |
809 mailbox.shared_memory_size(), | 811 mailbox.shared_memory_size(), |
810 Resource::External, | 812 Resource::External, |
811 GL_LINEAR, | 813 GL_LINEAR, |
812 GL_CLAMP_TO_EDGE); | 814 GL_CLAMP_TO_EDGE); |
813 } | 815 } |
814 resource.allocated = true; | 816 resource.allocated = true; |
815 resource.mailbox = mailbox; | 817 resource.mailbox = mailbox; |
816 resource.release_callback = | 818 resource.release_callback_impl = |
817 base::Bind(&SingleReleaseCallback::Run, | 819 base::Bind(&SingleReleaseCallbackImpl::Run, |
818 base::Owned(release_callback.release())); | 820 base::Owned(release_callback_impl.release())); |
819 resource.allow_overlay = mailbox.allow_overlay(); | 821 resource.allow_overlay = mailbox.allow_overlay(); |
820 return id; | 822 return id; |
821 } | 823 } |
822 | 824 |
823 void ResourceProvider::DeleteResource(ResourceId id) { | 825 void ResourceProvider::DeleteResource(ResourceId id) { |
824 DCHECK(thread_checker_.CalledOnValidThread()); | 826 DCHECK(thread_checker_.CalledOnValidThread()); |
825 ResourceMap::iterator it = resources_.find(id); | 827 ResourceMap::iterator it = resources_.find(id); |
826 CHECK(it != resources_.end()); | 828 CHECK(it != resources_.end()); |
827 Resource* resource = &it->second; | 829 Resource* resource = &it->second; |
828 DCHECK(!resource->marked_for_deletion); | 830 DCHECK(!resource->marked_for_deletion); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 } else { | 894 } else { |
893 DCHECK(resource->mailbox.IsSharedMemory()); | 895 DCHECK(resource->mailbox.IsSharedMemory()); |
894 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); | 896 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); |
895 if (resource->pixels && shared_memory) { | 897 if (resource->pixels && shared_memory) { |
896 DCHECK(shared_memory->memory() == resource->pixels); | 898 DCHECK(shared_memory->memory() == resource->pixels); |
897 resource->pixels = NULL; | 899 resource->pixels = NULL; |
898 delete resource->shared_bitmap; | 900 delete resource->shared_bitmap; |
899 resource->shared_bitmap = NULL; | 901 resource->shared_bitmap = NULL; |
900 } | 902 } |
901 } | 903 } |
902 resource->release_callback.Run(sync_point, lost_resource); | 904 resource->release_callback_impl.Run( |
| 905 sync_point, lost_resource, blocking_main_thread_task_runner_); |
903 } | 906 } |
904 if (resource->gl_id) { | 907 if (resource->gl_id) { |
905 GLES2Interface* gl = ContextGL(); | 908 GLES2Interface* gl = ContextGL(); |
906 DCHECK(gl); | 909 DCHECK(gl); |
907 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 910 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
908 resource->gl_id = 0; | 911 resource->gl_id = 0; |
909 } | 912 } |
910 if (resource->shared_bitmap) { | 913 if (resource->shared_bitmap) { |
911 DCHECK(resource->origin != Resource::External); | 914 DCHECK(resource->origin != Resource::External); |
912 DCHECK_EQ(Bitmap, resource->type); | 915 DCHECK_EQ(Bitmap, resource->type); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 ResourceProvider::PopulateSkBitmapWithResource( | 1222 ResourceProvider::PopulateSkBitmapWithResource( |
1220 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); | 1223 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); |
1221 DCHECK(valid()); | 1224 DCHECK(valid()); |
1222 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); | 1225 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); |
1223 } | 1226 } |
1224 | 1227 |
1225 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 1228 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
1226 resource_provider_->UnlockForWrite(resource_id_); | 1229 resource_provider_->UnlockForWrite(resource_id_); |
1227 } | 1230 } |
1228 | 1231 |
1229 ResourceProvider::ResourceProvider(OutputSurface* output_surface, | 1232 ResourceProvider::ResourceProvider( |
1230 SharedBitmapManager* shared_bitmap_manager, | 1233 OutputSurface* output_surface, |
1231 int highp_threshold_min, | 1234 SharedBitmapManager* shared_bitmap_manager, |
1232 bool use_rgba_4444_texture_format, | 1235 BlockingTaskRunner* blocking_main_thread_task_runner, |
1233 size_t id_allocation_chunk_size, | 1236 int highp_threshold_min, |
1234 bool use_distance_field_text) | 1237 bool use_rgba_4444_texture_format, |
| 1238 size_t id_allocation_chunk_size, |
| 1239 bool use_distance_field_text) |
1235 : output_surface_(output_surface), | 1240 : output_surface_(output_surface), |
1236 shared_bitmap_manager_(shared_bitmap_manager), | 1241 shared_bitmap_manager_(shared_bitmap_manager), |
| 1242 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
1237 lost_output_surface_(false), | 1243 lost_output_surface_(false), |
1238 highp_threshold_min_(highp_threshold_min), | 1244 highp_threshold_min_(highp_threshold_min), |
1239 next_id_(1), | 1245 next_id_(1), |
1240 next_child_(1), | 1246 next_child_(1), |
1241 default_resource_type_(InvalidType), | 1247 default_resource_type_(InvalidType), |
1242 use_texture_storage_ext_(false), | 1248 use_texture_storage_ext_(false), |
1243 use_texture_format_bgra_(false), | 1249 use_texture_format_bgra_(false), |
1244 use_texture_usage_hint_(false), | 1250 use_texture_usage_hint_(false), |
1245 use_compressed_texture_etc1_(false), | 1251 use_compressed_texture_etc1_(false), |
1246 max_texture_size_(0), | 1252 max_texture_size_(0), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 resource.marked_for_deletion = false; | 1420 resource.marked_for_deletion = false; |
1415 resource.imported_count++; | 1421 resource.imported_count++; |
1416 continue; | 1422 continue; |
1417 } | 1423 } |
1418 | 1424 |
1419 if ((!it->is_software && !gl) || | 1425 if ((!it->is_software && !gl) || |
1420 (it->is_software && !shared_bitmap_manager_)) { | 1426 (it->is_software && !shared_bitmap_manager_)) { |
1421 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); | 1427 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); |
1422 ReturnedResourceArray to_return; | 1428 ReturnedResourceArray to_return; |
1423 to_return.push_back(it->ToReturnedResource()); | 1429 to_return.push_back(it->ToReturnedResource()); |
1424 child_info.return_callback.Run(to_return); | 1430 child_info.return_callback.Run(to_return, |
| 1431 blocking_main_thread_task_runner_); |
1425 continue; | 1432 continue; |
1426 } | 1433 } |
1427 | 1434 |
1428 ResourceId local_id = next_id_++; | 1435 ResourceId local_id = next_id_++; |
1429 Resource& resource = resources_[local_id]; | 1436 Resource& resource = resources_[local_id]; |
1430 if (it->is_software) { | 1437 if (it->is_software) { |
1431 resource = Resource(it->mailbox_holder.mailbox, | 1438 resource = Resource(it->mailbox_holder.mailbox, |
1432 it->size, | 1439 it->size, |
1433 Resource::Delegated, | 1440 Resource::Delegated, |
1434 GL_LINEAR, | 1441 GL_LINEAR, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 if (need_sync_point) { | 1736 if (need_sync_point) { |
1730 DCHECK(gl); | 1737 DCHECK(gl); |
1731 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); | 1738 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
1732 for (size_t i = 0; i < to_return.size(); ++i) { | 1739 for (size_t i = 0; i < to_return.size(); ++i) { |
1733 if (!to_return[i].sync_point) | 1740 if (!to_return[i].sync_point) |
1734 to_return[i].sync_point = sync_point; | 1741 to_return[i].sync_point = sync_point; |
1735 } | 1742 } |
1736 } | 1743 } |
1737 | 1744 |
1738 if (!to_return.empty()) | 1745 if (!to_return.empty()) |
1739 child_info->return_callback.Run(to_return); | 1746 child_info->return_callback.Run(to_return, |
| 1747 blocking_main_thread_task_runner_); |
1740 | 1748 |
1741 if (child_info->marked_for_deletion && | 1749 if (child_info->marked_for_deletion && |
1742 child_info->parent_to_child_map.empty()) { | 1750 child_info->parent_to_child_map.empty()) { |
1743 DCHECK(child_info->child_to_parent_map.empty()); | 1751 DCHECK(child_info->child_to_parent_map.empty()); |
1744 children_.erase(child_it); | 1752 children_.erase(child_it); |
1745 } | 1753 } |
1746 } | 1754 } |
1747 | 1755 |
1748 RasterBuffer* ResourceProvider::AcquireGpuRasterBuffer(ResourceId id) { | 1756 RasterBuffer* ResourceProvider::AcquireGpuRasterBuffer(ResourceId id) { |
1749 // Resource needs to be locked for write since GpuRasterBuffer writes | 1757 // Resource needs to be locked for write since GpuRasterBuffer writes |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 ContextProvider* context_provider = output_surface_->context_provider(); | 2302 ContextProvider* context_provider = output_surface_->context_provider(); |
2295 return context_provider ? context_provider->ContextGL() : NULL; | 2303 return context_provider ? context_provider->ContextGL() : NULL; |
2296 } | 2304 } |
2297 | 2305 |
2298 class GrContext* ResourceProvider::GrContext() const { | 2306 class GrContext* ResourceProvider::GrContext() const { |
2299 ContextProvider* context_provider = output_surface_->context_provider(); | 2307 ContextProvider* context_provider = output_surface_->context_provider(); |
2300 return context_provider ? context_provider->GrContext() : NULL; | 2308 return context_provider ? context_provider->GrContext() : NULL; |
2301 } | 2309 } |
2302 | 2310 |
2303 } // namespace cc | 2311 } // namespace cc |
OLD | NEW |