| 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/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 gl_upload_query_id(0), | 210 gl_upload_query_id(0), |
| 211 gl_read_lock_query_id(0), | 211 gl_read_lock_query_id(0), |
| 212 pixels(NULL), | 212 pixels(NULL), |
| 213 lock_for_read_count(0), | 213 lock_for_read_count(0), |
| 214 imported_count(0), | 214 imported_count(0), |
| 215 exported_count(0), | 215 exported_count(0), |
| 216 dirty_image(false), | 216 dirty_image(false), |
| 217 locked_for_write(false), | 217 locked_for_write(false), |
| 218 lost(false), | 218 lost(false), |
| 219 marked_for_deletion(false), | 219 marked_for_deletion(false), |
| 220 pending_set_pixels(false), | |
| 221 set_pixels_completion_forced(false), | |
| 222 allocated(false), | 220 allocated(false), |
| 223 read_lock_fences_enabled(false), | 221 read_lock_fences_enabled(false), |
| 224 has_shared_bitmap_id(false), | 222 has_shared_bitmap_id(false), |
| 225 read_lock_fence(NULL), | 223 read_lock_fence(NULL), |
| 226 size(size), | 224 size(size), |
| 227 origin(origin), | 225 origin(origin), |
| 228 target(target), | 226 target(target), |
| 229 original_filter(filter), | 227 original_filter(filter), |
| 230 filter(filter), | 228 filter(filter), |
| 231 image_id(0), | 229 image_id(0), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 253 gl_upload_query_id(0), | 251 gl_upload_query_id(0), |
| 254 gl_read_lock_query_id(0), | 252 gl_read_lock_query_id(0), |
| 255 pixels(pixels), | 253 pixels(pixels), |
| 256 lock_for_read_count(0), | 254 lock_for_read_count(0), |
| 257 imported_count(0), | 255 imported_count(0), |
| 258 exported_count(0), | 256 exported_count(0), |
| 259 dirty_image(false), | 257 dirty_image(false), |
| 260 locked_for_write(false), | 258 locked_for_write(false), |
| 261 lost(false), | 259 lost(false), |
| 262 marked_for_deletion(false), | 260 marked_for_deletion(false), |
| 263 pending_set_pixels(false), | |
| 264 set_pixels_completion_forced(false), | |
| 265 allocated(false), | 261 allocated(false), |
| 266 read_lock_fences_enabled(false), | 262 read_lock_fences_enabled(false), |
| 267 has_shared_bitmap_id(!!bitmap), | 263 has_shared_bitmap_id(!!bitmap), |
| 268 read_lock_fence(NULL), | 264 read_lock_fence(NULL), |
| 269 size(size), | 265 size(size), |
| 270 origin(origin), | 266 origin(origin), |
| 271 target(0), | 267 target(0), |
| 272 original_filter(filter), | 268 original_filter(filter), |
| 273 filter(filter), | 269 filter(filter), |
| 274 image_id(0), | 270 image_id(0), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 297 gl_upload_query_id(0), | 293 gl_upload_query_id(0), |
| 298 gl_read_lock_query_id(0), | 294 gl_read_lock_query_id(0), |
| 299 pixels(NULL), | 295 pixels(NULL), |
| 300 lock_for_read_count(0), | 296 lock_for_read_count(0), |
| 301 imported_count(0), | 297 imported_count(0), |
| 302 exported_count(0), | 298 exported_count(0), |
| 303 dirty_image(false), | 299 dirty_image(false), |
| 304 locked_for_write(false), | 300 locked_for_write(false), |
| 305 lost(false), | 301 lost(false), |
| 306 marked_for_deletion(false), | 302 marked_for_deletion(false), |
| 307 pending_set_pixels(false), | |
| 308 set_pixels_completion_forced(false), | |
| 309 allocated(false), | 303 allocated(false), |
| 310 read_lock_fences_enabled(false), | 304 read_lock_fences_enabled(false), |
| 311 has_shared_bitmap_id(true), | 305 has_shared_bitmap_id(true), |
| 312 read_lock_fence(NULL), | 306 read_lock_fence(NULL), |
| 313 size(size), | 307 size(size), |
| 314 origin(origin), | 308 origin(origin), |
| 315 target(0), | 309 target(0), |
| 316 original_filter(filter), | 310 original_filter(filter), |
| 317 filter(filter), | 311 filter(filter), |
| 318 image_id(0), | 312 image_id(0), |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 false); | 532 false); |
| 539 } | 533 } |
| 540 | 534 |
| 541 void ResourceProvider::DeleteResource(ResourceId id) { | 535 void ResourceProvider::DeleteResource(ResourceId id) { |
| 542 DCHECK(thread_checker_.CalledOnValidThread()); | 536 DCHECK(thread_checker_.CalledOnValidThread()); |
| 543 ResourceMap::iterator it = resources_.find(id); | 537 ResourceMap::iterator it = resources_.find(id); |
| 544 CHECK(it != resources_.end()); | 538 CHECK(it != resources_.end()); |
| 545 Resource* resource = &it->second; | 539 Resource* resource = &it->second; |
| 546 DCHECK(!resource->marked_for_deletion); | 540 DCHECK(!resource->marked_for_deletion); |
| 547 DCHECK_EQ(resource->imported_count, 0); | 541 DCHECK_EQ(resource->imported_count, 0); |
| 548 DCHECK(resource->pending_set_pixels || !resource->locked_for_write); | 542 DCHECK(!resource->locked_for_write); |
| 549 | 543 |
| 550 if (resource->exported_count > 0 || resource->lock_for_read_count > 0 || | 544 if (resource->exported_count > 0 || resource->lock_for_read_count > 0 || |
| 551 !ReadLockFenceHasPassed(resource)) { | 545 !ReadLockFenceHasPassed(resource)) { |
| 552 resource->marked_for_deletion = true; | 546 resource->marked_for_deletion = true; |
| 553 return; | 547 return; |
| 554 } else { | 548 } else { |
| 555 DeleteResourceInternal(it, NORMAL); | 549 DeleteResourceInternal(it, NORMAL); |
| 556 } | 550 } |
| 557 } | 551 } |
| 558 | 552 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 DCHECK_EQ(RGBA_8888, resource->format); | 656 DCHECK_EQ(RGBA_8888, resource->format); |
| 663 SkImageInfo source_info = | 657 SkImageInfo source_info = |
| 664 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 658 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
| 665 size_t image_stride = image_size.width() * 4; | 659 size_t image_stride = image_size.width() * 4; |
| 666 | 660 |
| 667 ScopedWriteLockSoftware lock(this, id); | 661 ScopedWriteLockSoftware lock(this, id); |
| 668 SkCanvas dest(lock.sk_bitmap()); | 662 SkCanvas dest(lock.sk_bitmap()); |
| 669 dest.writePixels(source_info, image, image_stride, 0, 0); | 663 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 670 } else { | 664 } else { |
| 671 DCHECK(resource->gl_id); | 665 DCHECK(resource->gl_id); |
| 672 DCHECK(!resource->pending_set_pixels); | |
| 673 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 666 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 674 GLES2Interface* gl = ContextGL(); | 667 GLES2Interface* gl = ContextGL(); |
| 675 DCHECK(gl); | 668 DCHECK(gl); |
| 676 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 669 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 677 | 670 |
| 678 if (resource->format == ETC1) { | 671 if (resource->format == ETC1) { |
| 679 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); | 672 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); |
| 680 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), | 673 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), |
| 681 image_size.width(), image_size.height(), 0, | 674 image_size.width(), image_size.height(), 0, |
| 682 image_bytes, image); | 675 image_bytes, image); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 700 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { | 693 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { |
| 701 DCHECK(thread_checker_.CalledOnValidThread()); | 694 DCHECK(thread_checker_.CalledOnValidThread()); |
| 702 DCHECK(id); | 695 DCHECK(id); |
| 703 ResourceMap::iterator it = resources_.find(id); | 696 ResourceMap::iterator it = resources_.find(id); |
| 704 DCHECK(it != resources_.end()); | 697 DCHECK(it != resources_.end()); |
| 705 return &it->second; | 698 return &it->second; |
| 706 } | 699 } |
| 707 | 700 |
| 708 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { | 701 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
| 709 Resource* resource = GetResource(id); | 702 Resource* resource = GetResource(id); |
| 710 DCHECK(!resource->locked_for_write || | 703 DCHECK(!resource->locked_for_write) << "locked for write: " |
| 711 resource->set_pixels_completion_forced) << | 704 << resource->locked_for_write; |
| 712 "locked for write: " << resource->locked_for_write << | |
| 713 " pixels completion forced: " << resource->set_pixels_completion_forced; | |
| 714 DCHECK_EQ(resource->exported_count, 0); | 705 DCHECK_EQ(resource->exported_count, 0); |
| 715 // Uninitialized! Call SetPixels or LockForWrite first. | 706 // Uninitialized! Call SetPixels or LockForWrite first. |
| 716 DCHECK(resource->allocated); | 707 DCHECK(resource->allocated); |
| 717 | 708 |
| 718 LazyCreate(resource); | 709 LazyCreate(resource); |
| 719 | 710 |
| 720 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) { | 711 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) { |
| 721 DCHECK(resource->origin != Resource::INTERNAL); | 712 DCHECK(resource->origin != Resource::INTERNAL); |
| 722 DCHECK(resource->mailbox.IsTexture()); | 713 DCHECK(resource->mailbox.IsTexture()); |
| 723 | 714 |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 child_info->return_callback.Run(to_return, | 1451 child_info->return_callback.Run(to_return, |
| 1461 blocking_main_thread_task_runner_); | 1452 blocking_main_thread_task_runner_); |
| 1462 | 1453 |
| 1463 if (child_info->marked_for_deletion && | 1454 if (child_info->marked_for_deletion && |
| 1464 child_info->parent_to_child_map.empty()) { | 1455 child_info->parent_to_child_map.empty()) { |
| 1465 DCHECK(child_info->child_to_parent_map.empty()); | 1456 DCHECK(child_info->child_to_parent_map.empty()); |
| 1466 children_.erase(child_it); | 1457 children_.erase(child_it); |
| 1467 } | 1458 } |
| 1468 } | 1459 } |
| 1469 | 1460 |
| 1470 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | |
| 1471 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1472 "ResourceProvider::AcquirePixelBuffer"); | |
| 1473 | |
| 1474 Resource* resource = GetResource(id); | |
| 1475 DCHECK(resource->origin == Resource::INTERNAL); | |
| 1476 DCHECK_EQ(resource->exported_count, 0); | |
| 1477 DCHECK(!resource->image_id); | |
| 1478 DCHECK_NE(ETC1, resource->format); | |
| 1479 | |
| 1480 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | |
| 1481 GLES2Interface* gl = ContextGL(); | |
| 1482 DCHECK(gl); | |
| 1483 if (!resource->gl_pixel_buffer_id) | |
| 1484 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | |
| 1485 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
| 1486 resource->gl_pixel_buffer_id); | |
| 1487 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( | |
| 1488 resource->size, resource->format); | |
| 1489 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, resource_bytes, NULL, | |
| 1490 GL_DYNAMIC_DRAW); | |
| 1491 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1492 } | |
| 1493 | |
| 1494 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | |
| 1495 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1496 "ResourceProvider::ReleasePixelBuffer"); | |
| 1497 | |
| 1498 Resource* resource = GetResource(id); | |
| 1499 DCHECK(resource->origin == Resource::INTERNAL); | |
| 1500 DCHECK_EQ(resource->exported_count, 0); | |
| 1501 DCHECK(!resource->image_id); | |
| 1502 | |
| 1503 // The pixel buffer can be released while there is a pending "set pixels" | |
| 1504 // if completion has been forced. Any shared memory associated with this | |
| 1505 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM | |
| 1506 // command has been processed on the service side. It is also safe to | |
| 1507 // reuse any query id associated with this resource before they complete | |
| 1508 // as each new query has a unique submit count. | |
| 1509 if (resource->pending_set_pixels) { | |
| 1510 DCHECK(resource->set_pixels_completion_forced); | |
| 1511 resource->pending_set_pixels = false; | |
| 1512 resource->locked_for_write = false; | |
| 1513 } | |
| 1514 | |
| 1515 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | |
| 1516 if (!resource->gl_pixel_buffer_id) | |
| 1517 return; | |
| 1518 GLES2Interface* gl = ContextGL(); | |
| 1519 DCHECK(gl); | |
| 1520 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
| 1521 resource->gl_pixel_buffer_id); | |
| 1522 gl->BufferData( | |
| 1523 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); | |
| 1524 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1525 } | |
| 1526 | |
| 1527 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id, int* stride) { | |
| 1528 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1529 "ResourceProvider::MapPixelBuffer"); | |
| 1530 | |
| 1531 Resource* resource = GetResource(id); | |
| 1532 DCHECK(resource->origin == Resource::INTERNAL); | |
| 1533 DCHECK_EQ(resource->exported_count, 0); | |
| 1534 DCHECK(!resource->image_id); | |
| 1535 | |
| 1536 *stride = 0; | |
| 1537 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | |
| 1538 GLES2Interface* gl = ContextGL(); | |
| 1539 DCHECK(gl); | |
| 1540 DCHECK(resource->gl_pixel_buffer_id); | |
| 1541 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
| 1542 resource->gl_pixel_buffer_id); | |
| 1543 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( | |
| 1544 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | |
| 1545 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1546 // Buffer is required to be 4-byte aligned. | |
| 1547 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); | |
| 1548 return image; | |
| 1549 } | |
| 1550 | |
| 1551 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | |
| 1552 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1553 "ResourceProvider::UnmapPixelBuffer"); | |
| 1554 | |
| 1555 Resource* resource = GetResource(id); | |
| 1556 DCHECK(resource->origin == Resource::INTERNAL); | |
| 1557 DCHECK_EQ(resource->exported_count, 0); | |
| 1558 DCHECK(!resource->image_id); | |
| 1559 | |
| 1560 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | |
| 1561 GLES2Interface* gl = ContextGL(); | |
| 1562 DCHECK(gl); | |
| 1563 DCHECK(resource->gl_pixel_buffer_id); | |
| 1564 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
| 1565 resource->gl_pixel_buffer_id); | |
| 1566 gl->UnmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | |
| 1567 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1568 } | |
| 1569 | |
| 1570 GLenum ResourceProvider::BindForSampling(ResourceId resource_id, | 1461 GLenum ResourceProvider::BindForSampling(ResourceId resource_id, |
| 1571 GLenum unit, | 1462 GLenum unit, |
| 1572 GLenum filter) { | 1463 GLenum filter) { |
| 1573 DCHECK(thread_checker_.CalledOnValidThread()); | 1464 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1574 GLES2Interface* gl = ContextGL(); | 1465 GLES2Interface* gl = ContextGL(); |
| 1575 ResourceMap::iterator it = resources_.find(resource_id); | 1466 ResourceMap::iterator it = resources_.find(resource_id); |
| 1576 DCHECK(it != resources_.end()); | 1467 DCHECK(it != resources_.end()); |
| 1577 Resource* resource = &it->second; | 1468 Resource* resource = &it->second; |
| 1578 DCHECK(resource->lock_for_read_count); | 1469 DCHECK(resource->lock_for_read_count); |
| 1579 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); | 1470 DCHECK(!resource->locked_for_write); |
| 1580 | 1471 |
| 1581 ScopedSetActiveTexture scoped_active_tex(gl, unit); | 1472 ScopedSetActiveTexture scoped_active_tex(gl, unit); |
| 1582 GLenum target = resource->target; | 1473 GLenum target = resource->target; |
| 1583 gl->BindTexture(target, resource->gl_id); | 1474 gl->BindTexture(target, resource->gl_id); |
| 1584 if (filter != resource->filter) { | 1475 if (filter != resource->filter) { |
| 1585 gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); | 1476 gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); |
| 1586 gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); | 1477 gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); |
| 1587 resource->filter = filter; | 1478 resource->filter = filter; |
| 1588 } | 1479 } |
| 1589 | 1480 |
| 1590 if (resource->image_id && resource->dirty_image) | 1481 if (resource->image_id && resource->dirty_image) |
| 1591 BindImageForSampling(resource); | 1482 BindImageForSampling(resource); |
| 1592 | 1483 |
| 1593 return target; | 1484 return target; |
| 1594 } | 1485 } |
| 1595 | 1486 |
| 1596 void ResourceProvider::BeginSetPixels(ResourceId id) { | |
| 1597 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1598 "ResourceProvider::BeginSetPixels"); | |
| 1599 | |
| 1600 Resource* resource = GetResource(id); | |
| 1601 DCHECK(!resource->pending_set_pixels); | |
| 1602 | |
| 1603 LazyCreate(resource); | |
| 1604 DCHECK(resource->origin == Resource::INTERNAL); | |
| 1605 DCHECK(resource->gl_id || resource->allocated); | |
| 1606 DCHECK(ReadLockFenceHasPassed(resource)); | |
| 1607 DCHECK(!resource->image_id); | |
| 1608 | |
| 1609 bool allocate = !resource->allocated; | |
| 1610 resource->allocated = true; | |
| 1611 LockForWrite(id); | |
| 1612 | |
| 1613 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | |
| 1614 DCHECK(resource->gl_id); | |
| 1615 GLES2Interface* gl = ContextGL(); | |
| 1616 DCHECK(gl); | |
| 1617 DCHECK(resource->gl_pixel_buffer_id); | |
| 1618 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | |
| 1619 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | |
| 1620 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
| 1621 resource->gl_pixel_buffer_id); | |
| 1622 if (!resource->gl_upload_query_id) | |
| 1623 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); | |
| 1624 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | |
| 1625 resource->gl_upload_query_id); | |
| 1626 if (allocate) { | |
| 1627 gl->AsyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | |
| 1628 0, /* level */ | |
| 1629 GLInternalFormat(resource->format), | |
| 1630 resource->size.width(), | |
| 1631 resource->size.height(), | |
| 1632 0, /* border */ | |
| 1633 GLDataFormat(resource->format), | |
| 1634 GLDataType(resource->format), | |
| 1635 NULL); | |
| 1636 } else { | |
| 1637 gl->AsyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | |
| 1638 0, /* level */ | |
| 1639 0, /* x */ | |
| 1640 0, /* y */ | |
| 1641 resource->size.width(), | |
| 1642 resource->size.height(), | |
| 1643 GLDataFormat(resource->format), | |
| 1644 GLDataType(resource->format), | |
| 1645 NULL); | |
| 1646 } | |
| 1647 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | |
| 1648 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1649 | |
| 1650 resource->pending_set_pixels = true; | |
| 1651 resource->set_pixels_completion_forced = false; | |
| 1652 } | |
| 1653 | |
| 1654 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | |
| 1655 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1656 "ResourceProvider::ForceSetPixelsToComplete"); | |
| 1657 | |
| 1658 Resource* resource = GetResource(id); | |
| 1659 | |
| 1660 DCHECK(resource->locked_for_write); | |
| 1661 DCHECK(resource->pending_set_pixels); | |
| 1662 DCHECK(!resource->set_pixels_completion_forced); | |
| 1663 | |
| 1664 if (resource->gl_id) { | |
| 1665 GLES2Interface* gl = ContextGL(); | |
| 1666 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | |
| 1667 gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D); | |
| 1668 gl->BindTexture(GL_TEXTURE_2D, 0); | |
| 1669 } | |
| 1670 | |
| 1671 resource->set_pixels_completion_forced = true; | |
| 1672 } | |
| 1673 | |
| 1674 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { | |
| 1675 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 1676 "ResourceProvider::DidSetPixelsComplete"); | |
| 1677 | |
| 1678 Resource* resource = GetResource(id); | |
| 1679 | |
| 1680 DCHECK(resource->locked_for_write); | |
| 1681 DCHECK(resource->pending_set_pixels); | |
| 1682 | |
| 1683 if (resource->gl_id) { | |
| 1684 GLES2Interface* gl = ContextGL(); | |
| 1685 DCHECK(gl); | |
| 1686 DCHECK(resource->gl_upload_query_id); | |
| 1687 GLuint complete = 1; | |
| 1688 gl->GetQueryObjectuivEXT( | |
| 1689 resource->gl_upload_query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete); | |
| 1690 if (!complete) | |
| 1691 return false; | |
| 1692 } | |
| 1693 | |
| 1694 resource->pending_set_pixels = false; | |
| 1695 UnlockForWrite(resource); | |
| 1696 | |
| 1697 // Async set pixels commands are not necessarily processed in-sequence with | |
| 1698 // drawing commands. Read lock fences are required to ensure that async | |
| 1699 // commands don't access the resource while used for drawing. | |
| 1700 resource->read_lock_fences_enabled = true; | |
| 1701 | |
| 1702 return true; | |
| 1703 } | |
| 1704 | |
| 1705 void ResourceProvider::CreateForTesting(ResourceId id) { | 1487 void ResourceProvider::CreateForTesting(ResourceId id) { |
| 1706 LazyCreate(GetResource(id)); | 1488 LazyCreate(GetResource(id)); |
| 1707 } | 1489 } |
| 1708 | 1490 |
| 1709 GLenum ResourceProvider::TargetForTesting(ResourceId id) { | 1491 GLenum ResourceProvider::TargetForTesting(ResourceId id) { |
| 1710 Resource* resource = GetResource(id); | 1492 Resource* resource = GetResource(id); |
| 1711 return resource->target; | 1493 return resource->target; |
| 1712 } | 1494 } |
| 1713 | 1495 |
| 1714 void ResourceProvider::LazyCreate(Resource* resource) { | 1496 void ResourceProvider::LazyCreate(Resource* resource) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1878 const int kImportance = 2; | 1660 const int kImportance = 2; |
| 1879 pmd->CreateSharedGlobalAllocatorDump(guid); | 1661 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 1880 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1662 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 1881 } | 1663 } |
| 1882 } | 1664 } |
| 1883 | 1665 |
| 1884 return true; | 1666 return true; |
| 1885 } | 1667 } |
| 1886 | 1668 |
| 1887 } // namespace cc | 1669 } // namespace cc |
| OLD | NEW |