@@ -1145,6 +1145,10 @@ void OpenGLRenderer::setupDrawAALine() {
11451145 mDescription .isAA = true ;
11461146}
11471147
1148+ void OpenGLRenderer::setupDrawAARect () {
1149+ mDescription .isAARect = true ;
1150+ }
1151+
11481152void OpenGLRenderer::setupDrawPoint (float pointSize) {
11491153 mDescription .isPoint = true ;
11501154 mDescription .pointSize = pointSize;
@@ -1745,9 +1749,9 @@ status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const
17451749
17461750/* *
17471751 * This function uses a similar approach to that of AA lines in the drawLines() function.
1748- * We expand the rectangle by a half pixel in screen space on all sides, and use a fragment
1749- * shader to compute the translucency of the color, determined by whether a given pixel is
1750- * within that boundary region and how far into the region it is .
1752+ * We expand the rectangle by a half pixel in screen space on all sides. However, instead of using
1753+ * a fragment shader to compute the translucency of the color from its position, we simply use a
1754+ * varying parameter to define how far a given pixel is into the region.
17511755 */
17521756void OpenGLRenderer::drawAARect (float left, float top, float right, float bottom,
17531757 int color, SkXfermode::Mode mode) {
@@ -1759,10 +1763,8 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17591763 Matrix4 *mat = mSnapshot ->transform ;
17601764 float m00 = mat->data [Matrix4::kScaleX ];
17611765 float m01 = mat->data [Matrix4::kSkewY ];
1762- float m02 = mat->data [2 ];
17631766 float m10 = mat->data [Matrix4::kSkewX ];
17641767 float m11 = mat->data [Matrix4::kScaleX ];
1765- float m12 = mat->data [6 ];
17661768 float scaleX = sqrt (m00 * m00 + m01 * m01);
17671769 float scaleY = sqrt (m10 * m10 + m11 * m11);
17681770 inverseScaleX = (scaleX != 0 ) ? (inverseScaleX / scaleX) : 0 ;
@@ -1772,6 +1774,11 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17721774 float boundarySizeX = .5 * inverseScaleX;
17731775 float boundarySizeY = .5 * inverseScaleY;
17741776
1777+ float innerLeft = left + boundarySizeX;
1778+ float innerRight = right - boundarySizeX;
1779+ float innerTop = top + boundarySizeY;
1780+ float innerBottom = bottom - boundarySizeY;
1781+
17751782 // Adjust the rect by the AA boundary padding
17761783 left -= boundarySizeX;
17771784 right += boundarySizeX;
@@ -1781,7 +1788,7 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17811788 if (!quickReject (left, top, right, bottom)) {
17821789 setupDraw ();
17831790 setupDrawNoTexture ();
1784- setupDrawAALine ();
1791+ setupDrawAARect ();
17851792 setupDrawColor (color, ((color >> 24 ) & 0xFF ) * mSnapshot ->alpha );
17861793 setupDrawColorFilter ();
17871794 setupDrawShader ();
@@ -1792,34 +1799,52 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17921799 setupDrawColorFilterUniforms ();
17931800 setupDrawShaderIdentityUniforms ();
17941801
1795- AAVertex rects[4 ];
1796- AAVertex* aaVertices = &rects[0 ];
1797- void * widthCoords = ((GLbyte*) aaVertices) + gVertexAAWidthOffset ;
1798- void * lengthCoords = ((GLbyte*) aaVertices) + gVertexAALengthOffset ;
1799-
1800- int widthSlot;
1801- int lengthSlot;
1802+ AlphaVertex rects[14 ];
1803+ AlphaVertex* aVertices = &rects[0 ];
1804+ void * alphaCoords = ((GLbyte*) aVertices) + gVertexAlphaOffset ;
1805+
1806+ bool force = mCaches .unbindMeshBuffer ();
1807+ mCaches .bindPositionVertexPointer (force, mCaches .currentProgram ->position ,
1808+ aVertices, gAlphaVertexStride );
1809+ mCaches .resetTexCoordsVertexPointer ();
1810+ mCaches .unbindIndicesBuffer ();
1811+
1812+ int alphaSlot = mCaches .currentProgram ->getAttrib (" vtxAlpha" );
1813+ glEnableVertexAttribArray (alphaSlot);
1814+ glVertexAttribPointer (alphaSlot, 1 , GL_FLOAT, GL_FALSE, gAlphaVertexStride , alphaCoords);
1815+
1816+ // draw left
1817+ AlphaVertex::set (aVertices++, left, bottom, 0 );
1818+ AlphaVertex::set (aVertices++, innerLeft, innerBottom, 1 );
1819+ AlphaVertex::set (aVertices++, left, top, 0 );
1820+ AlphaVertex::set (aVertices++, innerLeft, innerTop, 1 );
1821+
1822+ // draw top
1823+ AlphaVertex::set (aVertices++, right, top, 0 );
1824+ AlphaVertex::set (aVertices++, innerRight, innerTop, 1 );
1825+
1826+ // draw right
1827+ AlphaVertex::set (aVertices++, right, bottom, 0 );
1828+ AlphaVertex::set (aVertices++, innerRight, innerBottom, 1 );
1829+
1830+ // draw bottom
1831+ AlphaVertex::set (aVertices++, left, bottom, 0 );
1832+ AlphaVertex::set (aVertices++, innerLeft, innerBottom, 1 );
1833+
1834+ // draw inner rect (repeating last vertex to create degenerate bridge triangles)
1835+ // TODO: also consider drawing the inner rect without the blending-forced shader, if
1836+ // blending is expensive. Note: can't use drawColorRect() since it doesn't use vertex
1837+ // buffers like below, resulting in slightly different transformed coordinates.
1838+ AlphaVertex::set (aVertices++, innerLeft, innerBottom, 1 );
1839+ AlphaVertex::set (aVertices++, innerLeft, innerTop, 1 );
1840+ AlphaVertex::set (aVertices++, innerRight, innerBottom, 1 );
1841+ AlphaVertex::set (aVertices++, innerRight, innerTop, 1 );
18021842
1803- float width = right - left;
1804- float height = bottom - top;
1805-
1806- float boundaryWidthProportion = .5 - ((width != 0 ) ? (2 * boundarySizeX) / width : 0 );
1807- float boundaryHeightProportion = .5 - ((height != 0 ) ? (2 * boundarySizeY) / height : 0 );
1808- setupDrawAALine ((void *) aaVertices, widthCoords, lengthCoords,
1809- boundaryWidthProportion, widthSlot, lengthSlot);
1810-
1811- int boundaryLengthSlot = mCaches .currentProgram ->getUniform (" boundaryLength" );
1812- glUniform1f (boundaryLengthSlot, boundaryHeightProportion);
1813-
1814- AAVertex::set (aaVertices++, left, bottom, 1 , 1 );
1815- AAVertex::set (aaVertices++, left, top, 1 , 0 );
1816- AAVertex::set (aaVertices++, right, bottom, 0 , 1 );
1817- AAVertex::set (aaVertices++, right, top, 0 , 0 );
18181843 dirtyLayer (left, top, right, bottom, *mSnapshot ->transform );
18191844
1820- glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
1845+ glDrawArrays (GL_TRIANGLE_STRIP, 0 , 14 );
18211846
1822- finishDrawAALine (widthSlot, lengthSlot );
1847+ glDisableVertexAttribArray (alphaSlot );
18231848 }
18241849}
18251850
@@ -1874,10 +1899,8 @@ status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
18741899 Matrix4 *mat = mSnapshot ->transform ;
18751900 float m00 = mat->data [Matrix4::kScaleX ];
18761901 float m01 = mat->data [Matrix4::kSkewY ];
1877- float m02 = mat->data [2 ];
18781902 float m10 = mat->data [Matrix4::kSkewX ];
18791903 float m11 = mat->data [Matrix4::kScaleX ];
1880- float m12 = mat->data [6 ];
18811904
18821905 float scaleX = sqrtf (m00 * m00 + m01 * m01);
18831906 float scaleY = sqrtf (m10 * m10 + m11 * m11);
0 commit comments