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

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: More changes from the notes. 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 if (mailbox.IsSharedMemory()) {
piman 2013/05/29 20:00:10 the second if is not needed anymore, but maybe can
slavi 2013/06/03 22:14:16 Done.
291 uint8_t *pixels = NULL;
292 Resource resource(pixels, mailbox.shared_memory_size(), 0, GL_LINEAR);
293 resource.external = true;
294 resource.allocated = true;
295 resource.mailbox = mailbox;
296 resources_[id] = resource;
297 }
285 return id; 298 return id;
286 } 299 }
287 300
288 void ResourceProvider::DeleteResource(ResourceId id) { 301 void ResourceProvider::DeleteResource(ResourceId id) {
289 DCHECK(thread_checker_.CalledOnValidThread()); 302 DCHECK(thread_checker_.CalledOnValidThread());
290 ResourceMap::iterator it = resources_.find(id); 303 ResourceMap::iterator it = resources_.find(id);
291 CHECK(it != resources_.end()); 304 CHECK(it != resources_.end());
292 Resource* resource = &it->second; 305 Resource* resource = &it->second;
293 DCHECK(!resource->lock_for_read_count); 306 DCHECK(!resource->lock_for_read_count);
294 DCHECK(!resource->marked_for_deletion); 307 DCHECK(!resource->marked_for_deletion);
(...skipping 30 matching lines...) Expand all
325 if (resource->gl_upload_query_id) { 338 if (resource->gl_upload_query_id) {
326 WebGraphicsContext3D* context3d = output_surface_->context3d(); 339 WebGraphicsContext3D* context3d = output_surface_->context3d();
327 DCHECK(context3d); 340 DCHECK(context3d);
328 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); 341 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id));
329 } 342 }
330 if (resource->gl_pixel_buffer_id) { 343 if (resource->gl_pixel_buffer_id) {
331 WebGraphicsContext3D* context3d = output_surface_->context3d(); 344 WebGraphicsContext3D* context3d = output_surface_->context3d();
332 DCHECK(context3d); 345 DCHECK(context3d);
333 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); 346 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id));
334 } 347 }
335 if (!resource->mailbox.IsEmpty() && resource->external) { 348 if (resource->mailbox.IsValid() && resource->external) {
336 WebGraphicsContext3D* context3d = output_surface_->context3d();
337 DCHECK(context3d);
338 unsigned sync_point = resource->mailbox.sync_point(); 349 unsigned sync_point = resource->mailbox.sync_point();
339 if (!lost_resource && resource->gl_id) { 350 if (resource->mailbox.IsTexture()) {
340 GLC(context3d, context3d->bindTexture( 351 WebGraphicsContext3D* context3d = output_surface_->context3d();
341 resource->mailbox.target(), resource->gl_id)); 352 DCHECK(context3d);
342 GLC(context3d, context3d->produceTextureCHROMIUM( 353 if (!lost_resource && resource->gl_id) {
343 resource->mailbox.target(), resource->mailbox.data())); 354 GLC(context3d, context3d->bindTexture(
355 resource->mailbox.target(), resource->gl_id));
356 GLC(context3d, context3d->produceTextureCHROMIUM(
357 resource->mailbox.target(), resource->mailbox.data()));
358 }
359 if (resource->gl_id)
360 GLC(context3d, context3d->deleteTexture(resource->gl_id));
361 if (!lost_resource && resource->gl_id)
362 sync_point = context3d->insertSyncPoint();
363 } else {
364 DCHECK(resource->mailbox.IsSharedMemory());
365 if (resource->shared_memory) {
366 if (resource->shared_memory->memory()) {
367 DCHECK(resource->shared_memory->memory() == resource->pixels);
368 resource->pixels = NULL;
369 }
370 delete resource->shared_memory;
371 resource->shared_memory = NULL;
372 }
344 } 373 }
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); 374 resource->mailbox.RunReleaseCallback(sync_point, lost_resource);
350 } 375 }
351 if (resource->pixels) 376 if (resource->pixels)
352 delete[] resource->pixels; 377 delete[] resource->pixels;
353 if (resource->pixel_buffer) 378 if (resource->pixel_buffer)
354 delete[] resource->pixel_buffer; 379 delete[] resource->pixel_buffer;
355 380
356 resources_.erase(it); 381 resources_.erase(it);
357 } 382 }
358 383
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 CHECK(it != resources_.end()); 505 CHECK(it != resources_.end());
481 Resource* resource = &it->second; 506 Resource* resource = &it->second;
482 DCHECK(!resource->locked_for_write || 507 DCHECK(!resource->locked_for_write ||
483 resource->set_pixels_completion_forced) << 508 resource->set_pixels_completion_forced) <<
484 "locked for write: " << resource->locked_for_write << 509 "locked for write: " << resource->locked_for_write <<
485 " pixels completion forced: " << resource->set_pixels_completion_forced; 510 " pixels completion forced: " << resource->set_pixels_completion_forced;
486 DCHECK(!resource->exported); 511 DCHECK(!resource->exported);
487 // Uninitialized! Call SetPixels or LockForWrite first. 512 // Uninitialized! Call SetPixels or LockForWrite first.
488 DCHECK(resource->allocated); 513 DCHECK(resource->allocated);
489 514
490 if (!resource->gl_id && resource->external && !resource->mailbox.IsEmpty()) { 515 if (resource->external) {
491 WebGraphicsContext3D* context3d = output_surface_->context3d(); 516 if (!resource->gl_id && resource->mailbox.IsTexture()) {
492 DCHECK(context3d); 517 WebGraphicsContext3D* context3d = output_surface_->context3d();
493 if (resource->mailbox.sync_point()) { 518 DCHECK(context3d);
494 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point())); 519 if (resource->mailbox.sync_point()) {
495 resource->mailbox.ResetSyncPoint(); 520 GLC(context3d,
521 context3d->waitSyncPoint(resource->mailbox.sync_point()));
522 resource->mailbox.ResetSyncPoint();
523 }
524 resource->gl_id = context3d->createTexture();
525 GLC(context3d, context3d->bindTexture(
526 resource->mailbox.target(), resource->gl_id));
527 GLC(context3d, context3d->consumeTextureCHROMIUM(
528 resource->mailbox.target(), resource->mailbox.data()));
529 } else if (!resource->shared_memory && resource->mailbox.IsSharedMemory()) {
530 CHECK(!resource->pixels);
531 resource->format = GL_RGBA;
532 resource->size = resource->mailbox.shared_memory_size();
533 resource->shared_memory = new base::SharedMemory(
534 resource->mailbox.handle(), false);
piman 2013/05/29 20:00:10 Actually, I just realized because of the RecreateL
slavi 2013/06/03 22:14:16 Done.
535 const size_t size = 4 * resource->size.GetArea();
536 if (resource->shared_memory->Map(size)) {
537 resource->pixels =
538 reinterpret_cast<uint8_t*>(resource->shared_memory->memory());
539 } else {
540 LOG(ERROR) << "Failed to map shared memory handle "
541 << " of size " << resource->size.ToString();
542 resource->pixels = new uint8_t[size];
543 std::fill_n(resource->pixels, size, 0xFF);
544 }
496 } 545 }
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 } 546 }
503 547
504 resource->lock_for_read_count++; 548 resource->lock_for_read_count++;
505 if (resource->enable_read_lock_fences) 549 if (resource->enable_read_lock_fences)
506 resource->read_lock_fence = current_read_lock_fence_; 550 resource->read_lock_fence = current_read_lock_fence_;
507 551
508 return resource; 552 return resource;
509 } 553 }
510 554
511 void ResourceProvider::UnlockForRead(ResourceId id) { 555 void ResourceProvider::UnlockForRead(ResourceId id) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 } 877 }
834 for (TransferableResourceArray::const_iterator it = resources.begin(); 878 for (TransferableResourceArray::const_iterator it = resources.begin();
835 it != resources.end(); 879 it != resources.end();
836 ++it) { 880 ++it) {
837 ResourceMap::iterator map_iterator = resources_.find(it->id); 881 ResourceMap::iterator map_iterator = resources_.find(it->id);
838 DCHECK(map_iterator != resources_.end()); 882 DCHECK(map_iterator != resources_.end());
839 Resource* resource = &map_iterator->second; 883 Resource* resource = &map_iterator->second;
840 DCHECK(resource->exported); 884 DCHECK(resource->exported);
841 resource->exported = false; 885 resource->exported = false;
842 resource->filter = it->filter; 886 resource->filter = it->filter;
843 DCHECK(resource->mailbox.Equals(it->mailbox)); 887 DCHECK(resource->mailbox.ContainsMailbox(it->mailbox));
844 if (resource->gl_id) { 888 if (resource->gl_id) {
845 if (it->sync_point) 889 if (it->sync_point)
846 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 890 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
847 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 891 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
848 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 892 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
849 it->mailbox.name)); 893 it->mailbox.name));
850 } else { 894 } else {
851 resource->mailbox = TextureMailbox(resource->mailbox.name(), 895 resource->mailbox = TextureMailbox(resource->mailbox.name(),
852 resource->mailbox.callback(), 896 resource->mailbox.callback(),
853 it->sync_point); 897 it->sync_point);
854 } 898 }
855 if (resource->marked_for_deletion) 899 if (resource->marked_for_deletion)
856 DeleteResourceInternal(map_iterator, Normal); 900 DeleteResourceInternal(map_iterator, Normal);
857 } 901 }
858 } 902 }
859 903
860 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, 904 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context,
861 ResourceId id, 905 ResourceId id,
862 TransferableResource* resource) { 906 TransferableResource* resource) {
863 DCHECK(thread_checker_.CalledOnValidThread()); 907 DCHECK(thread_checker_.CalledOnValidThread());
864 WebGraphicsContext3D* context3d = output_surface_->context3d(); 908 WebGraphicsContext3D* context3d = output_surface_->context3d();
865 ResourceMap::iterator it = resources_.find(id); 909 ResourceMap::iterator it = resources_.find(id);
866 CHECK(it != resources_.end()); 910 CHECK(it != resources_.end());
867 Resource* source = &it->second; 911 Resource* source = &it->second;
868 DCHECK(!source->locked_for_write); 912 DCHECK(!source->locked_for_write);
869 DCHECK(!source->lock_for_read_count); 913 DCHECK(!source->lock_for_read_count);
870 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); 914 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
871 DCHECK(source->allocated); 915 DCHECK(source->allocated);
872 if (source->exported) 916 if (source->exported)
873 return false; 917 return false;
874 resource->id = id; 918 resource->id = id;
875 resource->format = source->format; 919 resource->format = source->format;
876 resource->filter = source->filter; 920 resource->filter = source->filter;
877 resource->size = source->size; 921 resource->size = source->size;
878 922
879 if (source->mailbox.IsEmpty()) { 923 // TODO(skaslev) Implement this path for shared memory resources.
924 DCHECK(!source->mailbox.IsSharedMemory());
925
926 if (!source->mailbox.IsTexture()) {
880 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); 927 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name));
881 source->mailbox.SetName(resource->mailbox); 928 source->mailbox.SetName(resource->mailbox);
882 } else { 929 } else {
883 resource->mailbox = source->mailbox.name(); 930 resource->mailbox = source->mailbox.name();
884 } 931 }
885 932
886 if (source->gl_id) { 933 if (source->gl_id) {
887 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 934 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
888 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, 935 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D,
889 resource->mailbox.name)); 936 resource->mailbox.name));
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1412 WebGraphicsContext3D* context3d = output_surface_->context3d();
1366 DCHECK(context3d); 1413 DCHECK(context3d);
1367 int stride = 0; 1414 int stride = 0;
1368 context3d->getImageParameterivCHROMIUM( 1415 context3d->getImageParameterivCHROMIUM(
1369 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); 1416 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride);
1370 return stride; 1417 return stride;
1371 } 1418 }
1372 1419
1373 1420
1374 } // namespace cc 1421 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698