Bug 960254 - Part 1: Add new Map/Unmap APIs to DataSourceSurface. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Thu, 16 Jan 2014 13:17:22 +0100
changeset 163701 b61f6abbd13d93896e72edbb87ffde26c034d06b
parent 163700 2628e64cf37571a3699985562935c47cf051d9a6
child 163702 3ae8e5f144f160596797bd1dccecba9871587c03
push id38545
push userbschouten@mozilla.com
push dateThu, 16 Jan 2014 13:37:18 +0000
treeherdermozilla-inbound@327d381e24c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs960254
milestone29.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 960254 - Part 1: Add new Map/Unmap APIs to DataSourceSurface. r=jrmuizel
gfx/2d/2D.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -18,16 +18,18 @@
 // to be able to hold on to a GLContext.
 #include "mozilla/GenericRefCounted.h"
 
 // This RefPtr class isn't ideal for usage in Azure, as it doesn't allow T**
 // outparams using the &-operator. But it will have to do as there's no easy
 // solution.
 #include "mozilla/RefPtr.h"
 
+#include "mozilla/DebugOnly.h"
+
 #ifdef MOZ_ENABLE_FREETYPE
 #include <string>
 #endif
 
 struct _cairo_surface;
 typedef _cairo_surface cairo_surface_t;
 
 struct _cairo_scaled_font;
@@ -332,41 +334,73 @@ public:
    * DataSourceSurface's data can be accessed directly.
    */
   virtual TemporaryRef<DataSourceSurface> GetDataSurface() = 0;
 };
 
 class DataSourceSurface : public SourceSurface
 {
 public:
+  DataSourceSurface()
+    : mIsMapped(false)
+  {
+  }
+
+  struct MappedSurface {
+    uint8_t *mData;
+    int32_t mStride;
+  };
+
+  enum MapType {
+    READ,
+    WRITE,
+    READ_WRITE
+  };
+
   virtual SurfaceType GetType() const { return SurfaceType::DATA; }
-  /*
+  /* [DEPRECATED]
    * Get the raw bitmap data of the surface.
    * Can return null if there was OOM allocating surface data.
    */
   virtual uint8_t *GetData() = 0;
 
-  /*
+  /* [DEPRECATED]
    * Stride of the surface, distance in bytes between the start of the image
    * data belonging to row y and row y+1. This may be negative.
    * Can return 0 if there was OOM allocating surface data.
    */
   virtual int32_t Stride() = 0;
 
   /*
    * This function is called after modifying the data on the source surface
    * directly through the data pointer.
    */
   virtual void MarkDirty() {}
 
+  virtual bool Map(MapType, MappedSurface *aMappedSurface)
+  {
+    aMappedSurface->mData = GetData();
+    aMappedSurface->mStride = Stride();
+    mIsMapped = true;
+    return true;
+  }
+
+  virtual void Unmap()
+  {
+    MOZ_ASSERT(mIsMapped);
+    mIsMapped = false;
+  }
+
   /*
    * Returns a DataSourceSurface with the same data as this one, but
    * guaranteed to have surface->GetType() == SurfaceType::DATA.
    */
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
+
+  DebugOnly<bool> mIsMapped;
 };
 
 /* This is an abstract object that accepts path segments. */
 class PathSink : public RefCounted<PathSink>
 {
 public:
   virtual ~PathSink() {}