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_SOURCESURFACED2D1_H_ michael@0: #define MOZILLA_GFX_SOURCESURFACED2D1_H_ michael@0: michael@0: #include "2D.h" michael@0: #include "HelpersD2D.h" michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class DrawTargetD2D1; michael@0: michael@0: class SourceSurfaceD2D1 : public SourceSurface michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D1) michael@0: SourceSurfaceD2D1(ID2D1Image* aImage, ID2D1DeviceContext *aDC, michael@0: SurfaceFormat aFormat, const IntSize &aSize, michael@0: DrawTargetD2D1 *aDT = nullptr); michael@0: ~SourceSurfaceD2D1(); michael@0: michael@0: virtual SurfaceType GetType() const { return SurfaceType::D2D1_1_IMAGE; } michael@0: virtual IntSize GetSize() const { return mSize; } michael@0: virtual SurfaceFormat GetFormat() const { return mFormat; } michael@0: virtual TemporaryRef GetDataSurface(); michael@0: michael@0: ID2D1Image *GetImage() { return mImage; } michael@0: michael@0: void EnsureIndependent() { if (!mDrawTarget) return; DrawTargetWillChange(); } michael@0: michael@0: private: michael@0: friend class DrawTargetD2D1; michael@0: michael@0: void EnsureRealizedBitmap(); michael@0: michael@0: // This function is called by the draw target this texture belongs to when michael@0: // it is about to be changed. The texture will be required to make a copy michael@0: // of itself when this happens. michael@0: void DrawTargetWillChange(); michael@0: michael@0: // This will mark the surface as no longer depending on its drawtarget, michael@0: // this may happen on destruction or copying. michael@0: void MarkIndependent(); michael@0: michael@0: RefPtr mImage; michael@0: // This may be null if we were created for a non-bitmap image and have not michael@0: // had a reason yet to realize ourselves. michael@0: RefPtr mRealizedBitmap; michael@0: RefPtr mDC; michael@0: michael@0: SurfaceFormat mFormat; michael@0: IntSize mSize; michael@0: RefPtr mDrawTarget; michael@0: }; michael@0: michael@0: class DataSourceSurfaceD2D1 : public DataSourceSurface michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D1) michael@0: DataSourceSurfaceD2D1(ID2D1Bitmap1 *aMappableBitmap, SurfaceFormat aFormat); michael@0: ~DataSourceSurfaceD2D1(); michael@0: michael@0: virtual SurfaceType GetType() const { return SurfaceType::DATA; } michael@0: virtual IntSize GetSize() const; michael@0: virtual SurfaceFormat GetFormat() const { return mFormat; } michael@0: virtual uint8_t *GetData(); michael@0: virtual int32_t Stride(); michael@0: virtual bool Map(MapType, MappedSurface *aMappedSurface); michael@0: virtual void Unmap(); michael@0: michael@0: private: michael@0: friend class SourceSurfaceD2DTarget; michael@0: void EnsureMapped(); michael@0: michael@0: mutable RefPtr mBitmap; michael@0: SurfaceFormat mFormat; michael@0: D2D1_MAPPED_RECT mMap; michael@0: bool mMapped; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_SOURCESURFACED2D2TARGET_H_ */