Bug 892505 - Implement gfx::Factory::CreateDataSourceSurface. r=bas
authorNicolas Silva <nical@mozilla.com>
Wed, 17 Jul 2013 16:07:44 +0200
changeset 152133 a986d42c59e22dce93e85e47f763e3d4293ea40a
parent 152132 9497429e84631416465c1b2e2e026358efd629e7
child 152134 f6b26d7c37ff206c6917e5087dfd99cc1f037685
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs892505
milestone25.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 892505 - Implement gfx::Factory::CreateDataSourceSurface. r=bas
gfx/2d/Factory.cpp
gfx/2d/SourceSurfaceRawData.cpp
gfx/2d/SourceSurfaceRawData.h
gfx/2d/Tools.h
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -577,16 +577,28 @@ Factory::CreateWrappingDataSourceSurface
 
   if (newSurf->InitWrappingData(aData, aSize, aStride, aFormat, false)) {
     return newSurf;
   }
 
   return nullptr;
 }
 
+TemporaryRef<DataSourceSurface>
+Factory::CreateDataSourceSurface(const IntSize &aSize,
+                                 SurfaceFormat aFormat)
+{
+  RefPtr<SourceSurfaceAlignedRawData> newSurf = new SourceSurfaceAlignedRawData();
+  if (newSurf->Init(aSize, aFormat)) {
+    return newSurf;
+  }
+
+  return nullptr;
+}
+
 TemporaryRef<DrawEventRecorder>
 Factory::CreateEventRecorderForFile(const char *aFilename)
 {
   return new DrawEventRecorderFile(aFilename);
 }
 
 void
 Factory::SetGlobalEventRecorder(DrawEventRecorder *aRecorder)
--- a/gfx/2d/SourceSurfaceRawData.cpp
+++ b/gfx/2d/SourceSurfaceRawData.cpp
@@ -21,10 +21,22 @@ SourceSurfaceRawData::InitWrappingData(u
   mSize = aSize;
   mStride = aStride;
   mFormat = aFormat;
   mOwnData = aOwnData;
 
   return true;
 }
 
+bool
+SourceSurfaceAlignedRawData::Init(const IntSize &aSize,
+                                  SurfaceFormat aFormat)
+{
+  mStride = GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat));
+  mArray.Realloc(mStride * aSize.height);
+  mSize = aSize;
+  mFormat = aFormat;
+
+  return mArray != nullptr;
+}
+
 }
 }
--- a/gfx/2d/SourceSurfaceRawData.h
+++ b/gfx/2d/SourceSurfaceRawData.h
@@ -33,12 +33,34 @@ public:
 private:
   uint8_t *mRawData;
   int32_t mStride;
   SurfaceFormat mFormat;
   IntSize mSize;
   bool mOwnData;
 };
 
+class SourceSurfaceAlignedRawData : public DataSourceSurface
+{
+public:
+  SourceSurfaceAlignedRawData() {}
+
+  virtual uint8_t *GetData() { return mArray; }
+  virtual int32_t Stride() { return mStride; }
+
+  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual IntSize GetSize() const { return mSize; }
+  virtual SurfaceFormat GetFormat() const { return mFormat; }
+
+  bool Init(const IntSize &aSize,
+            SurfaceFormat aFormat);
+
+private:
+  AlignedArray<uint8_t> mArray;
+  int32_t mStride;
+  SurfaceFormat mFormat;
+  IntSize mSize;
+};
+
 }
 }
 
 #endif /* MOZILLA_GFX_SOURCESURFACERAWDATA_H_ */
--- a/gfx/2d/Tools.h
+++ b/gfx/2d/Tools.h
@@ -108,17 +108,17 @@ struct AlignedArray
   }
 
   MOZ_ALWAYS_INLINE void Realloc(size_t aSize)
   {
     delete [] mStorage;
     mStorage = new (std::nothrow) T[aSize + (alignment - 1)];
     if (uintptr_t(mStorage) % alignment) {
       // Our storage does not start at a <alignment>-byte boundary. Make sure mData does!
-      mPtr = (uint32_t*)(uintptr_t(mStorage) +
+      mPtr = (T*)(uintptr_t(mStorage) +
         (alignment - (uintptr_t(mStorage) % alignment)));
     } else {
       mPtr = mStorage;
     }
   }
 
   MOZ_ALWAYS_INLINE operator T*()
   {