Remove BufferContentType and add ValidBufferSize (bug 1399692 part 3, r=bas)
authorRyan Hunt <rhunt@eqrion.net>
Mon, 23 Oct 2017 14:56:13 -0400
changeset 444460 a1ba79c560d8388c2f06efc8bd429036808074c1
parent 444459 b9261720d6c23010c85af4bb0a5b34803f30d42e
child 444461 3a045db296d28bb1883a10fdb3490de3aa04e6bf
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1399692
milestone58.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
Remove BufferContentType and add ValidBufferSize (bug 1399692 part 3, r=bas) BufferContentType and BufferSizeOkFor make more sense as general functions for any RotatedBuffer, and this helps out in a later patch. MozReview-Commit-ID: EAVodvl4WTu
gfx/layers/RotatedBuffer.cpp
gfx/layers/RotatedBuffer.h
gfx/layers/client/ContentClient.cpp
gfx/layers/client/ContentClient.h
--- a/gfx/layers/RotatedBuffer.cpp
+++ b/gfx/layers/RotatedBuffer.cpp
@@ -384,16 +384,22 @@ RotatedBuffer::AdjustTo(const gfx::IntRe
     // set destBuffer.
     mBufferRect = aDestBufferRect;
     mBufferRotation = IntPoint(0,0);
   }
 
   return true;
 }
 
+RotatedBuffer::ContentType
+RotatedBuffer::GetContentType() const
+{
+  return ContentForFormat(GetFormat());
+}
+
 DrawTarget*
 RotatedBuffer::BorrowDrawTargetForQuadrantUpdate(const IntRect& aBounds,
                                                  ContextSource aSource,
                                                  DrawIterator* aIter,
                                                  bool aSetTransform,
                                                  Matrix* aOutMatrix)
 {
   IntRect bounds = aBounds;
--- a/gfx/layers/RotatedBuffer.h
+++ b/gfx/layers/RotatedBuffer.h
@@ -198,16 +198,21 @@ public:
    */
   bool DidSelfCopy() const { return mDidSelfCopy; }
 
   /**
    * Clears the self copy flag.
    */
   void ClearDidSelfCopy() { mDidSelfCopy = false; }
 
+  /**
+   * Gets the content type for this buffer.
+   */
+  ContentType GetContentType() const;
+
   virtual bool IsLocked() = 0;
   virtual bool Lock(OpenMode aMode) = 0;
   virtual void Unlock() = 0;
 
   virtual bool HaveBuffer() const = 0;
   virtual bool HaveBufferOnWhite() const = 0;
 
   virtual gfx::SurfaceFormat GetFormat() const = 0;
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -122,27 +122,27 @@ ContentClient::BeginPaint(PaintedLayer* 
 
   if (!dest.mCanKeepBufferContents) {
     // We're effectively clearing the valid region, so we need to draw
     // the entire needed region now.
     MOZ_ASSERT(!dest.mCanReuseBuffer);
     MOZ_ASSERT(dest.mValidRegion.IsEmpty());
 
     result.mRegionToInvalidate = aLayer->GetValidRegion();
-    Clear();
 
 #if defined(MOZ_DUMP_PAINTING)
     if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
-      if (result.mContentType != BufferContentType()) {
+      if (result.mContentType != mBuffer->GetContentType()) {
         printf_stderr("Invalidating entire rotated buffer (layer %p): content type changed\n", aLayer);
       } else if ((dest.mBufferMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) != mBuffer->HaveBufferOnWhite()) {
         printf_stderr("Invalidating entire rotated buffer (layer %p): component alpha changed\n", aLayer);
       }
     }
 #endif
+    Clear();
   }
 
   result.mRegionToDraw.Sub(dest.mNeededRegion,
                            dest.mValidRegion);
 
   if (result.mRegionToDraw.IsEmpty())
     return result;
 
@@ -375,17 +375,19 @@ ContentClient::CalculateBufferForPaint(P
   nsIntRegion validRegion = aLayer->GetValidRegion();
 
   bool canReuseBuffer = !!mBuffer;
   bool canKeepBufferContents = true;
 
   while (true) {
     mode = aLayer->GetSurfaceMode();
     neededRegion = aLayer->GetVisibleRegion().ToUnknownRegion();
-    canReuseBuffer = canReuseBuffer && BufferSizeOkFor(neededRegion.GetBounds().Size());
+    canReuseBuffer = canReuseBuffer && ValidBufferSize(mBufferSizePolicy,
+                                                       mBuffer->BufferRect().Size(),
+                                                       neededRegion.GetBounds().Size());
     contentType = layerContentType;
 
     if (canReuseBuffer) {
       if (mBuffer->BufferRect().Contains(neededRegion.GetBounds())) {
         // We don't need to adjust mBufferRect.
         destBufferRect = mBuffer->BufferRect();
       } else if (neededRegion.GetBounds().Size() <= mBuffer->BufferRect().Size()) {
         // The buffer's big enough but doesn't contain everything that's
@@ -428,17 +430,17 @@ ContentClient::CalculateBufferForPaint(P
       // pixels are sampled.
       neededRegion = destBufferRect;
     }
 
     // If we have an existing buffer, but the content type has changed or we
     // have transitioned into/out of component alpha, then we need to recreate it.
     if (canKeepBufferContents &&
         mBuffer &&
-        (contentType != BufferContentType() ||
+        (contentType != mBuffer->GetContentType() ||
         (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) != mBuffer->HaveBufferOnWhite()))
     {
       // Restart the decision process; we won't re-enter since we guard on
       // being able to keep the buffer contents.
       canReuseBuffer = false;
       canKeepBufferContents = false;
       validRegion.SetEmpty();
       continue;
@@ -456,32 +458,24 @@ ContentClient::CalculateBufferForPaint(P
   dest.mBufferRect = destBufferRect;
   dest.mBufferMode = mode;
   dest.mBufferContentType = contentType;
   dest.mCanReuseBuffer = canReuseBuffer;
   dest.mCanKeepBufferContents = canKeepBufferContents;
   return dest;
 }
 
-gfxContentType
-ContentClient::BufferContentType()
+bool
+ContentClient::ValidBufferSize(BufferSizePolicy aPolicy,
+                               const gfx::IntSize& aBufferSize,
+                               const gfx::IntSize& aVisibleBoundsSize)
 {
-  if (mBuffer) {
-    return ContentForFormat(mBuffer->GetFormat());
-  }
-  return gfxContentType::SENTINEL;
-}
-
-bool
-ContentClient::BufferSizeOkFor(const IntSize& aSize)
-{
-  MOZ_ASSERT(mBuffer);
-  return (aSize == mBuffer->BufferRect().Size() ||
-          (SizedToVisibleBounds != mBufferSizePolicy &&
-           aSize < mBuffer->BufferRect().Size()));
+  return (aVisibleBoundsSize == aBufferSize ||
+          (SizedToVisibleBounds != aPolicy &&
+           aVisibleBoundsSize < aBufferSize));
 }
 
 void
 ContentClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
 {
   aStream << aPrefix;
   aStream << nsPrintfCString("ContentClient (0x%p)", this).get();
 }
--- a/gfx/layers/client/ContentClient.h
+++ b/gfx/layers/client/ContentClient.h
@@ -198,25 +198,19 @@ protected:
   /**
    * Decide whether we can keep our current buffer and its contents,
    * and return a struct containing the regions to paint, invalidate,
    * the new buffer rect, surface mode, and content type.
    */
   BufferDecision CalculateBufferForPaint(PaintedLayer* aLayer,
                                          uint32_t aFlags);
 
-  /**
-   * Return the buffer's content type.  Requires a valid buffer.
-   */
-  gfxContentType BufferContentType();
-  /**
-   * Returns whether the specified size is adequate for the current
-   * buffer and buffer size policy.
-   */
-  bool BufferSizeOkFor(const gfx::IntSize& aSize);
+  static bool ValidBufferSize(BufferSizePolicy aPolicy,
+                              const gfx::IntSize& aBufferSize,
+                              const gfx::IntSize& aVisibleBoundsSize);
 
   /**
    * Any actions that should be performed at the last moment before we begin
    * rendering the next frame. I.e., after we calculate what we will draw,
    * but before we rotate the buffer and possibly create new buffers.
    * aRegionToDraw is the region which is guaranteed to be overwritten when
    * drawing the next frame.
    */