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 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 | 1496 |
1497 for (int _i = 0; _i < 4; _i++) { | 1497 for (int _i = 0; _i < 4; _i++) { |
1498 int _x = _i % 2; | 1498 int _x = _i % 2; |
1499 int _y = _i / 2; | 1499 int _y = _i / 2; |
1500 | 1500 |
1501 ivec3 screenPosI = screenPosIBase + ivec3(_x, _y, 0); | 1501 ivec3 screenPosI = screenPosIBase + ivec3(_x, _y, 0); |
1502 | 1502 |
1503 uint packedEdgesC = packedEdgesArray[(1 + _x) * 4 + (1 + _y)]; | 1503 uint packedEdgesC = packedEdgesArray[(1 + _x) * 4 + (1 + _y)]; |
1504 | 1504 |
1505 uvec4 edges = UnpackEdge(packedEdgesC); | 1505 uvec4 edges = UnpackEdge(packedEdgesC); |
1506 vec4 edgesFlt = vec4(edges); | 1506 uint numberOfEdges = edges.x + edges.y + edges.z + edges.w; |
1507 | 1507 if (numberOfEdges <= 1u) |
1508 float numberOfEdges = dot(edgesFlt, vec4(1, 1, 1, 1)); | |
1509 if (numberOfEdges <= 1.0) | |
1510 continue; | 1508 continue; |
1511 | 1509 |
| 1510 vec4 edgesFlt = vec4(edges); |
1512 float fromRight = edgesFlt.r; | 1511 float fromRight = edgesFlt.r; |
1513 float fromAbove = edgesFlt.g; | 1512 float fromAbove = edgesFlt.g; |
1514 float fromLeft = edgesFlt.b; | 1513 float fromLeft = edgesFlt.b; |
1515 float fromBelow = edgesFlt.a; | 1514 float fromBelow = edgesFlt.a; |
1516 | 1515 |
1517 vec4 xFroms = vec4(fromBelow, fromAbove, fromRight, fromLeft); | 1516 vec4 xFroms = vec4(fromBelow, fromAbove, fromRight, fromLeft); |
1518 | 1517 |
1519 float blurCoeff = 0.0; | 1518 float blurCoeff = 0.0; |
1520 | 1519 |
1521 // These are additional blurs that complement the main line-based | 1520 // These are additional blurs that complement the main line-based |
1522 // blurring; Unlike line-based, these do not necessarily preserve | 1521 // blurring; Unlike line-based, these do not necessarily preserve |
1523 // the total amount of screen colour as they will take | 1522 // the total amount of screen colour as they will take |
1524 // neighbouring pixel colours and apply them to the one currently | 1523 // neighbouring pixel colours and apply them to the one currently |
1525 // processed. | 1524 // processed. |
1526 | 1525 |
1527 // 1.) L-like shape. | 1526 // 1.) L-like shape. |
1528 // For this shape, the total amount of screen colour will be | 1527 // For this shape, the total amount of screen colour will be |
1529 // preserved when this is a part of a (zigzag) diagonal line as the | 1528 // preserved when this is a part of a (zigzag) diagonal line as the |
1530 // corners from the other side will do the same and take some of | 1529 // corners from the other side will do the same and take some of |
1531 // the current pixel's colour in return. | 1530 // the current pixel's colour in return. |
1532 // However, in the case when this is an actual corner, the pixel's | 1531 // However, in the case when this is an actual corner, the pixel's |
1533 // colour will be partially overwritten by it's 2 neighbours. | 1532 // colour will be partially overwritten by it's 2 neighbours. |
1534 if( numberOfEdges == 2.0 ) | 1533 if (numberOfEdges == 2u) |
1535 { | 1534 { |
1536 // with value of 0.15, the pixel will retain approx 77% of its | 1535 // with value of 0.15, the pixel will retain approx 77% of its |
1537 // colour and the remaining 23% will come from its 2 neighbours | 1536 // colour and the remaining 23% will come from its 2 neighbours |
1538 // (which are likely to be blurred too in the opposite direction) | 1537 // (which are likely to be blurred too in the opposite direction) |
1539 blurCoeff = 0.15; | 1538 blurCoeff = 0.15; |
1540 | 1539 |
1541 // Only do blending if it's L shape - if we're between two | 1540 // Only do blending if it's L shape - if we're between two |
1542 // parallel edges, don't do anything | 1541 // parallel edges, don't do anything |
1543 blurCoeff *= (1.0 - fromBelow * fromAbove) * | 1542 blurCoeff *= (1.0 - fromBelow * fromAbove) * |
1544 (1.0 - fromRight * fromLeft); | 1543 (1.0 - fromRight * fromLeft); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 bool isolated_l4 = (packedEdgesC == (0x02u | 0x04u)) && | 1594 bool isolated_l4 = (packedEdgesC == (0x02u | 0x04u)) && |
1596 bool((packedEdgesL & 0x08u) == 0x00u) && | 1595 bool((packedEdgesL & 0x08u) == 0x00u) && |
1597 bool((packedEdgesT & 0x01u) == 0x00u) && | 1596 bool((packedEdgesT & 0x01u) == 0x00u) && |
1598 bool((packedEdgesR & 0x02u) == 0x00u) && | 1597 bool((packedEdgesR & 0x02u) == 0x00u) && |
1599 bool((packedEdgesB & 0x04u) == 0x00u); | 1598 bool((packedEdgesB & 0x04u) == 0x00u); |
1600 if (isolated_l1 || isolated_l2 || isolated_l3 || isolated_l4) | 1599 if (isolated_l1 || isolated_l2 || isolated_l3 || isolated_l4) |
1601 continue; | 1600 continue; |
1602 } | 1601 } |
1603 | 1602 |
1604 // 2.) U-like shape (surrounded with edges from 3 sides) | 1603 // 2.) U-like shape (surrounded with edges from 3 sides) |
1605 if (numberOfEdges == 3.0) { | 1604 if (numberOfEdges == 3u) { |
1606 // with value of 0.13, the pixel will retain approx 72% of its | 1605 // with value of 0.13, the pixel will retain approx 72% of its |
1607 // colour and the remaining 28% will be picked from its 3 | 1606 // colour and the remaining 28% will be picked from its 3 |
1608 // neighbours (which are unlikely to be blurred too but could be) | 1607 // neighbours (which are unlikely to be blurred too but could be) |
1609 blurCoeff = 0.13; | 1608 blurCoeff = 0.13; |
1610 } | 1609 } |
1611 | 1610 |
1612 // 3.) Completely surrounded with edges from all 4 sides | 1611 // 3.) Completely surrounded with edges from all 4 sides |
1613 if (numberOfEdges == 4.0) { | 1612 if (numberOfEdges == 4u) { |
1614 // with value of 0.07, the pixel will retain 78% of its colour | 1613 // with value of 0.07, the pixel will retain 78% of its colour |
1615 // and the remaining 22% will come from its 4 neighbours (which | 1614 // and the remaining 22% will come from its 4 neighbours (which |
1616 // are unlikely to be blurred) | 1615 // are unlikely to be blurred) |
1617 blurCoeff = 0.07; | 1616 blurCoeff = 0.07; |
1618 } | 1617 } |
1619 | 1618 |
1620 // |blurCoeff| must be not zero at this point. | 1619 // |blurCoeff| must be not zero at this point. |
1621 vec4 blurMap = xFroms * blurCoeff; | 1620 vec4 blurMap = xFroms * blurCoeff; |
1622 | 1621 |
1623 vec4 pixelC = texelFetch(g_screenTexture, screenPosI.xy, 0); | 1622 vec4 pixelC = texelFetch(g_screenTexture, screenPosI.xy, 0); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 | 1662 |
1664 color /= fourWeightSum + 0.0001; | 1663 color /= fourWeightSum + 0.0001; |
1665 | 1664 |
1666 color = mix(color, pixelC, centerWeight / allWeightSum); | 1665 color = mix(color, pixelC, centerWeight / allWeightSum); |
1667 \n#ifdef IN_GAMMA_CORRECT_MODE\n | 1666 \n#ifdef IN_GAMMA_CORRECT_MODE\n |
1668 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb); | 1667 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb); |
1669 \n#endif\n | 1668 \n#endif\n |
1670 | 1669 |
1671 \n#ifdef DEBUG_OUTPUT_AAINFO\n | 1670 \n#ifdef DEBUG_OUTPUT_AAINFO\n |
1672 imageStore(g_resultTextureSlot2, screenPosI.xy, | 1671 imageStore(g_resultTextureSlot2, screenPosI.xy, |
1673 PackBlurAAInfo(screenPosI.xy, uint(numberOfEdges))); | 1672 PackBlurAAInfo(screenPosI.xy, numberOfEdges)); |
1674 \n#endif\n | 1673 \n#endif\n |
1675 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy, color); | 1674 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy, color); |
1676 | 1675 |
1677 if (numberOfEdges == 2.0) { | 1676 if (numberOfEdges == 2u) { |
1678 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)]; | 1677 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)]; |
1679 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)]; | 1678 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)]; |
1680 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)]; | 1679 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)]; |
1681 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)]; | 1680 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)]; |
1682 | 1681 |
1683 bool isHorizontalA = ((packedEdgesC) == (0x01u | 0x02u)) && | 1682 bool isHorizontalA = ((packedEdgesC) == (0x01u | 0x02u)) && |
1684 ((packedEdgesR & 0x08u) == 0x08u); | 1683 ((packedEdgesR & 0x08u) == 0x08u); |
1685 bool isHorizontalB = ((packedEdgesC) == (0x01u | 0x08u)) && | 1684 bool isHorizontalB = ((packedEdgesC) == (0x01u | 0x08u)) && |
1686 ((packedEdgesR & 0x02u) == 0x02u); | 1685 ((packedEdgesR & 0x02u) == 0x02u); |
1687 | 1686 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 \n#ifdef OUT_FBO\n | 1901 \n#ifdef OUT_FBO\n |
1903 outColor = pixel; | 1902 outColor = pixel; |
1904 \n#else\n | 1903 \n#else\n |
1905 imageStore(outTexture, screenPosI, pixel); | 1904 imageStore(outTexture, screenPosI, pixel); |
1906 \n#endif\n | 1905 \n#endif\n |
1907 } | 1906 } |
1908 ); | 1907 ); |
1909 /* clang-format on */ | 1908 /* clang-format on */ |
1910 | 1909 |
1911 } // namespace gpu | 1910 } // namespace gpu |
OLD | NEW |