Bug 1522310. Use GetRect() instead of IntRect(IntPoint(), GetSize()) in Filters code. r=mstange
authorJeff Muizelaar <jrmuizel@gmail.com>
Fri, 25 Jan 2019 23:03:16 +0000
changeset 499323 e6701b43c193ed00469b7b7b270e43f6bf834cc4
parent 499322 8e87ea84e5df448cd627f0cef05418d8fb0b717c
child 499324 5ae9eadd86a7eaaaeb0816f27aab4f17c055da44
push idunknown
push userunknown
push dateunknown
reviewersmstange
bugs1522310
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522310. Use GetRect() instead of IntRect(IntPoint(), GetSize()) in Filters code. r=mstange This is needed so that we can use SourceSurfaces that don't have a implicit 0,0 origin like those that would come from a DrawTargetTiled or DrawTargetOffset. Differential Revision: https://phabricator.services.mozilla.com/D17684
gfx/2d/2D.h
gfx/2d/DataSurfaceHelpers.cpp
gfx/2d/FilterNodeSoftware.cpp
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -338,16 +338,18 @@ class DrawTargetCaptureImpl;
  */
 class SourceSurface : public external::AtomicRefCounted<SourceSurface> {
  public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurface)
   virtual ~SourceSurface() {}
 
   virtual SurfaceType GetType() const = 0;
   virtual IntSize GetSize() const = 0;
+  /* GetRect is useful for when the underlying surface doesn't actually
+   * have a backing store starting at 0, 0. e.g. SourceSurfaceOffset */
   virtual IntRect GetRect() const { return IntRect(IntPoint(0, 0), GetSize()); }
   virtual SurfaceFormat GetFormat() const = 0;
 
   /** This returns false if some event has made this source surface invalid for
    * usage with current DrawTargets. For example in the case of Direct2D this
    * could return false if we have switched devices since this surface was
    * created.
    */
--- a/gfx/2d/DataSurfaceHelpers.cpp
+++ b/gfx/2d/DataSurfaceHelpers.cpp
@@ -274,16 +274,20 @@ size_t BufferSizeFromDimensions(int32_t 
     return 0;
   }
   return requiredBytes.value();
 }
 
 /**
  * aSrcRect: Rect relative to the aSrc surface
  * aDestPoint: Point inside aDest surface
+ *
+ * aSrcRect and aDestPoint are in internal local coordinates.
+ * i.e. locations of pixels and not in the same coordinate space
+ * as aSrc->GetRect()
  */
 bool CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
               IntRect aSrcRect, IntPoint aDestPoint) {
   if (aSrcRect.Overflows() ||
       IntRect(aDestPoint, aSrcRect.Size()).Overflows()) {
     MOZ_CRASH("GFX: we should never be getting invalid rects at this point");
   }
 
--- a/gfx/2d/FilterNodeSoftware.cpp
+++ b/gfx/2d/FilterNodeSoftware.cpp
@@ -397,16 +397,18 @@ static already_AddRefed<DataSourceSurfac
 
   IntRect sourceRect = aSurfaceRect;
 
   if (sourceRect.IsEqualEdges(aDestRect)) {
     return aSurface ? aSurface->GetDataSurface() : nullptr;
   }
 
   IntRect intersect = sourceRect.Intersect(aDestRect);
+
+  // create rects that are in surface local space.
   IntRect intersectInSourceSpace = intersect - sourceRect.TopLeft();
   IntRect intersectInDestSpace = intersect - aDestRect.TopLeft();
   SurfaceFormat format =
       aSurface ? aSurface->GetFormat() : SurfaceFormat(SurfaceFormat::B8G8R8A8);
 
   RefPtr<DataSourceSurface> target =
       Factory::CreateDataSourceSurface(aDestRect.Size(), format, true);
   if (MOZ2D_WARN_IF(!target)) {
@@ -721,17 +723,17 @@ FilterNodeSoftware::GetInputDataSourceSu
   IntRect surfaceRect;
 
   if (mInputSurfaces[inputIndex]) {
     // Input from input surface
     surface = mInputSurfaces[inputIndex];
 #ifdef DEBUG_DUMP_SURFACES
     printf("input from input surface:\n");
 #endif
-    surfaceRect = IntRect(IntPoint(0, 0), surface->GetSize());
+    surfaceRect = surface->GetRect();
   } else {
     // Input from input filter
 #ifdef DEBUG_DUMP_SURFACES
     printf("getting input from input filter %s...\n",
            mInputFilters[inputIndex]->GetName());
 #endif
     RefPtr<FilterNodeSoftware> filter = mInputFilters[inputIndex];
     MOZ_ASSERT(filter, "missing input");
@@ -824,18 +826,17 @@ IntRect FilterNodeSoftware::GetInputRect
 
   int32_t inputIndex = InputIndex(aInputEnumIndex);
   if (inputIndex < 0 || (uint32_t)inputIndex >= NumberOfSetInputs()) {
     gfxDevCrash(LogReason::FilterInputRect)
         << "Invalid rect " << inputIndex << " vs. " << NumberOfSetInputs();
     return IntRect();
   }
   if (mInputSurfaces[inputIndex]) {
-    return aInRect.Intersect(
-        IntRect(IntPoint(0, 0), mInputSurfaces[inputIndex]->GetSize()));
+    return aInRect.Intersect(mInputSurfaces[inputIndex]->GetRect());
   }
   RefPtr<FilterNodeSoftware> filter = mInputFilters[inputIndex];
   MOZ_ASSERT(filter, "missing input");
   return filter->GetOutputRectInRect(aInRect);
 }
 
 size_t FilterNodeSoftware::NumberOfSetInputs() {
   return std::max(mInputSurfaces.size(), mInputFilters.size());