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

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: Passed(&foo) instead for Passed(foo.Pass()). 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
« no previous file with comments | « cc/output/software_renderer.cc ('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/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ResourceId id = next_id_++; 229 ResourceId id = next_id_++;
230 Resource resource(texture_id, size, format, GL_LINEAR); 230 Resource resource(texture_id, size, format, GL_LINEAR);
231 resource.allocated = false; 231 resource.allocated = false;
232 resources_[id] = resource; 232 resources_[id] = resource;
233 return id; 233 return id;
234 } 234 }
235 235
236 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 236 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
237 DCHECK(thread_checker_.CalledOnValidThread()); 237 DCHECK(thread_checker_.CalledOnValidThread());
238 238
239 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 239 uint8_t* pixels = new uint8_t[4 * size.GetArea()];
240 240
241 ResourceId id = next_id_++; 241 ResourceId id = next_id_++;
242 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); 242 Resource resource(pixels, size, GL_RGBA, GL_LINEAR);
243 resource.allocated = true; 243 resource.allocated = true;
244 resources_[id] = resource; 244 resources_[id] = resource;
245 return id; 245 return id;
246 } 246 }
247 247
248 ResourceProvider::ResourceId 248 ResourceProvider::ResourceId
249 ResourceProvider::CreateResourceFromExternalTexture( 249 ResourceProvider::CreateResourceFromExternalTexture(
(...skipping 19 matching lines...) Expand all
269 resource.allocated = true; 269 resource.allocated = true;
270 resources_[id] = resource; 270 resources_[id] = resource;
271 return id; 271 return id;
272 } 272 }
273 273
274 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 274 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
275 const TextureMailbox& mailbox) { 275 const TextureMailbox& mailbox) {
276 DCHECK(thread_checker_.CalledOnValidThread()); 276 DCHECK(thread_checker_.CalledOnValidThread());
277 // Just store the information. Mailbox will be consumed in LockForRead(). 277 // Just store the information. Mailbox will be consumed in LockForRead().
278 ResourceId id = next_id_++; 278 ResourceId id = next_id_++;
279 unsigned texture_id = 0; 279 DCHECK(mailbox.IsValid());
280 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); 280 Resource& resource = resources_[id];
281 if (mailbox.IsTexture()) {
282 unsigned texture_id = 0;
283 resource = Resource(texture_id, gfx::Size(), 0, GL_LINEAR);
284 } else {
285 DCHECK(mailbox.IsSharedMemory());
286 base::SharedMemory* shared_memory = mailbox.shared_memory();
287 DCHECK(shared_memory->memory());
288 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
289 resource = Resource(pixels, mailbox.shared_memory_size(),
290 GL_RGBA, GL_LINEAR);
291 }
281 resource.external = true; 292 resource.external = true;
282 resource.allocated = true; 293 resource.allocated = true;
283 resource.mailbox = mailbox; 294 resource.mailbox = mailbox;
284 resources_[id] = resource;
285 return id; 295 return id;
286 } 296 }
287 297
288 void ResourceProvider::DeleteResource(ResourceId id) { 298 void ResourceProvider::DeleteResource(ResourceId id) {
289 DCHECK(thread_checker_.CalledOnValidThread()); 299 DCHECK(thread_checker_.CalledOnValidThread());
290 ResourceMap::iterator it = resources_.find(id); 300 ResourceMap::iterator it = resources_.find(id);
291 CHECK(it != resources_.end()); 301 CHECK(it != resources_.end());
292 Resource* resource = &it->second; 302 Resource* resource = &it->second;
293 DCHECK(!resource->lock_for_read_count); 303 DCHECK(!resource->lock_for_read_count);
294 DCHECK(!resource->marked_for_deletion); 304 DCHECK(!resource->marked_for_deletion);
(...skipping 30 matching lines...) Expand all
325 if (resource->gl_upload_query_id) { 335 if (resource->gl_upload_query_id) {
326 WebGraphicsContext3D* context3d = output_surface_->context3d(); 336 WebGraphicsContext3D* context3d = output_surface_->context3d();
327 DCHECK(context3d); 337 DCHECK(context3d);
328 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); 338 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id));
329 } 339 }
330 if (resource->gl_pixel_buffer_id) { 340 if (resource->gl_pixel_buffer_id) {
331 WebGraphicsContext3D* context3d = output_surface_->context3d(); 341 WebGraphicsContext3D* context3d = output_surface_->context3d();
332 DCHECK(context3d); 342 DCHECK(context3d);
333 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); 343 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id));
334 } 344 }
335 if (!resource->mailbox.IsEmpty() && resource->external) { 345 if (resource->mailbox.IsValid() && resource->external) {
336 WebGraphicsContext3D* context3d = output_surface_->context3d();
337 DCHECK(context3d);
338 unsigned sync_point = resource->mailbox.sync_point(); 346 unsigned sync_point = resource->mailbox.sync_point();
339 if (!lost_resource && resource->gl_id) { 347 if (resource->mailbox.IsTexture()) {
340 GLC(context3d, context3d->bindTexture( 348 WebGraphicsContext3D* context3d = output_surface_->context3d();
341 resource->mailbox.target(), resource->gl_id)); 349 DCHECK(context3d);
342 GLC(context3d, context3d->produceTextureCHROMIUM( 350 if (!lost_resource && resource->gl_id) {
343 resource->mailbox.target(), resource->mailbox.data())); 351 GLC(context3d, context3d->bindTexture(
352 resource->mailbox.target(), resource->gl_id));
353 GLC(context3d, context3d->produceTextureCHROMIUM(
354 resource->mailbox.target(), resource->mailbox.data()));
355 }
356 if (resource->gl_id)
357 GLC(context3d, context3d->deleteTexture(resource->gl_id));
358 if (!lost_resource && resource->gl_id)
359 sync_point = context3d->insertSyncPoint();
360 } else {
361 DCHECK(resource->mailbox.IsSharedMemory());
362 base::SharedMemory* shared_memory = resource->mailbox.shared_memory();
363 if (resource->pixels && shared_memory) {
364 DCHECK(shared_memory->memory() == resource->pixels);
365 resource->pixels = NULL;
366 }
344 } 367 }
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); 368 resource->mailbox.RunReleaseCallback(sync_point, lost_resource);
350 } 369 }
351 if (resource->pixels) 370 if (resource->pixels)
352 delete[] resource->pixels; 371 delete[] resource->pixels;
353 if (resource->pixel_buffer) 372 if (resource->pixel_buffer)
354 delete[] resource->pixel_buffer; 373 delete[] resource->pixel_buffer;
355 374
356 resources_.erase(it); 375 resources_.erase(it);
357 } 376 }
358 377
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 CHECK(it != resources_.end()); 499 CHECK(it != resources_.end());
481 Resource* resource = &it->second; 500 Resource* resource = &it->second;
482 DCHECK(!resource->locked_for_write || 501 DCHECK(!resource->locked_for_write ||
483 resource->set_pixels_completion_forced) << 502 resource->set_pixels_completion_forced) <<
484 "locked for write: " << resource->locked_for_write << 503 "locked for write: " << resource->locked_for_write <<
485 " pixels completion forced: " << resource->set_pixels_completion_forced; 504 " pixels completion forced: " << resource->set_pixels_completion_forced;
486 DCHECK(!resource->exported); 505 DCHECK(!resource->exported);
487 // Uninitialized! Call SetPixels or LockForWrite first. 506 // Uninitialized! Call SetPixels or LockForWrite first.
488 DCHECK(resource->allocated); 507 DCHECK(resource->allocated);
489 508
490 if (!resource->gl_id && resource->external && !resource->mailbox.IsEmpty()) { 509 if (resource->external) {
491 WebGraphicsContext3D* context3d = output_surface_->context3d(); 510 if (!resource->gl_id && resource->mailbox.IsTexture()) {
492 DCHECK(context3d); 511 WebGraphicsContext3D* context3d = output_surface_->context3d();
493 if (resource->mailbox.sync_point()) { 512 DCHECK(context3d);
494 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point())); 513 if (resource->mailbox.sync_point()) {
495 resource->mailbox.ResetSyncPoint(); 514 GLC(context3d,
515 context3d->waitSyncPoint(resource->mailbox.sync_point()));
516 resource->mailbox.ResetSyncPoint();
517 }
518 resource->gl_id = context3d->createTexture();
519 GLC(context3d, context3d->bindTexture(
520 resource->mailbox.target(), resource->gl_id));
521 GLC(context3d, context3d->consumeTextureCHROMIUM(
522 resource->mailbox.target(), resource->mailbox.data()));
496 } 523 }
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 } 524 }
503 525
504 resource->lock_for_read_count++; 526 resource->lock_for_read_count++;
505 if (resource->enable_read_lock_fences) 527 if (resource->enable_read_lock_fences)
506 resource->read_lock_fence = current_read_lock_fence_; 528 resource->read_lock_fence = current_read_lock_fence_;
507 529
508 return resource; 530 return resource;
509 } 531 }
510 532
511 void ResourceProvider::UnlockForRead(ResourceId id) { 533 void ResourceProvider::UnlockForRead(ResourceId id) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 } 855 }
834 for (TransferableResourceArray::const_iterator it = resources.begin(); 856 for (TransferableResourceArray::const_iterator it = resources.begin();
835 it != resources.end(); 857 it != resources.end();
836 ++it) { 858 ++it) {
837 ResourceMap::iterator map_iterator = resources_.find(it->id); 859 ResourceMap::iterator map_iterator = resources_.find(it->id);
838 DCHECK(map_iterator != resources_.end()); 860 DCHECK(map_iterator != resources_.end());
839 Resource* resource = &map_iterator->second; 861 Resource* resource = &map_iterator->second;
840 DCHECK(resource->exported); 862 DCHECK(resource->exported);
841 resource->exported = false; 863 resource->exported = false;
842 resource->filter = it->filter; 864 resource->filter = it->filter;
843 DCHECK(resource->mailbox.Equals(it->mailbox)); 865 DCHECK(resource->mailbox.ContainsMailbox(it->mailbox));
844 if (resource->gl_id) { 866 if (resource->gl_id) {
845 if (it->sync_point) 867 if (it->sync_point)
846 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 868 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
847 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 869 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
848 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 870 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
849 it->mailbox.name)); 871 it->mailbox.name));
850 } else { 872 } else {
851 resource->mailbox = TextureMailbox(resource->mailbox.name(), 873 resource->mailbox = TextureMailbox(resource->mailbox.name(),
852 resource->mailbox.callback(), 874 resource->mailbox.callback(),
853 it->sync_point); 875 it->sync_point);
854 } 876 }
855 if (resource->marked_for_deletion) 877 if (resource->marked_for_deletion)
856 DeleteResourceInternal(map_iterator, Normal); 878 DeleteResourceInternal(map_iterator, Normal);
857 } 879 }
858 } 880 }
859 881
860 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, 882 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context,
861 ResourceId id, 883 ResourceId id,
862 TransferableResource* resource) { 884 TransferableResource* resource) {
863 DCHECK(thread_checker_.CalledOnValidThread()); 885 DCHECK(thread_checker_.CalledOnValidThread());
864 WebGraphicsContext3D* context3d = output_surface_->context3d(); 886 WebGraphicsContext3D* context3d = output_surface_->context3d();
865 ResourceMap::iterator it = resources_.find(id); 887 ResourceMap::iterator it = resources_.find(id);
866 CHECK(it != resources_.end()); 888 CHECK(it != resources_.end());
867 Resource* source = &it->second; 889 Resource* source = &it->second;
868 DCHECK(!source->locked_for_write); 890 DCHECK(!source->locked_for_write);
869 DCHECK(!source->lock_for_read_count); 891 DCHECK(!source->lock_for_read_count);
870 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); 892 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
871 DCHECK(source->allocated); 893 DCHECK(source->allocated);
872 if (source->exported) 894 if (source->exported)
873 return false; 895 return false;
874 resource->id = id; 896 resource->id = id;
875 resource->format = source->format; 897 resource->format = source->format;
876 resource->filter = source->filter; 898 resource->filter = source->filter;
877 resource->size = source->size; 899 resource->size = source->size;
878 900
879 if (source->mailbox.IsEmpty()) { 901 // TODO(skaslev) Implement this path for shared memory resources.
902 DCHECK(!source->mailbox.IsSharedMemory());
903
904 if (!source->mailbox.IsTexture()) {
880 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); 905 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name));
881 source->mailbox.SetName(resource->mailbox); 906 source->mailbox.SetName(resource->mailbox);
882 } else { 907 } else {
883 resource->mailbox = source->mailbox.name(); 908 resource->mailbox = source->mailbox.name();
884 } 909 }
885 910
886 if (source->gl_id) { 911 if (source->gl_id) {
887 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 912 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
888 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, 913 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D,
889 resource->mailbox.name)); 914 resource->mailbox.name));
(...skipping 16 matching lines...) Expand all
906 if (resource->gl_id) { 931 if (resource->gl_id) {
907 WebGraphicsContext3D* context3d = output_surface_->context3d(); 932 WebGraphicsContext3D* context3d = output_surface_->context3d();
908 DCHECK(context3d); 933 DCHECK(context3d);
909 if (!resource->gl_pixel_buffer_id) 934 if (!resource->gl_pixel_buffer_id)
910 resource->gl_pixel_buffer_id = context3d->createBuffer(); 935 resource->gl_pixel_buffer_id = context3d->createBuffer();
911 context3d->bindBuffer( 936 context3d->bindBuffer(
912 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 937 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
913 resource->gl_pixel_buffer_id); 938 resource->gl_pixel_buffer_id);
914 context3d->bufferData( 939 context3d->bufferData(
915 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 940 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
916 resource->size.width() * resource->size.height() * 4, 941 4 * resource->size.GetArea(),
917 NULL, 942 NULL,
918 GL_DYNAMIC_DRAW); 943 GL_DYNAMIC_DRAW);
919 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 944 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
920 } 945 }
921 946
922 if (resource->pixels) { 947 if (resource->pixels) {
923 if (resource->pixel_buffer) 948 if (resource->pixel_buffer)
924 return; 949 return;
925 950
926 resource->pixel_buffer = new uint8_t[ 951 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
927 resource->size.width() * resource->size.height() * 4];
928 } 952 }
929 } 953 }
930 954
931 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 955 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
932 DCHECK(thread_checker_.CalledOnValidThread()); 956 DCHECK(thread_checker_.CalledOnValidThread());
933 ResourceMap::iterator it = resources_.find(id); 957 ResourceMap::iterator it = resources_.find(id);
934 CHECK(it != resources_.end()); 958 CHECK(it != resources_.end());
935 Resource* resource = &it->second; 959 Resource* resource = &it->second;
936 DCHECK(!resource->external); 960 DCHECK(!resource->external);
937 DCHECK(!resource->exported); 961 DCHECK(!resource->exported);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 resource->size.height(), 1066 resource->size.height(),
1043 resource->format, 1067 resource->format,
1044 GL_UNSIGNED_BYTE, 1068 GL_UNSIGNED_BYTE,
1045 NULL); 1069 NULL);
1046 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1070 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1047 context3d->deleteBuffer(resource->gl_pixel_buffer_id); 1071 context3d->deleteBuffer(resource->gl_pixel_buffer_id);
1048 resource->gl_pixel_buffer_id = 0; 1072 resource->gl_pixel_buffer_id = 0;
1049 } 1073 }
1050 1074
1051 if (resource->pixels) { 1075 if (resource->pixels) {
1076 DCHECK(!resource->mailbox.IsValid());
1052 DCHECK(resource->pixel_buffer); 1077 DCHECK(resource->pixel_buffer);
1053 DCHECK(resource->format == GL_RGBA); 1078 DCHECK(resource->format == GL_RGBA);
1054 1079
1055 ScopedWriteLockSoftware lock(this, id); 1080 ScopedWriteLockSoftware lock(this, id);
1056 std::swap(resource->pixels, resource->pixel_buffer); 1081 std::swap(resource->pixels, resource->pixel_buffer);
1057 delete[] resource->pixel_buffer; 1082 delete[] resource->pixel_buffer;
1058 resource->pixel_buffer = NULL; 1083 resource->pixel_buffer = NULL;
1059 } 1084 }
1060 } 1085 }
1061 1086
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1394 WebGraphicsContext3D* context3d = output_surface_->context3d();
1370 DCHECK(context3d); 1395 DCHECK(context3d);
1371 int stride = 0; 1396 int stride = 0;
1372 context3d->getImageParameterivCHROMIUM( 1397 context3d->getImageParameterivCHROMIUM(
1373 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); 1398 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride);
1374 return stride; 1399 return stride;
1375 } 1400 }
1376 1401
1377 1402
1378 } // namespace cc 1403 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/software_renderer.cc ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698