| 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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 580 |
| 581 void ResourceProvider::DeleteResource(ResourceId id) { | 581 void ResourceProvider::DeleteResource(ResourceId id) { |
| 582 DCHECK(thread_checker_.CalledOnValidThread()); | 582 DCHECK(thread_checker_.CalledOnValidThread()); |
| 583 ResourceMap::iterator it = resources_.find(id); | 583 ResourceMap::iterator it = resources_.find(id); |
| 584 CHECK(it != resources_.end()); | 584 CHECK(it != resources_.end()); |
| 585 Resource* resource = &it->second; | 585 Resource* resource = &it->second; |
| 586 DCHECK(!resource->marked_for_deletion); | 586 DCHECK(!resource->marked_for_deletion); |
| 587 DCHECK_EQ(resource->imported_count, 0); | 587 DCHECK_EQ(resource->imported_count, 0); |
| 588 DCHECK(resource->pending_set_pixels || !resource->locked_for_write); | 588 DCHECK(resource->pending_set_pixels || !resource->locked_for_write); |
| 589 | 589 |
| 590 if (resource->exported_count > 0 || resource->lock_for_read_count > 0) { | 590 if (resource->exported_count > 0 || resource->lock_for_read_count > 0 || |
| 591 !ReadLockFenceHasPassed(resource)) { |
| 591 resource->marked_for_deletion = true; | 592 resource->marked_for_deletion = true; |
| 592 return; | 593 return; |
| 593 } else { | 594 } else { |
| 594 DeleteResourceInternal(it, NORMAL); | 595 DeleteResourceInternal(it, NORMAL); |
| 595 } | 596 } |
| 596 } | 597 } |
| 597 | 598 |
| 598 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 599 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| 599 DeleteStyle style) { | 600 DeleteStyle style) { |
| 600 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 601 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 !resource->lost && ReadLockFenceHasPassed(resource); | 941 !resource->lost && ReadLockFenceHasPassed(resource); |
| 941 } | 942 } |
| 942 | 943 |
| 943 void ResourceProvider::UnlockForWrite(ResourceProvider::Resource* resource) { | 944 void ResourceProvider::UnlockForWrite(ResourceProvider::Resource* resource) { |
| 944 DCHECK(resource->locked_for_write); | 945 DCHECK(resource->locked_for_write); |
| 945 DCHECK_EQ(resource->exported_count, 0); | 946 DCHECK_EQ(resource->exported_count, 0); |
| 946 DCHECK(resource->origin == Resource::INTERNAL); | 947 DCHECK(resource->origin == Resource::INTERNAL); |
| 947 resource->locked_for_write = false; | 948 resource->locked_for_write = false; |
| 948 } | 949 } |
| 949 | 950 |
| 951 void ResourceProvider::EnableReadLockFences(ResourceId id) { |
| 952 Resource* resource = GetResource(id); |
| 953 DCHECK(resource); |
| 954 resource->read_lock_fences_enabled = true; |
| 955 } |
| 956 |
| 950 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( | 957 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( |
| 951 ResourceProvider* resource_provider, | 958 ResourceProvider* resource_provider, |
| 952 ResourceId resource_id) | 959 ResourceId resource_id) |
| 953 : resource_provider_(resource_provider), | 960 : resource_provider_(resource_provider), |
| 954 resource_id_(resource_id), | 961 resource_id_(resource_id), |
| 955 resource_(resource_provider->LockForRead(resource_id)) { | 962 resource_(resource_provider->LockForRead(resource_id)) { |
| 956 DCHECK(resource_); | 963 DCHECK(resource_); |
| 957 } | 964 } |
| 958 | 965 |
| 959 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { | 966 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 GL_LINEAR, it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); | 1375 GL_LINEAR, it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE)); |
| 1369 } else { | 1376 } else { |
| 1370 resource = InsertResource( | 1377 resource = InsertResource( |
| 1371 local_id, Resource(0, it->size, Resource::DELEGATED, | 1378 local_id, Resource(0, it->size, Resource::DELEGATED, |
| 1372 it->mailbox_holder.texture_target, it->filter, 0, | 1379 it->mailbox_holder.texture_target, it->filter, 0, |
| 1373 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, | 1380 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, |
| 1374 TEXTURE_HINT_IMMUTABLE, it->format)); | 1381 TEXTURE_HINT_IMMUTABLE, it->format)); |
| 1375 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox, | 1382 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox, |
| 1376 it->mailbox_holder.texture_target, | 1383 it->mailbox_holder.texture_target, |
| 1377 it->mailbox_holder.sync_point); | 1384 it->mailbox_holder.sync_point); |
| 1385 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; |
| 1378 } | 1386 } |
| 1379 resource->child_id = child; | 1387 resource->child_id = child; |
| 1380 // Don't allocate a texture for a child. | 1388 // Don't allocate a texture for a child. |
| 1381 resource->allocated = true; | 1389 resource->allocated = true; |
| 1382 resource->imported_count = 1; | 1390 resource->imported_count = 1; |
| 1383 child_info.parent_to_child_map[local_id] = it->id; | 1391 child_info.parent_to_child_map[local_id] = it->id; |
| 1384 child_info.child_to_parent_map[it->id] = local_id; | 1392 child_info.child_to_parent_map[it->id] = local_id; |
| 1385 } | 1393 } |
| 1386 } | 1394 } |
| 1387 | 1395 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 continue; | 1431 continue; |
| 1424 | 1432 |
| 1425 Resource* resource = &map_iterator->second; | 1433 Resource* resource = &map_iterator->second; |
| 1426 | 1434 |
| 1427 CHECK_GE(resource->exported_count, returned.count); | 1435 CHECK_GE(resource->exported_count, returned.count); |
| 1428 resource->exported_count -= returned.count; | 1436 resource->exported_count -= returned.count; |
| 1429 resource->lost |= returned.lost; | 1437 resource->lost |= returned.lost; |
| 1430 if (resource->exported_count) | 1438 if (resource->exported_count) |
| 1431 continue; | 1439 continue; |
| 1432 | 1440 |
| 1433 // Need to wait for the current read lock fence to pass before we can | |
| 1434 // recycle this resource. | |
| 1435 if (resource->read_lock_fences_enabled) { | |
| 1436 if (current_read_lock_fence_.get()) | |
| 1437 current_read_lock_fence_->Set(); | |
| 1438 resource->read_lock_fence = current_read_lock_fence_; | |
| 1439 } | |
| 1440 | |
| 1441 if (returned.sync_point) { | 1441 if (returned.sync_point) { |
| 1442 DCHECK(!resource->has_shared_bitmap_id); | 1442 DCHECK(!resource->has_shared_bitmap_id); |
| 1443 if (resource->origin == Resource::INTERNAL) { | 1443 if (resource->origin == Resource::INTERNAL) { |
| 1444 DCHECK(resource->gl_id); | 1444 DCHECK(resource->gl_id); |
| 1445 gl->WaitSyncPointCHROMIUM(returned.sync_point); | 1445 gl->WaitSyncPointCHROMIUM(returned.sync_point); |
| 1446 } else { | 1446 } else { |
| 1447 DCHECK(!resource->gl_id); | 1447 DCHECK(!resource->gl_id); |
| 1448 resource->mailbox.set_sync_point(returned.sync_point); | 1448 resource->mailbox.set_sync_point(returned.sync_point); |
| 1449 } | 1449 } |
| 1450 } | 1450 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1475 Resource* source = GetResource(id); | 1475 Resource* source = GetResource(id); |
| 1476 DCHECK(!source->locked_for_write); | 1476 DCHECK(!source->locked_for_write); |
| 1477 DCHECK(!source->lock_for_read_count); | 1477 DCHECK(!source->lock_for_read_count); |
| 1478 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); | 1478 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); |
| 1479 DCHECK(source->allocated); | 1479 DCHECK(source->allocated); |
| 1480 resource->id = id; | 1480 resource->id = id; |
| 1481 resource->format = source->format; | 1481 resource->format = source->format; |
| 1482 resource->mailbox_holder.texture_target = source->target; | 1482 resource->mailbox_holder.texture_target = source->target; |
| 1483 resource->filter = source->filter; | 1483 resource->filter = source->filter; |
| 1484 resource->size = source->size; | 1484 resource->size = source->size; |
| 1485 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; |
| 1485 resource->is_repeated = (source->wrap_mode == GL_REPEAT); | 1486 resource->is_repeated = (source->wrap_mode == GL_REPEAT); |
| 1486 | 1487 |
| 1487 if (source->type == RESOURCE_TYPE_BITMAP) { | 1488 if (source->type == RESOURCE_TYPE_BITMAP) { |
| 1488 resource->mailbox_holder.mailbox = source->shared_bitmap_id; | 1489 resource->mailbox_holder.mailbox = source->shared_bitmap_id; |
| 1489 resource->is_software = true; | 1490 resource->is_software = true; |
| 1490 } else if (!source->mailbox.IsValid()) { | 1491 } else if (!source->mailbox.IsValid()) { |
| 1491 LazyCreate(source); | 1492 LazyCreate(source); |
| 1492 DCHECK(source->gl_id); | 1493 DCHECK(source->gl_id); |
| 1493 DCHECK(source->origin == Resource::INTERNAL); | 1494 DCHECK(source->origin == Resource::INTERNAL); |
| 1494 if (source->image_id) { | 1495 if (source->image_id) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 | 1545 |
| 1545 DCHECK(!resource.locked_for_write); | 1546 DCHECK(!resource.locked_for_write); |
| 1546 DCHECK(child_info->parent_to_child_map.count(local_id)); | 1547 DCHECK(child_info->parent_to_child_map.count(local_id)); |
| 1547 | 1548 |
| 1548 ResourceId child_id = child_info->parent_to_child_map[local_id]; | 1549 ResourceId child_id = child_info->parent_to_child_map[local_id]; |
| 1549 DCHECK(child_info->child_to_parent_map.count(child_id)); | 1550 DCHECK(child_info->child_to_parent_map.count(child_id)); |
| 1550 | 1551 |
| 1551 bool is_lost = | 1552 bool is_lost = |
| 1552 resource.lost || | 1553 resource.lost || |
| 1553 (resource.type == RESOURCE_TYPE_GL_TEXTURE && lost_output_surface_); | 1554 (resource.type == RESOURCE_TYPE_GL_TEXTURE && lost_output_surface_); |
| 1554 if (resource.exported_count > 0 || resource.lock_for_read_count > 0) { | 1555 if (resource.exported_count > 0 || resource.lock_for_read_count > 0 || |
| 1556 !ReadLockFenceHasPassed(&resource)) { |
| 1555 if (style != FOR_SHUTDOWN) { | 1557 if (style != FOR_SHUTDOWN) { |
| 1556 // Defer this until we receive the resource back from the parent or | 1558 // Defer this until we receive the resource back from the parent or |
| 1557 // the read lock is released. | 1559 // the read lock is released. |
| 1558 resource.marked_for_deletion = true; | 1560 resource.marked_for_deletion = true; |
| 1559 continue; | 1561 continue; |
| 1560 } | 1562 } |
| 1561 | 1563 |
| 1562 // We still have an exported_count, so we'll have to lose it. | 1564 // We still have an exported_count, so we'll have to lose it. |
| 1563 is_lost = true; | 1565 is_lost = true; |
| 1564 } | 1566 } |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 } | 2049 } |
| 2048 | 2050 |
| 2049 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2051 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
| 2050 ContextProvider* context_provider = | 2052 ContextProvider* context_provider = |
| 2051 worker_context ? output_surface_->worker_context_provider() | 2053 worker_context ? output_surface_->worker_context_provider() |
| 2052 : output_surface_->context_provider(); | 2054 : output_surface_->context_provider(); |
| 2053 return context_provider ? context_provider->GrContext() : NULL; | 2055 return context_provider ? context_provider->GrContext() : NULL; |
| 2054 } | 2056 } |
| 2055 | 2057 |
| 2056 } // namespace cc | 2058 } // namespace cc |
| OLD | NEW |