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

Side by Side Diff: cc/resources/resource_provider.cc

Issue 23023005: cc: refcount resources as we send them to the parent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 } // namespace 67 } // namespace
68 68
69 ResourceProvider::Resource::Resource() 69 ResourceProvider::Resource::Resource()
70 : gl_id(0), 70 : gl_id(0),
71 gl_pixel_buffer_id(0), 71 gl_pixel_buffer_id(0),
72 gl_upload_query_id(0), 72 gl_upload_query_id(0),
73 pixels(NULL), 73 pixels(NULL),
74 pixel_buffer(NULL), 74 pixel_buffer(NULL),
75 lock_for_read_count(0), 75 lock_for_read_count(0),
76 imported_count(0),
77 exported_count(0),
76 locked_for_write(false), 78 locked_for_write(false),
77 external(false), 79 external(false),
78 exported(false),
79 marked_for_deletion(false), 80 marked_for_deletion(false),
80 pending_set_pixels(false), 81 pending_set_pixels(false),
81 set_pixels_completion_forced(false), 82 set_pixels_completion_forced(false),
82 allocated(false), 83 allocated(false),
83 enable_read_lock_fences(false), 84 enable_read_lock_fences(false),
84 read_lock_fence(NULL), 85 read_lock_fence(NULL),
85 size(), 86 size(),
86 format(0), 87 format(0),
87 filter(0), 88 filter(0),
88 image_id(0), 89 image_id(0),
89 texture_pool(0), 90 texture_pool(0),
90 hint(TextureUsageAny), 91 hint(TextureUsageAny),
91 type(static_cast<ResourceType>(0)) {} 92 type(static_cast<ResourceType>(0)) {}
92 93
93 ResourceProvider::Resource::~Resource() {} 94 ResourceProvider::Resource::~Resource() {}
94 95
95 ResourceProvider::Resource::Resource( 96 ResourceProvider::Resource::Resource(
96 unsigned texture_id, 97 unsigned texture_id,
97 gfx::Size size, 98 gfx::Size size,
98 GLenum format, 99 GLenum format,
99 GLenum filter, 100 GLenum filter,
100 GLenum texture_pool, 101 GLenum texture_pool,
101 TextureUsageHint hint) 102 TextureUsageHint hint)
102 : gl_id(texture_id), 103 : gl_id(texture_id),
103 gl_pixel_buffer_id(0), 104 gl_pixel_buffer_id(0),
104 gl_upload_query_id(0), 105 gl_upload_query_id(0),
105 pixels(NULL), 106 pixels(NULL),
106 pixel_buffer(NULL), 107 pixel_buffer(NULL),
107 lock_for_read_count(0), 108 lock_for_read_count(0),
109 imported_count(0),
110 exported_count(0),
108 locked_for_write(false), 111 locked_for_write(false),
109 external(false), 112 external(false),
110 exported(false),
111 marked_for_deletion(false), 113 marked_for_deletion(false),
112 pending_set_pixels(false), 114 pending_set_pixels(false),
113 set_pixels_completion_forced(false), 115 set_pixels_completion_forced(false),
114 allocated(false), 116 allocated(false),
115 enable_read_lock_fences(false), 117 enable_read_lock_fences(false),
116 read_lock_fence(NULL), 118 read_lock_fence(NULL),
117 size(size), 119 size(size),
118 format(format), 120 format(format),
119 filter(filter), 121 filter(filter),
120 image_id(0), 122 image_id(0),
121 texture_pool(texture_pool), 123 texture_pool(texture_pool),
122 hint(hint), 124 hint(hint),
123 type(GLTexture) {} 125 type(GLTexture) {}
124 126
125 ResourceProvider::Resource::Resource( 127 ResourceProvider::Resource::Resource(
126 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) 128 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter)
127 : gl_id(0), 129 : gl_id(0),
128 gl_pixel_buffer_id(0), 130 gl_pixel_buffer_id(0),
129 gl_upload_query_id(0), 131 gl_upload_query_id(0),
130 pixels(pixels), 132 pixels(pixels),
131 pixel_buffer(NULL), 133 pixel_buffer(NULL),
132 lock_for_read_count(0), 134 lock_for_read_count(0),
135 imported_count(0),
136 exported_count(0),
133 locked_for_write(false), 137 locked_for_write(false),
134 external(false), 138 external(false),
135 exported(false),
136 marked_for_deletion(false), 139 marked_for_deletion(false),
137 pending_set_pixels(false), 140 pending_set_pixels(false),
138 set_pixels_completion_forced(false), 141 set_pixels_completion_forced(false),
139 allocated(false), 142 allocated(false),
140 enable_read_lock_fences(false), 143 enable_read_lock_fences(false),
141 read_lock_fence(NULL), 144 read_lock_fence(NULL),
142 size(size), 145 size(size),
143 format(format), 146 format(format),
144 filter(filter), 147 filter(filter),
145 image_id(0), 148 image_id(0),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 WebGraphicsContext3D* ResourceProvider::GraphicsContext3D() { 185 WebGraphicsContext3D* ResourceProvider::GraphicsContext3D() {
183 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(thread_checker_.CalledOnValidThread());
184 return output_surface_->context3d(); 187 return output_surface_->context3d();
185 } 188 }
186 189
187 bool ResourceProvider::InUseByConsumer(ResourceId id) { 190 bool ResourceProvider::InUseByConsumer(ResourceId id) {
188 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
189 ResourceMap::iterator it = resources_.find(id); 192 ResourceMap::iterator it = resources_.find(id);
190 CHECK(it != resources_.end()); 193 CHECK(it != resources_.end());
191 Resource* resource = &it->second; 194 Resource* resource = &it->second;
192 return !!resource->lock_for_read_count || resource->exported; 195 return resource->lock_for_read_count > 0 || resource->exported_count > 0;
193 } 196 }
194 197
195 ResourceProvider::ResourceId ResourceProvider::CreateResource( 198 ResourceProvider::ResourceId ResourceProvider::CreateResource(
196 gfx::Size size, GLenum format, TextureUsageHint hint) { 199 gfx::Size size, GLenum format, TextureUsageHint hint) {
197 DCHECK(!size.IsEmpty()); 200 DCHECK(!size.IsEmpty());
198 switch (default_resource_type_) { 201 switch (default_resource_type_) {
199 case GLTexture: 202 case GLTexture:
200 return CreateGLTexture( 203 return CreateGLTexture(
201 size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, hint); 204 size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, hint);
202 case Bitmap: 205 case Bitmap:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return id; 305 return id;
303 } 306 }
304 307
305 void ResourceProvider::DeleteResource(ResourceId id) { 308 void ResourceProvider::DeleteResource(ResourceId id) {
306 DCHECK(thread_checker_.CalledOnValidThread()); 309 DCHECK(thread_checker_.CalledOnValidThread());
307 ResourceMap::iterator it = resources_.find(id); 310 ResourceMap::iterator it = resources_.find(id);
308 CHECK(it != resources_.end()); 311 CHECK(it != resources_.end());
309 Resource* resource = &it->second; 312 Resource* resource = &it->second;
310 DCHECK(!resource->lock_for_read_count); 313 DCHECK(!resource->lock_for_read_count);
311 DCHECK(!resource->marked_for_deletion); 314 DCHECK(!resource->marked_for_deletion);
315 DCHECK_EQ(resource->imported_count, 0);
312 DCHECK(resource->pending_set_pixels || !resource->locked_for_write); 316 DCHECK(resource->pending_set_pixels || !resource->locked_for_write);
313 317
314 if (resource->exported) { 318 if (resource->exported_count > 0) {
315 resource->marked_for_deletion = true; 319 resource->marked_for_deletion = true;
316 return; 320 return;
317 } else { 321 } else {
318 DeleteResourceInternal(it, Normal); 322 DeleteResourceInternal(it, Normal);
319 } 323 }
320 } 324 }
321 325
322 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, 326 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
323 DeleteStyle style) { 327 DeleteStyle style) {
324 Resource* resource = &it->second; 328 Resource* resource = &it->second;
325 bool lost_resource = lost_output_surface_; 329 bool lost_resource = lost_output_surface_;
326 330
327 DCHECK(!resource->exported || style != Normal); 331 DCHECK(resource->exported_count == 0 || style != Normal);
328 if (style == ForShutdown && resource->exported) 332 if (style == ForShutdown && resource->exported_count > 0)
329 lost_resource = true; 333 lost_resource = true;
330 334
331 if (resource->image_id) { 335 if (resource->image_id) {
332 WebGraphicsContext3D* context3d = output_surface_->context3d(); 336 WebGraphicsContext3D* context3d = output_surface_->context3d();
333 DCHECK(context3d); 337 DCHECK(context3d);
334 GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id)); 338 GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id));
335 } 339 }
336 340
337 if (resource->gl_id && !resource->external) { 341 if (resource->gl_id && !resource->external) {
338 WebGraphicsContext3D* context3d = output_surface_->context3d(); 342 WebGraphicsContext3D* context3d = output_surface_->context3d();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 gfx::Rect image_rect, 393 gfx::Rect image_rect,
390 gfx::Rect source_rect, 394 gfx::Rect source_rect,
391 gfx::Vector2d dest_offset) { 395 gfx::Vector2d dest_offset) {
392 DCHECK(thread_checker_.CalledOnValidThread()); 396 DCHECK(thread_checker_.CalledOnValidThread());
393 ResourceMap::iterator it = resources_.find(id); 397 ResourceMap::iterator it = resources_.find(id);
394 CHECK(it != resources_.end()); 398 CHECK(it != resources_.end());
395 Resource* resource = &it->second; 399 Resource* resource = &it->second;
396 DCHECK(!resource->locked_for_write); 400 DCHECK(!resource->locked_for_write);
397 DCHECK(!resource->lock_for_read_count); 401 DCHECK(!resource->lock_for_read_count);
398 DCHECK(!resource->external); 402 DCHECK(!resource->external);
399 DCHECK(!resource->exported); 403 DCHECK_EQ(resource->exported_count, 0);
400 DCHECK(ReadLockFenceHasPassed(resource)); 404 DCHECK(ReadLockFenceHasPassed(resource));
401 LazyAllocate(resource); 405 LazyAllocate(resource);
402 406
403 if (resource->gl_id) { 407 if (resource->gl_id) {
404 DCHECK(!resource->pending_set_pixels); 408 DCHECK(!resource->pending_set_pixels);
405 WebGraphicsContext3D* context3d = output_surface_->context3d(); 409 WebGraphicsContext3D* context3d = output_surface_->context3d();
406 DCHECK(context3d); 410 DCHECK(context3d);
407 DCHECK(texture_uploader_.get()); 411 DCHECK(texture_uploader_.get());
408 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 412 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
409 texture_uploader_->Upload(image, 413 texture_uploader_->Upload(image,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 500
497 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { 501 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
498 DCHECK(thread_checker_.CalledOnValidThread()); 502 DCHECK(thread_checker_.CalledOnValidThread());
499 ResourceMap::iterator it = resources_.find(id); 503 ResourceMap::iterator it = resources_.find(id);
500 CHECK(it != resources_.end()); 504 CHECK(it != resources_.end());
501 Resource* resource = &it->second; 505 Resource* resource = &it->second;
502 DCHECK(!resource->locked_for_write || 506 DCHECK(!resource->locked_for_write ||
503 resource->set_pixels_completion_forced) << 507 resource->set_pixels_completion_forced) <<
504 "locked for write: " << resource->locked_for_write << 508 "locked for write: " << resource->locked_for_write <<
505 " pixels completion forced: " << resource->set_pixels_completion_forced; 509 " pixels completion forced: " << resource->set_pixels_completion_forced;
506 DCHECK(!resource->exported); 510 DCHECK_EQ(resource->exported_count, 0);
507 // Uninitialized! Call SetPixels or LockForWrite first. 511 // Uninitialized! Call SetPixels or LockForWrite first.
508 DCHECK(resource->allocated); 512 DCHECK(resource->allocated);
509 513
510 LazyCreate(resource); 514 LazyCreate(resource);
511 515
512 if (resource->external) { 516 if (resource->external) {
513 if (!resource->gl_id && resource->mailbox.IsTexture()) { 517 if (!resource->gl_id && resource->mailbox.IsTexture()) {
514 WebGraphicsContext3D* context3d = output_surface_->context3d(); 518 WebGraphicsContext3D* context3d = output_surface_->context3d();
515 DCHECK(context3d); 519 DCHECK(context3d);
516 if (resource->mailbox.sync_point()) { 520 if (resource->mailbox.sync_point()) {
(...skipping 15 matching lines...) Expand all
532 536
533 return resource; 537 return resource;
534 } 538 }
535 539
536 void ResourceProvider::UnlockForRead(ResourceId id) { 540 void ResourceProvider::UnlockForRead(ResourceId id) {
537 DCHECK(thread_checker_.CalledOnValidThread()); 541 DCHECK(thread_checker_.CalledOnValidThread());
538 ResourceMap::iterator it = resources_.find(id); 542 ResourceMap::iterator it = resources_.find(id);
539 CHECK(it != resources_.end()); 543 CHECK(it != resources_.end());
540 Resource* resource = &it->second; 544 Resource* resource = &it->second;
541 DCHECK_GT(resource->lock_for_read_count, 0); 545 DCHECK_GT(resource->lock_for_read_count, 0);
542 DCHECK(!resource->exported); 546 DCHECK_EQ(resource->exported_count, 0);
543 resource->lock_for_read_count--; 547 resource->lock_for_read_count--;
544 } 548 }
545 549
546 const ResourceProvider::Resource* ResourceProvider::LockForWrite( 550 const ResourceProvider::Resource* ResourceProvider::LockForWrite(
547 ResourceId id) { 551 ResourceId id) {
548 DCHECK(thread_checker_.CalledOnValidThread()); 552 DCHECK(thread_checker_.CalledOnValidThread());
549 ResourceMap::iterator it = resources_.find(id); 553 ResourceMap::iterator it = resources_.find(id);
550 CHECK(it != resources_.end()); 554 CHECK(it != resources_.end());
551 Resource* resource = &it->second; 555 Resource* resource = &it->second;
552 DCHECK(!resource->locked_for_write); 556 DCHECK(!resource->locked_for_write);
553 DCHECK(!resource->lock_for_read_count); 557 DCHECK(!resource->lock_for_read_count);
554 DCHECK(!resource->exported); 558 DCHECK_EQ(resource->exported_count, 0);
555 DCHECK(!resource->external); 559 DCHECK(!resource->external);
556 DCHECK(ReadLockFenceHasPassed(resource)); 560 DCHECK(ReadLockFenceHasPassed(resource));
557 LazyAllocate(resource); 561 LazyAllocate(resource);
558 562
559 resource->locked_for_write = true; 563 resource->locked_for_write = true;
560 return resource; 564 return resource;
561 } 565 }
562 566
563 bool ResourceProvider::CanLockForWrite(ResourceId id) { 567 bool ResourceProvider::CanLockForWrite(ResourceId id) {
564 DCHECK(thread_checker_.CalledOnValidThread()); 568 DCHECK(thread_checker_.CalledOnValidThread());
565 ResourceMap::iterator it = resources_.find(id); 569 ResourceMap::iterator it = resources_.find(id);
566 CHECK(it != resources_.end()); 570 CHECK(it != resources_.end());
567 Resource* resource = &it->second; 571 Resource* resource = &it->second;
568 return !resource->locked_for_write && 572 return !resource->locked_for_write &&
569 !resource->lock_for_read_count && 573 !resource->lock_for_read_count &&
570 !resource->exported && 574 !resource->exported_count &&
571 !resource->external && 575 !resource->external &&
572 ReadLockFenceHasPassed(resource); 576 ReadLockFenceHasPassed(resource);
573 } 577 }
574 578
575 void ResourceProvider::UnlockForWrite(ResourceId id) { 579 void ResourceProvider::UnlockForWrite(ResourceId id) {
576 DCHECK(thread_checker_.CalledOnValidThread()); 580 DCHECK(thread_checker_.CalledOnValidThread());
577 ResourceMap::iterator it = resources_.find(id); 581 ResourceMap::iterator it = resources_.find(id);
578 CHECK(it != resources_.end()); 582 CHECK(it != resources_.end());
579 Resource* resource = &it->second; 583 Resource* resource = &it->second;
580 DCHECK(resource->locked_for_write); 584 DCHECK(resource->locked_for_write);
581 DCHECK(!resource->exported); 585 DCHECK_EQ(resource->exported_count, 0);
582 DCHECK(!resource->external); 586 DCHECK(!resource->external);
583 resource->locked_for_write = false; 587 resource->locked_for_write = false;
584 } 588 }
585 589
586 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( 590 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(
587 ResourceProvider* resource_provider, 591 ResourceProvider* resource_provider,
588 ResourceProvider::ResourceId resource_id) 592 ResourceProvider::ResourceId resource_id)
589 : resource_provider_(resource_provider), 593 : resource_provider_(resource_provider),
590 resource_id_(resource_id), 594 resource_id_(resource_id),
591 texture_id_(resource_provider->LockForRead(resource_id)->gl_id) { 595 texture_id_(resource_provider->LockForRead(resource_id)->gl_id) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return child; 766 return child;
763 } 767 }
764 768
765 void ResourceProvider::DestroyChild(int child_id) { 769 void ResourceProvider::DestroyChild(int child_id) {
766 DCHECK(thread_checker_.CalledOnValidThread()); 770 DCHECK(thread_checker_.CalledOnValidThread());
767 ChildMap::iterator it = children_.find(child_id); 771 ChildMap::iterator it = children_.find(child_id);
768 DCHECK(it != children_.end()); 772 DCHECK(it != children_.end());
769 Child& child = it->second; 773 Child& child = it->second;
770 for (ResourceIdMap::iterator child_it = child.child_to_parent_map.begin(); 774 for (ResourceIdMap::iterator child_it = child.child_to_parent_map.begin();
771 child_it != child.child_to_parent_map.end(); 775 child_it != child.child_to_parent_map.end();
772 ++child_it) 776 ++child_it) {
773 DeleteResource(child_it->second); 777 ResourceId id = child_it->second;
778 // We're abandoning this resource, it will not get recycled.
779 // crbug.com/224062
780 ResourceMap::iterator resource_it = resources_.find(id);
781 CHECK(resource_it != resources_.end());
782 resource_it->second.imported_count = 0;
783 DeleteResource(id);
784 }
774 children_.erase(it); 785 children_.erase(it);
775 } 786 }
776 787
777 const ResourceProvider::ResourceIdMap& ResourceProvider::GetChildToParentMap( 788 const ResourceProvider::ResourceIdMap& ResourceProvider::GetChildToParentMap(
778 int child) const { 789 int child) const {
779 DCHECK(thread_checker_.CalledOnValidThread()); 790 DCHECK(thread_checker_.CalledOnValidThread());
780 ChildMap::const_iterator it = children_.find(child); 791 ChildMap::const_iterator it = children_.find(child);
781 DCHECK(it != children_.end()); 792 DCHECK(it != children_.end());
782 return it->second.child_to_parent_map; 793 return it->second.child_to_parent_map;
783 } 794 }
784 795
785 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, 796 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources,
786 TransferableResourceArray* list) { 797 TransferableResourceArray* list) {
787 DCHECK(thread_checker_.CalledOnValidThread()); 798 DCHECK(thread_checker_.CalledOnValidThread());
788 WebGraphicsContext3D* context3d = output_surface_->context3d(); 799 WebGraphicsContext3D* context3d = output_surface_->context3d();
789 if (!context3d || !context3d->makeContextCurrent()) { 800 if (!context3d || !context3d->makeContextCurrent()) {
790 // TODO(skaslev): Implement this path for software compositing. 801 // TODO(skaslev): Implement this path for software compositing.
791 return; 802 return;
792 } 803 }
793 bool need_sync_point = false; 804 bool need_sync_point = false;
794 for (ResourceIdArray::const_iterator it = resources.begin(); 805 for (ResourceIdArray::const_iterator it = resources.begin();
795 it != resources.end(); 806 it != resources.end();
796 ++it) { 807 ++it) {
797 TransferableResource resource; 808 TransferableResource resource;
798 if (TransferResource(context3d, *it, &resource)) { 809 TransferResource(context3d, *it, &resource);
799 if (!resource.sync_point) 810 if (!resource.sync_point)
800 need_sync_point = true; 811 need_sync_point = true;
801 resources_.find(*it)->second.exported = true; 812 ++resources_.find(*it)->second.exported_count;
802 list->push_back(resource); 813 list->push_back(resource);
803 }
804 } 814 }
805 if (need_sync_point) { 815 if (need_sync_point) {
806 unsigned int sync_point = context3d->insertSyncPoint(); 816 unsigned int sync_point = context3d->insertSyncPoint();
807 for (TransferableResourceArray::iterator it = list->begin(); 817 for (TransferableResourceArray::iterator it = list->begin();
808 it != list->end(); 818 it != list->end();
809 ++it) { 819 ++it) {
810 if (!it->sync_point) 820 if (!it->sync_point)
811 it->sync_point = sync_point; 821 it->sync_point = sync_point;
812 } 822 }
813 } 823 }
814 } 824 }
815 825
816 void ResourceProvider::PrepareSendToChild(int child, 826 void ResourceProvider::PrepareSendToChild(int child,
817 const ResourceIdArray& resources, 827 const ResourceIdArray& resources,
818 TransferableResourceArray* list) { 828 TransferableResourceArray* list) {
819 DCHECK(thread_checker_.CalledOnValidThread()); 829 DCHECK(thread_checker_.CalledOnValidThread());
820 WebGraphicsContext3D* context3d = output_surface_->context3d(); 830 WebGraphicsContext3D* context3d = output_surface_->context3d();
821 if (!context3d || !context3d->makeContextCurrent()) { 831 if (!context3d || !context3d->makeContextCurrent()) {
822 // TODO(skaslev): Implement this path for software compositing. 832 // TODO(skaslev): Implement this path for software compositing.
823 return; 833 return;
824 } 834 }
825 Child& child_info = children_.find(child)->second; 835 Child& child_info = children_.find(child)->second;
826 bool need_sync_point = false; 836 bool need_sync_point = false;
827 for (ResourceIdArray::const_iterator it = resources.begin(); 837 for (ResourceIdArray::const_iterator it = resources.begin();
828 it != resources.end(); 838 it != resources.end();
829 ++it) { 839 ++it) {
830 TransferableResource resource; 840 TransferableResource resource;
831 if (!TransferResource(context3d, *it, &resource)) 841 TransferResource(context3d, *it, &resource);
832 NOTREACHED();
833 if (!resource.sync_point) 842 if (!resource.sync_point)
834 need_sync_point = true; 843 need_sync_point = true;
835 DCHECK(child_info.parent_to_child_map.find(*it) != 844 DCHECK(child_info.parent_to_child_map.find(*it) !=
836 child_info.parent_to_child_map.end()); 845 child_info.parent_to_child_map.end());
837 resource.id = child_info.parent_to_child_map[*it]; 846 resource.id = child_info.parent_to_child_map[*it];
838 child_info.parent_to_child_map.erase(*it); 847 child_info.parent_to_child_map.erase(*it);
839 child_info.child_to_parent_map.erase(resource.id); 848 child_info.child_to_parent_map.erase(resource.id);
840 list->push_back(resource); 849 for (int i = 0; i < resources_[*it].imported_count; ++i)
850 list->push_back(resource);
851 resources_[*it].imported_count = 0;
841 DeleteResource(*it); 852 DeleteResource(*it);
842 } 853 }
843 if (need_sync_point) { 854 if (need_sync_point) {
844 unsigned int sync_point = context3d->insertSyncPoint(); 855 unsigned int sync_point = context3d->insertSyncPoint();
845 for (TransferableResourceArray::iterator it = list->begin(); 856 for (TransferableResourceArray::iterator it = list->begin();
846 it != list->end(); 857 it != list->end();
847 ++it) { 858 ++it) {
848 if (!it->sync_point) 859 if (!it->sync_point)
849 it->sync_point = sync_point; 860 it->sync_point = sync_point;
850 } 861 }
851 } 862 }
852 } 863 }
853 864
854 void ResourceProvider::ReceiveFromChild( 865 void ResourceProvider::ReceiveFromChild(
855 int child, const TransferableResourceArray& resources) { 866 int child, const TransferableResourceArray& resources) {
856 DCHECK(thread_checker_.CalledOnValidThread()); 867 DCHECK(thread_checker_.CalledOnValidThread());
857 WebGraphicsContext3D* context3d = output_surface_->context3d(); 868 WebGraphicsContext3D* context3d = output_surface_->context3d();
858 if (!context3d || !context3d->makeContextCurrent()) { 869 if (!context3d || !context3d->makeContextCurrent()) {
859 // TODO(skaslev): Implement this path for software compositing. 870 // TODO(skaslev): Implement this path for software compositing.
860 return; 871 return;
861 } 872 }
862 Child& child_info = children_.find(child)->second; 873 Child& child_info = children_.find(child)->second;
863 for (TransferableResourceArray::const_iterator it = resources.begin(); 874 for (TransferableResourceArray::const_iterator it = resources.begin();
864 it != resources.end(); 875 it != resources.end();
865 ++it) { 876 ++it) {
877 ResourceIdMap::iterator resource_in_map_it =
878 child_info.child_to_parent_map.find(it->id);
879 if (resource_in_map_it != child_info.child_to_parent_map.end()) {
880 resources_[resource_in_map_it->second].imported_count++;
881 continue;
882 }
866 unsigned texture_id; 883 unsigned texture_id;
867 // NOTE: If the parent is a browser and the child a renderer, the parent 884 // NOTE: If the parent is a browser and the child a renderer, the parent
868 // is not supposed to have its context wait, because that could induce 885 // is not supposed to have its context wait, because that could induce
869 // deadlocks and/or security issues. The caller is responsible for 886 // deadlocks and/or security issues. The caller is responsible for
870 // waiting asynchronously, and resetting sync_point before calling this. 887 // waiting asynchronously, and resetting sync_point before calling this.
871 // However if the parent is a renderer (e.g. browser tag), it may be ok 888 // However if the parent is a renderer (e.g. browser tag), it may be ok
872 // (and is simpler) to wait. 889 // (and is simpler) to wait.
873 if (it->sync_point) 890 if (it->sync_point)
874 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 891 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
875 GLC(context3d, texture_id = context3d->createTexture()); 892 GLC(context3d, texture_id = context3d->createTexture());
876 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 893 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
877 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 894 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
878 it->mailbox.name)); 895 it->mailbox.name));
879 ResourceId id = next_id_++; 896 ResourceId id = next_id_++;
880 Resource resource( 897 Resource resource(
881 texture_id, it->size, it->format, it->filter, 0, TextureUsageAny); 898 texture_id, it->size, it->format, it->filter, 0, TextureUsageAny);
882 resource.mailbox.SetName(it->mailbox); 899 resource.mailbox.SetName(it->mailbox);
883 // Don't allocate a texture for a child. 900 // Don't allocate a texture for a child.
884 resource.allocated = true; 901 resource.allocated = true;
902 resource.imported_count = 1;
885 resources_[id] = resource; 903 resources_[id] = resource;
886 child_info.parent_to_child_map[id] = it->id; 904 child_info.parent_to_child_map[id] = it->id;
887 child_info.child_to_parent_map[it->id] = id; 905 child_info.child_to_parent_map[it->id] = id;
888 } 906 }
889 } 907 }
890 908
891 void ResourceProvider::ReceiveFromParent( 909 void ResourceProvider::ReceiveFromParent(
892 const TransferableResourceArray& resources) { 910 const TransferableResourceArray& resources) {
893 DCHECK(thread_checker_.CalledOnValidThread()); 911 DCHECK(thread_checker_.CalledOnValidThread());
894 WebGraphicsContext3D* context3d = output_surface_->context3d(); 912 WebGraphicsContext3D* context3d = output_surface_->context3d();
895 if (!context3d || !context3d->makeContextCurrent()) { 913 if (!context3d || !context3d->makeContextCurrent()) {
896 // TODO(skaslev): Implement this path for software compositing. 914 // TODO(skaslev): Implement this path for software compositing.
897 return; 915 return;
898 } 916 }
899 for (TransferableResourceArray::const_iterator it = resources.begin(); 917 for (TransferableResourceArray::const_iterator it = resources.begin();
900 it != resources.end(); 918 it != resources.end();
901 ++it) { 919 ++it) {
902 ResourceMap::iterator map_iterator = resources_.find(it->id); 920 ResourceMap::iterator map_iterator = resources_.find(it->id);
903 DCHECK(map_iterator != resources_.end()); 921 DCHECK(map_iterator != resources_.end());
904 Resource* resource = &map_iterator->second; 922 Resource* resource = &map_iterator->second;
905 DCHECK(resource->exported); 923 DCHECK_GT(resource->exported_count, 0);
906 resource->exported = false; 924 --resource->exported_count;
925 if (resource->exported_count)
926 continue;
907 resource->filter = it->filter; 927 resource->filter = it->filter;
908 DCHECK(resource->mailbox.ContainsMailbox(it->mailbox)); 928 DCHECK(resource->mailbox.ContainsMailbox(it->mailbox));
909 if (resource->gl_id) { 929 if (resource->gl_id) {
910 if (it->sync_point) 930 if (it->sync_point)
911 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 931 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
912 } else { 932 } else {
913 resource->mailbox = TextureMailbox(resource->mailbox.name(), 933 resource->mailbox = TextureMailbox(resource->mailbox.name(),
914 resource->mailbox.callback(), 934 resource->mailbox.callback(),
915 it->sync_point); 935 it->sync_point);
916 } 936 }
917 if (resource->marked_for_deletion) 937 if (resource->marked_for_deletion)
918 DeleteResourceInternal(map_iterator, Normal); 938 DeleteResourceInternal(map_iterator, Normal);
919 } 939 }
920 } 940 }
921 941
922 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, 942 void ResourceProvider::TransferResource(WebGraphicsContext3D* context,
923 ResourceId id, 943 ResourceId id,
924 TransferableResource* resource) { 944 TransferableResource* resource) {
925 DCHECK(thread_checker_.CalledOnValidThread()); 945 DCHECK(thread_checker_.CalledOnValidThread());
926 ResourceMap::iterator it = resources_.find(id); 946 ResourceMap::iterator it = resources_.find(id);
927 CHECK(it != resources_.end()); 947 CHECK(it != resources_.end());
928 Resource* source = &it->second; 948 Resource* source = &it->second;
929 DCHECK(!source->locked_for_write); 949 DCHECK(!source->locked_for_write);
930 DCHECK(!source->lock_for_read_count); 950 DCHECK(!source->lock_for_read_count);
931 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); 951 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
932 DCHECK(source->allocated); 952 DCHECK(source->allocated);
933 if (source->exported)
934 return false;
935 resource->id = id; 953 resource->id = id;
936 resource->format = source->format; 954 resource->format = source->format;
937 resource->filter = source->filter; 955 resource->filter = source->filter;
938 resource->size = source->size; 956 resource->size = source->size;
939 957
940 // TODO(skaslev) Implement this path for shared memory resources. 958 // TODO(skaslev) Implement this path for shared memory resources.
941 DCHECK(!source->mailbox.IsSharedMemory()); 959 DCHECK(!source->mailbox.IsSharedMemory());
942 960
943 if (!source->mailbox.IsTexture()) { 961 if (!source->mailbox.IsTexture()) {
944 // This is a resource allocated by the compositor, we need to produce it. 962 // This is a resource allocated by the compositor, we need to produce it.
945 // Don't set a sync point, the caller will do it. 963 // Don't set a sync point, the caller will do it.
946 DCHECK(source->gl_id); 964 DCHECK(source->gl_id);
947 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 965 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
948 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); 966 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name));
949 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, 967 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D,
950 resource->mailbox.name)); 968 resource->mailbox.name));
951 source->mailbox.SetName(resource->mailbox); 969 source->mailbox.SetName(resource->mailbox);
952 } else { 970 } else {
953 // This is either an external resource, or a compositor resource that we 971 // This is either an external resource, or a compositor resource that we
954 // already exported. Make sure to forward the sync point that we were given. 972 // already exported. Make sure to forward the sync point that we were given.
955 resource->mailbox = source->mailbox.name(); 973 resource->mailbox = source->mailbox.name();
956 resource->sync_point = source->mailbox.sync_point(); 974 resource->sync_point = source->mailbox.sync_point();
957 source->mailbox.ResetSyncPoint(); 975 source->mailbox.ResetSyncPoint();
958 } 976 }
959
960 return true;
961 } 977 }
962 978
963 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { 979 void ResourceProvider::AcquirePixelBuffer(ResourceId id) {
964 DCHECK(thread_checker_.CalledOnValidThread()); 980 DCHECK(thread_checker_.CalledOnValidThread());
965 ResourceMap::iterator it = resources_.find(id); 981 ResourceMap::iterator it = resources_.find(id);
966 CHECK(it != resources_.end()); 982 CHECK(it != resources_.end());
967 Resource* resource = &it->second; 983 Resource* resource = &it->second;
968 DCHECK(!resource->external); 984 DCHECK(!resource->external);
969 DCHECK(!resource->exported); 985 DCHECK_EQ(resource->exported_count, 0);
970 DCHECK(!resource->image_id); 986 DCHECK(!resource->image_id);
971 987
972 if (resource->type == GLTexture) { 988 if (resource->type == GLTexture) {
973 WebGraphicsContext3D* context3d = output_surface_->context3d(); 989 WebGraphicsContext3D* context3d = output_surface_->context3d();
974 DCHECK(context3d); 990 DCHECK(context3d);
975 if (!resource->gl_pixel_buffer_id) 991 if (!resource->gl_pixel_buffer_id)
976 resource->gl_pixel_buffer_id = context3d->createBuffer(); 992 resource->gl_pixel_buffer_id = context3d->createBuffer();
977 context3d->bindBuffer( 993 context3d->bindBuffer(
978 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 994 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
979 resource->gl_pixel_buffer_id); 995 resource->gl_pixel_buffer_id);
(...skipping 12 matching lines...) Expand all
992 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1008 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
993 } 1009 }
994 } 1010 }
995 1011
996 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 1012 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
997 DCHECK(thread_checker_.CalledOnValidThread()); 1013 DCHECK(thread_checker_.CalledOnValidThread());
998 ResourceMap::iterator it = resources_.find(id); 1014 ResourceMap::iterator it = resources_.find(id);
999 CHECK(it != resources_.end()); 1015 CHECK(it != resources_.end());
1000 Resource* resource = &it->second; 1016 Resource* resource = &it->second;
1001 DCHECK(!resource->external); 1017 DCHECK(!resource->external);
1002 DCHECK(!resource->exported); 1018 DCHECK_EQ(resource->exported_count, 0);
1003 DCHECK(!resource->image_id); 1019 DCHECK(!resource->image_id);
1004 1020
1005 // The pixel buffer can be released while there is a pending "set pixels" 1021 // The pixel buffer can be released while there is a pending "set pixels"
1006 // if completion has been forced. Any shared memory associated with this 1022 // if completion has been forced. Any shared memory associated with this
1007 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM 1023 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM
1008 // command has been processed on the service side. It is also safe to 1024 // command has been processed on the service side. It is also safe to
1009 // reuse any query id associated with this resource before they complete 1025 // reuse any query id associated with this resource before they complete
1010 // as each new query has a unique submit count. 1026 // as each new query has a unique submit count.
1011 if (resource->pending_set_pixels) { 1027 if (resource->pending_set_pixels) {
1012 DCHECK(resource->set_pixels_completion_forced); 1028 DCHECK(resource->set_pixels_completion_forced);
(...skipping 24 matching lines...) Expand all
1037 resource->pixel_buffer = NULL; 1053 resource->pixel_buffer = NULL;
1038 } 1054 }
1039 } 1055 }
1040 1056
1041 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { 1057 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) {
1042 DCHECK(thread_checker_.CalledOnValidThread()); 1058 DCHECK(thread_checker_.CalledOnValidThread());
1043 ResourceMap::iterator it = resources_.find(id); 1059 ResourceMap::iterator it = resources_.find(id);
1044 CHECK(it != resources_.end()); 1060 CHECK(it != resources_.end());
1045 Resource* resource = &it->second; 1061 Resource* resource = &it->second;
1046 DCHECK(!resource->external); 1062 DCHECK(!resource->external);
1047 DCHECK(!resource->exported); 1063 DCHECK_EQ(resource->exported_count, 0);
1048 DCHECK(!resource->image_id); 1064 DCHECK(!resource->image_id);
1049 1065
1050 if (resource->type == GLTexture) { 1066 if (resource->type == GLTexture) {
1051 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1067 WebGraphicsContext3D* context3d = output_surface_->context3d();
1052 DCHECK(context3d); 1068 DCHECK(context3d);
1053 DCHECK(resource->gl_pixel_buffer_id); 1069 DCHECK(resource->gl_pixel_buffer_id);
1054 context3d->bindBuffer( 1070 context3d->bindBuffer(
1055 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1071 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1056 resource->gl_pixel_buffer_id); 1072 resource->gl_pixel_buffer_id);
1057 uint8_t* image = static_cast<uint8_t*>( 1073 uint8_t* image = static_cast<uint8_t*>(
(...skipping 10 matching lines...) Expand all
1068 1084
1069 return NULL; 1085 return NULL;
1070 } 1086 }
1071 1087
1072 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { 1088 void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
1073 DCHECK(thread_checker_.CalledOnValidThread()); 1089 DCHECK(thread_checker_.CalledOnValidThread());
1074 ResourceMap::iterator it = resources_.find(id); 1090 ResourceMap::iterator it = resources_.find(id);
1075 CHECK(it != resources_.end()); 1091 CHECK(it != resources_.end());
1076 Resource* resource = &it->second; 1092 Resource* resource = &it->second;
1077 DCHECK(!resource->external); 1093 DCHECK(!resource->external);
1078 DCHECK(!resource->exported); 1094 DCHECK_EQ(resource->exported_count, 0);
1079 DCHECK(!resource->image_id); 1095 DCHECK(!resource->image_id);
1080 1096
1081 if (resource->type == GLTexture) { 1097 if (resource->type == GLTexture) {
1082 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1098 WebGraphicsContext3D* context3d = output_surface_->context3d();
1083 DCHECK(context3d); 1099 DCHECK(context3d);
1084 DCHECK(resource->gl_pixel_buffer_id); 1100 DCHECK(resource->gl_pixel_buffer_id);
1085 context3d->bindBuffer( 1101 context3d->bindBuffer(
1086 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1102 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1087 resource->gl_pixel_buffer_id); 1103 resource->gl_pixel_buffer_id);
1088 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); 1104 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 resource->enable_read_lock_fences = enable; 1351 resource->enable_read_lock_fences = enable;
1336 } 1352 }
1337 1353
1338 void ResourceProvider::AcquireImage(ResourceId id) { 1354 void ResourceProvider::AcquireImage(ResourceId id) {
1339 DCHECK(thread_checker_.CalledOnValidThread()); 1355 DCHECK(thread_checker_.CalledOnValidThread());
1340 ResourceMap::iterator it = resources_.find(id); 1356 ResourceMap::iterator it = resources_.find(id);
1341 CHECK(it != resources_.end()); 1357 CHECK(it != resources_.end());
1342 Resource* resource = &it->second; 1358 Resource* resource = &it->second;
1343 1359
1344 DCHECK(!resource->external); 1360 DCHECK(!resource->external);
1345 DCHECK(!resource->exported); 1361 DCHECK_EQ(resource->exported_count, 0);
1346 1362
1347 if (resource->type != GLTexture) 1363 if (resource->type != GLTexture)
1348 return; 1364 return;
1349 1365
1350 if (resource->image_id) 1366 if (resource->image_id)
1351 return; 1367 return;
1352 1368
1353 resource->allocated = true; 1369 resource->allocated = true;
1354 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1370 WebGraphicsContext3D* context3d = output_surface_->context3d();
1355 DCHECK(context3d); 1371 DCHECK(context3d);
1356 resource->image_id = context3d->createImageCHROMIUM( 1372 resource->image_id = context3d->createImageCHROMIUM(
1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); 1373 resource->size.width(), resource->size.height(), GL_RGBA8_OES);
1358 DCHECK(resource->image_id); 1374 DCHECK(resource->image_id);
1359 } 1375 }
1360 1376
1361 void ResourceProvider::ReleaseImage(ResourceId id) { 1377 void ResourceProvider::ReleaseImage(ResourceId id) {
1362 DCHECK(thread_checker_.CalledOnValidThread()); 1378 DCHECK(thread_checker_.CalledOnValidThread());
1363 ResourceMap::iterator it = resources_.find(id); 1379 ResourceMap::iterator it = resources_.find(id);
1364 CHECK(it != resources_.end()); 1380 CHECK(it != resources_.end());
1365 Resource* resource = &it->second; 1381 Resource* resource = &it->second;
1366 1382
1367 DCHECK(!resource->external); 1383 DCHECK(!resource->external);
1368 DCHECK(!resource->exported); 1384 DCHECK_EQ(resource->exported_count, 0);
1369 1385
1370 if (!resource->image_id) 1386 if (!resource->image_id)
1371 return; 1387 return;
1372 1388
1373 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1389 WebGraphicsContext3D* context3d = output_surface_->context3d();
1374 DCHECK(context3d); 1390 DCHECK(context3d);
1375 context3d->destroyImageCHROMIUM(resource->image_id); 1391 context3d->destroyImageCHROMIUM(resource->image_id);
1376 resource->image_id = 0; 1392 resource->image_id = 0;
1377 resource->allocated = false; 1393 resource->allocated = false;
1378 } 1394 }
1379 1395
1380 uint8_t* ResourceProvider::MapImage(ResourceId id) { 1396 uint8_t* ResourceProvider::MapImage(ResourceId id) {
1381 DCHECK(thread_checker_.CalledOnValidThread()); 1397 DCHECK(thread_checker_.CalledOnValidThread());
1382 ResourceMap::iterator it = resources_.find(id); 1398 ResourceMap::iterator it = resources_.find(id);
1383 CHECK(it != resources_.end()); 1399 CHECK(it != resources_.end());
1384 Resource* resource = &it->second; 1400 Resource* resource = &it->second;
1385 1401
1386 DCHECK(ReadLockFenceHasPassed(resource)); 1402 DCHECK(ReadLockFenceHasPassed(resource));
1387 DCHECK(!resource->external); 1403 DCHECK(!resource->external);
1388 DCHECK(!resource->exported); 1404 DCHECK_EQ(resource->exported_count, 0);
1389 1405
1390 if (resource->image_id) { 1406 if (resource->image_id) {
1391 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1407 WebGraphicsContext3D* context3d = output_surface_->context3d();
1392 DCHECK(context3d); 1408 DCHECK(context3d);
1393 return static_cast<uint8_t*>( 1409 return static_cast<uint8_t*>(
1394 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); 1410 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE));
1395 } 1411 }
1396 1412
1397 if (resource->pixels) 1413 if (resource->pixels)
1398 return resource->pixels; 1414 return resource->pixels;
1399 1415
1400 return NULL; 1416 return NULL;
1401 } 1417 }
1402 1418
1403 void ResourceProvider::UnmapImage(ResourceId id) { 1419 void ResourceProvider::UnmapImage(ResourceId id) {
1404 DCHECK(thread_checker_.CalledOnValidThread()); 1420 DCHECK(thread_checker_.CalledOnValidThread());
1405 ResourceMap::iterator it = resources_.find(id); 1421 ResourceMap::iterator it = resources_.find(id);
1406 CHECK(it != resources_.end()); 1422 CHECK(it != resources_.end());
1407 Resource* resource = &it->second; 1423 Resource* resource = &it->second;
1408 1424
1409 DCHECK(!resource->external); 1425 DCHECK(!resource->external);
1410 DCHECK(!resource->exported); 1426 DCHECK_EQ(resource->exported_count, 0);
1411 1427
1412 if (resource->image_id) { 1428 if (resource->image_id) {
1413 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1429 WebGraphicsContext3D* context3d = output_surface_->context3d();
1414 DCHECK(context3d); 1430 DCHECK(context3d);
1415 context3d->unmapImageCHROMIUM(resource->image_id); 1431 context3d->unmapImageCHROMIUM(resource->image_id);
1416 } 1432 }
1417 } 1433 }
1418 1434
1419 int ResourceProvider::GetImageStride(ResourceId id) { 1435 int ResourceProvider::GetImageStride(ResourceId id) {
1420 DCHECK(thread_checker_.CalledOnValidThread()); 1436 DCHECK(thread_checker_.CalledOnValidThread());
1421 ResourceMap::iterator it = resources_.find(id); 1437 ResourceMap::iterator it = resources_.find(id);
1422 CHECK(it != resources_.end()); 1438 CHECK(it != resources_.end());
1423 Resource* resource = &it->second; 1439 Resource* resource = &it->second;
1424 1440
1425 DCHECK(!resource->external); 1441 DCHECK(!resource->external);
1426 DCHECK(!resource->exported); 1442 DCHECK_EQ(resource->exported_count, 0);
1427 1443
1428 int stride = 0; 1444 int stride = 0;
1429 1445
1430 if (resource->image_id) { 1446 if (resource->image_id) {
1431 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1447 WebGraphicsContext3D* context3d = output_surface_->context3d();
1432 DCHECK(context3d); 1448 DCHECK(context3d);
1433 context3d->getImageParameterivCHROMIUM( 1449 context3d->getImageParameterivCHROMIUM(
1434 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); 1450 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride);
1435 } 1451 }
1436 1452
1437 return stride; 1453 return stride;
1438 } 1454 }
1439 1455
1440 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { 1456 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) {
1441 GLint active_unit = 0; 1457 GLint active_unit = 0;
1442 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1458 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1443 return active_unit; 1459 return active_unit;
1444 } 1460 }
1445 1461
1446 } // namespace cc 1462 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698