diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-10 11:39:27 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-10 11:39:27 +0100 |
commit | 974a481d12bf430891725bd3662876358e57e11a (patch) | |
tree | cad011151456251fef2f1b8d02ef4b4e45fad61a /gfx/2d | |
parent | 6bd66b1728eeddb058066edda740aaeb2ceaec23 (diff) | |
parent | 736d25cbec4541186ed46c935c117ce4d1c7f3bb (diff) | |
download | UXP-974a481d12bf430891725bd3662876358e57e11a.tar UXP-974a481d12bf430891725bd3662876358e57e11a.tar.gz UXP-974a481d12bf430891725bd3662876358e57e11a.tar.lz UXP-974a481d12bf430891725bd3662876358e57e11a.tar.xz UXP-974a481d12bf430891725bd3662876358e57e11a.zip |
Merge branch 'master' into js-modules
# Conflicts:
# modules/libpref/init/all.js
Diffstat (limited to 'gfx/2d')
-rw-r--r-- | gfx/2d/2D.h | 3 | ||||
-rw-r--r-- | gfx/2d/Matrix.h | 44 | ||||
-rw-r--r-- | gfx/2d/Types.h | 10 |
3 files changed, 32 insertions, 25 deletions
diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index c1fba3463..e2020dc9e 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -488,6 +488,9 @@ public: /** * Returns a DataSourceSurface with the same data as this one, but * guaranteed to have surface->GetType() == SurfaceType::DATA. + * + * The returning surface might be null, because of OOM or gfx device reset. + * The caller needs to do null-check before using it. */ virtual already_AddRefed<DataSourceSurface> GetDataSurface() override; diff --git a/gfx/2d/Matrix.h b/gfx/2d/Matrix.h index 22a01ca10..d6835c8e6 100644 --- a/gfx/2d/Matrix.h +++ b/gfx/2d/Matrix.h @@ -723,7 +723,7 @@ public: * The resulting vertices are populated in aVerts. aVerts must be * pre-allocated to hold at least kTransformAndClipRectMaxVerts Points. * The vertex count is returned by TransformAndClipRect. It is possible to - * emit fewer that 3 vertices, indicating that aRect will not be visible + * emit fewer than 3 vertices, indicating that aRect will not be visible * within aClip. */ template<class F> @@ -734,7 +734,8 @@ public: // Initialize a double-buffered array of points in homogenous space with // the input rectangle, aRect. Point4DTyped<UnknownUnits, F> points[2][kTransformAndClipRectMaxVerts]; - Point4DTyped<UnknownUnits, F>* dstPoint = points[0]; + Point4DTyped<UnknownUnits, F>* dstPointStart = points[0]; + Point4DTyped<UnknownUnits, F>* dstPoint = dstPointStart; *dstPoint++ = TransformPoint(Point4DTyped<UnknownUnits, F>(aRect.x, aRect.y, 0, 1)); *dstPoint++ = TransformPoint(Point4DTyped<UnknownUnits, F>(aRect.XMost(), aRect.y, 0, 1)); @@ -750,16 +751,26 @@ public: planeNormals[3] = Point4DTyped<UnknownUnits, F>(0.0, -1.0, 0.0, aClip.YMost()); // Iterate through each clipping plane and clip the polygon. - // In each pass, we double buffer, alternating between points[0] and - // points[1]. + // For each clipping plane, we intersect the plane with all polygon edges. + // Each pass can increase or decrease the number of points that make up the + // current clipped polygon. We double buffer that set of points, alternating + // between points[0] and points[1]. for (int plane=0; plane < 4; plane++) { planeNormals[plane].Normalize(); - Point4DTyped<UnknownUnits, F>* srcPoint = points[plane & 1]; + Point4DTyped<UnknownUnits, F>* srcPoint = dstPointStart; Point4DTyped<UnknownUnits, F>* srcPointEnd = dstPoint; - dstPoint = points[~plane & 1]; - Point4DTyped<UnknownUnits, F>* dstPointStart = dstPoint; - + dstPointStart = points[~plane & 1]; + dstPoint = dstPointStart; + + // Iterate over the polygon edges. In each iteration the current edge is + // the edge from prevPoint to srcPoint. If the two end points lie on + // different sides of the plane, we have an intersection. Otherwise, the + // edge is either completely "inside" the half-space created by the + // clipping plane, and we add srcPoint, or it is completely "outside", and + // we discard srcPoint. + // We may create duplicated points in the polygon. We keep those around + // until all clipping is done and then filter out duplicates at the end. Point4DTyped<UnknownUnits, F>* prevPoint = srcPointEnd - 1; F prevDot = planeNormals[plane].DotProduct(*prevPoint); while (srcPoint < srcPointEnd && ((dstPoint - dstPointStart) < kTransformAndClipRectMaxVerts)) { @@ -783,14 +794,16 @@ public: } if (dstPoint == dstPointStart) { + // No polygon points were produced, so the polygon has been + // completely clipped away by the current clipping plane. Exit. break; } } - size_t dstPointCount = 0; - size_t srcPointCount = dstPoint - points[0]; - for (Point4DTyped<UnknownUnits, F>* srcPoint = points[0]; srcPoint < points[0] + srcPointCount; srcPoint++) { - + Point4DTyped<UnknownUnits, F>* srcPoint = dstPointStart; + Point4DTyped<UnknownUnits, F>* srcPointEnd = dstPoint; + size_t vertCount = 0; + while (srcPoint < srcPointEnd) { PointTyped<TargetUnits, F> p; if (srcPoint->w == 0.0) { // If a point lies on the intersection of the clipping planes at @@ -800,12 +813,13 @@ public: p = srcPoint->As2DPoint(); } // Emit only unique points - if (dstPointCount == 0 || p != aVerts[dstPointCount - 1]) { - aVerts[dstPointCount++] = p; + if (vertCount == 0 || p != aVerts[vertCount - 1]) { + aVerts[vertCount++] = p; } + srcPoint++; } - return dstPointCount; + return vertCount; } static const int kTransformAndClipRectMaxVerts = 32; diff --git a/gfx/2d/Types.h b/gfx/2d/Types.h index 7b1676ab2..3cdf077b1 100644 --- a/gfx/2d/Types.h +++ b/gfx/2d/Types.h @@ -65,18 +65,8 @@ enum class SurfaceFormat : int8_t { // This represents the unknown format. UNKNOWN, - // The following values are endian-independent synonyms. The _UINT32 suffix - // indicates that the name reflects the layout when viewed as a uint32_t - // value. -#if MOZ_LITTLE_ENDIAN A8R8G8B8_UINT32 = B8G8R8A8, // 0xAARRGGBB X8R8G8B8_UINT32 = B8G8R8X8 // 0x00RRGGBB -#elif MOZ_BIG_ENDIAN - A8R8G8B8_UINT32 = A8R8G8B8, // 0xAARRGGBB - X8R8G8B8_UINT32 = X8R8G8B8 // 0x00RRGGBB -#else -# error "bad endianness" -#endif }; inline bool IsOpaque(SurfaceFormat aFormat) |