Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 const double kTextureUploadTickRate = 0.004; | 35 const double kTextureUploadTickRate = 0.004; |
| 36 | 36 |
| 37 GLenum TextureToStorageFormat(ResourceFormat format) { | 37 GLenum TextureToStorageFormat(ResourceFormat format) { |
| 38 GLenum storage_format = GL_RGBA8_OES; | 38 GLenum storage_format = GL_RGBA8_OES; |
| 39 switch (format) { | 39 switch (format) { |
| 40 case RGBA_8888: | 40 case RGBA_8888: |
| 41 break; | 41 break; |
| 42 case BGRA_8888: | 42 case BGRA_8888: |
| 43 storage_format = GL_BGRA8_EXT; | 43 storage_format = GL_BGRA8_EXT; |
| 44 break; | 44 break; |
| 45 case ETC1: | |
| 45 case RGBA_4444: | 46 case RGBA_4444: |
| 46 case LUMINANCE_8: | 47 case LUMINANCE_8: |
| 47 case RGB_565: | 48 case RGB_565: |
| 48 NOTREACHED(); | 49 NOTREACHED(); |
| 49 break; | 50 break; |
| 50 } | 51 } |
| 51 | 52 |
| 52 return storage_format; | 53 return storage_format; |
| 53 } | 54 } |
| 54 | 55 |
| 55 bool IsFormatSupportedForStorage(ResourceFormat format) { | 56 bool IsFormatSupportedForStorage(ResourceFormat format) { |
| 56 switch (format) { | 57 switch (format) { |
| 57 case RGBA_8888: | 58 case RGBA_8888: |
| 58 case BGRA_8888: | 59 case BGRA_8888: |
| 59 return true; | 60 return true; |
| 61 case ETC1: | |
| 60 case RGBA_4444: | 62 case RGBA_4444: |
| 61 case LUMINANCE_8: | 63 case LUMINANCE_8: |
| 62 case RGB_565: | 64 case RGB_565: |
| 63 return false; | 65 return false; |
| 64 } | 66 } |
| 65 return false; | 67 return false; |
| 66 } | 68 } |
| 67 | 69 |
| 68 class ScopedSetActiveTexture { | 70 class ScopedSetActiveTexture { |
| 69 public: | 71 public: |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 default_resource_type_ = GLTexture; | 798 default_resource_type_ = GLTexture; |
| 797 | 799 |
| 798 const ContextProvider::Capabilities& caps = | 800 const ContextProvider::Capabilities& caps = |
| 799 output_surface_->context_provider()->ContextCapabilities(); | 801 output_surface_->context_provider()->ContextCapabilities(); |
| 800 | 802 |
| 801 bool use_map_sub = caps.map_sub; | 803 bool use_map_sub = caps.map_sub; |
| 802 bool use_bgra = caps.texture_format_bgra8888; | 804 bool use_bgra = caps.texture_format_bgra8888; |
| 803 use_texture_storage_ext_ = caps.texture_storage; | 805 use_texture_storage_ext_ = caps.texture_storage; |
| 804 use_shallow_flush_ = caps.shallow_flush; | 806 use_shallow_flush_ = caps.shallow_flush; |
| 805 use_texture_usage_hint_ = caps.texture_usage; | 807 use_texture_usage_hint_ = caps.texture_usage; |
| 808 use_compressed_texture_etc1_ = caps.texture_format_etc1; | |
| 806 | 809 |
| 807 texture_uploader_ = | 810 texture_uploader_ = TextureUploader::Create( |
| 808 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 811 context3d, use_map_sub, use_shallow_flush_, use_compressed_texture_etc1_); |
| 809 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 812 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
| 810 &max_texture_size_)); | 813 &max_texture_size_)); |
| 811 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 814 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
| 812 | 815 |
| 813 return true; | 816 return true; |
| 814 } | 817 } |
| 815 | 818 |
| 816 void ResourceProvider::CleanUpGLIfNeeded() { | 819 void ResourceProvider::CleanUpGLIfNeeded() { |
| 817 WebGraphicsContext3D* context3d = Context3d(); | 820 WebGraphicsContext3D* context3d = Context3d(); |
| 818 if (default_resource_type_ != GLTexture) { | 821 if (default_resource_type_ != GLTexture) { |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 | 1206 |
| 1204 if (!to_return.empty()) | 1207 if (!to_return.empty()) |
| 1205 child_info->return_callback.Run(to_return); | 1208 child_info->return_callback.Run(to_return); |
| 1206 } | 1209 } |
| 1207 | 1210 |
| 1208 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 1211 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
| 1209 Resource* resource = GetResource(id); | 1212 Resource* resource = GetResource(id); |
| 1210 DCHECK(!resource->external); | 1213 DCHECK(!resource->external); |
| 1211 DCHECK_EQ(resource->exported_count, 0); | 1214 DCHECK_EQ(resource->exported_count, 0); |
| 1212 DCHECK(!resource->image_id); | 1215 DCHECK(!resource->image_id); |
| 1216 DCHECK_NE(ETC1, resource->format); | |
| 1213 | 1217 |
| 1214 if (resource->type == GLTexture) { | 1218 if (resource->type == GLTexture) { |
| 1215 WebGraphicsContext3D* context3d = Context3d(); | 1219 WebGraphicsContext3D* context3d = Context3d(); |
| 1216 DCHECK(context3d); | 1220 DCHECK(context3d); |
| 1217 if (!resource->gl_pixel_buffer_id) | 1221 if (!resource->gl_pixel_buffer_id) |
| 1218 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 1222 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
| 1219 context3d->bindBuffer( | 1223 context3d->bindBuffer( |
| 1220 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1224 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1221 resource->gl_pixel_buffer_id); | 1225 resource->gl_pixel_buffer_id); |
| 1222 unsigned bytes_per_pixel = BytesPerPixel(resource->format); | 1226 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; |
| 1223 context3d->bufferData( | 1227 context3d->bufferData( |
| 1224 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1228 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1225 resource->size.height() * RoundUp(bytes_per_pixel | 1229 resource->size.height() * RoundUp(bytes_per_pixel |
| 1226 * resource->size.width(), 4u), | 1230 * resource->size.width(), 4u), |
| 1227 NULL, | 1231 NULL, |
| 1228 GL_DYNAMIC_DRAW); | 1232 GL_DYNAMIC_DRAW); |
| 1229 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1233 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1230 } | 1234 } |
| 1231 | 1235 |
| 1232 if (resource->pixels) { | 1236 if (resource->pixels) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1360 | 1364 |
| 1361 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1365 void ResourceProvider::BeginSetPixels(ResourceId id) { |
| 1362 Resource* resource = GetResource(id); | 1366 Resource* resource = GetResource(id); |
| 1363 DCHECK(!resource->pending_set_pixels); | 1367 DCHECK(!resource->pending_set_pixels); |
| 1364 | 1368 |
| 1365 LazyCreate(resource); | 1369 LazyCreate(resource); |
| 1366 DCHECK(resource->gl_id || resource->allocated); | 1370 DCHECK(resource->gl_id || resource->allocated); |
| 1367 DCHECK(ReadLockFenceHasPassed(resource)); | 1371 DCHECK(ReadLockFenceHasPassed(resource)); |
| 1368 DCHECK(!resource->image_id); | 1372 DCHECK(!resource->image_id); |
| 1369 | 1373 |
| 1374 gfx::Size& size = resource->size; | |
|
aelias_OOO_until_Jul13
2013/10/23 19:54:07
Please delete the "&", it doesn't look like you're
powei
2013/10/23 22:20:07
Done.
| |
| 1370 bool allocate = !resource->allocated; | 1375 bool allocate = !resource->allocated; |
| 1371 resource->allocated = true; | 1376 resource->allocated = true; |
| 1372 LockForWrite(id); | 1377 LockForWrite(id); |
| 1373 | 1378 |
| 1374 if (resource->gl_id) { | 1379 if (resource->gl_id) { |
| 1375 WebGraphicsContext3D* context3d = Context3d(); | 1380 WebGraphicsContext3D* context3d = Context3d(); |
| 1376 DCHECK(context3d); | 1381 DCHECK(context3d); |
| 1377 DCHECK(resource->gl_pixel_buffer_id); | 1382 DCHECK(resource->gl_pixel_buffer_id); |
| 1378 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 1383 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 1379 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1384 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1380 context3d->bindBuffer( | 1385 context3d->bindBuffer( |
| 1381 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1386 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1382 resource->gl_pixel_buffer_id); | 1387 resource->gl_pixel_buffer_id); |
| 1383 if (!resource->gl_upload_query_id) | 1388 if (!resource->gl_upload_query_id) |
| 1384 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1389 resource->gl_upload_query_id = context3d->createQueryEXT(); |
| 1385 context3d->beginQueryEXT( | 1390 context3d->beginQueryEXT( |
| 1386 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1391 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
| 1387 resource->gl_upload_query_id); | 1392 resource->gl_upload_query_id); |
| 1388 if (allocate) { | 1393 if (allocate) { |
|
no sievers
2013/10/23 20:33:15
I think the change in here is wrong. Don't the UI
powei
2013/10/23 22:20:07
Done. Removed. You're right. I got careless and
| |
| 1389 context3d->asyncTexImage2DCHROMIUM( | 1394 if (resource->format == ETC1) { |
| 1390 GL_TEXTURE_2D, | 1395 DCHECK(use_compressed_texture_etc1_); |
| 1391 0, /* level */ | 1396 DCHECK_EQ(0, size.width() % 4); |
| 1392 GLInternalFormat(resource->format), | 1397 DCHECK_EQ(0, size.height() % 4); |
| 1393 resource->size.width(), | 1398 context3d->compressedTexImage2D( |
| 1394 resource->size.height(), | 1399 GL_TEXTURE_2D, |
| 1395 0, /* border */ | 1400 0, /* level */ |
| 1396 GLDataFormat(resource->format), | 1401 GLInternalFormat(resource->format), |
| 1397 GLDataType(resource->format), | 1402 size.width(), |
| 1398 NULL); | 1403 size.height(), |
| 1404 0, /* border */ | |
| 1405 cc::Resource::MemorySizeBytes(size, resource->format), | |
| 1406 NULL); | |
| 1407 } else { | |
| 1408 context3d->asyncTexImage2DCHROMIUM( | |
| 1409 GL_TEXTURE_2D, | |
| 1410 0, /* level */ | |
| 1411 GLInternalFormat(resource->format), | |
| 1412 size.width(), | |
| 1413 size.height(), | |
| 1414 0, /* border */ | |
| 1415 GLDataFormat(resource->format), | |
| 1416 GLDataType(resource->format), | |
| 1417 NULL); | |
| 1418 } | |
| 1399 } else { | 1419 } else { |
| 1400 context3d->asyncTexSubImage2DCHROMIUM( | 1420 if (resource->format == ETC1) { |
| 1401 GL_TEXTURE_2D, | 1421 DCHECK(use_compressed_texture_etc1_); |
| 1402 0, /* level */ | 1422 DCHECK_EQ(0, size.width() % 4); |
| 1403 0, /* x */ | 1423 DCHECK_EQ(0, size.height() % 4); |
| 1404 0, /* y */ | 1424 context3d->compressedTexSubImage2D( |
| 1405 resource->size.width(), | 1425 GL_TEXTURE_2D, |
| 1406 resource->size.height(), | 1426 0, /* level */ |
| 1407 GLDataFormat(resource->format), | 1427 0, /* x */ |
| 1408 GLDataType(resource->format), | 1428 0, /* y */ |
| 1409 NULL); | 1429 size.width(), |
| 1430 size.height(), | |
| 1431 GLDataFormat(resource->format), | |
| 1432 cc::Resource::MemorySizeBytes(size, resource->format), | |
| 1433 NULL); | |
| 1434 } else { | |
| 1435 context3d->asyncTexSubImage2DCHROMIUM( | |
| 1436 GL_TEXTURE_2D, | |
| 1437 0, /* level */ | |
| 1438 0, /* x */ | |
| 1439 0, /* y */ | |
| 1440 size.width(), | |
| 1441 size.height(), | |
| 1442 GLDataFormat(resource->format), | |
| 1443 GLDataType(resource->format), | |
| 1444 NULL); | |
| 1445 } | |
| 1410 } | 1446 } |
| 1411 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1447 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
| 1412 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1448 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1413 } | 1449 } |
| 1414 | 1450 |
| 1415 if (resource->pixels) { | 1451 if (resource->pixels) { |
| 1416 DCHECK(!resource->mailbox.IsValid()); | 1452 DCHECK(!resource->mailbox.IsValid()); |
| 1417 DCHECK(resource->pixel_buffer); | 1453 DCHECK(resource->pixel_buffer); |
| 1418 DCHECK_EQ(RGBA_8888, resource->format); | 1454 DCHECK_EQ(RGBA_8888, resource->format); |
| 1419 | 1455 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 ResourceFormat format = resource->format; | 1571 ResourceFormat format = resource->format; |
| 1536 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1572 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 1537 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) { | 1573 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) { |
| 1538 GLenum storage_format = TextureToStorageFormat(format); | 1574 GLenum storage_format = TextureToStorageFormat(format); |
| 1539 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1575 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
| 1540 1, | 1576 1, |
| 1541 storage_format, | 1577 storage_format, |
| 1542 size.width(), | 1578 size.width(), |
| 1543 size.height())); | 1579 size.height())); |
| 1544 } else { | 1580 } else { |
| 1545 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1581 if (format == ETC1) { |
| 1546 0, | 1582 DCHECK(use_compressed_texture_etc1_); |
| 1547 GLInternalFormat(format), | 1583 DCHECK_EQ(0, size.width() % 4); |
| 1548 size.width(), | 1584 DCHECK_EQ(0, size.height() % 4); |
| 1549 size.height(), | 1585 GLC(context3d, |
| 1550 0, | 1586 context3d->compressedTexImage2D( |
| 1551 GLDataFormat(format), | 1587 GL_TEXTURE_2D, |
| 1552 GLDataType(format), | 1588 0, |
| 1553 NULL)); | 1589 GLInternalFormat(format), |
| 1590 size.width(), | |
| 1591 size.height(), | |
| 1592 0, | |
| 1593 cc::Resource::MemorySizeBytes(size, format), | |
| 1594 NULL)); | |
| 1595 } else { | |
| 1596 GLC(context3d, | |
| 1597 context3d->texImage2D(GL_TEXTURE_2D, | |
| 1598 0, | |
| 1599 GLInternalFormat(format), | |
| 1600 size.width(), | |
| 1601 size.height(), | |
| 1602 0, | |
| 1603 GLDataFormat(format), | |
| 1604 GLDataType(format), | |
| 1605 NULL)); | |
| 1606 } | |
| 1554 } | 1607 } |
| 1555 } | 1608 } |
| 1556 | 1609 |
| 1557 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1610 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
| 1558 bool enable) { | 1611 bool enable) { |
| 1559 Resource* resource = GetResource(id); | 1612 Resource* resource = GetResource(id); |
| 1560 resource->enable_read_lock_fences = enable; | 1613 resource->enable_read_lock_fences = enable; |
| 1561 } | 1614 } |
| 1562 | 1615 |
| 1563 void ResourceProvider::AcquireImage(ResourceId id) { | 1616 void ResourceProvider::AcquireImage(ResourceId id) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1651 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1704 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1652 return active_unit; | 1705 return active_unit; |
| 1653 } | 1706 } |
| 1654 | 1707 |
| 1655 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1708 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1656 ContextProvider* context_provider = output_surface_->context_provider(); | 1709 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1657 return context_provider ? context_provider->Context3d() : NULL; | 1710 return context_provider ? context_provider->Context3d() : NULL; |
| 1658 } | 1711 } |
| 1659 | 1712 |
| 1660 } // namespace cc | 1713 } // namespace cc |
| OLD | NEW |