Bug 1019753, part 1 - Add a ClearDataSourceSurface() helper to DataSurfaceHelpers. r=Bas
☠☠ backed out by 4faf95ee3620 ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Wed, 04 Jun 2014 08:08:39 +0100
changeset 205695 c5953a77827641fdf9c17c3e6745599cb47fce16
parent 205694 b61f2deb78fa7497ead85e8e582d245ccf619a13
child 205696 8dc53499b0c07077df186c7c6dcc62b98aa318d2
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1019753
milestone32.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 1019753, part 1 - Add a ClearDataSourceSurface() helper to DataSurfaceHelpers. r=Bas
gfx/2d/DataSurfaceHelpers.cpp
gfx/2d/DataSurfaceHelpers.h
gfx/2d/FilterNodeSoftware.cpp
--- a/gfx/2d/DataSurfaceHelpers.cpp
+++ b/gfx/2d/DataSurfaceHelpers.cpp
@@ -1,15 +1,18 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 <cstring>
+
 #include "2D.h"
 #include "DataSurfaceHelpers.h"
+#include "Tools.h"
 
 namespace mozilla {
 namespace gfx {
 
 void
 ConvertBGRXToBGRA(uint8_t* aData, const IntSize &aSize, int32_t aStride)
 {
   uint32_t* pixel = reinterpret_cast<uint32_t*>(aData);
@@ -132,10 +135,35 @@ SurfaceToPackedBGR(DataSourceSurface *aS
   CopyBGRXSurfaceDataToPackedBGRArray(map.mData, imageBuffer, size,
                                       map.mStride);
 
   aSurface->Unmap();
 
   return imageBuffer;
 }
 
+void
+ClearDataSourceSurface(DataSourceSurface *aSurface)
+{
+  DataSourceSurface::MappedSurface map;
+  if (!aSurface->Map(DataSourceSurface::MapType::WRITE, &map)) {
+    MOZ_ASSERT(false, "Failed to map DataSourceSurface");
+    return;
+  }
+
+  // We avoid writing into the gaps between the rows here since we can't be
+  // sure that some drivers don't use those bytes.
+
+  uint32_t width = aSurface->GetSize().width;
+  uint32_t bytesPerRow = width * BytesPerPixel(aSurface->GetFormat());
+  uint8_t* row = map.mData;
+  uint8_t* end = row + map.mStride * aSurface->GetSize().height;
+
+  while (row != end) {
+    memset(row, 0, bytesPerRow);
+    row += map.mStride;
+  }
+
+  aSurface->Unmap();
+}
+
 }
 }
--- a/gfx/2d/DataSurfaceHelpers.h
+++ b/gfx/2d/DataSurfaceHelpers.h
@@ -40,12 +40,19 @@ SurfaceToPackedBGRA(DataSourceSurface *a
  * This function is currently only intended for use with surfaces of format
  * SurfaceFormat::B8G8R8X8 since the X components of the pixel data (if any)
  * are simply dropped (no attempt is made to un-pre-multiply alpha from the
  * color components).
  */
 uint8_t*
 SurfaceToPackedBGR(DataSourceSurface *aSurface);
 
+/**
+ * Clears all the bytes in a DataSourceSurface's data array to zero (so to
+ * transparent black for SurfaceFormat::B8G8R8A8, for example).
+ */
+void
+ClearDataSourceSurface(DataSourceSurface *aSurface);
+
 }
 }
 
 #endif // _MOZILLA_GFX_DATASURFACEHELPERS_H
--- a/gfx/2d/FilterNodeSoftware.cpp
+++ b/gfx/2d/FilterNodeSoftware.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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/. */
 
 #define _USE_MATH_DEFINES
 
 #include <cmath>
+#include "DataSurfaceHelpers.h"
 #include "FilterNodeSoftware.h"
 #include "2D.h"
 #include "Tools.h"
 #include "Blur.h"
 #include <map>
 #include "FilterProcessing.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/DebugOnly.h"
@@ -188,24 +189,16 @@ private:
 
 // from xpcom/ds/nsMathUtils.h
 static int32_t
 NS_lround(double x)
 {
   return x >= 0.0 ? int32_t(x + 0.5) : int32_t(x - 0.5);
 }
 
-void
-ClearDataSourceSurface(DataSourceSurface *aSurface)
-{
-  size_t numBytes = aSurface->GetSize().height * aSurface->Stride();
-  uint8_t* data = aSurface->GetData();
-  PodZero(data, numBytes);
-}
-
 // This check is safe against integer overflow.
 static bool
 SurfaceContainsPoint(SourceSurface* aSurface, const IntPoint& aPoint)
 {
   IntSize size = aSurface->GetSize();
   return aPoint.x >= 0 && aPoint.x < size.width &&
          aPoint.y >= 0 && aPoint.y < size.height;
 }