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/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 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 ResourceMap::iterator& map_iterator = sorted_resources[i].second; | 1187 ResourceMap::iterator& map_iterator = sorted_resources[i].second; |
1188 ResourceId local_id = map_iterator->first; | 1188 ResourceId local_id = map_iterator->first; |
1189 Resource* resource = &map_iterator->second; | 1189 Resource* resource = &map_iterator->second; |
1190 | 1190 |
1191 CHECK_GE(resource->exported_count, returned.count); | 1191 CHECK_GE(resource->exported_count, returned.count); |
1192 resource->exported_count -= returned.count; | 1192 resource->exported_count -= returned.count; |
1193 resource->lost |= returned.lost; | 1193 resource->lost |= returned.lost; |
1194 if (resource->exported_count) | 1194 if (resource->exported_count) |
1195 continue; | 1195 continue; |
1196 | 1196 |
| 1197 // Need to wait for the current read lock fence to pass before we can |
| 1198 // recycle this resource. |
| 1199 if (resource->enable_read_lock_fences) |
| 1200 resource->read_lock_fence = current_read_lock_fence_; |
| 1201 |
1197 if (resource->gl_id) { | 1202 if (resource->gl_id) { |
1198 if (returned.sync_point) | 1203 if (returned.sync_point) |
1199 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); | 1204 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); |
1200 } else if (!resource->shared_bitmap) { | 1205 } else if (!resource->shared_bitmap) { |
1201 resource->mailbox = | 1206 resource->mailbox = |
1202 TextureMailbox(resource->mailbox.name(), returned.sync_point); | 1207 TextureMailbox(resource->mailbox.name(), returned.sync_point); |
1203 } | 1208 } |
1204 | 1209 |
1205 if (!resource->marked_for_deletion) | 1210 if (!resource->marked_for_deletion) |
1206 continue; | 1211 continue; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 resource->id = id; | 1253 resource->id = id; |
1249 resource->format = source->format; | 1254 resource->format = source->format; |
1250 resource->target = source->target; | 1255 resource->target = source->target; |
1251 resource->filter = source->filter; | 1256 resource->filter = source->filter; |
1252 resource->size = source->size; | 1257 resource->size = source->size; |
1253 | 1258 |
1254 if (source->shared_bitmap) { | 1259 if (source->shared_bitmap) { |
1255 resource->mailbox = source->shared_bitmap->id(); | 1260 resource->mailbox = source->shared_bitmap->id(); |
1256 resource->is_software = true; | 1261 resource->is_software = true; |
1257 } else if (!source->mailbox.IsValid()) { | 1262 } else if (!source->mailbox.IsValid()) { |
| 1263 LazyCreate(source); |
| 1264 DCHECK(source->gl_id); |
| 1265 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); |
| 1266 if (source->image_id) { |
| 1267 DCHECK(source->dirty_image); |
| 1268 BindImageForSampling(source); |
| 1269 } |
1258 // This is a resource allocated by the compositor, we need to produce it. | 1270 // This is a resource allocated by the compositor, we need to produce it. |
1259 // Don't set a sync point, the caller will do it. | 1271 // Don't set a sync point, the caller will do it. |
1260 DCHECK(source->gl_id); | |
1261 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); | |
1262 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox.name)); | 1272 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox.name)); |
1263 GLC(gl, | 1273 GLC(gl, |
1264 gl->ProduceTextureCHROMIUM(resource->target, resource->mailbox.name)); | 1274 gl->ProduceTextureCHROMIUM(resource->target, resource->mailbox.name)); |
1265 source->mailbox.SetName(resource->mailbox); | 1275 source->mailbox.SetName(resource->mailbox); |
1266 } else { | 1276 } else { |
1267 DCHECK(source->mailbox.IsTexture()); | 1277 DCHECK(source->mailbox.IsTexture()); |
| 1278 if (source->image_id && source->dirty_image) { |
| 1279 DCHECK(source->gl_id); |
| 1280 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); |
| 1281 BindImageForSampling(source); |
| 1282 } |
1268 // This is either an external resource, or a compositor resource that we | 1283 // This is either an external resource, or a compositor resource that we |
1269 // already exported. Make sure to forward the sync point that we were given. | 1284 // already exported. Make sure to forward the sync point that we were given. |
1270 resource->mailbox = source->mailbox.name(); | 1285 resource->mailbox = source->mailbox.name(); |
1271 resource->sync_point = source->mailbox.sync_point(); | 1286 resource->sync_point = source->mailbox.sync_point(); |
1272 source->mailbox.ResetSyncPoint(); | 1287 source->mailbox.ResetSyncPoint(); |
1273 } | 1288 } |
1274 } | 1289 } |
1275 | 1290 |
1276 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( | 1291 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
1277 ChildMap::iterator child_it, | 1292 ChildMap::iterator child_it, |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 | 1505 |
1491 ScopedSetActiveTexture scoped_active_tex(gl, unit); | 1506 ScopedSetActiveTexture scoped_active_tex(gl, unit); |
1492 GLenum target = resource->target; | 1507 GLenum target = resource->target; |
1493 GLC(gl, gl->BindTexture(target, resource->gl_id)); | 1508 GLC(gl, gl->BindTexture(target, resource->gl_id)); |
1494 if (filter != resource->filter) { | 1509 if (filter != resource->filter) { |
1495 GLC(gl, gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter)); | 1510 GLC(gl, gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter)); |
1496 GLC(gl, gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter)); | 1511 GLC(gl, gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter)); |
1497 resource->filter = filter; | 1512 resource->filter = filter; |
1498 } | 1513 } |
1499 | 1514 |
1500 if (resource->image_id && resource->dirty_image) { | 1515 if (resource->image_id && resource->dirty_image) |
1501 // Release image currently bound to texture. | 1516 BindImageForSampling(resource); |
1502 if (resource->bound_image_id) | |
1503 gl->ReleaseTexImage2DCHROMIUM(target, resource->bound_image_id); | |
1504 gl->BindTexImage2DCHROMIUM(target, resource->image_id); | |
1505 resource->bound_image_id = resource->image_id; | |
1506 resource->dirty_image = false; | |
1507 } | |
1508 | 1517 |
1509 return target; | 1518 return target; |
1510 } | 1519 } |
1511 | 1520 |
1512 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1521 void ResourceProvider::BeginSetPixels(ResourceId id) { |
1513 Resource* resource = GetResource(id); | 1522 Resource* resource = GetResource(id); |
1514 DCHECK(!resource->pending_set_pixels); | 1523 DCHECK(!resource->pending_set_pixels); |
1515 | 1524 |
1516 LazyCreate(resource); | 1525 LazyCreate(resource); |
1517 DCHECK(resource->gl_id || resource->allocated); | 1526 DCHECK(resource->gl_id || resource->allocated); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 } | 1630 } |
1622 | 1631 |
1623 void ResourceProvider::LazyCreate(Resource* resource) { | 1632 void ResourceProvider::LazyCreate(Resource* resource) { |
1624 if (resource->type != GLTexture || resource->gl_id != 0) | 1633 if (resource->type != GLTexture || resource->gl_id != 0) |
1625 return; | 1634 return; |
1626 | 1635 |
1627 // Early out for resources that don't require texture creation. | 1636 // Early out for resources that don't require texture creation. |
1628 if (resource->texture_pool == 0) | 1637 if (resource->texture_pool == 0) |
1629 return; | 1638 return; |
1630 | 1639 |
| 1640 DCHECK(!resource->external); |
| 1641 DCHECK(!resource->mailbox.IsValid()); |
1631 resource->gl_id = texture_id_allocator_->NextId(); | 1642 resource->gl_id = texture_id_allocator_->NextId(); |
1632 | 1643 |
1633 GLES2Interface* gl = ContextGL(); | 1644 GLES2Interface* gl = ContextGL(); |
1634 DCHECK(gl); | 1645 DCHECK(gl); |
1635 | 1646 |
1636 // Create and set texture properties. Allocation is delayed until needed. | 1647 // Create and set texture properties. Allocation is delayed until needed. |
1637 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 1648 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
1638 GLC(gl, | 1649 GLC(gl, |
1639 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 1650 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
1640 GLC(gl, | 1651 GLC(gl, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 size.width(), | 1700 size.width(), |
1690 size.height(), | 1701 size.height(), |
1691 0, | 1702 0, |
1692 GLDataFormat(format), | 1703 GLDataFormat(format), |
1693 GLDataType(format), | 1704 GLDataType(format), |
1694 NULL)); | 1705 NULL)); |
1695 } | 1706 } |
1696 } | 1707 } |
1697 } | 1708 } |
1698 | 1709 |
| 1710 void ResourceProvider::BindImageForSampling(Resource* resource) { |
| 1711 GLES2Interface* gl = ContextGL(); |
| 1712 DCHECK(resource->gl_id); |
| 1713 DCHECK(resource->image_id); |
| 1714 |
| 1715 // Release image currently bound to texture. |
| 1716 if (resource->bound_image_id) |
| 1717 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); |
| 1718 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); |
| 1719 resource->bound_image_id = resource->image_id; |
| 1720 resource->dirty_image = false; |
| 1721 } |
| 1722 |
1699 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1723 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1700 bool enable) { | 1724 bool enable) { |
1701 Resource* resource = GetResource(id); | 1725 Resource* resource = GetResource(id); |
1702 resource->enable_read_lock_fences = enable; | 1726 resource->enable_read_lock_fences = enable; |
1703 } | 1727 } |
1704 | 1728 |
1705 void ResourceProvider::AcquireImage(ResourceId id) { | 1729 void ResourceProvider::AcquireImage(ResourceId id) { |
1706 Resource* resource = GetResource(id); | 1730 Resource* resource = GetResource(id); |
1707 DCHECK(!resource->external); | 1731 DCHECK(!resource->external); |
1708 DCHECK_EQ(resource->exported_count, 0); | 1732 DCHECK_EQ(resource->exported_count, 0); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1828 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1805 return active_unit; | 1829 return active_unit; |
1806 } | 1830 } |
1807 | 1831 |
1808 GLES2Interface* ResourceProvider::ContextGL() const { | 1832 GLES2Interface* ResourceProvider::ContextGL() const { |
1809 ContextProvider* context_provider = output_surface_->context_provider(); | 1833 ContextProvider* context_provider = output_surface_->context_provider(); |
1810 return context_provider ? context_provider->ContextGL() : NULL; | 1834 return context_provider ? context_provider->ContextGL() : NULL; |
1811 } | 1835 } |
1812 | 1836 |
1813 } // namespace cc | 1837 } // namespace cc |
OLD | NEW |