@@ -1141,6 +1141,10 @@ void OpenGLRenderer::setupDrawAALine() {
11411141 mDescription .isAA = true ;
11421142}
11431143
1144+ void OpenGLRenderer::setupDrawAARect () {
1145+ mDescription .isAARect = true ;
1146+ }
1147+
11441148void OpenGLRenderer::setupDrawPoint (float pointSize) {
11451149 mDescription .isPoint = true ;
11461150 mDescription .pointSize = pointSize;
@@ -1741,9 +1745,9 @@ status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const
17411745
17421746/* *
17431747 * This function uses a similar approach to that of AA lines in the drawLines() function.
1744- * We expand the rectangle by a half pixel in screen space on all sides, and use a fragment
1745- * shader to compute the translucency of the color, determined by whether a given pixel is
1746- * within that boundary region and how far into the region it is .
1748+ * We expand the rectangle by a half pixel in screen space on all sides. However, instead of using
1749+ * a fragment shader to compute the translucency of the color from its position, we simply use a
1750+ * varying parameter to define how far a given pixel is into the region.
17471751 */
17481752void OpenGLRenderer::drawAARect (float left, float top, float right, float bottom,
17491753 int color, SkXfermode::Mode mode) {
@@ -1755,10 +1759,8 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17551759 Matrix4 *mat = mSnapshot ->transform ;
17561760 float m00 = mat->data [Matrix4::kScaleX ];
17571761 float m01 = mat->data [Matrix4::kSkewY ];
1758- float m02 = mat->data [2 ];
17591762 float m10 = mat->data [Matrix4::kSkewX ];
17601763 float m11 = mat->data [Matrix4::kScaleX ];
1761- float m12 = mat->data [6 ];
17621764 float scaleX = sqrt (m00 * m00 + m01 * m01);
17631765 float scaleY = sqrt (m10 * m10 + m11 * m11);
17641766 inverseScaleX = (scaleX != 0 ) ? (inverseScaleX / scaleX) : 0 ;
@@ -1768,6 +1770,11 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17681770 float boundarySizeX = .5 * inverseScaleX;
17691771 float boundarySizeY = .5 * inverseScaleY;
17701772
1773+ float innerLeft = left + boundarySizeX;
1774+ float innerRight = right - boundarySizeX;
1775+ float innerTop = top + boundarySizeY;
1776+ float innerBottom = bottom - boundarySizeY;
1777+
17711778 // Adjust the rect by the AA boundary padding
17721779 left -= boundarySizeX;
17731780 right += boundarySizeX;
@@ -1777,7 +1784,7 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17771784 if (!quickReject (left, top, right, bottom)) {
17781785 setupDraw ();
17791786 setupDrawNoTexture ();
1780- setupDrawAALine ();
1787+ setupDrawAARect ();
17811788 setupDrawColor (color, ((color >> 24 ) & 0xFF ) * mSnapshot ->alpha );
17821789 setupDrawColorFilter ();
17831790 setupDrawShader ();
@@ -1788,34 +1795,52 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17881795 setupDrawColorFilterUniforms ();
17891796 setupDrawShaderIdentityUniforms ();
17901797
1791- AAVertex rects[4 ];
1792- AAVertex* aaVertices = &rects[0 ];
1793- void * widthCoords = ((GLbyte*) aaVertices) + gVertexAAWidthOffset ;
1794- void * lengthCoords = ((GLbyte*) aaVertices) + gVertexAALengthOffset ;
1795-
1796- int widthSlot;
1797- int lengthSlot;
1798+ AlphaVertex rects[14 ];
1799+ AlphaVertex* aVertices = &rects[0 ];
1800+ void * alphaCoords = ((GLbyte*) aVertices) + gVertexAlphaOffset ;
1801+
1802+ bool force = mCaches .unbindMeshBuffer ();
1803+ mCaches .bindPositionVertexPointer (force, mCaches .currentProgram ->position ,
1804+ aVertices, gAlphaVertexStride );
1805+ mCaches .resetTexCoordsVertexPointer ();
1806+ mCaches .unbindIndicesBuffer ();
1807+
1808+ int alphaSlot = mCaches .currentProgram ->getAttrib (" vtxAlpha" );
1809+ glEnableVertexAttribArray (alphaSlot);
1810+ glVertexAttribPointer (alphaSlot, 1 , GL_FLOAT, GL_FALSE, gAlphaVertexStride , alphaCoords);
1811+
1812+ // draw left
1813+ AlphaVertex::set (aVertices++, left, bottom, 0 );
1814+ AlphaVertex::set (aVertices++, innerLeft, innerBottom, 1 );
1815+ AlphaVertex::set (aVertices++, left, top, 0 );
1816+ AlphaVertex::set (aVertices++, innerLeft, innerTop, 1 );
1817+
1818+ // draw top
1819+ AlphaVertex::set (aVertices++, right, top, 0 );
1820+ AlphaVertex::set (aVertices++, innerRight, innerTop, 1 );
1821+
1822+ // draw right
1823+ AlphaVertex::set (aVertices++, right, bottom, 0 );
1824+ AlphaVertex::set (aVertices++, innerRight, innerBottom, 1 );
1825+
1826+ // draw bottom
1827+ AlphaVertex::set (aVertices++, left, bottom, 0 );
1828+ AlphaVertex::set (aVertices++, innerLeft, innerBottom, 1 );
1829+
1830+ // draw inner rect (repeating last vertex to create degenerate bridge triangles)
1831+ // TODO: also consider drawing the inner rect without the blending-forced shader, if
1832+ // blending is expensive. Note: can't use drawColorRect() since it doesn't use vertex
1833+ // buffers like below, resulting in slightly different transformed coordinates.
1834+ AlphaVertex::set (aVertices++, innerLeft, innerBottom, 1 );
1835+ AlphaVertex::set (aVertices++, innerLeft, innerTop, 1 );
1836+ AlphaVertex::set (aVertices++, innerRight, innerBottom, 1 );
1837+ AlphaVertex::set (aVertices++, innerRight, innerTop, 1 );
17981838
1799- float width = right - left;
1800- float height = bottom - top;
1801-
1802- float boundaryWidthProportion = .5 - ((width != 0 ) ? (2 * boundarySizeX) / width : 0 );
1803- float boundaryHeightProportion = .5 - ((height != 0 ) ? (2 * boundarySizeY) / height : 0 );
1804- setupDrawAALine ((void *) aaVertices, widthCoords, lengthCoords,
1805- boundaryWidthProportion, widthSlot, lengthSlot);
1806-
1807- int boundaryLengthSlot = mCaches .currentProgram ->getUniform (" boundaryLength" );
1808- glUniform1f (boundaryLengthSlot, boundaryHeightProportion);
1809-
1810- AAVertex::set (aaVertices++, left, bottom, 1 , 1 );
1811- AAVertex::set (aaVertices++, left, top, 1 , 0 );
1812- AAVertex::set (aaVertices++, right, bottom, 0 , 1 );
1813- AAVertex::set (aaVertices++, right, top, 0 , 0 );
18141839 dirtyLayer (left, top, right, bottom, *mSnapshot ->transform );
18151840
1816- glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
1841+ glDrawArrays (GL_TRIANGLE_STRIP, 0 , 14 );
18171842
1818- finishDrawAALine (widthSlot, lengthSlot );
1843+ glDisableVertexAttribArray (alphaSlot );
18191844 }
18201845}
18211846
@@ -1870,10 +1895,8 @@ status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
18701895 Matrix4 *mat = mSnapshot ->transform ;
18711896 float m00 = mat->data [Matrix4::kScaleX ];
18721897 float m01 = mat->data [Matrix4::kSkewY ];
1873- float m02 = mat->data [2 ];
18741898 float m10 = mat->data [Matrix4::kSkewX ];
18751899 float m11 = mat->data [Matrix4::kScaleX ];
1876- float m12 = mat->data [6 ];
18771900
18781901 float scaleX = sqrtf (m00 * m00 + m01 * m01);
18791902 float scaleY = sqrtf (m10 * m10 + m11 * m11);
0 commit comments