Bug 1478815 part 7 - Add a buffer unrotate operation to DrawTarget. r=bas
authorRyan Hunt <rhunt@eqrion.net>
Wed, 01 Aug 2018 12:50:32 -0500
changeset 486009 f07a1e9cbab30755c76e3c1334b7d78aee1fb4e3
parent 486008 1fb06d46b562f86af248aeda9aa721372014ceab
child 486010 f6f972d4003bb7bcd1b6d8aac24446613cab1072
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1478815
milestone63.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 1478815 part 7 - Add a buffer unrotate operation to DrawTarget. r=bas This commit adds a buffer unrotate operation to DrawTarget. It's initially implemented with LockBits in DrawTarget. DrawTargetDual overrides the implementation to pass on the operation to it's DrawTargets. No override is given for DrawTargetCapture as we intentionally avoid this code path when async painting as it can fail. This is needed so that RotatedBuffer can expose a single DrawTarget, which can be a DrawTarget (for normal alpha), DrawTargetDual (for component alpha), or DrawTargetCapture (when async painting). MozReview-Commit-ID: csjjZ733hl
gfx/2d/2D.h
gfx/2d/BufferUnrotate.cpp
gfx/2d/BufferUnrotate.h
gfx/2d/DrawTarget.cpp
gfx/2d/DrawTargetDual.h
gfx/2d/moz.build
gfx/layers/BufferUnrotate.cpp
gfx/layers/BufferUnrotate.h
gfx/layers/LayerScope.cpp
gfx/layers/RotatedBuffer.cpp
gfx/layers/moz.build
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -1299,16 +1299,21 @@ public:
   virtual void Blur(const AlphaBoxBlur& aBlur);
 
   /**
    * Performs an in-place edge padding operation.
    */
   virtual void PadEdges(const IntRegion& aRegion);
 
   /**
+   * Performs an in-place buffer unrotation operation.
+   */
+  virtual bool Unrotate(IntPoint aRotation);
+
+  /**
    * Create a SourceSurface optimized for use with this DrawTarget from
    * existing bitmap data in memory.
    *
    * The SourceSurface does not take ownership of aData, and may be freed at any time.
    */
   virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
                                                                       const IntSize &aSize,
                                                                       int32_t aStride,
rename from gfx/layers/BufferUnrotate.cpp
rename to gfx/2d/BufferUnrotate.cpp
--- a/gfx/layers/BufferUnrotate.cpp
+++ b/gfx/2d/BufferUnrotate.cpp
@@ -6,16 +6,19 @@
 
 #include <algorithm> // min & max
 #include <cstdlib>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+namespace mozilla {
+namespace gfx {
+
 void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight,
                     int aByteStride, int aXBoundary, int aYBoundary)
 {
   if (aXBoundary != 0) {
     uint8_t* line = new uint8_t[aByteWidth];
     uint32_t smallStart = 0;
     uint32_t smallLen = aXBoundary;
     uint32_t smallDest = aByteWidth - aXBoundary;
@@ -58,8 +61,10 @@ void BufferUnrotate(uint8_t* aBuffer, in
     uint8_t* smallestSide = new uint8_t[aByteStride * smallestHeight];
     memcpy(smallestSide, &aBuffer[smallOffset], aByteStride * smallestHeight);
     memmove(&aBuffer[largeDestOffset], &aBuffer[largeOffset], aByteStride * largestHeight);
     memcpy(&aBuffer[smallDestOffset], smallestSide, aByteStride * smallestHeight);
     delete[] smallestSide;
   }
 }
 
+} // namespace gfx
+} // namespace mozilla
rename from gfx/layers/BufferUnrotate.h
rename to gfx/2d/BufferUnrotate.h
--- a/gfx/layers/BufferUnrotate.h
+++ b/gfx/2d/BufferUnrotate.h
@@ -1,15 +1,21 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef GFX_BUFFERUNROTATE_H
-#define GFX_BUFFERUNROTATE_H
+#ifndef MOZILLA_GFX_BUFFER_UNROTATE_H
+#define MOZILLA_GFX_BUFFER_UNROTATE_H
 
 #include "mozilla/Types.h"
 
+namespace mozilla {
+namespace gfx {
+
 void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight,
                     int aByteStride, int aXByteBoundary, int aYBoundary);
 
-#endif // GFX_BUFFERUNROTATE_H
+} // namespace gfx
+} // namespace mozilla
+
+#endif // MOZILLA_GFX_BUFFER_UNROTATE_H
--- a/gfx/2d/DrawTarget.cpp
+++ b/gfx/2d/DrawTarget.cpp
@@ -2,20 +2,22 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "2D.h"
 #include "Logging.h"
 #include "PathHelpers.h"
+#include "Tools.h"
 
 #include "DrawTargetCapture.h"
 
 #include "BufferEdgePad.h"
+#include "BufferUnrotate.h"
 
 #ifdef BUILD_ARM_NEON
 #include "mozilla/arm.h"
 #include "LuminanceNEON.h"
 #endif
 
 namespace mozilla {
 namespace gfx {
@@ -291,10 +293,31 @@ DrawTarget::Blur(const AlphaBoxBlur& aBl
 }
 
 void
 DrawTarget::PadEdges(const IntRegion& aRegion)
 {
   PadDrawTargetOutFromRegion(this, aRegion);
 }
 
+bool
+DrawTarget::Unrotate(IntPoint aRotation)
+{
+  unsigned char* data;
+  IntSize size;
+  int32_t stride;
+  SurfaceFormat format;
+
+  if (LockBits(&data, &size, &stride, &format)) {
+    uint8_t bytesPerPixel = BytesPerPixel(format);
+    BufferUnrotate(data,
+                   size.width * bytesPerPixel,
+                   size.height, stride,
+                   aRotation.x * bytesPerPixel,
+                   aRotation.y);
+    ReleaseBits(data);
+    return true;
+  }
+  return false;
+}
+
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/2d/DrawTargetDual.h
+++ b/gfx/2d/DrawTargetDual.h
@@ -110,16 +110,22 @@ public:
   virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions) override;
 
   virtual void PushLayer(bool aOpaque, Float aOpacity,
                          SourceSurface* aMask,
                          const Matrix& aMaskTransform,
                          const IntRect& aBounds = IntRect(),
                          bool aCopyBackground = false) override;
 
+  virtual bool Unrotate(IntPoint aRotation) override
+  {
+    return mA->Unrotate(aRotation) &&
+           mB->Unrotate(aRotation);
+  }
+
   virtual already_AddRefed<SourceSurface>
     CreateSourceSurfaceFromData(unsigned char *aData,
                                 const IntSize &aSize,
                                 int32_t aStride,
                                 SurfaceFormat aFormat) const override
   {
     return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
   }
--- a/gfx/2d/moz.build
+++ b/gfx/2d/moz.build
@@ -159,16 +159,17 @@ elif CONFIG['CPU_ARCH'].startswith('mips
     SOURCES += [
         'BlurLS3.cpp',
     ]
 
 UNIFIED_SOURCES += [
     'BezierUtils.cpp',
     'Blur.cpp',
     'BufferEdgePad.cpp',
+    'BufferUnrotate.cpp',
     'CaptureCommandList.cpp',
     'DataSourceSurface.cpp',
     'DataSurfaceHelpers.cpp',
     'DrawEventRecorder.cpp',
     'DrawingJob.cpp',
     'DrawTarget.cpp',
     'DrawTargetCairo.cpp',
     'DrawTargetCapture.cpp',
--- a/gfx/layers/LayerScope.cpp
+++ b/gfx/layers/LayerScope.cpp
@@ -46,16 +46,20 @@
 #include "nsIEventTarget.h"
 #include "nsProxyRelease.h"
 #include <list>
 
 // Undo the damage done by mozzconf.h
 #undef compress
 #include "mozilla/Compression.h"
 
+// Undo the damage done by X11
+#ifdef Status
+#  undef Status
+#endif
 // Protocol buffer (generated automatically)
 #include "protobuf/LayerScopePacket.pb.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::Compression;
 using namespace mozilla::gfx;
--- a/gfx/layers/RotatedBuffer.cpp
+++ b/gfx/layers/RotatedBuffer.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RotatedBuffer.h"
 #include <sys/types.h>                  // for int32_t
 #include <algorithm>                    // for max
 #include "BasicImplData.h"              // for BasicImplData
 #include "BasicLayersImpl.h"            // for ToData
-#include "BufferUnrotate.h"             // for BufferUnrotate
 #include "GeckoProfiler.h"              // for AUTO_PROFILER_LABEL
 #include "Layers.h"                     // for PaintedLayer, Layer, etc
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "gfxPrefs.h"                   // for gfxPrefs
 #include "gfxUtils.h"                   // for gfxUtils
 #include "mozilla/ArrayUtils.h"         // for ArrayLength
 #include "mozilla/gfx/BasePoint.h"      // for BasePoint
 #include "mozilla/gfx/BaseRect.h"       // for BaseRect
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -349,17 +349,16 @@ UNIFIED_SOURCES += [
     'basic/BasicContainerLayer.cpp',
     'basic/BasicImages.cpp',
     'basic/BasicLayerManager.cpp',
     'basic/BasicLayersImpl.cpp',
     'basic/BasicPaintedLayer.cpp',
     'basic/TextureHostBasic.cpp',
     'BSPTree.cpp',
     'BufferTexture.cpp',
-    'BufferUnrotate.cpp',
     'CanvasRenderer.cpp',
     'client/CanvasClient.cpp',
     'client/ClientCanvasLayer.cpp',
     'client/ClientCanvasRenderer.cpp',
     'client/ClientColorLayer.cpp',
     'client/ClientContainerLayer.cpp',
     'client/ClientImageLayer.cpp',
     'client/ClientLayerManager.cpp',