OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resource_provider.h" | 5 #include "cc/resource_provider.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 , glUploadQueryId(0) | 54 , glUploadQueryId(0) |
55 , pixels(0) | 55 , pixels(0) |
56 , pixelBuffer(0) | 56 , pixelBuffer(0) |
57 , lockForReadCount(0) | 57 , lockForReadCount(0) |
58 , lockedForWrite(false) | 58 , lockedForWrite(false) |
59 , external(false) | 59 , external(false) |
60 , exported(false) | 60 , exported(false) |
61 , markedForDeletion(false) | 61 , markedForDeletion(false) |
62 , pendingSetPixels(false) | 62 , pendingSetPixels(false) |
63 , allocated(false) | 63 , allocated(false) |
| 64 , enableReadLockFences(false) |
| 65 , readLockFence(NULL) |
64 , size() | 66 , size() |
65 , format(0) | 67 , format(0) |
66 , filter(0) | 68 , filter(0) |
67 , type(static_cast<ResourceType>(0)) | 69 , type(static_cast<ResourceType>(0)) |
68 { | 70 { |
69 } | 71 } |
70 | 72 |
71 ResourceProvider::Resource::~Resource() | 73 ResourceProvider::Resource::~Resource() |
72 { | 74 { |
73 } | 75 } |
74 | 76 |
75 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size,
GLenum format, GLenum filter) | 77 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size,
GLenum format, GLenum filter) |
76 : glId(textureId) | 78 : glId(textureId) |
77 , glPixelBufferId(0) | 79 , glPixelBufferId(0) |
78 , glUploadQueryId(0) | 80 , glUploadQueryId(0) |
79 , pixels(0) | 81 , pixels(0) |
80 , pixelBuffer(0) | 82 , pixelBuffer(0) |
81 , lockForReadCount(0) | 83 , lockForReadCount(0) |
82 , lockedForWrite(false) | 84 , lockedForWrite(false) |
83 , external(false) | 85 , external(false) |
84 , exported(false) | 86 , exported(false) |
85 , markedForDeletion(false) | 87 , markedForDeletion(false) |
86 , pendingSetPixels(false) | 88 , pendingSetPixels(false) |
87 , allocated(false) | 89 , allocated(false) |
| 90 , enableReadLockFences(false) |
| 91 , readLockFence(NULL) |
88 , size(size) | 92 , size(size) |
89 , format(format) | 93 , format(format) |
90 , filter(filter) | 94 , filter(filter) |
91 , type(GLTexture) | 95 , type(GLTexture) |
92 { | 96 { |
93 } | 97 } |
94 | 98 |
95 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe
num format, GLenum filter) | 99 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe
num format, GLenum filter) |
96 : glId(0) | 100 : glId(0) |
97 , glPixelBufferId(0) | 101 , glPixelBufferId(0) |
98 , glUploadQueryId(0) | 102 , glUploadQueryId(0) |
99 , pixels(pixels) | 103 , pixels(pixels) |
100 , pixelBuffer(0) | 104 , pixelBuffer(0) |
101 , lockForReadCount(0) | 105 , lockForReadCount(0) |
102 , lockedForWrite(false) | 106 , lockedForWrite(false) |
103 , external(false) | 107 , external(false) |
104 , exported(false) | 108 , exported(false) |
105 , markedForDeletion(false) | 109 , markedForDeletion(false) |
106 , pendingSetPixels(false) | 110 , pendingSetPixels(false) |
107 , allocated(false) | 111 , allocated(false) |
| 112 , enableReadLockFences(false) |
| 113 , readLockFence(NULL) |
108 , size(size) | 114 , size(size) |
109 , format(format) | 115 , format(format) |
110 , filter(filter) | 116 , filter(filter) |
111 , type(Bitmap) | 117 , type(Bitmap) |
112 { | 118 { |
113 } | 119 } |
114 | 120 |
115 ResourceProvider::Child::Child() | 121 ResourceProvider::Child::Child() |
116 { | 122 { |
117 } | 123 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
:Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) | 327 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
:Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) |
322 { | 328 { |
323 DCHECK(m_threadChecker.CalledOnValidThread()); | 329 DCHECK(m_threadChecker.CalledOnValidThread()); |
324 ResourceMap::iterator it = m_resources.find(id); | 330 ResourceMap::iterator it = m_resources.find(id); |
325 CHECK(it != m_resources.end()); | 331 CHECK(it != m_resources.end()); |
326 Resource* resource = &it->second; | 332 Resource* resource = &it->second; |
327 DCHECK(!resource->lockedForWrite); | 333 DCHECK(!resource->lockedForWrite); |
328 DCHECK(!resource->lockForReadCount); | 334 DCHECK(!resource->lockForReadCount); |
329 DCHECK(!resource->external); | 335 DCHECK(!resource->external); |
330 DCHECK(!resource->exported); | 336 DCHECK(!resource->exported); |
| 337 DCHECK(readLockFenceHasPassed(resource)); |
331 lazyAllocate(resource); | 338 lazyAllocate(resource); |
332 | 339 |
333 if (resource->glId) { | 340 if (resource->glId) { |
334 DCHECK(!resource->pendingSetPixels); | 341 DCHECK(!resource->pendingSetPixels); |
335 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 342 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
336 DCHECK(context3d); | 343 DCHECK(context3d); |
337 DCHECK(m_textureUploader.get()); | 344 DCHECK(m_textureUploader.get()); |
338 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 345 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
339 m_textureUploader->upload(image, | 346 m_textureUploader->upload(image, |
340 imageRect, | 347 imageRect, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 if (resource->mailbox.sync_point()) { | 435 if (resource->mailbox.sync_point()) { |
429 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point
())); | 436 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point
())); |
430 resource->mailbox.ResetSyncPoint(); | 437 resource->mailbox.ResetSyncPoint(); |
431 } | 438 } |
432 resource->glId = context3d->createTexture(); | 439 resource->glId = context3d->createTexture(); |
433 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 440 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
434 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, resource
->mailbox.data())); | 441 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, resource
->mailbox.data())); |
435 } | 442 } |
436 | 443 |
437 resource->lockForReadCount++; | 444 resource->lockForReadCount++; |
| 445 if (resource->enableReadLockFences) |
| 446 resource->readLockFence = m_currentReadLockFence; |
| 447 |
438 return resource; | 448 return resource; |
439 } | 449 } |
440 | 450 |
441 void ResourceProvider::unlockForRead(ResourceId id) | 451 void ResourceProvider::unlockForRead(ResourceId id) |
442 { | 452 { |
443 DCHECK(m_threadChecker.CalledOnValidThread()); | 453 DCHECK(m_threadChecker.CalledOnValidThread()); |
444 ResourceMap::iterator it = m_resources.find(id); | 454 ResourceMap::iterator it = m_resources.find(id); |
445 CHECK(it != m_resources.end()); | 455 CHECK(it != m_resources.end()); |
446 Resource* resource = &it->second; | 456 Resource* resource = &it->second; |
447 DCHECK(resource->lockForReadCount > 0); | 457 DCHECK(resource->lockForReadCount > 0); |
448 DCHECK(!resource->exported); | 458 DCHECK(!resource->exported); |
449 resource->lockForReadCount--; | 459 resource->lockForReadCount--; |
450 } | 460 } |
451 | 461 |
452 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) | 462 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) |
453 { | 463 { |
454 DCHECK(m_threadChecker.CalledOnValidThread()); | 464 DCHECK(m_threadChecker.CalledOnValidThread()); |
455 ResourceMap::iterator it = m_resources.find(id); | 465 ResourceMap::iterator it = m_resources.find(id); |
456 CHECK(it != m_resources.end()); | 466 CHECK(it != m_resources.end()); |
457 Resource* resource = &it->second; | 467 Resource* resource = &it->second; |
458 DCHECK(!resource->lockedForWrite); | 468 DCHECK(!resource->lockedForWrite); |
459 DCHECK(!resource->lockForReadCount); | 469 DCHECK(!resource->lockForReadCount); |
460 DCHECK(!resource->exported); | 470 DCHECK(!resource->exported); |
461 DCHECK(!resource->external); | 471 DCHECK(!resource->external); |
| 472 DCHECK(readLockFenceHasPassed(resource)); |
462 lazyAllocate(resource); | 473 lazyAllocate(resource); |
463 | 474 |
464 resource->lockedForWrite = true; | 475 resource->lockedForWrite = true; |
465 return resource; | 476 return resource; |
466 } | 477 } |
467 | 478 |
| 479 bool ResourceProvider::canLockForWrite(ResourceId id) |
| 480 { |
| 481 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 482 ResourceMap::iterator it = m_resources.find(id); |
| 483 CHECK(it != m_resources.end()); |
| 484 Resource* resource = &it->second; |
| 485 return !resource->lockedForWrite && |
| 486 !resource->lockForReadCount && |
| 487 !resource->exported && |
| 488 !resource->external && |
| 489 readLockFenceHasPassed(resource); |
| 490 } |
| 491 |
468 void ResourceProvider::unlockForWrite(ResourceId id) | 492 void ResourceProvider::unlockForWrite(ResourceId id) |
469 { | 493 { |
470 DCHECK(m_threadChecker.CalledOnValidThread()); | 494 DCHECK(m_threadChecker.CalledOnValidThread()); |
471 ResourceMap::iterator it = m_resources.find(id); | 495 ResourceMap::iterator it = m_resources.find(id); |
472 CHECK(it != m_resources.end()); | 496 CHECK(it != m_resources.end()); |
473 Resource* resource = &it->second; | 497 Resource* resource = &it->second; |
474 DCHECK(resource->lockedForWrite); | 498 DCHECK(resource->lockedForWrite); |
475 DCHECK(!resource->exported); | 499 DCHECK(!resource->exported); |
476 DCHECK(!resource->external); | 500 DCHECK(!resource->external); |
477 resource->lockedForWrite = false; | 501 resource->lockedForWrite = false; |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 void ResourceProvider::setPixelsFromBuffer(ResourceId id) | 903 void ResourceProvider::setPixelsFromBuffer(ResourceId id) |
880 { | 904 { |
881 DCHECK(m_threadChecker.CalledOnValidThread()); | 905 DCHECK(m_threadChecker.CalledOnValidThread()); |
882 ResourceMap::iterator it = m_resources.find(id); | 906 ResourceMap::iterator it = m_resources.find(id); |
883 CHECK(it != m_resources.end()); | 907 CHECK(it != m_resources.end()); |
884 Resource* resource = &it->second; | 908 Resource* resource = &it->second; |
885 DCHECK(!resource->lockedForWrite); | 909 DCHECK(!resource->lockedForWrite); |
886 DCHECK(!resource->lockForReadCount); | 910 DCHECK(!resource->lockForReadCount); |
887 DCHECK(!resource->external); | 911 DCHECK(!resource->external); |
888 DCHECK(!resource->exported); | 912 DCHECK(!resource->exported); |
| 913 DCHECK(readLockFenceHasPassed(resource)); |
889 lazyAllocate(resource); | 914 lazyAllocate(resource); |
890 | 915 |
891 if (resource->glId) { | 916 if (resource->glId) { |
892 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 917 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
893 DCHECK(context3d); | 918 DCHECK(context3d); |
894 DCHECK(resource->glPixelBufferId); | 919 DCHECK(resource->glPixelBufferId); |
895 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 920 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
896 context3d->bindBuffer( | 921 context3d->bindBuffer( |
897 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 922 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
898 resource->glPixelBufferId); | 923 resource->glPixelBufferId); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 } | 967 } |
943 | 968 |
944 void ResourceProvider::beginSetPixels(ResourceId id) | 969 void ResourceProvider::beginSetPixels(ResourceId id) |
945 { | 970 { |
946 DCHECK(m_threadChecker.CalledOnValidThread()); | 971 DCHECK(m_threadChecker.CalledOnValidThread()); |
947 ResourceMap::iterator it = m_resources.find(id); | 972 ResourceMap::iterator it = m_resources.find(id); |
948 CHECK(it != m_resources.end()); | 973 CHECK(it != m_resources.end()); |
949 Resource* resource = &it->second; | 974 Resource* resource = &it->second; |
950 DCHECK(!resource->pendingSetPixels); | 975 DCHECK(!resource->pendingSetPixels); |
951 DCHECK(resource->glId || resource->allocated); | 976 DCHECK(resource->glId || resource->allocated); |
| 977 DCHECK(readLockFenceHasPassed(resource)); |
952 | 978 |
953 bool allocate = !resource->allocated; | 979 bool allocate = !resource->allocated; |
954 resource->allocated = true; | 980 resource->allocated = true; |
955 lockForWrite(id); | 981 lockForWrite(id); |
956 | 982 |
957 if (resource->glId) { | 983 if (resource->glId) { |
958 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 984 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
959 DCHECK(context3d); | 985 DCHECK(context3d); |
960 DCHECK(resource->glPixelBufferId); | 986 DCHECK(resource->glPixelBufferId); |
961 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 987 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 Resource* resource = &it->second; | 1057 Resource* resource = &it->second; |
1032 lazyAllocate(resource); | 1058 lazyAllocate(resource); |
1033 } | 1059 } |
1034 | 1060 |
1035 void ResourceProvider::lazyAllocate(Resource* resource) { | 1061 void ResourceProvider::lazyAllocate(Resource* resource) { |
1036 DCHECK(resource); | 1062 DCHECK(resource); |
1037 DCHECK(resource->glId || resource->allocated); | 1063 DCHECK(resource->glId || resource->allocated); |
1038 | 1064 |
1039 if (resource->allocated || !resource->glId) | 1065 if (resource->allocated || !resource->glId) |
1040 return; | 1066 return; |
1041 | |
1042 resource->allocated = true; | 1067 resource->allocated = true; |
1043 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 1068 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
1044 gfx::Size& size = resource->size; | 1069 gfx::Size& size = resource->size; |
1045 GLenum format = resource->format; | 1070 GLenum format = resource->format; |
1046 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 1071 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
1047 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 1072 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
1048 GLenum storageFormat = textureToStorageFormat(format); | 1073 GLenum storageFormat = textureToStorageFormat(format); |
1049 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); | 1074 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); |
1050 } else | 1075 } else |
1051 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 1076 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
1052 } | 1077 } |
1053 | 1078 |
| 1079 void ResourceProvider::enableReadLockFences(ResourceProvider::ResourceId id, boo
l enable) { |
| 1080 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 1081 ResourceMap::iterator it = m_resources.find(id); |
| 1082 CHECK(it != m_resources.end()); |
| 1083 Resource* resource = &it->second; |
| 1084 resource->enableReadLockFences = enable; |
| 1085 } |
1054 | 1086 |
1055 } // namespace cc | 1087 } // namespace cc |
OLD | NEW |