Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 27973002: cc: Adding ETC1 support to UIResourceBitmap and ResourceProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "cc/base/util.h" 14 #include "cc/base/util.h"
15 #include "cc/output/gl_renderer.h" // For the GLC() macro. 15 #include "cc/output/gl_renderer.h" // For the GLC() macro.
16 #include "cc/resources/platform_color.h" 16 #include "cc/resources/platform_color.h"
17 #include "cc/resources/resource.h"
kaanb 2013/10/18 16:54:49 you shouldn't need this include, isn't it already
powei 2013/10/23 05:36:15 Done.
17 #include "cc/resources/returned_resource.h" 18 #include "cc/resources/returned_resource.h"
18 #include "cc/resources/transferable_resource.h" 19 #include "cc/resources/transferable_resource.h"
19 #include "cc/scheduler/texture_uploader.h" 20 #include "cc/scheduler/texture_uploader.h"
20 #include "gpu/GLES2/gl2extchromium.h" 21 #include "gpu/GLES2/gl2extchromium.h"
21 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 22 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
22 #include "third_party/khronos/GLES2/gl2.h" 23 #include "third_party/khronos/GLES2/gl2.h"
23 #include "third_party/khronos/GLES2/gl2ext.h" 24 #include "third_party/khronos/GLES2/gl2ext.h"
24 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
25 #include "ui/gfx/vector2d.h" 26 #include "ui/gfx/vector2d.h"
26 27
27 using WebKit::WebGraphicsContext3D; 28 using WebKit::WebGraphicsContext3D;
28 29
29 namespace cc { 30 namespace cc {
30 31
31 namespace { 32 namespace {
32 33
33 // Measured in seconds. 34 // Measured in seconds.
34 const double kSoftwareUploadTickRate = 0.000250; 35 const double kSoftwareUploadTickRate = 0.000250;
35 const double kTextureUploadTickRate = 0.004; 36 const double kTextureUploadTickRate = 0.004;
36 37
37 GLenum TextureToStorageFormat(ResourceFormat format) { 38 GLenum TextureToStorageFormat(ResourceFormat format) {
38 GLenum storage_format = GL_RGBA8_OES; 39 GLenum storage_format = GL_RGBA8_OES;
39 switch (format) { 40 switch (format) {
40 case RGBA_8888: 41 case RGBA_8888:
41 break; 42 break;
42 case BGRA_8888: 43 case BGRA_8888:
43 storage_format = GL_BGRA8_EXT; 44 storage_format = GL_BGRA8_EXT;
44 break; 45 break;
46 case ETC1:
45 case RGBA_4444: 47 case RGBA_4444:
46 case LUMINANCE_8: 48 case LUMINANCE_8:
47 case RGB_565: 49 case RGB_565:
48 NOTREACHED(); 50 NOTREACHED();
49 break; 51 break;
50 } 52 }
51 53
52 return storage_format; 54 return storage_format;
53 } 55 }
54 56
55 bool IsFormatSupportedForStorage(ResourceFormat format) { 57 bool IsFormatSupportedForStorage(ResourceFormat format) {
56 switch (format) { 58 switch (format) {
57 case RGBA_8888: 59 case RGBA_8888:
58 case BGRA_8888: 60 case BGRA_8888:
59 return true; 61 return true;
62 case ETC1:
60 case RGBA_4444: 63 case RGBA_4444:
61 case LUMINANCE_8: 64 case LUMINANCE_8:
62 case RGB_565: 65 case RGB_565:
63 return false; 66 return false;
64 } 67 }
65 return false; 68 return false;
66 } 69 }
67 70
68 class ScopedSetActiveTexture { 71 class ScopedSetActiveTexture {
69 public: 72 public:
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1386 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1384 context3d->bindBuffer( 1387 context3d->bindBuffer(
1385 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1388 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1386 resource->gl_pixel_buffer_id); 1389 resource->gl_pixel_buffer_id);
1387 if (!resource->gl_upload_query_id) 1390 if (!resource->gl_upload_query_id)
1388 resource->gl_upload_query_id = context3d->createQueryEXT(); 1391 resource->gl_upload_query_id = context3d->createQueryEXT();
1389 context3d->beginQueryEXT( 1392 context3d->beginQueryEXT(
1390 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1393 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1391 resource->gl_upload_query_id); 1394 resource->gl_upload_query_id);
1392 if (allocate) { 1395 if (allocate) {
1393 context3d->asyncTexImage2DCHROMIUM( 1396 if (resource->format == ETC1) {
1394 GL_TEXTURE_2D, 1397 context3d->compressedTexImage2D(
1395 0, /* level */ 1398 GL_TEXTURE_2D,
1396 GLInternalFormat(resource->format), 1399 0, /* level */
1397 resource->size.width(), 1400 GLInternalFormat(resource->format),
1398 resource->size.height(), 1401 resource->size.width(),
1399 0, /* border */ 1402 resource->size.height(),
1400 GLDataFormat(resource->format), 1403 0, /* border */
1401 GLDataType(resource->format), 1404 cc::Resource::ETC1SizeInBytes(resource->size),
1402 NULL); 1405 NULL);
1406 } else {
1407 context3d->asyncTexImage2DCHROMIUM(
1408 GL_TEXTURE_2D,
1409 0, /* level */
1410 GLInternalFormat(resource->format),
1411 resource->size.width(),
1412 resource->size.height(),
1413 0, /* border */
1414 GLDataFormat(resource->format),
1415 GLDataType(resource->format),
1416 NULL);
1417 }
1403 } else { 1418 } else {
1404 context3d->asyncTexSubImage2DCHROMIUM( 1419 if (resource->format == ETC1) {
1405 GL_TEXTURE_2D, 1420 context3d->compressedTexSubImage2D(
1406 0, /* level */ 1421 GL_TEXTURE_2D,
1407 0, /* x */ 1422 0, /* level */
1408 0, /* y */ 1423 0, /* x */
1409 resource->size.width(), 1424 0, /* y */
1410 resource->size.height(), 1425 resource->size.width(),
1411 GLDataFormat(resource->format), 1426 resource->size.height(),
1412 GLDataType(resource->format), 1427 GLDataFormat(resource->format),
1413 NULL); 1428 cc::Resource::ETC1SizeInBytes(resource->size),
1429 NULL);
1430 } else {
1431 context3d->asyncTexSubImage2DCHROMIUM(
1432 GL_TEXTURE_2D,
1433 0, /* level */
1434 0, /* x */
1435 0, /* y */
1436 resource->size.width(),
1437 resource->size.height(),
1438 GLDataFormat(resource->format),
1439 GLDataType(resource->format),
1440 NULL);
1441 }
1414 } 1442 }
1415 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1443 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1416 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1444 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1417 } 1445 }
1418 1446
1419 if (resource->pixels) { 1447 if (resource->pixels) {
1420 DCHECK(!resource->mailbox.IsValid()); 1448 DCHECK(!resource->mailbox.IsValid());
1421 DCHECK(resource->pixel_buffer); 1449 DCHECK(resource->pixel_buffer);
1422 DCHECK_EQ(RGBA_8888, resource->format); 1450 DCHECK_EQ(RGBA_8888, resource->format);
1423 1451
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 if (resource->allocated || !resource->gl_id) 1561 if (resource->allocated || !resource->gl_id)
1534 return; 1562 return;
1535 resource->allocated = true; 1563 resource->allocated = true;
1536 WebGraphicsContext3D* context3d = Context3d(); 1564 WebGraphicsContext3D* context3d = Context3d();
1537 gfx::Size& size = resource->size; 1565 gfx::Size& size = resource->size;
1538 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 1566 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
1539 ResourceFormat format = resource->format; 1567 ResourceFormat format = resource->format;
1540 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1568 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1541 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) { 1569 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) {
1542 GLenum storage_format = TextureToStorageFormat(format); 1570 GLenum storage_format = TextureToStorageFormat(format);
1543 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1571 GLC(context3d,
1544 1, 1572 context3d->texStorage2DEXT(
kaanb 2013/10/18 16:54:49 please revert this block, it just changes formatti
powei 2013/10/23 05:36:15 Done.
1545 storage_format, 1573 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height()));
1546 size.width(),
1547 size.height()));
1548 } else { 1574 } else {
1549 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1575 if (format == ETC1) {
1550 0, 1576 GLC(context3d,
1551 GLInternalFormat(format), 1577 context3d->compressedTexImage2D(
1552 size.width(), 1578 GL_TEXTURE_2D,
1553 size.height(), 1579 0,
1554 0, 1580 GLInternalFormat(format),
1555 GLDataFormat(format), 1581 size.width(),
1556 GLDataType(format), 1582 size.height(),
1557 NULL)); 1583 0,
1584 cc::Resource::ETC1SizeInBytes(resource->size),
1585 NULL));
1586 } else {
1587 GLC(context3d,
1588 context3d->texImage2D(GL_TEXTURE_2D,
1589 0,
1590 GLInternalFormat(format),
1591 size.width(),
1592 size.height(),
1593 0,
1594 GLDataFormat(format),
1595 GLDataType(format),
1596 NULL));
1597 }
1558 } 1598 }
1559 } 1599 }
1560 1600
1561 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1601 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1562 bool enable) { 1602 bool enable) {
1563 Resource* resource = GetResource(id); 1603 Resource* resource = GetResource(id);
1564 resource->enable_read_lock_fences = enable; 1604 resource->enable_read_lock_fences = enable;
1565 } 1605 }
1566 1606
1567 void ResourceProvider::AcquireImage(ResourceId id) { 1607 void ResourceProvider::AcquireImage(ResourceId id) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1692 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1653 return active_unit; 1693 return active_unit;
1654 } 1694 }
1655 1695
1656 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1696 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1657 ContextProvider* context_provider = output_surface_->context_provider(); 1697 ContextProvider* context_provider = output_surface_->context_provider();
1658 return context_provider ? context_provider->Context3d() : NULL; 1698 return context_provider ? context_provider->Context3d() : NULL;
1659 } 1699 }
1660 1700
1661 } // namespace cc 1701 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698