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

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

Issue 15001027: [Aura] Added Support for rendering software compositor frames as cc::TextureLayers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 6 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
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/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 locked_for_write(false), 76 locked_for_write(false),
77 external(false), 77 external(false),
78 exported(false), 78 exported(false),
79 marked_for_deletion(false), 79 marked_for_deletion(false),
80 pending_set_pixels(false), 80 pending_set_pixels(false),
81 set_pixels_completion_forced(false), 81 set_pixels_completion_forced(false),
82 allocated(false), 82 allocated(false),
83 enable_read_lock_fences(false), 83 enable_read_lock_fences(false),
84 read_lock_fence(NULL), 84 read_lock_fence(NULL),
85 size(), 85 size(),
86 shared_memory(NULL),
86 format(0), 87 format(0),
87 filter(0), 88 filter(0),
88 image_id(0), 89 image_id(0),
89 type(static_cast<ResourceType>(0)) {} 90 type(static_cast<ResourceType>(0)) {}
90 91
91 ResourceProvider::Resource::~Resource() {} 92 ResourceProvider::Resource::~Resource() {}
92 93
93 ResourceProvider::Resource::Resource( 94 ResourceProvider::Resource::Resource(
94 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter) 95 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter)
95 : gl_id(texture_id), 96 : gl_id(texture_id),
96 gl_pixel_buffer_id(0), 97 gl_pixel_buffer_id(0),
97 gl_upload_query_id(0), 98 gl_upload_query_id(0),
98 pixels(NULL), 99 pixels(NULL),
99 pixel_buffer(NULL), 100 pixel_buffer(NULL),
100 lock_for_read_count(0), 101 lock_for_read_count(0),
101 locked_for_write(false), 102 locked_for_write(false),
102 external(false), 103 external(false),
103 exported(false), 104 exported(false),
104 marked_for_deletion(false), 105 marked_for_deletion(false),
105 pending_set_pixels(false), 106 pending_set_pixels(false),
106 set_pixels_completion_forced(false), 107 set_pixels_completion_forced(false),
107 allocated(false), 108 allocated(false),
108 enable_read_lock_fences(false), 109 enable_read_lock_fences(false),
109 read_lock_fence(NULL), 110 read_lock_fence(NULL),
110 size(size), 111 size(size),
112 shared_memory(NULL),
111 format(format), 113 format(format),
112 filter(filter), 114 filter(filter),
113 image_id(0), 115 image_id(0),
114 type(GLTexture) {} 116 type(GLTexture) {}
115 117
116 ResourceProvider::Resource::Resource( 118 ResourceProvider::Resource::Resource(
117 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) 119 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter)
118 : gl_id(0), 120 : gl_id(0),
119 gl_pixel_buffer_id(0), 121 gl_pixel_buffer_id(0),
120 gl_upload_query_id(0), 122 gl_upload_query_id(0),
121 pixels(pixels), 123 pixels(pixels),
122 pixel_buffer(NULL), 124 pixel_buffer(NULL),
123 lock_for_read_count(0), 125 lock_for_read_count(0),
124 locked_for_write(false), 126 locked_for_write(false),
125 external(false), 127 external(false),
126 exported(false), 128 exported(false),
127 marked_for_deletion(false), 129 marked_for_deletion(false),
128 pending_set_pixels(false), 130 pending_set_pixels(false),
129 set_pixels_completion_forced(false), 131 set_pixels_completion_forced(false),
130 allocated(false), 132 allocated(false),
131 enable_read_lock_fences(false), 133 enable_read_lock_fences(false),
132 read_lock_fence(NULL), 134 read_lock_fence(NULL),
133 size(size), 135 size(size),
136 shared_memory(NULL),
134 format(format), 137 format(format),
135 filter(filter), 138 filter(filter),
136 image_id(0), 139 image_id(0),
137 type(Bitmap) {} 140 type(Bitmap) {}
138 141
139 ResourceProvider::Child::Child() {} 142 ResourceProvider::Child::Child() {}
140 143
141 ResourceProvider::Child::~Child() {} 144 ResourceProvider::Child::~Child() {}
142 145
143 scoped_ptr<ResourceProvider> ResourceProvider::Create( 146 scoped_ptr<ResourceProvider> ResourceProvider::Create(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 resource.allocated = true; 272 resource.allocated = true;
270 resources_[id] = resource; 273 resources_[id] = resource;
271 return id; 274 return id;
272 } 275 }
273 276
274 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 277 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
275 const TextureMailbox& mailbox) { 278 const TextureMailbox& mailbox) {
276 DCHECK(thread_checker_.CalledOnValidThread()); 279 DCHECK(thread_checker_.CalledOnValidThread());
277 // Just store the information. Mailbox will be consumed in LockForRead(). 280 // Just store the information. Mailbox will be consumed in LockForRead().
278 ResourceId id = next_id_++; 281 ResourceId id = next_id_++;
279 unsigned texture_id = 0; 282 DCHECK(mailbox.IsValid());
280 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); 283 if (mailbox.IsTexture()) {
281 resource.external = true; 284 unsigned texture_id = 0;
282 resource.allocated = true; 285 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR);
283 resource.mailbox = mailbox; 286 resource.external = true;
284 resources_[id] = resource; 287 resource.allocated = true;
288 resource.mailbox = mailbox;
289 resources_[id] = resource;
290 } else {
291 DCHECK(mailbox.IsSharedMemory());
292 uint8_t *pixels = NULL;
293 Resource resource(pixels, mailbox.shared_memory_size(), 0, GL_LINEAR);
294 resource.external = true;
295 resource.allocated = true;
296 resource.mailbox = mailbox;
297 resources_[id] = resource;
298 }
285 return id; 299 return id;
286 } 300 }
287 301
288 void ResourceProvider::DeleteResource(ResourceId id) { 302 void ResourceProvider::DeleteResource(ResourceId id) {
289 DCHECK(thread_checker_.CalledOnValidThread()); 303 DCHECK(thread_checker_.CalledOnValidThread());
290 ResourceMap::iterator it = resources_.find(id); 304 ResourceMap::iterator it = resources_.find(id);
291 CHECK(it != resources_.end()); 305 CHECK(it != resources_.end());
292 Resource* resource = &it->second; 306 Resource* resource = &it->second;
293 DCHECK(!resource->lock_for_read_count); 307 DCHECK(!resource->lock_for_read_count);
294 DCHECK(!resource->marked_for_deletion); 308 DCHECK(!resource->marked_for_deletion);
(...skipping 30 matching lines...) Expand all
325 if (resource->gl_upload_query_id) { 339 if (resource->gl_upload_query_id) {
326 WebGraphicsContext3D* context3d = output_surface_->context3d(); 340 WebGraphicsContext3D* context3d = output_surface_->context3d();
327 DCHECK(context3d); 341 DCHECK(context3d);
328 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); 342 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id));
329 } 343 }
330 if (resource->gl_pixel_buffer_id) { 344 if (resource->gl_pixel_buffer_id) {
331 WebGraphicsContext3D* context3d = output_surface_->context3d(); 345 WebGraphicsContext3D* context3d = output_surface_->context3d();
332 DCHECK(context3d); 346 DCHECK(context3d);
333 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); 347 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id));
334 } 348 }
335 if (!resource->mailbox.IsEmpty() && resource->external) { 349 if (resource->mailbox.IsValid() && resource->external) {
336 WebGraphicsContext3D* context3d = output_surface_->context3d();
337 DCHECK(context3d);
338 unsigned sync_point = resource->mailbox.sync_point(); 350 unsigned sync_point = resource->mailbox.sync_point();
339 if (!lost_resource && resource->gl_id) { 351 if (resource->mailbox.IsTexture()) {
340 GLC(context3d, context3d->bindTexture( 352 WebGraphicsContext3D* context3d = output_surface_->context3d();
341 resource->mailbox.target(), resource->gl_id)); 353 DCHECK(context3d);
342 GLC(context3d, context3d->produceTextureCHROMIUM( 354 if (!lost_resource && resource->gl_id) {
343 resource->mailbox.target(), resource->mailbox.data())); 355 GLC(context3d, context3d->bindTexture(
356 resource->mailbox.target(), resource->gl_id));
357 GLC(context3d, context3d->produceTextureCHROMIUM(
358 resource->mailbox.target(), resource->mailbox.data()));
359 }
360 if (resource->gl_id)
361 GLC(context3d, context3d->deleteTexture(resource->gl_id));
362 if (!lost_resource && resource->gl_id)
363 sync_point = context3d->insertSyncPoint();
364 } else {
365 DCHECK(resource->mailbox.IsSharedMemory());
366 if (resource->shared_memory) {
367 if (resource->shared_memory->memory()) {
368 DCHECK(resource->shared_memory->memory() == resource->pixels);
369 resource->pixels = NULL;
370 }
371 delete resource->shared_memory;
372 resource->shared_memory = NULL;
373 }
344 } 374 }
345 if (resource->gl_id)
346 GLC(context3d, context3d->deleteTexture(resource->gl_id));
347 if (!lost_resource && resource->gl_id)
348 sync_point = context3d->insertSyncPoint();
349 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); 375 resource->mailbox.RunReleaseCallback(sync_point, lost_resource);
350 } 376 }
351 if (resource->pixels) 377 if (resource->pixels)
352 delete[] resource->pixels; 378 delete[] resource->pixels;
353 if (resource->pixel_buffer) 379 if (resource->pixel_buffer)
354 delete[] resource->pixel_buffer; 380 delete[] resource->pixel_buffer;
355 381
356 resources_.erase(it); 382 resources_.erase(it);
357 } 383 }
358 384
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 CHECK(it != resources_.end()); 506 CHECK(it != resources_.end());
481 Resource* resource = &it->second; 507 Resource* resource = &it->second;
482 DCHECK(!resource->locked_for_write || 508 DCHECK(!resource->locked_for_write ||
483 resource->set_pixels_completion_forced) << 509 resource->set_pixels_completion_forced) <<
484 "locked for write: " << resource->locked_for_write << 510 "locked for write: " << resource->locked_for_write <<
485 " pixels completion forced: " << resource->set_pixels_completion_forced; 511 " pixels completion forced: " << resource->set_pixels_completion_forced;
486 DCHECK(!resource->exported); 512 DCHECK(!resource->exported);
487 // Uninitialized! Call SetPixels or LockForWrite first. 513 // Uninitialized! Call SetPixels or LockForWrite first.
488 DCHECK(resource->allocated); 514 DCHECK(resource->allocated);
489 515
490 if (!resource->gl_id && resource->external && !resource->mailbox.IsEmpty()) { 516 if (resource->external && resource->mailbox.IsValid()) {
491 WebGraphicsContext3D* context3d = output_surface_->context3d(); 517 bool is_texture_mailbox = resource->mailbox.IsTexture();
492 DCHECK(context3d); 518 if (!resource->gl_id && is_texture_mailbox) {
493 if (resource->mailbox.sync_point()) { 519 WebGraphicsContext3D* context3d = output_surface_->context3d();
494 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point())); 520 DCHECK(context3d);
495 resource->mailbox.ResetSyncPoint(); 521 if (resource->mailbox.sync_point()) {
522 GLC(context3d,
523 context3d->waitSyncPoint(resource->mailbox.sync_point()));
524 resource->mailbox.ResetSyncPoint();
525 }
526 resource->gl_id = context3d->createTexture();
527 GLC(context3d, context3d->bindTexture(
528 resource->mailbox.target(), resource->gl_id));
529 GLC(context3d, context3d->consumeTextureCHROMIUM(
530 resource->mailbox.target(), resource->mailbox.data()));
531 } else if (!resource->shared_memory && !is_texture_mailbox) {
532 DCHECK(resource->mailbox.IsSharedMemory());
533 CHECK(!resource->pixels);
534 resource->format = GL_RGBA;
535 resource->size = resource->mailbox.shared_memory_size();
536 base::SharedMemoryHandle handle =
537 base::SharedMemory::DuplicateHandle(resource->mailbox.handle());
538 resource->shared_memory = new base::SharedMemory(handle, false);
539 const size_t size = resource->mailbox.shared_memory_size_in_bytes();
540 if (resource->shared_memory->Map(size)) {
541 resource->pixels =
542 reinterpret_cast<uint8_t*>(resource->shared_memory->memory());
543 } else {
544 LOG(ERROR) << "Failed to map shared memory mailbox "
545 << " of size " << resource->size.ToString();
546 resource->pixels = new uint8_t[size];
547 std::fill_n(resource->pixels, size, 0xFF);
548 }
496 } 549 }
497 resource->gl_id = context3d->createTexture();
498 GLC(context3d, context3d->bindTexture(
499 resource->mailbox.target(), resource->gl_id));
500 GLC(context3d, context3d->consumeTextureCHROMIUM(
501 resource->mailbox.target(), resource->mailbox.data()));
502 } 550 }
503 551
504 resource->lock_for_read_count++; 552 resource->lock_for_read_count++;
505 if (resource->enable_read_lock_fences) 553 if (resource->enable_read_lock_fences)
506 resource->read_lock_fence = current_read_lock_fence_; 554 resource->read_lock_fence = current_read_lock_fence_;
507 555
508 return resource; 556 return resource;
509 } 557 }
510 558
511 void ResourceProvider::UnlockForRead(ResourceId id) { 559 void ResourceProvider::UnlockForRead(ResourceId id) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 } 881 }
834 for (TransferableResourceArray::const_iterator it = resources.begin(); 882 for (TransferableResourceArray::const_iterator it = resources.begin();
835 it != resources.end(); 883 it != resources.end();
836 ++it) { 884 ++it) {
837 ResourceMap::iterator map_iterator = resources_.find(it->id); 885 ResourceMap::iterator map_iterator = resources_.find(it->id);
838 DCHECK(map_iterator != resources_.end()); 886 DCHECK(map_iterator != resources_.end());
839 Resource* resource = &map_iterator->second; 887 Resource* resource = &map_iterator->second;
840 DCHECK(resource->exported); 888 DCHECK(resource->exported);
841 resource->exported = false; 889 resource->exported = false;
842 resource->filter = it->filter; 890 resource->filter = it->filter;
843 DCHECK(resource->mailbox.Equals(it->mailbox)); 891 DCHECK(resource->mailbox.ContainsMailbox(it->mailbox));
844 if (resource->gl_id) { 892 if (resource->gl_id) {
845 if (it->sync_point) 893 if (it->sync_point)
846 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 894 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
847 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 895 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
848 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 896 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
849 it->mailbox.name)); 897 it->mailbox.name));
850 } else { 898 } else {
851 resource->mailbox = TextureMailbox(resource->mailbox.name(), 899 resource->mailbox = TextureMailbox(resource->mailbox.name(),
852 resource->mailbox.callback(), 900 resource->mailbox.callback(),
853 it->sync_point); 901 it->sync_point);
854 } 902 }
855 if (resource->marked_for_deletion) 903 if (resource->marked_for_deletion)
856 DeleteResourceInternal(map_iterator, Normal); 904 DeleteResourceInternal(map_iterator, Normal);
857 } 905 }
858 } 906 }
859 907
860 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, 908 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context,
861 ResourceId id, 909 ResourceId id,
862 TransferableResource* resource) { 910 TransferableResource* resource) {
863 DCHECK(thread_checker_.CalledOnValidThread()); 911 DCHECK(thread_checker_.CalledOnValidThread());
864 WebGraphicsContext3D* context3d = output_surface_->context3d(); 912 WebGraphicsContext3D* context3d = output_surface_->context3d();
865 ResourceMap::iterator it = resources_.find(id); 913 ResourceMap::iterator it = resources_.find(id);
866 CHECK(it != resources_.end()); 914 CHECK(it != resources_.end());
867 Resource* source = &it->second; 915 Resource* source = &it->second;
868 DCHECK(!source->locked_for_write); 916 DCHECK(!source->locked_for_write);
869 DCHECK(!source->lock_for_read_count); 917 DCHECK(!source->lock_for_read_count);
870 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); 918 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
871 DCHECK(source->allocated); 919 DCHECK(source->allocated);
872 if (source->exported) 920 if (source->exported)
873 return false; 921 return false;
874 resource->id = id; 922 resource->id = id;
875 resource->format = source->format; 923 resource->format = source->format;
876 resource->filter = source->filter; 924 resource->filter = source->filter;
877 resource->size = source->size; 925 resource->size = source->size;
878 926
879 if (source->mailbox.IsEmpty()) { 927 // TODO(skaslev) Implement this path for shared memory resources.
928 DCHECK(!source->mailbox.IsSharedMemory());
929
930 if (!source->mailbox.IsTexture()) {
880 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); 931 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name));
881 source->mailbox.SetName(resource->mailbox); 932 source->mailbox.SetName(resource->mailbox);
882 } else { 933 } else {
883 resource->mailbox = source->mailbox.name(); 934 resource->mailbox = source->mailbox.name();
884 } 935 }
885 936
886 if (source->gl_id) { 937 if (source->gl_id) {
887 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 938 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
888 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, 939 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D,
889 resource->mailbox.name)); 940 resource->mailbox.name));
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1420 WebGraphicsContext3D* context3d = output_surface_->context3d();
1370 DCHECK(context3d); 1421 DCHECK(context3d);
1371 int stride = 0; 1422 int stride = 0;
1372 context3d->getImageParameterivCHROMIUM( 1423 context3d->getImageParameterivCHROMIUM(
1373 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); 1424 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride);
1374 return stride; 1425 return stride;
1375 } 1426 }
1376 1427
1377 1428
1378 } // namespace cc 1429 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698