From ccea287183c5b5aff6f22448fe5f031f5e3e8d02 Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Thu, 16 Jan 2014 13:17:22 +0100 Subject: [PATCH] Bug 960254 - Part 1: Add new Map/Unmap APIs to DataSourceSurface. r=jrmuizel --- gfx/2d/2D.h | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index f084c4e1028..b462817f5b9 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -23,6 +23,8 @@ // solution. #include "mozilla/RefPtr.h" +#include "mozilla/DebugOnly.h" + #ifdef MOZ_ENABLE_FREETYPE #include #endif @@ -337,14 +339,30 @@ public: 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. @@ -357,11 +375,27 @@ public: */ 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 GetDataSurface(); + + DebugOnly mIsMapped; }; /* This is an abstract object that accepts path segments. */