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_SOURCESURFACED2DTARGET_H_ michael@0: #define MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ michael@0: michael@0: #include "2D.h" michael@0: #include "HelpersD2D.h" michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class DrawTargetD2D; michael@0: michael@0: class SourceSurfaceD2DTarget : public SourceSurface michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2DTarget) michael@0: SourceSurfaceD2DTarget(DrawTargetD2D* aDrawTarget, ID3D10Texture2D* aTexture, michael@0: SurfaceFormat aFormat); michael@0: ~SourceSurfaceD2DTarget(); michael@0: michael@0: virtual SurfaceType GetType() const { return SurfaceType::D2D1_DRAWTARGET; } michael@0: virtual IntSize GetSize() const; michael@0: virtual SurfaceFormat GetFormat() const; michael@0: virtual TemporaryRef GetDataSurface(); michael@0: virtual void *GetNativeSurface(NativeSurfaceType aType); michael@0: michael@0: DrawTargetD2D* GetDT() { return mDrawTarget; } michael@0: ID2D1Bitmap *GetBitmap(ID2D1RenderTarget *aRT); michael@0: michael@0: private: michael@0: friend class DrawTargetD2D; michael@0: michael@0: ID3D10ShaderResourceView *GetSRView(); 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 mSRView; michael@0: RefPtr mBitmap; michael@0: // Non-null if this is a "lazy copy" of the given draw target. michael@0: // Null if we've made a copy. The target is not kept alive, otherwise we'd michael@0: // have leaks since it might keep us alive. If the target is destroyed, it michael@0: // will notify us. michael@0: DrawTargetD2D* mDrawTarget; michael@0: mutable RefPtr mTexture; michael@0: SurfaceFormat mFormat; michael@0: bool mOwnsCopy; michael@0: }; michael@0: michael@0: class DataSourceSurfaceD2DTarget : public DataSourceSurface michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2DTarget) michael@0: DataSourceSurfaceD2DTarget(SurfaceFormat aFormat); michael@0: ~DataSourceSurfaceD2DTarget(); michael@0: michael@0: virtual SurfaceType GetType() const { return SurfaceType::DATA; } michael@0: virtual IntSize GetSize() const; michael@0: virtual SurfaceFormat GetFormat() const; 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 mTexture; michael@0: SurfaceFormat mFormat; michael@0: D3D10_MAPPED_TEXTURE2D mMap; michael@0: bool mMapped; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ */