| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa
_intel.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa
_intel.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/service/framebuffer_manager.h" | 8 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 10 #include "ui/gl/gl_context.h" | 10 #include "ui/gl/gl_context.h" |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 int _y = _i / 2; | 1475 int _y = _i / 2; |
| 1476 | 1476 |
| 1477 ivec3 screenPosI = screenPosIBase + ivec3(_x, _y, 0); | 1477 ivec3 screenPosI = screenPosIBase + ivec3(_x, _y, 0); |
| 1478 | 1478 |
| 1479 uint packedEdgesC = packedEdgesArray[(1 + _x) * 4 + (1 + _y)]; | 1479 uint packedEdgesC = packedEdgesArray[(1 + _x) * 4 + (1 + _y)]; |
| 1480 | 1480 |
| 1481 uvec4 edges = UnpackEdge(packedEdgesC); | 1481 uvec4 edges = UnpackEdge(packedEdgesC); |
| 1482 vec4 edgesFlt = vec4(edges); | 1482 vec4 edgesFlt = vec4(edges); |
| 1483 | 1483 |
| 1484 float numberOfEdges = dot(edgesFlt, vec4(1, 1, 1, 1)); | 1484 float numberOfEdges = dot(edgesFlt, vec4(1, 1, 1, 1)); |
| 1485 if (numberOfEdges < 2.0) | 1485 if (numberOfEdges <= 1.0) |
| 1486 continue; | 1486 continue; |
| 1487 | 1487 |
| 1488 float fromRight = edgesFlt.r; | 1488 float fromRight = edgesFlt.r; |
| 1489 float fromAbove = edgesFlt.g; | 1489 float fromAbove = edgesFlt.g; |
| 1490 float fromLeft = edgesFlt.b; | 1490 float fromLeft = edgesFlt.b; |
| 1491 float fromBelow = edgesFlt.a; | 1491 float fromBelow = edgesFlt.a; |
| 1492 | 1492 |
| 1493 vec4 xFroms = vec4(fromBelow, fromAbove, fromRight, fromLeft); | 1493 vec4 xFroms = vec4(fromBelow, fromAbove, fromRight, fromLeft); |
| 1494 | 1494 |
| 1495 float blurCoeff = 0.0; | 1495 float blurCoeff = 0.0; |
| 1496 | 1496 |
| 1497 // These are additional blurs that complement the main line-based | 1497 // These are additional blurs that complement the main line-based |
| 1498 // blurring; Unlike line-based, these do not necessarily preserve | 1498 // blurring; Unlike line-based, these do not necessarily preserve |
| 1499 // the total amount of screen colour as they will take | 1499 // the total amount of screen colour as they will take |
| 1500 // neighbouring pixel colours and apply them to the one currently | 1500 // neighbouring pixel colours and apply them to the one currently |
| 1501 // processed. | 1501 // processed. |
| 1502 | 1502 |
| 1503 // 1.) L-like shape. | 1503 // 1.) L-like shape. |
| 1504 // For this shape, the total amount of screen colour will be | 1504 // For this shape, the total amount of screen colour will be |
| 1505 // preserved when this is a part of a (zigzag) diagonal line as the | 1505 // preserved when this is a part of a (zigzag) diagonal line as the |
| 1506 // corners from the other side will do the same and take some of | 1506 // corners from the other side will do the same and take some of |
| 1507 // the current pixel's colour in return. | 1507 // the current pixel's colour in return. |
| 1508 // However, in the case when this is an actual corner, the pixel's | 1508 // However, in the case when this is an actual corner, the pixel's |
| 1509 // colour will be partially overwritten by it's 2 neighbours. | 1509 // colour will be partially overwritten by it's 2 neighbours. |
| 1510 // if( numberOfEdges > 1.0 ) | 1510 if( numberOfEdges == 2.0 ) |
| 1511 { | 1511 { |
| 1512 // with value of 0.15, the pixel will retain approx 77% of its | 1512 // with value of 0.15, the pixel will retain approx 77% of its |
| 1513 // colour and the remaining 23% will come from its 2 neighbours | 1513 // colour and the remaining 23% will come from its 2 neighbours |
| 1514 // (which are likely to be blurred too in the opposite direction) | 1514 // (which are likely to be blurred too in the opposite direction) |
| 1515 blurCoeff = 0.08; | 1515 blurCoeff = 0.08; |
| 1516 | 1516 |
| 1517 // Only do blending if it's L shape - if we're between two | 1517 // Only do blending if it's L shape - if we're between two |
| 1518 // parallel edges, don't do anything | 1518 // parallel edges, don't do anything |
| 1519 blurCoeff *= (1.0 - fromBelow * fromAbove) * | 1519 blurCoeff *= (1.0 - fromBelow * fromAbove) * |
| 1520 (1.0 - fromRight * fromLeft); | 1520 (1.0 - fromRight * fromLeft); |
| 1521 |
| 1522 if (blurCoeff == 0.0) |
| 1523 continue; |
| 1524 |
| 1525 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)]; |
| 1526 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)]; |
| 1527 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)]; |
| 1528 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)]; |
| 1529 |
| 1530 // Don't blend large L shape because it would be the intended shape |
| 1531 // with high probability. e.g. rectangle |
| 1532 // large_l1 large_l2 large_l3 large_l4 |
| 1533 // _ _ | | _ _ |
| 1534 // X| X| |X |X |
| 1535 // | ¯¯¯¯ ¯¯¯¯ | |
| 1536 bool large_l1 = (packedEdgesC == (0x01u | 0x02u)) && |
| 1537 bool(packedEdgesL & 0x02u) && |
| 1538 bool(packedEdgesB & 0x01u); |
| 1539 bool large_l2 = (packedEdgesC == (0x01u | 0x08u)) && |
| 1540 bool(packedEdgesL & 0x08u) && |
| 1541 bool(packedEdgesT & 0x01u); |
| 1542 bool large_l3 = (packedEdgesC == (0x04u | 0x08u)) && |
| 1543 bool(packedEdgesR & 0x08u) && |
| 1544 bool(packedEdgesT & 0x04u); |
| 1545 bool large_l4 = (packedEdgesC == (0x02u | 0x04u)) && |
| 1546 bool(packedEdgesR & 0x02u) && |
| 1547 bool(packedEdgesB & 0x04u); |
| 1548 if (large_l1 || large_l2 || large_l3 || large_l4) |
| 1549 continue; |
| 1521 } | 1550 } |
| 1522 | 1551 |
| 1523 // 2.) U-like shape (surrounded with edges from 3 sides) | 1552 // 2.) U-like shape (surrounded with edges from 3 sides) |
| 1524 if (numberOfEdges > 2.0) { | 1553 if (numberOfEdges == 3.0) { |
| 1525 // with value of 0.13, the pixel will retain approx 72% of its | 1554 // with value of 0.13, the pixel will retain approx 72% of its |
| 1526 // colour and the remaining 28% will be picked from its 3 | 1555 // colour and the remaining 28% will be picked from its 3 |
| 1527 // neighbours (which are unlikely to be blurred too but could be) | 1556 // neighbours (which are unlikely to be blurred too but could be) |
| 1528 blurCoeff = 0.11; | 1557 blurCoeff = 0.11; |
| 1529 } | 1558 } |
| 1530 | 1559 |
| 1531 // 3.) Completely surrounded with edges from all 4 sides | 1560 // 3.) Completely surrounded with edges from all 4 sides |
| 1532 if (numberOfEdges > 3.0) { | 1561 if (numberOfEdges == 4.0) { |
| 1533 // with value of 0.07, the pixel will retain 78% of its colour | 1562 // with value of 0.07, the pixel will retain 78% of its colour |
| 1534 // and the remaining 22% will come from its 4 neighbours (which | 1563 // and the remaining 22% will come from its 4 neighbours (which |
| 1535 // are unlikely to be blurred) | 1564 // are unlikely to be blurred) |
| 1536 blurCoeff = 0.05; | 1565 blurCoeff = 0.05; |
| 1537 } | 1566 } |
| 1538 | 1567 |
| 1539 if (blurCoeff == 0.0) { | 1568 // |blurCoeff| must be not zero at this point. |
| 1540 // this avoids Z search below as well but that's ok because a Z | |
| 1541 // shape will also always have some blurCoeff | |
| 1542 continue; | |
| 1543 } | |
| 1544 | |
| 1545 vec4 blurMap = xFroms * blurCoeff; | 1569 vec4 blurMap = xFroms * blurCoeff; |
| 1546 | 1570 |
| 1547 vec4 pixelC = texelFetch(g_screenTexture, screenPosI.xy, 0); | 1571 vec4 pixelC = texelFetch(g_screenTexture, screenPosI.xy, 0); |
| 1548 | 1572 |
| 1549 const float centerWeight = 1.0; | 1573 const float centerWeight = 1.0; |
| 1550 float fromBelowWeight = blurMap.x; | 1574 float fromBelowWeight = blurMap.x; |
| 1551 float fromAboveWeight = blurMap.y; | 1575 float fromAboveWeight = blurMap.y; |
| 1552 float fromRightWeight = blurMap.z; | 1576 float fromRightWeight = blurMap.z; |
| 1553 float fromLeftWeight = blurMap.w; | 1577 float fromLeftWeight = blurMap.w; |
| 1554 | 1578 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 \n#ifdef OUT_FBO\n | 1852 \n#ifdef OUT_FBO\n |
| 1829 outColor = pixel; | 1853 outColor = pixel; |
| 1830 \n#else\n | 1854 \n#else\n |
| 1831 imageStore(outTexture, screenPosI, pixel); | 1855 imageStore(outTexture, screenPosI, pixel); |
| 1832 \n#endif\n | 1856 \n#endif\n |
| 1833 } | 1857 } |
| 1834 ); | 1858 ); |
| 1835 /* clang-format on */ | 1859 /* clang-format on */ |
| 1836 | 1860 |
| 1837 } // namespace gpu | 1861 } // namespace gpu |
| OLD | NEW |