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" |
11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 15 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
16 #include "cc/resources/platform_color.h" | 16 #include "cc/resources/platform_color.h" |
| 17 #include "cc/resources/returned_resource.h" |
17 #include "cc/resources/transferable_resource.h" | 18 #include "cc/resources/transferable_resource.h" |
18 #include "cc/scheduler/texture_uploader.h" | 19 #include "cc/scheduler/texture_uploader.h" |
19 #include "gpu/GLES2/gl2extchromium.h" | 20 #include "gpu/GLES2/gl2extchromium.h" |
20 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 21 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
21 #include "third_party/khronos/GLES2/gl2.h" | 22 #include "third_party/khronos/GLES2/gl2.h" |
22 #include "third_party/khronos/GLES2/gl2ext.h" | 23 #include "third_party/khronos/GLES2/gl2ext.h" |
23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
24 #include "ui/gfx/vector2d.h" | 25 #include "ui/gfx/vector2d.h" |
25 | 26 |
26 using WebKit::WebGraphicsContext3D; | 27 using WebKit::WebGraphicsContext3D; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 177 } |
177 | 178 |
178 ResourceProvider::~ResourceProvider() { | 179 ResourceProvider::~ResourceProvider() { |
179 while (!resources_.empty()) | 180 while (!resources_.empty()) |
180 DeleteResourceInternal(resources_.begin(), ForShutdown); | 181 DeleteResourceInternal(resources_.begin(), ForShutdown); |
181 | 182 |
182 CleanUpGLIfNeeded(); | 183 CleanUpGLIfNeeded(); |
183 } | 184 } |
184 | 185 |
185 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 186 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
186 DCHECK(thread_checker_.CalledOnValidThread()); | 187 Resource* resource = GetResource(id); |
187 ResourceMap::iterator it = resources_.find(id); | |
188 CHECK(it != resources_.end()); | |
189 Resource* resource = &it->second; | |
190 return resource->lock_for_read_count > 0 || resource->exported_count > 0; | 188 return resource->lock_for_read_count > 0 || resource->exported_count > 0; |
191 } | 189 } |
192 | 190 |
193 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 191 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
194 gfx::Size size, GLenum format, TextureUsageHint hint) { | 192 gfx::Size size, GLenum format, TextureUsageHint hint) { |
195 DCHECK(!size.IsEmpty()); | 193 DCHECK(!size.IsEmpty()); |
196 switch (default_resource_type_) { | 194 switch (default_resource_type_) { |
197 case GLTexture: | 195 case GLTexture: |
198 return CreateGLTexture( | 196 return CreateGLTexture( |
199 size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, hint); | 197 size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, hint); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 if (resource->pixels) | 368 if (resource->pixels) |
371 delete[] resource->pixels; | 369 delete[] resource->pixels; |
372 if (resource->pixel_buffer) | 370 if (resource->pixel_buffer) |
373 delete[] resource->pixel_buffer; | 371 delete[] resource->pixel_buffer; |
374 | 372 |
375 resources_.erase(it); | 373 resources_.erase(it); |
376 } | 374 } |
377 | 375 |
378 ResourceProvider::ResourceType ResourceProvider::GetResourceType( | 376 ResourceProvider::ResourceType ResourceProvider::GetResourceType( |
379 ResourceId id) { | 377 ResourceId id) { |
380 ResourceMap::iterator it = resources_.find(id); | 378 return GetResource(id)->type; |
381 CHECK(it != resources_.end()); | |
382 Resource* resource = &it->second; | |
383 return resource->type; | |
384 } | 379 } |
385 | 380 |
386 void ResourceProvider::SetPixels(ResourceId id, | 381 void ResourceProvider::SetPixels(ResourceId id, |
387 const uint8_t* image, | 382 const uint8_t* image, |
388 gfx::Rect image_rect, | 383 gfx::Rect image_rect, |
389 gfx::Rect source_rect, | 384 gfx::Rect source_rect, |
390 gfx::Vector2d dest_offset) { | 385 gfx::Vector2d dest_offset) { |
391 DCHECK(thread_checker_.CalledOnValidThread()); | 386 Resource* resource = GetResource(id); |
392 ResourceMap::iterator it = resources_.find(id); | |
393 CHECK(it != resources_.end()); | |
394 Resource* resource = &it->second; | |
395 DCHECK(!resource->locked_for_write); | 387 DCHECK(!resource->locked_for_write); |
396 DCHECK(!resource->lock_for_read_count); | 388 DCHECK(!resource->lock_for_read_count); |
397 DCHECK(!resource->external); | 389 DCHECK(!resource->external); |
398 DCHECK_EQ(resource->exported_count, 0); | 390 DCHECK_EQ(resource->exported_count, 0); |
399 DCHECK(ReadLockFenceHasPassed(resource)); | 391 DCHECK(ReadLockFenceHasPassed(resource)); |
400 LazyAllocate(resource); | 392 LazyAllocate(resource); |
401 | 393 |
402 if (resource->gl_id) { | 394 if (resource->gl_id) { |
403 DCHECK(!resource->pending_set_pixels); | 395 DCHECK(!resource->pending_set_pixels); |
404 WebGraphicsContext3D* context3d = Context3d(); | 396 WebGraphicsContext3D* context3d = Context3d(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 bool ResourceProvider::ShallowFlushIfSupported() { | 478 bool ResourceProvider::ShallowFlushIfSupported() { |
487 DCHECK(thread_checker_.CalledOnValidThread()); | 479 DCHECK(thread_checker_.CalledOnValidThread()); |
488 WebGraphicsContext3D* context3d = Context3d(); | 480 WebGraphicsContext3D* context3d = Context3d(); |
489 if (!context3d || !use_shallow_flush_) | 481 if (!context3d || !use_shallow_flush_) |
490 return false; | 482 return false; |
491 | 483 |
492 context3d->shallowFlushCHROMIUM(); | 484 context3d->shallowFlushCHROMIUM(); |
493 return true; | 485 return true; |
494 } | 486 } |
495 | 487 |
496 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { | 488 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { |
497 DCHECK(thread_checker_.CalledOnValidThread()); | 489 DCHECK(thread_checker_.CalledOnValidThread()); |
498 ResourceMap::iterator it = resources_.find(id); | 490 ResourceMap::iterator it = resources_.find(id); |
499 CHECK(it != resources_.end()); | 491 CHECK(it != resources_.end()); |
500 Resource* resource = &it->second; | 492 return &it->second; |
| 493 } |
| 494 |
| 495 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
| 496 Resource* resource = GetResource(id); |
501 DCHECK(!resource->locked_for_write || | 497 DCHECK(!resource->locked_for_write || |
502 resource->set_pixels_completion_forced) << | 498 resource->set_pixels_completion_forced) << |
503 "locked for write: " << resource->locked_for_write << | 499 "locked for write: " << resource->locked_for_write << |
504 " pixels completion forced: " << resource->set_pixels_completion_forced; | 500 " pixels completion forced: " << resource->set_pixels_completion_forced; |
505 DCHECK_EQ(resource->exported_count, 0); | 501 DCHECK_EQ(resource->exported_count, 0); |
506 // Uninitialized! Call SetPixels or LockForWrite first. | 502 // Uninitialized! Call SetPixels or LockForWrite first. |
507 DCHECK(resource->allocated); | 503 DCHECK(resource->allocated); |
508 | 504 |
509 LazyCreate(resource); | 505 LazyCreate(resource); |
510 | 506 |
(...skipping 15 matching lines...) Expand all Loading... |
526 } | 522 } |
527 | 523 |
528 resource->lock_for_read_count++; | 524 resource->lock_for_read_count++; |
529 if (resource->enable_read_lock_fences) | 525 if (resource->enable_read_lock_fences) |
530 resource->read_lock_fence = current_read_lock_fence_; | 526 resource->read_lock_fence = current_read_lock_fence_; |
531 | 527 |
532 return resource; | 528 return resource; |
533 } | 529 } |
534 | 530 |
535 void ResourceProvider::UnlockForRead(ResourceId id) { | 531 void ResourceProvider::UnlockForRead(ResourceId id) { |
536 DCHECK(thread_checker_.CalledOnValidThread()); | 532 Resource* resource = GetResource(id); |
537 ResourceMap::iterator it = resources_.find(id); | |
538 CHECK(it != resources_.end()); | |
539 Resource* resource = &it->second; | |
540 DCHECK_GT(resource->lock_for_read_count, 0); | 533 DCHECK_GT(resource->lock_for_read_count, 0); |
541 DCHECK_EQ(resource->exported_count, 0); | 534 DCHECK_EQ(resource->exported_count, 0); |
542 resource->lock_for_read_count--; | 535 resource->lock_for_read_count--; |
543 } | 536 } |
544 | 537 |
545 const ResourceProvider::Resource* ResourceProvider::LockForWrite( | 538 const ResourceProvider::Resource* ResourceProvider::LockForWrite( |
546 ResourceId id) { | 539 ResourceId id) { |
547 DCHECK(thread_checker_.CalledOnValidThread()); | 540 Resource* resource = GetResource(id); |
548 ResourceMap::iterator it = resources_.find(id); | |
549 CHECK(it != resources_.end()); | |
550 Resource* resource = &it->second; | |
551 DCHECK(!resource->locked_for_write); | 541 DCHECK(!resource->locked_for_write); |
552 DCHECK(!resource->lock_for_read_count); | 542 DCHECK(!resource->lock_for_read_count); |
553 DCHECK_EQ(resource->exported_count, 0); | 543 DCHECK_EQ(resource->exported_count, 0); |
554 DCHECK(!resource->external); | 544 DCHECK(!resource->external); |
555 DCHECK(ReadLockFenceHasPassed(resource)); | 545 DCHECK(ReadLockFenceHasPassed(resource)); |
556 LazyAllocate(resource); | 546 LazyAllocate(resource); |
557 | 547 |
558 resource->locked_for_write = true; | 548 resource->locked_for_write = true; |
559 return resource; | 549 return resource; |
560 } | 550 } |
561 | 551 |
562 bool ResourceProvider::CanLockForWrite(ResourceId id) { | 552 bool ResourceProvider::CanLockForWrite(ResourceId id) { |
563 DCHECK(thread_checker_.CalledOnValidThread()); | 553 Resource* resource = GetResource(id); |
564 ResourceMap::iterator it = resources_.find(id); | |
565 CHECK(it != resources_.end()); | |
566 Resource* resource = &it->second; | |
567 return !resource->locked_for_write && | 554 return !resource->locked_for_write && |
568 !resource->lock_for_read_count && | 555 !resource->lock_for_read_count && |
569 !resource->exported_count && | 556 !resource->exported_count && |
570 !resource->external && | 557 !resource->external && |
571 ReadLockFenceHasPassed(resource); | 558 ReadLockFenceHasPassed(resource); |
572 } | 559 } |
573 | 560 |
574 void ResourceProvider::UnlockForWrite(ResourceId id) { | 561 void ResourceProvider::UnlockForWrite(ResourceId id) { |
575 DCHECK(thread_checker_.CalledOnValidThread()); | 562 Resource* resource = GetResource(id); |
576 ResourceMap::iterator it = resources_.find(id); | |
577 CHECK(it != resources_.end()); | |
578 Resource* resource = &it->second; | |
579 DCHECK(resource->locked_for_write); | 563 DCHECK(resource->locked_for_write); |
580 DCHECK_EQ(resource->exported_count, 0); | 564 DCHECK_EQ(resource->exported_count, 0); |
581 DCHECK(!resource->external); | 565 DCHECK(!resource->external); |
582 resource->locked_for_write = false; | 566 resource->locked_for_write = false; |
583 } | 567 } |
584 | 568 |
585 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( | 569 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( |
586 ResourceProvider* resource_provider, | 570 ResourceProvider* resource_provider, |
587 ResourceProvider::ResourceId resource_id) | 571 ResourceProvider::ResourceId resource_id) |
588 : resource_provider_(resource_provider), | 572 : resource_provider_(resource_provider), |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 unsigned int sync_point = context3d->insertSyncPoint(); | 797 unsigned int sync_point = context3d->insertSyncPoint(); |
814 for (TransferableResourceArray::iterator it = list->begin(); | 798 for (TransferableResourceArray::iterator it = list->begin(); |
815 it != list->end(); | 799 it != list->end(); |
816 ++it) { | 800 ++it) { |
817 if (!it->sync_point) | 801 if (!it->sync_point) |
818 it->sync_point = sync_point; | 802 it->sync_point = sync_point; |
819 } | 803 } |
820 } | 804 } |
821 } | 805 } |
822 | 806 |
823 void ResourceProvider::PrepareSendToChild(int child, | 807 void ResourceProvider::PrepareSendReturnsToChild( |
824 const ResourceIdArray& resources, | 808 int child, |
825 TransferableResourceArray* list) { | 809 const ResourceIdArray& resources, |
| 810 ReturnedResourceArray* list) { |
826 DCHECK(thread_checker_.CalledOnValidThread()); | 811 DCHECK(thread_checker_.CalledOnValidThread()); |
827 WebGraphicsContext3D* context3d = Context3d(); | 812 WebGraphicsContext3D* context3d = Context3d(); |
828 if (!context3d || !context3d->makeContextCurrent()) { | 813 if (!context3d || !context3d->makeContextCurrent()) { |
829 // TODO(skaslev): Implement this path for software compositing. | 814 // TODO(skaslev): Implement this path for software compositing. |
830 return; | 815 return; |
831 } | 816 } |
832 Child& child_info = children_.find(child)->second; | 817 Child& child_info = children_.find(child)->second; |
833 bool need_sync_point = false; | 818 bool need_sync_point = false; |
834 for (ResourceIdArray::const_iterator it = resources.begin(); | 819 for (ResourceIdArray::const_iterator it = resources.begin(); |
835 it != resources.end(); | 820 it != resources.end(); ++it) { |
836 ++it) { | 821 Resource* resource = GetResource(*it); |
837 TransferableResource resource; | 822 DCHECK(!resource->locked_for_write); |
838 TransferResource(context3d, *it, &resource); | 823 DCHECK(!resource->lock_for_read_count); |
839 if (!resource.sync_point) | |
840 need_sync_point = true; | |
841 DCHECK(child_info.parent_to_child_map.find(*it) != | 824 DCHECK(child_info.parent_to_child_map.find(*it) != |
842 child_info.parent_to_child_map.end()); | 825 child_info.parent_to_child_map.end()); |
843 resource.id = child_info.parent_to_child_map[*it]; | 826 |
| 827 ReturnedResource returned; |
| 828 returned.id = child_info.parent_to_child_map[*it]; |
| 829 returned.filter = resource->filter; |
| 830 returned.sync_point = resource->mailbox.sync_point(); |
| 831 if (!returned.sync_point) |
| 832 need_sync_point = true; |
| 833 returned.count = resource->imported_count; |
| 834 list->push_back(returned); |
| 835 |
844 child_info.parent_to_child_map.erase(*it); | 836 child_info.parent_to_child_map.erase(*it); |
845 child_info.child_to_parent_map.erase(resource.id); | 837 child_info.child_to_parent_map.erase(returned.id); |
846 for (int i = 0; i < resources_[*it].imported_count; ++i) | |
847 list->push_back(resource); | |
848 resources_[*it].imported_count = 0; | 838 resources_[*it].imported_count = 0; |
849 DeleteResource(*it); | 839 DeleteResource(*it); |
850 } | 840 } |
851 if (need_sync_point) { | 841 if (need_sync_point) { |
852 unsigned int sync_point = context3d->insertSyncPoint(); | 842 unsigned int sync_point = context3d->insertSyncPoint(); |
853 for (TransferableResourceArray::iterator it = list->begin(); | 843 for (ReturnedResourceArray::iterator it = list->begin(); |
854 it != list->end(); | 844 it != list->end(); ++it) { |
855 ++it) { | |
856 if (!it->sync_point) | 845 if (!it->sync_point) |
857 it->sync_point = sync_point; | 846 it->sync_point = sync_point; |
858 } | 847 } |
859 } | 848 } |
860 } | 849 } |
861 | 850 |
862 void ResourceProvider::ReceiveFromChild( | 851 void ResourceProvider::ReceiveFromChild( |
863 int child, const TransferableResourceArray& resources) { | 852 int child, const TransferableResourceArray& resources) { |
864 DCHECK(thread_checker_.CalledOnValidThread()); | 853 DCHECK(thread_checker_.CalledOnValidThread()); |
865 WebGraphicsContext3D* context3d = Context3d(); | 854 WebGraphicsContext3D* context3d = Context3d(); |
(...skipping 30 matching lines...) Expand all Loading... |
896 resource.mailbox.SetName(it->mailbox); | 885 resource.mailbox.SetName(it->mailbox); |
897 // Don't allocate a texture for a child. | 886 // Don't allocate a texture for a child. |
898 resource.allocated = true; | 887 resource.allocated = true; |
899 resource.imported_count = 1; | 888 resource.imported_count = 1; |
900 resources_[id] = resource; | 889 resources_[id] = resource; |
901 child_info.parent_to_child_map[id] = it->id; | 890 child_info.parent_to_child_map[id] = it->id; |
902 child_info.child_to_parent_map[it->id] = id; | 891 child_info.child_to_parent_map[it->id] = id; |
903 } | 892 } |
904 } | 893 } |
905 | 894 |
906 void ResourceProvider::ReceiveFromParent( | 895 void ResourceProvider::ReceiveReturnsFromParent( |
907 const TransferableResourceArray& resources) { | 896 const ReturnedResourceArray& resources) { |
908 DCHECK(thread_checker_.CalledOnValidThread()); | 897 DCHECK(thread_checker_.CalledOnValidThread()); |
909 WebGraphicsContext3D* context3d = Context3d(); | 898 WebGraphicsContext3D* context3d = Context3d(); |
910 if (!context3d || !context3d->makeContextCurrent()) { | 899 if (!context3d || !context3d->makeContextCurrent()) { |
911 // TODO(skaslev): Implement this path for software compositing. | 900 // TODO(skaslev): Implement this path for software compositing. |
912 return; | 901 return; |
913 } | 902 } |
914 for (TransferableResourceArray::const_iterator it = resources.begin(); | 903 for (ReturnedResourceArray::const_iterator it = resources.begin(); |
915 it != resources.end(); | 904 it != resources.end(); |
916 ++it) { | 905 ++it) { |
917 ResourceMap::iterator map_iterator = resources_.find(it->id); | 906 ResourceMap::iterator map_iterator = resources_.find(it->id); |
918 DCHECK(map_iterator != resources_.end()); | 907 DCHECK(map_iterator != resources_.end()); |
919 Resource* resource = &map_iterator->second; | 908 Resource* resource = &map_iterator->second; |
920 DCHECK_GT(resource->exported_count, 0); | 909 CHECK_GE(resource->exported_count, it->count); |
921 --resource->exported_count; | 910 resource->exported_count -= it->count; |
922 if (resource->exported_count) | 911 if (resource->exported_count) |
923 continue; | 912 continue; |
924 resource->filter = it->filter; | 913 resource->filter = it->filter; |
925 DCHECK(resource->mailbox.ContainsMailbox(it->mailbox)); | |
926 if (resource->gl_id) { | 914 if (resource->gl_id) { |
927 if (it->sync_point) | 915 if (it->sync_point) |
928 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 916 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
929 } else { | 917 } else { |
930 resource->mailbox = TextureMailbox(resource->mailbox.name(), | 918 resource->mailbox = TextureMailbox(resource->mailbox.name(), |
931 resource->mailbox.callback(), | 919 resource->mailbox.callback(), |
932 it->sync_point); | 920 it->sync_point); |
933 } | 921 } |
934 if (resource->marked_for_deletion) | 922 if (resource->marked_for_deletion) |
935 DeleteResourceInternal(map_iterator, Normal); | 923 DeleteResourceInternal(map_iterator, Normal); |
936 } | 924 } |
937 } | 925 } |
938 | 926 |
939 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 927 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
940 ResourceId id, | 928 ResourceId id, |
941 TransferableResource* resource) { | 929 TransferableResource* resource) { |
942 DCHECK(thread_checker_.CalledOnValidThread()); | 930 Resource* source = GetResource(id); |
943 ResourceMap::iterator it = resources_.find(id); | |
944 CHECK(it != resources_.end()); | |
945 Resource* source = &it->second; | |
946 DCHECK(!source->locked_for_write); | 931 DCHECK(!source->locked_for_write); |
947 DCHECK(!source->lock_for_read_count); | 932 DCHECK(!source->lock_for_read_count); |
948 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); | 933 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
949 DCHECK(source->allocated); | 934 DCHECK(source->allocated); |
950 resource->id = id; | 935 resource->id = id; |
951 resource->format = source->format; | 936 resource->format = source->format; |
952 resource->filter = source->filter; | 937 resource->filter = source->filter; |
953 resource->size = source->size; | 938 resource->size = source->size; |
954 | 939 |
955 // TODO(skaslev) Implement this path for shared memory resources. | 940 // TODO(skaslev) Implement this path for shared memory resources. |
(...skipping 11 matching lines...) Expand all Loading... |
967 } else { | 952 } else { |
968 // This is either an external resource, or a compositor resource that we | 953 // This is either an external resource, or a compositor resource that we |
969 // already exported. Make sure to forward the sync point that we were given. | 954 // already exported. Make sure to forward the sync point that we were given. |
970 resource->mailbox = source->mailbox.name(); | 955 resource->mailbox = source->mailbox.name(); |
971 resource->sync_point = source->mailbox.sync_point(); | 956 resource->sync_point = source->mailbox.sync_point(); |
972 source->mailbox.ResetSyncPoint(); | 957 source->mailbox.ResetSyncPoint(); |
973 } | 958 } |
974 } | 959 } |
975 | 960 |
976 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 961 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
977 DCHECK(thread_checker_.CalledOnValidThread()); | 962 Resource* resource = GetResource(id); |
978 ResourceMap::iterator it = resources_.find(id); | |
979 CHECK(it != resources_.end()); | |
980 Resource* resource = &it->second; | |
981 DCHECK(!resource->external); | 963 DCHECK(!resource->external); |
982 DCHECK_EQ(resource->exported_count, 0); | 964 DCHECK_EQ(resource->exported_count, 0); |
983 DCHECK(!resource->image_id); | 965 DCHECK(!resource->image_id); |
984 | 966 |
985 if (resource->type == GLTexture) { | 967 if (resource->type == GLTexture) { |
986 WebGraphicsContext3D* context3d = Context3d(); | 968 WebGraphicsContext3D* context3d = Context3d(); |
987 DCHECK(context3d); | 969 DCHECK(context3d); |
988 if (!resource->gl_pixel_buffer_id) | 970 if (!resource->gl_pixel_buffer_id) |
989 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 971 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
990 context3d->bindBuffer( | 972 context3d->bindBuffer( |
991 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 973 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
992 resource->gl_pixel_buffer_id); | 974 resource->gl_pixel_buffer_id); |
993 context3d->bufferData( | 975 context3d->bufferData( |
994 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 976 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
995 4 * resource->size.GetArea(), | 977 4 * resource->size.GetArea(), |
996 NULL, | 978 NULL, |
997 GL_DYNAMIC_DRAW); | 979 GL_DYNAMIC_DRAW); |
998 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 980 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
999 } | 981 } |
1000 | 982 |
1001 if (resource->pixels) { | 983 if (resource->pixels) { |
1002 if (resource->pixel_buffer) | 984 if (resource->pixel_buffer) |
1003 return; | 985 return; |
1004 | 986 |
1005 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 987 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
1006 } | 988 } |
1007 } | 989 } |
1008 | 990 |
1009 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 991 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
1010 DCHECK(thread_checker_.CalledOnValidThread()); | 992 Resource* resource = GetResource(id); |
1011 ResourceMap::iterator it = resources_.find(id); | |
1012 CHECK(it != resources_.end()); | |
1013 Resource* resource = &it->second; | |
1014 DCHECK(!resource->external); | 993 DCHECK(!resource->external); |
1015 DCHECK_EQ(resource->exported_count, 0); | 994 DCHECK_EQ(resource->exported_count, 0); |
1016 DCHECK(!resource->image_id); | 995 DCHECK(!resource->image_id); |
1017 | 996 |
1018 // The pixel buffer can be released while there is a pending "set pixels" | 997 // The pixel buffer can be released while there is a pending "set pixels" |
1019 // if completion has been forced. Any shared memory associated with this | 998 // if completion has been forced. Any shared memory associated with this |
1020 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM | 999 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM |
1021 // command has been processed on the service side. It is also safe to | 1000 // command has been processed on the service side. It is also safe to |
1022 // reuse any query id associated with this resource before they complete | 1001 // reuse any query id associated with this resource before they complete |
1023 // as each new query has a unique submit count. | 1002 // as each new query has a unique submit count. |
(...skipping 21 matching lines...) Expand all Loading... |
1045 | 1024 |
1046 if (resource->pixels) { | 1025 if (resource->pixels) { |
1047 if (!resource->pixel_buffer) | 1026 if (!resource->pixel_buffer) |
1048 return; | 1027 return; |
1049 delete[] resource->pixel_buffer; | 1028 delete[] resource->pixel_buffer; |
1050 resource->pixel_buffer = NULL; | 1029 resource->pixel_buffer = NULL; |
1051 } | 1030 } |
1052 } | 1031 } |
1053 | 1032 |
1054 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 1033 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
1055 DCHECK(thread_checker_.CalledOnValidThread()); | 1034 Resource* resource = GetResource(id); |
1056 ResourceMap::iterator it = resources_.find(id); | |
1057 CHECK(it != resources_.end()); | |
1058 Resource* resource = &it->second; | |
1059 DCHECK(!resource->external); | 1035 DCHECK(!resource->external); |
1060 DCHECK_EQ(resource->exported_count, 0); | 1036 DCHECK_EQ(resource->exported_count, 0); |
1061 DCHECK(!resource->image_id); | 1037 DCHECK(!resource->image_id); |
1062 | 1038 |
1063 if (resource->type == GLTexture) { | 1039 if (resource->type == GLTexture) { |
1064 WebGraphicsContext3D* context3d = Context3d(); | 1040 WebGraphicsContext3D* context3d = Context3d(); |
1065 DCHECK(context3d); | 1041 DCHECK(context3d); |
1066 DCHECK(resource->gl_pixel_buffer_id); | 1042 DCHECK(resource->gl_pixel_buffer_id); |
1067 context3d->bindBuffer( | 1043 context3d->bindBuffer( |
1068 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1044 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1069 resource->gl_pixel_buffer_id); | 1045 resource->gl_pixel_buffer_id); |
1070 uint8_t* image = static_cast<uint8_t*>( | 1046 uint8_t* image = static_cast<uint8_t*>( |
1071 context3d->mapBufferCHROMIUM( | 1047 context3d->mapBufferCHROMIUM( |
1072 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 1048 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
1073 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1049 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1074 // Buffer is required to be 4-byte aligned. | 1050 // Buffer is required to be 4-byte aligned. |
1075 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); | 1051 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); |
1076 return image; | 1052 return image; |
1077 } | 1053 } |
1078 | 1054 |
1079 if (resource->pixels) | 1055 if (resource->pixels) |
1080 return resource->pixel_buffer; | 1056 return resource->pixel_buffer; |
1081 | 1057 |
1082 return NULL; | 1058 return NULL; |
1083 } | 1059 } |
1084 | 1060 |
1085 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 1061 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
1086 DCHECK(thread_checker_.CalledOnValidThread()); | 1062 Resource* resource = GetResource(id); |
1087 ResourceMap::iterator it = resources_.find(id); | |
1088 CHECK(it != resources_.end()); | |
1089 Resource* resource = &it->second; | |
1090 DCHECK(!resource->external); | 1063 DCHECK(!resource->external); |
1091 DCHECK_EQ(resource->exported_count, 0); | 1064 DCHECK_EQ(resource->exported_count, 0); |
1092 DCHECK(!resource->image_id); | 1065 DCHECK(!resource->image_id); |
1093 | 1066 |
1094 if (resource->type == GLTexture) { | 1067 if (resource->type == GLTexture) { |
1095 WebGraphicsContext3D* context3d = Context3d(); | 1068 WebGraphicsContext3D* context3d = Context3d(); |
1096 DCHECK(context3d); | 1069 DCHECK(context3d); |
1097 DCHECK(resource->gl_pixel_buffer_id); | 1070 DCHECK(resource->gl_pixel_buffer_id); |
1098 context3d->bindBuffer( | 1071 context3d->bindBuffer( |
1099 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1072 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); | 1124 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); |
1152 if (unit != GL_TEXTURE0) | 1125 if (unit != GL_TEXTURE0) |
1153 GLC(context3d, context3d->activeTexture(unit)); | 1126 GLC(context3d, context3d->activeTexture(unit)); |
1154 context3d->releaseTexImage2DCHROMIUM(target, resource->image_id); | 1127 context3d->releaseTexImage2DCHROMIUM(target, resource->image_id); |
1155 // Active unit being GL_TEXTURE0 is effectively the ground state. | 1128 // Active unit being GL_TEXTURE0 is effectively the ground state. |
1156 if (unit != GL_TEXTURE0) | 1129 if (unit != GL_TEXTURE0) |
1157 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); | 1130 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); |
1158 } | 1131 } |
1159 | 1132 |
1160 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1133 void ResourceProvider::BeginSetPixels(ResourceId id) { |
1161 DCHECK(thread_checker_.CalledOnValidThread()); | 1134 Resource* resource = GetResource(id); |
1162 ResourceMap::iterator it = resources_.find(id); | |
1163 CHECK(it != resources_.end()); | |
1164 Resource* resource = &it->second; | |
1165 DCHECK(!resource->pending_set_pixels); | 1135 DCHECK(!resource->pending_set_pixels); |
1166 | 1136 |
1167 LazyCreate(resource); | 1137 LazyCreate(resource); |
1168 DCHECK(resource->gl_id || resource->allocated); | 1138 DCHECK(resource->gl_id || resource->allocated); |
1169 DCHECK(ReadLockFenceHasPassed(resource)); | 1139 DCHECK(ReadLockFenceHasPassed(resource)); |
1170 DCHECK(!resource->image_id); | 1140 DCHECK(!resource->image_id); |
1171 | 1141 |
1172 bool allocate = !resource->allocated; | 1142 bool allocate = !resource->allocated; |
1173 resource->allocated = true; | 1143 resource->allocated = true; |
1174 LockForWrite(id); | 1144 LockForWrite(id); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 std::swap(resource->pixels, resource->pixel_buffer); | 1189 std::swap(resource->pixels, resource->pixel_buffer); |
1220 delete[] resource->pixel_buffer; | 1190 delete[] resource->pixel_buffer; |
1221 resource->pixel_buffer = NULL; | 1191 resource->pixel_buffer = NULL; |
1222 } | 1192 } |
1223 | 1193 |
1224 resource->pending_set_pixels = true; | 1194 resource->pending_set_pixels = true; |
1225 resource->set_pixels_completion_forced = false; | 1195 resource->set_pixels_completion_forced = false; |
1226 } | 1196 } |
1227 | 1197 |
1228 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | 1198 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
1229 DCHECK(thread_checker_.CalledOnValidThread()); | 1199 Resource* resource = GetResource(id); |
1230 ResourceMap::iterator it = resources_.find(id); | |
1231 CHECK(it != resources_.end()); | |
1232 Resource* resource = &it->second; | |
1233 DCHECK(resource->locked_for_write); | 1200 DCHECK(resource->locked_for_write); |
1234 DCHECK(resource->pending_set_pixels); | 1201 DCHECK(resource->pending_set_pixels); |
1235 DCHECK(!resource->set_pixels_completion_forced); | 1202 DCHECK(!resource->set_pixels_completion_forced); |
1236 | 1203 |
1237 if (resource->gl_id) { | 1204 if (resource->gl_id) { |
1238 WebGraphicsContext3D* context3d = Context3d(); | 1205 WebGraphicsContext3D* context3d = Context3d(); |
1239 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1206 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1240 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); | 1207 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); |
1241 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); | 1208 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); |
1242 } | 1209 } |
1243 | 1210 |
1244 resource->set_pixels_completion_forced = true; | 1211 resource->set_pixels_completion_forced = true; |
1245 } | 1212 } |
1246 | 1213 |
1247 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { | 1214 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { |
1248 DCHECK(thread_checker_.CalledOnValidThread()); | 1215 Resource* resource = GetResource(id); |
1249 ResourceMap::iterator it = resources_.find(id); | |
1250 CHECK(it != resources_.end()); | |
1251 Resource* resource = &it->second; | |
1252 DCHECK(resource->locked_for_write); | 1216 DCHECK(resource->locked_for_write); |
1253 DCHECK(resource->pending_set_pixels); | 1217 DCHECK(resource->pending_set_pixels); |
1254 | 1218 |
1255 if (resource->gl_id) { | 1219 if (resource->gl_id) { |
1256 WebGraphicsContext3D* context3d = Context3d(); | 1220 WebGraphicsContext3D* context3d = Context3d(); |
1257 DCHECK(context3d); | 1221 DCHECK(context3d); |
1258 DCHECK(resource->gl_upload_query_id); | 1222 DCHECK(resource->gl_upload_query_id); |
1259 unsigned complete = 1; | 1223 unsigned complete = 1; |
1260 context3d->getQueryObjectuivEXT( | 1224 context3d->getQueryObjectuivEXT( |
1261 resource->gl_upload_query_id, | 1225 resource->gl_upload_query_id, |
1262 GL_QUERY_RESULT_AVAILABLE_EXT, | 1226 GL_QUERY_RESULT_AVAILABLE_EXT, |
1263 &complete); | 1227 &complete); |
1264 if (!complete) | 1228 if (!complete) |
1265 return false; | 1229 return false; |
1266 } | 1230 } |
1267 | 1231 |
1268 resource->pending_set_pixels = false; | 1232 resource->pending_set_pixels = false; |
1269 UnlockForWrite(id); | 1233 UnlockForWrite(id); |
1270 | 1234 |
1271 return true; | 1235 return true; |
1272 } | 1236 } |
1273 | 1237 |
1274 void ResourceProvider::CreateForTesting(ResourceId id) { | 1238 void ResourceProvider::CreateForTesting(ResourceId id) { |
1275 ResourceMap::iterator it = resources_.find(id); | 1239 LazyCreate(GetResource(id)); |
1276 CHECK(it != resources_.end()); | |
1277 Resource* resource = &it->second; | |
1278 LazyCreate(resource); | |
1279 } | 1240 } |
1280 | 1241 |
1281 void ResourceProvider::LazyCreate(Resource* resource) { | 1242 void ResourceProvider::LazyCreate(Resource* resource) { |
1282 if (resource->type != GLTexture || resource->gl_id != 0) | 1243 if (resource->type != GLTexture || resource->gl_id != 0) |
1283 return; | 1244 return; |
1284 | 1245 |
1285 // Early out for resources that don't require texture creation. | 1246 // Early out for resources that don't require texture creation. |
1286 if (resource->texture_pool == 0) | 1247 if (resource->texture_pool == 0) |
1287 return; | 1248 return; |
1288 | 1249 |
1289 WebGraphicsContext3D* context3d = Context3d(); | 1250 WebGraphicsContext3D* context3d = Context3d(); |
1290 DCHECK(context3d); | 1251 DCHECK(context3d); |
1291 // Create and set texture properties. Allocation is delayed until needed. | 1252 // Create and set texture properties. Allocation is delayed until needed. |
1292 resource->gl_id = CreateTextureId(context3d); | 1253 resource->gl_id = CreateTextureId(context3d); |
1293 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, | 1254 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, |
1294 GL_TEXTURE_POOL_CHROMIUM, | 1255 GL_TEXTURE_POOL_CHROMIUM, |
1295 resource->texture_pool)); | 1256 resource->texture_pool)); |
1296 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { | 1257 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { |
1297 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, | 1258 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, |
1298 GL_TEXTURE_USAGE_ANGLE, | 1259 GL_TEXTURE_USAGE_ANGLE, |
1299 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 1260 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
1300 } | 1261 } |
1301 } | 1262 } |
1302 | 1263 |
1303 void ResourceProvider::AllocateForTesting(ResourceId id) { | 1264 void ResourceProvider::AllocateForTesting(ResourceId id) { |
1304 ResourceMap::iterator it = resources_.find(id); | 1265 LazyAllocate(GetResource(id)); |
1305 CHECK(it != resources_.end()); | |
1306 Resource* resource = &it->second; | |
1307 LazyAllocate(resource); | |
1308 } | 1266 } |
1309 | 1267 |
1310 void ResourceProvider::LazyAllocate(Resource* resource) { | 1268 void ResourceProvider::LazyAllocate(Resource* resource) { |
1311 DCHECK(resource); | 1269 DCHECK(resource); |
1312 LazyCreate(resource); | 1270 LazyCreate(resource); |
1313 | 1271 |
1314 DCHECK(resource->gl_id || resource->allocated); | 1272 DCHECK(resource->gl_id || resource->allocated); |
1315 if (resource->allocated || !resource->gl_id) | 1273 if (resource->allocated || !resource->gl_id) |
1316 return; | 1274 return; |
1317 resource->allocated = true; | 1275 resource->allocated = true; |
(...skipping 16 matching lines...) Expand all Loading... |
1334 size.height(), | 1292 size.height(), |
1335 0, | 1293 0, |
1336 format, | 1294 format, |
1337 GL_UNSIGNED_BYTE, | 1295 GL_UNSIGNED_BYTE, |
1338 NULL)); | 1296 NULL)); |
1339 } | 1297 } |
1340 } | 1298 } |
1341 | 1299 |
1342 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1300 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1343 bool enable) { | 1301 bool enable) { |
1344 DCHECK(thread_checker_.CalledOnValidThread()); | 1302 Resource* resource = GetResource(id); |
1345 ResourceMap::iterator it = resources_.find(id); | |
1346 CHECK(it != resources_.end()); | |
1347 Resource* resource = &it->second; | |
1348 resource->enable_read_lock_fences = enable; | 1303 resource->enable_read_lock_fences = enable; |
1349 } | 1304 } |
1350 | 1305 |
1351 void ResourceProvider::AcquireImage(ResourceId id) { | 1306 void ResourceProvider::AcquireImage(ResourceId id) { |
1352 DCHECK(thread_checker_.CalledOnValidThread()); | 1307 Resource* resource = GetResource(id); |
1353 ResourceMap::iterator it = resources_.find(id); | |
1354 CHECK(it != resources_.end()); | |
1355 Resource* resource = &it->second; | |
1356 | |
1357 DCHECK(!resource->external); | 1308 DCHECK(!resource->external); |
1358 DCHECK_EQ(resource->exported_count, 0); | 1309 DCHECK_EQ(resource->exported_count, 0); |
1359 | 1310 |
1360 if (resource->type != GLTexture) | 1311 if (resource->type != GLTexture) |
1361 return; | 1312 return; |
1362 | 1313 |
1363 if (resource->image_id) | 1314 if (resource->image_id) |
1364 return; | 1315 return; |
1365 | 1316 |
1366 resource->allocated = true; | 1317 resource->allocated = true; |
1367 WebGraphicsContext3D* context3d = Context3d(); | 1318 WebGraphicsContext3D* context3d = Context3d(); |
1368 DCHECK(context3d); | 1319 DCHECK(context3d); |
1369 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); | 1320 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); |
1370 resource->image_id = context3d->createImageCHROMIUM( | 1321 resource->image_id = context3d->createImageCHROMIUM( |
1371 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | 1322 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
1372 DCHECK(resource->image_id); | 1323 DCHECK(resource->image_id); |
1373 } | 1324 } |
1374 | 1325 |
1375 void ResourceProvider::ReleaseImage(ResourceId id) { | 1326 void ResourceProvider::ReleaseImage(ResourceId id) { |
1376 DCHECK(thread_checker_.CalledOnValidThread()); | 1327 Resource* resource = GetResource(id); |
1377 ResourceMap::iterator it = resources_.find(id); | |
1378 CHECK(it != resources_.end()); | |
1379 Resource* resource = &it->second; | |
1380 | |
1381 DCHECK(!resource->external); | 1328 DCHECK(!resource->external); |
1382 DCHECK_EQ(resource->exported_count, 0); | 1329 DCHECK_EQ(resource->exported_count, 0); |
1383 | 1330 |
1384 if (!resource->image_id) | 1331 if (!resource->image_id) |
1385 return; | 1332 return; |
1386 | 1333 |
1387 WebGraphicsContext3D* context3d = Context3d(); | 1334 WebGraphicsContext3D* context3d = Context3d(); |
1388 DCHECK(context3d); | 1335 DCHECK(context3d); |
1389 context3d->destroyImageCHROMIUM(resource->image_id); | 1336 context3d->destroyImageCHROMIUM(resource->image_id); |
1390 resource->image_id = 0; | 1337 resource->image_id = 0; |
1391 resource->allocated = false; | 1338 resource->allocated = false; |
1392 } | 1339 } |
1393 | 1340 |
1394 uint8_t* ResourceProvider::MapImage(ResourceId id) { | 1341 uint8_t* ResourceProvider::MapImage(ResourceId id) { |
1395 DCHECK(thread_checker_.CalledOnValidThread()); | 1342 Resource* resource = GetResource(id); |
1396 ResourceMap::iterator it = resources_.find(id); | |
1397 CHECK(it != resources_.end()); | |
1398 Resource* resource = &it->second; | |
1399 | |
1400 DCHECK(ReadLockFenceHasPassed(resource)); | 1343 DCHECK(ReadLockFenceHasPassed(resource)); |
1401 DCHECK(!resource->external); | 1344 DCHECK(!resource->external); |
1402 DCHECK_EQ(resource->exported_count, 0); | 1345 DCHECK_EQ(resource->exported_count, 0); |
1403 | 1346 |
1404 if (resource->image_id) { | 1347 if (resource->image_id) { |
1405 WebGraphicsContext3D* context3d = Context3d(); | 1348 WebGraphicsContext3D* context3d = Context3d(); |
1406 DCHECK(context3d); | 1349 DCHECK(context3d); |
1407 return static_cast<uint8_t*>( | 1350 return static_cast<uint8_t*>( |
1408 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); | 1351 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); |
1409 } | 1352 } |
1410 | 1353 |
1411 if (resource->pixels) | 1354 if (resource->pixels) |
1412 return resource->pixels; | 1355 return resource->pixels; |
1413 | 1356 |
1414 return NULL; | 1357 return NULL; |
1415 } | 1358 } |
1416 | 1359 |
1417 void ResourceProvider::UnmapImage(ResourceId id) { | 1360 void ResourceProvider::UnmapImage(ResourceId id) { |
1418 DCHECK(thread_checker_.CalledOnValidThread()); | 1361 Resource* resource = GetResource(id); |
1419 ResourceMap::iterator it = resources_.find(id); | |
1420 CHECK(it != resources_.end()); | |
1421 Resource* resource = &it->second; | |
1422 | |
1423 DCHECK(!resource->external); | 1362 DCHECK(!resource->external); |
1424 DCHECK_EQ(resource->exported_count, 0); | 1363 DCHECK_EQ(resource->exported_count, 0); |
1425 | 1364 |
1426 if (resource->image_id) { | 1365 if (resource->image_id) { |
1427 WebGraphicsContext3D* context3d = Context3d(); | 1366 WebGraphicsContext3D* context3d = Context3d(); |
1428 DCHECK(context3d); | 1367 DCHECK(context3d); |
1429 context3d->unmapImageCHROMIUM(resource->image_id); | 1368 context3d->unmapImageCHROMIUM(resource->image_id); |
1430 } | 1369 } |
1431 } | 1370 } |
1432 | 1371 |
1433 int ResourceProvider::GetImageStride(ResourceId id) { | 1372 int ResourceProvider::GetImageStride(ResourceId id) { |
1434 DCHECK(thread_checker_.CalledOnValidThread()); | 1373 Resource* resource = GetResource(id); |
1435 ResourceMap::iterator it = resources_.find(id); | |
1436 CHECK(it != resources_.end()); | |
1437 Resource* resource = &it->second; | |
1438 | |
1439 DCHECK(!resource->external); | 1374 DCHECK(!resource->external); |
1440 DCHECK_EQ(resource->exported_count, 0); | 1375 DCHECK_EQ(resource->exported_count, 0); |
1441 | 1376 |
1442 int stride = 0; | 1377 int stride = 0; |
1443 | 1378 |
1444 if (resource->image_id) { | 1379 if (resource->image_id) { |
1445 WebGraphicsContext3D* context3d = Context3d(); | 1380 WebGraphicsContext3D* context3d = Context3d(); |
1446 DCHECK(context3d); | 1381 DCHECK(context3d); |
1447 context3d->getImageParameterivCHROMIUM( | 1382 context3d->getImageParameterivCHROMIUM( |
1448 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); | 1383 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); |
1449 } | 1384 } |
1450 | 1385 |
1451 return stride; | 1386 return stride; |
1452 } | 1387 } |
1453 | 1388 |
1454 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { | 1389 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { |
1455 GLint active_unit = 0; | 1390 GLint active_unit = 0; |
1456 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1391 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1457 return active_unit; | 1392 return active_unit; |
1458 } | 1393 } |
1459 | 1394 |
1460 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1395 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
1461 ContextProvider* context_provider = output_surface_->context_provider(); | 1396 ContextProvider* context_provider = output_surface_->context_provider(); |
1462 return context_provider ? context_provider->Context3d() : NULL; | 1397 return context_provider ? context_provider->Context3d() : NULL; |
1463 } | 1398 } |
1464 | 1399 |
1465 } // namespace cc | 1400 } // namespace cc |
OLD | NEW |