michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_SOURCESURFACED2D_H_ michael@0: #define MOZILLA_GFX_SOURCESURFACED2D_H_ michael@0: michael@0: #include "2D.h" michael@0: #include "HelpersD2D.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class DataSourceSurfaceD2D; michael@0: michael@0: class SourceSurfaceD2D : public SourceSurface michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D) michael@0: SourceSurfaceD2D(); michael@0: ~SourceSurfaceD2D(); michael@0: michael@0: virtual SurfaceType GetType() const { return SurfaceType::D2D1_BITMAP; } michael@0: virtual IntSize GetSize() const; michael@0: virtual SurfaceFormat GetFormat() const; michael@0: virtual bool IsValid() const; michael@0: michael@0: virtual TemporaryRef GetDataSurface(); michael@0: michael@0: ID2D1Bitmap *GetBitmap() { return mBitmap; } michael@0: michael@0: bool InitFromData(unsigned char *aData, michael@0: const IntSize &aSize, michael@0: int32_t aStride, michael@0: SurfaceFormat aFormat, michael@0: ID2D1RenderTarget *aRT); michael@0: bool InitFromTexture(ID3D10Texture2D *aTexture, michael@0: SurfaceFormat aFormat, michael@0: ID2D1RenderTarget *aRT); michael@0: private: michael@0: friend class DrawTargetD2D; michael@0: friend class DataSourceSurfaceD2D; michael@0: michael@0: uint32_t GetByteSize() const; michael@0: michael@0: RefPtr mBitmap; michael@0: // We need to keep this pointer here to check surface validity. michael@0: RefPtr mDevice; michael@0: SurfaceFormat mFormat; michael@0: IntSize mSize; michael@0: }; michael@0: michael@0: michael@0: class DataSourceSurfaceD2D : public DataSourceSurface michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D) michael@0: DataSourceSurfaceD2D(SourceSurfaceD2D* aSourceSurface); michael@0: virtual ~DataSourceSurfaceD2D(); michael@0: michael@0: virtual unsigned char* GetData(); michael@0: virtual int32_t Stride(); michael@0: virtual IntSize GetSize() const; michael@0: virtual SurfaceFormat GetFormat() const; michael@0: virtual bool Map(MapType, MappedSurface *aMappedSurface); michael@0: virtual void Unmap(); michael@0: michael@0: bool IsValid() michael@0: { michael@0: return mTexture; michael@0: } michael@0: michael@0: private: michael@0: void EnsureMappedTexture(); michael@0: michael@0: RefPtr mTexture; michael@0: michael@0: D3D10_MAPPED_TEXTURE2D mData; michael@0: michael@0: SurfaceFormat mFormat; michael@0: IntSize mSize; michael@0: bool mMapped; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_SOURCESURFACED2D_H_ */